eslint-plugin-react-naming-convention 2.0.0-next.17 → 2.0.0-next.170

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,29 +17,32 @@ npm install --save-dev eslint-plugin-react-naming-convention
17
17
  // @ts-check
18
18
  import js from "@eslint/js";
19
19
  import reactNamingConvention from "eslint-plugin-react-naming-convention";
20
+ import { defineConfig } from "eslint/config";
20
21
  import tseslint from "typescript-eslint";
21
22
 
22
- export default tseslint.config({
23
- files: ["**/*.ts", "**/*.tsx"],
24
- extends: [
25
- js.configs.recommended,
26
- tseslint.configs.recommended,
27
- ],
28
- plugins: {
29
- "react-naming-convention": reactNamingConvention,
30
- },
31
- languageOptions: {
32
- parser: tseslint.parser,
33
- parserOptions: {
34
- projectService: true,
35
- tsconfigRootDir: import.meta.dirname,
23
+ export default defineConfig([
24
+ {
25
+ files: ["**/*.ts", "**/*.tsx"],
26
+ extends: [
27
+ js.configs.recommended,
28
+ tseslint.configs.recommended,
29
+ ],
30
+ plugins: {
31
+ "react-naming-convention": reactNamingConvention,
32
+ },
33
+ languageOptions: {
34
+ parser: tseslint.parser,
35
+ parserOptions: {
36
+ projectService: true,
37
+ tsconfigRootDir: import.meta.dirname,
38
+ },
39
+ },
40
+ rules: {
41
+ // Put rules you want to use here
42
+ "react-naming-convention/component-name": "warn",
36
43
  },
37
44
  },
38
- rules: {
39
- // Put rules you want to use here
40
- "react-naming-convention/component-name": "warn",
41
- },
42
- });
45
+ ]);
43
46
  ```
44
47
 
45
48
  ## Rules
package/dist/index.d.ts CHANGED
@@ -1,71 +1,24 @@
1
- import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
- import { RulePreset } from '@eslint-react/kit';
3
-
4
- type MessageID$2 = "missingDestructuring" | "invalidSetterNaming";
5
-
6
- type MessageID$1 = "useJsxFileExtension" | "useNonJsxFileExtension";
7
-
8
- type MessageID = "filenameEmpty" | "filenameInvalid";
1
+ import * as _eslint_react_kit0 from "@eslint-react/kit";
9
2
 
3
+ //#region src/index.d.ts
10
4
  declare const _default: {
11
- configs: {
12
- recommended: {
13
- plugins: {
14
- "react-naming-convention": {
15
- readonly meta: {
16
- readonly name: string;
17
- readonly version: string;
18
- };
19
- readonly rules: {
20
- readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", readonly [("CONSTANT_CASE" | "PascalCase") | {
21
- allowAllCaps?: boolean;
22
- excepts?: readonly string[];
23
- rule?: "CONSTANT_CASE" | "PascalCase";
24
- } | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
25
- readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
26
- readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
27
- excepts?: readonly string[];
28
- rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
29
- } | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
30
- readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("always" | "as-needed") | {
31
- allow?: "always" | "as-needed";
32
- extensions?: readonly string[];
33
- ignoreFilesWithoutCode?: boolean;
34
- } | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
35
- readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$2, [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
36
- };
37
- };
38
- };
39
- name: string;
40
- rules: RulePreset;
41
- };
42
- "recommended-legacy": {
43
- plugins: string[];
44
- rules: RulePreset;
45
- };
5
+ configs: {
6
+ recommended: {
7
+ plugins: {};
8
+ name?: string;
9
+ rules?: Record<string, _eslint_react_kit0.RuleConfig>;
10
+ settings?: _eslint_react_kit0.SettingsConfig;
46
11
  };
47
- meta: {
48
- readonly name: string;
49
- readonly version: string;
50
- };
51
- rules: {
52
- readonly "component-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", readonly [("CONSTANT_CASE" | "PascalCase") | {
53
- allowAllCaps?: boolean;
54
- excepts?: readonly string[];
55
- rule?: "CONSTANT_CASE" | "PascalCase";
56
- } | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
57
- readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"invalid", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
58
- readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
59
- excepts?: readonly string[];
60
- rule?: "PascalCase" | "camelCase" | "kebab-case" | "snake_case";
61
- } | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
62
- readonly "filename-extension": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("always" | "as-needed") | {
63
- allow?: "always" | "as-needed";
64
- extensions?: readonly string[];
65
- ignoreFilesWithoutCode?: boolean;
66
- } | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
67
- readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$2, [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
12
+ "recommended-legacy": {
13
+ plugins: string[];
14
+ rules: Record<string, _eslint_react_kit0.RuleConfig<unknown[]>> | undefined;
68
15
  };
16
+ };
17
+ meta: {
18
+ name: string;
19
+ version: string;
20
+ };
21
+ rules: Record<string, _eslint_react_kit0.CompatibleRule>;
69
22
  };
70
-
71
- export { _default as default };
23
+ //#endregion
24
+ export { _default as default };
package/dist/index.js CHANGED
@@ -1,486 +1,468 @@
1
- import * as AST from '@eslint-react/ast';
2
- import * as ER2 from '@eslint-react/core';
3
- import { RegExp } from '@eslint-react/kit';
4
- import { getDocsUrl, getSettingsFromContext } from '@eslint-react/shared';
5
- import { ESLintUtils } from '@typescript-eslint/utils';
6
- import { identity, isObject } from '@eslint-react/eff';
7
- import { AST_NODE_TYPES } from '@typescript-eslint/types';
8
- import { match, P } from 'ts-pattern';
9
- import path from 'node:path';
10
- import { snakeCase, pascalCase, camelCase, kebabCase } from 'string-ts';
1
+ import { getConfigAdapters, getDocsUrl, getSettingsFromContext } from "@eslint-react/shared";
2
+ import * as AST from "@eslint-react/ast";
3
+ import * as ER from "@eslint-react/core";
4
+ import { RegExp } from "@eslint-react/kit";
5
+ import { ESLintUtils } from "@typescript-eslint/utils";
6
+ import { identity, isObject } from "@eslint-react/eff";
7
+ import { AST_NODE_TYPES } from "@typescript-eslint/types";
8
+ import { P, match } from "ts-pattern";
9
+ import path from "node:path";
10
+ import { camelCase, kebabCase, pascalCase, snakeCase } from "string-ts";
11
11
 
12
+ //#region rolldown:runtime
12
13
  var __defProp = Object.defineProperty;
13
14
  var __export = (target, all) => {
14
- for (var name3 in all)
15
- __defProp(target, name3, { get: all[name3], enumerable: true });
15
+ for (var name$2 in all) __defProp(target, name$2, {
16
+ get: all[name$2],
17
+ enumerable: true
18
+ });
16
19
  };
17
20
 
18
- // src/configs/recommended.ts
21
+ //#endregion
22
+ //#region src/configs/recommended.ts
19
23
  var recommended_exports = {};
20
24
  __export(recommended_exports, {
21
- name: () => name,
22
- rules: () => rules
25
+ name: () => name$1,
26
+ rules: () => rules
23
27
  });
24
- var name = "react-naming-convention/recommended";
25
- var rules = {
26
- "react-naming-convention/context-name": "warn"
27
- // "react-naming-convention/use-state": "warn",
28
- };
28
+ const name$1 = "react-naming-convention/recommended";
29
+ const rules = { "react-naming-convention/context-name": "warn" };
30
+
31
+ //#endregion
32
+ //#region package.json
33
+ var name = "eslint-plugin-react-naming-convention";
34
+ var version = "2.0.0-next.170";
29
35
 
30
- // package.json
31
- var name2 = "eslint-plugin-react-naming-convention";
32
- var version = "2.0.0-next.17";
33
- var createRule = ESLintUtils.RuleCreator(getDocsUrl("naming-convention"));
36
+ //#endregion
37
+ //#region src/utils/create-rule.ts
38
+ const createRule = ESLintUtils.RuleCreator(getDocsUrl("naming-convention"));
34
39
 
35
- // src/rules/component-name.ts
36
- var defaultOptions = [
37
- {
38
- allowAllCaps: false,
39
- excepts: [],
40
- rule: "PascalCase"
41
- }
42
- ];
43
- var schema = [
44
- {
45
- anyOf: [
46
- {
47
- type: "string",
48
- enum: ["PascalCase", "CONSTANT_CASE"]
49
- },
50
- {
51
- type: "object",
52
- additionalProperties: false,
53
- properties: {
54
- allowAllCaps: { type: "boolean" },
55
- excepts: {
56
- type: "array",
57
- items: { type: "string", format: "regex" }
58
- },
59
- rule: {
60
- type: "string",
61
- enum: ["PascalCase", "CONSTANT_CASE"]
62
- }
63
- }
64
- }
65
- ]
66
- }
67
- ];
68
- var RULE_NAME = "component-name";
40
+ //#endregion
41
+ //#region src/rules/component-name.ts
42
+ const defaultOptions$2 = [{
43
+ allowAllCaps: false,
44
+ excepts: [],
45
+ rule: "PascalCase"
46
+ }];
47
+ const schema$2 = [{ anyOf: [{
48
+ type: "string",
49
+ enum: ["PascalCase", "CONSTANT_CASE"]
50
+ }, {
51
+ type: "object",
52
+ additionalProperties: false,
53
+ properties: {
54
+ allowAllCaps: { type: "boolean" },
55
+ excepts: {
56
+ type: "array",
57
+ items: {
58
+ type: "string",
59
+ format: "regex"
60
+ }
61
+ },
62
+ rule: {
63
+ type: "string",
64
+ enum: ["PascalCase", "CONSTANT_CASE"]
65
+ }
66
+ }
67
+ }] }];
68
+ const RULE_NAME$4 = "component-name";
69
69
  var component_name_default = createRule({
70
- meta: {
71
- type: "problem",
72
- defaultOptions: [...defaultOptions],
73
- docs: {
74
- description: "Enforces naming conventions for components."
75
- },
76
- messages: {
77
- invalid: "A component name '{{name}}' does not match {{rule}}."
78
- },
79
- schema
80
- },
81
- name: RULE_NAME,
82
- create,
83
- defaultOptions
70
+ meta: {
71
+ type: "problem",
72
+ defaultOptions: [...defaultOptions$2],
73
+ docs: { description: "Enforces naming conventions for components." },
74
+ messages: { invalidComponentName: "A component name '{{name}}' does not match {{rule}}." },
75
+ schema: schema$2
76
+ },
77
+ name: RULE_NAME$4,
78
+ create: create$4,
79
+ defaultOptions: defaultOptions$2
84
80
  });
85
- function create(context) {
86
- const options = normalizeOptions(context.options);
87
- const { rule } = options;
88
- const collector = ER2.useComponentCollector(context);
89
- const collectorLegacy = ER2.useComponentCollectorLegacy();
90
- return {
91
- ...collector.listeners,
92
- ...collectorLegacy.listeners,
93
- "Program:exit"(program) {
94
- const functionComponents = collector.ctx.getAllComponents(program);
95
- const classComponents = collectorLegacy.ctx.getAllComponents(program);
96
- for (const { node: component } of functionComponents.values()) {
97
- const id = AST.getFunctionId(component);
98
- if (id?.name == null) continue;
99
- const name3 = id.name;
100
- if (isValidName(name3, options)) return;
101
- context.report({
102
- messageId: "invalid",
103
- node: id,
104
- data: { name: name3, rule }
105
- });
106
- }
107
- for (const { node: component } of classComponents.values()) {
108
- const id = AST.getClassId(component);
109
- if (id?.name == null) continue;
110
- const name3 = id.name;
111
- if (isValidName(name3, options)) continue;
112
- context.report({
113
- messageId: "invalid",
114
- node: id,
115
- data: { name: name3, rule }
116
- });
117
- }
118
- }
119
- };
81
+ function create$4(context) {
82
+ const options = normalizeOptions(context.options);
83
+ const { rule } = options;
84
+ const collector = ER.useComponentCollector(context);
85
+ const collectorLegacy = ER.useComponentCollectorLegacy();
86
+ return {
87
+ ...collector.listeners,
88
+ ...collectorLegacy.listeners,
89
+ "Program:exit"(program) {
90
+ const functionComponents = collector.ctx.getAllComponents(program);
91
+ const classComponents = collectorLegacy.ctx.getAllComponents(program);
92
+ for (const { node: component } of functionComponents.values()) {
93
+ const id = AST.getFunctionId(component);
94
+ if (id?.name == null) continue;
95
+ const name$2 = id.name;
96
+ if (isValidName(name$2, options)) continue;
97
+ context.report({
98
+ messageId: "invalidComponentName",
99
+ node: id,
100
+ data: {
101
+ name: name$2,
102
+ rule
103
+ }
104
+ });
105
+ }
106
+ for (const { node: component } of classComponents.values()) {
107
+ const id = AST.getClassId(component);
108
+ if (id?.name == null) continue;
109
+ const name$2 = id.name;
110
+ if (isValidName(name$2, options)) continue;
111
+ context.report({
112
+ messageId: "invalidComponentName",
113
+ node: id,
114
+ data: {
115
+ name: name$2,
116
+ rule
117
+ }
118
+ });
119
+ }
120
+ }
121
+ };
120
122
  }
121
123
  function normalizeOptions(options) {
122
- const opts = options[0];
123
- const defaultOpts = defaultOptions[0];
124
- if (opts == null) return defaultOpts;
125
- return {
126
- ...defaultOpts,
127
- ...typeof opts === "string" ? { rule: opts } : {
128
- ...opts,
129
- excepts: opts.excepts?.map((s) => RegExp.toRegExp(s)) ?? []
130
- }
131
- };
124
+ const opts = options[0];
125
+ const defaultOpts = defaultOptions$2[0];
126
+ if (opts == null) return defaultOpts;
127
+ return {
128
+ ...defaultOpts,
129
+ ...typeof opts === "string" ? { rule: opts } : {
130
+ ...opts,
131
+ excepts: opts.excepts?.map((s) => RegExp.toRegExp(s)) ?? []
132
+ }
133
+ };
132
134
  }
133
- function isValidName(name3, options) {
134
- if (name3 == null) return true;
135
- if (options.excepts.some((regex) => regex.test(name3))) return true;
136
- const normalized = name3.split(".").at(-1) ?? name3;
137
- switch (options.rule) {
138
- case "CONSTANT_CASE":
139
- return RegExp.CONSTANT_CASE.test(normalized);
140
- case "PascalCase":
141
- if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) {
142
- return options.allowAllCaps;
143
- }
144
- return RegExp.PASCAL_CASE.test(normalized);
145
- }
135
+ function isValidName(name$2, options) {
136
+ if (name$2 == null) return true;
137
+ if (options.excepts.some((regex) => regex.test(name$2))) return true;
138
+ const normalized = name$2.split(".").at(-1) ?? name$2;
139
+ switch (options.rule) {
140
+ case "CONSTANT_CASE": return RegExp.CONSTANT_CASE.test(normalized);
141
+ case "PascalCase":
142
+ if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) return options.allowAllCaps;
143
+ return RegExp.PASCAL_CASE.test(normalized);
144
+ }
146
145
  }
147
- var RULE_NAME2 = "context-name";
146
+
147
+ //#endregion
148
+ //#region src/rules/context-name.ts
149
+ const RULE_NAME$3 = "context-name";
148
150
  var context_name_default = createRule({
149
- meta: {
150
- type: "problem",
151
- docs: {
152
- description: "Enforces context name to be a valid component name with the suffix `Context`."
153
- },
154
- messages: {
155
- invalid: "A context name must be a valid component name with the suffix 'Context'."
156
- },
157
- schema: []
158
- },
159
- name: RULE_NAME2,
160
- create: create2,
161
- defaultOptions: []
151
+ meta: {
152
+ type: "problem",
153
+ docs: { description: "Enforces context name to be a valid component name with the suffix `Context`." },
154
+ messages: { invalidContextName: "A context name must be a valid component name with the suffix 'Context'." },
155
+ schema: []
156
+ },
157
+ name: RULE_NAME$3,
158
+ create: create$3,
159
+ defaultOptions: []
162
160
  });
163
- function create2(context) {
164
- if (!context.sourceCode.text.includes("createContext")) return {};
165
- return {
166
- CallExpression(node) {
167
- if (!ER2.isCreateContextCall(context, node)) return;
168
- const id = ER2.getInstanceId(node);
169
- if (id == null) return;
170
- const name3 = match(id).with({ type: AST_NODE_TYPES.Identifier, name: P.select() }, identity).with({ type: AST_NODE_TYPES.MemberExpression, property: { name: P.select(P.string) } }, identity).otherwise(() => null);
171
- if (name3 != null && ER2.isComponentName(name3) && name3.endsWith("Context")) return;
172
- context.report({
173
- messageId: "invalid",
174
- node: id
175
- });
176
- }
177
- };
161
+ function create$3(context) {
162
+ if (!context.sourceCode.text.includes("createContext")) return {};
163
+ return { CallExpression(node) {
164
+ if (!ER.isCreateContextCall(context, node)) return;
165
+ const id = ER.getInstanceId(node);
166
+ if (id == null) return;
167
+ const name$2 = match(id).with({
168
+ type: AST_NODE_TYPES.Identifier,
169
+ name: P.select()
170
+ }, identity).with({
171
+ type: AST_NODE_TYPES.MemberExpression,
172
+ property: { name: P.select(P.string) }
173
+ }, identity).otherwise(() => null);
174
+ if (name$2 != null && ER.isComponentName(name$2) && name$2.endsWith("Context")) return;
175
+ context.report({
176
+ messageId: "invalidContextName",
177
+ node: id
178
+ });
179
+ } };
178
180
  }
179
- var RULE_NAME3 = "filename";
180
- var defaultOptions2 = [
181
- {
182
- excepts: ["^index$"],
183
- rule: "PascalCase"
184
- }
185
- ];
186
- var schema2 = [
187
- {
188
- anyOf: [
189
- {
190
- type: "string",
191
- enum: ["PascalCase", "camelCase", "kebab-case", "snake_case"]
192
- },
193
- {
194
- type: "object",
195
- additionalProperties: false,
196
- properties: {
197
- excepts: {
198
- type: "array",
199
- items: { type: "string", format: "regex" }
200
- },
201
- extensions: {
202
- type: "array",
203
- items: { type: "string" },
204
- uniqueItems: true
205
- },
206
- rule: {
207
- type: "string",
208
- enum: ["PascalCase", "camelCase", "kebab-case", "snake_case"]
209
- }
210
- }
211
- }
212
- ]
213
- }
214
- ];
181
+
182
+ //#endregion
183
+ //#region src/rules/filename.ts
184
+ const RULE_NAME$2 = "filename";
185
+ const defaultOptions$1 = [{
186
+ excepts: [
187
+ "index",
188
+ String.raw`/^_/`,
189
+ String.raw`/^\$/`,
190
+ String.raw`/^[0-9]+$/`,
191
+ String.raw`/^\[[^\]]+\]$/`
192
+ ],
193
+ rule: "PascalCase"
194
+ }];
195
+ const schema$1 = [{ anyOf: [{
196
+ type: "string",
197
+ enum: [
198
+ "PascalCase",
199
+ "camelCase",
200
+ "kebab-case",
201
+ "snake_case"
202
+ ]
203
+ }, {
204
+ type: "object",
205
+ additionalProperties: false,
206
+ properties: {
207
+ excepts: {
208
+ type: "array",
209
+ items: {
210
+ type: "string",
211
+ format: "regex"
212
+ }
213
+ },
214
+ extensions: {
215
+ type: "array",
216
+ items: { type: "string" },
217
+ uniqueItems: true
218
+ },
219
+ rule: {
220
+ type: "string",
221
+ enum: [
222
+ "PascalCase",
223
+ "camelCase",
224
+ "kebab-case",
225
+ "snake_case"
226
+ ]
227
+ }
228
+ }
229
+ }] }];
215
230
  var filename_default = createRule({
216
- meta: {
217
- type: "problem",
218
- defaultOptions: [...defaultOptions2],
219
- docs: {
220
- description: "Enforces consistent file naming conventions."
221
- },
222
- messages: {
223
- filenameEmpty: "A file must have non-empty name.",
224
- filenameInvalid: "A file with name '{{name}}' does not match {{rule}}. Rename it to '{{suggestion}}'."
225
- },
226
- schema: schema2
227
- },
228
- name: RULE_NAME3,
229
- create: create3,
230
- defaultOptions: defaultOptions2
231
+ meta: {
232
+ type: "problem",
233
+ defaultOptions: [...defaultOptions$1],
234
+ docs: { description: "Enforces consistent file naming conventions." },
235
+ messages: {
236
+ empty: "A file must have non-empty name.",
237
+ invalidCase: "A file with name '{{name}}' does not match {{rule}}. Rename it to '{{suggestion}}'."
238
+ },
239
+ schema: schema$1
240
+ },
241
+ name: RULE_NAME$2,
242
+ create: create$2,
243
+ defaultOptions: defaultOptions$1
231
244
  });
232
- function create3(context) {
233
- const options = context.options[0] ?? defaultOptions2[0];
234
- const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
235
- const excepts = typeof options === "string" ? [] : (options.excepts ?? []).map((s) => RegExp.toRegExp(s));
236
- function validate(name3, casing = rule, ignores = excepts) {
237
- const shouldIgnore = ignores.some((pattern) => pattern.test(name3));
238
- if (shouldIgnore) return true;
239
- return match(casing).with("PascalCase", () => RegExp.PASCAL_CASE.test(name3)).with("camelCase", () => RegExp.CAMEL_CASE.test(name3)).with("kebab-case", () => RegExp.KEBAB_CASE.test(name3)).with("snake_case", () => RegExp.SNAKE_CASE.test(name3)).exhaustive();
240
- }
241
- function getSuggestion(name3, casing = rule) {
242
- return match(casing).with("PascalCase", () => pascalCase(name3)).with("camelCase", () => camelCase(name3)).with("kebab-case", () => kebabCase(name3)).with("snake_case", () => snakeCase(name3)).exhaustive();
243
- }
244
- return {
245
- Program(node) {
246
- const [basename = "", ...rest] = path.basename(context.filename).split(".");
247
- if (basename.length === 0) {
248
- context.report({ messageId: "filenameEmpty", node });
249
- return;
250
- }
251
- if (validate(basename)) {
252
- return;
253
- }
254
- context.report({
255
- messageId: "filenameInvalid",
256
- node,
257
- data: {
258
- name: context.filename,
259
- rule,
260
- suggestion: [getSuggestion(basename), ...rest].join(".")
261
- }
262
- });
263
- }
264
- };
245
+ function create$2(context) {
246
+ const options = context.options[0] ?? defaultOptions$1[0];
247
+ const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
248
+ const excepts = typeof options === "string" ? [] : (options.excepts ?? []).map((s) => RegExp.toRegExp(s));
249
+ function validate(name$2, casing = rule, ignores = excepts) {
250
+ if (ignores.some((pattern) => pattern.test(name$2))) return true;
251
+ const filteredName = name$2.match(/[\w.-]/gu)?.join("") ?? "";
252
+ if (filteredName.length === 0) return true;
253
+ return match(casing).with("PascalCase", () => RegExp.PASCAL_CASE.test(filteredName)).with("camelCase", () => RegExp.CAMEL_CASE.test(filteredName)).with("kebab-case", () => RegExp.KEBAB_CASE.test(filteredName)).with("snake_case", () => RegExp.SNAKE_CASE.test(filteredName)).exhaustive();
254
+ }
255
+ function getSuggestion(name$2, casing = rule) {
256
+ return match(casing).with("PascalCase", () => pascalCase(name$2)).with("camelCase", () => camelCase(name$2)).with("kebab-case", () => kebabCase(name$2)).with("snake_case", () => snakeCase(name$2)).exhaustive();
257
+ }
258
+ return { Program(node) {
259
+ const [basename = "", ...rest] = path.basename(context.filename).split(".");
260
+ if (basename.length === 0) {
261
+ context.report({
262
+ messageId: "empty",
263
+ node
264
+ });
265
+ return;
266
+ }
267
+ if (validate(basename)) return;
268
+ context.report({
269
+ messageId: "invalidCase",
270
+ node,
271
+ data: {
272
+ name: context.filename,
273
+ rule,
274
+ suggestion: [getSuggestion(basename), ...rest].join(".")
275
+ }
276
+ });
277
+ } };
265
278
  }
266
- var RULE_NAME4 = "filename-extension";
267
- var defaultOptions3 = [{
268
- allow: "as-needed",
269
- extensions: [".jsx", ".tsx"],
270
- ignoreFilesWithoutCode: false
279
+
280
+ //#endregion
281
+ //#region src/rules/filename-extension.ts
282
+ const RULE_NAME$1 = "filename-extension";
283
+ const defaultOptions = [{
284
+ allow: "as-needed",
285
+ extensions: [".jsx", ".tsx"],
286
+ ignoreFilesWithoutCode: false
271
287
  }];
272
- var schema3 = [
273
- {
274
- anyOf: [
275
- {
276
- type: "string",
277
- enum: ["always", "as-needed"]
278
- },
279
- {
280
- type: "object",
281
- additionalProperties: false,
282
- properties: {
283
- allow: {
284
- type: "string",
285
- enum: ["always", "as-needed"]
286
- },
287
- extensions: {
288
- type: "array",
289
- items: {
290
- type: "string"
291
- },
292
- uniqueItems: true
293
- },
294
- ignoreFilesWithoutCode: {
295
- type: "boolean"
296
- }
297
- }
298
- }
299
- ]
300
- }
301
- ];
288
+ const schema = [{ anyOf: [{
289
+ type: "string",
290
+ enum: ["always", "as-needed"]
291
+ }, {
292
+ type: "object",
293
+ additionalProperties: false,
294
+ properties: {
295
+ allow: {
296
+ type: "string",
297
+ enum: ["always", "as-needed"]
298
+ },
299
+ extensions: {
300
+ type: "array",
301
+ items: { type: "string" },
302
+ uniqueItems: true
303
+ },
304
+ ignoreFilesWithoutCode: { type: "boolean" }
305
+ }
306
+ }] }];
302
307
  var filename_extension_default = createRule({
303
- meta: {
304
- type: "problem",
305
- defaultOptions: [...defaultOptions3],
306
- docs: {
307
- description: "Enforces consistent file naming conventions."
308
- },
309
- messages: {
310
- useJsxFileExtension: "Use {{extensions}} file extension for JSX files.",
311
- useNonJsxFileExtension: "Do not use {{extensions}} file extension for files without JSX."
312
- },
313
- schema: schema3
314
- },
315
- name: RULE_NAME4,
316
- create: create4,
317
- defaultOptions: defaultOptions3
308
+ meta: {
309
+ type: "problem",
310
+ defaultOptions: [...defaultOptions],
311
+ docs: { description: "Enforces consistent file naming conventions." },
312
+ messages: {
313
+ missingJSXExtension: "Use {{extensions}} file extension for JSX files.",
314
+ unnecessaryJSXExtension: "Do not use {{extensions}} file extension for files without JSX."
315
+ },
316
+ schema
317
+ },
318
+ name: RULE_NAME$1,
319
+ create: create$1,
320
+ defaultOptions
318
321
  });
319
- function create4(context) {
320
- const options = context.options[0] ?? defaultOptions3[0];
321
- const allow = isObject(options) ? options.allow : options;
322
- const extensions = isObject(options) && "extensions" in options ? options.extensions : defaultOptions3[0].extensions;
323
- const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
324
- const filename = context.filename;
325
- let hasJSXNode = false;
326
- return {
327
- JSXElement() {
328
- hasJSXNode = true;
329
- },
330
- JSXFragment() {
331
- hasJSXNode = true;
332
- },
333
- "Program:exit"(program) {
334
- const fileNameExt = filename.slice(filename.lastIndexOf("."));
335
- const isJSXExt = extensions.includes(fileNameExt);
336
- if (hasJSXNode && !isJSXExt) {
337
- context.report({
338
- messageId: "useJsxFileExtension",
339
- node: program,
340
- data: {
341
- extensions: extensionsString
342
- }
343
- });
344
- return;
345
- }
346
- const hasCode = program.body.length > 0;
347
- const ignoreFilesWithoutCode = isObject(options) && options.ignoreFilesWithoutCode === true;
348
- if (!hasCode && ignoreFilesWithoutCode) {
349
- return;
350
- }
351
- if (!hasJSXNode && isJSXExt && allow === "as-needed") {
352
- context.report({
353
- messageId: "useNonJsxFileExtension",
354
- node: program,
355
- data: {
356
- extensions: extensionsString
357
- }
358
- });
359
- }
360
- }
361
- };
322
+ function create$1(context) {
323
+ const options = context.options[0] ?? defaultOptions[0];
324
+ const allow = isObject(options) ? options.allow : options;
325
+ const extensions = isObject(options) && "extensions" in options ? options.extensions : defaultOptions[0].extensions;
326
+ const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
327
+ const filename = context.filename;
328
+ let hasJSXNode = false;
329
+ return {
330
+ JSXElement() {
331
+ hasJSXNode = true;
332
+ },
333
+ JSXFragment() {
334
+ hasJSXNode = true;
335
+ },
336
+ "Program:exit"(program) {
337
+ const fileNameExt = filename.slice(filename.lastIndexOf("."));
338
+ const isJSXExt = extensions.includes(fileNameExt);
339
+ if (hasJSXNode && !isJSXExt) {
340
+ context.report({
341
+ messageId: "missingJSXExtension",
342
+ node: program,
343
+ data: { extensions: extensionsString }
344
+ });
345
+ return;
346
+ }
347
+ const hasCode = program.body.length > 0;
348
+ const ignoreFilesWithoutCode = isObject(options) && options.ignoreFilesWithoutCode === true;
349
+ if (!hasCode && ignoreFilesWithoutCode) return;
350
+ if (!hasJSXNode && isJSXExt && allow === "as-needed") context.report({
351
+ messageId: "unnecessaryJSXExtension",
352
+ node: program,
353
+ data: { extensions: extensionsString }
354
+ });
355
+ }
356
+ };
362
357
  }
363
- var RULE_NAME5 = "use-state";
364
- var RULE_FEATURES = [];
358
+
359
+ //#endregion
360
+ //#region src/rules/use-state.ts
361
+ const RULE_NAME = "use-state";
362
+ const RULE_FEATURES = [];
365
363
  var use_state_default = createRule({
366
- meta: {
367
- type: "problem",
368
- docs: {
369
- description: "Enforces destructuring and symmetric naming of `useState` hook value and setter.",
370
- [Symbol.for("rule_features")]: RULE_FEATURES
371
- },
372
- messages: {
373
- invalidSetterNaming: "The setter should be named 'set' followed by the capitalized state variable name, e.g., 'setState' for 'state'.",
374
- missingDestructuring: "useState should be destructured into a value and setter pair, e.g., const [state, setState] = useState(...)."
375
- },
376
- schema: []
377
- },
378
- name: RULE_NAME5,
379
- create: create5,
380
- defaultOptions: []
364
+ meta: {
365
+ type: "problem",
366
+ docs: {
367
+ description: "Enforces destructuring and symmetric naming of `useState` hook value and setter.",
368
+ [Symbol.for("rule_features")]: RULE_FEATURES
369
+ },
370
+ messages: {
371
+ invalidAssignment: "useState should be destructured into a value and setter pair, e.g., const [state, setState] = useState(...).",
372
+ invalidSetterName: "The setter should be named 'set' followed by the capitalized state variable name, e.g., 'setState' for 'state'."
373
+ },
374
+ schema: []
375
+ },
376
+ name: RULE_NAME,
377
+ create,
378
+ defaultOptions: []
381
379
  });
382
- function create5(context) {
383
- const alias = getSettingsFromContext(context).additionalHooks.useState ?? [];
384
- const isUseStateCall = ER2.isReactHookCallWithNameAlias(context, "useState", alias);
385
- return {
386
- CallExpression(node) {
387
- if (!isUseStateCall(node)) {
388
- return;
389
- }
390
- if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
391
- context.report({
392
- messageId: "missingDestructuring",
393
- node
394
- });
395
- return;
396
- }
397
- const id = ER2.getInstanceId(node);
398
- if (id?.type !== AST_NODE_TYPES.ArrayPattern) {
399
- context.report({
400
- messageId: "missingDestructuring",
401
- node: id ?? node
402
- });
403
- return;
404
- }
405
- const [value, setter] = id.elements;
406
- if (value == null || setter == null) {
407
- context.report({
408
- messageId: "missingDestructuring",
409
- node: id
410
- });
411
- return;
412
- }
413
- const setterName = match(setter).with({ type: AST_NODE_TYPES.Identifier }, (id2) => id2.name).otherwise(() => null);
414
- if (setterName == null || !setterName.startsWith("set")) {
415
- context.report({
416
- messageId: "invalidSetterNaming",
417
- node: setter
418
- });
419
- return;
420
- }
421
- const valueName = match(value).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name3 }) => snakeCase(name3)).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
422
- const values = properties.reduce((acc, prop) => {
423
- if (prop.type === AST_NODE_TYPES.Property && prop.key.type === AST_NODE_TYPES.Identifier) {
424
- return [...acc, prop.key.name];
425
- }
426
- return acc;
427
- }, []);
428
- return values.join("_");
429
- }).otherwise(() => null);
430
- if (valueName == null) {
431
- context.report({
432
- messageId: "invalidSetterNaming",
433
- node: value
434
- });
435
- return;
436
- }
437
- if (snakeCase(setterName) !== `set_${valueName}`) {
438
- context.report({
439
- messageId: "invalidSetterNaming",
440
- node: setter
441
- });
442
- return;
443
- }
444
- }
445
- };
380
+ function create(context) {
381
+ const alias = getSettingsFromContext(context).additionalHooks.useState ?? [];
382
+ const isUseStateCall = ER.isReactHookCallWithNameAlias(context, "useState", alias);
383
+ return { CallExpression(node) {
384
+ if (!isUseStateCall(node)) return;
385
+ if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
386
+ context.report({
387
+ messageId: "invalidAssignment",
388
+ node
389
+ });
390
+ return;
391
+ }
392
+ const id = ER.getInstanceId(node);
393
+ if (id?.type !== AST_NODE_TYPES.ArrayPattern) {
394
+ context.report({
395
+ messageId: "invalidAssignment",
396
+ node: id ?? node
397
+ });
398
+ return;
399
+ }
400
+ const [value, setter] = id.elements;
401
+ if (value == null || setter == null) {
402
+ context.report({
403
+ messageId: "invalidAssignment",
404
+ node: id
405
+ });
406
+ return;
407
+ }
408
+ const setterName = match(setter).with({ type: AST_NODE_TYPES.Identifier }, (id$1) => id$1.name).otherwise(() => null);
409
+ if (setterName == null || !setterName.startsWith("set")) {
410
+ context.report({
411
+ messageId: "invalidSetterName",
412
+ node: setter
413
+ });
414
+ return;
415
+ }
416
+ const valueName = match(value).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name$2 }) => snakeCase(name$2)).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
417
+ const values = properties.reduce((acc, prop) => {
418
+ if (prop.type === AST_NODE_TYPES.Property && prop.key.type === AST_NODE_TYPES.Identifier) return [...acc, prop.key.name];
419
+ return acc;
420
+ }, []);
421
+ return values.join("_");
422
+ }).otherwise(() => null);
423
+ if (valueName == null) {
424
+ context.report({
425
+ messageId: "invalidSetterName",
426
+ node: value
427
+ });
428
+ return;
429
+ }
430
+ if (snakeCase(setterName) !== `set_${valueName}`) {
431
+ context.report({
432
+ messageId: "invalidSetterName",
433
+ node: setter
434
+ });
435
+ return;
436
+ }
437
+ } };
446
438
  }
447
439
 
448
- // src/plugin.ts
449
- var plugin = {
450
- meta: {
451
- name: name2,
452
- version
453
- },
454
- rules: {
455
- ["component-name"]: component_name_default,
456
- ["context-name"]: context_name_default,
457
- ["filename"]: filename_default,
458
- ["filename-extension"]: filename_extension_default,
459
- ["use-state"]: use_state_default
460
- }
440
+ //#endregion
441
+ //#region src/plugin.ts
442
+ const plugin = {
443
+ meta: {
444
+ name,
445
+ version
446
+ },
447
+ rules: {
448
+ ["component-name"]: component_name_default,
449
+ ["context-name"]: context_name_default,
450
+ ["filename"]: filename_default,
451
+ ["filename-extension"]: filename_extension_default,
452
+ ["use-state"]: use_state_default
453
+ }
461
454
  };
462
455
 
463
- // src/index.ts
464
- function makeConfig(config) {
465
- return {
466
- ...config,
467
- plugins: {
468
- "react-naming-convention": plugin
469
- }
470
- };
471
- }
472
- function makeLegacyConfig({ rules: rules2 }) {
473
- return {
474
- plugins: ["react-naming-convention"],
475
- rules: rules2
476
- };
477
- }
478
- var index_default = {
479
- ...plugin,
480
- configs: {
481
- ["recommended"]: makeConfig(recommended_exports),
482
- ["recommended-legacy"]: makeLegacyConfig(recommended_exports)
483
- }
456
+ //#endregion
457
+ //#region src/index.ts
458
+ const { toFlatConfig, toLegacyConfig } = getConfigAdapters("react-naming-convention", plugin);
459
+ var src_default = {
460
+ ...plugin,
461
+ configs: {
462
+ ["recommended"]: toFlatConfig(recommended_exports),
463
+ ["recommended-legacy"]: toLegacyConfig(recommended_exports)
464
+ }
484
465
  };
485
466
 
486
- export { index_default as default };
467
+ //#endregion
468
+ export { src_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-naming-convention",
3
- "version": "2.0.0-next.17",
3
+ "version": "2.0.0-next.170",
4
4
  "description": "ESLint React's ESLint plugin for naming convention related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -35,27 +35,27 @@
35
35
  "./package.json"
36
36
  ],
37
37
  "dependencies": {
38
- "@typescript-eslint/scope-manager": "^8.32.0",
39
- "@typescript-eslint/type-utils": "^8.32.0",
40
- "@typescript-eslint/types": "^8.32.0",
41
- "@typescript-eslint/utils": "^8.32.0",
38
+ "@typescript-eslint/scope-manager": "^8.42.0",
39
+ "@typescript-eslint/type-utils": "^8.42.0",
40
+ "@typescript-eslint/types": "^8.42.0",
41
+ "@typescript-eslint/utils": "^8.42.0",
42
42
  "string-ts": "^2.2.1",
43
- "ts-pattern": "^5.7.0",
44
- "@eslint-react/ast": "2.0.0-next.17",
45
- "@eslint-react/core": "2.0.0-next.17",
46
- "@eslint-react/kit": "2.0.0-next.17",
47
- "@eslint-react/eff": "2.0.0-next.17",
48
- "@eslint-react/var": "2.0.0-next.17",
49
- "@eslint-react/shared": "2.0.0-next.17"
43
+ "ts-pattern": "^5.8.0",
44
+ "@eslint-react/ast": "2.0.0-next.170",
45
+ "@eslint-react/core": "2.0.0-next.170",
46
+ "@eslint-react/kit": "2.0.0-next.170",
47
+ "@eslint-react/shared": "2.0.0-next.170",
48
+ "@eslint-react/var": "2.0.0-next.170",
49
+ "@eslint-react/eff": "2.0.0-next.170"
50
50
  },
51
51
  "devDependencies": {
52
- "@types/react": "^19.1.3",
53
- "@types/react-dom": "^19.1.3",
54
- "tsup": "^8.4.0",
52
+ "@types/react": "^19.1.12",
53
+ "@types/react-dom": "^19.1.9",
54
+ "tsdown": "^0.14.2",
55
55
  "@local/configs": "0.0.0"
56
56
  },
57
57
  "peerDependencies": {
58
- "eslint": "^9.26.0",
58
+ "eslint": "^9.35.0",
59
59
  "typescript": "^4.9.5 || ^5.4.5"
60
60
  },
61
61
  "peerDependenciesMeta": {
@@ -67,14 +67,13 @@
67
67
  }
68
68
  },
69
69
  "engines": {
70
- "bun": ">=1.0.15",
71
70
  "node": ">=20.19.0"
72
71
  },
73
72
  "publishConfig": {
74
73
  "access": "public"
75
74
  },
76
75
  "scripts": {
77
- "build": "tsup --dts-resolve",
76
+ "build": "tsdown",
78
77
  "lint:publish": "publint",
79
78
  "lint:ts": "tsc --noEmit"
80
79
  }