Skip to content

Commit b9c496f

Browse files
committed
feat(plugins/naming-convention):add 'ignoreFilesWithoutCode' option to 'filename-extension'
1 parent 2b113e8 commit b9c496f

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

packages/plugins/eslint-plugin-react-naming-convention/src/rules/filename-extension.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ type Options = readonly [
1818
| {
1919
allow?: Allow;
2020
extensions?: readonly string[];
21+
ignoreFilesWithoutCode?: boolean;
2122
},
2223
];
2324
/* eslint-enable no-restricted-syntax */
2425

2526
const defaultOptions = [{
2627
allow: "as-needed",
2728
extensions: [".jsx", ".tsx"],
29+
ignoreFilesWithoutCode: false,
2830
}] as const satisfies Options;
2931

3032
const schema = [
@@ -49,6 +51,9 @@ const schema = [
4951
},
5052
uniqueItems: true,
5153
},
54+
ignoreFilesWithoutCode: {
55+
type: "boolean",
56+
},
5257
},
5358
},
5459
],
@@ -98,6 +103,9 @@ export default createRule<Options, MessageID>({
98103
return;
99104
}
100105

106+
const hasCode = node.body.length > 0;
107+
const ignoreFilesWithoutCode = isObject(options) && options.ignoreFilesWithoutCode;
108+
if (!hasCode && ignoreFilesWithoutCode) return;
101109
if (
102110
!hasJSXCode
103111
&& isJSXExt

website/pages/docs/rules/naming-convention-component-name.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function ExampleComponent() {
3636

3737
## Rule Options
3838

39-
- `rule`: The rule to apply to the file name. Can be one of the following:
39+
- `rule`: The rule to apply to the file name. Default is `"PascalCase"`. Possible values:
4040
1. `PascalCase`: PascalCase
4141
2. `CONSTANT_CASE`: CONSTANT_CASE
4242
- `excepts`: (optional) An array of component names that are allowed to not follow the rule.

website/pages/docs/rules/naming-convention-filename-extension.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ This rule enforces consistent file extensions for JSX files.
1414

1515
## Rule Options
1616

17-
- `allow`: When to allow a JSX filename extension.
17+
- `allow`: When to allow a JSX filename extension. Default is `"as-needed"`. Possible values:
1818
1. `"always"`: allow all file use JSX file extension.
19-
2. `"as-needed"`: (default) allow JSX file extension only if the file contains JSX syntax.
20-
- `extensions`: List of file extensions that should be checked by this rule. By default, The default value is `[".jsx", ".tsx"]` which checks only `.jsx` and `.tsx` files.
19+
2. `"as-needed"`: allow JSX file extension only if the file contains JSX syntax.
20+
- `extensions`: List of file extensions that should be treated as JSX files. Default is `[".jsx", ".tsx"]`.
21+
- `ignoreFilesWithoutCode`: When set to `true`, this rule will ignore files that do not contain JSX syntax. Default is `true`.
2122

2223
## Rule Options Examples
2324

website/pages/docs/rules/naming-convention-filename.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ src/components/example-component.tsx
5050

5151
## Rule Options
5252

53-
- `rule`: The rule to apply to the file name. Can be one of the following:
54-
1. `PascalCase`: PascalCase (default)
53+
- `rule`: The rule to apply to the file name. Default is `"PascalCase"`. Possible values:
54+
1. `PascalCase`: PascalCase
5555
2. `camelCase`: camelCase
5656
3. `kebab-case`: kebab-case
5757
4. `snake_case`: snake_case

0 commit comments

Comments
 (0)