eslint-plugin-react-naming-convention 2.4.0-next.2 → 2.4.0-next.3
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 +45 -23
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ const rules = {
|
|
|
39
39
|
//#endregion
|
|
40
40
|
//#region package.json
|
|
41
41
|
var name = "eslint-plugin-react-naming-convention";
|
|
42
|
-
var version = "2.4.0-next.
|
|
42
|
+
var version = "2.4.0-next.3";
|
|
43
43
|
|
|
44
44
|
//#endregion
|
|
45
45
|
//#region src/utils/create-rule.ts
|
|
@@ -50,12 +50,12 @@ const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
|
50
50
|
|
|
51
51
|
//#endregion
|
|
52
52
|
//#region src/rules/component-name.ts
|
|
53
|
-
const defaultOptions$
|
|
53
|
+
const defaultOptions$3 = [{
|
|
54
54
|
allowAllCaps: false,
|
|
55
55
|
excepts: [],
|
|
56
56
|
rule: "PascalCase"
|
|
57
57
|
}];
|
|
58
|
-
const schema$
|
|
58
|
+
const schema$3 = [{ anyOf: [{
|
|
59
59
|
type: "string",
|
|
60
60
|
enum: ["PascalCase", "CONSTANT_CASE"]
|
|
61
61
|
}, {
|
|
@@ -81,17 +81,17 @@ const RULE_FEATURES$4 = ["CFG"];
|
|
|
81
81
|
var component_name_default = createRule({
|
|
82
82
|
meta: {
|
|
83
83
|
type: "problem",
|
|
84
|
-
defaultOptions: [...defaultOptions$
|
|
84
|
+
defaultOptions: [...defaultOptions$3],
|
|
85
85
|
docs: {
|
|
86
86
|
description: "Enforces naming conventions for components.",
|
|
87
87
|
[Symbol.for("rule_features")]: RULE_FEATURES$4
|
|
88
88
|
},
|
|
89
89
|
messages: { invalidComponentName: "A component name '{{name}}' does not match {{rule}}." },
|
|
90
|
-
schema: schema$
|
|
90
|
+
schema: schema$3
|
|
91
91
|
},
|
|
92
92
|
name: RULE_NAME$4,
|
|
93
93
|
create: create$4,
|
|
94
|
-
defaultOptions: defaultOptions$
|
|
94
|
+
defaultOptions: defaultOptions$3
|
|
95
95
|
});
|
|
96
96
|
function create$4(context) {
|
|
97
97
|
const options = normalizeOptions(context.options);
|
|
@@ -135,7 +135,7 @@ function create$4(context) {
|
|
|
135
135
|
}
|
|
136
136
|
function normalizeOptions(options) {
|
|
137
137
|
const opts = options[0];
|
|
138
|
-
const defaultOpts = defaultOptions$
|
|
138
|
+
const defaultOpts = defaultOptions$3[0];
|
|
139
139
|
if (opts == null) return defaultOpts;
|
|
140
140
|
return {
|
|
141
141
|
...defaultOpts,
|
|
@@ -200,7 +200,7 @@ function create$3(context) {
|
|
|
200
200
|
//#region src/rules/filename.ts
|
|
201
201
|
const RULE_NAME$2 = "filename";
|
|
202
202
|
const RULE_FEATURES$2 = ["CFG"];
|
|
203
|
-
const defaultOptions$
|
|
203
|
+
const defaultOptions$2 = [{
|
|
204
204
|
excepts: [
|
|
205
205
|
"index",
|
|
206
206
|
String.raw`/^_/`,
|
|
@@ -210,7 +210,7 @@ const defaultOptions$1 = [{
|
|
|
210
210
|
],
|
|
211
211
|
rule: "PascalCase"
|
|
212
212
|
}];
|
|
213
|
-
const schema$
|
|
213
|
+
const schema$2 = [{ anyOf: [{
|
|
214
214
|
type: "string",
|
|
215
215
|
enum: [
|
|
216
216
|
"PascalCase",
|
|
@@ -248,7 +248,7 @@ const schema$1 = [{ anyOf: [{
|
|
|
248
248
|
var filename_default = createRule({
|
|
249
249
|
meta: {
|
|
250
250
|
type: "problem",
|
|
251
|
-
defaultOptions: [...defaultOptions$
|
|
251
|
+
defaultOptions: [...defaultOptions$2],
|
|
252
252
|
docs: {
|
|
253
253
|
description: "Enforces consistent file naming conventions.",
|
|
254
254
|
[Symbol.for("rule_features")]: RULE_FEATURES$2
|
|
@@ -257,14 +257,14 @@ var filename_default = createRule({
|
|
|
257
257
|
empty: "A file must have non-empty name.",
|
|
258
258
|
invalidCase: "A file with name '{{name}}' does not match {{rule}}. Rename it to '{{suggestion}}'."
|
|
259
259
|
},
|
|
260
|
-
schema: schema$
|
|
260
|
+
schema: schema$2
|
|
261
261
|
},
|
|
262
262
|
name: RULE_NAME$2,
|
|
263
263
|
create: create$2,
|
|
264
|
-
defaultOptions: defaultOptions$
|
|
264
|
+
defaultOptions: defaultOptions$2
|
|
265
265
|
});
|
|
266
266
|
function create$2(context) {
|
|
267
|
-
const options = context.options[0] ?? defaultOptions$
|
|
267
|
+
const options = context.options[0] ?? defaultOptions$2[0];
|
|
268
268
|
const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
|
|
269
269
|
const excepts = typeof options === "string" ? [] : (options.excepts ?? []).map((s) => toRegExp(s));
|
|
270
270
|
function validate(name$2, casing = rule, ignores = excepts) {
|
|
@@ -302,12 +302,12 @@ function create$2(context) {
|
|
|
302
302
|
//#region src/rules/filename-extension.ts
|
|
303
303
|
const RULE_NAME$1 = "filename-extension";
|
|
304
304
|
const RULE_FEATURES$1 = ["CFG"];
|
|
305
|
-
const defaultOptions = [{
|
|
305
|
+
const defaultOptions$1 = [{
|
|
306
306
|
allow: "as-needed",
|
|
307
307
|
extensions: [".jsx", ".tsx"],
|
|
308
308
|
ignoreFilesWithoutCode: false
|
|
309
309
|
}];
|
|
310
|
-
const schema = [{ anyOf: [{
|
|
310
|
+
const schema$1 = [{ anyOf: [{
|
|
311
311
|
type: "string",
|
|
312
312
|
enum: ["always", "as-needed"]
|
|
313
313
|
}, {
|
|
@@ -329,7 +329,7 @@ const schema = [{ anyOf: [{
|
|
|
329
329
|
var filename_extension_default = createRule({
|
|
330
330
|
meta: {
|
|
331
331
|
type: "problem",
|
|
332
|
-
defaultOptions: [...defaultOptions],
|
|
332
|
+
defaultOptions: [...defaultOptions$1],
|
|
333
333
|
docs: {
|
|
334
334
|
description: "Enforces consistent file naming conventions.",
|
|
335
335
|
[Symbol.for("rule_features")]: RULE_FEATURES$1
|
|
@@ -338,16 +338,16 @@ var filename_extension_default = createRule({
|
|
|
338
338
|
missingJSXExtension: "Use {{extensions}} file extension for JSX files.",
|
|
339
339
|
unnecessaryJSXExtension: "Do not use {{extensions}} file extension for files without JSX."
|
|
340
340
|
},
|
|
341
|
-
schema
|
|
341
|
+
schema: schema$1
|
|
342
342
|
},
|
|
343
343
|
name: RULE_NAME$1,
|
|
344
344
|
create: create$1,
|
|
345
|
-
defaultOptions
|
|
345
|
+
defaultOptions: defaultOptions$1
|
|
346
346
|
});
|
|
347
347
|
function create$1(context) {
|
|
348
|
-
const options = context.options[0] ?? defaultOptions[0];
|
|
348
|
+
const options = context.options[0] ?? defaultOptions$1[0];
|
|
349
349
|
const allow = isObject(options) ? options.allow : options;
|
|
350
|
-
const extensions = isObject(options) && "extensions" in options ? options.extensions : defaultOptions[0].extensions;
|
|
350
|
+
const extensions = isObject(options) && "extensions" in options ? options.extensions : defaultOptions$1[0].extensions;
|
|
351
351
|
const extensionsString = extensions.map((ext) => `'${ext}'`).join(", ");
|
|
352
352
|
const filename = context.filename;
|
|
353
353
|
let hasJSXNode = false;
|
|
@@ -385,6 +385,24 @@ function create$1(context) {
|
|
|
385
385
|
//#region src/rules/use-state.ts
|
|
386
386
|
const RULE_NAME = "use-state";
|
|
387
387
|
const RULE_FEATURES = [];
|
|
388
|
+
const defaultOptions = [{
|
|
389
|
+
enforceAssignment: false,
|
|
390
|
+
enforceSetterName: true
|
|
391
|
+
}];
|
|
392
|
+
const schema = [{
|
|
393
|
+
type: "object",
|
|
394
|
+
additionalProperties: false,
|
|
395
|
+
properties: {
|
|
396
|
+
enforceAssignment: {
|
|
397
|
+
type: "boolean",
|
|
398
|
+
default: false
|
|
399
|
+
},
|
|
400
|
+
enforceSetterName: {
|
|
401
|
+
type: "boolean",
|
|
402
|
+
default: true
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}];
|
|
388
406
|
var use_state_default = createRule({
|
|
389
407
|
meta: {
|
|
390
408
|
type: "problem",
|
|
@@ -396,16 +414,18 @@ var use_state_default = createRule({
|
|
|
396
414
|
invalidAssignment: "useState should be destructured into a value and setter pair, e.g., const [state, setState] = useState(...).",
|
|
397
415
|
invalidSetterName: "The setter should be named 'set' followed by the capitalized state variable name, e.g., 'setState' for 'state'."
|
|
398
416
|
},
|
|
399
|
-
schema
|
|
417
|
+
schema
|
|
400
418
|
},
|
|
401
419
|
name: RULE_NAME,
|
|
402
420
|
create,
|
|
403
|
-
defaultOptions
|
|
421
|
+
defaultOptions
|
|
404
422
|
});
|
|
405
423
|
function create(context) {
|
|
424
|
+
const { enforceAssignment = false, enforceSetterName = true } = context.options[0] ?? defaultOptions[0];
|
|
406
425
|
return { CallExpression(node) {
|
|
407
426
|
if (!isUseStateCall(node)) return;
|
|
408
427
|
if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
|
|
428
|
+
if (!enforceAssignment) return;
|
|
409
429
|
context.report({
|
|
410
430
|
messageId: "invalidAssignment",
|
|
411
431
|
node
|
|
@@ -414,6 +434,7 @@ function create(context) {
|
|
|
414
434
|
}
|
|
415
435
|
const id = getInstanceId(node);
|
|
416
436
|
if (id?.type !== AST_NODE_TYPES.ArrayPattern) {
|
|
437
|
+
if (!enforceAssignment) return;
|
|
417
438
|
context.report({
|
|
418
439
|
messageId: "invalidAssignment",
|
|
419
440
|
node: id ?? node
|
|
@@ -422,13 +443,14 @@ function create(context) {
|
|
|
422
443
|
}
|
|
423
444
|
const [value, setter] = id.elements;
|
|
424
445
|
if (value == null) {
|
|
446
|
+
if (!enforceAssignment) return;
|
|
425
447
|
context.report({
|
|
426
448
|
messageId: "invalidAssignment",
|
|
427
449
|
node: id
|
|
428
450
|
});
|
|
429
451
|
return;
|
|
430
452
|
}
|
|
431
|
-
if (setter == null) return;
|
|
453
|
+
if (setter == null || !enforceSetterName) return;
|
|
432
454
|
const setterName = match(setter).with({ type: AST_NODE_TYPES.Identifier }, (id$1) => id$1.name).otherwise(() => null);
|
|
433
455
|
if (setterName == null || !setterName.startsWith("set")) {
|
|
434
456
|
context.report({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-naming-convention",
|
|
3
|
-
"version": "2.4.0-next.
|
|
3
|
+
"version": "2.4.0-next.3",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for naming convention related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"@typescript-eslint/utils": "^8.49.0",
|
|
45
45
|
"string-ts": "^2.3.1",
|
|
46
46
|
"ts-pattern": "^5.9.0",
|
|
47
|
-
"@eslint-react/ast": "2.4.0-next.
|
|
48
|
-
"@eslint-react/eff": "2.4.0-next.
|
|
49
|
-
"@eslint-react/core": "2.4.0-next.
|
|
50
|
-
"@eslint-react/shared": "2.4.0-next.
|
|
51
|
-
"@eslint-react/var": "2.4.0-next.
|
|
47
|
+
"@eslint-react/ast": "2.4.0-next.3",
|
|
48
|
+
"@eslint-react/eff": "2.4.0-next.3",
|
|
49
|
+
"@eslint-react/core": "2.4.0-next.3",
|
|
50
|
+
"@eslint-react/shared": "2.4.0-next.3",
|
|
51
|
+
"@eslint-react/var": "2.4.0-next.3"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/react": "^19.2.7",
|