diff --git a/rules/no-empty-file.js b/rules/no-empty-file.js index db750c049b..2d82a888d1 100644 --- a/rules/no-empty-file.js +++ b/rules/no-empty-file.js @@ -17,9 +17,9 @@ const hasTripeSlashDirectives = comments => /** @param {import('eslint').Rule.RuleContext} context */ const create = context => { - const filename = context.getPhysicalFilename().toLowerCase(); + const filename = context.getPhysicalFilename(); - if (!/\.(?:js|mjs|cjs|ts|mts|cts)$/.test(filename)) { + if (!/\.(?:js|mjs|cjs|jsx|ts|mts|cts|tsx)$/i.test(filename)) { return; } diff --git a/test/no-empty-file.mjs b/test/no-empty-file.mjs index 1fa0816494..cc8113acf5 100644 --- a/test/no-empty-file.mjs +++ b/test/no-empty-file.mjs @@ -35,7 +35,6 @@ test.snapshot({ 'md', 'vue', 'svelte', - 'tsx', ].map(extension => ({code: '', filename: `example.${extension}`})), ...[ 'd.ts', @@ -69,9 +68,11 @@ test.snapshot({ ].map(code => ({code, filename: 'example.js'})), ...[ 'mjs', - 'cjs', + 'cJs', 'ts', - 'mts', + 'tsx', + 'jsx', + 'MTS', 'cts', ].map(extension => ({code: '{}', filename: `example.${extension}`})), ], diff --git a/test/snapshots/no-empty-file.mjs.md b/test/snapshots/no-empty-file.mjs.md index 0bbc8f1f61..d30116737d 100644 --- a/test/snapshots/no-empty-file.mjs.md +++ b/test/snapshots/no-empty-file.mjs.md @@ -355,7 +355,7 @@ Generated by [AVA](https://avajs.dev). > Filename `␊ - example.cjs␊ + example.cJs␊ ` > Error 1/1 @@ -387,7 +387,7 @@ Generated by [AVA](https://avajs.dev). > Filename `␊ - example.mts␊ + example.tsx␊ ` > Error 1/1 @@ -400,6 +400,38 @@ Generated by [AVA](https://avajs.dev). ## Invalid #25 1 | {} +> Filename + + `␊ + example.jsx␊ + ` + +> Error 1/1 + + `␊ + > 1 | {}␊ + | ^^ Empty files are not allowed.␊ + ` + +## Invalid #26 + 1 | {} + +> Filename + + `␊ + example.MTS␊ + ` + +> Error 1/1 + + `␊ + > 1 | {}␊ + | ^^ Empty files are not allowed.␊ + ` + +## Invalid #27 + 1 | {} + > Filename `␊ diff --git a/test/snapshots/no-empty-file.mjs.snap b/test/snapshots/no-empty-file.mjs.snap index f383ae6dae..e8787cb432 100644 Binary files a/test/snapshots/no-empty-file.mjs.snap and b/test/snapshots/no-empty-file.mjs.snap differ