Skip to content

Commit b9cbbed

Browse files
authored
filename-case: Allow $-prefixed filenames (#3012)
1 parent 9cd57bf commit b9cbbed

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

docs/rules/filename-case.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Enforces all linted files to have their names in a certain case style and lowerc
1111

1212
Files named `index.js`, `index.mjs`, `index.cjs`, `index.ts`, `index.tsx`, `index.vue` are ignored as they can't change case (Only a problem with `pascalCase`).
1313

14-
Characters in the filename except `a-z`, `A-Z`, `0-9`, `-`, and `_` are ignored.
14+
Characters other than `a-z`, `A-Z`, `0-9`, `-`, and `_` are ignored for casing and kept as-is in suggested filenames.
15+
16+
The filename case check ignores filenames starting with `$`, as they are commonly used for route parameters.
1517

1618
## Cases
1719

rules/filename-case.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const create = context => {
167167
}
168168

169169
const {leading, words} = splitFilename(filename);
170-
const isValid = validateFilename(words, chosenCasesFunctions);
170+
const isValid = filename.startsWith('$') || validateFilename(words, chosenCasesFunctions);
171171

172172
if (isValid) {
173173
if (!isLowerCase(extension)) {

test/filename-case.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,14 @@ test({
9393
testCase('src/foo/_FooBar.js', 'pascalCase'),
9494
testCase('src/foo/___FooBar.js', 'pascalCase'),
9595
testCase('src/foo/$foo.js'),
96+
testCase('src/foo/$userId.tsx'),
97+
testCase('src/foo/$foo_bar.js'),
98+
testCase('src/foo/$fooBar.js'),
9699
testManyCases('src/foo/foo-bar.js'),
97100
testManyCases('src/foo/foo-bar.js', {}),
98101
testManyCases('src/foo/fooBar.js', {camelCase: true}),
99102
testManyCases('src/foo/FooBar.js', {kebabCase: true, pascalCase: true}),
103+
testManyCases('src/foo/$idCertidao.tsx', {kebabCase: true, pascalCase: true}),
100104
testManyCases('src/foo/___foo_bar.js', {snakeCase: true, pascalCase: true}),
101105
testCaseWithOptions('src/foo/bar.js'),
102106
testCase('src/foo/[fooBar].js', 'camelCase'),
@@ -248,7 +252,14 @@ test({
248252
},
249253
]),
250254
// Ignored
251-
...['index.js', 'index.mjs', 'index.cjs', 'index.ts', 'index.tsx', 'index.vue'].flatMap(filename => ['camelCase', 'snakeCase', 'kebabCase', 'pascalCase'].map(chosenCase => testCase(filename, chosenCase))),
255+
...[
256+
'index.js',
257+
'index.mjs',
258+
'index.cjs',
259+
'index.ts',
260+
'index.tsx',
261+
'index.vue',
262+
].flatMap(filename => ['camelCase', 'snakeCase', 'kebabCase', 'pascalCase'].map(chosenCase => testCase(filename, chosenCase))),
252263
testCaseWithOptions('index.tsx', undefined, [{case: 'pascalCase', multipleFileExtensions: false}]),
253264
testCaseWithOptions('src/index.tsx', undefined, [{case: 'pascalCase', multipleFileExtensions: false}]),
254265
testCaseWithOptions('src/foo/fooBar.test.js', undefined, [{case: 'camelCase', multipleFileExtensions: false}]),
@@ -257,6 +268,7 @@ test({
257268
testCaseWithOptions('src/foo/foo.test.js', undefined, [{case: 'kebabCase', multipleFileExtensions: false}]),
258269
testCaseWithOptions('src/foo/foo-bar.test.js', undefined, [{case: 'kebabCase', multipleFileExtensions: false}]),
259270
testCaseWithOptions('src/foo/foo-bar.test-utils.js', undefined, [{case: 'kebabCase', multipleFileExtensions: false}]),
271+
testCaseWithOptions('src/foo/$userId.test.tsx', undefined, [{case: 'kebabCase', multipleFileExtensions: false}]),
260272
testCaseWithOptions('src/foo/Foo.Test.js', undefined, [{case: 'pascalCase', multipleFileExtensions: false}]),
261273
testCaseWithOptions('src/foo/FooBar.Test.js', undefined, [{case: 'pascalCase', multipleFileExtensions: false}]),
262274
testCaseWithOptions('src/foo/FooBar.TestUtils.js', undefined, [{case: 'pascalCase', multipleFileExtensions: false}]),
@@ -431,14 +443,14 @@ test({
431443
'Filename is not in kebab case. Rename it to `[foo-bar].js`.',
432444
),
433445
testCase(
434-
'src/foo/$foo_bar.js',
446+
'src/foo/foo$Bar.js',
435447
undefined,
436-
'Filename is not in kebab case. Rename it to `$foo-bar.js`.',
448+
'Filename is not in kebab case. Rename it to `foo$bar.js`.',
437449
),
438450
testCase(
439-
'src/foo/$fooBar.js',
451+
'src/foo/$userId.TSX',
440452
undefined,
441-
'Filename is not in kebab case. Rename it to `$foo-bar.js`.',
453+
'File extension `.TSX` is not in lowercase. Rename it to `$userId.tsx`.',
442454
),
443455
testManyCases(
444456
'src/foo/{foo_bar}.js',

0 commit comments

Comments
 (0)