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