Skip to content

Commit 9a9670d

Browse files
authored
fix(eslint-plugin): support arbitrary extensions in definition files (#10957)
* support arbitrary extensions in definition files * updated test case * updated test and refactoring
1 parent c7c9b1a commit 9a9670d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/eslint-plugin/src/util/misc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export function isDefinitionFile(fileName: string): boolean {
2525
return true;
2626
}
2727
}
28-
return false;
28+
29+
return /\.d\.(ts|cts|mts|.*\.ts)$/.test(lowerFileName);
2930
}
3031

3132
/**

packages/eslint-plugin/tests/util/misc.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
import * as misc from '../../src/util/misc';
22

3+
describe('isDefinitionFile', () => {
4+
it.each([['index.d.ts'], ['module.d.cts'], ['package.d.mts']])(
5+
'returns true for standard definition file: %s',
6+
filename => {
7+
expect(misc.isDefinitionFile(filename)).toBe(true);
8+
},
9+
);
10+
11+
it.each([['styles.d.css.ts'], ['component.d.vue.ts'], ['env.d.node.ts']])(
12+
'returns true for arbitrary extension definition file: %s',
13+
filename => {
14+
expect(misc.isDefinitionFile(filename)).toBe(true);
15+
},
16+
);
17+
18+
it.each([['index.ts'], ['app.tsx'], ['styles.css.ts'], ['vite.config.ts']])(
19+
'returns false for non definition file: %s',
20+
filename => {
21+
expect(misc.isDefinitionFile(filename)).toBe(false);
22+
},
23+
);
24+
});
25+
326
describe('formatWordList', () => {
427
it('can format with no words', () => {
528
expect(misc.formatWordList([])).toBe('');

0 commit comments

Comments
 (0)