|
| 1 | +/** |
| 2 | + * @file The folder should follow the folder naming convention |
| 3 | + * @author Duke Luo |
| 4 | + */ |
| 5 | +'use strict'; |
| 6 | + |
| 7 | +const path = require('path'); |
| 8 | +const proxyquire = require('proxyquire'); |
| 9 | +const RuleTester = require('eslint').RuleTester; |
| 10 | + |
| 11 | +const rule = proxyquire('../../../lib/rules/folder-naming-convention', { |
| 12 | + path: { ...path.win32, '@global': true }, |
| 13 | +}); |
| 14 | +const ruleTester = new RuleTester(); |
| 15 | + |
| 16 | +ruleTester.run( |
| 17 | + "folder-naming-convention with option on Windows: [{ '*/__tests__/': 'PASCAL_CASE', 'src/*/': 'CAMEL_CASE' }]", |
| 18 | + rule, |
| 19 | + { |
| 20 | + valid: [ |
| 21 | + { |
| 22 | + code: "var foo = 'bar';", |
| 23 | + filename: |
| 24 | + 'src\\components\\DisplayLabel\\__tests__\\displayLabel.test.js', |
| 25 | + options: [{ '*/__tests__/': 'PASCAL_CASE', 'src/*/': 'CAMEL_CASE' }], |
| 26 | + }, |
| 27 | + ], |
| 28 | + |
| 29 | + invalid: [ |
| 30 | + { |
| 31 | + code: "var foo = 'bar';", |
| 32 | + filename: |
| 33 | + 'src\\Components\\DisplayLabel\\__tests__\\displayLabel.test.js', |
| 34 | + options: [{ '*/__tests__/': 'PASCAL_CASE', 'src/*/': 'CAMEL_CASE' }], |
| 35 | + errors: [ |
| 36 | + { |
| 37 | + message: |
| 38 | + 'The folder "Components" does not match the "CAMEL_CASE" style', |
| 39 | + column: 1, |
| 40 | + line: 1, |
| 41 | + }, |
| 42 | + ], |
| 43 | + }, |
| 44 | + { |
| 45 | + code: "var foo = 'bar';", |
| 46 | + filename: |
| 47 | + 'src\\components\\displayLabel\\__tests__\\displayLabel.test.js', |
| 48 | + options: [{ '*/__tests__/': 'PASCAL_CASE', 'src/*/': 'CAMEL_CASE' }], |
| 49 | + errors: [ |
| 50 | + { |
| 51 | + message: |
| 52 | + 'The folder "displayLabel" does not match the "PASCAL_CASE" style', |
| 53 | + column: 1, |
| 54 | + line: 1, |
| 55 | + }, |
| 56 | + ], |
| 57 | + }, |
| 58 | + ], |
| 59 | + } |
| 60 | +); |
| 61 | + |
| 62 | +ruleTester.run( |
| 63 | + "folder-naming-convention with option on Windows: [{ 'src/**/': 'CAMEL_CASE' }]", |
| 64 | + rule, |
| 65 | + { |
| 66 | + valid: [ |
| 67 | + { |
| 68 | + code: "var foo = 'bar';", |
| 69 | + filename: 'src\\components\\displayLabel\\displayLabel.js', |
| 70 | + options: [{ 'src/**/': 'CAMEL_CASE' }], |
| 71 | + }, |
| 72 | + ], |
| 73 | + |
| 74 | + invalid: [ |
| 75 | + { |
| 76 | + code: "var foo = 'bar';", |
| 77 | + filename: 'src\\Components\\DisplayLabel\\displayLabel.js', |
| 78 | + options: [{ 'src/**/': 'CAMEL_CASE' }], |
| 79 | + errors: [ |
| 80 | + { |
| 81 | + message: |
| 82 | + 'The folder "Components" does not match the "CAMEL_CASE" style', |
| 83 | + column: 1, |
| 84 | + line: 1, |
| 85 | + }, |
| 86 | + ], |
| 87 | + }, |
| 88 | + { |
| 89 | + code: "var foo = 'bar';", |
| 90 | + filename: 'src\\components\\DisplayLabel\\displayLabel.js', |
| 91 | + options: [{ 'src/**/': 'CAMEL_CASE' }], |
| 92 | + errors: [ |
| 93 | + { |
| 94 | + message: |
| 95 | + 'The folder "DisplayLabel" does not match the "CAMEL_CASE" style', |
| 96 | + column: 1, |
| 97 | + line: 1, |
| 98 | + }, |
| 99 | + ], |
| 100 | + }, |
| 101 | + ], |
| 102 | + } |
| 103 | +); |
| 104 | + |
| 105 | +ruleTester.run( |
| 106 | + "folder-naming-convention with option on Windows: [{ 'components/*/': '__+([a-z])' }]", |
| 107 | + rule, |
| 108 | + { |
| 109 | + valid: [ |
| 110 | + { |
| 111 | + code: "var foo = 'bar';", |
| 112 | + filename: 'src\\components\\__displaylabel\\index.js', |
| 113 | + options: [{ 'components/*/': '__+([a-z])' }], |
| 114 | + }, |
| 115 | + ], |
| 116 | + |
| 117 | + invalid: [ |
| 118 | + { |
| 119 | + code: "var foo = 'bar';", |
| 120 | + filename: 'src\\components\\_displayLabel\\index.js', |
| 121 | + options: [{ 'components/*/': '__+([a-z])' }], |
| 122 | + errors: [ |
| 123 | + { |
| 124 | + message: |
| 125 | + 'The folder "_displayLabel" does not match the "__+([a-z])" style', |
| 126 | + column: 1, |
| 127 | + line: 1, |
| 128 | + }, |
| 129 | + ], |
| 130 | + }, |
| 131 | + { |
| 132 | + code: "var foo = 'bar';", |
| 133 | + filename: 'src\\components\\__displayLabel\\index.js', |
| 134 | + options: [{ 'components/*/': '__+([a-z])' }], |
| 135 | + errors: [ |
| 136 | + { |
| 137 | + message: |
| 138 | + 'The folder "__displayLabel" does not match the "__+([a-z])" style', |
| 139 | + column: 1, |
| 140 | + line: 1, |
| 141 | + }, |
| 142 | + ], |
| 143 | + }, |
| 144 | + ], |
| 145 | + } |
| 146 | +); |
| 147 | + |
| 148 | +ruleTester.run( |
| 149 | + 'folder-naming-convention with folder that has not been set on Windows', |
| 150 | + rule, |
| 151 | + { |
| 152 | + valid: [ |
| 153 | + { |
| 154 | + code: "var foo = 'bar';", |
| 155 | + filename: 'scripts\\build.js', |
| 156 | + options: [{ '*/__tests__/': 'PASCAL_CASE', 'src/*/': 'CAMEL_CASE' }], |
| 157 | + }, |
| 158 | + ], |
| 159 | + |
| 160 | + invalid: [], |
| 161 | + } |
| 162 | +); |
| 163 | + |
| 164 | +ruleTester.run( |
| 165 | + "folder-naming-convention with option on Windows: [{ '*/__tests__/': 'FOO', 'src/*/': 'CAMEL_CASE' }]", |
| 166 | + rule, |
| 167 | + { |
| 168 | + valid: [], |
| 169 | + |
| 170 | + invalid: [ |
| 171 | + { |
| 172 | + code: "var foo = 'bar';", |
| 173 | + filename: 'src\\utils\\calculatePrice.js', |
| 174 | + options: [{ '*/__tests__/': 'FOO', 'src/*/': 'CAMEL_CASE' }], |
| 175 | + errors: [ |
| 176 | + { |
| 177 | + message: 'There is an invalid pattern "FOO", please check it', |
| 178 | + column: 1, |
| 179 | + line: 1, |
| 180 | + }, |
| 181 | + ], |
| 182 | + }, |
| 183 | + ], |
| 184 | + } |
| 185 | +); |
| 186 | + |
| 187 | +ruleTester.run( |
| 188 | + "filename-naming-convention with option on Windows: [{ '*/__tests__/': 'PASCAL_CASE', 'src/': 'CAMEL_CASE' }]", |
| 189 | + rule, |
| 190 | + { |
| 191 | + valid: [], |
| 192 | + |
| 193 | + invalid: [ |
| 194 | + { |
| 195 | + code: "var foo = 'bar';", |
| 196 | + filename: 'src\\utils\\calculatePrice.js', |
| 197 | + options: [{ '*/__tests__/': 'PASCAL_CASE', 'src/': 'CAMEL_CASE' }], |
| 198 | + errors: [ |
| 199 | + { |
| 200 | + message: 'There is an invalid pattern "src/", please check it', |
| 201 | + column: 1, |
| 202 | + line: 1, |
| 203 | + }, |
| 204 | + ], |
| 205 | + }, |
| 206 | + ], |
| 207 | + } |
| 208 | +); |
0 commit comments