Skip to content

Commit 44f8b62

Browse files
committed
release: 0.9.7-beta.0
1 parent 447a0f3 commit 44f8b62

File tree

10 files changed

+84
-37
lines changed

10 files changed

+84
-37
lines changed

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
## v0.9.7-beta.0 (Draft)
1+
## v0.9.7-beta.0 (Thu Dec 14 2023)
22

33
### Release Notes
44

5+
#### Rule `named-convention/filename` add `extensions` option
6+
7+
#### Rule `named-convention/filename-extension` add `extensions` option
8+
9+
#### Rule `named-convention/filename-extension` rename `rule` option to `allow`
10+
511
---
612

713
#### 🏠 Internal
814

15+
- `@eslint-react/eslint-plugin-naming-convention`
16+
- Rule `named-convention/filename` add `extensions` option.
17+
- Rule `named-convention/filename-extension` rename `rule` option to `allow`.
18+
- Rule `named-convention/filename-extension` add `extensions` option.
19+
20+
- `@eslint-react/shared`
21+
- Remove `JSX_EXTENSIONS` from `@eslint-react/shared`.
22+
923
- `@eslint-react/monorepo`
1024
- Update `bun` to `1.0.17`.
25+
- Update `vitest` to `1.0.4`.
26+
- Update `eslint-config-with-tsconfig` to `2.9.160`.
1127

1228
#### Authors: 1
1329

packages/eslint-plugin-naming-convention/src/rules/filename-extension.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This rule enforces consistent file extensions for JSX files.
2020

2121
## Rule Options
2222

23-
This rule has a string option:
24-
25-
- `"always"`: (default) allow all file use JSX file extension.
26-
- `"as-needed"`: allow JSX file extension only if the file contains JSX syntax.
23+
- `allow`: When to allow a JSX filename extension.
24+
- `"always"`: (default) allow all file use JSX file extension.
25+
- `"as-needed"`: allow JSX file extension only if the file contains JSX syntax.
26+
- `extensions`: List of file extensions that should be checked by this rule. By default, it checks `.jsx`, `.tsx` and `.mtx` files.

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ruleTester.run(RULE_NAME, rule, {
3232
{
3333
filename: "react.tsx",
3434
code: withoutJSX,
35-
options: [{ rule: "always" }],
35+
options: [{ allow: "always" }],
3636
},
3737
],
3838
invalid: [
@@ -49,12 +49,27 @@ ruleTester.run(RULE_NAME, rule, {
4949
{
5050
filename: "react.tsx",
5151
code: withoutJSX,
52-
options: [{ rule: "as-needed" }],
52+
options: [{ allow: "as-needed" }],
5353
errors: [
5454
{
5555
messageId: "FILE_NAME_EXTENSION_UNEXPECTED",
5656
},
5757
],
5858
},
59+
{
60+
filename: "react.tsx",
61+
code: withJSXElement,
62+
options: [
63+
{
64+
allow: "as-needed",
65+
extensions: ["mtx"],
66+
},
67+
],
68+
errors: [
69+
{
70+
messageId: "FILE_NAME_EXTENSION_INVALID",
71+
},
72+
],
73+
},
5974
],
6075
});

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MutRef, P } from "@eslint-react/tools";
22
import type { ESLintUtils } from "@typescript-eslint/utils";
33
import type { JSONSchema4 } from "@typescript-eslint/utils/json-schema";
44

5-
import { createRule, isJSXFile } from "../utils";
5+
import { createRule } from "../utils";
66

77
export const RULE_NAME = "filename-extension";
88

