eslint-plugin-react-naming-convention 1.28.1-beta.4 → 1.28.1-beta.7
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.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +72 -64
- package/dist/index.mjs +77 -69
- package/package.json +7 -6
package/dist/index.d.mts
CHANGED
|
@@ -24,6 +24,7 @@ declare const _default: {
|
|
|
24
24
|
excepts?: readonly string[];
|
|
25
25
|
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
26
26
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
27
|
+
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"contextName", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
27
28
|
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
28
29
|
excepts?: readonly string[];
|
|
29
30
|
extensions?: readonly string[];
|
|
@@ -34,7 +35,7 @@ declare const _default: {
|
|
|
34
35
|
extensions?: readonly string[];
|
|
35
36
|
ignoreFilesWithoutCode?: boolean;
|
|
36
37
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
37
|
-
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
38
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"badValueOrSetterName", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
38
39
|
};
|
|
39
40
|
};
|
|
40
41
|
};
|
|
@@ -58,6 +59,7 @@ declare const _default: {
|
|
|
58
59
|
excepts?: readonly string[];
|
|
59
60
|
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
60
61
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
62
|
+
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"contextName", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
61
63
|
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
62
64
|
excepts?: readonly string[];
|
|
63
65
|
extensions?: readonly string[];
|
|
@@ -68,7 +70,7 @@ declare const _default: {
|
|
|
68
70
|
extensions?: readonly string[];
|
|
69
71
|
ignoreFilesWithoutCode?: boolean;
|
|
70
72
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
71
|
-
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
73
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"badValueOrSetterName", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
72
74
|
};
|
|
73
75
|
};
|
|
74
76
|
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ declare const _default: {
|
|
|
24
24
|
excepts?: readonly string[];
|
|
25
25
|
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
26
26
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
27
|
+
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"contextName", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
27
28
|
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
28
29
|
excepts?: readonly string[];
|
|
29
30
|
extensions?: readonly string[];
|
|
@@ -34,7 +35,7 @@ declare const _default: {
|
|
|
34
35
|
extensions?: readonly string[];
|
|
35
36
|
ignoreFilesWithoutCode?: boolean;
|
|
36
37
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
37
|
-
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
38
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"badValueOrSetterName", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
38
39
|
};
|
|
39
40
|
};
|
|
40
41
|
};
|
|
@@ -58,6 +59,7 @@ declare const _default: {
|
|
|
58
59
|
excepts?: readonly string[];
|
|
59
60
|
rule?: "CONSTANT_CASE" | "PascalCase";
|
|
60
61
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
62
|
+
readonly "context-name": _typescript_eslint_utils_ts_eslint.RuleModule<"contextName", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
61
63
|
readonly filename: _typescript_eslint_utils_ts_eslint.RuleModule<MessageID$1, readonly [("PascalCase" | "camelCase" | "kebab-case" | "snake_case") | {
|
|
62
64
|
excepts?: readonly string[];
|
|
63
65
|
extensions?: readonly string[];
|
|
@@ -68,7 +70,7 @@ declare const _default: {
|
|
|
68
70
|
extensions?: readonly string[];
|
|
69
71
|
ignoreFilesWithoutCode?: boolean;
|
|
70
72
|
} | undefined], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
71
|
-
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"
|
|
73
|
+
readonly "use-state": _typescript_eslint_utils_ts_eslint.RuleModule<"badValueOrSetterName", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
72
74
|
};
|
|
73
75
|
};
|
|
74
76
|
|
package/dist/index.js
CHANGED
|
@@ -6,9 +6,9 @@ var eff = require('@eslint-react/eff');
|
|
|
6
6
|
var JSX = require('@eslint-react/jsx');
|
|
7
7
|
var shared = require('@eslint-react/shared');
|
|
8
8
|
var tsPattern = require('ts-pattern');
|
|
9
|
+
var types = require('@typescript-eslint/types');
|
|
9
10
|
var path = require('path');
|
|
10
11
|
var stringTs = require('string-ts');
|
|
11
|
-
var types = require('@typescript-eslint/types');
|
|
12
12
|
|
|
13
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
|
|
@@ -51,7 +51,7 @@ var rules = {};
|
|
|
51
51
|
|
|
52
52
|
// package.json
|
|
53
53
|
var name2 = "eslint-plugin-react-naming-convention";
|
|
54
|
-
var version = "1.28.1-beta.
|
|
54
|
+
var version = "1.28.1-beta.7";
|
|
55
55
|
var createRule = shared.createRuleForPlugin("naming-convention");
|
|
56
56
|
|
|
57
57
|
// src/rules/component-name.ts
|
|
@@ -204,7 +204,39 @@ var component_name_default = createRule({
|
|
|
204
204
|
},
|
|
205
205
|
defaultOptions
|
|
206
206
|
});
|
|
207
|
-
var RULE_NAME2 = "
|
|
207
|
+
var RULE_NAME2 = "context-name";
|
|
208
|
+
var context_name_default = createRule({
|
|
209
|
+
meta: {
|
|
210
|
+
type: "problem",
|
|
211
|
+
docs: {
|
|
212
|
+
description: "enforce context name to end with `Context`."
|
|
213
|
+
},
|
|
214
|
+
messages: {
|
|
215
|
+
contextName: "Context name must end with `Context`."
|
|
216
|
+
},
|
|
217
|
+
schema: []
|
|
218
|
+
},
|
|
219
|
+
name: RULE_NAME2,
|
|
220
|
+
create(context) {
|
|
221
|
+
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
222
|
+
return {
|
|
223
|
+
CallExpression(node) {
|
|
224
|
+
if (!core.isCreateContextCall(context, node)) return;
|
|
225
|
+
const id = core.getInstanceId(node);
|
|
226
|
+
if (id == null) return;
|
|
227
|
+
const name3 = tsPattern.match(id).with({ type: types.AST_NODE_TYPES.Identifier, name: tsPattern.P.select() }, eff.identity).with({ type: types.AST_NODE_TYPES.MemberExpression, property: { name: tsPattern.P.select(tsPattern.P.string) } }, eff.identity).otherwise(() => eff._);
|
|
228
|
+
if (name3 == null) return;
|
|
229
|
+
if (name3.endsWith("Context")) return;
|
|
230
|
+
context.report({
|
|
231
|
+
messageId: "contextName",
|
|
232
|
+
node: id
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
defaultOptions: []
|
|
238
|
+
});
|
|
239
|
+
var RULE_NAME3 = "filename";
|
|
208
240
|
var defaultOptions2 = [
|
|
209
241
|
{
|
|
210
242
|
excepts: ["^index$"],
|
|
@@ -254,7 +286,7 @@ var filename_default = createRule({
|
|
|
254
286
|
},
|
|
255
287
|
schema: schema2
|
|
256
288
|
},
|
|
257
|
-
name:
|
|
289
|
+
name: RULE_NAME3,
|
|
258
290
|
create(context) {
|
|
259
291
|
const options = context.options[0] ?? defaultOptions2[0];
|
|
260
292
|
const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
|
|
@@ -291,7 +323,7 @@ var filename_default = createRule({
|
|
|
291
323
|
},
|
|
292
324
|
defaultOptions: defaultOptions2
|
|
293
325
|
});
|
|
294
|
-
var
|
|
326
|
+
var RULE_NAME4 = "filename-extension";
|
|
295
327
|
var defaultOptions3 = [{
|
|
296
328
|
allow: "as-needed",
|
|
297
329
|
extensions: [".jsx", ".tsx"],
|
|
@@ -340,7 +372,7 @@ var filename_extension_default = createRule({
|
|
|
340
372
|
},
|
|
341
373
|
schema: schema3
|
|
342
374
|
},
|
|
343
|
-
name:
|
|
375
|
+
name: RULE_NAME4,
|
|
344
376
|
create(context) {
|
|
345
377
|
const options = context.options[0] ?? defaultOptions3[0];
|
|
346
378
|
const allow = eff.isObject(options) ? options.allow : options;
|
|
@@ -387,14 +419,10 @@ var filename_extension_default = createRule({
|
|
|
387
419
|
},
|
|
388
420
|
defaultOptions: defaultOptions3
|
|
389
421
|
});
|
|
390
|
-
var
|
|
422
|
+
var RULE_NAME5 = "use-state";
|
|
391
423
|
var RULE_FEATURES = [
|
|
392
424
|
"CHK"
|
|
393
425
|
];
|
|
394
|
-
function isSetterNameLoose(name3) {
|
|
395
|
-
const fourthChar = [...name3][3];
|
|
396
|
-
return name3.startsWith("set") && fourthChar === fourthChar?.toUpperCase();
|
|
397
|
-
}
|
|
398
426
|
var use_state_default = createRule({
|
|
399
427
|
meta: {
|
|
400
428
|
type: "problem",
|
|
@@ -403,65 +431,44 @@ var use_state_default = createRule({
|
|
|
403
431
|
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
404
432
|
},
|
|
405
433
|
messages: {
|
|
406
|
-
|
|
434
|
+
badValueOrSetterName: "An useState call is not destructured into value + setter pair."
|
|
407
435
|
},
|
|
408
436
|
schema: []
|
|
409
437
|
},
|
|
410
|
-
name:
|
|
438
|
+
name: RULE_NAME5,
|
|
411
439
|
create(context) {
|
|
412
|
-
const alias = shared.getSettingsFromContext(context).additionalHooks.useState ?? [];
|
|
413
|
-
const {
|
|
414
|
-
ctx,
|
|
415
|
-
listeners
|
|
416
|
-
} = core.useComponentCollector(
|
|
417
|
-
context,
|
|
418
|
-
{
|
|
419
|
-
collectDisplayName: false,
|
|
420
|
-
collectHookCalls: true,
|
|
421
|
-
hint: core.DEFAULT_COMPONENT_HINT
|
|
422
|
-
}
|
|
423
|
-
);
|
|
424
440
|
return {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
if (!isSetterNameLoose(setState.name)) {
|
|
449
|
-
context.report({ messageId: "unexpected", node: id });
|
|
450
|
-
}
|
|
451
|
-
break;
|
|
452
|
-
}
|
|
453
|
-
if (state?.type !== types.AST_NODE_TYPES.Identifier || setState?.type !== types.AST_NODE_TYPES.Identifier) {
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
const [stateName, setStateName] = [state.name, setState.name];
|
|
457
|
-
const expectedSetterName = `set${stringTs.capitalize(stateName)}`;
|
|
458
|
-
if (setStateName === expectedSetterName) {
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
context.report({ messageId: "unexpected", node: id });
|
|
462
|
-
}
|
|
441
|
+
"CallExpression[callee.name='useState']"(node) {
|
|
442
|
+
if (node.parent.type !== types.AST_NODE_TYPES.VariableDeclarator) {
|
|
443
|
+
context.report({ messageId: "badValueOrSetterName", node });
|
|
444
|
+
}
|
|
445
|
+
const id = core.getInstanceId(node);
|
|
446
|
+
if (id?.type !== types.AST_NODE_TYPES.ArrayPattern) {
|
|
447
|
+
context.report({ messageId: "badValueOrSetterName", node });
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const [value, setter] = id.elements;
|
|
451
|
+
if (value == null || setter == null) {
|
|
452
|
+
context.report({ messageId: "badValueOrSetterName", node });
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const setterName = tsPattern.match(setter).with({ type: types.AST_NODE_TYPES.Identifier }, (id2) => id2.name).otherwise(() => eff._);
|
|
456
|
+
if (setterName == null || !setterName.startsWith("set")) {
|
|
457
|
+
context.report({ messageId: "badValueOrSetterName", node });
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const valueName = tsPattern.match(value).with({ type: types.AST_NODE_TYPES.Identifier }, (id2) => id2.name).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
|
|
461
|
+
const values = properties.reduce((acc, prop) => {
|
|
462
|
+
if (prop.type === types.AST_NODE_TYPES.Property && prop.key.type === types.AST_NODE_TYPES.Identifier) {
|
|
463
|
+
return [...acc, prop.key.name];
|
|
463
464
|
}
|
|
464
|
-
|
|
465
|
+
return acc;
|
|
466
|
+
}, []);
|
|
467
|
+
return values.join("_");
|
|
468
|
+
}).otherwise(() => eff._);
|
|
469
|
+
if (valueName == null || `set_${valueName}` !== stringTs.snakeCase(setterName)) {
|
|
470
|
+
context.report({ messageId: "badValueOrSetterName", node });
|
|
471
|
+
return;
|
|
465
472
|
}
|
|
466
473
|
}
|
|
467
474
|
};
|
|
@@ -477,6 +484,7 @@ var plugin = {
|
|
|
477
484
|
},
|
|
478
485
|
rules: {
|
|
479
486
|
"component-name": component_name_default,
|
|
487
|
+
"context-name": context_name_default,
|
|
480
488
|
filename: filename_default,
|
|
481
489
|
"filename-extension": filename_extension_default,
|
|
482
490
|
"use-state": use_state_default
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
|
-
import { useComponentCollector, useComponentCollectorLegacy,
|
|
3
|
-
import {
|
|
2
|
+
import { useComponentCollector, useComponentCollectorLegacy, isCreateContextCall, getInstanceId } from '@eslint-react/core';
|
|
3
|
+
import { identity, _, isObject } from '@eslint-react/eff';
|
|
4
4
|
import * as JSX from '@eslint-react/jsx';
|
|
5
|
-
import { createRuleForPlugin,
|
|
6
|
-
import { match } from 'ts-pattern';
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import { capitalize, pascalCase, camelCase, kebabCase, snakeCase } from 'string-ts';
|
|
5
|
+
import { createRuleForPlugin, RE_CONSTANT_CASE, RE_PASCAL_CASE, RE_CAMEL_CASE, RE_KEBAB_CASE, RE_SNAKE_CASE } from '@eslint-react/shared';
|
|
6
|
+
import { match, P } from 'ts-pattern';
|
|
9
7
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { snakeCase, pascalCase, camelCase, kebabCase } from 'string-ts';
|
|
10
10
|
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
12
12
|
var __export = (target, all) => {
|
|
@@ -25,7 +25,7 @@ var rules = {};
|
|
|
25
25
|
|
|
26
26
|
// package.json
|
|
27
27
|
var name2 = "eslint-plugin-react-naming-convention";
|
|
28
|
-
var version = "1.28.1-beta.
|
|
28
|
+
var version = "1.28.1-beta.7";
|
|
29
29
|
var createRule = createRuleForPlugin("naming-convention");
|
|
30
30
|
|
|
31
31
|
// src/rules/component-name.ts
|
|
@@ -178,7 +178,39 @@ var component_name_default = createRule({
|
|
|
178
178
|
},
|
|
179
179
|
defaultOptions
|
|
180
180
|
});
|
|
181
|
-
var RULE_NAME2 = "
|
|
181
|
+
var RULE_NAME2 = "context-name";
|
|
182
|
+
var context_name_default = createRule({
|
|
183
|
+
meta: {
|
|
184
|
+
type: "problem",
|
|
185
|
+
docs: {
|
|
186
|
+
description: "enforce context name to end with `Context`."
|
|
187
|
+
},
|
|
188
|
+
messages: {
|
|
189
|
+
contextName: "Context name must end with `Context`."
|
|
190
|
+
},
|
|
191
|
+
schema: []
|
|
192
|
+
},
|
|
193
|
+
name: RULE_NAME2,
|
|
194
|
+
create(context) {
|
|
195
|
+
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
196
|
+
return {
|
|
197
|
+
CallExpression(node) {
|
|
198
|
+
if (!isCreateContextCall(context, node)) return;
|
|
199
|
+
const id = getInstanceId(node);
|
|
200
|
+
if (id == null) return;
|
|
201
|
+
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(() => _);
|
|
202
|
+
if (name3 == null) return;
|
|
203
|
+
if (name3.endsWith("Context")) return;
|
|
204
|
+
context.report({
|
|
205
|
+
messageId: "contextName",
|
|
206
|
+
node: id
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
defaultOptions: []
|
|
212
|
+
});
|
|
213
|
+
var RULE_NAME3 = "filename";
|
|
182
214
|
var defaultOptions2 = [
|
|
183
215
|
{
|
|
184
216
|
excepts: ["^index$"],
|
|
@@ -228,7 +260,7 @@ var filename_default = createRule({
|
|
|
228
260
|
},
|
|
229
261
|
schema: schema2
|
|
230
262
|
},
|
|
231
|
-
name:
|
|
263
|
+
name: RULE_NAME3,
|
|
232
264
|
create(context) {
|
|
233
265
|
const options = context.options[0] ?? defaultOptions2[0];
|
|
234
266
|
const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
|
|
@@ -265,7 +297,7 @@ var filename_default = createRule({
|
|
|
265
297
|
},
|
|
266
298
|
defaultOptions: defaultOptions2
|
|
267
299
|
});
|
|
268
|
-
var
|
|
300
|
+
var RULE_NAME4 = "filename-extension";
|
|
269
301
|
var defaultOptions3 = [{
|
|
270
302
|
allow: "as-needed",
|
|
271
303
|
extensions: [".jsx", ".tsx"],
|
|
@@ -314,7 +346,7 @@ var filename_extension_default = createRule({
|
|
|
314
346
|
},
|
|
315
347
|
schema: schema3
|
|
316
348
|
},
|
|
317
|
-
name:
|
|
349
|
+
name: RULE_NAME4,
|
|
318
350
|
create(context) {
|
|
319
351
|
const options = context.options[0] ?? defaultOptions3[0];
|
|
320
352
|
const allow = isObject(options) ? options.allow : options;
|
|
@@ -361,14 +393,10 @@ var filename_extension_default = createRule({
|
|
|
361
393
|
},
|
|
362
394
|
defaultOptions: defaultOptions3
|
|
363
395
|
});
|
|
364
|
-
var
|
|
396
|
+
var RULE_NAME5 = "use-state";
|
|
365
397
|
var RULE_FEATURES = [
|
|
366
398
|
"CHK"
|
|
367
399
|
];
|
|
368
|
-
function isSetterNameLoose(name3) {
|
|
369
|
-
const fourthChar = [...name3][3];
|
|
370
|
-
return name3.startsWith("set") && fourthChar === fourthChar?.toUpperCase();
|
|
371
|
-
}
|
|
372
400
|
var use_state_default = createRule({
|
|
373
401
|
meta: {
|
|
374
402
|
type: "problem",
|
|
@@ -377,65 +405,44 @@ var use_state_default = createRule({
|
|
|
377
405
|
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
378
406
|
},
|
|
379
407
|
messages: {
|
|
380
|
-
|
|
408
|
+
badValueOrSetterName: "An useState call is not destructured into value + setter pair."
|
|
381
409
|
},
|
|
382
410
|
schema: []
|
|
383
411
|
},
|
|
384
|
-
name:
|
|
412
|
+
name: RULE_NAME5,
|
|
385
413
|
create(context) {
|
|
386
|
-
const alias = getSettingsFromContext(context).additionalHooks.useState ?? [];
|
|
387
|
-
const {
|
|
388
|
-
ctx,
|
|
389
|
-
listeners
|
|
390
|
-
} = useComponentCollector(
|
|
391
|
-
context,
|
|
392
|
-
{
|
|
393
|
-
collectDisplayName: false,
|
|
394
|
-
collectHookCalls: true,
|
|
395
|
-
hint: DEFAULT_COMPONENT_HINT
|
|
396
|
-
}
|
|
397
|
-
);
|
|
398
414
|
return {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (!isSetterNameLoose(setState.name)) {
|
|
423
|
-
context.report({ messageId: "unexpected", node: id });
|
|
424
|
-
}
|
|
425
|
-
break;
|
|
426
|
-
}
|
|
427
|
-
if (state?.type !== AST_NODE_TYPES.Identifier || setState?.type !== AST_NODE_TYPES.Identifier) {
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
const [stateName, setStateName] = [state.name, setState.name];
|
|
431
|
-
const expectedSetterName = `set${capitalize(stateName)}`;
|
|
432
|
-
if (setStateName === expectedSetterName) {
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
context.report({ messageId: "unexpected", node: id });
|
|
436
|
-
}
|
|
415
|
+
"CallExpression[callee.name='useState']"(node) {
|
|
416
|
+
if (node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
|
|
417
|
+
context.report({ messageId: "badValueOrSetterName", node });
|
|
418
|
+
}
|
|
419
|
+
const id = getInstanceId(node);
|
|
420
|
+
if (id?.type !== AST_NODE_TYPES.ArrayPattern) {
|
|
421
|
+
context.report({ messageId: "badValueOrSetterName", node });
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const [value, setter] = id.elements;
|
|
425
|
+
if (value == null || setter == null) {
|
|
426
|
+
context.report({ messageId: "badValueOrSetterName", node });
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const setterName = match(setter).with({ type: AST_NODE_TYPES.Identifier }, (id2) => id2.name).otherwise(() => _);
|
|
430
|
+
if (setterName == null || !setterName.startsWith("set")) {
|
|
431
|
+
context.report({ messageId: "badValueOrSetterName", node });
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
const valueName = match(value).with({ type: AST_NODE_TYPES.Identifier }, (id2) => id2.name).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties }) => {
|
|
435
|
+
const values = properties.reduce((acc, prop) => {
|
|
436
|
+
if (prop.type === AST_NODE_TYPES.Property && prop.key.type === AST_NODE_TYPES.Identifier) {
|
|
437
|
+
return [...acc, prop.key.name];
|
|
437
438
|
}
|
|
438
|
-
|
|
439
|
+
return acc;
|
|
440
|
+
}, []);
|
|
441
|
+
return values.join("_");
|
|
442
|
+
}).otherwise(() => _);
|
|
443
|
+
if (valueName == null || `set_${valueName}` !== snakeCase(setterName)) {
|
|
444
|
+
context.report({ messageId: "badValueOrSetterName", node });
|
|
445
|
+
return;
|
|
439
446
|
}
|
|
440
447
|
}
|
|
441
448
|
};
|
|
@@ -451,6 +458,7 @@ var plugin = {
|
|
|
451
458
|
},
|
|
452
459
|
rules: {
|
|
453
460
|
"component-name": component_name_default,
|
|
461
|
+
"context-name": context_name_default,
|
|
454
462
|
filename: filename_default,
|
|
455
463
|
"filename-extension": filename_extension_default,
|
|
456
464
|
"use-state": use_state_default
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-naming-convention",
|
|
3
|
-
"version": "1.28.1-beta.
|
|
3
|
+
"version": "1.28.1-beta.7",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for naming convention related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -49,11 +49,12 @@
|
|
|
49
49
|
"@typescript-eslint/utils": "^8.25.0",
|
|
50
50
|
"string-ts": "^2.2.1",
|
|
51
51
|
"ts-pattern": "^5.6.2",
|
|
52
|
-
"@eslint-react/ast": "1.28.1-beta.
|
|
53
|
-
"@eslint-react/core": "1.28.1-beta.
|
|
54
|
-
"@eslint-react/eff": "1.28.1-beta.
|
|
55
|
-
"@eslint-react/jsx": "1.28.1-beta.
|
|
56
|
-
"@eslint-react/shared": "1.28.1-beta.
|
|
52
|
+
"@eslint-react/ast": "1.28.1-beta.7",
|
|
53
|
+
"@eslint-react/core": "1.28.1-beta.7",
|
|
54
|
+
"@eslint-react/eff": "1.28.1-beta.7",
|
|
55
|
+
"@eslint-react/jsx": "1.28.1-beta.7",
|
|
56
|
+
"@eslint-react/shared": "1.28.1-beta.7",
|
|
57
|
+
"@eslint-react/var": "1.28.1-beta.7"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
60
|
"@types/react": "^19.0.10",
|