eslint-plugin-nextfriday 1.4.0 → 1.5.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.
- package/CHANGELOG.md +6 -0
- package/README.md +3 -0
- package/docs/rules/NO_ENV_FALLBACK.md +53 -0
- package/lib/index.cjs +136 -80
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +14 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +137 -81
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
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: "1.
|
|
4
|
+
version: "1.5.0",
|
|
5
5
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
6
6
|
keywords: [
|
|
7
7
|
"eslint",
|
|
@@ -51,8 +51,8 @@ var package_default = {
|
|
|
51
51
|
"changeset:publish": "npm publish --provenance --access public",
|
|
52
52
|
"changeset:version": "changeset version",
|
|
53
53
|
clear: "rm -rf lib node_modules/.cache .eslintcache",
|
|
54
|
-
eslint: "eslint src --ext .js,.ts
|
|
55
|
-
"eslint:check": "eslint src --ext .js,.ts
|
|
54
|
+
eslint: "eslint src --ext .js,.ts --fix",
|
|
55
|
+
"eslint:check": "eslint src --ext .js,.ts",
|
|
56
56
|
preinstall: "npx only-allow pnpm",
|
|
57
57
|
prepare: "husky",
|
|
58
58
|
prepublishOnly: "pnpm run build",
|
|
@@ -426,12 +426,65 @@ var noEmoji = createRule6({
|
|
|
426
426
|
});
|
|
427
427
|
var no_emoji_default = noEmoji;
|
|
428
428
|
|
|
429
|
-
// src/rules/no-
|
|
430
|
-
import { ESLintUtils as ESLintUtils7 } from "@typescript-eslint/utils";
|
|
429
|
+
// src/rules/no-env-fallback.ts
|
|
430
|
+
import { ESLintUtils as ESLintUtils7, AST_NODE_TYPES as AST_NODE_TYPES3 } from "@typescript-eslint/utils";
|
|
431
431
|
var createRule7 = ESLintUtils7.RuleCreator(
|
|
432
432
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
433
433
|
);
|
|
434
|
-
var
|
|
434
|
+
var noEnvFallback = createRule7({
|
|
435
|
+
name: "no-env-fallback",
|
|
436
|
+
meta: {
|
|
437
|
+
type: "problem",
|
|
438
|
+
docs: {
|
|
439
|
+
description: "Disallow fallback values for environment variables as they can be dangerous in production"
|
|
440
|
+
},
|
|
441
|
+
messages: {
|
|
442
|
+
noEnvFallback: "Avoid using fallback values with process.env. Environment variables should fail explicitly when missing rather than silently using a default value."
|
|
443
|
+
},
|
|
444
|
+
schema: []
|
|
445
|
+
},
|
|
446
|
+
defaultOptions: [],
|
|
447
|
+
create(context) {
|
|
448
|
+
const isProcessEnvAccess = (node) => {
|
|
449
|
+
if (node.type !== AST_NODE_TYPES3.MemberExpression) {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
const { object } = node;
|
|
453
|
+
if (object.type !== AST_NODE_TYPES3.MemberExpression) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
const processNode = object.object;
|
|
457
|
+
const envNode = object.property;
|
|
458
|
+
return processNode.type === AST_NODE_TYPES3.Identifier && processNode.name === "process" && envNode.type === AST_NODE_TYPES3.Identifier && envNode.name === "env";
|
|
459
|
+
};
|
|
460
|
+
return {
|
|
461
|
+
LogicalExpression(node) {
|
|
462
|
+
if ((node.operator === "||" || node.operator === "??") && isProcessEnvAccess(node.left)) {
|
|
463
|
+
context.report({
|
|
464
|
+
node,
|
|
465
|
+
messageId: "noEnvFallback"
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
ConditionalExpression(node) {
|
|
470
|
+
if (isProcessEnvAccess(node.test)) {
|
|
471
|
+
context.report({
|
|
472
|
+
node,
|
|
473
|
+
messageId: "noEnvFallback"
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
var no_env_fallback_default = noEnvFallback;
|
|
481
|
+
|
|
482
|
+
// src/rules/no-explicit-return-type.ts
|
|
483
|
+
import { ESLintUtils as ESLintUtils8 } from "@typescript-eslint/utils";
|
|
484
|
+
var createRule8 = ESLintUtils8.RuleCreator(
|
|
485
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
486
|
+
);
|
|
487
|
+
var noExplicitReturnType = createRule8({
|
|
435
488
|
name: "no-explicit-return-type",
|
|
436
489
|
meta: {
|
|
437
490
|
type: "suggestion",
|
|
@@ -471,11 +524,11 @@ var noExplicitReturnType = createRule7({
|
|
|
471
524
|
var no_explicit_return_type_default = noExplicitReturnType;
|
|
472
525
|
|
|
473
526
|
// src/rules/no-logic-in-params.ts
|
|
474
|
-
import { ESLintUtils as
|
|
475
|
-
var
|
|
527
|
+
import { ESLintUtils as ESLintUtils9, AST_NODE_TYPES as AST_NODE_TYPES4 } from "@typescript-eslint/utils";
|
|
528
|
+
var createRule9 = ESLintUtils9.RuleCreator(
|
|
476
529
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
477
530
|
);
|
|
478
|
-
var noLogicInParams =
|
|
531
|
+
var noLogicInParams = createRule9({
|
|
479
532
|
name: "no-logic-in-params",
|
|
480
533
|
meta: {
|
|
481
534
|
type: "suggestion",
|
|
@@ -490,20 +543,20 @@ var noLogicInParams = createRule8({
|
|
|
490
543
|
defaultOptions: [],
|
|
491
544
|
create(context) {
|
|
492
545
|
const isComplexExpression = (node) => {
|
|
493
|
-
if (node.type ===
|
|
546
|
+
if (node.type === AST_NODE_TYPES4.SpreadElement) {
|
|
494
547
|
return false;
|
|
495
548
|
}
|
|
496
|
-
if (node.type ===
|
|
549
|
+
if (node.type === AST_NODE_TYPES4.ConditionalExpression) {
|
|
497
550
|
return true;
|
|
498
551
|
}
|
|
499
|
-
if (node.type ===
|
|
552
|
+
if (node.type === AST_NODE_TYPES4.LogicalExpression) {
|
|
500
553
|
return true;
|
|
501
554
|
}
|
|
502
|
-
if (node.type ===
|
|
555
|
+
if (node.type === AST_NODE_TYPES4.BinaryExpression) {
|
|
503
556
|
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
504
557
|
return logicalOperators.includes(node.operator);
|
|
505
558
|
}
|
|
506
|
-
if (node.type ===
|
|
559
|
+
if (node.type === AST_NODE_TYPES4.UnaryExpression) {
|
|
507
560
|
return node.operator === "!";
|
|
508
561
|
}
|
|
509
562
|
return false;
|
|
@@ -535,11 +588,11 @@ var noLogicInParams = createRule8({
|
|
|
535
588
|
var no_logic_in_params_default = noLogicInParams;
|
|
536
589
|
|
|
537
590
|
// src/rules/prefer-destructuring-params.ts
|
|
538
|
-
import { AST_NODE_TYPES as
|
|
539
|
-
var
|
|
591
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES5, ESLintUtils as ESLintUtils10 } from "@typescript-eslint/utils";
|
|
592
|
+
var createRule10 = ESLintUtils10.RuleCreator(
|
|
540
593
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
541
594
|
);
|
|
542
|
-
var preferDestructuringParams =
|
|
595
|
+
var preferDestructuringParams = createRule10({
|
|
543
596
|
name: "prefer-destructuring-params",
|
|
544
597
|
meta: {
|
|
545
598
|
type: "suggestion",
|
|
@@ -555,18 +608,18 @@ var preferDestructuringParams = createRule9({
|
|
|
555
608
|
create(context) {
|
|
556
609
|
const isCallbackFunction = (node) => {
|
|
557
610
|
const { parent } = node;
|
|
558
|
-
return parent?.type ===
|
|
611
|
+
return parent?.type === AST_NODE_TYPES5.CallExpression;
|
|
559
612
|
};
|
|
560
613
|
const isDeveloperFunction = (node) => {
|
|
561
|
-
if (node.type ===
|
|
614
|
+
if (node.type === AST_NODE_TYPES5.FunctionDeclaration) {
|
|
562
615
|
return true;
|
|
563
616
|
}
|
|
564
|
-
if (node.type ===
|
|
617
|
+
if (node.type === AST_NODE_TYPES5.FunctionExpression || node.type === AST_NODE_TYPES5.ArrowFunctionExpression) {
|
|
565
618
|
if (isCallbackFunction(node)) {
|
|
566
619
|
return false;
|
|
567
620
|
}
|
|
568
621
|
const { parent } = node;
|
|
569
|
-
return parent?.type ===
|
|
622
|
+
return parent?.type === AST_NODE_TYPES5.VariableDeclarator || parent?.type === AST_NODE_TYPES5.AssignmentExpression || parent?.type === AST_NODE_TYPES5.Property || parent?.type === AST_NODE_TYPES5.MethodDefinition;
|
|
570
623
|
}
|
|
571
624
|
return false;
|
|
572
625
|
};
|
|
@@ -578,7 +631,7 @@ var preferDestructuringParams = createRule9({
|
|
|
578
631
|
if (!isDeveloperFunction(node)) {
|
|
579
632
|
return;
|
|
580
633
|
}
|
|
581
|
-
if (node.type ===
|
|
634
|
+
if (node.type === AST_NODE_TYPES5.FunctionDeclaration && node.id) {
|
|
582
635
|
const functionName = node.id.name;
|
|
583
636
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
584
637
|
return;
|
|
@@ -588,7 +641,7 @@ var preferDestructuringParams = createRule9({
|
|
|
588
641
|
return;
|
|
589
642
|
}
|
|
590
643
|
const hasNonDestructuredParams = node.params.some(
|
|
591
|
-
(param) => param.type !==
|
|
644
|
+
(param) => param.type !== AST_NODE_TYPES5.ObjectPattern && param.type !== AST_NODE_TYPES5.RestElement
|
|
592
645
|
);
|
|
593
646
|
if (hasNonDestructuredParams) {
|
|
594
647
|
context.report({
|
|
@@ -607,11 +660,11 @@ var preferDestructuringParams = createRule9({
|
|
|
607
660
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
608
661
|
|
|
609
662
|
// src/rules/prefer-import-type.ts
|
|
610
|
-
import { AST_NODE_TYPES as
|
|
611
|
-
var
|
|
663
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES6, ESLintUtils as ESLintUtils11 } from "@typescript-eslint/utils";
|
|
664
|
+
var createRule11 = ESLintUtils11.RuleCreator(
|
|
612
665
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
613
666
|
);
|
|
614
|
-
var preferImportType =
|
|
667
|
+
var preferImportType = createRule11({
|
|
615
668
|
name: "prefer-import-type",
|
|
616
669
|
meta: {
|
|
617
670
|
type: "suggestion",
|
|
@@ -642,14 +695,14 @@ var preferImportType = createRule10({
|
|
|
642
695
|
return;
|
|
643
696
|
}
|
|
644
697
|
const isTypeOnlyImport = node.specifiers.every((specifier) => {
|
|
645
|
-
if (specifier.type ===
|
|
698
|
+
if (specifier.type === AST_NODE_TYPES6.ImportDefaultSpecifier) {
|
|
646
699
|
return false;
|
|
647
700
|
}
|
|
648
|
-
if (specifier.type ===
|
|
701
|
+
if (specifier.type === AST_NODE_TYPES6.ImportNamespaceSpecifier) {
|
|
649
702
|
return false;
|
|
650
703
|
}
|
|
651
|
-
if (specifier.type ===
|
|
652
|
-
const importedName = specifier.imported.type ===
|
|
704
|
+
if (specifier.type === AST_NODE_TYPES6.ImportSpecifier) {
|
|
705
|
+
const importedName = specifier.imported.type === AST_NODE_TYPES6.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
653
706
|
const isKnownTypeOnly = node.source.value === "@typescript-eslint/utils" && ["TSESTree", "RuleContext"].includes(importedName) || node.source.value === "react" && ["Component", "ComponentProps", "ReactNode", "FC", "JSX", "ReactElement", "PropsWithChildren"].includes(
|
|
654
707
|
importedName
|
|
655
708
|
) || importedName.endsWith("Type") || importedName.endsWith("Interface") || importedName.endsWith("Props");
|
|
@@ -677,11 +730,11 @@ var preferImportType = createRule10({
|
|
|
677
730
|
var prefer_import_type_default = preferImportType;
|
|
678
731
|
|
|
679
732
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
680
|
-
import { AST_NODE_TYPES as
|
|
681
|
-
var
|
|
733
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES7, ESLintUtils as ESLintUtils12 } from "@typescript-eslint/utils";
|
|
734
|
+
var createRule12 = ESLintUtils12.RuleCreator(
|
|
682
735
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
683
736
|
);
|
|
684
|
-
var preferInterfaceOverInlineTypes =
|
|
737
|
+
var preferInterfaceOverInlineTypes = createRule12({
|
|
685
738
|
name: "prefer-interface-over-inline-types",
|
|
686
739
|
meta: {
|
|
687
740
|
type: "suggestion",
|
|
@@ -697,54 +750,54 @@ var preferInterfaceOverInlineTypes = createRule11({
|
|
|
697
750
|
defaultOptions: [],
|
|
698
751
|
create(context) {
|
|
699
752
|
function hasJSXInConditional(node) {
|
|
700
|
-
return node.consequent.type ===
|
|
753
|
+
return node.consequent.type === AST_NODE_TYPES7.JSXElement || node.consequent.type === AST_NODE_TYPES7.JSXFragment || node.alternate.type === AST_NODE_TYPES7.JSXElement || node.alternate.type === AST_NODE_TYPES7.JSXFragment;
|
|
701
754
|
}
|
|
702
755
|
function hasJSXInLogical(node) {
|
|
703
|
-
return node.right.type ===
|
|
756
|
+
return node.right.type === AST_NODE_TYPES7.JSXElement || node.right.type === AST_NODE_TYPES7.JSXFragment;
|
|
704
757
|
}
|
|
705
758
|
function hasJSXReturn(block) {
|
|
706
759
|
return block.body.some((stmt) => {
|
|
707
|
-
if (stmt.type ===
|
|
708
|
-
return stmt.argument.type ===
|
|
760
|
+
if (stmt.type === AST_NODE_TYPES7.ReturnStatement && stmt.argument) {
|
|
761
|
+
return stmt.argument.type === AST_NODE_TYPES7.JSXElement || stmt.argument.type === AST_NODE_TYPES7.JSXFragment || stmt.argument.type === AST_NODE_TYPES7.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES7.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
709
762
|
}
|
|
710
763
|
return false;
|
|
711
764
|
});
|
|
712
765
|
}
|
|
713
766
|
function isReactComponent(node) {
|
|
714
|
-
if (node.type ===
|
|
715
|
-
if (node.body.type ===
|
|
767
|
+
if (node.type === AST_NODE_TYPES7.ArrowFunctionExpression) {
|
|
768
|
+
if (node.body.type === AST_NODE_TYPES7.JSXElement || node.body.type === AST_NODE_TYPES7.JSXFragment) {
|
|
716
769
|
return true;
|
|
717
770
|
}
|
|
718
|
-
if (node.body.type ===
|
|
771
|
+
if (node.body.type === AST_NODE_TYPES7.BlockStatement) {
|
|
719
772
|
return hasJSXReturn(node.body);
|
|
720
773
|
}
|
|
721
|
-
} else if (node.type ===
|
|
722
|
-
if (node.body && node.body.type ===
|
|
774
|
+
} else if (node.type === AST_NODE_TYPES7.FunctionExpression || node.type === AST_NODE_TYPES7.FunctionDeclaration) {
|
|
775
|
+
if (node.body && node.body.type === AST_NODE_TYPES7.BlockStatement) {
|
|
723
776
|
return hasJSXReturn(node.body);
|
|
724
777
|
}
|
|
725
778
|
}
|
|
726
779
|
return false;
|
|
727
780
|
}
|
|
728
781
|
function isInlineTypeAnnotation(node) {
|
|
729
|
-
if (node.type ===
|
|
782
|
+
if (node.type === AST_NODE_TYPES7.TSTypeLiteral) {
|
|
730
783
|
return true;
|
|
731
784
|
}
|
|
732
|
-
if (node.type ===
|
|
733
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
785
|
+
if (node.type === AST_NODE_TYPES7.TSTypeReference && node.typeArguments) {
|
|
786
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES7.TSTypeLiteral);
|
|
734
787
|
}
|
|
735
|
-
if (node.type ===
|
|
788
|
+
if (node.type === AST_NODE_TYPES7.TSUnionType) {
|
|
736
789
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
737
790
|
}
|
|
738
791
|
return false;
|
|
739
792
|
}
|
|
740
793
|
function hasInlineObjectType(node) {
|
|
741
|
-
if (node.type ===
|
|
794
|
+
if (node.type === AST_NODE_TYPES7.TSTypeLiteral) {
|
|
742
795
|
return true;
|
|
743
796
|
}
|
|
744
|
-
if (node.type ===
|
|
745
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
797
|
+
if (node.type === AST_NODE_TYPES7.TSTypeReference && node.typeArguments) {
|
|
798
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES7.TSTypeLiteral);
|
|
746
799
|
}
|
|
747
|
-
if (node.type ===
|
|
800
|
+
if (node.type === AST_NODE_TYPES7.TSUnionType) {
|
|
748
801
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
749
802
|
}
|
|
750
803
|
return false;
|
|
@@ -757,7 +810,7 @@ var preferInterfaceOverInlineTypes = createRule11({
|
|
|
757
810
|
return;
|
|
758
811
|
}
|
|
759
812
|
const param = node.params[0];
|
|
760
|
-
if (param.type ===
|
|
813
|
+
if (param.type === AST_NODE_TYPES7.Identifier && param.typeAnnotation) {
|
|
761
814
|
const { typeAnnotation } = param.typeAnnotation;
|
|
762
815
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
763
816
|
context.report({
|
|
@@ -777,11 +830,11 @@ var preferInterfaceOverInlineTypes = createRule11({
|
|
|
777
830
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
778
831
|
|
|
779
832
|
// src/rules/prefer-named-param-types.ts
|
|
780
|
-
import { AST_NODE_TYPES as
|
|
781
|
-
var
|
|
833
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES8, ESLintUtils as ESLintUtils13 } from "@typescript-eslint/utils";
|
|
834
|
+
var createRule13 = ESLintUtils13.RuleCreator(
|
|
782
835
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
783
836
|
);
|
|
784
|
-
var preferNamedParamTypes =
|
|
837
|
+
var preferNamedParamTypes = createRule13({
|
|
785
838
|
name: "prefer-named-param-types",
|
|
786
839
|
meta: {
|
|
787
840
|
type: "suggestion",
|
|
@@ -796,16 +849,16 @@ var preferNamedParamTypes = createRule12({
|
|
|
796
849
|
defaultOptions: [],
|
|
797
850
|
create(context) {
|
|
798
851
|
function hasInlineObjectType(param) {
|
|
799
|
-
if (param.type ===
|
|
852
|
+
if (param.type === AST_NODE_TYPES8.AssignmentPattern) {
|
|
800
853
|
return hasInlineObjectType(param.left);
|
|
801
854
|
}
|
|
802
|
-
if (param.type ===
|
|
803
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
855
|
+
if (param.type === AST_NODE_TYPES8.ObjectPattern) {
|
|
856
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES8.TSTypeLiteral) {
|
|
804
857
|
return true;
|
|
805
858
|
}
|
|
806
859
|
}
|
|
807
|
-
if (param.type ===
|
|
808
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
860
|
+
if (param.type === AST_NODE_TYPES8.Identifier) {
|
|
861
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES8.TSTypeLiteral) {
|
|
809
862
|
return true;
|
|
810
863
|
}
|
|
811
864
|
}
|
|
@@ -839,11 +892,11 @@ var preferNamedParamTypes = createRule12({
|
|
|
839
892
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
840
893
|
|
|
841
894
|
// src/rules/prefer-react-import-types.ts
|
|
842
|
-
import { AST_NODE_TYPES as
|
|
843
|
-
var
|
|
895
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES9, ESLintUtils as ESLintUtils14 } from "@typescript-eslint/utils";
|
|
896
|
+
var createRule14 = ESLintUtils14.RuleCreator(
|
|
844
897
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
845
898
|
);
|
|
846
|
-
var preferReactImportTypes =
|
|
899
|
+
var preferReactImportTypes = createRule14({
|
|
847
900
|
name: "prefer-react-import-types",
|
|
848
901
|
meta: {
|
|
849
902
|
type: "suggestion",
|
|
@@ -919,7 +972,7 @@ var preferReactImportTypes = createRule13({
|
|
|
919
972
|
]);
|
|
920
973
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
921
974
|
function checkMemberExpression(node) {
|
|
922
|
-
if (node.object.type ===
|
|
975
|
+
if (node.object.type === AST_NODE_TYPES9.Identifier && node.object.name === "React" && node.property.type === AST_NODE_TYPES9.Identifier && allReactExports.has(node.property.name)) {
|
|
923
976
|
const typeName = node.property.name;
|
|
924
977
|
const isType = reactTypes.has(typeName);
|
|
925
978
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -936,7 +989,7 @@ var preferReactImportTypes = createRule13({
|
|
|
936
989
|
return {
|
|
937
990
|
MemberExpression: checkMemberExpression,
|
|
938
991
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
939
|
-
if (node.left.type ===
|
|
992
|
+
if (node.left.type === AST_NODE_TYPES9.Identifier && node.left.name === "React" && node.right.type === AST_NODE_TYPES9.Identifier && allReactExports.has(node.right.name)) {
|
|
940
993
|
const typeName = node.right.name;
|
|
941
994
|
const isType = reactTypes.has(typeName);
|
|
942
995
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -956,11 +1009,11 @@ var preferReactImportTypes = createRule13({
|
|
|
956
1009
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
957
1010
|
|
|
958
1011
|
// src/rules/react-props-destructure.ts
|
|
959
|
-
import { AST_NODE_TYPES as
|
|
960
|
-
var
|
|
1012
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES10, ESLintUtils as ESLintUtils15 } from "@typescript-eslint/utils";
|
|
1013
|
+
var createRule15 = ESLintUtils15.RuleCreator(
|
|
961
1014
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
962
1015
|
);
|
|
963
|
-
var reactPropsDestructure =
|
|
1016
|
+
var reactPropsDestructure = createRule15({
|
|
964
1017
|
name: "react-props-destructure",
|
|
965
1018
|
meta: {
|
|
966
1019
|
type: "suggestion",
|
|
@@ -976,29 +1029,29 @@ var reactPropsDestructure = createRule14({
|
|
|
976
1029
|
defaultOptions: [],
|
|
977
1030
|
create(context) {
|
|
978
1031
|
function hasJSXInConditional(node) {
|
|
979
|
-
return node.consequent.type ===
|
|
1032
|
+
return node.consequent.type === AST_NODE_TYPES10.JSXElement || node.consequent.type === AST_NODE_TYPES10.JSXFragment || node.alternate.type === AST_NODE_TYPES10.JSXElement || node.alternate.type === AST_NODE_TYPES10.JSXFragment;
|
|
980
1033
|
}
|
|
981
1034
|
function hasJSXInLogical(node) {
|
|
982
|
-
return node.right.type ===
|
|
1035
|
+
return node.right.type === AST_NODE_TYPES10.JSXElement || node.right.type === AST_NODE_TYPES10.JSXFragment;
|
|
983
1036
|
}
|
|
984
1037
|
function hasJSXReturn(block) {
|
|
985
1038
|
return block.body.some((stmt) => {
|
|
986
|
-
if (stmt.type ===
|
|
987
|
-
return stmt.argument.type ===
|
|
1039
|
+
if (stmt.type === AST_NODE_TYPES10.ReturnStatement && stmt.argument) {
|
|
1040
|
+
return stmt.argument.type === AST_NODE_TYPES10.JSXElement || stmt.argument.type === AST_NODE_TYPES10.JSXFragment || stmt.argument.type === AST_NODE_TYPES10.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES10.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
988
1041
|
}
|
|
989
1042
|
return false;
|
|
990
1043
|
});
|
|
991
1044
|
}
|
|
992
1045
|
function isReactComponent(node) {
|
|
993
|
-
if (node.type ===
|
|
994
|
-
if (node.body.type ===
|
|
1046
|
+
if (node.type === AST_NODE_TYPES10.ArrowFunctionExpression) {
|
|
1047
|
+
if (node.body.type === AST_NODE_TYPES10.JSXElement || node.body.type === AST_NODE_TYPES10.JSXFragment) {
|
|
995
1048
|
return true;
|
|
996
1049
|
}
|
|
997
|
-
if (node.body.type ===
|
|
1050
|
+
if (node.body.type === AST_NODE_TYPES10.BlockStatement) {
|
|
998
1051
|
return hasJSXReturn(node.body);
|
|
999
1052
|
}
|
|
1000
|
-
} else if (node.type ===
|
|
1001
|
-
if (node.body && node.body.type ===
|
|
1053
|
+
} else if (node.type === AST_NODE_TYPES10.FunctionExpression || node.type === AST_NODE_TYPES10.FunctionDeclaration) {
|
|
1054
|
+
if (node.body && node.body.type === AST_NODE_TYPES10.BlockStatement) {
|
|
1002
1055
|
return hasJSXReturn(node.body);
|
|
1003
1056
|
}
|
|
1004
1057
|
}
|
|
@@ -1012,9 +1065,9 @@ var reactPropsDestructure = createRule14({
|
|
|
1012
1065
|
return;
|
|
1013
1066
|
}
|
|
1014
1067
|
const param = node.params[0];
|
|
1015
|
-
if (param.type ===
|
|
1016
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
1017
|
-
if (prop.key.type ===
|
|
1068
|
+
if (param.type === AST_NODE_TYPES10.ObjectPattern) {
|
|
1069
|
+
const properties = param.properties.filter((prop) => prop.type === AST_NODE_TYPES10.Property).map((prop) => {
|
|
1070
|
+
if (prop.key.type === AST_NODE_TYPES10.Identifier) {
|
|
1018
1071
|
return prop.key.name;
|
|
1019
1072
|
}
|
|
1020
1073
|
return null;
|
|
@@ -1052,6 +1105,7 @@ var rules = {
|
|
|
1052
1105
|
"md-filename-case-restriction": md_filename_case_restriction_default,
|
|
1053
1106
|
"no-complex-inline-return": no_complex_inline_return_default,
|
|
1054
1107
|
"no-emoji": no_emoji_default,
|
|
1108
|
+
"no-env-fallback": no_env_fallback_default,
|
|
1055
1109
|
"no-explicit-return-type": no_explicit_return_type_default,
|
|
1056
1110
|
"no-logic-in-params": no_logic_in_params_default,
|
|
1057
1111
|
"prefer-destructuring-params": prefer_destructuring_params_default,
|
|
@@ -1075,7 +1129,8 @@ var baseRules = {
|
|
|
1075
1129
|
"nextfriday/prefer-named-param-types": "warn",
|
|
1076
1130
|
"nextfriday/prefer-react-import-types": "warn",
|
|
1077
1131
|
"nextfriday/no-complex-inline-return": "warn",
|
|
1078
|
-
"nextfriday/no-logic-in-params": "warn"
|
|
1132
|
+
"nextfriday/no-logic-in-params": "warn",
|
|
1133
|
+
"nextfriday/no-env-fallback": "warn"
|
|
1079
1134
|
};
|
|
1080
1135
|
var baseRecommendedRules = {
|
|
1081
1136
|
"nextfriday/no-emoji": "error",
|
|
@@ -1087,7 +1142,8 @@ var baseRecommendedRules = {
|
|
|
1087
1142
|
"nextfriday/prefer-named-param-types": "error",
|
|
1088
1143
|
"nextfriday/prefer-react-import-types": "error",
|
|
1089
1144
|
"nextfriday/no-complex-inline-return": "error",
|
|
1090
|
-
"nextfriday/no-logic-in-params": "error"
|
|
1145
|
+
"nextfriday/no-logic-in-params": "error",
|
|
1146
|
+
"nextfriday/no-env-fallback": "error"
|
|
1091
1147
|
};
|
|
1092
1148
|
var jsxRules = {
|
|
1093
1149
|
"nextfriday/jsx-pascal-case": "warn",
|