eslint-plugin-nextfriday 3.2.0 → 3.2.1
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/CHANGELOG.md +6 -0
- package/docs/rules/ENFORCE_CONSTANT_CASE.md +28 -17
- package/lib/index.cjs +14 -47
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +14 -47
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "eslint-plugin-nextfriday",
|
|
4
|
-
version: "3.2.
|
|
4
|
+
version: "3.2.1",
|
|
5
5
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
6
6
|
keywords: [
|
|
7
7
|
"eslint",
|
|
@@ -408,40 +408,14 @@ var createRule3 = ESLintUtils3.RuleCreator(
|
|
|
408
408
|
);
|
|
409
409
|
var SCREAMING_SNAKE_CASE_REGEX = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
410
410
|
var SNAKE_CASE_REGEX2 = /^[a-z]+_[a-z0-9_]*$/;
|
|
411
|
-
var BOOLEAN_PREFIXES2 = ["is", "has", "should", "can", "did", "will", "was", "are", "does", "had"];
|
|
412
411
|
var toScreamingSnakeCase = (str) => str.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toUpperCase();
|
|
413
|
-
var
|
|
414
|
-
if (!name.startsWith(prefix)) {
|
|
415
|
-
return false;
|
|
416
|
-
}
|
|
417
|
-
if (name.length === prefix.length) {
|
|
418
|
-
return true;
|
|
419
|
-
}
|
|
420
|
-
const nextChar = name.charAt(prefix.length);
|
|
421
|
-
return nextChar === nextChar.toUpperCase() && nextChar !== nextChar.toLowerCase();
|
|
422
|
-
});
|
|
423
|
-
var isBooleanLiteral2 = (init) => init.type === AST_NODE_TYPES4.Literal && typeof init.value === "boolean";
|
|
424
|
-
var isAsConstAssertion = (node) => node.type === AST_NODE_TYPES4.TSAsExpression && node.typeAnnotation.type === AST_NODE_TYPES4.TSTypeReference && node.typeAnnotation.typeName.type === AST_NODE_TYPES4.Identifier && node.typeAnnotation.typeName.name === "const";
|
|
425
|
-
var isStaticValue2 = (init) => {
|
|
426
|
-
if (isAsConstAssertion(init)) {
|
|
427
|
-
return true;
|
|
428
|
-
}
|
|
412
|
+
var isMagicLiteral = (init) => {
|
|
429
413
|
if (init.type === AST_NODE_TYPES4.Literal) {
|
|
430
|
-
return
|
|
414
|
+
return typeof init.value === "string" || typeof init.value === "number";
|
|
431
415
|
}
|
|
432
|
-
if (init.type === AST_NODE_TYPES4.UnaryExpression
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
if (init.type === AST_NODE_TYPES4.TemplateLiteral && init.expressions.length === 0) {
|
|
436
|
-
return true;
|
|
437
|
-
}
|
|
438
|
-
if (init.type === AST_NODE_TYPES4.ArrayExpression) {
|
|
439
|
-
return init.elements.every((el) => el !== null && el.type !== AST_NODE_TYPES4.SpreadElement && isStaticValue2(el));
|
|
440
|
-
}
|
|
441
|
-
if (init.type === AST_NODE_TYPES4.ObjectExpression) {
|
|
442
|
-
return init.properties.every(
|
|
443
|
-
(prop) => prop.type === AST_NODE_TYPES4.Property && isStaticValue2(prop.value)
|
|
444
|
-
);
|
|
416
|
+
if (init.type === AST_NODE_TYPES4.UnaryExpression) {
|
|
417
|
+
const { argument, operator } = init;
|
|
418
|
+
return (operator === "-" || operator === "+") && argument.type === AST_NODE_TYPES4.Literal && typeof argument.value === "number";
|
|
445
419
|
}
|
|
446
420
|
return false;
|
|
447
421
|
};
|
|
@@ -455,13 +429,12 @@ var isGlobalScope2 = (node) => {
|
|
|
455
429
|
}
|
|
456
430
|
return false;
|
|
457
431
|
};
|
|
458
|
-
var isFunctionOrComponent = (init) => init.type === AST_NODE_TYPES4.ArrowFunctionExpression || init.type === AST_NODE_TYPES4.FunctionExpression;
|
|
459
432
|
var enforceConstantCase = createRule3({
|
|
460
433
|
name: "enforce-constant-case",
|
|
461
434
|
meta: {
|
|
462
435
|
type: "suggestion",
|
|
463
436
|
docs: {
|
|
464
|
-
description: "Enforce SCREAMING_SNAKE_CASE for global
|
|
437
|
+
description: "Enforce SCREAMING_SNAKE_CASE for global magic-number and magic-text constants"
|
|
465
438
|
},
|
|
466
439
|
messages: {
|
|
467
440
|
useScreamingSnakeCase: "Constant '{{ name }}' should use SCREAMING_SNAKE_CASE. Rename to '{{ suggestion }}'.",
|
|
@@ -483,16 +456,10 @@ var enforceConstantCase = createRule3({
|
|
|
483
456
|
if (declarator.id.type !== AST_NODE_TYPES4.Identifier || !declarator.init) {
|
|
484
457
|
return;
|
|
485
458
|
}
|
|
486
|
-
if (
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
if (!isStaticValue2(declarator.init)) {
|
|
459
|
+
if (!isMagicLiteral(declarator.init)) {
|
|
490
460
|
return;
|
|
491
461
|
}
|
|
492
462
|
const { name } = declarator.id;
|
|
493
|
-
if (isBooleanLiteral2(declarator.init) && startsWithBooleanPrefix2(name)) {
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
463
|
if (SNAKE_CASE_REGEX2.test(name)) {
|
|
497
464
|
context.report({
|
|
498
465
|
node: declarator.id,
|
|
@@ -2822,9 +2789,9 @@ var createRule38 = ESLintUtils38.RuleCreator(
|
|
|
2822
2789
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2823
2790
|
);
|
|
2824
2791
|
var SCREAMING_SNAKE_CASE_REGEX3 = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
2825
|
-
var
|
|
2826
|
-
var
|
|
2827
|
-
if (
|
|
2792
|
+
var isAsConstAssertion = (node) => node.type === AST_NODE_TYPES36.TSAsExpression && node.typeAnnotation.type === AST_NODE_TYPES36.TSTypeReference && node.typeAnnotation.typeName.type === AST_NODE_TYPES36.Identifier && node.typeAnnotation.typeName.name === "const";
|
|
2793
|
+
var isStaticValue2 = (init) => {
|
|
2794
|
+
if (isAsConstAssertion(init)) {
|
|
2828
2795
|
return true;
|
|
2829
2796
|
}
|
|
2830
2797
|
if (init.type === AST_NODE_TYPES36.Literal) {
|
|
@@ -2837,11 +2804,11 @@ var isStaticValue3 = (init) => {
|
|
|
2837
2804
|
return true;
|
|
2838
2805
|
}
|
|
2839
2806
|
if (init.type === AST_NODE_TYPES36.ArrayExpression) {
|
|
2840
|
-
return init.elements.every((el) => el !== null && el.type !== AST_NODE_TYPES36.SpreadElement &&
|
|
2807
|
+
return init.elements.every((el) => el !== null && el.type !== AST_NODE_TYPES36.SpreadElement && isStaticValue2(el));
|
|
2841
2808
|
}
|
|
2842
2809
|
if (init.type === AST_NODE_TYPES36.ObjectExpression) {
|
|
2843
2810
|
return init.properties.every(
|
|
2844
|
-
(prop) => prop.type === AST_NODE_TYPES36.Property &&
|
|
2811
|
+
(prop) => prop.type === AST_NODE_TYPES36.Property && isStaticValue2(prop.value)
|
|
2845
2812
|
);
|
|
2846
2813
|
}
|
|
2847
2814
|
return false;
|
|
@@ -2901,7 +2868,7 @@ var noMisleadingConstantCase = createRule38({
|
|
|
2901
2868
|
if (!declarator.init) {
|
|
2902
2869
|
return;
|
|
2903
2870
|
}
|
|
2904
|
-
if (!
|
|
2871
|
+
if (!isStaticValue2(declarator.init)) {
|
|
2905
2872
|
context.report({
|
|
2906
2873
|
node: declarator.id,
|
|
2907
2874
|
messageId: "dynamicScreamingCase",
|