eslint-plugin-nextfriday 3.2.1 → 4.0.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 +16 -0
- package/README.md +33 -61
- package/docs/agents/domain.md +51 -0
- package/docs/agents/issue-tracker.md +22 -0
- package/docs/agents/triage-labels.md +15 -0
- package/docs/rules/NO_INLINE_NESTED_OBJECT.md +45 -27
- package/docs/rules/PREFER_GUARD_CLAUSE.md +2 -0
- package/docs/rules/PREFER_IMPORT_TYPE.md +5 -0
- package/docs/rules/PREFER_INTERFACE_FOR_COMPONENT_PROPS.md +53 -0
- package/docs/rules/PREFER_NAMED_PARAM_TYPES.md +5 -1
- package/docs/rules/PREFER_PROPS_WITH_CHILDREN.md +112 -0
- package/lib/index.cjs +657 -714
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +92 -200
- package/lib/index.d.ts +92 -200
- package/lib/index.js +624 -681
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/docs/rules/ENFORCE_CURLY_NEWLINE.md +0 -55
- package/docs/rules/FILE_KEBAB_CASE.md +0 -70
- package/docs/rules/JSX_PASCAL_CASE.md +0 -71
- package/docs/rules/NEXTJS_REQUIRE_PUBLIC_ENV.md +0 -44
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: "
|
|
4
|
+
version: "4.0.0",
|
|
5
5
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
6
6
|
keywords: [
|
|
7
7
|
"eslint",
|
|
@@ -397,6 +397,10 @@ import { basename, extname } from "path";
|
|
|
397
397
|
import { AST_NODE_TYPES as AST_NODE_TYPES3 } from "@typescript-eslint/utils";
|
|
398
398
|
var getFileExtension = (filename) => extname(filename).slice(1);
|
|
399
399
|
var getBaseName = (filename) => basename(filename, extname(filename));
|
|
400
|
+
var isJsxFile = (filename) => {
|
|
401
|
+
const ext = getFileExtension(filename);
|
|
402
|
+
return ext === "jsx" || ext === "tsx";
|
|
403
|
+
};
|
|
400
404
|
var isConfigFile = (filename) => {
|
|
401
405
|
const baseName = getBaseName(filename);
|
|
402
406
|
return /\.(config|rc|setup|spec|test)$/.test(baseName) || /\.(config|rc|setup|spec|test)\./.test(filename) || /^\.(eslintrc|babelrc|prettierrc)/.test(filename);
|
|
@@ -482,84 +486,13 @@ var enforceConstantCase = createRule3({
|
|
|
482
486
|
});
|
|
483
487
|
var enforce_constant_case_default = enforceConstantCase;
|
|
484
488
|
|
|
485
|
-
// src/rules/enforce-curly-newline.ts
|
|
486
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES5, ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
|
|
487
|
-
var createRule4 = ESLintUtils4.RuleCreator(
|
|
488
|
-
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
489
|
-
);
|
|
490
|
-
var enforceCurlyNewline = createRule4({
|
|
491
|
-
name: "enforce-curly-newline",
|
|
492
|
-
meta: {
|
|
493
|
-
type: "layout",
|
|
494
|
-
docs: {
|
|
495
|
-
description: "Enforce curly braces for multi-line if statements and forbid them for single-line"
|
|
496
|
-
},
|
|
497
|
-
fixable: "code",
|
|
498
|
-
messages: {
|
|
499
|
-
requireBraces: "Multi-line if statements must use curly braces.",
|
|
500
|
-
forbidBraces: "Single-line if statements must not use curly braces."
|
|
501
|
-
},
|
|
502
|
-
schema: []
|
|
503
|
-
},
|
|
504
|
-
defaultOptions: [],
|
|
505
|
-
create(context) {
|
|
506
|
-
const { sourceCode } = context;
|
|
507
|
-
return {
|
|
508
|
-
IfStatement(node) {
|
|
509
|
-
const { consequent } = node;
|
|
510
|
-
const startLine = node.loc.start.line;
|
|
511
|
-
const endLine = node.loc.end.line;
|
|
512
|
-
const isSingleLine2 = startLine === endLine;
|
|
513
|
-
const hasBraces = consequent.type === AST_NODE_TYPES5.BlockStatement;
|
|
514
|
-
if (isSingleLine2 && hasBraces) {
|
|
515
|
-
if (consequent.body.length !== 1) {
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
const innerStatement = consequent.body[0];
|
|
519
|
-
const innerText = sourceCode.getText(innerStatement);
|
|
520
|
-
context.report({
|
|
521
|
-
node: consequent,
|
|
522
|
-
messageId: "forbidBraces",
|
|
523
|
-
fix(fixer) {
|
|
524
|
-
return fixer.replaceText(consequent, innerText);
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
if (!isSingleLine2 && !hasBraces) {
|
|
529
|
-
context.report({
|
|
530
|
-
node: consequent,
|
|
531
|
-
messageId: "requireBraces",
|
|
532
|
-
fix(fixer) {
|
|
533
|
-
const consequentText = sourceCode.getText(consequent);
|
|
534
|
-
const closingParen = sourceCode.getTokenBefore(consequent);
|
|
535
|
-
if (!closingParen) {
|
|
536
|
-
return null;
|
|
537
|
-
}
|
|
538
|
-
const ifStartLine = sourceCode.lines[startLine - 1];
|
|
539
|
-
const indentRegex = /^(\s*)/;
|
|
540
|
-
const indentMatch = indentRegex.exec(ifStartLine);
|
|
541
|
-
const baseIndent = indentMatch ? indentMatch[1] : "";
|
|
542
|
-
const bodyIndent = `${baseIndent} `;
|
|
543
|
-
const newText = ` {
|
|
544
|
-
${bodyIndent}${consequentText.trim()}
|
|
545
|
-
${baseIndent}}`;
|
|
546
|
-
return fixer.replaceTextRange([closingParen.range[1], consequent.range[1]], newText);
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
var enforce_curly_newline_default = enforceCurlyNewline;
|
|
555
|
-
|
|
556
489
|
// src/rules/enforce-hook-naming.ts
|
|
557
490
|
import path from "path";
|
|
558
|
-
import { AST_NODE_TYPES as
|
|
559
|
-
var
|
|
491
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES5, ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
|
|
492
|
+
var createRule4 = ESLintUtils4.RuleCreator(
|
|
560
493
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
561
494
|
);
|
|
562
|
-
var enforceHookNaming =
|
|
495
|
+
var enforceHookNaming = createRule4({
|
|
563
496
|
name: "enforce-hook-naming",
|
|
564
497
|
meta: {
|
|
565
498
|
type: "suggestion",
|
|
@@ -598,22 +531,22 @@ var enforceHookNaming = createRule5({
|
|
|
598
531
|
};
|
|
599
532
|
return {
|
|
600
533
|
ExportNamedDeclaration(node) {
|
|
601
|
-
if (node.declaration?.type ===
|
|
534
|
+
if (node.declaration?.type === AST_NODE_TYPES5.FunctionDeclaration && node.declaration.id) {
|
|
602
535
|
checkFunctionName(node.declaration.id.name, node.declaration.id, "missingUsePrefix");
|
|
603
536
|
}
|
|
604
|
-
if (node.declaration?.type ===
|
|
537
|
+
if (node.declaration?.type === AST_NODE_TYPES5.VariableDeclaration) {
|
|
605
538
|
node.declaration.declarations.forEach((declarator) => {
|
|
606
|
-
if (declarator.id.type ===
|
|
539
|
+
if (declarator.id.type === AST_NODE_TYPES5.Identifier) {
|
|
607
540
|
checkFunctionName(declarator.id.name, declarator.id, "missingUsePrefix");
|
|
608
541
|
}
|
|
609
542
|
});
|
|
610
543
|
}
|
|
611
544
|
},
|
|
612
545
|
ExportDefaultDeclaration(node) {
|
|
613
|
-
if (node.declaration.type ===
|
|
546
|
+
if (node.declaration.type === AST_NODE_TYPES5.Identifier) {
|
|
614
547
|
checkFunctionName(node.declaration.name, node.declaration, "defaultExportMissingUsePrefix");
|
|
615
548
|
}
|
|
616
|
-
if (node.declaration.type ===
|
|
549
|
+
if (node.declaration.type === AST_NODE_TYPES5.FunctionDeclaration && node.declaration.id) {
|
|
617
550
|
checkFunctionName(node.declaration.id.name, node.declaration.id, "defaultExportMissingUsePrefix");
|
|
618
551
|
}
|
|
619
552
|
}
|
|
@@ -623,26 +556,26 @@ var enforceHookNaming = createRule5({
|
|
|
623
556
|
var enforce_hook_naming_default = enforceHookNaming;
|
|
624
557
|
|
|
625
558
|
// src/rules/enforce-property-case.ts
|
|
626
|
-
import { AST_NODE_TYPES as
|
|
627
|
-
var
|
|
559
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES6, ESLintUtils as ESLintUtils5 } from "@typescript-eslint/utils";
|
|
560
|
+
var createRule5 = ESLintUtils5.RuleCreator(
|
|
628
561
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
629
562
|
);
|
|
630
563
|
var SNAKE_CASE_REGEX3 = /^[a-z]+_[a-z0-9_]*$/;
|
|
631
564
|
var SCREAMING_SNAKE_CASE_REGEX2 = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
632
565
|
var isInsideAsConst = (node) => {
|
|
633
566
|
const { parent } = node;
|
|
634
|
-
if (parent.type ===
|
|
567
|
+
if (parent.type === AST_NODE_TYPES6.TSAsExpression && parent.typeAnnotation.type === AST_NODE_TYPES6.TSTypeReference && parent.typeAnnotation.typeName.type === AST_NODE_TYPES6.Identifier && parent.typeAnnotation.typeName.name === "const") {
|
|
635
568
|
return true;
|
|
636
569
|
}
|
|
637
|
-
if (parent.type ===
|
|
570
|
+
if (parent.type === AST_NODE_TYPES6.ArrayExpression) {
|
|
638
571
|
const grandparent = parent.parent;
|
|
639
|
-
if (grandparent?.type ===
|
|
572
|
+
if (grandparent?.type === AST_NODE_TYPES6.TSAsExpression && grandparent.typeAnnotation.type === AST_NODE_TYPES6.TSTypeReference && grandparent.typeAnnotation.typeName.type === AST_NODE_TYPES6.Identifier && grandparent.typeAnnotation.typeName.name === "const") {
|
|
640
573
|
return true;
|
|
641
574
|
}
|
|
642
575
|
}
|
|
643
576
|
return false;
|
|
644
577
|
};
|
|
645
|
-
var enforcePropertyCase =
|
|
578
|
+
var enforcePropertyCase = createRule5({
|
|
646
579
|
name: "enforce-property-case",
|
|
647
580
|
meta: {
|
|
648
581
|
type: "suggestion",
|
|
@@ -658,7 +591,7 @@ var enforcePropertyCase = createRule6({
|
|
|
658
591
|
create(context) {
|
|
659
592
|
return {
|
|
660
593
|
Property(node) {
|
|
661
|
-
if (node.parent.type !==
|
|
594
|
+
if (node.parent.type !== AST_NODE_TYPES6.ObjectExpression) {
|
|
662
595
|
return;
|
|
663
596
|
}
|
|
664
597
|
if (isInsideAsConst(node.parent)) {
|
|
@@ -667,7 +600,7 @@ var enforcePropertyCase = createRule6({
|
|
|
667
600
|
if (node.computed) {
|
|
668
601
|
return;
|
|
669
602
|
}
|
|
670
|
-
if (node.key.type !==
|
|
603
|
+
if (node.key.type !== AST_NODE_TYPES6.Identifier) {
|
|
671
604
|
return;
|
|
672
605
|
}
|
|
673
606
|
const { name } = node.key;
|
|
@@ -686,11 +619,11 @@ var enforce_property_case_default = enforcePropertyCase;
|
|
|
686
619
|
|
|
687
620
|
// src/rules/enforce-props-suffix.ts
|
|
688
621
|
import path2 from "path";
|
|
689
|
-
import { AST_NODE_TYPES as
|
|
690
|
-
var
|
|
622
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES7, ESLintUtils as ESLintUtils6 } from "@typescript-eslint/utils";
|
|
623
|
+
var createRule6 = ESLintUtils6.RuleCreator(
|
|
691
624
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
692
625
|
);
|
|
693
|
-
var enforcePropsSuffix =
|
|
626
|
+
var enforcePropsSuffix = createRule6({
|
|
694
627
|
name: "enforce-props-suffix",
|
|
695
628
|
meta: {
|
|
696
629
|
type: "suggestion",
|
|
@@ -724,13 +657,13 @@ var enforcePropsSuffix = createRule7({
|
|
|
724
657
|
};
|
|
725
658
|
return {
|
|
726
659
|
TSInterfaceDeclaration(node) {
|
|
727
|
-
if (node.id.type ===
|
|
660
|
+
if (node.id.type === AST_NODE_TYPES7.Identifier) {
|
|
728
661
|
checkTypeName(node.id.name, node.id);
|
|
729
662
|
}
|
|
730
663
|
},
|
|
731
664
|
TSTypeAliasDeclaration(node) {
|
|
732
|
-
if (node.id.type ===
|
|
733
|
-
if (node.typeAnnotation.type ===
|
|
665
|
+
if (node.id.type === AST_NODE_TYPES7.Identifier) {
|
|
666
|
+
if (node.typeAnnotation.type === AST_NODE_TYPES7.TSTypeLiteral) {
|
|
734
667
|
checkTypeName(node.id.name, node.id);
|
|
735
668
|
}
|
|
736
669
|
}
|
|
@@ -741,11 +674,11 @@ var enforcePropsSuffix = createRule7({
|
|
|
741
674
|
var enforce_props_suffix_default = enforcePropsSuffix;
|
|
742
675
|
|
|
743
676
|
// src/rules/enforce-readonly-component-props.ts
|
|
744
|
-
import { AST_NODE_TYPES as
|
|
745
|
-
var
|
|
677
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES8, ESLintUtils as ESLintUtils7 } from "@typescript-eslint/utils";
|
|
678
|
+
var createRule7 = ESLintUtils7.RuleCreator(
|
|
746
679
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
747
680
|
);
|
|
748
|
-
var enforceReadonlyComponentProps =
|
|
681
|
+
var enforceReadonlyComponentProps = createRule7({
|
|
749
682
|
name: "enforce-readonly-component-props",
|
|
750
683
|
meta: {
|
|
751
684
|
type: "suggestion",
|
|
@@ -761,40 +694,40 @@ var enforceReadonlyComponentProps = createRule8({
|
|
|
761
694
|
defaultOptions: [],
|
|
762
695
|
create(context) {
|
|
763
696
|
function hasJSXInConditional(node) {
|
|
764
|
-
return node.consequent.type ===
|
|
697
|
+
return node.consequent.type === AST_NODE_TYPES8.JSXElement || node.consequent.type === AST_NODE_TYPES8.JSXFragment || node.alternate.type === AST_NODE_TYPES8.JSXElement || node.alternate.type === AST_NODE_TYPES8.JSXFragment;
|
|
765
698
|
}
|
|
766
699
|
function hasJSXInLogical(node) {
|
|
767
|
-
return node.right.type ===
|
|
700
|
+
return node.right.type === AST_NODE_TYPES8.JSXElement || node.right.type === AST_NODE_TYPES8.JSXFragment;
|
|
768
701
|
}
|
|
769
702
|
function hasJSXReturn(block) {
|
|
770
703
|
return block.body.some((stmt) => {
|
|
771
|
-
if (stmt.type ===
|
|
772
|
-
return stmt.argument.type ===
|
|
704
|
+
if (stmt.type === AST_NODE_TYPES8.ReturnStatement && stmt.argument) {
|
|
705
|
+
return stmt.argument.type === AST_NODE_TYPES8.JSXElement || stmt.argument.type === AST_NODE_TYPES8.JSXFragment || stmt.argument.type === AST_NODE_TYPES8.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES8.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
773
706
|
}
|
|
774
707
|
return false;
|
|
775
708
|
});
|
|
776
709
|
}
|
|
777
710
|
function isReactComponent2(node) {
|
|
778
|
-
if (node.type ===
|
|
779
|
-
if (node.body.type ===
|
|
711
|
+
if (node.type === AST_NODE_TYPES8.ArrowFunctionExpression) {
|
|
712
|
+
if (node.body.type === AST_NODE_TYPES8.JSXElement || node.body.type === AST_NODE_TYPES8.JSXFragment) {
|
|
780
713
|
return true;
|
|
781
714
|
}
|
|
782
|
-
if (node.body.type ===
|
|
715
|
+
if (node.body.type === AST_NODE_TYPES8.BlockStatement) {
|
|
783
716
|
return hasJSXReturn(node.body);
|
|
784
717
|
}
|
|
785
|
-
} else if (node.type ===
|
|
786
|
-
if (node.body && node.body.type ===
|
|
718
|
+
} else if (node.type === AST_NODE_TYPES8.FunctionExpression || node.type === AST_NODE_TYPES8.FunctionDeclaration) {
|
|
719
|
+
if (node.body && node.body.type === AST_NODE_TYPES8.BlockStatement) {
|
|
787
720
|
return hasJSXReturn(node.body);
|
|
788
721
|
}
|
|
789
722
|
}
|
|
790
723
|
return false;
|
|
791
724
|
}
|
|
792
725
|
function isNamedType(node) {
|
|
793
|
-
return node.type ===
|
|
726
|
+
return node.type === AST_NODE_TYPES8.TSTypeReference;
|
|
794
727
|
}
|
|
795
728
|
function isAlreadyReadonly(node) {
|
|
796
|
-
if (node.type ===
|
|
797
|
-
if (node.typeName.type ===
|
|
729
|
+
if (node.type === AST_NODE_TYPES8.TSTypeReference && node.typeName) {
|
|
730
|
+
if (node.typeName.type === AST_NODE_TYPES8.Identifier && node.typeName.name === "Readonly") {
|
|
798
731
|
return true;
|
|
799
732
|
}
|
|
800
733
|
}
|
|
@@ -808,7 +741,7 @@ var enforceReadonlyComponentProps = createRule8({
|
|
|
808
741
|
return;
|
|
809
742
|
}
|
|
810
743
|
const param = node.params[0];
|
|
811
|
-
if (param.type ===
|
|
744
|
+
if (param.type === AST_NODE_TYPES8.Identifier && param.typeAnnotation) {
|
|
812
745
|
const { typeAnnotation } = param.typeAnnotation;
|
|
813
746
|
if (isNamedType(typeAnnotation) && !isAlreadyReadonly(typeAnnotation)) {
|
|
814
747
|
const { sourceCode } = context;
|
|
@@ -833,8 +766,8 @@ var enforceReadonlyComponentProps = createRule8({
|
|
|
833
766
|
var enforce_readonly_component_props_default = enforceReadonlyComponentProps;
|
|
834
767
|
|
|
835
768
|
// src/rules/enforce-service-naming.ts
|
|
836
|
-
import { AST_NODE_TYPES as
|
|
837
|
-
var
|
|
769
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES9, ESLintUtils as ESLintUtils8 } from "@typescript-eslint/utils";
|
|
770
|
+
var createRule8 = ESLintUtils8.RuleCreator(
|
|
838
771
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
839
772
|
);
|
|
840
773
|
var BANNED_PREFIXES = {
|
|
@@ -843,7 +776,7 @@ var BANNED_PREFIXES = {
|
|
|
843
776
|
handle: ["create", "verify"],
|
|
844
777
|
set: ["update", "save", "patch"]
|
|
845
778
|
};
|
|
846
|
-
var enforceServiceNaming =
|
|
779
|
+
var enforceServiceNaming = createRule8({
|
|
847
780
|
name: "enforce-service-naming",
|
|
848
781
|
meta: {
|
|
849
782
|
type: "suggestion",
|
|
@@ -886,12 +819,12 @@ var enforceServiceNaming = createRule9({
|
|
|
886
819
|
};
|
|
887
820
|
return {
|
|
888
821
|
ExportNamedDeclaration(node) {
|
|
889
|
-
if (node.declaration?.type ===
|
|
822
|
+
if (node.declaration?.type === AST_NODE_TYPES9.FunctionDeclaration && node.declaration.id) {
|
|
890
823
|
checkExportedFunction(node.declaration, node.declaration.id);
|
|
891
824
|
}
|
|
892
|
-
if (node.declaration?.type ===
|
|
825
|
+
if (node.declaration?.type === AST_NODE_TYPES9.VariableDeclaration) {
|
|
893
826
|
node.declaration.declarations.forEach((declarator) => {
|
|
894
|
-
if (declarator.id.type ===
|
|
827
|
+
if (declarator.id.type === AST_NODE_TYPES9.Identifier && declarator.init?.type === AST_NODE_TYPES9.ArrowFunctionExpression) {
|
|
895
828
|
checkExportedFunction(declarator.init, declarator.id);
|
|
896
829
|
}
|
|
897
830
|
});
|
|
@@ -903,11 +836,11 @@ var enforceServiceNaming = createRule9({
|
|
|
903
836
|
var enforce_service_naming_default = enforceServiceNaming;
|
|
904
837
|
|
|
905
838
|
// src/rules/enforce-sorted-destructuring.ts
|
|
906
|
-
import { AST_NODE_TYPES as
|
|
907
|
-
var
|
|
839
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES10, ESLintUtils as ESLintUtils9 } from "@typescript-eslint/utils";
|
|
840
|
+
var createRule9 = ESLintUtils9.RuleCreator(
|
|
908
841
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
909
842
|
);
|
|
910
|
-
var enforceSortedDestructuring =
|
|
843
|
+
var enforceSortedDestructuring = createRule9({
|
|
911
844
|
name: "enforce-sorted-destructuring",
|
|
912
845
|
meta: {
|
|
913
846
|
type: "suggestion",
|
|
@@ -923,19 +856,19 @@ var enforceSortedDestructuring = createRule10({
|
|
|
923
856
|
defaultOptions: [],
|
|
924
857
|
create(context) {
|
|
925
858
|
function getPropertyName(property) {
|
|
926
|
-
if (property.type ===
|
|
859
|
+
if (property.type === AST_NODE_TYPES10.RestElement) {
|
|
927
860
|
return null;
|
|
928
861
|
}
|
|
929
|
-
if (property.key.type ===
|
|
862
|
+
if (property.key.type === AST_NODE_TYPES10.Identifier) {
|
|
930
863
|
return property.key.name;
|
|
931
864
|
}
|
|
932
865
|
return null;
|
|
933
866
|
}
|
|
934
867
|
function hasDefaultValue(property) {
|
|
935
|
-
return property.value.type ===
|
|
868
|
+
return property.value.type === AST_NODE_TYPES10.AssignmentPattern && Boolean(property.value.right);
|
|
936
869
|
}
|
|
937
870
|
function checkVariableDeclarator(node) {
|
|
938
|
-
if (node.id.type !==
|
|
871
|
+
if (node.id.type !== AST_NODE_TYPES10.ObjectPattern) {
|
|
939
872
|
return;
|
|
940
873
|
}
|
|
941
874
|
const { properties } = node.id;
|
|
@@ -943,7 +876,7 @@ var enforceSortedDestructuring = createRule10({
|
|
|
943
876
|
return;
|
|
944
877
|
}
|
|
945
878
|
const propertyInfo = properties.map((prop) => {
|
|
946
|
-
if (prop.type ===
|
|
879
|
+
if (prop.type === AST_NODE_TYPES10.RestElement) {
|
|
947
880
|
return null;
|
|
948
881
|
}
|
|
949
882
|
return {
|
|
@@ -982,20 +915,20 @@ var enforceSortedDestructuring = createRule10({
|
|
|
982
915
|
var enforce_sorted_destructuring_default = enforceSortedDestructuring;
|
|
983
916
|
|
|
984
917
|
// src/rules/enforce-type-declaration-order.ts
|
|
985
|
-
import { AST_NODE_TYPES as
|
|
986
|
-
var
|
|
918
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES11, ESLintUtils as ESLintUtils10 } from "@typescript-eslint/utils";
|
|
919
|
+
var createRule10 = ESLintUtils10.RuleCreator(
|
|
987
920
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
988
921
|
);
|
|
989
922
|
function getTypeDeclarationName(node) {
|
|
990
|
-
if (node.type ===
|
|
923
|
+
if (node.type === AST_NODE_TYPES11.TSInterfaceDeclaration && node.id.type === AST_NODE_TYPES11.Identifier) {
|
|
991
924
|
return { name: node.id.name, position: node.range[0] };
|
|
992
925
|
}
|
|
993
|
-
if (node.type ===
|
|
926
|
+
if (node.type === AST_NODE_TYPES11.TSTypeAliasDeclaration && node.id.type === AST_NODE_TYPES11.Identifier) {
|
|
994
927
|
return { name: node.id.name, position: node.range[0] };
|
|
995
928
|
}
|
|
996
929
|
return null;
|
|
997
930
|
}
|
|
998
|
-
var enforceTypeDeclarationOrder =
|
|
931
|
+
var enforceTypeDeclarationOrder = createRule10({
|
|
999
932
|
name: "enforce-type-declaration-order",
|
|
1000
933
|
meta: {
|
|
1001
934
|
type: "suggestion",
|
|
@@ -1026,7 +959,7 @@ var enforceTypeDeclarationOrder = createRule11({
|
|
|
1026
959
|
}
|
|
1027
960
|
},
|
|
1028
961
|
"TSPropertySignature TSTypeReference": function checkTypeReference(node) {
|
|
1029
|
-
if (node.typeName.type !==
|
|
962
|
+
if (node.typeName.type !== AST_NODE_TYPES11.Identifier) {
|
|
1030
963
|
return;
|
|
1031
964
|
}
|
|
1032
965
|
const referencedName = node.typeName.name;
|
|
@@ -1062,55 +995,9 @@ var enforceTypeDeclarationOrder = createRule11({
|
|
|
1062
995
|
});
|
|
1063
996
|
var enforce_type_declaration_order_default = enforceTypeDeclarationOrder;
|
|
1064
997
|
|
|
1065
|
-
// src/rules/file-kebab-case.ts
|
|
1066
|
-
import path3 from "path";
|
|
1067
|
-
import { ESLintUtils as ESLintUtils12 } from "@typescript-eslint/utils";
|
|
1068
|
-
var createRule12 = ESLintUtils12.RuleCreator(
|
|
1069
|
-
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1070
|
-
);
|
|
1071
|
-
var isKebabCase = (str) => {
|
|
1072
|
-
if (/\.(config|rc|setup|spec|test)$/.test(str) || /^[a-z0-9]+(?:-[a-z0-9]+)*\.[a-z0-9]+(?:-[a-z0-9]+)*$/.test(str)) {
|
|
1073
|
-
return /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\.[a-z0-9]+(?:-[a-z0-9]+)*)*$/.test(str);
|
|
1074
|
-
}
|
|
1075
|
-
return /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(str);
|
|
1076
|
-
};
|
|
1077
|
-
var fileKebabCase = createRule12({
|
|
1078
|
-
name: "file-kebab-case",
|
|
1079
|
-
meta: {
|
|
1080
|
-
type: "problem",
|
|
1081
|
-
docs: {
|
|
1082
|
-
description: "Enforce kebab-case filenames for .ts and .js files"
|
|
1083
|
-
},
|
|
1084
|
-
messages: {
|
|
1085
|
-
fileKebabCase: "File names must be kebab-case"
|
|
1086
|
-
},
|
|
1087
|
-
schema: []
|
|
1088
|
-
},
|
|
1089
|
-
defaultOptions: [],
|
|
1090
|
-
create(context) {
|
|
1091
|
-
return {
|
|
1092
|
-
Program() {
|
|
1093
|
-
const { filename } = context;
|
|
1094
|
-
const ext = path3.extname(filename);
|
|
1095
|
-
if (ext !== ".ts" && ext !== ".js") {
|
|
1096
|
-
return;
|
|
1097
|
-
}
|
|
1098
|
-
const basename2 = path3.basename(filename, ext);
|
|
1099
|
-
if (!isKebabCase(basename2)) {
|
|
1100
|
-
context.report({
|
|
1101
|
-
loc: { line: 1, column: 0 },
|
|
1102
|
-
messageId: "fileKebabCase"
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
};
|
|
1107
|
-
}
|
|
1108
|
-
});
|
|
1109
|
-
var file_kebab_case_default = fileKebabCase;
|
|
1110
|
-
|
|
1111
998
|
// src/rules/index-export-only.ts
|
|
1112
|
-
import { AST_NODE_TYPES as
|
|
1113
|
-
var
|
|
999
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES12, ESLintUtils as ESLintUtils11 } from "@typescript-eslint/utils";
|
|
1000
|
+
var createRule11 = ESLintUtils11.RuleCreator(
|
|
1114
1001
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1115
1002
|
);
|
|
1116
1003
|
var isIndexFile = (filename) => getBaseName(filename) === "index";
|
|
@@ -1118,26 +1005,26 @@ var isAllowedExportNamed = (node) => {
|
|
|
1118
1005
|
if (!node.declaration) {
|
|
1119
1006
|
return true;
|
|
1120
1007
|
}
|
|
1121
|
-
return node.declaration.type ===
|
|
1008
|
+
return node.declaration.type === AST_NODE_TYPES12.TSTypeAliasDeclaration || node.declaration.type === AST_NODE_TYPES12.TSInterfaceDeclaration;
|
|
1122
1009
|
};
|
|
1123
|
-
var isAllowedExportDefault = (node) => node.declaration.type ===
|
|
1010
|
+
var isAllowedExportDefault = (node) => node.declaration.type === AST_NODE_TYPES12.Identifier;
|
|
1124
1011
|
var isAllowedTopLevel = (node) => {
|
|
1125
1012
|
switch (node.type) {
|
|
1126
|
-
case
|
|
1127
|
-
case
|
|
1128
|
-
case
|
|
1129
|
-
case
|
|
1130
|
-
case
|
|
1013
|
+
case AST_NODE_TYPES12.ImportDeclaration:
|
|
1014
|
+
case AST_NODE_TYPES12.ExportAllDeclaration:
|
|
1015
|
+
case AST_NODE_TYPES12.TSTypeAliasDeclaration:
|
|
1016
|
+
case AST_NODE_TYPES12.TSInterfaceDeclaration:
|
|
1017
|
+
case AST_NODE_TYPES12.TSImportEqualsDeclaration:
|
|
1131
1018
|
return true;
|
|
1132
|
-
case
|
|
1019
|
+
case AST_NODE_TYPES12.ExportNamedDeclaration:
|
|
1133
1020
|
return isAllowedExportNamed(node);
|
|
1134
|
-
case
|
|
1021
|
+
case AST_NODE_TYPES12.ExportDefaultDeclaration:
|
|
1135
1022
|
return isAllowedExportDefault(node);
|
|
1136
1023
|
default:
|
|
1137
1024
|
return false;
|
|
1138
1025
|
}
|
|
1139
1026
|
};
|
|
1140
|
-
var indexExportOnly =
|
|
1027
|
+
var indexExportOnly = createRule11({
|
|
1141
1028
|
name: "index-export-only",
|
|
1142
1029
|
meta: {
|
|
1143
1030
|
type: "suggestion",
|
|
@@ -1171,11 +1058,11 @@ var indexExportOnly = createRule13({
|
|
|
1171
1058
|
var index_export_only_default = indexExportOnly;
|
|
1172
1059
|
|
|
1173
1060
|
// src/rules/jsx-newline-between-elements.ts
|
|
1174
|
-
import { AST_NODE_TYPES as
|
|
1175
|
-
var
|
|
1061
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES13, ESLintUtils as ESLintUtils12 } from "@typescript-eslint/utils";
|
|
1062
|
+
var createRule12 = ESLintUtils12.RuleCreator(
|
|
1176
1063
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1177
1064
|
);
|
|
1178
|
-
var jsxNewlineBetweenElements =
|
|
1065
|
+
var jsxNewlineBetweenElements = createRule12({
|
|
1179
1066
|
name: "jsx-newline-between-elements",
|
|
1180
1067
|
meta: {
|
|
1181
1068
|
type: "layout",
|
|
@@ -1193,7 +1080,7 @@ var jsxNewlineBetweenElements = createRule14({
|
|
|
1193
1080
|
create(context) {
|
|
1194
1081
|
const { sourceCode } = context;
|
|
1195
1082
|
function isSignificantJSXChild(node) {
|
|
1196
|
-
return node.type ===
|
|
1083
|
+
return node.type === AST_NODE_TYPES13.JSXElement || node.type === AST_NODE_TYPES13.JSXFragment || node.type === AST_NODE_TYPES13.JSXExpressionContainer;
|
|
1197
1084
|
}
|
|
1198
1085
|
function isMultiLine(node) {
|
|
1199
1086
|
return node.loc.start.line !== node.loc.end.line;
|
|
@@ -1243,11 +1130,11 @@ var jsxNewlineBetweenElements = createRule14({
|
|
|
1243
1130
|
var jsx_newline_between_elements_default = jsxNewlineBetweenElements;
|
|
1244
1131
|
|
|
1245
1132
|
// src/rules/jsx-no-inline-object-prop.ts
|
|
1246
|
-
import { AST_NODE_TYPES as
|
|
1247
|
-
var
|
|
1133
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES14, ESLintUtils as ESLintUtils13 } from "@typescript-eslint/utils";
|
|
1134
|
+
var createRule13 = ESLintUtils13.RuleCreator(
|
|
1248
1135
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1249
1136
|
);
|
|
1250
|
-
var jsxNoInlineObjectProp =
|
|
1137
|
+
var jsxNoInlineObjectProp = createRule13({
|
|
1251
1138
|
name: "jsx-no-inline-object-prop",
|
|
1252
1139
|
meta: {
|
|
1253
1140
|
type: "suggestion",
|
|
@@ -1263,7 +1150,7 @@ var jsxNoInlineObjectProp = createRule15({
|
|
|
1263
1150
|
create(context) {
|
|
1264
1151
|
return {
|
|
1265
1152
|
JSXAttribute(node) {
|
|
1266
|
-
if (node.value?.type ===
|
|
1153
|
+
if (node.value?.type === AST_NODE_TYPES14.JSXExpressionContainer && node.value.expression.type === AST_NODE_TYPES14.ObjectExpression) {
|
|
1267
1154
|
context.report({
|
|
1268
1155
|
node: node.value,
|
|
1269
1156
|
messageId: "noInlineObject"
|
|
@@ -1276,17 +1163,17 @@ var jsxNoInlineObjectProp = createRule15({
|
|
|
1276
1163
|
var jsx_no_inline_object_prop_default = jsxNoInlineObjectProp;
|
|
1277
1164
|
|
|
1278
1165
|
// src/rules/jsx-no-newline-single-line-elements.ts
|
|
1279
|
-
import { AST_NODE_TYPES as
|
|
1280
|
-
var
|
|
1166
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15, ESLintUtils as ESLintUtils14 } from "@typescript-eslint/utils";
|
|
1167
|
+
var createRule14 = ESLintUtils14.RuleCreator(
|
|
1281
1168
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1282
1169
|
);
|
|
1283
1170
|
function isJSXElementOrFragment(node) {
|
|
1284
|
-
return node.type ===
|
|
1171
|
+
return node.type === AST_NODE_TYPES15.JSXElement || node.type === AST_NODE_TYPES15.JSXFragment;
|
|
1285
1172
|
}
|
|
1286
1173
|
function isSingleLine(node) {
|
|
1287
1174
|
return node.loc.start.line === node.loc.end.line;
|
|
1288
1175
|
}
|
|
1289
|
-
var jsxNoNewlineSingleLineElements =
|
|
1176
|
+
var jsxNoNewlineSingleLineElements = createRule14({
|
|
1290
1177
|
name: "jsx-no-newline-single-line-elements",
|
|
1291
1178
|
meta: {
|
|
1292
1179
|
type: "layout",
|
|
@@ -1304,7 +1191,7 @@ var jsxNoNewlineSingleLineElements = createRule16({
|
|
|
1304
1191
|
const { sourceCode } = context;
|
|
1305
1192
|
function checkSiblings(children) {
|
|
1306
1193
|
const nonWhitespace = children.filter(
|
|
1307
|
-
(child) => !(child.type ===
|
|
1194
|
+
(child) => !(child.type === AST_NODE_TYPES15.JSXText && child.value.trim() === "")
|
|
1308
1195
|
);
|
|
1309
1196
|
nonWhitespace.forEach((next, index) => {
|
|
1310
1197
|
if (index === 0) {
|
|
@@ -1355,11 +1242,11 @@ ${indent}`);
|
|
|
1355
1242
|
var jsx_no_newline_single_line_elements_default = jsxNoNewlineSingleLineElements;
|
|
1356
1243
|
|
|
1357
1244
|
// src/rules/jsx-no-non-component-function.ts
|
|
1358
|
-
import { AST_NODE_TYPES as
|
|
1359
|
-
var
|
|
1245
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES16, ESLintUtils as ESLintUtils15 } from "@typescript-eslint/utils";
|
|
1246
|
+
var createRule15 = ESLintUtils15.RuleCreator(
|
|
1360
1247
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1361
1248
|
);
|
|
1362
|
-
var jsxNoNonComponentFunction =
|
|
1249
|
+
var jsxNoNonComponentFunction = createRule15({
|
|
1363
1250
|
name: "jsx-no-non-component-function",
|
|
1364
1251
|
meta: {
|
|
1365
1252
|
type: "problem",
|
|
@@ -1379,13 +1266,13 @@ var jsxNoNonComponentFunction = createRule17({
|
|
|
1379
1266
|
return {};
|
|
1380
1267
|
}
|
|
1381
1268
|
function isReactComponent2(node) {
|
|
1382
|
-
const functionName = node.type ===
|
|
1269
|
+
const functionName = node.type === AST_NODE_TYPES16.FunctionDeclaration && node.id ? node.id.name : null;
|
|
1383
1270
|
if (functionName && /^[A-Z]/.test(functionName)) {
|
|
1384
1271
|
return true;
|
|
1385
1272
|
}
|
|
1386
1273
|
if (node.returnType?.typeAnnotation) {
|
|
1387
1274
|
const returnTypeNode = node.returnType.typeAnnotation;
|
|
1388
|
-
if (returnTypeNode.type ===
|
|
1275
|
+
if (returnTypeNode.type === AST_NODE_TYPES16.TSTypeReference && returnTypeNode.typeName.type === AST_NODE_TYPES16.Identifier) {
|
|
1389
1276
|
const typeName = returnTypeNode.typeName.name;
|
|
1390
1277
|
if (typeName === "JSX" || typeName === "ReactElement" || typeName === "ReactNode") {
|
|
1391
1278
|
return true;
|
|
@@ -1402,13 +1289,13 @@ var jsxNoNonComponentFunction = createRule17({
|
|
|
1402
1289
|
if (!parent) {
|
|
1403
1290
|
return;
|
|
1404
1291
|
}
|
|
1405
|
-
if (parent.type ===
|
|
1292
|
+
if (parent.type === AST_NODE_TYPES16.ExportDefaultDeclaration || parent.type === AST_NODE_TYPES16.ExportNamedDeclaration) {
|
|
1406
1293
|
return;
|
|
1407
1294
|
}
|
|
1408
|
-
if (declaratorNode?.parent?.parent?.type ===
|
|
1295
|
+
if (declaratorNode?.parent?.parent?.type === AST_NODE_TYPES16.ExportNamedDeclaration) {
|
|
1409
1296
|
return;
|
|
1410
1297
|
}
|
|
1411
|
-
if (declaratorNode?.id.type ===
|
|
1298
|
+
if (declaratorNode?.id.type === AST_NODE_TYPES16.Identifier) {
|
|
1412
1299
|
const varName = declaratorNode.id.name;
|
|
1413
1300
|
if (/^[A-Z]/.test(varName)) {
|
|
1414
1301
|
return;
|
|
@@ -1433,20 +1320,20 @@ var jsxNoNonComponentFunction = createRule17({
|
|
|
1433
1320
|
var jsx_no_non_component_function_default = jsxNoNonComponentFunction;
|
|
1434
1321
|
|
|
1435
1322
|
// src/rules/jsx-no-ternary-null.ts
|
|
1436
|
-
import { AST_NODE_TYPES as
|
|
1437
|
-
var
|
|
1323
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES17, ESLintUtils as ESLintUtils16 } from "@typescript-eslint/utils";
|
|
1324
|
+
var createRule16 = ESLintUtils16.RuleCreator(
|
|
1438
1325
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1439
1326
|
);
|
|
1440
1327
|
function isNullOrUndefined(node) {
|
|
1441
|
-
if (node.type ===
|
|
1328
|
+
if (node.type === AST_NODE_TYPES17.Literal && node.value === null) {
|
|
1442
1329
|
return true;
|
|
1443
1330
|
}
|
|
1444
|
-
if (node.type ===
|
|
1331
|
+
if (node.type === AST_NODE_TYPES17.Identifier && node.name === "undefined") {
|
|
1445
1332
|
return true;
|
|
1446
1333
|
}
|
|
1447
1334
|
return false;
|
|
1448
1335
|
}
|
|
1449
|
-
var jsxNoTernaryNull =
|
|
1336
|
+
var jsxNoTernaryNull = createRule16({
|
|
1450
1337
|
name: "jsx-no-ternary-null",
|
|
1451
1338
|
meta: {
|
|
1452
1339
|
type: "suggestion",
|
|
@@ -1464,7 +1351,7 @@ var jsxNoTernaryNull = createRule18({
|
|
|
1464
1351
|
return {
|
|
1465
1352
|
JSXExpressionContainer(node) {
|
|
1466
1353
|
const { expression } = node;
|
|
1467
|
-
if (expression.type !==
|
|
1354
|
+
if (expression.type !== AST_NODE_TYPES17.ConditionalExpression) {
|
|
1468
1355
|
return;
|
|
1469
1356
|
}
|
|
1470
1357
|
const { test, consequent, alternate } = expression;
|
|
@@ -1496,11 +1383,11 @@ var jsxNoTernaryNull = createRule18({
|
|
|
1496
1383
|
var jsx_no_ternary_null_default = jsxNoTernaryNull;
|
|
1497
1384
|
|
|
1498
1385
|
// src/rules/jsx-no-variable-in-callback.ts
|
|
1499
|
-
import { AST_NODE_TYPES as
|
|
1500
|
-
var
|
|
1386
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18, ESLintUtils as ESLintUtils17 } from "@typescript-eslint/utils";
|
|
1387
|
+
var createRule17 = ESLintUtils17.RuleCreator(
|
|
1501
1388
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1502
1389
|
);
|
|
1503
|
-
var jsxNoVariableInCallback =
|
|
1390
|
+
var jsxNoVariableInCallback = createRule17({
|
|
1504
1391
|
name: "jsx-no-variable-in-callback",
|
|
1505
1392
|
meta: {
|
|
1506
1393
|
type: "suggestion",
|
|
@@ -1517,7 +1404,7 @@ var jsxNoVariableInCallback = createRule19({
|
|
|
1517
1404
|
function isInsideJSX(node) {
|
|
1518
1405
|
let current = node.parent;
|
|
1519
1406
|
while (current) {
|
|
1520
|
-
if (current.type ===
|
|
1407
|
+
if (current.type === AST_NODE_TYPES18.JSXElement || current.type === AST_NODE_TYPES18.JSXFragment) {
|
|
1521
1408
|
return true;
|
|
1522
1409
|
}
|
|
1523
1410
|
current = current.parent;
|
|
@@ -1531,11 +1418,11 @@ var jsxNoVariableInCallback = createRule19({
|
|
|
1531
1418
|
if (!isInsideJSX(node)) {
|
|
1532
1419
|
return false;
|
|
1533
1420
|
}
|
|
1534
|
-
if (node.parent.type ===
|
|
1421
|
+
if (node.parent.type === AST_NODE_TYPES18.CallExpression || node.parent.type === AST_NODE_TYPES18.JSXExpressionContainer) {
|
|
1535
1422
|
return true;
|
|
1536
1423
|
}
|
|
1537
|
-
if (node.parent.type ===
|
|
1538
|
-
if (node.parent.parent.type ===
|
|
1424
|
+
if (node.parent.type === AST_NODE_TYPES18.ArrayExpression && node.parent.parent) {
|
|
1425
|
+
if (node.parent.parent.type === AST_NODE_TYPES18.CallExpression || node.parent.parent.type === AST_NODE_TYPES18.JSXExpressionContainer) {
|
|
1539
1426
|
return true;
|
|
1540
1427
|
}
|
|
1541
1428
|
}
|
|
@@ -1546,11 +1433,11 @@ var jsxNoVariableInCallback = createRule19({
|
|
|
1546
1433
|
return;
|
|
1547
1434
|
}
|
|
1548
1435
|
const { body } = node;
|
|
1549
|
-
if (body.type !==
|
|
1436
|
+
if (body.type !== AST_NODE_TYPES18.BlockStatement) {
|
|
1550
1437
|
return;
|
|
1551
1438
|
}
|
|
1552
1439
|
body.body.forEach((statement) => {
|
|
1553
|
-
if (statement.type ===
|
|
1440
|
+
if (statement.type === AST_NODE_TYPES18.VariableDeclaration) {
|
|
1554
1441
|
context.report({
|
|
1555
1442
|
node: statement,
|
|
1556
1443
|
messageId: "noVariableInCallback"
|
|
@@ -1566,53 +1453,12 @@ var jsxNoVariableInCallback = createRule19({
|
|
|
1566
1453
|
});
|
|
1567
1454
|
var jsx_no_variable_in_callback_default = jsxNoVariableInCallback;
|
|
1568
1455
|
|
|
1569
|
-
// src/rules/jsx-pascal-case.ts
|
|
1570
|
-
import path4 from "path";
|
|
1571
|
-
import { ESLintUtils as ESLintUtils20 } from "@typescript-eslint/utils";
|
|
1572
|
-
var createRule20 = ESLintUtils20.RuleCreator(
|
|
1573
|
-
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1574
|
-
);
|
|
1575
|
-
var isPascalCase = (str) => /^[A-Z][a-zA-Z0-9]*$/.test(str) && !/^[A-Z]+$/.test(str);
|
|
1576
|
-
var jsxPascalCase = createRule20({
|
|
1577
|
-
name: "jsx-pascal-case",
|
|
1578
|
-
meta: {
|
|
1579
|
-
type: "problem",
|
|
1580
|
-
docs: {
|
|
1581
|
-
description: "Enforce PascalCase filenames for .jsx and .tsx files"
|
|
1582
|
-
},
|
|
1583
|
-
messages: {
|
|
1584
|
-
jsxPascalCase: "JSX/TSX file names must be PascalCase"
|
|
1585
|
-
},
|
|
1586
|
-
schema: []
|
|
1587
|
-
},
|
|
1588
|
-
defaultOptions: [],
|
|
1589
|
-
create(context) {
|
|
1590
|
-
return {
|
|
1591
|
-
Program() {
|
|
1592
|
-
const { filename } = context;
|
|
1593
|
-
const ext = path4.extname(filename);
|
|
1594
|
-
if (ext !== ".jsx" && ext !== ".tsx") {
|
|
1595
|
-
return;
|
|
1596
|
-
}
|
|
1597
|
-
const basename2 = path4.basename(filename, ext);
|
|
1598
|
-
if (!isPascalCase(basename2)) {
|
|
1599
|
-
context.report({
|
|
1600
|
-
loc: { line: 1, column: 0 },
|
|
1601
|
-
messageId: "jsxPascalCase"
|
|
1602
|
-
});
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
};
|
|
1606
|
-
}
|
|
1607
|
-
});
|
|
1608
|
-
var jsx_pascal_case_default = jsxPascalCase;
|
|
1609
|
-
|
|
1610
1456
|
// src/rules/jsx-require-suspense.ts
|
|
1611
|
-
import { AST_NODE_TYPES as
|
|
1612
|
-
var
|
|
1457
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES19, ESLintUtils as ESLintUtils18 } from "@typescript-eslint/utils";
|
|
1458
|
+
var createRule18 = ESLintUtils18.RuleCreator(
|
|
1613
1459
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1614
1460
|
);
|
|
1615
|
-
var jsxRequireSuspense =
|
|
1461
|
+
var jsxRequireSuspense = createRule18({
|
|
1616
1462
|
name: "jsx-require-suspense",
|
|
1617
1463
|
meta: {
|
|
1618
1464
|
type: "problem",
|
|
@@ -1630,7 +1476,7 @@ var jsxRequireSuspense = createRule21({
|
|
|
1630
1476
|
const isInsideSuspense = (node) => {
|
|
1631
1477
|
let current = node.parent;
|
|
1632
1478
|
while (current) {
|
|
1633
|
-
if (current.type ===
|
|
1479
|
+
if (current.type === AST_NODE_TYPES19.JSXElement && current.openingElement.name.type === AST_NODE_TYPES19.JSXIdentifier && current.openingElement.name.name === "Suspense") {
|
|
1634
1480
|
return true;
|
|
1635
1481
|
}
|
|
1636
1482
|
current = current.parent;
|
|
@@ -1639,16 +1485,16 @@ var jsxRequireSuspense = createRule21({
|
|
|
1639
1485
|
};
|
|
1640
1486
|
return {
|
|
1641
1487
|
VariableDeclarator(node) {
|
|
1642
|
-
if (node.id.type ===
|
|
1488
|
+
if (node.id.type === AST_NODE_TYPES19.Identifier && node.init?.type === AST_NODE_TYPES19.CallExpression) {
|
|
1643
1489
|
const { callee } = node.init;
|
|
1644
|
-
const isLazyCall = callee.type ===
|
|
1490
|
+
const isLazyCall = callee.type === AST_NODE_TYPES19.Identifier && callee.name === "lazy" || callee.type === AST_NODE_TYPES19.MemberExpression && callee.object.type === AST_NODE_TYPES19.Identifier && callee.object.name === "React" && callee.property.type === AST_NODE_TYPES19.Identifier && callee.property.name === "lazy";
|
|
1645
1491
|
if (isLazyCall) {
|
|
1646
1492
|
lazyComponents.add(node.id.name);
|
|
1647
1493
|
}
|
|
1648
1494
|
}
|
|
1649
1495
|
},
|
|
1650
1496
|
JSXOpeningElement(node) {
|
|
1651
|
-
if (node.name.type ===
|
|
1497
|
+
if (node.name.type === AST_NODE_TYPES19.JSXIdentifier) {
|
|
1652
1498
|
const componentName = node.name.name;
|
|
1653
1499
|
if (lazyComponents.has(componentName) && !isInsideSuspense(node)) {
|
|
1654
1500
|
context.report({
|
|
@@ -1667,11 +1513,11 @@ var jsxRequireSuspense = createRule21({
|
|
|
1667
1513
|
var jsx_require_suspense_default = jsxRequireSuspense;
|
|
1668
1514
|
|
|
1669
1515
|
// src/rules/jsx-simple-props.ts
|
|
1670
|
-
import { AST_NODE_TYPES as
|
|
1671
|
-
var
|
|
1516
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES20, ESLintUtils as ESLintUtils19 } from "@typescript-eslint/utils";
|
|
1517
|
+
var createRule19 = ESLintUtils19.RuleCreator(
|
|
1672
1518
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1673
1519
|
);
|
|
1674
|
-
var jsxSimpleProps =
|
|
1520
|
+
var jsxSimpleProps = createRule19({
|
|
1675
1521
|
name: "jsx-simple-props",
|
|
1676
1522
|
meta: {
|
|
1677
1523
|
type: "suggestion",
|
|
@@ -1686,25 +1532,25 @@ var jsxSimpleProps = createRule22({
|
|
|
1686
1532
|
defaultOptions: [],
|
|
1687
1533
|
create(context) {
|
|
1688
1534
|
const allowedExpressionTypes = /* @__PURE__ */ new Set([
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1535
|
+
AST_NODE_TYPES20.Identifier,
|
|
1536
|
+
AST_NODE_TYPES20.Literal,
|
|
1537
|
+
AST_NODE_TYPES20.JSXElement,
|
|
1538
|
+
AST_NODE_TYPES20.JSXFragment,
|
|
1539
|
+
AST_NODE_TYPES20.MemberExpression,
|
|
1540
|
+
AST_NODE_TYPES20.ArrowFunctionExpression,
|
|
1541
|
+
AST_NODE_TYPES20.FunctionExpression
|
|
1696
1542
|
]);
|
|
1697
1543
|
return {
|
|
1698
1544
|
JSXAttribute(node) {
|
|
1699
1545
|
if (!node.value) {
|
|
1700
1546
|
return;
|
|
1701
1547
|
}
|
|
1702
|
-
if (node.value.type ===
|
|
1548
|
+
if (node.value.type === AST_NODE_TYPES20.Literal) {
|
|
1703
1549
|
return;
|
|
1704
1550
|
}
|
|
1705
|
-
if (node.value.type ===
|
|
1551
|
+
if (node.value.type === AST_NODE_TYPES20.JSXExpressionContainer) {
|
|
1706
1552
|
const { expression } = node.value;
|
|
1707
|
-
if (expression.type ===
|
|
1553
|
+
if (expression.type === AST_NODE_TYPES20.JSXEmptyExpression) {
|
|
1708
1554
|
return;
|
|
1709
1555
|
}
|
|
1710
1556
|
if (!allowedExpressionTypes.has(expression.type)) {
|
|
@@ -1721,8 +1567,8 @@ var jsxSimpleProps = createRule22({
|
|
|
1721
1567
|
var jsx_simple_props_default = jsxSimpleProps;
|
|
1722
1568
|
|
|
1723
1569
|
// src/rules/jsx-sort-props.ts
|
|
1724
|
-
import { AST_NODE_TYPES as
|
|
1725
|
-
var
|
|
1570
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21, ESLintUtils as ESLintUtils20 } from "@typescript-eslint/utils";
|
|
1571
|
+
var createRule20 = ESLintUtils20.RuleCreator(
|
|
1726
1572
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1727
1573
|
);
|
|
1728
1574
|
var TYPE_GROUP = {
|
|
@@ -1736,15 +1582,15 @@ var TYPE_GROUP = {
|
|
|
1736
1582
|
SHORTHAND: 8
|
|
1737
1583
|
};
|
|
1738
1584
|
var EXPRESSION_TYPE_TO_GROUP = /* @__PURE__ */ new Map([
|
|
1739
|
-
[
|
|
1740
|
-
[
|
|
1741
|
-
[
|
|
1742
|
-
[
|
|
1743
|
-
[
|
|
1744
|
-
[
|
|
1585
|
+
[AST_NODE_TYPES21.ObjectExpression, TYPE_GROUP.OBJECT_ARRAY],
|
|
1586
|
+
[AST_NODE_TYPES21.ArrayExpression, TYPE_GROUP.OBJECT_ARRAY],
|
|
1587
|
+
[AST_NODE_TYPES21.ArrowFunctionExpression, TYPE_GROUP.FUNCTION],
|
|
1588
|
+
[AST_NODE_TYPES21.FunctionExpression, TYPE_GROUP.FUNCTION],
|
|
1589
|
+
[AST_NODE_TYPES21.JSXElement, TYPE_GROUP.JSX],
|
|
1590
|
+
[AST_NODE_TYPES21.JSXFragment, TYPE_GROUP.JSX]
|
|
1745
1591
|
]);
|
|
1746
1592
|
function isHyphenatedName(node) {
|
|
1747
|
-
return node.name.type ===
|
|
1593
|
+
return node.name.type === AST_NODE_TYPES21.JSXIdentifier && node.name.name.includes("-");
|
|
1748
1594
|
}
|
|
1749
1595
|
function getStringGroup(node) {
|
|
1750
1596
|
return isHyphenatedName(node) ? TYPE_GROUP.HYPHENATED_STRING : TYPE_GROUP.STRING;
|
|
@@ -1756,13 +1602,13 @@ function getLiteralValueGroup(value) {
|
|
|
1756
1602
|
return TYPE_GROUP.NUMBER_BOOLEAN_NULL;
|
|
1757
1603
|
}
|
|
1758
1604
|
function getExpressionGroup(expression) {
|
|
1759
|
-
if (expression.type ===
|
|
1605
|
+
if (expression.type === AST_NODE_TYPES21.Literal) {
|
|
1760
1606
|
return getLiteralValueGroup(expression.value);
|
|
1761
1607
|
}
|
|
1762
|
-
if (expression.type ===
|
|
1608
|
+
if (expression.type === AST_NODE_TYPES21.TemplateLiteral) {
|
|
1763
1609
|
return null;
|
|
1764
1610
|
}
|
|
1765
|
-
if (expression.type ===
|
|
1611
|
+
if (expression.type === AST_NODE_TYPES21.Identifier && expression.name === "undefined") {
|
|
1766
1612
|
return TYPE_GROUP.NUMBER_BOOLEAN_NULL;
|
|
1767
1613
|
}
|
|
1768
1614
|
return EXPRESSION_TYPE_TO_GROUP.get(expression.type) ?? TYPE_GROUP.EXPRESSION;
|
|
@@ -1771,17 +1617,17 @@ function getTypeGroup(node) {
|
|
|
1771
1617
|
if (node.value === null) {
|
|
1772
1618
|
return TYPE_GROUP.SHORTHAND;
|
|
1773
1619
|
}
|
|
1774
|
-
if (node.value.type ===
|
|
1620
|
+
if (node.value.type === AST_NODE_TYPES21.Literal) {
|
|
1775
1621
|
if (typeof node.value.value === "string") {
|
|
1776
1622
|
return getStringGroup(node);
|
|
1777
1623
|
}
|
|
1778
1624
|
return TYPE_GROUP.NUMBER_BOOLEAN_NULL;
|
|
1779
1625
|
}
|
|
1780
|
-
if (node.value.type !==
|
|
1626
|
+
if (node.value.type !== AST_NODE_TYPES21.JSXExpressionContainer) {
|
|
1781
1627
|
return null;
|
|
1782
1628
|
}
|
|
1783
1629
|
const { expression } = node.value;
|
|
1784
|
-
if (expression.type ===
|
|
1630
|
+
if (expression.type === AST_NODE_TYPES21.JSXEmptyExpression) {
|
|
1785
1631
|
return null;
|
|
1786
1632
|
}
|
|
1787
1633
|
const group = getExpressionGroup(expression);
|
|
@@ -1793,7 +1639,7 @@ function getTypeGroup(node) {
|
|
|
1793
1639
|
function hasUnsortedProps(attributes) {
|
|
1794
1640
|
let lastGroup = 0;
|
|
1795
1641
|
return attributes.some((attribute) => {
|
|
1796
|
-
if (attribute.type ===
|
|
1642
|
+
if (attribute.type === AST_NODE_TYPES21.JSXSpreadAttribute) {
|
|
1797
1643
|
lastGroup = 0;
|
|
1798
1644
|
return false;
|
|
1799
1645
|
}
|
|
@@ -1817,7 +1663,7 @@ function getSegments(attributes) {
|
|
|
1817
1663
|
const result = [];
|
|
1818
1664
|
let current = [];
|
|
1819
1665
|
attributes.forEach((attr) => {
|
|
1820
|
-
if (attr.type ===
|
|
1666
|
+
if (attr.type === AST_NODE_TYPES21.JSXSpreadAttribute) {
|
|
1821
1667
|
if (current.length > 0) {
|
|
1822
1668
|
result.push(current);
|
|
1823
1669
|
current = [];
|
|
@@ -1831,7 +1677,7 @@ function getSegments(attributes) {
|
|
|
1831
1677
|
}
|
|
1832
1678
|
return result;
|
|
1833
1679
|
}
|
|
1834
|
-
var jsxSortProps =
|
|
1680
|
+
var jsxSortProps = createRule20({
|
|
1835
1681
|
name: "jsx-sort-props",
|
|
1836
1682
|
meta: {
|
|
1837
1683
|
type: "suggestion",
|
|
@@ -1866,11 +1712,11 @@ var jsxSortProps = createRule23({
|
|
|
1866
1712
|
var jsx_sort_props_default = jsxSortProps;
|
|
1867
1713
|
|
|
1868
1714
|
// src/rules/jsx-spread-props-last.ts
|
|
1869
|
-
import { AST_NODE_TYPES as
|
|
1870
|
-
var
|
|
1715
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22, ESLintUtils as ESLintUtils21 } from "@typescript-eslint/utils";
|
|
1716
|
+
var createRule21 = ESLintUtils21.RuleCreator(
|
|
1871
1717
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1872
1718
|
);
|
|
1873
|
-
var jsxSpreadPropsLast =
|
|
1719
|
+
var jsxSpreadPropsLast = createRule21({
|
|
1874
1720
|
name: "jsx-spread-props-last",
|
|
1875
1721
|
meta: {
|
|
1876
1722
|
type: "suggestion",
|
|
@@ -1889,12 +1735,12 @@ var jsxSpreadPropsLast = createRule24({
|
|
|
1889
1735
|
const { attributes } = node;
|
|
1890
1736
|
let lastNonSpreadIndex = -1;
|
|
1891
1737
|
attributes.forEach((attribute, index) => {
|
|
1892
|
-
if (attribute.type !==
|
|
1738
|
+
if (attribute.type !== AST_NODE_TYPES22.JSXSpreadAttribute) {
|
|
1893
1739
|
lastNonSpreadIndex = index;
|
|
1894
1740
|
}
|
|
1895
1741
|
});
|
|
1896
1742
|
attributes.forEach((attribute, index) => {
|
|
1897
|
-
if (attribute.type ===
|
|
1743
|
+
if (attribute.type === AST_NODE_TYPES22.JSXSpreadAttribute && index < lastNonSpreadIndex) {
|
|
1898
1744
|
context.report({
|
|
1899
1745
|
node: attribute,
|
|
1900
1746
|
messageId: "spreadNotLast"
|
|
@@ -1908,12 +1754,12 @@ var jsxSpreadPropsLast = createRule24({
|
|
|
1908
1754
|
var jsx_spread_props_last_default = jsxSpreadPropsLast;
|
|
1909
1755
|
|
|
1910
1756
|
// src/rules/newline-after-multiline-block.ts
|
|
1911
|
-
import { AST_NODE_TYPES as
|
|
1912
|
-
var
|
|
1757
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23, ESLintUtils as ESLintUtils22 } from "@typescript-eslint/utils";
|
|
1758
|
+
var createRule22 = ESLintUtils22.RuleCreator(
|
|
1913
1759
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1914
1760
|
);
|
|
1915
1761
|
function isImportDeclaration(node) {
|
|
1916
|
-
return node.type ===
|
|
1762
|
+
return node.type === AST_NODE_TYPES23.ImportDeclaration;
|
|
1917
1763
|
}
|
|
1918
1764
|
function checkStatements(statements, context) {
|
|
1919
1765
|
const { sourceCode } = context;
|
|
@@ -1948,7 +1794,7 @@ function checkStatements(statements, context) {
|
|
|
1948
1794
|
}
|
|
1949
1795
|
});
|
|
1950
1796
|
}
|
|
1951
|
-
var newlineAfterMultilineBlock =
|
|
1797
|
+
var newlineAfterMultilineBlock = createRule22({
|
|
1952
1798
|
name: "newline-after-multiline-block",
|
|
1953
1799
|
meta: {
|
|
1954
1800
|
type: "layout",
|
|
@@ -1976,11 +1822,11 @@ var newlineAfterMultilineBlock = createRule25({
|
|
|
1976
1822
|
var newline_after_multiline_block_default = newlineAfterMultilineBlock;
|
|
1977
1823
|
|
|
1978
1824
|
// src/rules/newline-before-return.ts
|
|
1979
|
-
import { AST_NODE_TYPES as
|
|
1980
|
-
var
|
|
1825
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24, ESLintUtils as ESLintUtils23 } from "@typescript-eslint/utils";
|
|
1826
|
+
var createRule23 = ESLintUtils23.RuleCreator(
|
|
1981
1827
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1982
1828
|
);
|
|
1983
|
-
var newlineBeforeReturn =
|
|
1829
|
+
var newlineBeforeReturn = createRule23({
|
|
1984
1830
|
name: "newline-before-return",
|
|
1985
1831
|
meta: {
|
|
1986
1832
|
type: "layout",
|
|
@@ -1998,7 +1844,7 @@ var newlineBeforeReturn = createRule26({
|
|
|
1998
1844
|
const { sourceCode } = context;
|
|
1999
1845
|
function checkReturnStatement(node) {
|
|
2000
1846
|
const { parent } = node;
|
|
2001
|
-
if (!parent || parent.type !==
|
|
1847
|
+
if (!parent || parent.type !== AST_NODE_TYPES24.BlockStatement) {
|
|
2002
1848
|
return;
|
|
2003
1849
|
}
|
|
2004
1850
|
const { body: statements } = parent;
|
|
@@ -2034,61 +1880,12 @@ var newlineBeforeReturn = createRule26({
|
|
|
2034
1880
|
});
|
|
2035
1881
|
var newline_before_return_default = newlineBeforeReturn;
|
|
2036
1882
|
|
|
2037
|
-
// src/rules/nextjs-require-public-env.ts
|
|
2038
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES26, ESLintUtils as ESLintUtils27 } from "@typescript-eslint/utils";
|
|
2039
|
-
var createRule27 = ESLintUtils27.RuleCreator(
|
|
2040
|
-
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2041
|
-
);
|
|
2042
|
-
var nextjsRequirePublicEnv = createRule27({
|
|
2043
|
-
name: "nextjs-require-public-env",
|
|
2044
|
-
meta: {
|
|
2045
|
-
type: "problem",
|
|
2046
|
-
docs: {
|
|
2047
|
-
description: "Require NEXT_PUBLIC_ prefix for environment variables in client components"
|
|
2048
|
-
},
|
|
2049
|
-
messages: {
|
|
2050
|
-
requirePublicPrefix: "Environment variable '{{ name }}' must use NEXT_PUBLIC_ prefix in client components. Use 'NEXT_PUBLIC_{{ name }}' instead."
|
|
2051
|
-
},
|
|
2052
|
-
schema: []
|
|
2053
|
-
},
|
|
2054
|
-
defaultOptions: [],
|
|
2055
|
-
create(context) {
|
|
2056
|
-
let isClientComponent = false;
|
|
2057
|
-
return {
|
|
2058
|
-
Program(node) {
|
|
2059
|
-
const firstStatement = node.body[0];
|
|
2060
|
-
if (firstStatement?.type === AST_NODE_TYPES26.ExpressionStatement && firstStatement.expression.type === AST_NODE_TYPES26.Literal && firstStatement.expression.value === "use client") {
|
|
2061
|
-
isClientComponent = true;
|
|
2062
|
-
}
|
|
2063
|
-
},
|
|
2064
|
-
MemberExpression(node) {
|
|
2065
|
-
if (!isClientComponent) {
|
|
2066
|
-
return;
|
|
2067
|
-
}
|
|
2068
|
-
if (node.object.type === AST_NODE_TYPES26.MemberExpression && node.object.object.type === AST_NODE_TYPES26.Identifier && node.object.object.name === "process" && node.object.property.type === AST_NODE_TYPES26.Identifier && node.object.property.name === "env" && node.property.type === AST_NODE_TYPES26.Identifier) {
|
|
2069
|
-
const envVarName = node.property.name;
|
|
2070
|
-
if (!envVarName.startsWith("NEXT_PUBLIC_") && envVarName !== "NODE_ENV") {
|
|
2071
|
-
context.report({
|
|
2072
|
-
node: node.property,
|
|
2073
|
-
messageId: "requirePublicPrefix",
|
|
2074
|
-
data: {
|
|
2075
|
-
name: envVarName
|
|
2076
|
-
}
|
|
2077
|
-
});
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
};
|
|
2082
|
-
}
|
|
2083
|
-
});
|
|
2084
|
-
var nextjs_require_public_env_default = nextjsRequirePublicEnv;
|
|
2085
|
-
|
|
2086
1883
|
// src/rules/no-complex-inline-return.ts
|
|
2087
|
-
import { AST_NODE_TYPES as
|
|
2088
|
-
var
|
|
1884
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25, ESLintUtils as ESLintUtils24 } from "@typescript-eslint/utils";
|
|
1885
|
+
var createRule24 = ESLintUtils24.RuleCreator(
|
|
2089
1886
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2090
1887
|
);
|
|
2091
|
-
var noComplexInlineReturn =
|
|
1888
|
+
var noComplexInlineReturn = createRule24({
|
|
2092
1889
|
name: "no-complex-inline-return",
|
|
2093
1890
|
meta: {
|
|
2094
1891
|
type: "suggestion",
|
|
@@ -2104,13 +1901,13 @@ var noComplexInlineReturn = createRule28({
|
|
|
2104
1901
|
create(context) {
|
|
2105
1902
|
const isComplexExpression = (node) => {
|
|
2106
1903
|
if (!node) return false;
|
|
2107
|
-
if (node.type ===
|
|
1904
|
+
if (node.type === AST_NODE_TYPES25.ConditionalExpression) {
|
|
2108
1905
|
return true;
|
|
2109
1906
|
}
|
|
2110
|
-
if (node.type ===
|
|
1907
|
+
if (node.type === AST_NODE_TYPES25.LogicalExpression) {
|
|
2111
1908
|
return true;
|
|
2112
1909
|
}
|
|
2113
|
-
if (node.type ===
|
|
1910
|
+
if (node.type === AST_NODE_TYPES25.NewExpression) {
|
|
2114
1911
|
return true;
|
|
2115
1912
|
}
|
|
2116
1913
|
return false;
|
|
@@ -2130,11 +1927,11 @@ var noComplexInlineReturn = createRule28({
|
|
|
2130
1927
|
var no_complex_inline_return_default = noComplexInlineReturn;
|
|
2131
1928
|
|
|
2132
1929
|
// src/rules/no-direct-date.ts
|
|
2133
|
-
import { AST_NODE_TYPES as
|
|
2134
|
-
var
|
|
1930
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26, ESLintUtils as ESLintUtils25 } from "@typescript-eslint/utils";
|
|
1931
|
+
var createRule25 = ESLintUtils25.RuleCreator(
|
|
2135
1932
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2136
1933
|
);
|
|
2137
|
-
var noDirectDate =
|
|
1934
|
+
var noDirectDate = createRule25({
|
|
2138
1935
|
name: "no-direct-date",
|
|
2139
1936
|
meta: {
|
|
2140
1937
|
type: "problem",
|
|
@@ -2152,7 +1949,7 @@ var noDirectDate = createRule29({
|
|
|
2152
1949
|
create(context) {
|
|
2153
1950
|
return {
|
|
2154
1951
|
NewExpression(node) {
|
|
2155
|
-
if (node.callee.type ===
|
|
1952
|
+
if (node.callee.type === AST_NODE_TYPES26.Identifier && node.callee.name === "Date") {
|
|
2156
1953
|
context.report({
|
|
2157
1954
|
node,
|
|
2158
1955
|
messageId: "noNewDate"
|
|
@@ -2160,7 +1957,7 @@ var noDirectDate = createRule29({
|
|
|
2160
1957
|
}
|
|
2161
1958
|
},
|
|
2162
1959
|
CallExpression(node) {
|
|
2163
|
-
if (node.callee.type ===
|
|
1960
|
+
if (node.callee.type === AST_NODE_TYPES26.MemberExpression && node.callee.object.type === AST_NODE_TYPES26.Identifier && node.callee.object.name === "Date" && node.callee.property.type === AST_NODE_TYPES26.Identifier) {
|
|
2164
1961
|
const methodName = node.callee.property.name;
|
|
2165
1962
|
if (methodName === "now") {
|
|
2166
1963
|
context.report({
|
|
@@ -2183,11 +1980,11 @@ var no_direct_date_default = noDirectDate;
|
|
|
2183
1980
|
|
|
2184
1981
|
// src/rules/no-emoji.ts
|
|
2185
1982
|
import emojiRegex from "emoji-regex";
|
|
2186
|
-
import { ESLintUtils as
|
|
2187
|
-
var
|
|
1983
|
+
import { ESLintUtils as ESLintUtils26 } from "@typescript-eslint/utils";
|
|
1984
|
+
var createRule26 = ESLintUtils26.RuleCreator(
|
|
2188
1985
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2189
1986
|
);
|
|
2190
|
-
var noEmoji =
|
|
1987
|
+
var noEmoji = createRule26({
|
|
2191
1988
|
name: "no-emoji",
|
|
2192
1989
|
meta: {
|
|
2193
1990
|
type: "problem",
|
|
@@ -2221,11 +2018,11 @@ var noEmoji = createRule30({
|
|
|
2221
2018
|
var no_emoji_default = noEmoji;
|
|
2222
2019
|
|
|
2223
2020
|
// src/rules/no-env-fallback.ts
|
|
2224
|
-
import { AST_NODE_TYPES as
|
|
2225
|
-
var
|
|
2021
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27, ESLintUtils as ESLintUtils27 } from "@typescript-eslint/utils";
|
|
2022
|
+
var createRule27 = ESLintUtils27.RuleCreator(
|
|
2226
2023
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2227
2024
|
);
|
|
2228
|
-
var noEnvFallback =
|
|
2025
|
+
var noEnvFallback = createRule27({
|
|
2229
2026
|
name: "no-env-fallback",
|
|
2230
2027
|
meta: {
|
|
2231
2028
|
type: "problem",
|
|
@@ -2240,16 +2037,16 @@ var noEnvFallback = createRule31({
|
|
|
2240
2037
|
defaultOptions: [],
|
|
2241
2038
|
create(context) {
|
|
2242
2039
|
const isProcessEnvAccess = (node) => {
|
|
2243
|
-
if (node.type !==
|
|
2040
|
+
if (node.type !== AST_NODE_TYPES27.MemberExpression) {
|
|
2244
2041
|
return false;
|
|
2245
2042
|
}
|
|
2246
2043
|
const { object } = node;
|
|
2247
|
-
if (object.type !==
|
|
2044
|
+
if (object.type !== AST_NODE_TYPES27.MemberExpression) {
|
|
2248
2045
|
return false;
|
|
2249
2046
|
}
|
|
2250
2047
|
const processNode = object.object;
|
|
2251
2048
|
const envNode = object.property;
|
|
2252
|
-
return processNode.type ===
|
|
2049
|
+
return processNode.type === AST_NODE_TYPES27.Identifier && processNode.name === "process" && envNode.type === AST_NODE_TYPES27.Identifier && envNode.name === "env";
|
|
2253
2050
|
};
|
|
2254
2051
|
return {
|
|
2255
2052
|
LogicalExpression(node) {
|
|
@@ -2274,11 +2071,11 @@ var noEnvFallback = createRule31({
|
|
|
2274
2071
|
var no_env_fallback_default = noEnvFallback;
|
|
2275
2072
|
|
|
2276
2073
|
// src/rules/no-inline-default-export.ts
|
|
2277
|
-
import { AST_NODE_TYPES as
|
|
2278
|
-
var
|
|
2074
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28, ESLintUtils as ESLintUtils28 } from "@typescript-eslint/utils";
|
|
2075
|
+
var createRule28 = ESLintUtils28.RuleCreator(
|
|
2279
2076
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2280
2077
|
);
|
|
2281
|
-
var noInlineDefaultExport =
|
|
2078
|
+
var noInlineDefaultExport = createRule28({
|
|
2282
2079
|
name: "no-inline-default-export",
|
|
2283
2080
|
meta: {
|
|
2284
2081
|
type: "suggestion",
|
|
@@ -2297,7 +2094,7 @@ var noInlineDefaultExport = createRule32({
|
|
|
2297
2094
|
return {
|
|
2298
2095
|
ExportDefaultDeclaration(node) {
|
|
2299
2096
|
const { declaration } = node;
|
|
2300
|
-
if (declaration.type ===
|
|
2097
|
+
if (declaration.type === AST_NODE_TYPES28.FunctionDeclaration) {
|
|
2301
2098
|
if (declaration.id) {
|
|
2302
2099
|
context.report({
|
|
2303
2100
|
node,
|
|
@@ -2312,7 +2109,7 @@ var noInlineDefaultExport = createRule32({
|
|
|
2312
2109
|
});
|
|
2313
2110
|
}
|
|
2314
2111
|
}
|
|
2315
|
-
if (declaration.type ===
|
|
2112
|
+
if (declaration.type === AST_NODE_TYPES28.ClassDeclaration) {
|
|
2316
2113
|
if (declaration.id) {
|
|
2317
2114
|
context.report({
|
|
2318
2115
|
node,
|
|
@@ -2327,7 +2124,7 @@ var noInlineDefaultExport = createRule32({
|
|
|
2327
2124
|
});
|
|
2328
2125
|
}
|
|
2329
2126
|
}
|
|
2330
|
-
if (declaration.type ===
|
|
2127
|
+
if (declaration.type === AST_NODE_TYPES28.ArrowFunctionExpression || declaration.type === AST_NODE_TYPES28.FunctionExpression) {
|
|
2331
2128
|
context.report({
|
|
2332
2129
|
node,
|
|
2333
2130
|
messageId: "noAnonymousDefaultExport",
|
|
@@ -2340,14 +2137,14 @@ var noInlineDefaultExport = createRule32({
|
|
|
2340
2137
|
if (!declaration) {
|
|
2341
2138
|
return;
|
|
2342
2139
|
}
|
|
2343
|
-
if (declaration.type ===
|
|
2140
|
+
if (declaration.type === AST_NODE_TYPES28.FunctionDeclaration && declaration.id) {
|
|
2344
2141
|
context.report({
|
|
2345
2142
|
node,
|
|
2346
2143
|
messageId: "noInlineNamedExport",
|
|
2347
2144
|
data: { type: "function", name: declaration.id.name }
|
|
2348
2145
|
});
|
|
2349
2146
|
}
|
|
2350
|
-
if (declaration.type ===
|
|
2147
|
+
if (declaration.type === AST_NODE_TYPES28.ClassDeclaration && declaration.id) {
|
|
2351
2148
|
context.report({
|
|
2352
2149
|
node,
|
|
2353
2150
|
messageId: "noInlineNamedExport",
|
|
@@ -2361,36 +2158,45 @@ var noInlineDefaultExport = createRule32({
|
|
|
2361
2158
|
var no_inline_default_export_default = noInlineDefaultExport;
|
|
2362
2159
|
|
|
2363
2160
|
// src/rules/no-inline-nested-object.ts
|
|
2364
|
-
import { AST_NODE_TYPES as
|
|
2365
|
-
var
|
|
2161
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29, ESLintUtils as ESLintUtils29 } from "@typescript-eslint/utils";
|
|
2162
|
+
var createRule29 = ESLintUtils29.RuleCreator(
|
|
2366
2163
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2367
2164
|
);
|
|
2368
2165
|
function isObjectOrArray(node) {
|
|
2369
|
-
return node.type ===
|
|
2166
|
+
return node.type === AST_NODE_TYPES29.ObjectExpression || node.type === AST_NODE_TYPES29.ArrayExpression || node.type === AST_NODE_TYPES29.TSAsExpression;
|
|
2370
2167
|
}
|
|
2371
2168
|
function getInnerExpression(node) {
|
|
2372
|
-
if (node.type ===
|
|
2169
|
+
if (node.type === AST_NODE_TYPES29.TSAsExpression) {
|
|
2373
2170
|
return getInnerExpression(node.expression);
|
|
2374
2171
|
}
|
|
2375
2172
|
return node;
|
|
2376
2173
|
}
|
|
2377
|
-
function
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2174
|
+
function isNestedStructure(node) {
|
|
2175
|
+
const inner = getInnerExpression(node);
|
|
2176
|
+
return inner.type === AST_NODE_TYPES29.ObjectExpression || inner.type === AST_NODE_TYPES29.ArrayExpression;
|
|
2177
|
+
}
|
|
2178
|
+
function containsNestedStructure(node) {
|
|
2179
|
+
if (node.type === AST_NODE_TYPES29.ObjectExpression) {
|
|
2180
|
+
return node.properties.some((prop) => {
|
|
2181
|
+
if (prop.type !== AST_NODE_TYPES29.Property) return false;
|
|
2182
|
+
return isNestedStructure(prop.value);
|
|
2183
|
+
});
|
|
2184
|
+
}
|
|
2185
|
+
return node.elements.some((el) => {
|
|
2186
|
+
if (el === null) return false;
|
|
2187
|
+
return isNestedStructure(el);
|
|
2382
2188
|
});
|
|
2383
2189
|
}
|
|
2384
|
-
var noInlineNestedObject =
|
|
2190
|
+
var noInlineNestedObject = createRule29({
|
|
2385
2191
|
name: "no-inline-nested-object",
|
|
2386
2192
|
meta: {
|
|
2387
2193
|
type: "layout",
|
|
2388
2194
|
docs: {
|
|
2389
|
-
description: "Require nested objects
|
|
2195
|
+
description: "Require object or array values that contain further nested objects or arrays to span multiple lines"
|
|
2390
2196
|
},
|
|
2391
2197
|
fixable: "whitespace",
|
|
2392
2198
|
messages: {
|
|
2393
|
-
requireMultiline: "
|
|
2199
|
+
requireMultiline: "Inline collections containing nested objects or arrays should span multiple lines"
|
|
2394
2200
|
},
|
|
2395
2201
|
schema: []
|
|
2396
2202
|
},
|
|
@@ -2403,23 +2209,20 @@ var noInlineNestedObject = createRule33({
|
|
|
2403
2209
|
return;
|
|
2404
2210
|
}
|
|
2405
2211
|
const valueNode = getInnerExpression(node.value);
|
|
2406
|
-
if (valueNode.type !==
|
|
2212
|
+
if (valueNode.type !== AST_NODE_TYPES29.ObjectExpression && valueNode.type !== AST_NODE_TYPES29.ArrayExpression) {
|
|
2407
2213
|
return;
|
|
2408
2214
|
}
|
|
2409
2215
|
if (!valueNode.loc) {
|
|
2410
2216
|
return;
|
|
2411
2217
|
}
|
|
2412
|
-
const elements = valueNode.type === AST_NODE_TYPES31.ObjectExpression ? valueNode.properties : valueNode.elements;
|
|
2413
|
-
if (elements.length <= 1) {
|
|
2414
|
-
return;
|
|
2415
|
-
}
|
|
2416
|
-
if (valueNode.type === AST_NODE_TYPES31.ArrayExpression && arrayContainsOnlyPrimitives(valueNode)) {
|
|
2417
|
-
return;
|
|
2418
|
-
}
|
|
2419
2218
|
const isMultiline = valueNode.loc.start.line !== valueNode.loc.end.line;
|
|
2420
2219
|
if (isMultiline) {
|
|
2421
2220
|
return;
|
|
2422
2221
|
}
|
|
2222
|
+
if (!containsNestedStructure(valueNode)) {
|
|
2223
|
+
return;
|
|
2224
|
+
}
|
|
2225
|
+
const elements = valueNode.type === AST_NODE_TYPES29.ObjectExpression ? valueNode.properties : valueNode.elements;
|
|
2423
2226
|
context.report({
|
|
2424
2227
|
node: valueNode,
|
|
2425
2228
|
messageId: "requireMultiline",
|
|
@@ -2432,7 +2235,7 @@ var noInlineNestedObject = createRule33({
|
|
|
2432
2235
|
const indent = " ".repeat(node.loc?.start.column ?? 0);
|
|
2433
2236
|
const innerIndent = `${indent} `;
|
|
2434
2237
|
const elementTexts = elements.filter((el) => el !== null).map((el) => sourceCode.getText(el));
|
|
2435
|
-
const isObject = valueNode.type ===
|
|
2238
|
+
const isObject = valueNode.type === AST_NODE_TYPES29.ObjectExpression;
|
|
2436
2239
|
const openChar = isObject ? "{" : "[";
|
|
2437
2240
|
const closeChar = isObject ? "}" : "]";
|
|
2438
2241
|
const formattedElements = elementTexts.map((text) => `${innerIndent}${text},`).join("\n");
|
|
@@ -2449,20 +2252,20 @@ ${indent}${closeChar}`;
|
|
|
2449
2252
|
var no_inline_nested_object_default = noInlineNestedObject;
|
|
2450
2253
|
|
|
2451
2254
|
// src/rules/no-inline-return-properties.ts
|
|
2452
|
-
import { AST_NODE_TYPES as
|
|
2453
|
-
var
|
|
2255
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30, ESLintUtils as ESLintUtils30 } from "@typescript-eslint/utils";
|
|
2256
|
+
var createRule30 = ESLintUtils30.RuleCreator(
|
|
2454
2257
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2455
2258
|
);
|
|
2456
2259
|
var isShorthandProperty = (property) => {
|
|
2457
|
-
if (property.type ===
|
|
2260
|
+
if (property.type === AST_NODE_TYPES30.SpreadElement) {
|
|
2458
2261
|
return true;
|
|
2459
2262
|
}
|
|
2460
|
-
if (property.type !==
|
|
2263
|
+
if (property.type !== AST_NODE_TYPES30.Property) {
|
|
2461
2264
|
return false;
|
|
2462
2265
|
}
|
|
2463
2266
|
return property.shorthand;
|
|
2464
2267
|
};
|
|
2465
|
-
var noInlineReturnProperties =
|
|
2268
|
+
var noInlineReturnProperties = createRule30({
|
|
2466
2269
|
name: "no-inline-return-properties",
|
|
2467
2270
|
meta: {
|
|
2468
2271
|
type: "suggestion",
|
|
@@ -2478,20 +2281,20 @@ var noInlineReturnProperties = createRule34({
|
|
|
2478
2281
|
create(context) {
|
|
2479
2282
|
return {
|
|
2480
2283
|
ReturnStatement(node) {
|
|
2481
|
-
if (!node.argument || node.argument.type !==
|
|
2284
|
+
if (!node.argument || node.argument.type !== AST_NODE_TYPES30.ObjectExpression) {
|
|
2482
2285
|
return;
|
|
2483
2286
|
}
|
|
2484
2287
|
node.argument.properties.forEach((property) => {
|
|
2485
2288
|
if (isShorthandProperty(property)) {
|
|
2486
2289
|
return;
|
|
2487
2290
|
}
|
|
2488
|
-
if (property.type !==
|
|
2291
|
+
if (property.type !== AST_NODE_TYPES30.Property) {
|
|
2489
2292
|
return;
|
|
2490
2293
|
}
|
|
2491
2294
|
let keyName = null;
|
|
2492
|
-
if (property.key.type ===
|
|
2295
|
+
if (property.key.type === AST_NODE_TYPES30.Identifier) {
|
|
2493
2296
|
keyName = property.key.name;
|
|
2494
|
-
} else if (property.key.type ===
|
|
2297
|
+
} else if (property.key.type === AST_NODE_TYPES30.Literal) {
|
|
2495
2298
|
keyName = String(property.key.value);
|
|
2496
2299
|
}
|
|
2497
2300
|
context.report({
|
|
@@ -2507,12 +2310,12 @@ var noInlineReturnProperties = createRule34({
|
|
|
2507
2310
|
var no_inline_return_properties_default = noInlineReturnProperties;
|
|
2508
2311
|
|
|
2509
2312
|
// src/rules/no-inline-type-import.ts
|
|
2510
|
-
import { AST_NODE_TYPES as
|
|
2511
|
-
var
|
|
2313
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31, ESLintUtils as ESLintUtils31 } from "@typescript-eslint/utils";
|
|
2314
|
+
var createRule31 = ESLintUtils31.RuleCreator(
|
|
2512
2315
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2513
2316
|
);
|
|
2514
|
-
var isInlineTypeSpecifier = (specifier) => specifier.type ===
|
|
2515
|
-
var noInlineTypeImport =
|
|
2317
|
+
var isInlineTypeSpecifier = (specifier) => specifier.type === AST_NODE_TYPES31.ImportSpecifier && specifier.importKind === "type";
|
|
2318
|
+
var noInlineTypeImport = createRule31({
|
|
2516
2319
|
name: "no-inline-type-import",
|
|
2517
2320
|
meta: {
|
|
2518
2321
|
type: "suggestion",
|
|
@@ -2549,7 +2352,7 @@ var noInlineTypeImport = createRule35({
|
|
|
2549
2352
|
);
|
|
2550
2353
|
const typeImport = `import type { ${typeSpecifierTexts.join(", ")} } from ${sourceText};`;
|
|
2551
2354
|
const valueSpecifiers = node.specifiers.filter(
|
|
2552
|
-
(specifier) => !(specifier.type ===
|
|
2355
|
+
(specifier) => !(specifier.type === AST_NODE_TYPES31.ImportSpecifier && specifier.importKind === "type")
|
|
2553
2356
|
);
|
|
2554
2357
|
if (valueSpecifiers.length === 0) {
|
|
2555
2358
|
return fixer.replaceText(node, typeImport);
|
|
@@ -2557,11 +2360,11 @@ var noInlineTypeImport = createRule35({
|
|
|
2557
2360
|
const parts = [];
|
|
2558
2361
|
const namedValueSpecifiers = [];
|
|
2559
2362
|
for (const specifier of valueSpecifiers) {
|
|
2560
|
-
if (specifier.type ===
|
|
2363
|
+
if (specifier.type === AST_NODE_TYPES31.ImportDefaultSpecifier) {
|
|
2561
2364
|
parts.push(specifier.local.name);
|
|
2562
|
-
} else if (specifier.type ===
|
|
2365
|
+
} else if (specifier.type === AST_NODE_TYPES31.ImportNamespaceSpecifier) {
|
|
2563
2366
|
parts.push(`* as ${specifier.local.name}`);
|
|
2564
|
-
} else if (specifier.type ===
|
|
2367
|
+
} else if (specifier.type === AST_NODE_TYPES31.ImportSpecifier) {
|
|
2565
2368
|
namedValueSpecifiers.push(specifier);
|
|
2566
2369
|
}
|
|
2567
2370
|
}
|
|
@@ -2581,8 +2384,8 @@ ${typeImport}`);
|
|
|
2581
2384
|
var no_inline_type_import_default = noInlineTypeImport;
|
|
2582
2385
|
|
|
2583
2386
|
// src/rules/no-lazy-identifiers.ts
|
|
2584
|
-
import { AST_NODE_TYPES as
|
|
2585
|
-
var
|
|
2387
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32, ESLintUtils as ESLintUtils32 } from "@typescript-eslint/utils";
|
|
2388
|
+
var createRule32 = ESLintUtils32.RuleCreator(
|
|
2586
2389
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2587
2390
|
);
|
|
2588
2391
|
var KEYBOARD_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm", "1234567890"];
|
|
@@ -2623,7 +2426,7 @@ var isLazyIdentifier = (name) => {
|
|
|
2623
2426
|
}
|
|
2624
2427
|
return false;
|
|
2625
2428
|
};
|
|
2626
|
-
var noLazyIdentifiers =
|
|
2429
|
+
var noLazyIdentifiers = createRule32({
|
|
2627
2430
|
name: "no-lazy-identifiers",
|
|
2628
2431
|
meta: {
|
|
2629
2432
|
type: "problem",
|
|
@@ -2649,27 +2452,27 @@ var noLazyIdentifiers = createRule36({
|
|
|
2649
2452
|
});
|
|
2650
2453
|
};
|
|
2651
2454
|
const checkPattern = (pattern) => {
|
|
2652
|
-
if (pattern.type ===
|
|
2455
|
+
if (pattern.type === AST_NODE_TYPES32.Identifier) {
|
|
2653
2456
|
checkIdentifier(pattern);
|
|
2654
|
-
} else if (pattern.type ===
|
|
2457
|
+
} else if (pattern.type === AST_NODE_TYPES32.ObjectPattern) {
|
|
2655
2458
|
pattern.properties.forEach((prop) => {
|
|
2656
|
-
if (prop.type ===
|
|
2459
|
+
if (prop.type === AST_NODE_TYPES32.Property && prop.value.type === AST_NODE_TYPES32.Identifier) {
|
|
2657
2460
|
checkIdentifier(prop.value);
|
|
2658
|
-
} else if (prop.type ===
|
|
2461
|
+
} else if (prop.type === AST_NODE_TYPES32.RestElement && prop.argument.type === AST_NODE_TYPES32.Identifier) {
|
|
2659
2462
|
checkIdentifier(prop.argument);
|
|
2660
2463
|
}
|
|
2661
2464
|
});
|
|
2662
|
-
} else if (pattern.type ===
|
|
2465
|
+
} else if (pattern.type === AST_NODE_TYPES32.ArrayPattern) {
|
|
2663
2466
|
pattern.elements.forEach((element) => {
|
|
2664
|
-
if (element?.type ===
|
|
2467
|
+
if (element?.type === AST_NODE_TYPES32.Identifier) {
|
|
2665
2468
|
checkIdentifier(element);
|
|
2666
|
-
} else if (element?.type ===
|
|
2469
|
+
} else if (element?.type === AST_NODE_TYPES32.RestElement && element.argument.type === AST_NODE_TYPES32.Identifier) {
|
|
2667
2470
|
checkIdentifier(element.argument);
|
|
2668
2471
|
}
|
|
2669
2472
|
});
|
|
2670
|
-
} else if (pattern.type ===
|
|
2473
|
+
} else if (pattern.type === AST_NODE_TYPES32.AssignmentPattern && pattern.left.type === AST_NODE_TYPES32.Identifier) {
|
|
2671
2474
|
checkIdentifier(pattern.left);
|
|
2672
|
-
} else if (pattern.type ===
|
|
2475
|
+
} else if (pattern.type === AST_NODE_TYPES32.RestElement && pattern.argument.type === AST_NODE_TYPES32.Identifier) {
|
|
2673
2476
|
checkIdentifier(pattern.argument);
|
|
2674
2477
|
}
|
|
2675
2478
|
};
|
|
@@ -2714,11 +2517,11 @@ var noLazyIdentifiers = createRule36({
|
|
|
2714
2517
|
var no_lazy_identifiers_default = noLazyIdentifiers;
|
|
2715
2518
|
|
|
2716
2519
|
// src/rules/no-logic-in-params.ts
|
|
2717
|
-
import { AST_NODE_TYPES as
|
|
2718
|
-
var
|
|
2520
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33, ESLintUtils as ESLintUtils33 } from "@typescript-eslint/utils";
|
|
2521
|
+
var createRule33 = ESLintUtils33.RuleCreator(
|
|
2719
2522
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2720
2523
|
);
|
|
2721
|
-
var noLogicInParams =
|
|
2524
|
+
var noLogicInParams = createRule33({
|
|
2722
2525
|
name: "no-logic-in-params",
|
|
2723
2526
|
meta: {
|
|
2724
2527
|
type: "suggestion",
|
|
@@ -2733,20 +2536,20 @@ var noLogicInParams = createRule37({
|
|
|
2733
2536
|
defaultOptions: [],
|
|
2734
2537
|
create(context) {
|
|
2735
2538
|
const isComplexExpression = (node) => {
|
|
2736
|
-
if (node.type ===
|
|
2539
|
+
if (node.type === AST_NODE_TYPES33.SpreadElement) {
|
|
2737
2540
|
return false;
|
|
2738
2541
|
}
|
|
2739
|
-
if (node.type ===
|
|
2542
|
+
if (node.type === AST_NODE_TYPES33.ConditionalExpression) {
|
|
2740
2543
|
return true;
|
|
2741
2544
|
}
|
|
2742
|
-
if (node.type ===
|
|
2545
|
+
if (node.type === AST_NODE_TYPES33.LogicalExpression) {
|
|
2743
2546
|
return true;
|
|
2744
2547
|
}
|
|
2745
|
-
if (node.type ===
|
|
2548
|
+
if (node.type === AST_NODE_TYPES33.BinaryExpression) {
|
|
2746
2549
|
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
2747
2550
|
return logicalOperators.includes(node.operator);
|
|
2748
2551
|
}
|
|
2749
|
-
if (node.type ===
|
|
2552
|
+
if (node.type === AST_NODE_TYPES33.UnaryExpression) {
|
|
2750
2553
|
return node.operator === "!";
|
|
2751
2554
|
}
|
|
2752
2555
|
return false;
|
|
@@ -2759,7 +2562,7 @@ var noLogicInParams = createRule37({
|
|
|
2759
2562
|
messageId: "noLogicInParams"
|
|
2760
2563
|
});
|
|
2761
2564
|
}
|
|
2762
|
-
if (arg.type ===
|
|
2565
|
+
if (arg.type === AST_NODE_TYPES33.ArrayExpression) {
|
|
2763
2566
|
arg.elements.forEach((element) => {
|
|
2764
2567
|
if (element && isComplexExpression(element)) {
|
|
2765
2568
|
context.report({
|
|
@@ -2784,46 +2587,46 @@ var noLogicInParams = createRule37({
|
|
|
2784
2587
|
var no_logic_in_params_default = noLogicInParams;
|
|
2785
2588
|
|
|
2786
2589
|
// src/rules/no-misleading-constant-case.ts
|
|
2787
|
-
import { AST_NODE_TYPES as
|
|
2788
|
-
var
|
|
2590
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34, ESLintUtils as ESLintUtils34 } from "@typescript-eslint/utils";
|
|
2591
|
+
var createRule34 = ESLintUtils34.RuleCreator(
|
|
2789
2592
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2790
2593
|
);
|
|
2791
2594
|
var SCREAMING_SNAKE_CASE_REGEX3 = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
2792
|
-
var isAsConstAssertion = (node) => node.type ===
|
|
2595
|
+
var isAsConstAssertion = (node) => node.type === AST_NODE_TYPES34.TSAsExpression && node.typeAnnotation.type === AST_NODE_TYPES34.TSTypeReference && node.typeAnnotation.typeName.type === AST_NODE_TYPES34.Identifier && node.typeAnnotation.typeName.name === "const";
|
|
2793
2596
|
var isStaticValue2 = (init) => {
|
|
2794
2597
|
if (isAsConstAssertion(init)) {
|
|
2795
2598
|
return true;
|
|
2796
2599
|
}
|
|
2797
|
-
if (init.type ===
|
|
2600
|
+
if (init.type === AST_NODE_TYPES34.Literal) {
|
|
2798
2601
|
return true;
|
|
2799
2602
|
}
|
|
2800
|
-
if (init.type ===
|
|
2603
|
+
if (init.type === AST_NODE_TYPES34.UnaryExpression && init.argument.type === AST_NODE_TYPES34.Literal) {
|
|
2801
2604
|
return true;
|
|
2802
2605
|
}
|
|
2803
|
-
if (init.type ===
|
|
2606
|
+
if (init.type === AST_NODE_TYPES34.TemplateLiteral && init.expressions.length === 0) {
|
|
2804
2607
|
return true;
|
|
2805
2608
|
}
|
|
2806
|
-
if (init.type ===
|
|
2807
|
-
return init.elements.every((el) => el !== null && el.type !==
|
|
2609
|
+
if (init.type === AST_NODE_TYPES34.ArrayExpression) {
|
|
2610
|
+
return init.elements.every((el) => el !== null && el.type !== AST_NODE_TYPES34.SpreadElement && isStaticValue2(el));
|
|
2808
2611
|
}
|
|
2809
|
-
if (init.type ===
|
|
2612
|
+
if (init.type === AST_NODE_TYPES34.ObjectExpression) {
|
|
2810
2613
|
return init.properties.every(
|
|
2811
|
-
(prop) => prop.type ===
|
|
2614
|
+
(prop) => prop.type === AST_NODE_TYPES34.Property && isStaticValue2(prop.value)
|
|
2812
2615
|
);
|
|
2813
2616
|
}
|
|
2814
2617
|
return false;
|
|
2815
2618
|
};
|
|
2816
2619
|
var isGlobalScope3 = (node) => {
|
|
2817
2620
|
const { parent } = node;
|
|
2818
|
-
if (parent.type ===
|
|
2621
|
+
if (parent.type === AST_NODE_TYPES34.Program) {
|
|
2819
2622
|
return true;
|
|
2820
2623
|
}
|
|
2821
|
-
if (parent.type ===
|
|
2624
|
+
if (parent.type === AST_NODE_TYPES34.ExportNamedDeclaration && parent.parent?.type === AST_NODE_TYPES34.Program) {
|
|
2822
2625
|
return true;
|
|
2823
2626
|
}
|
|
2824
2627
|
return false;
|
|
2825
2628
|
};
|
|
2826
|
-
var noMisleadingConstantCase =
|
|
2629
|
+
var noMisleadingConstantCase = createRule34({
|
|
2827
2630
|
name: "no-misleading-constant-case",
|
|
2828
2631
|
meta: {
|
|
2829
2632
|
type: "suggestion",
|
|
@@ -2842,7 +2645,7 @@ var noMisleadingConstantCase = createRule38({
|
|
|
2842
2645
|
return {
|
|
2843
2646
|
VariableDeclaration(node) {
|
|
2844
2647
|
node.declarations.forEach((declarator) => {
|
|
2845
|
-
if (declarator.id.type !==
|
|
2648
|
+
if (declarator.id.type !== AST_NODE_TYPES34.Identifier) {
|
|
2846
2649
|
return;
|
|
2847
2650
|
}
|
|
2848
2651
|
const { name } = declarator.id;
|
|
@@ -2883,11 +2686,11 @@ var noMisleadingConstantCase = createRule38({
|
|
|
2883
2686
|
var no_misleading_constant_case_default = noMisleadingConstantCase;
|
|
2884
2687
|
|
|
2885
2688
|
// src/rules/no-nested-interface-declaration.ts
|
|
2886
|
-
import { AST_NODE_TYPES as
|
|
2887
|
-
var
|
|
2689
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35, ESLintUtils as ESLintUtils35 } from "@typescript-eslint/utils";
|
|
2690
|
+
var createRule35 = ESLintUtils35.RuleCreator(
|
|
2888
2691
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2889
2692
|
);
|
|
2890
|
-
var noNestedInterfaceDeclaration =
|
|
2693
|
+
var noNestedInterfaceDeclaration = createRule35({
|
|
2891
2694
|
name: "no-nested-interface-declaration",
|
|
2892
2695
|
meta: {
|
|
2893
2696
|
type: "suggestion",
|
|
@@ -2908,15 +2711,15 @@ var noNestedInterfaceDeclaration = createRule39({
|
|
|
2908
2711
|
return;
|
|
2909
2712
|
}
|
|
2910
2713
|
const { typeAnnotation } = node.typeAnnotation;
|
|
2911
|
-
if (typeAnnotation.type ===
|
|
2714
|
+
if (typeAnnotation.type === AST_NODE_TYPES35.TSTypeLiteral) {
|
|
2912
2715
|
context.report({
|
|
2913
2716
|
node: typeAnnotation,
|
|
2914
2717
|
messageId: "noNestedInterface"
|
|
2915
2718
|
});
|
|
2916
2719
|
return;
|
|
2917
2720
|
}
|
|
2918
|
-
if (typeAnnotation.type ===
|
|
2919
|
-
if (typeAnnotation.elementType.type ===
|
|
2721
|
+
if (typeAnnotation.type === AST_NODE_TYPES35.TSArrayType) {
|
|
2722
|
+
if (typeAnnotation.elementType.type === AST_NODE_TYPES35.TSTypeLiteral) {
|
|
2920
2723
|
context.report({
|
|
2921
2724
|
node: typeAnnotation.elementType,
|
|
2922
2725
|
messageId: "noNestedInterface"
|
|
@@ -2924,9 +2727,9 @@ var noNestedInterfaceDeclaration = createRule39({
|
|
|
2924
2727
|
}
|
|
2925
2728
|
return;
|
|
2926
2729
|
}
|
|
2927
|
-
if (typeAnnotation.type ===
|
|
2730
|
+
if (typeAnnotation.type === AST_NODE_TYPES35.TSTypeReference && typeAnnotation.typeArguments) {
|
|
2928
2731
|
typeAnnotation.typeArguments.params.forEach((param) => {
|
|
2929
|
-
if (param.type ===
|
|
2732
|
+
if (param.type === AST_NODE_TYPES35.TSTypeLiteral) {
|
|
2930
2733
|
context.report({
|
|
2931
2734
|
node: param,
|
|
2932
2735
|
messageId: "noNestedInterface"
|
|
@@ -2941,11 +2744,11 @@ var noNestedInterfaceDeclaration = createRule39({
|
|
|
2941
2744
|
var no_nested_interface_declaration_default = noNestedInterfaceDeclaration;
|
|
2942
2745
|
|
|
2943
2746
|
// src/rules/no-nested-ternary.ts
|
|
2944
|
-
import { AST_NODE_TYPES as
|
|
2945
|
-
var
|
|
2747
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36, ESLintUtils as ESLintUtils36 } from "@typescript-eslint/utils";
|
|
2748
|
+
var createRule36 = ESLintUtils36.RuleCreator(
|
|
2946
2749
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2947
2750
|
);
|
|
2948
|
-
var noNestedTernary =
|
|
2751
|
+
var noNestedTernary = createRule36({
|
|
2949
2752
|
name: "no-nested-ternary",
|
|
2950
2753
|
meta: {
|
|
2951
2754
|
type: "suggestion",
|
|
@@ -2962,13 +2765,13 @@ var noNestedTernary = createRule40({
|
|
|
2962
2765
|
return {
|
|
2963
2766
|
ConditionalExpression(node) {
|
|
2964
2767
|
const { consequent, alternate } = node;
|
|
2965
|
-
if (consequent.type ===
|
|
2768
|
+
if (consequent.type === AST_NODE_TYPES36.ConditionalExpression) {
|
|
2966
2769
|
context.report({
|
|
2967
2770
|
node: consequent,
|
|
2968
2771
|
messageId: "noNestedTernary"
|
|
2969
2772
|
});
|
|
2970
2773
|
}
|
|
2971
|
-
if (alternate.type ===
|
|
2774
|
+
if (alternate.type === AST_NODE_TYPES36.ConditionalExpression) {
|
|
2972
2775
|
context.report({
|
|
2973
2776
|
node: alternate,
|
|
2974
2777
|
messageId: "noNestedTernary"
|
|
@@ -2981,11 +2784,11 @@ var noNestedTernary = createRule40({
|
|
|
2981
2784
|
var no_nested_ternary_default = noNestedTernary;
|
|
2982
2785
|
|
|
2983
2786
|
// src/rules/no-relative-imports.ts
|
|
2984
|
-
import { AST_NODE_TYPES as
|
|
2985
|
-
var
|
|
2787
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37, ESLintUtils as ESLintUtils37 } from "@typescript-eslint/utils";
|
|
2788
|
+
var createRule37 = ESLintUtils37.RuleCreator(
|
|
2986
2789
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2987
2790
|
);
|
|
2988
|
-
var noRelativeImports =
|
|
2791
|
+
var noRelativeImports = createRule37({
|
|
2989
2792
|
name: "no-relative-imports",
|
|
2990
2793
|
meta: {
|
|
2991
2794
|
type: "suggestion",
|
|
@@ -3009,22 +2812,22 @@ var noRelativeImports = createRule41({
|
|
|
3009
2812
|
};
|
|
3010
2813
|
return {
|
|
3011
2814
|
ImportDeclaration(node) {
|
|
3012
|
-
if (node.source.type ===
|
|
2815
|
+
if (node.source.type === AST_NODE_TYPES37.Literal && typeof node.source.value === "string") {
|
|
3013
2816
|
checkImportPath(node.source.value, node);
|
|
3014
2817
|
}
|
|
3015
2818
|
},
|
|
3016
2819
|
ImportExpression(node) {
|
|
3017
|
-
if (node.source.type ===
|
|
2820
|
+
if (node.source.type === AST_NODE_TYPES37.Literal && typeof node.source.value === "string") {
|
|
3018
2821
|
checkImportPath(node.source.value, node);
|
|
3019
2822
|
}
|
|
3020
2823
|
},
|
|
3021
2824
|
ExportNamedDeclaration(node) {
|
|
3022
|
-
if (node.source?.type ===
|
|
2825
|
+
if (node.source?.type === AST_NODE_TYPES37.Literal && typeof node.source.value === "string") {
|
|
3023
2826
|
checkImportPath(node.source.value, node);
|
|
3024
2827
|
}
|
|
3025
2828
|
},
|
|
3026
2829
|
ExportAllDeclaration(node) {
|
|
3027
|
-
if (node.source.type ===
|
|
2830
|
+
if (node.source.type === AST_NODE_TYPES37.Literal && typeof node.source.value === "string") {
|
|
3028
2831
|
checkImportPath(node.source.value, node);
|
|
3029
2832
|
}
|
|
3030
2833
|
}
|
|
@@ -3034,8 +2837,8 @@ var noRelativeImports = createRule41({
|
|
|
3034
2837
|
var no_relative_imports_default = noRelativeImports;
|
|
3035
2838
|
|
|
3036
2839
|
// src/rules/no-single-char-variables.ts
|
|
3037
|
-
import { AST_NODE_TYPES as
|
|
3038
|
-
var
|
|
2840
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38, ESLintUtils as ESLintUtils38 } from "@typescript-eslint/utils";
|
|
2841
|
+
var createRule38 = ESLintUtils38.RuleCreator(
|
|
3039
2842
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3040
2843
|
);
|
|
3041
2844
|
var ALLOWED_IN_FOR_LOOPS = /* @__PURE__ */ new Set(["i", "j", "k", "n"]);
|
|
@@ -3047,7 +2850,7 @@ var isForLoopInit = (node) => {
|
|
|
3047
2850
|
if (!parentNode) {
|
|
3048
2851
|
return false;
|
|
3049
2852
|
}
|
|
3050
|
-
if (parentNode.type ===
|
|
2853
|
+
if (parentNode.type === AST_NODE_TYPES38.ForStatement) {
|
|
3051
2854
|
const { init } = parentNode;
|
|
3052
2855
|
if (init && init === current) {
|
|
3053
2856
|
return true;
|
|
@@ -3066,7 +2869,7 @@ var isAllowedInContext = (name, node) => {
|
|
|
3066
2869
|
}
|
|
3067
2870
|
return false;
|
|
3068
2871
|
};
|
|
3069
|
-
var noSingleCharVariables =
|
|
2872
|
+
var noSingleCharVariables = createRule38({
|
|
3070
2873
|
name: "no-single-char-variables",
|
|
3071
2874
|
meta: {
|
|
3072
2875
|
type: "suggestion",
|
|
@@ -3095,27 +2898,27 @@ var noSingleCharVariables = createRule42({
|
|
|
3095
2898
|
});
|
|
3096
2899
|
};
|
|
3097
2900
|
const checkPattern = (pattern, declarationNode) => {
|
|
3098
|
-
if (pattern.type ===
|
|
2901
|
+
if (pattern.type === AST_NODE_TYPES38.Identifier) {
|
|
3099
2902
|
checkIdentifier(pattern, declarationNode);
|
|
3100
|
-
} else if (pattern.type ===
|
|
2903
|
+
} else if (pattern.type === AST_NODE_TYPES38.ObjectPattern) {
|
|
3101
2904
|
pattern.properties.forEach((prop) => {
|
|
3102
|
-
if (prop.type ===
|
|
2905
|
+
if (prop.type === AST_NODE_TYPES38.Property && prop.value.type === AST_NODE_TYPES38.Identifier) {
|
|
3103
2906
|
checkIdentifier(prop.value, declarationNode);
|
|
3104
|
-
} else if (prop.type ===
|
|
2907
|
+
} else if (prop.type === AST_NODE_TYPES38.RestElement && prop.argument.type === AST_NODE_TYPES38.Identifier) {
|
|
3105
2908
|
checkIdentifier(prop.argument, declarationNode);
|
|
3106
2909
|
}
|
|
3107
2910
|
});
|
|
3108
|
-
} else if (pattern.type ===
|
|
2911
|
+
} else if (pattern.type === AST_NODE_TYPES38.ArrayPattern) {
|
|
3109
2912
|
pattern.elements.forEach((element) => {
|
|
3110
|
-
if (element?.type ===
|
|
2913
|
+
if (element?.type === AST_NODE_TYPES38.Identifier) {
|
|
3111
2914
|
checkIdentifier(element, declarationNode);
|
|
3112
|
-
} else if (element?.type ===
|
|
2915
|
+
} else if (element?.type === AST_NODE_TYPES38.RestElement && element.argument.type === AST_NODE_TYPES38.Identifier) {
|
|
3113
2916
|
checkIdentifier(element.argument, declarationNode);
|
|
3114
2917
|
}
|
|
3115
2918
|
});
|
|
3116
|
-
} else if (pattern.type ===
|
|
2919
|
+
} else if (pattern.type === AST_NODE_TYPES38.AssignmentPattern && pattern.left.type === AST_NODE_TYPES38.Identifier) {
|
|
3117
2920
|
checkIdentifier(pattern.left, declarationNode);
|
|
3118
|
-
} else if (pattern.type ===
|
|
2921
|
+
} else if (pattern.type === AST_NODE_TYPES38.RestElement && pattern.argument.type === AST_NODE_TYPES38.Identifier) {
|
|
3119
2922
|
checkIdentifier(pattern.argument, declarationNode);
|
|
3120
2923
|
}
|
|
3121
2924
|
};
|
|
@@ -3149,11 +2952,11 @@ var noSingleCharVariables = createRule42({
|
|
|
3149
2952
|
var no_single_char_variables_default = noSingleCharVariables;
|
|
3150
2953
|
|
|
3151
2954
|
// src/rules/prefer-async-await.ts
|
|
3152
|
-
import { AST_NODE_TYPES as
|
|
3153
|
-
var
|
|
2955
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39, ESLintUtils as ESLintUtils39 } from "@typescript-eslint/utils";
|
|
2956
|
+
var createRule39 = ESLintUtils39.RuleCreator(
|
|
3154
2957
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3155
2958
|
);
|
|
3156
|
-
var preferAsyncAwait =
|
|
2959
|
+
var preferAsyncAwait = createRule39({
|
|
3157
2960
|
name: "prefer-async-await",
|
|
3158
2961
|
meta: {
|
|
3159
2962
|
type: "suggestion",
|
|
@@ -3169,7 +2972,7 @@ var preferAsyncAwait = createRule43({
|
|
|
3169
2972
|
create(context) {
|
|
3170
2973
|
return {
|
|
3171
2974
|
CallExpression(node) {
|
|
3172
|
-
if (node.callee.type ===
|
|
2975
|
+
if (node.callee.type === AST_NODE_TYPES39.MemberExpression && node.callee.property.type === AST_NODE_TYPES39.Identifier && node.callee.property.name === "then") {
|
|
3173
2976
|
context.report({
|
|
3174
2977
|
node: node.callee.property,
|
|
3175
2978
|
messageId: "preferAsyncAwait"
|
|
@@ -3182,11 +2985,11 @@ var preferAsyncAwait = createRule43({
|
|
|
3182
2985
|
var prefer_async_await_default = preferAsyncAwait;
|
|
3183
2986
|
|
|
3184
2987
|
// src/rules/prefer-destructuring-params.ts
|
|
3185
|
-
import { AST_NODE_TYPES as
|
|
3186
|
-
var
|
|
2988
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40, ESLintUtils as ESLintUtils40 } from "@typescript-eslint/utils";
|
|
2989
|
+
var createRule40 = ESLintUtils40.RuleCreator(
|
|
3187
2990
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3188
2991
|
);
|
|
3189
|
-
var preferDestructuringParams =
|
|
2992
|
+
var preferDestructuringParams = createRule40({
|
|
3190
2993
|
name: "prefer-destructuring-params",
|
|
3191
2994
|
meta: {
|
|
3192
2995
|
type: "suggestion",
|
|
@@ -3202,18 +3005,18 @@ var preferDestructuringParams = createRule44({
|
|
|
3202
3005
|
create(context) {
|
|
3203
3006
|
const isCallbackFunction2 = (node) => {
|
|
3204
3007
|
const { parent } = node;
|
|
3205
|
-
return parent?.type ===
|
|
3008
|
+
return parent?.type === AST_NODE_TYPES40.CallExpression;
|
|
3206
3009
|
};
|
|
3207
3010
|
const isDeveloperFunction = (node) => {
|
|
3208
|
-
if (node.type ===
|
|
3011
|
+
if (node.type === AST_NODE_TYPES40.FunctionDeclaration) {
|
|
3209
3012
|
return true;
|
|
3210
3013
|
}
|
|
3211
|
-
if (node.type ===
|
|
3014
|
+
if (node.type === AST_NODE_TYPES40.FunctionExpression || node.type === AST_NODE_TYPES40.ArrowFunctionExpression) {
|
|
3212
3015
|
if (isCallbackFunction2(node)) {
|
|
3213
3016
|
return false;
|
|
3214
3017
|
}
|
|
3215
3018
|
const { parent } = node;
|
|
3216
|
-
return parent?.type ===
|
|
3019
|
+
return parent?.type === AST_NODE_TYPES40.VariableDeclarator || parent?.type === AST_NODE_TYPES40.AssignmentExpression || parent?.type === AST_NODE_TYPES40.Property || parent?.type === AST_NODE_TYPES40.MethodDefinition;
|
|
3217
3020
|
}
|
|
3218
3021
|
return false;
|
|
3219
3022
|
};
|
|
@@ -3225,7 +3028,7 @@ var preferDestructuringParams = createRule44({
|
|
|
3225
3028
|
if (!isDeveloperFunction(node)) {
|
|
3226
3029
|
return;
|
|
3227
3030
|
}
|
|
3228
|
-
if (node.type ===
|
|
3031
|
+
if (node.type === AST_NODE_TYPES40.FunctionDeclaration && node.id) {
|
|
3229
3032
|
const functionName = node.id.name;
|
|
3230
3033
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
3231
3034
|
return;
|
|
@@ -3235,7 +3038,7 @@ var preferDestructuringParams = createRule44({
|
|
|
3235
3038
|
return;
|
|
3236
3039
|
}
|
|
3237
3040
|
const hasNonDestructuredParams = node.params.some(
|
|
3238
|
-
(param) => param.type !==
|
|
3041
|
+
(param) => param.type !== AST_NODE_TYPES40.ObjectPattern && param.type !== AST_NODE_TYPES40.RestElement
|
|
3239
3042
|
);
|
|
3240
3043
|
if (hasNonDestructuredParams) {
|
|
3241
3044
|
context.report({
|
|
@@ -3254,8 +3057,8 @@ var preferDestructuringParams = createRule44({
|
|
|
3254
3057
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
3255
3058
|
|
|
3256
3059
|
// src/rules/prefer-function-declaration.ts
|
|
3257
|
-
import { AST_NODE_TYPES as
|
|
3258
|
-
var
|
|
3060
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41, ESLintUtils as ESLintUtils41 } from "@typescript-eslint/utils";
|
|
3061
|
+
var createRule41 = ESLintUtils41.RuleCreator(
|
|
3259
3062
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3260
3063
|
);
|
|
3261
3064
|
var isTsFile = (filename) => filename.endsWith(".ts") && !filename.endsWith(".d.ts");
|
|
@@ -3264,33 +3067,33 @@ var isCallbackContext = (node) => {
|
|
|
3264
3067
|
if (!parent) {
|
|
3265
3068
|
return false;
|
|
3266
3069
|
}
|
|
3267
|
-
if (parent.type ===
|
|
3070
|
+
if (parent.type === AST_NODE_TYPES41.CallExpression && parent.arguments.includes(node)) {
|
|
3268
3071
|
return true;
|
|
3269
3072
|
}
|
|
3270
|
-
if (parent.type ===
|
|
3073
|
+
if (parent.type === AST_NODE_TYPES41.NewExpression && parent.arguments.includes(node)) {
|
|
3271
3074
|
return true;
|
|
3272
3075
|
}
|
|
3273
|
-
if (parent.type ===
|
|
3076
|
+
if (parent.type === AST_NODE_TYPES41.ReturnStatement) {
|
|
3274
3077
|
return true;
|
|
3275
3078
|
}
|
|
3276
|
-
if (parent.type ===
|
|
3079
|
+
if (parent.type === AST_NODE_TYPES41.Property) {
|
|
3277
3080
|
return true;
|
|
3278
3081
|
}
|
|
3279
|
-
if (parent.type ===
|
|
3082
|
+
if (parent.type === AST_NODE_TYPES41.ArrayExpression) {
|
|
3280
3083
|
return true;
|
|
3281
3084
|
}
|
|
3282
|
-
if (parent.type ===
|
|
3085
|
+
if (parent.type === AST_NODE_TYPES41.ConditionalExpression) {
|
|
3283
3086
|
return true;
|
|
3284
3087
|
}
|
|
3285
|
-
if (parent.type ===
|
|
3088
|
+
if (parent.type === AST_NODE_TYPES41.LogicalExpression) {
|
|
3286
3089
|
return true;
|
|
3287
3090
|
}
|
|
3288
|
-
if (parent.type ===
|
|
3091
|
+
if (parent.type === AST_NODE_TYPES41.AssignmentExpression && parent.left !== node) {
|
|
3289
3092
|
return true;
|
|
3290
3093
|
}
|
|
3291
3094
|
return false;
|
|
3292
3095
|
};
|
|
3293
|
-
var preferFunctionDeclaration =
|
|
3096
|
+
var preferFunctionDeclaration = createRule41({
|
|
3294
3097
|
name: "prefer-function-declaration",
|
|
3295
3098
|
meta: {
|
|
3296
3099
|
type: "suggestion",
|
|
@@ -3311,14 +3114,14 @@ var preferFunctionDeclaration = createRule45({
|
|
|
3311
3114
|
}
|
|
3312
3115
|
return {
|
|
3313
3116
|
VariableDeclarator(node) {
|
|
3314
|
-
if (node.id.type !==
|
|
3117
|
+
if (node.id.type !== AST_NODE_TYPES41.Identifier) {
|
|
3315
3118
|
return;
|
|
3316
3119
|
}
|
|
3317
3120
|
const { init } = node;
|
|
3318
3121
|
if (!init) {
|
|
3319
3122
|
return;
|
|
3320
3123
|
}
|
|
3321
|
-
if (init.type ===
|
|
3124
|
+
if (init.type === AST_NODE_TYPES41.ArrowFunctionExpression) {
|
|
3322
3125
|
if (isCallbackContext(init)) {
|
|
3323
3126
|
return;
|
|
3324
3127
|
}
|
|
@@ -3328,7 +3131,7 @@ var preferFunctionDeclaration = createRule45({
|
|
|
3328
3131
|
data: { name: node.id.name }
|
|
3329
3132
|
});
|
|
3330
3133
|
}
|
|
3331
|
-
if (init.type ===
|
|
3134
|
+
if (init.type === AST_NODE_TYPES41.FunctionExpression) {
|
|
3332
3135
|
if (isCallbackContext(init)) {
|
|
3333
3136
|
return;
|
|
3334
3137
|
}
|
|
@@ -3345,11 +3148,11 @@ var preferFunctionDeclaration = createRule45({
|
|
|
3345
3148
|
var prefer_function_declaration_default = preferFunctionDeclaration;
|
|
3346
3149
|
|
|
3347
3150
|
// src/rules/prefer-guard-clause.ts
|
|
3348
|
-
import { AST_NODE_TYPES as
|
|
3349
|
-
var
|
|
3151
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42, ESLintUtils as ESLintUtils42 } from "@typescript-eslint/utils";
|
|
3152
|
+
var createRule42 = ESLintUtils42.RuleCreator(
|
|
3350
3153
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3351
3154
|
);
|
|
3352
|
-
var preferGuardClause =
|
|
3155
|
+
var preferGuardClause = createRule42({
|
|
3353
3156
|
name: "prefer-guard-clause",
|
|
3354
3157
|
meta: {
|
|
3355
3158
|
type: "suggestion",
|
|
@@ -3366,8 +3169,8 @@ var preferGuardClause = createRule46({
|
|
|
3366
3169
|
return {
|
|
3367
3170
|
IfStatement(node) {
|
|
3368
3171
|
const { consequent } = node;
|
|
3369
|
-
if (consequent.type ===
|
|
3370
|
-
const hasNestedIf = consequent.body.some((statement) => statement.type ===
|
|
3172
|
+
if (consequent.type === AST_NODE_TYPES42.BlockStatement) {
|
|
3173
|
+
const hasNestedIf = consequent.body.some((statement) => statement.type === AST_NODE_TYPES42.IfStatement);
|
|
3371
3174
|
if (hasNestedIf && consequent.body.length === 1) {
|
|
3372
3175
|
context.report({
|
|
3373
3176
|
node,
|
|
@@ -3375,7 +3178,7 @@ var preferGuardClause = createRule46({
|
|
|
3375
3178
|
});
|
|
3376
3179
|
}
|
|
3377
3180
|
}
|
|
3378
|
-
if (consequent.type ===
|
|
3181
|
+
if (consequent.type === AST_NODE_TYPES42.IfStatement) {
|
|
3379
3182
|
context.report({
|
|
3380
3183
|
node,
|
|
3381
3184
|
messageId: "preferGuardClause"
|
|
@@ -3388,11 +3191,11 @@ var preferGuardClause = createRule46({
|
|
|
3388
3191
|
var prefer_guard_clause_default = preferGuardClause;
|
|
3389
3192
|
|
|
3390
3193
|
// src/rules/prefer-import-type.ts
|
|
3391
|
-
import { AST_NODE_TYPES as
|
|
3392
|
-
var
|
|
3194
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43, ESLintUtils as ESLintUtils43 } from "@typescript-eslint/utils";
|
|
3195
|
+
var createRule43 = ESLintUtils43.RuleCreator(
|
|
3393
3196
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3394
3197
|
);
|
|
3395
|
-
var preferImportType =
|
|
3198
|
+
var preferImportType = createRule43({
|
|
3396
3199
|
name: "prefer-import-type",
|
|
3397
3200
|
meta: {
|
|
3398
3201
|
type: "suggestion",
|
|
@@ -3411,22 +3214,22 @@ var preferImportType = createRule47({
|
|
|
3411
3214
|
let current = node;
|
|
3412
3215
|
while (current) {
|
|
3413
3216
|
switch (current.type) {
|
|
3414
|
-
case
|
|
3415
|
-
case
|
|
3416
|
-
case
|
|
3417
|
-
case
|
|
3418
|
-
case
|
|
3419
|
-
case
|
|
3420
|
-
case
|
|
3421
|
-
case
|
|
3422
|
-
case
|
|
3423
|
-
case
|
|
3424
|
-
case
|
|
3425
|
-
case
|
|
3426
|
-
case
|
|
3217
|
+
case AST_NODE_TYPES43.TSTypeReference:
|
|
3218
|
+
case AST_NODE_TYPES43.TSTypeAnnotation:
|
|
3219
|
+
case AST_NODE_TYPES43.TSTypeParameterInstantiation:
|
|
3220
|
+
case AST_NODE_TYPES43.TSInterfaceHeritage:
|
|
3221
|
+
case AST_NODE_TYPES43.TSClassImplements:
|
|
3222
|
+
case AST_NODE_TYPES43.TSTypeQuery:
|
|
3223
|
+
case AST_NODE_TYPES43.TSTypeAssertion:
|
|
3224
|
+
case AST_NODE_TYPES43.TSAsExpression:
|
|
3225
|
+
case AST_NODE_TYPES43.TSSatisfiesExpression:
|
|
3226
|
+
case AST_NODE_TYPES43.TSTypeAliasDeclaration:
|
|
3227
|
+
case AST_NODE_TYPES43.TSInterfaceDeclaration:
|
|
3228
|
+
case AST_NODE_TYPES43.TSTypeParameter:
|
|
3229
|
+
case AST_NODE_TYPES43.TSQualifiedName:
|
|
3427
3230
|
return true;
|
|
3428
|
-
case
|
|
3429
|
-
case
|
|
3231
|
+
case AST_NODE_TYPES43.MemberExpression:
|
|
3232
|
+
case AST_NODE_TYPES43.Identifier:
|
|
3430
3233
|
current = current.parent;
|
|
3431
3234
|
break;
|
|
3432
3235
|
default:
|
|
@@ -3456,27 +3259,27 @@ var preferImportType = createRule47({
|
|
|
3456
3259
|
return false;
|
|
3457
3260
|
}
|
|
3458
3261
|
switch (parent.type) {
|
|
3459
|
-
case
|
|
3460
|
-
case
|
|
3461
|
-
case
|
|
3462
|
-
case
|
|
3463
|
-
case
|
|
3464
|
-
case
|
|
3465
|
-
case
|
|
3466
|
-
case
|
|
3467
|
-
case
|
|
3468
|
-
case
|
|
3469
|
-
case
|
|
3470
|
-
case
|
|
3471
|
-
case
|
|
3472
|
-
case
|
|
3473
|
-
case
|
|
3474
|
-
case
|
|
3475
|
-
case
|
|
3476
|
-
case
|
|
3477
|
-
case
|
|
3478
|
-
case
|
|
3479
|
-
case
|
|
3262
|
+
case AST_NODE_TYPES43.CallExpression:
|
|
3263
|
+
case AST_NODE_TYPES43.NewExpression:
|
|
3264
|
+
case AST_NODE_TYPES43.JSXOpeningElement:
|
|
3265
|
+
case AST_NODE_TYPES43.JSXClosingElement:
|
|
3266
|
+
case AST_NODE_TYPES43.MemberExpression:
|
|
3267
|
+
case AST_NODE_TYPES43.VariableDeclarator:
|
|
3268
|
+
case AST_NODE_TYPES43.TaggedTemplateExpression:
|
|
3269
|
+
case AST_NODE_TYPES43.SpreadElement:
|
|
3270
|
+
case AST_NODE_TYPES43.ExportSpecifier:
|
|
3271
|
+
case AST_NODE_TYPES43.ArrayExpression:
|
|
3272
|
+
case AST_NODE_TYPES43.ObjectExpression:
|
|
3273
|
+
case AST_NODE_TYPES43.BinaryExpression:
|
|
3274
|
+
case AST_NODE_TYPES43.LogicalExpression:
|
|
3275
|
+
case AST_NODE_TYPES43.UnaryExpression:
|
|
3276
|
+
case AST_NODE_TYPES43.ReturnStatement:
|
|
3277
|
+
case AST_NODE_TYPES43.ArrowFunctionExpression:
|
|
3278
|
+
case AST_NODE_TYPES43.ConditionalExpression:
|
|
3279
|
+
case AST_NODE_TYPES43.AwaitExpression:
|
|
3280
|
+
case AST_NODE_TYPES43.YieldExpression:
|
|
3281
|
+
case AST_NODE_TYPES43.Property:
|
|
3282
|
+
case AST_NODE_TYPES43.JSXExpressionContainer:
|
|
3480
3283
|
return true;
|
|
3481
3284
|
default:
|
|
3482
3285
|
return false;
|
|
@@ -3487,6 +3290,12 @@ var preferImportType = createRule47({
|
|
|
3487
3290
|
if (node.importKind === "type") {
|
|
3488
3291
|
return;
|
|
3489
3292
|
}
|
|
3293
|
+
const hasInlineTypeSpecifier = node.specifiers.some(
|
|
3294
|
+
(specifier) => specifier.type === AST_NODE_TYPES43.ImportSpecifier && specifier.importKind === "type"
|
|
3295
|
+
);
|
|
3296
|
+
if (hasInlineTypeSpecifier) {
|
|
3297
|
+
return;
|
|
3298
|
+
}
|
|
3490
3299
|
if (context.filename.includes(".test.") || context.filename.includes(".spec.") || context.filename.includes("__tests__")) {
|
|
3491
3300
|
return;
|
|
3492
3301
|
}
|
|
@@ -3500,13 +3309,13 @@ var preferImportType = createRule47({
|
|
|
3500
3309
|
}
|
|
3501
3310
|
const scope = context.sourceCode.getScope(node);
|
|
3502
3311
|
const isTypeOnlyImport2 = node.specifiers.every((specifier) => {
|
|
3503
|
-
if (specifier.type ===
|
|
3312
|
+
if (specifier.type === AST_NODE_TYPES43.ImportDefaultSpecifier) {
|
|
3504
3313
|
return false;
|
|
3505
3314
|
}
|
|
3506
|
-
if (specifier.type ===
|
|
3315
|
+
if (specifier.type === AST_NODE_TYPES43.ImportNamespaceSpecifier) {
|
|
3507
3316
|
return false;
|
|
3508
3317
|
}
|
|
3509
|
-
if (specifier.type ===
|
|
3318
|
+
if (specifier.type === AST_NODE_TYPES43.ImportSpecifier) {
|
|
3510
3319
|
const localName = specifier.local.name;
|
|
3511
3320
|
return !isUsedAsValue(localName, scope);
|
|
3512
3321
|
}
|
|
@@ -3532,19 +3341,19 @@ var preferImportType = createRule47({
|
|
|
3532
3341
|
var prefer_import_type_default = preferImportType;
|
|
3533
3342
|
|
|
3534
3343
|
// src/rules/prefer-inline-literal-union.ts
|
|
3535
|
-
import { AST_NODE_TYPES as
|
|
3536
|
-
var
|
|
3344
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44, ESLintUtils as ESLintUtils44 } from "@typescript-eslint/utils";
|
|
3345
|
+
var createRule44 = ESLintUtils44.RuleCreator(
|
|
3537
3346
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3538
3347
|
);
|
|
3539
3348
|
function isLiteralUnionType(node) {
|
|
3540
|
-
if (node.type !==
|
|
3349
|
+
if (node.type !== AST_NODE_TYPES44.TSUnionType) {
|
|
3541
3350
|
return false;
|
|
3542
3351
|
}
|
|
3543
3352
|
return node.types.every(
|
|
3544
|
-
(member) => member.type ===
|
|
3353
|
+
(member) => member.type === AST_NODE_TYPES44.TSLiteralType || member.type === AST_NODE_TYPES44.TSNullKeyword || member.type === AST_NODE_TYPES44.TSUndefinedKeyword
|
|
3545
3354
|
);
|
|
3546
3355
|
}
|
|
3547
|
-
var preferInlineLiteralUnion =
|
|
3356
|
+
var preferInlineLiteralUnion = createRule44({
|
|
3548
3357
|
name: "prefer-inline-literal-union",
|
|
3549
3358
|
meta: {
|
|
3550
3359
|
type: "suggestion",
|
|
@@ -3571,10 +3380,10 @@ var preferInlineLiteralUnion = createRule48({
|
|
|
3571
3380
|
return;
|
|
3572
3381
|
}
|
|
3573
3382
|
const { typeAnnotation } = node.typeAnnotation;
|
|
3574
|
-
if (typeAnnotation.type !==
|
|
3383
|
+
if (typeAnnotation.type !== AST_NODE_TYPES44.TSTypeReference) {
|
|
3575
3384
|
return;
|
|
3576
3385
|
}
|
|
3577
|
-
if (typeAnnotation.typeName.type !==
|
|
3386
|
+
if (typeAnnotation.typeName.type !== AST_NODE_TYPES44.Identifier) {
|
|
3578
3387
|
return;
|
|
3579
3388
|
}
|
|
3580
3389
|
const aliasName = typeAnnotation.typeName.name;
|
|
@@ -3598,12 +3407,12 @@ var preferInlineLiteralUnion = createRule48({
|
|
|
3598
3407
|
var prefer_inline_literal_union_default = preferInlineLiteralUnion;
|
|
3599
3408
|
|
|
3600
3409
|
// src/rules/prefer-inline-type-export.ts
|
|
3601
|
-
import { AST_NODE_TYPES as
|
|
3602
|
-
var
|
|
3410
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45, ESLintUtils as ESLintUtils45 } from "@typescript-eslint/utils";
|
|
3411
|
+
var createRule45 = ESLintUtils45.RuleCreator(
|
|
3603
3412
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3604
3413
|
);
|
|
3605
|
-
var isTypeDeclaration = (node) => node.type ===
|
|
3606
|
-
var preferInlineTypeExport =
|
|
3414
|
+
var isTypeDeclaration = (node) => node.type === AST_NODE_TYPES45.TSInterfaceDeclaration || node.type === AST_NODE_TYPES45.TSTypeAliasDeclaration;
|
|
3415
|
+
var preferInlineTypeExport = createRule45({
|
|
3607
3416
|
name: "prefer-inline-type-export",
|
|
3608
3417
|
meta: {
|
|
3609
3418
|
type: "suggestion",
|
|
@@ -3620,12 +3429,12 @@ var preferInlineTypeExport = createRule49({
|
|
|
3620
3429
|
create(context) {
|
|
3621
3430
|
const typeDeclarations = /* @__PURE__ */ new Map();
|
|
3622
3431
|
function collectDeclaration(node) {
|
|
3623
|
-
if (node.parent.type !==
|
|
3432
|
+
if (node.parent.type !== AST_NODE_TYPES45.ExportNamedDeclaration) {
|
|
3624
3433
|
typeDeclarations.set(node.id.name, node);
|
|
3625
3434
|
}
|
|
3626
3435
|
}
|
|
3627
3436
|
function reportSpecifier(specifier, statement, declarationNode) {
|
|
3628
|
-
if (specifier.local.type !==
|
|
3437
|
+
if (specifier.local.type !== AST_NODE_TYPES45.Identifier) {
|
|
3629
3438
|
return;
|
|
3630
3439
|
}
|
|
3631
3440
|
const { name } = specifier.local;
|
|
@@ -3658,16 +3467,16 @@ var preferInlineTypeExport = createRule49({
|
|
|
3658
3467
|
return {
|
|
3659
3468
|
Program(node) {
|
|
3660
3469
|
node.body.forEach((statement) => {
|
|
3661
|
-
if (statement.type ===
|
|
3470
|
+
if (statement.type === AST_NODE_TYPES45.TSInterfaceDeclaration || statement.type === AST_NODE_TYPES45.TSTypeAliasDeclaration) {
|
|
3662
3471
|
collectDeclaration(statement);
|
|
3663
3472
|
}
|
|
3664
3473
|
});
|
|
3665
3474
|
node.body.forEach((statement) => {
|
|
3666
|
-
if (statement.type !==
|
|
3475
|
+
if (statement.type !== AST_NODE_TYPES45.ExportNamedDeclaration || statement.declaration !== null) {
|
|
3667
3476
|
return;
|
|
3668
3477
|
}
|
|
3669
3478
|
statement.specifiers.forEach((specifier) => {
|
|
3670
|
-
if (specifier.local.type !==
|
|
3479
|
+
if (specifier.local.type !== AST_NODE_TYPES45.Identifier) {
|
|
3671
3480
|
return;
|
|
3672
3481
|
}
|
|
3673
3482
|
const declarationNode = typeDeclarations.get(specifier.local.name);
|
|
@@ -3683,12 +3492,69 @@ var preferInlineTypeExport = createRule49({
|
|
|
3683
3492
|
});
|
|
3684
3493
|
var prefer_inline_type_export_default = preferInlineTypeExport;
|
|
3685
3494
|
|
|
3495
|
+
// src/rules/prefer-interface-for-component-props.ts
|
|
3496
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46, ESLintUtils as ESLintUtils46 } from "@typescript-eslint/utils";
|
|
3497
|
+
var createRule46 = ESLintUtils46.RuleCreator(
|
|
3498
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3499
|
+
);
|
|
3500
|
+
var preferInterfaceForComponentProps = createRule46({
|
|
3501
|
+
name: "prefer-interface-for-component-props",
|
|
3502
|
+
meta: {
|
|
3503
|
+
type: "suggestion",
|
|
3504
|
+
docs: {
|
|
3505
|
+
description: "Enforce 'interface' over 'type' alias for component prop declarations in component files (*.tsx, *.jsx)"
|
|
3506
|
+
},
|
|
3507
|
+
fixable: "code",
|
|
3508
|
+
schema: [],
|
|
3509
|
+
messages: {
|
|
3510
|
+
preferInterface: "Component props '{{ name }}' should use 'interface' instead of 'type' alias."
|
|
3511
|
+
}
|
|
3512
|
+
},
|
|
3513
|
+
defaultOptions: [],
|
|
3514
|
+
create(context) {
|
|
3515
|
+
if (!isJsxFile(context.filename)) {
|
|
3516
|
+
return {};
|
|
3517
|
+
}
|
|
3518
|
+
return {
|
|
3519
|
+
TSTypeAliasDeclaration(node) {
|
|
3520
|
+
if (node.id.type !== AST_NODE_TYPES46.Identifier) {
|
|
3521
|
+
return;
|
|
3522
|
+
}
|
|
3523
|
+
if (!node.id.name.endsWith("Props")) {
|
|
3524
|
+
return;
|
|
3525
|
+
}
|
|
3526
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES46.TSTypeLiteral) {
|
|
3527
|
+
return;
|
|
3528
|
+
}
|
|
3529
|
+
const { name } = node.id;
|
|
3530
|
+
context.report({
|
|
3531
|
+
node: node.id,
|
|
3532
|
+
messageId: "preferInterface",
|
|
3533
|
+
data: { name },
|
|
3534
|
+
fix(fixer) {
|
|
3535
|
+
const { sourceCode } = context;
|
|
3536
|
+
const typeText = sourceCode.getText(node.typeAnnotation);
|
|
3537
|
+
const typeParamsText = node.typeParameters ? sourceCode.getText(node.typeParameters) : "";
|
|
3538
|
+
const newText = `interface ${name}${typeParamsText} ${typeText}`;
|
|
3539
|
+
const tokenAfter = sourceCode.getTokenAfter(node);
|
|
3540
|
+
if (tokenAfter && tokenAfter.value === ";") {
|
|
3541
|
+
return fixer.replaceTextRange([node.range[0], tokenAfter.range[1]], newText);
|
|
3542
|
+
}
|
|
3543
|
+
return fixer.replaceText(node, newText);
|
|
3544
|
+
}
|
|
3545
|
+
});
|
|
3546
|
+
}
|
|
3547
|
+
};
|
|
3548
|
+
}
|
|
3549
|
+
});
|
|
3550
|
+
var prefer_interface_for_component_props_default = preferInterfaceForComponentProps;
|
|
3551
|
+
|
|
3686
3552
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
3687
|
-
import { AST_NODE_TYPES as
|
|
3688
|
-
var
|
|
3553
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47, ESLintUtils as ESLintUtils47 } from "@typescript-eslint/utils";
|
|
3554
|
+
var createRule47 = ESLintUtils47.RuleCreator(
|
|
3689
3555
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3690
3556
|
);
|
|
3691
|
-
var preferInterfaceOverInlineTypes =
|
|
3557
|
+
var preferInterfaceOverInlineTypes = createRule47({
|
|
3692
3558
|
name: "prefer-interface-over-inline-types",
|
|
3693
3559
|
meta: {
|
|
3694
3560
|
type: "suggestion",
|
|
@@ -3704,54 +3570,54 @@ var preferInterfaceOverInlineTypes = createRule50({
|
|
|
3704
3570
|
defaultOptions: [],
|
|
3705
3571
|
create(context) {
|
|
3706
3572
|
function hasJSXInConditional(node) {
|
|
3707
|
-
return node.consequent.type ===
|
|
3573
|
+
return node.consequent.type === AST_NODE_TYPES47.JSXElement || node.consequent.type === AST_NODE_TYPES47.JSXFragment || node.alternate.type === AST_NODE_TYPES47.JSXElement || node.alternate.type === AST_NODE_TYPES47.JSXFragment;
|
|
3708
3574
|
}
|
|
3709
3575
|
function hasJSXInLogical(node) {
|
|
3710
|
-
return node.right.type ===
|
|
3576
|
+
return node.right.type === AST_NODE_TYPES47.JSXElement || node.right.type === AST_NODE_TYPES47.JSXFragment;
|
|
3711
3577
|
}
|
|
3712
3578
|
function hasJSXReturn(block) {
|
|
3713
3579
|
return block.body.some((stmt) => {
|
|
3714
|
-
if (stmt.type ===
|
|
3715
|
-
return stmt.argument.type ===
|
|
3580
|
+
if (stmt.type === AST_NODE_TYPES47.ReturnStatement && stmt.argument) {
|
|
3581
|
+
return stmt.argument.type === AST_NODE_TYPES47.JSXElement || stmt.argument.type === AST_NODE_TYPES47.JSXFragment || stmt.argument.type === AST_NODE_TYPES47.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES47.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
3716
3582
|
}
|
|
3717
3583
|
return false;
|
|
3718
3584
|
});
|
|
3719
3585
|
}
|
|
3720
3586
|
function isReactComponent2(node) {
|
|
3721
|
-
if (node.type ===
|
|
3722
|
-
if (node.body.type ===
|
|
3587
|
+
if (node.type === AST_NODE_TYPES47.ArrowFunctionExpression) {
|
|
3588
|
+
if (node.body.type === AST_NODE_TYPES47.JSXElement || node.body.type === AST_NODE_TYPES47.JSXFragment) {
|
|
3723
3589
|
return true;
|
|
3724
3590
|
}
|
|
3725
|
-
if (node.body.type ===
|
|
3591
|
+
if (node.body.type === AST_NODE_TYPES47.BlockStatement) {
|
|
3726
3592
|
return hasJSXReturn(node.body);
|
|
3727
3593
|
}
|
|
3728
|
-
} else if (node.type ===
|
|
3729
|
-
if (node.body && node.body.type ===
|
|
3594
|
+
} else if (node.type === AST_NODE_TYPES47.FunctionExpression || node.type === AST_NODE_TYPES47.FunctionDeclaration) {
|
|
3595
|
+
if (node.body && node.body.type === AST_NODE_TYPES47.BlockStatement) {
|
|
3730
3596
|
return hasJSXReturn(node.body);
|
|
3731
3597
|
}
|
|
3732
3598
|
}
|
|
3733
3599
|
return false;
|
|
3734
3600
|
}
|
|
3735
3601
|
function isInlineTypeAnnotation(node) {
|
|
3736
|
-
if (node.type ===
|
|
3602
|
+
if (node.type === AST_NODE_TYPES47.TSTypeLiteral) {
|
|
3737
3603
|
return true;
|
|
3738
3604
|
}
|
|
3739
|
-
if (node.type ===
|
|
3740
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3605
|
+
if (node.type === AST_NODE_TYPES47.TSTypeReference && node.typeArguments) {
|
|
3606
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES47.TSTypeLiteral);
|
|
3741
3607
|
}
|
|
3742
|
-
if (node.type ===
|
|
3608
|
+
if (node.type === AST_NODE_TYPES47.TSUnionType) {
|
|
3743
3609
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
3744
3610
|
}
|
|
3745
3611
|
return false;
|
|
3746
3612
|
}
|
|
3747
3613
|
function hasInlineObjectType(node) {
|
|
3748
|
-
if (node.type ===
|
|
3614
|
+
if (node.type === AST_NODE_TYPES47.TSTypeLiteral) {
|
|
3749
3615
|
return true;
|
|
3750
3616
|
}
|
|
3751
|
-
if (node.type ===
|
|
3752
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3617
|
+
if (node.type === AST_NODE_TYPES47.TSTypeReference && node.typeArguments) {
|
|
3618
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES47.TSTypeLiteral);
|
|
3753
3619
|
}
|
|
3754
|
-
if (node.type ===
|
|
3620
|
+
if (node.type === AST_NODE_TYPES47.TSUnionType) {
|
|
3755
3621
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
3756
3622
|
}
|
|
3757
3623
|
return false;
|
|
@@ -3764,7 +3630,7 @@ var preferInterfaceOverInlineTypes = createRule50({
|
|
|
3764
3630
|
return;
|
|
3765
3631
|
}
|
|
3766
3632
|
const param = node.params[0];
|
|
3767
|
-
if (param.type ===
|
|
3633
|
+
if (param.type === AST_NODE_TYPES47.Identifier && param.typeAnnotation) {
|
|
3768
3634
|
const { typeAnnotation } = param.typeAnnotation;
|
|
3769
3635
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
3770
3636
|
context.report({
|
|
@@ -3784,11 +3650,11 @@ var preferInterfaceOverInlineTypes = createRule50({
|
|
|
3784
3650
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
3785
3651
|
|
|
3786
3652
|
// src/rules/prefer-jsx-template-literals.ts
|
|
3787
|
-
import { AST_NODE_TYPES as
|
|
3788
|
-
var
|
|
3653
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48, ESLintUtils as ESLintUtils48 } from "@typescript-eslint/utils";
|
|
3654
|
+
var createRule48 = ESLintUtils48.RuleCreator(
|
|
3789
3655
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3790
3656
|
);
|
|
3791
|
-
var preferJSXTemplateLiterals =
|
|
3657
|
+
var preferJSXTemplateLiterals = createRule48({
|
|
3792
3658
|
name: "prefer-jsx-template-literals",
|
|
3793
3659
|
meta: {
|
|
3794
3660
|
type: "suggestion",
|
|
@@ -3857,9 +3723,9 @@ var preferJSXTemplateLiterals = createRule51({
|
|
|
3857
3723
|
if (!child || !nextChild) {
|
|
3858
3724
|
return;
|
|
3859
3725
|
}
|
|
3860
|
-
if (child.type ===
|
|
3726
|
+
if (child.type === AST_NODE_TYPES48.JSXText && nextChild.type === AST_NODE_TYPES48.JSXExpressionContainer) {
|
|
3861
3727
|
handleTextBeforeExpression(child, nextChild);
|
|
3862
|
-
} else if (child.type ===
|
|
3728
|
+
} else if (child.type === AST_NODE_TYPES48.JSXExpressionContainer && nextChild.type === AST_NODE_TYPES48.JSXText) {
|
|
3863
3729
|
handleExpressionBeforeText(child, nextChild);
|
|
3864
3730
|
}
|
|
3865
3731
|
}
|
|
@@ -3872,11 +3738,32 @@ var preferJSXTemplateLiterals = createRule51({
|
|
|
3872
3738
|
var prefer_jsx_template_literals_default = preferJSXTemplateLiterals;
|
|
3873
3739
|
|
|
3874
3740
|
// src/rules/prefer-named-param-types.ts
|
|
3875
|
-
import { AST_NODE_TYPES as
|
|
3876
|
-
var
|
|
3741
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49, ESLintUtils as ESLintUtils49 } from "@typescript-eslint/utils";
|
|
3742
|
+
var createRule49 = ESLintUtils49.RuleCreator(
|
|
3877
3743
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3878
3744
|
);
|
|
3879
|
-
var
|
|
3745
|
+
var returnsJsx2 = (node) => {
|
|
3746
|
+
if (node.type === AST_NODE_TYPES49.JSXElement || node.type === AST_NODE_TYPES49.JSXFragment) {
|
|
3747
|
+
return true;
|
|
3748
|
+
}
|
|
3749
|
+
if (node.type === AST_NODE_TYPES49.ConditionalExpression) {
|
|
3750
|
+
return returnsJsx2(node.consequent) || returnsJsx2(node.alternate);
|
|
3751
|
+
}
|
|
3752
|
+
if (node.type === AST_NODE_TYPES49.LogicalExpression) {
|
|
3753
|
+
return returnsJsx2(node.left) || returnsJsx2(node.right);
|
|
3754
|
+
}
|
|
3755
|
+
return false;
|
|
3756
|
+
};
|
|
3757
|
+
var bodyReturnsJsx2 = (body) => {
|
|
3758
|
+
if (body.type !== AST_NODE_TYPES49.BlockStatement) {
|
|
3759
|
+
return returnsJsx2(body);
|
|
3760
|
+
}
|
|
3761
|
+
return body.body.some(
|
|
3762
|
+
(stmt) => stmt.type === AST_NODE_TYPES49.ReturnStatement && stmt.argument !== null && returnsJsx2(stmt.argument)
|
|
3763
|
+
);
|
|
3764
|
+
};
|
|
3765
|
+
var isReactComponentFunction = (node) => bodyReturnsJsx2(node.body);
|
|
3766
|
+
var preferNamedParamTypes = createRule49({
|
|
3880
3767
|
name: "prefer-named-param-types",
|
|
3881
3768
|
meta: {
|
|
3882
3769
|
type: "suggestion",
|
|
@@ -3891,16 +3778,16 @@ var preferNamedParamTypes = createRule52({
|
|
|
3891
3778
|
defaultOptions: [],
|
|
3892
3779
|
create(context) {
|
|
3893
3780
|
function hasInlineObjectType(param) {
|
|
3894
|
-
if (param.type ===
|
|
3781
|
+
if (param.type === AST_NODE_TYPES49.AssignmentPattern) {
|
|
3895
3782
|
return hasInlineObjectType(param.left);
|
|
3896
3783
|
}
|
|
3897
|
-
if (param.type ===
|
|
3898
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3784
|
+
if (param.type === AST_NODE_TYPES49.ObjectPattern) {
|
|
3785
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES49.TSTypeLiteral) {
|
|
3899
3786
|
return true;
|
|
3900
3787
|
}
|
|
3901
3788
|
}
|
|
3902
|
-
if (param.type ===
|
|
3903
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3789
|
+
if (param.type === AST_NODE_TYPES49.Identifier) {
|
|
3790
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES49.TSTypeLiteral) {
|
|
3904
3791
|
return true;
|
|
3905
3792
|
}
|
|
3906
3793
|
}
|
|
@@ -3913,6 +3800,9 @@ var preferNamedParamTypes = createRule52({
|
|
|
3913
3800
|
} else if ("value" in node && node.value) {
|
|
3914
3801
|
params = node.value.params;
|
|
3915
3802
|
}
|
|
3803
|
+
if ((node.type === AST_NODE_TYPES49.FunctionDeclaration || node.type === AST_NODE_TYPES49.FunctionExpression || node.type === AST_NODE_TYPES49.ArrowFunctionExpression) && params.length === 1 && params[0].type === AST_NODE_TYPES49.Identifier && isReactComponentFunction(node)) {
|
|
3804
|
+
return;
|
|
3805
|
+
}
|
|
3916
3806
|
params.forEach((param) => {
|
|
3917
3807
|
if (hasInlineObjectType(param)) {
|
|
3918
3808
|
context.report({
|
|
@@ -3933,12 +3823,91 @@ var preferNamedParamTypes = createRule52({
|
|
|
3933
3823
|
});
|
|
3934
3824
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
3935
3825
|
|
|
3826
|
+
// src/rules/prefer-props-with-children.ts
|
|
3827
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50, ESLintUtils as ESLintUtils50 } from "@typescript-eslint/utils";
|
|
3828
|
+
var createRule50 = ESLintUtils50.RuleCreator(
|
|
3829
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3830
|
+
);
|
|
3831
|
+
var preferPropsWithChildren = createRule50({
|
|
3832
|
+
name: "prefer-props-with-children",
|
|
3833
|
+
meta: {
|
|
3834
|
+
type: "suggestion",
|
|
3835
|
+
docs: {
|
|
3836
|
+
description: "Prefer PropsWithChildren<T> over manually declaring children: ReactNode in component props"
|
|
3837
|
+
},
|
|
3838
|
+
schema: [],
|
|
3839
|
+
messages: {
|
|
3840
|
+
usePropsWithChildren: "Use 'PropsWithChildren<T>' instead of manually declaring 'children: ReactNode'."
|
|
3841
|
+
}
|
|
3842
|
+
},
|
|
3843
|
+
defaultOptions: [],
|
|
3844
|
+
create(context) {
|
|
3845
|
+
function isReactNodeType(typeNode) {
|
|
3846
|
+
if (!typeNode) {
|
|
3847
|
+
return false;
|
|
3848
|
+
}
|
|
3849
|
+
if (typeNode.type !== AST_NODE_TYPES50.TSTypeReference) {
|
|
3850
|
+
return false;
|
|
3851
|
+
}
|
|
3852
|
+
const { typeName } = typeNode;
|
|
3853
|
+
if (typeName.type === AST_NODE_TYPES50.Identifier) {
|
|
3854
|
+
return typeName.name === "ReactNode";
|
|
3855
|
+
}
|
|
3856
|
+
if (typeName.type === AST_NODE_TYPES50.TSQualifiedName && typeName.left.type === AST_NODE_TYPES50.Identifier && typeName.left.name === "React" && typeName.right.type === AST_NODE_TYPES50.Identifier && typeName.right.name === "ReactNode") {
|
|
3857
|
+
return true;
|
|
3858
|
+
}
|
|
3859
|
+
return false;
|
|
3860
|
+
}
|
|
3861
|
+
function findChildrenReactNode(members) {
|
|
3862
|
+
for (const member of members) {
|
|
3863
|
+
if (member.type !== AST_NODE_TYPES50.TSPropertySignature) {
|
|
3864
|
+
continue;
|
|
3865
|
+
}
|
|
3866
|
+
if (member.key.type !== AST_NODE_TYPES50.Identifier) {
|
|
3867
|
+
continue;
|
|
3868
|
+
}
|
|
3869
|
+
if (member.key.name !== "children") {
|
|
3870
|
+
continue;
|
|
3871
|
+
}
|
|
3872
|
+
if (!member.typeAnnotation) {
|
|
3873
|
+
continue;
|
|
3874
|
+
}
|
|
3875
|
+
if (isReactNodeType(member.typeAnnotation.typeAnnotation)) {
|
|
3876
|
+
return member;
|
|
3877
|
+
}
|
|
3878
|
+
}
|
|
3879
|
+
return void 0;
|
|
3880
|
+
}
|
|
3881
|
+
return {
|
|
3882
|
+
TSInterfaceDeclaration(node) {
|
|
3883
|
+
const childrenMember = findChildrenReactNode(node.body.body);
|
|
3884
|
+
if (childrenMember) {
|
|
3885
|
+
context.report({
|
|
3886
|
+
node: childrenMember,
|
|
3887
|
+
messageId: "usePropsWithChildren"
|
|
3888
|
+
});
|
|
3889
|
+
}
|
|
3890
|
+
},
|
|
3891
|
+
TSTypeLiteral(node) {
|
|
3892
|
+
const childrenMember = findChildrenReactNode(node.members);
|
|
3893
|
+
if (childrenMember) {
|
|
3894
|
+
context.report({
|
|
3895
|
+
node: childrenMember,
|
|
3896
|
+
messageId: "usePropsWithChildren"
|
|
3897
|
+
});
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
3900
|
+
};
|
|
3901
|
+
}
|
|
3902
|
+
});
|
|
3903
|
+
var prefer_props_with_children_default = preferPropsWithChildren;
|
|
3904
|
+
|
|
3936
3905
|
// src/rules/prefer-react-import-types.ts
|
|
3937
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES51, ESLintUtils as
|
|
3938
|
-
var
|
|
3906
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ESLintUtils as ESLintUtils51 } from "@typescript-eslint/utils";
|
|
3907
|
+
var createRule51 = ESLintUtils51.RuleCreator(
|
|
3939
3908
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3940
3909
|
);
|
|
3941
|
-
var preferReactImportTypes =
|
|
3910
|
+
var preferReactImportTypes = createRule51({
|
|
3942
3911
|
name: "prefer-react-import-types",
|
|
3943
3912
|
meta: {
|
|
3944
3913
|
type: "suggestion",
|
|
@@ -4051,11 +4020,11 @@ var preferReactImportTypes = createRule53({
|
|
|
4051
4020
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
4052
4021
|
|
|
4053
4022
|
// src/rules/react-props-destructure.ts
|
|
4054
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES52, ESLintUtils as
|
|
4055
|
-
var
|
|
4023
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES52, ESLintUtils as ESLintUtils52 } from "@typescript-eslint/utils";
|
|
4024
|
+
var createRule52 = ESLintUtils52.RuleCreator(
|
|
4056
4025
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4057
4026
|
);
|
|
4058
|
-
var reactPropsDestructure =
|
|
4027
|
+
var reactPropsDestructure = createRule52({
|
|
4059
4028
|
name: "react-props-destructure",
|
|
4060
4029
|
meta: {
|
|
4061
4030
|
type: "suggestion",
|
|
@@ -4136,8 +4105,8 @@ var reactPropsDestructure = createRule54({
|
|
|
4136
4105
|
var react_props_destructure_default = reactPropsDestructure;
|
|
4137
4106
|
|
|
4138
4107
|
// src/rules/require-explicit-return-type.ts
|
|
4139
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES53, ESLintUtils as
|
|
4140
|
-
var
|
|
4108
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES53, ESLintUtils as ESLintUtils53 } from "@typescript-eslint/utils";
|
|
4109
|
+
var createRule53 = ESLintUtils53.RuleCreator(
|
|
4141
4110
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4142
4111
|
);
|
|
4143
4112
|
var isReactComponent = (node) => {
|
|
@@ -4186,7 +4155,7 @@ var getFunctionName = (node) => {
|
|
|
4186
4155
|
}
|
|
4187
4156
|
return null;
|
|
4188
4157
|
};
|
|
4189
|
-
var requireExplicitReturnType =
|
|
4158
|
+
var requireExplicitReturnType = createRule53({
|
|
4190
4159
|
name: "require-explicit-return-type",
|
|
4191
4160
|
meta: {
|
|
4192
4161
|
type: "suggestion",
|
|
@@ -4235,8 +4204,8 @@ var requireExplicitReturnType = createRule55({
|
|
|
4235
4204
|
var require_explicit_return_type_default = requireExplicitReturnType;
|
|
4236
4205
|
|
|
4237
4206
|
// src/rules/sort-exports.ts
|
|
4238
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES54, ESLintUtils as
|
|
4239
|
-
var
|
|
4207
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES54, ESLintUtils as ESLintUtils54 } from "@typescript-eslint/utils";
|
|
4208
|
+
var createRule54 = ESLintUtils54.RuleCreator(
|
|
4240
4209
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4241
4210
|
);
|
|
4242
4211
|
var GROUP_NAMES = ["", "external/alias re-export", "relative re-export", "local export"];
|
|
@@ -4250,7 +4219,7 @@ function getExportGroup(node) {
|
|
|
4250
4219
|
}
|
|
4251
4220
|
return 1;
|
|
4252
4221
|
}
|
|
4253
|
-
var sortExports =
|
|
4222
|
+
var sortExports = createRule54({
|
|
4254
4223
|
name: "sort-exports",
|
|
4255
4224
|
meta: {
|
|
4256
4225
|
type: "suggestion",
|
|
@@ -4309,8 +4278,8 @@ var sortExports = createRule56({
|
|
|
4309
4278
|
var sort_exports_default = sortExports;
|
|
4310
4279
|
|
|
4311
4280
|
// src/rules/sort-imports.ts
|
|
4312
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES55, ESLintUtils as
|
|
4313
|
-
var
|
|
4281
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55, ESLintUtils as ESLintUtils55 } from "@typescript-eslint/utils";
|
|
4282
|
+
var createRule55 = ESLintUtils55.RuleCreator(
|
|
4314
4283
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4315
4284
|
);
|
|
4316
4285
|
var NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
@@ -4377,7 +4346,7 @@ function getImportGroup(node) {
|
|
|
4377
4346
|
function isTypeOnlyImport(node) {
|
|
4378
4347
|
return node.importKind === "type" && node.specifiers.length > 0;
|
|
4379
4348
|
}
|
|
4380
|
-
var sortImports =
|
|
4349
|
+
var sortImports = createRule55({
|
|
4381
4350
|
name: "sort-imports",
|
|
4382
4351
|
meta: {
|
|
4383
4352
|
type: "suggestion",
|
|
@@ -4443,8 +4412,8 @@ var sortImports = createRule57({
|
|
|
4443
4412
|
var sort_imports_default = sortImports;
|
|
4444
4413
|
|
|
4445
4414
|
// src/rules/sort-type-alphabetically.ts
|
|
4446
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES56, ESLintUtils as
|
|
4447
|
-
var
|
|
4415
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES56, ESLintUtils as ESLintUtils56 } from "@typescript-eslint/utils";
|
|
4416
|
+
var createRule56 = ESLintUtils56.RuleCreator(
|
|
4448
4417
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4449
4418
|
);
|
|
4450
4419
|
function isAlphabeticallySortedWithinGroups(members) {
|
|
@@ -4460,7 +4429,7 @@ function isAlphabeticallySortedWithinGroups(members) {
|
|
|
4460
4429
|
const isOptionalSorted = optional.every((name, index) => index === 0 || optional[index - 1].localeCompare(name) <= 0);
|
|
4461
4430
|
return isRequiredSorted && isOptionalSorted;
|
|
4462
4431
|
}
|
|
4463
|
-
var sortTypeAlphabetically =
|
|
4432
|
+
var sortTypeAlphabetically = createRule56({
|
|
4464
4433
|
name: "sort-type-alphabetically",
|
|
4465
4434
|
meta: {
|
|
4466
4435
|
type: "suggestion",
|
|
@@ -4535,8 +4504,8 @@ var sortTypeAlphabetically = createRule58({
|
|
|
4535
4504
|
var sort_type_alphabetically_default = sortTypeAlphabetically;
|
|
4536
4505
|
|
|
4537
4506
|
// src/rules/sort-type-required-first.ts
|
|
4538
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES57, ESLintUtils as
|
|
4539
|
-
var
|
|
4507
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES57, ESLintUtils as ESLintUtils57 } from "@typescript-eslint/utils";
|
|
4508
|
+
var createRule57 = ESLintUtils57.RuleCreator(
|
|
4540
4509
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4541
4510
|
);
|
|
4542
4511
|
function isRequiredBeforeOptional(members) {
|
|
@@ -4552,7 +4521,7 @@ function isRequiredBeforeOptional(members) {
|
|
|
4552
4521
|
}
|
|
4553
4522
|
return properties.slice(firstOptionalIndex).every((prop) => prop.optional);
|
|
4554
4523
|
}
|
|
4555
|
-
var sortTypeRequiredFirst =
|
|
4524
|
+
var sortTypeRequiredFirst = createRule57({
|
|
4556
4525
|
name: "sort-type-required-first",
|
|
4557
4526
|
meta: {
|
|
4558
4527
|
type: "suggestion",
|
|
@@ -4619,7 +4588,6 @@ var rules = {
|
|
|
4619
4588
|
"boolean-naming-prefix": boolean_naming_prefix_default,
|
|
4620
4589
|
"enforce-camel-case": enforce_camel_case_default,
|
|
4621
4590
|
"enforce-constant-case": enforce_constant_case_default,
|
|
4622
|
-
"enforce-curly-newline": enforce_curly_newline_default,
|
|
4623
4591
|
"enforce-hook-naming": enforce_hook_naming_default,
|
|
4624
4592
|
"enforce-property-case": enforce_property_case_default,
|
|
4625
4593
|
"enforce-props-suffix": enforce_props_suffix_default,
|
|
@@ -4627,7 +4595,6 @@ var rules = {
|
|
|
4627
4595
|
"enforce-service-naming": enforce_service_naming_default,
|
|
4628
4596
|
"enforce-sorted-destructuring": enforce_sorted_destructuring_default,
|
|
4629
4597
|
"enforce-type-declaration-order": enforce_type_declaration_order_default,
|
|
4630
|
-
"file-kebab-case": file_kebab_case_default,
|
|
4631
4598
|
"index-export-only": index_export_only_default,
|
|
4632
4599
|
"jsx-newline-between-elements": jsx_newline_between_elements_default,
|
|
4633
4600
|
"jsx-no-inline-object-prop": jsx_no_inline_object_prop_default,
|
|
@@ -4635,14 +4602,12 @@ var rules = {
|
|
|
4635
4602
|
"jsx-no-non-component-function": jsx_no_non_component_function_default,
|
|
4636
4603
|
"jsx-no-ternary-null": jsx_no_ternary_null_default,
|
|
4637
4604
|
"jsx-no-variable-in-callback": jsx_no_variable_in_callback_default,
|
|
4638
|
-
"jsx-pascal-case": jsx_pascal_case_default,
|
|
4639
4605
|
"jsx-require-suspense": jsx_require_suspense_default,
|
|
4640
4606
|
"jsx-simple-props": jsx_simple_props_default,
|
|
4641
4607
|
"jsx-sort-props": jsx_sort_props_default,
|
|
4642
4608
|
"jsx-spread-props-last": jsx_spread_props_last_default,
|
|
4643
4609
|
"newline-after-multiline-block": newline_after_multiline_block_default,
|
|
4644
4610
|
"newline-before-return": newline_before_return_default,
|
|
4645
|
-
"nextjs-require-public-env": nextjs_require_public_env_default,
|
|
4646
4611
|
"no-complex-inline-return": no_complex_inline_return_default,
|
|
4647
4612
|
"no-direct-date": no_direct_date_default,
|
|
4648
4613
|
"no-emoji": no_emoji_default,
|
|
@@ -4665,9 +4630,11 @@ var rules = {
|
|
|
4665
4630
|
"prefer-import-type": prefer_import_type_default,
|
|
4666
4631
|
"prefer-inline-literal-union": prefer_inline_literal_union_default,
|
|
4667
4632
|
"prefer-inline-type-export": prefer_inline_type_export_default,
|
|
4633
|
+
"prefer-interface-for-component-props": prefer_interface_for_component_props_default,
|
|
4668
4634
|
"prefer-interface-over-inline-types": prefer_interface_over_inline_types_default,
|
|
4669
4635
|
"prefer-jsx-template-literals": prefer_jsx_template_literals_default,
|
|
4670
4636
|
"prefer-named-param-types": prefer_named_param_types_default,
|
|
4637
|
+
"prefer-props-with-children": prefer_props_with_children_default,
|
|
4671
4638
|
"prefer-react-import-types": prefer_react_import_types_default,
|
|
4672
4639
|
"react-props-destructure": react_props_destructure_default,
|
|
4673
4640
|
"require-explicit-return-type": require_explicit_return_type_default,
|
|
@@ -4684,13 +4651,11 @@ var baseRules = {
|
|
|
4684
4651
|
"nextfriday/boolean-naming-prefix": "warn",
|
|
4685
4652
|
"nextfriday/enforce-camel-case": "warn",
|
|
4686
4653
|
"nextfriday/enforce-constant-case": "warn",
|
|
4687
|
-
"nextfriday/enforce-curly-newline": "warn",
|
|
4688
4654
|
"nextfriday/enforce-hook-naming": "warn",
|
|
4689
4655
|
"nextfriday/enforce-property-case": "warn",
|
|
4690
4656
|
"nextfriday/enforce-service-naming": "warn",
|
|
4691
4657
|
"nextfriday/enforce-sorted-destructuring": "warn",
|
|
4692
4658
|
"nextfriday/enforce-type-declaration-order": "warn",
|
|
4693
|
-
"nextfriday/file-kebab-case": "warn",
|
|
4694
4659
|
"nextfriday/index-export-only": "warn",
|
|
4695
4660
|
"nextfriday/newline-after-multiline-block": "warn",
|
|
4696
4661
|
"nextfriday/newline-before-return": "warn",
|
|
@@ -4728,13 +4693,11 @@ var baseRecommendedRules = {
|
|
|
4728
4693
|
"nextfriday/boolean-naming-prefix": "error",
|
|
4729
4694
|
"nextfriday/enforce-camel-case": "error",
|
|
4730
4695
|
"nextfriday/enforce-constant-case": "error",
|
|
4731
|
-
"nextfriday/enforce-curly-newline": "error",
|
|
4732
4696
|
"nextfriday/enforce-hook-naming": "error",
|
|
4733
4697
|
"nextfriday/enforce-property-case": "error",
|
|
4734
4698
|
"nextfriday/enforce-service-naming": "error",
|
|
4735
4699
|
"nextfriday/enforce-sorted-destructuring": "error",
|
|
4736
4700
|
"nextfriday/enforce-type-declaration-order": "error",
|
|
4737
|
-
"nextfriday/file-kebab-case": "error",
|
|
4738
4701
|
"nextfriday/index-export-only": "error",
|
|
4739
4702
|
"nextfriday/newline-after-multiline-block": "error",
|
|
4740
4703
|
"nextfriday/newline-before-return": "error",
|
|
@@ -4777,13 +4740,14 @@ var jsxRules = {
|
|
|
4777
4740
|
"nextfriday/jsx-no-non-component-function": "warn",
|
|
4778
4741
|
"nextfriday/jsx-no-ternary-null": "warn",
|
|
4779
4742
|
"nextfriday/jsx-no-variable-in-callback": "warn",
|
|
4780
|
-
"nextfriday/jsx-pascal-case": "warn",
|
|
4781
4743
|
"nextfriday/jsx-require-suspense": "warn",
|
|
4782
4744
|
"nextfriday/jsx-simple-props": "warn",
|
|
4783
4745
|
"nextfriday/jsx-sort-props": "warn",
|
|
4784
4746
|
"nextfriday/jsx-spread-props-last": "warn",
|
|
4747
|
+
"nextfriday/prefer-interface-for-component-props": "warn",
|
|
4785
4748
|
"nextfriday/prefer-interface-over-inline-types": "warn",
|
|
4786
4749
|
"nextfriday/prefer-jsx-template-literals": "warn",
|
|
4750
|
+
"nextfriday/prefer-props-with-children": "warn",
|
|
4787
4751
|
"nextfriday/react-props-destructure": "warn"
|
|
4788
4752
|
};
|
|
4789
4753
|
var jsxRecommendedRules = {
|
|
@@ -4795,41 +4759,22 @@ var jsxRecommendedRules = {
|
|
|
4795
4759
|
"nextfriday/jsx-no-non-component-function": "error",
|
|
4796
4760
|
"nextfriday/jsx-no-ternary-null": "error",
|
|
4797
4761
|
"nextfriday/jsx-no-variable-in-callback": "error",
|
|
4798
|
-
"nextfriday/jsx-pascal-case": "error",
|
|
4799
4762
|
"nextfriday/jsx-require-suspense": "error",
|
|
4800
4763
|
"nextfriday/jsx-simple-props": "error",
|
|
4801
4764
|
"nextfriday/jsx-sort-props": "error",
|
|
4802
4765
|
"nextfriday/jsx-spread-props-last": "error",
|
|
4766
|
+
"nextfriday/prefer-interface-for-component-props": "error",
|
|
4803
4767
|
"nextfriday/prefer-interface-over-inline-types": "error",
|
|
4804
4768
|
"nextfriday/prefer-jsx-template-literals": "error",
|
|
4769
|
+
"nextfriday/prefer-props-with-children": "error",
|
|
4805
4770
|
"nextfriday/react-props-destructure": "error"
|
|
4806
4771
|
};
|
|
4807
|
-
var nextjsOnlyRules = {
|
|
4808
|
-
"nextfriday/nextjs-require-public-env": "warn"
|
|
4809
|
-
};
|
|
4810
|
-
var nextjsOnlyRecommendedRules = {
|
|
4811
|
-
"nextfriday/nextjs-require-public-env": "error"
|
|
4812
|
-
};
|
|
4813
4772
|
var createConfig = (configRules) => ({
|
|
4814
4773
|
plugins: {
|
|
4815
4774
|
nextfriday: plugin
|
|
4816
4775
|
},
|
|
4817
4776
|
rules: configRules
|
|
4818
4777
|
});
|
|
4819
|
-
var NEXTJS_ROUTING_GLOBS = [
|
|
4820
|
-
"app/**/*.{js,jsx,ts,tsx}",
|
|
4821
|
-
"src/app/**/*.{js,jsx,ts,tsx}",
|
|
4822
|
-
"pages/**/*.{js,jsx,ts,tsx}",
|
|
4823
|
-
"src/pages/**/*.{js,jsx,ts,tsx}"
|
|
4824
|
-
];
|
|
4825
|
-
var nextjsRoutingOverride = {
|
|
4826
|
-
files: NEXTJS_ROUTING_GLOBS,
|
|
4827
|
-
rules: {
|
|
4828
|
-
"nextfriday/file-kebab-case": "off",
|
|
4829
|
-
"nextfriday/jsx-pascal-case": "off"
|
|
4830
|
-
}
|
|
4831
|
-
};
|
|
4832
|
-
var createNextjsConfig = (configRules) => [createConfig(configRules), nextjsRoutingOverride];
|
|
4833
4778
|
var configs = {
|
|
4834
4779
|
base: createConfig(baseRules),
|
|
4835
4780
|
"base/recommended": createConfig(baseRecommendedRules),
|
|
@@ -4841,15 +4786,13 @@ var configs = {
|
|
|
4841
4786
|
...baseRecommendedRules,
|
|
4842
4787
|
...jsxRecommendedRules
|
|
4843
4788
|
}),
|
|
4844
|
-
nextjs:
|
|
4789
|
+
nextjs: createConfig({
|
|
4845
4790
|
...baseRules,
|
|
4846
|
-
...jsxRules
|
|
4847
|
-
...nextjsOnlyRules
|
|
4791
|
+
...jsxRules
|
|
4848
4792
|
}),
|
|
4849
|
-
"nextjs/recommended":
|
|
4793
|
+
"nextjs/recommended": createConfig({
|
|
4850
4794
|
...baseRecommendedRules,
|
|
4851
|
-
...jsxRecommendedRules
|
|
4852
|
-
...nextjsOnlyRecommendedRules
|
|
4795
|
+
...jsxRecommendedRules
|
|
4853
4796
|
})
|
|
4854
4797
|
};
|
|
4855
4798
|
var nextfridayPlugin = {
|