@@ -13,7 +13,8 @@ type Cond = "always" | "as-needed";
1313
/* eslint-disable no-restricted-syntax */
1414
type Options = readonly [
1515
| {
16-
rule?: Cond;
16+
allow?: Cond;
17+
extensions?: readonly string[];
1718
// Reserved for future use
1819
// excepts?: readonly string[];
1920
}
@@ -22,7 +23,10 @@ type Options = readonly [
2223
];
2324
/* eslint-enable no-restricted-syntax */
2425

25-
const defaultOptions = ["as-needed"] as const satisfies Options;
26+
const defaultOptions = [{
27+
allow: "as-needed",
28+
extensions: ["jsx", "tsx", "mtx"],
29+
}] as const satisfies Options;
2630

2731
const schema = [
2832
{
@@ -35,10 +39,17 @@ const schema = [
3539
type: "object",
3640
additionalProperties: false,
3741
properties: {
38-
rule: {
42+
allow: {
3943
type: "string",
4044
enum: ["always", "as-needed"],
4145
},
46+
extensions: {
47+
type: "array",
48+
items: {
49+
type: "string",
50+
},
51+
uniqueItems: true,
52+
},
4253
},
4354
},
4455
],
@@ -55,14 +66,17 @@ export default createRule<Options, MessageID>({
5566
},
5667
schema,
5768
messages: {
58-
FILE_NAME_EXTENSION_INVALID: "JSX files must have a `.jsx` or `.tsx` extension",
59-
FILE_NAME_EXTENSION_UNEXPECTED: "use `.jsx` or `.tsx` extension as needed",
69+
FILE_NAME_EXTENSION_INVALID: "JSX file extension is required",
70+
FILE_NAME_EXTENSION_UNEXPECTED: "use JSX file extension as needed",
6071
},
6172
},
6273
defaultOptions,
6374
create(context) {
6475
const options = context.options[0] ?? defaultOptions[0];
65-
const cond = P.isString(options) ? options : options.rule ?? "as-needed";
76+
const allow = P.isObject(options) ? options.allow : options;
77+
const extensions = P.isObject(options) && "extensions" in options
78+
? options.extensions
79+
: defaultOptions[0].extensions;
6680

6781
const filename = context.getFilename();
6882
const hasJSXNodeRef = MutRef.make<boolean>(false);
@@ -75,11 +89,13 @@ export default createRule<Options, MessageID>({
7589
MutRef.set(hasJSXNodeRef, true);
7690
},
7791
"Program:exit"(node) {
78-
const fileNameExt = filename.slice(filename.lastIndexOf("."));
79-
const isJSX = isJSXFile(fileNameExt);
92+
const fileNameExt = filename
93+
.slice(filename.lastIndexOf("."))
94+
.replace(".", "");
95+
const isJSXExt = extensions.includes(fileNameExt);
8096
const hasJSXCode = MutRef.get(hasJSXNodeRef);
8197

82-
if (!isJSX && hasJSXCode) {
98+
if (hasJSXCode && !isJSXExt) {
8399
context.report({
84100
messageId: "FILE_NAME_EXTENSION_INVALID",
85101
node,
@@ -89,9 +105,9 @@ export default createRule<Options, MessageID>({
89105
}
90106

91107
if (
92-
isJSX
93-
&& !hasJSXCode
94-
&& cond === "as-needed"
108+
!hasJSXCode
109+
&& isJSXExt
110+
&& allow === "as-needed"
95111
) {
96112
context.report({
97113
messageId: "FILE_NAME_EXTENSION_UNEXPECTED",

packages/eslint-plugin-naming-convention/src/rules/filename.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ src/components/example-component.tsx
6767
- `kebab-case`: kebab-case
6868
- `snake_case`: snake_case
6969
- `excepts`: List of file names that should be ignored by this rule.
70+
- `extensions`: List of file extensions that should be checked by this rule. By default, it checks `.jsx`, `.tsx` and `.mtx` files.

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { JSONSchema4 } from "@typescript-eslint/utils/json-schema";
55
import type { ReportDescriptor } from "@typescript-eslint/utils/ts-eslint";
66
import path from "pathe";
77

8-
import { createRule, isJSXFile } from "../utils";
8+
import { createRule } from "../utils";
99

1010
export const RULE_NAME = "filename";
1111

@@ -14,6 +14,7 @@ export type MessageID = "FILENAME_CASE_MISMATCH" | "FILENAME_CASE_MISMATCH_SUGGE
1414
/* eslint-disable no-restricted-syntax */
1515
type Options = readonly [
1616
| {
17+
extensions?: readonly string[];
1718
excepts?: readonly string[];
1819
rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
1920
}
@@ -24,6 +25,7 @@ type Options = readonly [
2425

2526
const defaultOptions = [
2627
{
28+
extensions: ["jsx", "tsx", "mtx"],
2729
excepts: ["index"],
2830
rule: "PascalCase",
2931
},
@@ -40,6 +42,11 @@ const schema = [
4042
type: "object",
4143
additionalProperties: false,
4244
properties: {
45+
extensions: {
46+
type: "array",
47+
items: { type: "string" },
48+
uniqueItems: true,
49+
},
4350
excepts: {
4451
type: "array",
4552
items: { type: "string", format: "regex" },
@@ -59,7 +66,7 @@ export default createRule<Options, MessageID>({
5966
meta: {
6067
type: "suggestion",
6168
docs: {
62-
description: "enforce naming convention for JSX file names",
69+
description: "enforce naming convention for JSX filenames",
6370
requiresTypeChecking: false,
6471
},
6572
schema,
@@ -75,11 +82,16 @@ export default createRule<Options, MessageID>({
7582
const options = context.options[0] ?? defaultOptions[0];
7683
const rule = P.isString(options) ? options : options.rule ?? "PascalCase";
7784
const excepts = P.isString(options) ? [] : options.excepts ?? [];
85+
const extensions = P.isObject(options) && "extensions" in options
86+
? options.extensions
87+
: defaultOptions[0].extensions;
7888

7989
const filename = context.getFilename();
80-
const fileNameExt = filename.slice(filename.lastIndexOf("."));
90+
const fileNameExt = filename
91+
.slice(filename.lastIndexOf("."))
92+
.replace(".", "");
8193

82-
if (!isJSXFile(fileNameExt)) {
94+
if (!extensions.includes(fileNameExt)) {
8395
return {};
8496
}
8597

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from "./create-rule";
2-
export * from "./is-jsx-file";

packages/eslint-plugin-naming-convention/src/utils/is-jsx-file.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/shared/docs/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
- [GITHUB\_URL](README.md#github_url)
4040
- [HostHTMLComponentTypes](README.md#hosthtmlcomponenttypes)
4141
- [HostSVGComponentTypes](README.md#hostsvgcomponenttypes)
42-
- [JSX\_EXTENSIONS](README.md#jsx_extensions)
4342
- [NPM\_SCOPE](README.md#npm_scope)
4443
- [RE\_JAVASCRIPT\_PROTOCOL](README.md#re_javascript_protocol)
4544
- [ReactHostHTMLComponent](README.md#reacthosthtmlcomponent)
@@ -260,12 +259,6 @@ Rule severity.
260259

261260
---
262261

263-
### JSX\_EXTENSIONS
264-
265-
`Const` **JSX\_EXTENSIONS**: `string`[]
266-
267-
---
268-
269262
### NPM\_SCOPE
270263

271264
`Const` **NPM\_SCOPE**: `"@eslint-react"`

packages/shared/src/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ export const GITHUB_URL = "https://github.com/rel1cx/eslint-react/blob/main";
44

55
export const WEBSITE_URL = "https://eslint-react.rel1cx.io";
66

7-
export const JSX_EXTENSIONS = [".jsx", ".tsx"];
8-
97
// @see https://github.com/facebook/react/blob/6db7f4209e6f32ebde298a0b7451710dd6aa3e19/packages/react-dom-bindings/src/shared/sanitizeURL.js#L22
108
// dprint-ignore
119
// eslint-disable-next-line no-control-regex

0 commit comments

Comments
 (0)