eslint-plugin-react-naming-convention 3.0.0-beta.7 → 3.0.0-beta.70
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 +1 -1
- package/dist/index.d.ts +5 -16
- package/dist/index.js +45 -243
- package/package.json +9 -8
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ESLint, Linter } from "eslint";
|
|
2
2
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
plugins: {};
|
|
8
|
-
name?: string;
|
|
9
|
-
rules?: Record<string, _eslint_react_shared0.RuleConfig>;
|
|
10
|
-
settings?: _eslint_react_shared0.SettingsConfig;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
meta: {
|
|
14
|
-
name: string;
|
|
15
|
-
version: string;
|
|
16
|
-
};
|
|
17
|
-
rules: Record<string, _eslint_react_shared0.CompatibleRule>;
|
|
4
|
+
type ConfigName = "recommended";
|
|
5
|
+
declare const finalPlugin: ESLint.Plugin & {
|
|
6
|
+
configs: Record<ConfigName, Linter.Config>;
|
|
18
7
|
};
|
|
19
8
|
//#endregion
|
|
20
|
-
export {
|
|
9
|
+
export { finalPlugin as default };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { RE_CONSTANT_CASE, RE_PASCAL_CASE, WEBSITE_URL, defineRuleListener, getConfigAdapters, getSettingsFromContext, toRegExp } from "@eslint-react/shared";
|
|
2
1
|
import * as core from "@eslint-react/core";
|
|
3
|
-
import {
|
|
2
|
+
import { WEBSITE_URL, defineRuleListener } from "@eslint-react/shared";
|
|
4
3
|
import { findEnclosingAssignmentTarget } from "@eslint-react/var";
|
|
5
4
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
6
|
-
import { compare } from "compare-versions";
|
|
7
5
|
import { P, match } from "ts-pattern";
|
|
6
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
8
7
|
import * as ast from "@eslint-react/ast";
|
|
9
|
-
import { snakeCase } from "string-ts";
|
|
10
8
|
|
|
11
9
|
//#region \0rolldown/runtime.js
|
|
12
10
|
var __defProp = Object.defineProperty;
|
|
@@ -24,24 +22,10 @@ var __exportAll = (all, no_symbols) => {
|
|
|
24
22
|
return target;
|
|
25
23
|
};
|
|
26
24
|
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/configs/recommended.ts
|
|
29
|
-
var recommended_exports = /* @__PURE__ */ __exportAll({
|
|
30
|
-
name: () => name$1,
|
|
31
|
-
rules: () => rules
|
|
32
|
-
});
|
|
33
|
-
const name$1 = "react-naming-convention/recommended";
|
|
34
|
-
const rules = {
|
|
35
|
-
"react-naming-convention/context-name": "warn",
|
|
36
|
-
"react-naming-convention/id-name": "warn",
|
|
37
|
-
"react-naming-convention/ref-name": "warn",
|
|
38
|
-
"react-naming-convention/use-state": "warn"
|
|
39
|
-
};
|
|
40
|
-
|
|
41
25
|
//#endregion
|
|
42
26
|
//#region package.json
|
|
43
|
-
var name = "eslint-plugin-react-naming-convention";
|
|
44
|
-
var version = "3.0.0-beta.
|
|
27
|
+
var name$1 = "eslint-plugin-react-naming-convention";
|
|
28
|
+
var version = "3.0.0-beta.70";
|
|
45
29
|
|
|
46
30
|
//#endregion
|
|
47
31
|
//#region src/utils/create-rule.ts
|
|
@@ -51,103 +35,8 @@ function getDocsUrl(ruleName) {
|
|
|
51
35
|
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
52
36
|
|
|
53
37
|
//#endregion
|
|
54
|
-
//#region src/rules/
|
|
55
|
-
const
|
|
56
|
-
allowAllCaps: false,
|
|
57
|
-
excepts: [],
|
|
58
|
-
rule: "PascalCase"
|
|
59
|
-
}];
|
|
60
|
-
const schema$1 = [{ anyOf: [{
|
|
61
|
-
type: "string",
|
|
62
|
-
enum: ["PascalCase", "CONSTANT_CASE"]
|
|
63
|
-
}, {
|
|
64
|
-
type: "object",
|
|
65
|
-
additionalProperties: false,
|
|
66
|
-
properties: {
|
|
67
|
-
allowAllCaps: { type: "boolean" },
|
|
68
|
-
excepts: {
|
|
69
|
-
type: "array",
|
|
70
|
-
items: {
|
|
71
|
-
type: "string",
|
|
72
|
-
format: "regex"
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
rule: {
|
|
76
|
-
type: "string",
|
|
77
|
-
enum: ["PascalCase", "CONSTANT_CASE"]
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}] }];
|
|
81
|
-
const RULE_NAME$4 = "component-name";
|
|
82
|
-
var component_name_default = createRule({
|
|
83
|
-
meta: {
|
|
84
|
-
type: "problem",
|
|
85
|
-
defaultOptions: [...defaultOptions$1],
|
|
86
|
-
docs: { description: "Enforces naming conventions for components." },
|
|
87
|
-
messages: { invalidComponentName: "A component name '{{name}}' does not match {{rule}}." },
|
|
88
|
-
schema: schema$1
|
|
89
|
-
},
|
|
90
|
-
name: RULE_NAME$4,
|
|
91
|
-
create: create$4,
|
|
92
|
-
defaultOptions: defaultOptions$1
|
|
93
|
-
});
|
|
94
|
-
function create$4(context) {
|
|
95
|
-
const options = normalizeOptions(context.options);
|
|
96
|
-
const { rule } = options;
|
|
97
|
-
const fCollector = core.useComponentCollector(context);
|
|
98
|
-
const cCollector = core.useComponentCollectorLegacy(context);
|
|
99
|
-
return defineRuleListener(fCollector.visitor, cCollector.visitor, { "Program:exit"(program) {
|
|
100
|
-
for (const { id, name, node: component } of fCollector.ctx.getAllComponents(program)) {
|
|
101
|
-
if (isValidName(name, options)) continue;
|
|
102
|
-
context.report({
|
|
103
|
-
messageId: "invalidComponentName",
|
|
104
|
-
node: id ?? component,
|
|
105
|
-
data: {
|
|
106
|
-
name,
|
|
107
|
-
rule
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
for (const { id, name, node } of cCollector.ctx.getAllComponents(program)) {
|
|
112
|
-
if (isValidName(name, options)) continue;
|
|
113
|
-
context.report({
|
|
114
|
-
messageId: "invalidComponentName",
|
|
115
|
-
node: id ?? node,
|
|
116
|
-
data: {
|
|
117
|
-
name,
|
|
118
|
-
rule
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
} });
|
|
123
|
-
}
|
|
124
|
-
function normalizeOptions(options) {
|
|
125
|
-
const opts = options[0];
|
|
126
|
-
const defaultOpts = defaultOptions$1[0];
|
|
127
|
-
if (opts == null) return defaultOpts;
|
|
128
|
-
return {
|
|
129
|
-
...defaultOpts,
|
|
130
|
-
...typeof opts === "string" ? { rule: opts } : {
|
|
131
|
-
...opts,
|
|
132
|
-
excepts: opts.excepts?.map((s) => toRegExp(s)) ?? []
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function isValidName(name, options) {
|
|
137
|
-
if (name == null) return true;
|
|
138
|
-
if (options.excepts.some((regex) => regex.test(name))) return true;
|
|
139
|
-
const normalized = name.split(".").at(-1) ?? name;
|
|
140
|
-
switch (options.rule) {
|
|
141
|
-
case "CONSTANT_CASE": return RE_CONSTANT_CASE.test(normalized);
|
|
142
|
-
case "PascalCase":
|
|
143
|
-
if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) return options.allowAllCaps;
|
|
144
|
-
return RE_PASCAL_CASE.test(normalized);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
//#endregion
|
|
149
|
-
//#region src/rules/context-name.ts
|
|
150
|
-
const RULE_NAME$3 = "context-name";
|
|
38
|
+
//#region src/rules/context-name/context-name.ts
|
|
39
|
+
const RULE_NAME$2 = "context-name";
|
|
151
40
|
var context_name_default = createRule({
|
|
152
41
|
meta: {
|
|
153
42
|
type: "suggestion",
|
|
@@ -155,15 +44,13 @@ var context_name_default = createRule({
|
|
|
155
44
|
messages: { invalidContextName: "A context name must be a valid component name with the suffix 'Context'." },
|
|
156
45
|
schema: []
|
|
157
46
|
},
|
|
158
|
-
name: RULE_NAME$
|
|
159
|
-
create: create$
|
|
47
|
+
name: RULE_NAME$2,
|
|
48
|
+
create: create$2,
|
|
160
49
|
defaultOptions: []
|
|
161
50
|
});
|
|
162
|
-
function create$
|
|
51
|
+
function create$2(context) {
|
|
163
52
|
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
164
|
-
|
|
165
|
-
if (compare(version, "19.0.0", "<")) return {};
|
|
166
|
-
return { CallExpression(node) {
|
|
53
|
+
return defineRuleListener({ CallExpression(node) {
|
|
167
54
|
if (!core.isCreateContextCall(context, node)) return;
|
|
168
55
|
const [id, name] = match(findEnclosingAssignmentTarget(node)).with({
|
|
169
56
|
type: AST_NODE_TYPES.Identifier,
|
|
@@ -178,12 +65,12 @@ function create$3(context) {
|
|
|
178
65
|
messageId: "invalidContextName",
|
|
179
66
|
node: id
|
|
180
67
|
});
|
|
181
|
-
} };
|
|
68
|
+
} });
|
|
182
69
|
}
|
|
183
70
|
|
|
184
71
|
//#endregion
|
|
185
|
-
//#region src/rules/id-name.ts
|
|
186
|
-
const RULE_NAME$
|
|
72
|
+
//#region src/rules/id-name/id-name.ts
|
|
73
|
+
const RULE_NAME$1 = "id-name";
|
|
187
74
|
var id_name_default = createRule({
|
|
188
75
|
meta: {
|
|
189
76
|
type: "suggestion",
|
|
@@ -191,13 +78,13 @@ var id_name_default = createRule({
|
|
|
191
78
|
messages: { invalidIdName: "An identifier assigned from 'useId' must be named 'id' or end with 'Id'." },
|
|
192
79
|
schema: []
|
|
193
80
|
},
|
|
194
|
-
name: RULE_NAME$
|
|
195
|
-
create: create$
|
|
81
|
+
name: RULE_NAME$1,
|
|
82
|
+
create: create$1,
|
|
196
83
|
defaultOptions: []
|
|
197
84
|
});
|
|
198
|
-
function create$
|
|
85
|
+
function create$1(context) {
|
|
199
86
|
if (!context.sourceCode.text.includes("useId")) return {};
|
|
200
|
-
return { CallExpression(node) {
|
|
87
|
+
return defineRuleListener({ CallExpression(node) {
|
|
201
88
|
if (!core.isUseIdCall(node)) return;
|
|
202
89
|
const [id, name] = match(findEnclosingAssignmentTarget(node)).with({
|
|
203
90
|
type: AST_NODE_TYPES.Identifier,
|
|
@@ -212,12 +99,12 @@ function create$2(context) {
|
|
|
212
99
|
messageId: "invalidIdName",
|
|
213
100
|
node: id
|
|
214
101
|
});
|
|
215
|
-
} };
|
|
102
|
+
} });
|
|
216
103
|
}
|
|
217
104
|
|
|
218
105
|
//#endregion
|
|
219
|
-
//#region src/rules/ref-name.ts
|
|
220
|
-
const RULE_NAME
|
|
106
|
+
//#region src/rules/ref-name/ref-name.ts
|
|
107
|
+
const RULE_NAME = "ref-name";
|
|
221
108
|
var ref_name_default = createRule({
|
|
222
109
|
meta: {
|
|
223
110
|
type: "suggestion",
|
|
@@ -225,13 +112,13 @@ var ref_name_default = createRule({
|
|
|
225
112
|
messages: { invalidRefName: "A ref identifier must be named 'ref' or ending in 'Ref'." },
|
|
226
113
|
schema: []
|
|
227
114
|
},
|
|
228
|
-
name: RULE_NAME
|
|
229
|
-
create
|
|
115
|
+
name: RULE_NAME,
|
|
116
|
+
create,
|
|
230
117
|
defaultOptions: []
|
|
231
118
|
});
|
|
232
|
-
function create
|
|
119
|
+
function create(context) {
|
|
233
120
|
if (!context.sourceCode.text.includes("useRef")) return {};
|
|
234
|
-
return { CallExpression(node) {
|
|
121
|
+
return defineRuleListener({ CallExpression(node) {
|
|
235
122
|
if (!core.isUseRefCall(node)) return;
|
|
236
123
|
if (ast.getUnderlyingExpression(node.parent).type === AST_NODE_TYPES.MemberExpression) return;
|
|
237
124
|
const [id, name] = match(findEnclosingAssignmentTarget(node)).with({
|
|
@@ -247,129 +134,44 @@ function create$1(context) {
|
|
|
247
134
|
messageId: "invalidRefName",
|
|
248
135
|
node: id
|
|
249
136
|
});
|
|
250
|
-
} };
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
//#endregion
|
|
254
|
-
//#region src/rules/use-state.ts
|
|
255
|
-
const RULE_NAME = "use-state";
|
|
256
|
-
const defaultOptions = [{
|
|
257
|
-
enforceAssignment: false,
|
|
258
|
-
enforceSetterName: true
|
|
259
|
-
}];
|
|
260
|
-
const schema = [{
|
|
261
|
-
type: "object",
|
|
262
|
-
additionalProperties: false,
|
|
263
|
-
properties: {
|
|
264
|
-
enforceAssignment: {
|
|
265
|
-
type: "boolean",
|
|
266
|
-
default: false
|
|
267
|
-
},
|
|
268
|
-
enforceSetterName: {
|
|
269
|
-
type: "boolean",
|
|
270
|
-
default: true
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}];
|
|
274
|
-
var use_state_default = createRule({
|
|
275
|
-
meta: {
|
|
276
|
-
type: "suggestion",
|
|
277
|
-
docs: { description: "Enforces destructuring and symmetric naming of the 'useState' hook value and setter." },
|
|
278
|
-
messages: {
|
|
279
|
-
invalidAssignment: "useState should be destructured into a value and setter pair, e.g., const [state, setState] = useState(...).",
|
|
280
|
-
invalidSetterName: "The setter should be named 'set' followed by the capitalized state variable name, e.g., 'setState' for 'state'."
|
|
281
|
-
},
|
|
282
|
-
schema
|
|
283
|
-
},
|
|
284
|
-
name: RULE_NAME,
|
|
285
|
-
create,
|
|
286
|
-
defaultOptions
|
|
287
|
-
});
|
|
288
|
-
function create(context) {
|
|
289
|
-
const { enforceAssignment = false, enforceSetterName = true } = context.options[0] ?? defaultOptions[0];
|
|
290
|
-
return { CallExpression(node) {
|
|
291
|
-
if (!core.isUseStateCall(node)) return;
|
|
292
|
-
if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
|
|
293
|
-
if (!enforceAssignment) return;
|
|
294
|
-
context.report({
|
|
295
|
-
messageId: "invalidAssignment",
|
|
296
|
-
node
|
|
297
|
-
});
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
const id = findEnclosingAssignmentTarget(node);
|
|
301
|
-
if (id?.type !== AST_NODE_TYPES.ArrayPattern) {
|
|
302
|
-
if (!enforceAssignment) return;
|
|
303
|
-
context.report({
|
|
304
|
-
messageId: "invalidAssignment",
|
|
305
|
-
node: id ?? node
|
|
306
|
-
});
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
const [value, setter] = id.elements;
|
|
310
|
-
if (value == null) {
|
|
311
|
-
if (!enforceAssignment) return;
|
|
312
|
-
context.report({
|
|
313
|
-
messageId: "invalidAssignment",
|
|
314
|
-
node: id
|
|
315
|
-
});
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
if (setter == null || !enforceSetterName) return;
|
|
319
|
-
const setterName = match(setter).with({ type: AST_NODE_TYPES.Identifier }, (id) => id.name).otherwise(() => null);
|
|
320
|
-
if (setterName == null || !setterName.startsWith("set")) {
|
|
321
|
-
context.report({
|
|
322
|
-
messageId: "invalidSetterName",
|
|
323
|
-
node: setter
|
|
324
|
-
});
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
const valueName = match(value).with({ type: AST_NODE_TYPES.Identifier }, ({ name }) => snakeCase(name)).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
|
|
328
|
-
return properties.reduce((acc, prop) => {
|
|
329
|
-
if (prop.type === AST_NODE_TYPES.Property && prop.key.type === AST_NODE_TYPES.Identifier) return [...acc, prop.key.name];
|
|
330
|
-
return acc;
|
|
331
|
-
}, []).join("_");
|
|
332
|
-
}).otherwise(() => null);
|
|
333
|
-
if (valueName == null) {
|
|
334
|
-
context.report({
|
|
335
|
-
messageId: "invalidSetterName",
|
|
336
|
-
node: value
|
|
337
|
-
});
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
if (snakeCase(setterName) !== `set_${valueName}`) {
|
|
341
|
-
context.report({
|
|
342
|
-
messageId: "invalidSetterName",
|
|
343
|
-
node: setter
|
|
344
|
-
});
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
} };
|
|
137
|
+
} });
|
|
348
138
|
}
|
|
349
139
|
|
|
350
140
|
//#endregion
|
|
351
141
|
//#region src/plugin.ts
|
|
352
142
|
const plugin = {
|
|
353
143
|
meta: {
|
|
354
|
-
name,
|
|
144
|
+
name: name$1,
|
|
355
145
|
version
|
|
356
146
|
},
|
|
357
147
|
rules: {
|
|
358
|
-
["component-name"]: component_name_default,
|
|
359
148
|
["context-name"]: context_name_default,
|
|
360
149
|
["id-name"]: id_name_default,
|
|
361
|
-
["ref-name"]: ref_name_default
|
|
362
|
-
["use-state"]: use_state_default
|
|
150
|
+
["ref-name"]: ref_name_default
|
|
363
151
|
}
|
|
364
152
|
};
|
|
365
153
|
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/configs/recommended.ts
|
|
156
|
+
var recommended_exports = /* @__PURE__ */ __exportAll({
|
|
157
|
+
name: () => name,
|
|
158
|
+
plugins: () => plugins,
|
|
159
|
+
rules: () => rules
|
|
160
|
+
});
|
|
161
|
+
const name = "react-naming-convention/recommended";
|
|
162
|
+
const rules = {
|
|
163
|
+
"react-naming-convention/context-name": "warn",
|
|
164
|
+
"react-naming-convention/id-name": "warn",
|
|
165
|
+
"react-naming-convention/ref-name": "warn"
|
|
166
|
+
};
|
|
167
|
+
const plugins = { "react-naming-convention": plugin };
|
|
168
|
+
|
|
366
169
|
//#endregion
|
|
367
170
|
//#region src/index.ts
|
|
368
|
-
const
|
|
369
|
-
var src_default = {
|
|
171
|
+
const finalPlugin = {
|
|
370
172
|
...plugin,
|
|
371
|
-
configs: { ["recommended"]:
|
|
173
|
+
configs: { ["recommended"]: recommended_exports }
|
|
372
174
|
};
|
|
373
175
|
|
|
374
176
|
//#endregion
|
|
375
|
-
export {
|
|
177
|
+
export { finalPlugin as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-naming-convention",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.70",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for naming convention related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -45,16 +45,17 @@
|
|
|
45
45
|
"compare-versions": "^6.1.1",
|
|
46
46
|
"string-ts": "^2.3.1",
|
|
47
47
|
"ts-pattern": "^5.9.0",
|
|
48
|
-
"@eslint-react/ast": "3.0.0-beta.
|
|
49
|
-
"@eslint-react/core": "3.0.0-beta.
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/
|
|
48
|
+
"@eslint-react/ast": "3.0.0-beta.70",
|
|
49
|
+
"@eslint-react/core": "3.0.0-beta.70",
|
|
50
|
+
"@eslint-react/shared": "3.0.0-beta.70",
|
|
51
|
+
"@eslint-react/var": "3.0.0-beta.70",
|
|
52
|
+
"@eslint-react/eff": "3.0.0-beta.70"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.2.14",
|
|
56
56
|
"@types/react-dom": "^19.2.3",
|
|
57
|
-
"
|
|
57
|
+
"eslint": "^10.0.2",
|
|
58
|
+
"tsdown": "^0.21.0-beta.2",
|
|
58
59
|
"@local/configs": "0.0.0"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
|
@@ -70,6 +71,6 @@
|
|
|
70
71
|
"scripts": {
|
|
71
72
|
"build": "tsdown",
|
|
72
73
|
"lint:publish": "publint",
|
|
73
|
-
"lint:ts": "
|
|
74
|
+
"lint:ts": "tsl"
|
|
74
75
|
}
|
|
75
76
|
}
|