eslint-plugin-react-naming-convention 3.0.0-next.19 → 3.0.0-next.20
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/dist/index.js +25 -125
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -6,7 +6,6 @@ import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
|
6
6
|
import { compare } from "compare-versions";
|
|
7
7
|
import { P, match } from "ts-pattern";
|
|
8
8
|
import * as ast from "@eslint-react/ast";
|
|
9
|
-
import { snakeCase } from "string-ts";
|
|
10
9
|
|
|
11
10
|
//#region \0rolldown/runtime.js
|
|
12
11
|
var __defProp = Object.defineProperty;
|
|
@@ -34,14 +33,13 @@ const name$1 = "react-naming-convention/recommended";
|
|
|
34
33
|
const rules = {
|
|
35
34
|
"react-naming-convention/context-name": "warn",
|
|
36
35
|
"react-naming-convention/id-name": "warn",
|
|
37
|
-
"react-naming-convention/ref-name": "warn"
|
|
38
|
-
"react-naming-convention/use-state": "warn"
|
|
36
|
+
"react-naming-convention/ref-name": "warn"
|
|
39
37
|
};
|
|
40
38
|
|
|
41
39
|
//#endregion
|
|
42
40
|
//#region package.json
|
|
43
41
|
var name = "eslint-plugin-react-naming-convention";
|
|
44
|
-
var version = "3.0.0-next.
|
|
42
|
+
var version = "3.0.0-next.20";
|
|
45
43
|
|
|
46
44
|
//#endregion
|
|
47
45
|
//#region src/utils/create-rule.ts
|
|
@@ -52,12 +50,12 @@ const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
|
52
50
|
|
|
53
51
|
//#endregion
|
|
54
52
|
//#region src/rules/component-name.ts
|
|
55
|
-
const defaultOptions
|
|
53
|
+
const defaultOptions = [{
|
|
56
54
|
allowAllCaps: false,
|
|
57
55
|
excepts: [],
|
|
58
56
|
rule: "PascalCase"
|
|
59
57
|
}];
|
|
60
|
-
const schema
|
|
58
|
+
const schema = [{ anyOf: [{
|
|
61
59
|
type: "string",
|
|
62
60
|
enum: ["PascalCase", "CONSTANT_CASE"]
|
|
63
61
|
}, {
|
|
@@ -78,20 +76,20 @@ const schema$1 = [{ anyOf: [{
|
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
78
|
}] }];
|
|
81
|
-
const RULE_NAME$
|
|
79
|
+
const RULE_NAME$3 = "component-name";
|
|
82
80
|
var component_name_default = createRule({
|
|
83
81
|
meta: {
|
|
84
82
|
type: "problem",
|
|
85
|
-
defaultOptions: [...defaultOptions
|
|
83
|
+
defaultOptions: [...defaultOptions],
|
|
86
84
|
docs: { description: "Enforces naming conventions for components." },
|
|
87
85
|
messages: { invalidComponentName: "A component name '{{name}}' does not match {{rule}}." },
|
|
88
|
-
schema
|
|
86
|
+
schema
|
|
89
87
|
},
|
|
90
|
-
name: RULE_NAME$
|
|
91
|
-
create: create$
|
|
92
|
-
defaultOptions
|
|
88
|
+
name: RULE_NAME$3,
|
|
89
|
+
create: create$3,
|
|
90
|
+
defaultOptions
|
|
93
91
|
});
|
|
94
|
-
function create$
|
|
92
|
+
function create$3(context) {
|
|
95
93
|
const options = normalizeOptions(context.options);
|
|
96
94
|
const { rule } = options;
|
|
97
95
|
const fCollector = core.useComponentCollector(context);
|
|
@@ -123,7 +121,7 @@ function create$4(context) {
|
|
|
123
121
|
}
|
|
124
122
|
function normalizeOptions(options) {
|
|
125
123
|
const opts = options[0];
|
|
126
|
-
const defaultOpts = defaultOptions
|
|
124
|
+
const defaultOpts = defaultOptions[0];
|
|
127
125
|
if (opts == null) return defaultOpts;
|
|
128
126
|
return {
|
|
129
127
|
...defaultOpts,
|
|
@@ -147,7 +145,7 @@ function isValidName(name, options) {
|
|
|
147
145
|
|
|
148
146
|
//#endregion
|
|
149
147
|
//#region src/rules/context-name.ts
|
|
150
|
-
const RULE_NAME$
|
|
148
|
+
const RULE_NAME$2 = "context-name";
|
|
151
149
|
var context_name_default = createRule({
|
|
152
150
|
meta: {
|
|
153
151
|
type: "suggestion",
|
|
@@ -155,11 +153,11 @@ var context_name_default = createRule({
|
|
|
155
153
|
messages: { invalidContextName: "A context name must be a valid component name with the suffix 'Context'." },
|
|
156
154
|
schema: []
|
|
157
155
|
},
|
|
158
|
-
name: RULE_NAME$
|
|
159
|
-
create: create$
|
|
156
|
+
name: RULE_NAME$2,
|
|
157
|
+
create: create$2,
|
|
160
158
|
defaultOptions: []
|
|
161
159
|
});
|
|
162
|
-
function create$
|
|
160
|
+
function create$2(context) {
|
|
163
161
|
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
164
162
|
const { version } = getSettingsFromContext(context);
|
|
165
163
|
if (compare(version, "19.0.0", "<")) return {};
|
|
@@ -183,7 +181,7 @@ function create$3(context) {
|
|
|
183
181
|
|
|
184
182
|
//#endregion
|
|
185
183
|
//#region src/rules/id-name.ts
|
|
186
|
-
const RULE_NAME$
|
|
184
|
+
const RULE_NAME$1 = "id-name";
|
|
187
185
|
var id_name_default = createRule({
|
|
188
186
|
meta: {
|
|
189
187
|
type: "suggestion",
|
|
@@ -191,11 +189,11 @@ var id_name_default = createRule({
|
|
|
191
189
|
messages: { invalidIdName: "An identifier assigned from 'useId' must be named 'id' or end with 'Id'." },
|
|
192
190
|
schema: []
|
|
193
191
|
},
|
|
194
|
-
name: RULE_NAME$
|
|
195
|
-
create: create$
|
|
192
|
+
name: RULE_NAME$1,
|
|
193
|
+
create: create$1,
|
|
196
194
|
defaultOptions: []
|
|
197
195
|
});
|
|
198
|
-
function create$
|
|
196
|
+
function create$1(context) {
|
|
199
197
|
if (!context.sourceCode.text.includes("useId")) return {};
|
|
200
198
|
return defineRuleListener({ CallExpression(node) {
|
|
201
199
|
if (!core.isUseIdCall(node)) return;
|
|
@@ -217,7 +215,7 @@ function create$2(context) {
|
|
|
217
215
|
|
|
218
216
|
//#endregion
|
|
219
217
|
//#region src/rules/ref-name.ts
|
|
220
|
-
const RULE_NAME
|
|
218
|
+
const RULE_NAME = "ref-name";
|
|
221
219
|
var ref_name_default = createRule({
|
|
222
220
|
meta: {
|
|
223
221
|
type: "suggestion",
|
|
@@ -225,11 +223,11 @@ var ref_name_default = createRule({
|
|
|
225
223
|
messages: { invalidRefName: "A ref identifier must be named 'ref' or ending in 'Ref'." },
|
|
226
224
|
schema: []
|
|
227
225
|
},
|
|
228
|
-
name: RULE_NAME
|
|
229
|
-
create
|
|
226
|
+
name: RULE_NAME,
|
|
227
|
+
create,
|
|
230
228
|
defaultOptions: []
|
|
231
229
|
});
|
|
232
|
-
function create
|
|
230
|
+
function create(context) {
|
|
233
231
|
if (!context.sourceCode.text.includes("useRef")) return {};
|
|
234
232
|
return defineRuleListener({ CallExpression(node) {
|
|
235
233
|
if (!core.isUseRefCall(node)) return;
|
|
@@ -250,103 +248,6 @@ function create$1(context) {
|
|
|
250
248
|
} });
|
|
251
249
|
}
|
|
252
250
|
|
|
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 defineRuleListener({ 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
|
-
} });
|
|
348
|
-
}
|
|
349
|
-
|
|
350
251
|
//#endregion
|
|
351
252
|
//#region src/plugin.ts
|
|
352
253
|
const plugin = {
|
|
@@ -358,8 +259,7 @@ const plugin = {
|
|
|
358
259
|
["component-name"]: component_name_default,
|
|
359
260
|
["context-name"]: context_name_default,
|
|
360
261
|
["id-name"]: id_name_default,
|
|
361
|
-
["ref-name"]: ref_name_default
|
|
362
|
-
["use-state"]: use_state_default
|
|
262
|
+
["ref-name"]: ref_name_default
|
|
363
263
|
}
|
|
364
264
|
};
|
|
365
265
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-naming-convention",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.20",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for naming convention related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -45,11 +45,11 @@
|
|
|
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-next.
|
|
49
|
-
"@eslint-react/
|
|
50
|
-
"@eslint-react/eff": "3.0.0-next.
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/
|
|
48
|
+
"@eslint-react/ast": "3.0.0-next.20",
|
|
49
|
+
"@eslint-react/core": "3.0.0-next.20",
|
|
50
|
+
"@eslint-react/eff": "3.0.0-next.20",
|
|
51
|
+
"@eslint-react/shared": "3.0.0-next.20",
|
|
52
|
+
"@eslint-react/var": "3.0.0-next.20"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.2.14",
|