Skip to content

Commit

Permalink
filename-case: Ignore more index files (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Sep 15, 2020
1 parent b35c261 commit 64d03a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion rules/filename-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const numberRegex = /\d+/;
const PLACEHOLDER = '\uFFFF\uFFFF\uFFFF';
const PLACEHOLDER_REGEX = new RegExp(PLACEHOLDER, 'i');
const isIgnoredChar = char => !/^[a-z\d-_$]$/i.test(char);
const ignoredByDefault = new Set(['index.js', 'index.mjs', 'index.cjs', 'index.ts', 'index.tsx', 'index.vue']);

function ignoreNumbers(fn) {
return string => {
Expand Down Expand Up @@ -159,7 +160,7 @@ const create = context => {
const filename = path.basename(filenameWithExtension, extension);
const base = filename + extension;

if (base === 'index.js' || ignore.some(regexp => regexp.test(base))) {
if (ignoredByDefault.has(base) || ignore.some(regexp => regexp.test(base))) {
return;
}

Expand Down
10 changes: 8 additions & 2 deletions test/filename-case.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import test from 'ava';
import avaRuleTester from 'eslint-ava-rule-tester';
import {flatten} from 'lodash';
import rule from '../rules/filename-case';

const ruleTester = avaRuleTester(test, {
Expand Down Expand Up @@ -73,7 +74,6 @@ ruleTester.run('filename-case', rule, {
testCase('spec/Iss47Spec.js', 'pascalCase'),
testCase('spec/Iss47.100Spec.js', 'pascalCase'),
testCase('spec/I18n.js', 'pascalCase'),
testCase('spec/index.js', 'pascalCase'),
testCase(undefined, 'camelCase'),
testCase(undefined, 'snakeCase'),
testCase(undefined, 'kebabCase'),
Expand Down Expand Up @@ -239,7 +239,13 @@ ruleTester.run('filename-case', rule, {
},
ignore: [/FOOBAR\.js/u, /BaRbAz\.js/u]
}
])
]),
// Ignored
...flatten(
['index.js', 'index.mjs', 'index.cjs', 'index.ts', 'index.tsx', 'index.vue'].map(
filename => ['camelCase', 'snakeCase', 'kebabCase', 'pascalCase'].map(chosenCase => testCase(filename, chosenCase))
)
)
],
invalid: [
testCase(
Expand Down

0 comments on commit 64d03a5

Please sign in to comment.