Skip to content

Commit

Permalink
no-empty-file: Support .jsx and .tsx extensions (#2002)
Browse files Browse the repository at this point in the history
Co-authored-by: fisker Cheung <[email protected]>
  • Loading branch information
Felix-kln and fisker authored Feb 1, 2023
1 parent 4ada50e commit ba1a00e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions rules/no-empty-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 4 additions & 3 deletions test/no-empty-file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ test.snapshot({
'md',
'vue',
'svelte',
'tsx',
].map(extension => ({code: '', filename: `example.${extension}`})),
...[
'd.ts',
Expand Down Expand Up @@ -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}`})),
],
Expand Down
36 changes: 34 additions & 2 deletions test/snapshots/no-empty-file.mjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ Generated by [AVA](https://avajs.dev).
> Filename
`␊
example.cjs
example.cJs
`

> Error 1/1
Expand Down Expand Up @@ -387,7 +387,7 @@ Generated by [AVA](https://avajs.dev).
> Filename
`␊
example.mts
example.tsx
`

> Error 1/1
Expand All @@ -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
`␊
Expand Down
Binary file modified test/snapshots/no-empty-file.mjs.snap
Binary file not shown.

0 comments on commit ba1a00e

Please sign in to comment.