eslint-plugin-react-naming-convention 1.23.3-next.8 → 1.24.0-next.0

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.
Files changed (3) hide show
  1. package/dist/index.js +43 -44
  2. package/dist/index.mjs +44 -45
  3. package/package.json +10 -10
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ var path__default = /*#__PURE__*/_interopDefault(path);
36
36
 
37
37
  // package.json
38
38
  var name = "eslint-plugin-react-naming-convention";
39
- var version = "1.23.3-next.8";
39
+ var version = "1.24.0-next.0";
40
40
  var createRule = shared.createRuleForPlugin("naming-convention");
41
41
 
42
42
  // src/rules/component-name.ts
@@ -78,11 +78,11 @@ var schema = [
78
78
  }
79
79
  ];
80
80
  function normalizeOptions(options) {
81
- const [opts] = options;
82
- if (eff.isNullable(opts)) {
81
+ const opts = options[0];
82
+ if (opts == null) {
83
83
  return defaultOptions[0];
84
84
  }
85
- if (eff.isString(opts)) {
85
+ if (typeof opts === "string") {
86
86
  return { ...defaultOptions[0], rule: opts };
87
87
  }
88
88
  return {
@@ -91,23 +91,24 @@ function normalizeOptions(options) {
91
91
  };
92
92
  }
93
93
  function validate(name2, options) {
94
+ if (name2 === eff._) return false;
94
95
  if (options.excepts.some((regex) => regex.test(name2))) {
95
96
  return true;
96
97
  }
97
98
  let normalized = name2.normalize("NFKD").replace(/[\u0300-\u036F]/g, "");
98
99
  normalized = normalized.split(".").at(-1) ?? normalized;
99
- if (options.allowNamespace) {
100
+ if (options.allowNamespace !== eff._) {
100
101
  normalized = normalized.replace(":", "");
101
102
  }
102
- if (options.allowLeadingUnderscore) {
103
+ if (options.allowLeadingUnderscore !== eff._) {
103
104
  normalized = normalized.replace(/^_/, "");
104
105
  }
105
106
  return tsPattern.match(options.rule).with("CONSTANT_CASE", () => shared.RE_CONSTANT_CASE.test(normalized)).with("PascalCase", () => {
106
107
  if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) {
107
- return options.allowAllCaps;
108
+ return !!options.allowAllCaps;
108
109
  }
109
110
  return shared.RE_PASCAL_CASE.test(normalized);
110
- }).otherwise(eff.F.constFalse);
111
+ }).otherwise(eff.returnFalse);
111
112
  }
112
113
  var component_name_default = createRule({
113
114
  meta: {
@@ -149,11 +150,8 @@ var component_name_default = createRule({
149
150
  const functionComponents = collector.ctx.getAllComponents(node);
150
151
  const classComponents = collectorLegacy.ctx.getAllComponents(node);
151
152
  for (const { node: component } of functionComponents.values()) {
152
- const mbId = AST__namespace.getFunctionIdentifier(component);
153
- if (eff.O.isNone(mbId)) {
154
- continue;
155
- }
156
- const id = mbId.value;
153
+ const id = AST__namespace.getFunctionIdentifier(component);
154
+ if (id?.name === eff._) continue;
157
155
  if (validate(id.name, options)) {
158
156
  continue;
159
157
  }
@@ -166,19 +164,17 @@ var component_name_default = createRule({
166
164
  });
167
165
  }
168
166
  for (const { node: component } of classComponents.values()) {
169
- eff.F.pipe(
170
- AST__namespace.getClassIdentifier(component),
171
- eff.O.filter((id) => !validate(id.name, options)),
172
- eff.O.map((id) => {
173
- context.report({
174
- messageId: "componentName",
175
- node: id,
176
- data: {
177
- case: options.rule
178
- }
179
- });
180
- })
181
- );
167
+ const id = AST__namespace.getClassIdentifier(component);
168
+ if (id?.name === eff._) continue;
169
+ if (!validate(id.name, options)) {
170
+ context.report({
171
+ messageId: "componentName",
172
+ node: id,
173
+ data: {
174
+ case: options.rule
175
+ }
176
+ });
177
+ }
182
178
  }
183
179
  }
184
180
  };
@@ -239,13 +235,11 @@ var filename_default = createRule({
239
235
  name: RULE_NAME2,
240
236
  create(context) {
241
237
  const options = context.options[0] ?? defaultOptions2[0];
242
- const rule = eff.isString(options) ? options : options.rule ?? "PascalCase";
243
- const excepts = eff.isString(options) ? [] : options.excepts ?? [];
244
- const filename = context.filename;
238
+ const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
239
+ const excepts = typeof options === "string" ? [] : options.excepts ?? [];
245
240
  function validate2(name2, casing = rule, ignores = excepts) {
246
- if (ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2))) {
247
- return true;
248
- }
241
+ const shouldIgnore = ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2));
242
+ if (shouldIgnore) return true;
249
243
  return tsPattern.match(casing).with("PascalCase", () => shared.RE_PASCAL_CASE.test(name2)).with("camelCase", () => shared.RE_CAMEL_CASE.test(name2)).with("kebab-case", () => shared.RE_KEBAB_CASE.test(name2)).with("snake_case", () => shared.RE_SNAKE_CASE.test(name2)).exhaustive();
250
244
  }
251
245
  function getSuggestion(name2, casing = rule) {
@@ -265,7 +259,7 @@ var filename_default = createRule({
265
259
  messageId: "filenameCaseMismatchSuggestion",
266
260
  node,
267
261
  data: {
268
- name: filename,
262
+ name: context.filename,
269
263
  rule,
270
264
  suggestion: [getSuggestion(basename), ...rest].join(".")
271
265
  }
@@ -404,25 +398,30 @@ var use_state_default = createRule({
404
398
  continue;
405
399
  }
406
400
  const { id } = hookCall.parent;
407
- const descriptor = eff.O.some({ messageId: "useState", node: id });
408
- eff.F.pipe(
409
- tsPattern.match(id).with({ type: types.AST_NODE_TYPES.Identifier }, eff.F.constant(descriptor)).with({ type: types.AST_NODE_TYPES.ArrayPattern }, (n) => {
410
- const [state, setState] = n.elements;
401
+ switch (id.type) {
402
+ case types.AST_NODE_TYPES.Identifier: {
403
+ context.report({ messageId: "useState", node: id });
404
+ break;
405
+ }
406
+ case types.AST_NODE_TYPES.ArrayPattern: {
407
+ const [state, setState] = id.elements;
411
408
  if (state?.type === types.AST_NODE_TYPES.ObjectPattern && setState?.type === types.AST_NODE_TYPES.Identifier) {
412
- return isSetterNameLoose(setState.name) ? eff.O.none() : descriptor;
409
+ if (!isSetterNameLoose(setState.name)) {
410
+ context.report({ messageId: "useState", node: id });
411
+ }
412
+ break;
413
413
  }
414
414
  if (state?.type !== types.AST_NODE_TYPES.Identifier || setState?.type !== types.AST_NODE_TYPES.Identifier) {
415
- return eff.O.none();
415
+ return;
416
416
  }
417
417
  const [stateName, setStateName] = [state.name, setState.name];
418
418
  const expectedSetterName = `set${stringTs.capitalize(stateName)}`;
419
419
  if (setStateName === expectedSetterName) {
420
- return eff.O.none();
420
+ return;
421
421
  }
422
- return descriptor;
423
- }).otherwise(eff.O.none),
424
- eff.O.map(context.report)
425
- );
422
+ context.report({ messageId: "useState", node: id });
423
+ }
424
+ }
426
425
  }
427
426
  }
428
427
  }
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as AST from '@eslint-react/ast';
2
2
  import { useComponentCollector, useComponentCollectorLegacy, isUseStateCall, isReactHookCallWithNameLoose } from '@eslint-react/core';
3
- import { O, F, isString, isObject, isNullable } from '@eslint-react/eff';
3
+ import { _, isObject, returnFalse } from '@eslint-react/eff';
4
4
  import * as JSX from '@eslint-react/jsx';
5
5
  import { createRuleForPlugin, getSettingsFromContext, RE_CONSTANT_CASE, RE_PASCAL_CASE, RE_CAMEL_CASE, RE_KEBAB_CASE, RE_SNAKE_CASE } from '@eslint-react/shared';
6
6
  import { match } from 'ts-pattern';
@@ -10,7 +10,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/types';
10
10
 
11
11
  // package.json
12
12
  var name = "eslint-plugin-react-naming-convention";
13
- var version = "1.23.3-next.8";
13
+ var version = "1.24.0-next.0";
14
14
  var createRule = createRuleForPlugin("naming-convention");
15
15
 
16
16
  // src/rules/component-name.ts
@@ -52,11 +52,11 @@ var schema = [
52
52
  }
53
53
  ];
54
54
  function normalizeOptions(options) {
55
- const [opts] = options;
56
- if (isNullable(opts)) {
55
+ const opts = options[0];
56
+ if (opts == null) {
57
57
  return defaultOptions[0];
58
58
  }
59
- if (isString(opts)) {
59
+ if (typeof opts === "string") {
60
60
  return { ...defaultOptions[0], rule: opts };
61
61
  }
62
62
  return {
@@ -65,23 +65,24 @@ function normalizeOptions(options) {
65
65
  };
66
66
  }
67
67
  function validate(name2, options) {
68
+ if (name2 === _) return false;
68
69
  if (options.excepts.some((regex) => regex.test(name2))) {
69
70
  return true;
70
71
  }
71
72
  let normalized = name2.normalize("NFKD").replace(/[\u0300-\u036F]/g, "");
72
73
  normalized = normalized.split(".").at(-1) ?? normalized;
73
- if (options.allowNamespace) {
74
+ if (options.allowNamespace !== _) {
74
75
  normalized = normalized.replace(":", "");
75
76
  }
76
- if (options.allowLeadingUnderscore) {
77
+ if (options.allowLeadingUnderscore !== _) {
77
78
  normalized = normalized.replace(/^_/, "");
78
79
  }
79
80
  return match(options.rule).with("CONSTANT_CASE", () => RE_CONSTANT_CASE.test(normalized)).with("PascalCase", () => {
80
81
  if (normalized.length > 3 && /^[A-Z]+$/u.test(normalized)) {
81
- return options.allowAllCaps;
82
+ return !!options.allowAllCaps;
82
83
  }
83
84
  return RE_PASCAL_CASE.test(normalized);
84
- }).otherwise(F.constFalse);
85
+ }).otherwise(returnFalse);
85
86
  }
86
87
  var component_name_default = createRule({
87
88
  meta: {
@@ -123,11 +124,8 @@ var component_name_default = createRule({
123
124
  const functionComponents = collector.ctx.getAllComponents(node);
124
125
  const classComponents = collectorLegacy.ctx.getAllComponents(node);
125
126
  for (const { node: component } of functionComponents.values()) {
126
- const mbId = AST.getFunctionIdentifier(component);
127
- if (O.isNone(mbId)) {
128
- continue;
129
- }
130
- const id = mbId.value;
127
+ const id = AST.getFunctionIdentifier(component);
128
+ if (id?.name === _) continue;
131
129
  if (validate(id.name, options)) {
132
130
  continue;
133
131
  }
@@ -140,19 +138,17 @@ var component_name_default = createRule({
140
138
  });
141
139
  }
142
140
  for (const { node: component } of classComponents.values()) {
143
- F.pipe(
144
- AST.getClassIdentifier(component),
145
- O.filter((id) => !validate(id.name, options)),
146
- O.map((id) => {
147
- context.report({
148
- messageId: "componentName",
149
- node: id,
150
- data: {
151
- case: options.rule
152
- }
153
- });
154
- })
155
- );
141
+ const id = AST.getClassIdentifier(component);
142
+ if (id?.name === _) continue;
143
+ if (!validate(id.name, options)) {
144
+ context.report({
145
+ messageId: "componentName",
146
+ node: id,
147
+ data: {
148
+ case: options.rule
149
+ }
150
+ });
151
+ }
156
152
  }
157
153
  }
158
154
  };
@@ -213,13 +209,11 @@ var filename_default = createRule({
213
209
  name: RULE_NAME2,
214
210
  create(context) {
215
211
  const options = context.options[0] ?? defaultOptions2[0];
216
- const rule = isString(options) ? options : options.rule ?? "PascalCase";
217
- const excepts = isString(options) ? [] : options.excepts ?? [];
218
- const filename = context.filename;
212
+ const rule = typeof options === "string" ? options : options.rule ?? "PascalCase";
213
+ const excepts = typeof options === "string" ? [] : options.excepts ?? [];
219
214
  function validate2(name2, casing = rule, ignores = excepts) {
220
- if (ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2))) {
221
- return true;
222
- }
215
+ const shouldIgnore = ignores.map((pattern) => new RegExp(pattern, "u")).some((pattern) => pattern.test(name2));
216
+ if (shouldIgnore) return true;
223
217
  return match(casing).with("PascalCase", () => RE_PASCAL_CASE.test(name2)).with("camelCase", () => RE_CAMEL_CASE.test(name2)).with("kebab-case", () => RE_KEBAB_CASE.test(name2)).with("snake_case", () => RE_SNAKE_CASE.test(name2)).exhaustive();
224
218
  }
225
219
  function getSuggestion(name2, casing = rule) {
@@ -239,7 +233,7 @@ var filename_default = createRule({
239
233
  messageId: "filenameCaseMismatchSuggestion",
240
234
  node,
241
235
  data: {
242
- name: filename,
236
+ name: context.filename,
243
237
  rule,
244
238
  suggestion: [getSuggestion(basename), ...rest].join(".")
245
239
  }
@@ -378,25 +372,30 @@ var use_state_default = createRule({
378
372
  continue;
379
373
  }
380
374
  const { id } = hookCall.parent;
381
- const descriptor = O.some({ messageId: "useState", node: id });
382
- F.pipe(
383
- match(id).with({ type: AST_NODE_TYPES.Identifier }, F.constant(descriptor)).with({ type: AST_NODE_TYPES.ArrayPattern }, (n) => {
384
- const [state, setState] = n.elements;
375
+ switch (id.type) {
376
+ case AST_NODE_TYPES.Identifier: {
377
+ context.report({ messageId: "useState", node: id });
378
+ break;
379
+ }
380
+ case AST_NODE_TYPES.ArrayPattern: {
381
+ const [state, setState] = id.elements;
385
382
  if (state?.type === AST_NODE_TYPES.ObjectPattern && setState?.type === AST_NODE_TYPES.Identifier) {
386
- return isSetterNameLoose(setState.name) ? O.none() : descriptor;
383
+ if (!isSetterNameLoose(setState.name)) {
384
+ context.report({ messageId: "useState", node: id });
385
+ }
386
+ break;
387
387
  }
388
388
  if (state?.type !== AST_NODE_TYPES.Identifier || setState?.type !== AST_NODE_TYPES.Identifier) {
389
- return O.none();
389
+ return;
390
390
  }
391
391
  const [stateName, setStateName] = [state.name, setState.name];
392
392
  const expectedSetterName = `set${capitalize(stateName)}`;
393
393
  if (setStateName === expectedSetterName) {
394
- return O.none();
394
+ return;
395
395
  }
396
- return descriptor;
397
- }).otherwise(O.none),
398
- O.map(context.report)
399
- );
396
+ context.report({ messageId: "useState", node: id });
397
+ }
398
+ }
400
399
  }
401
400
  }
402
401
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-naming-convention",
3
- "version": "1.23.3-next.8",
3
+ "version": "1.24.0-next.0",
4
4
  "description": "ESLint React's ESLint plugin for naming convention related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -10,13 +10,13 @@
10
10
  "eslint-plugin",
11
11
  "eslint-plugin-react-naming-convention"
12
12
  ],
13
- "homepage": "https://github.com/rEl1cx/eslint-react",
13
+ "homepage": "https://github.com/Rel1cx/eslint-react",
14
14
  "bugs": {
15
- "url": "https://github.com/rEl1cx/eslint-react/issues"
15
+ "url": "https://github.com/Rel1cx/eslint-react/issues"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "git+https://github.com/rEl1cx/eslint-react.git",
19
+ "url": "git+https://github.com/Rel1cx/eslint-react.git",
20
20
  "directory": "packages/plugins/eslint-plugin-react-naming-convention"
21
21
  },
22
22
  "license": "MIT",
@@ -47,12 +47,12 @@
47
47
  "@typescript-eslint/utils": "^8.19.1",
48
48
  "string-ts": "^2.2.0",
49
49
  "ts-pattern": "^5.6.0",
50
- "@eslint-react/ast": "1.23.3-next.8",
51
- "@eslint-react/core": "1.23.3-next.8",
52
- "@eslint-react/eff": "1.23.3-next.8",
53
- "@eslint-react/shared": "1.23.3-next.8",
54
- "@eslint-react/jsx": "1.23.3-next.8",
55
- "@eslint-react/types": "1.23.3-next.8"
50
+ "@eslint-react/ast": "1.24.0-next.0",
51
+ "@eslint-react/core": "1.24.0-next.0",
52
+ "@eslint-react/eff": "1.24.0-next.0",
53
+ "@eslint-react/jsx": "1.24.0-next.0",
54
+ "@eslint-react/shared": "1.24.0-next.0",
55
+ "@eslint-react/types": "1.24.0-next.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/react": "^19.0.4",