eslint-plugin-nextfriday 3.2.1 → 4.1.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 +26 -0
- package/README.md +36 -70
- 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_GHOST_WRAPPER.md +75 -0
- package/docs/rules/NO_INLINE_NESTED_OBJECT.md +45 -27
- package/docs/rules/NO_REDUNDANT_FRAGMENT.md +56 -0
- 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 +748 -679
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +176 -200
- package/lib/index.d.ts +176 -200
- package/lib/index.js +685 -616
- 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.1.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) {
|
|
@@ -2273,12 +2070,58 @@ var noEnvFallback = createRule31({
|
|
|
2273
2070
|
});
|
|
2274
2071
|
var no_env_fallback_default = noEnvFallback;
|
|
2275
2072
|
|
|
2073
|
+
// src/rules/no-ghost-wrapper.ts
|
|
2074
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28, ESLintUtils as ESLintUtils28 } from "@typescript-eslint/utils";
|
|
2075
|
+
var createRule28 = ESLintUtils28.RuleCreator(
|
|
2076
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2077
|
+
);
|
|
2078
|
+
var GHOST_TAGS = /* @__PURE__ */ new Set(["div", "span"]);
|
|
2079
|
+
function isKeyAttribute(attribute) {
|
|
2080
|
+
return attribute.type === AST_NODE_TYPES28.JSXAttribute && attribute.name.type === AST_NODE_TYPES28.JSXIdentifier && attribute.name.name === "key";
|
|
2081
|
+
}
|
|
2082
|
+
var noGhostWrapper = createRule28({
|
|
2083
|
+
name: "no-ghost-wrapper",
|
|
2084
|
+
meta: {
|
|
2085
|
+
type: "problem",
|
|
2086
|
+
docs: {
|
|
2087
|
+
description: "Disallow bare <div> and <span> elements that have no meaningful attributes (Divitis / ghost wrappers)"
|
|
2088
|
+
},
|
|
2089
|
+
schema: [],
|
|
2090
|
+
messages: {
|
|
2091
|
+
noGhostWrapper: "Ghost <{{ tag }}> has no meaningful attributes. Use a Fragment (<>...</>), a semantic element (section, article, header, etc.), or add a meaningful attribute (className, role, data-*, ref, etc.). Note: 'key' alone does not count as meaningful."
|
|
2092
|
+
}
|
|
2093
|
+
},
|
|
2094
|
+
defaultOptions: [],
|
|
2095
|
+
create(context) {
|
|
2096
|
+
return {
|
|
2097
|
+
JSXOpeningElement(node) {
|
|
2098
|
+
if (node.name.type !== AST_NODE_TYPES28.JSXIdentifier) {
|
|
2099
|
+
return;
|
|
2100
|
+
}
|
|
2101
|
+
const tagName = node.name.name;
|
|
2102
|
+
if (!GHOST_TAGS.has(tagName)) {
|
|
2103
|
+
return;
|
|
2104
|
+
}
|
|
2105
|
+
const meaningfulAttributes = node.attributes.filter((attribute) => !isKeyAttribute(attribute));
|
|
2106
|
+
if (meaningfulAttributes.length === 0) {
|
|
2107
|
+
context.report({
|
|
2108
|
+
node,
|
|
2109
|
+
messageId: "noGhostWrapper",
|
|
2110
|
+
data: { tag: tagName }
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
});
|
|
2117
|
+
var no_ghost_wrapper_default = noGhostWrapper;
|
|
2118
|
+
|
|
2276
2119
|
// src/rules/no-inline-default-export.ts
|
|
2277
|
-
import { AST_NODE_TYPES as
|
|
2278
|
-
var
|
|
2120
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29, ESLintUtils as ESLintUtils29 } from "@typescript-eslint/utils";
|
|
2121
|
+
var createRule29 = ESLintUtils29.RuleCreator(
|
|
2279
2122
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2280
2123
|
);
|
|
2281
|
-
var noInlineDefaultExport =
|
|
2124
|
+
var noInlineDefaultExport = createRule29({
|
|
2282
2125
|
name: "no-inline-default-export",
|
|
2283
2126
|
meta: {
|
|
2284
2127
|
type: "suggestion",
|
|
@@ -2297,7 +2140,7 @@ var noInlineDefaultExport = createRule32({
|
|
|
2297
2140
|
return {
|
|
2298
2141
|
ExportDefaultDeclaration(node) {
|
|
2299
2142
|
const { declaration } = node;
|
|
2300
|
-
if (declaration.type ===
|
|
2143
|
+
if (declaration.type === AST_NODE_TYPES29.FunctionDeclaration) {
|
|
2301
2144
|
if (declaration.id) {
|
|
2302
2145
|
context.report({
|
|
2303
2146
|
node,
|
|
@@ -2312,7 +2155,7 @@ var noInlineDefaultExport = createRule32({
|
|
|
2312
2155
|
});
|
|
2313
2156
|
}
|
|
2314
2157
|
}
|
|
2315
|
-
if (declaration.type ===
|
|
2158
|
+
if (declaration.type === AST_NODE_TYPES29.ClassDeclaration) {
|
|
2316
2159
|
if (declaration.id) {
|
|
2317
2160
|
context.report({
|
|
2318
2161
|
node,
|
|
@@ -2327,7 +2170,7 @@ var noInlineDefaultExport = createRule32({
|
|
|
2327
2170
|
});
|
|
2328
2171
|
}
|
|
2329
2172
|
}
|
|
2330
|
-
if (declaration.type ===
|
|
2173
|
+
if (declaration.type === AST_NODE_TYPES29.ArrowFunctionExpression || declaration.type === AST_NODE_TYPES29.FunctionExpression) {
|
|
2331
2174
|
context.report({
|
|
2332
2175
|
node,
|
|
2333
2176
|
messageId: "noAnonymousDefaultExport",
|
|
@@ -2340,14 +2183,14 @@ var noInlineDefaultExport = createRule32({
|
|
|
2340
2183
|
if (!declaration) {
|
|
2341
2184
|
return;
|
|
2342
2185
|
}
|
|
2343
|
-
if (declaration.type ===
|
|
2186
|
+
if (declaration.type === AST_NODE_TYPES29.FunctionDeclaration && declaration.id) {
|
|
2344
2187
|
context.report({
|
|
2345
2188
|
node,
|
|
2346
2189
|
messageId: "noInlineNamedExport",
|
|
2347
2190
|
data: { type: "function", name: declaration.id.name }
|
|
2348
2191
|
});
|
|
2349
2192
|
}
|
|
2350
|
-
if (declaration.type ===
|
|
2193
|
+
if (declaration.type === AST_NODE_TYPES29.ClassDeclaration && declaration.id) {
|
|
2351
2194
|
context.report({
|
|
2352
2195
|
node,
|
|
2353
2196
|
messageId: "noInlineNamedExport",
|
|
@@ -2361,36 +2204,45 @@ var noInlineDefaultExport = createRule32({
|
|
|
2361
2204
|
var no_inline_default_export_default = noInlineDefaultExport;
|
|
2362
2205
|
|
|
2363
2206
|
// src/rules/no-inline-nested-object.ts
|
|
2364
|
-
import { AST_NODE_TYPES as
|
|
2365
|
-
var
|
|
2207
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30, ESLintUtils as ESLintUtils30 } from "@typescript-eslint/utils";
|
|
2208
|
+
var createRule30 = ESLintUtils30.RuleCreator(
|
|
2366
2209
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2367
2210
|
);
|
|
2368
2211
|
function isObjectOrArray(node) {
|
|
2369
|
-
return node.type ===
|
|
2212
|
+
return node.type === AST_NODE_TYPES30.ObjectExpression || node.type === AST_NODE_TYPES30.ArrayExpression || node.type === AST_NODE_TYPES30.TSAsExpression;
|
|
2370
2213
|
}
|
|
2371
2214
|
function getInnerExpression(node) {
|
|
2372
|
-
if (node.type ===
|
|
2215
|
+
if (node.type === AST_NODE_TYPES30.TSAsExpression) {
|
|
2373
2216
|
return getInnerExpression(node.expression);
|
|
2374
2217
|
}
|
|
2375
2218
|
return node;
|
|
2376
2219
|
}
|
|
2377
|
-
function
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2220
|
+
function isNestedStructure(node) {
|
|
2221
|
+
const inner = getInnerExpression(node);
|
|
2222
|
+
return inner.type === AST_NODE_TYPES30.ObjectExpression || inner.type === AST_NODE_TYPES30.ArrayExpression;
|
|
2223
|
+
}
|
|
2224
|
+
function containsNestedStructure(node) {
|
|
2225
|
+
if (node.type === AST_NODE_TYPES30.ObjectExpression) {
|
|
2226
|
+
return node.properties.some((prop) => {
|
|
2227
|
+
if (prop.type !== AST_NODE_TYPES30.Property) return false;
|
|
2228
|
+
return isNestedStructure(prop.value);
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
return node.elements.some((el) => {
|
|
2232
|
+
if (el === null) return false;
|
|
2233
|
+
return isNestedStructure(el);
|
|
2382
2234
|
});
|
|
2383
2235
|
}
|
|
2384
|
-
var noInlineNestedObject =
|
|
2236
|
+
var noInlineNestedObject = createRule30({
|
|
2385
2237
|
name: "no-inline-nested-object",
|
|
2386
2238
|
meta: {
|
|
2387
2239
|
type: "layout",
|
|
2388
2240
|
docs: {
|
|
2389
|
-
description: "Require nested objects
|
|
2241
|
+
description: "Require object or array values that contain further nested objects or arrays to span multiple lines"
|
|
2390
2242
|
},
|
|
2391
2243
|
fixable: "whitespace",
|
|
2392
2244
|
messages: {
|
|
2393
|
-
requireMultiline: "
|
|
2245
|
+
requireMultiline: "Inline collections containing nested objects or arrays should span multiple lines"
|
|
2394
2246
|
},
|
|
2395
2247
|
schema: []
|
|
2396
2248
|
},
|
|
@@ -2403,23 +2255,20 @@ var noInlineNestedObject = createRule33({
|
|
|
2403
2255
|
return;
|
|
2404
2256
|
}
|
|
2405
2257
|
const valueNode = getInnerExpression(node.value);
|
|
2406
|
-
if (valueNode.type !==
|
|
2258
|
+
if (valueNode.type !== AST_NODE_TYPES30.ObjectExpression && valueNode.type !== AST_NODE_TYPES30.ArrayExpression) {
|
|
2407
2259
|
return;
|
|
2408
2260
|
}
|
|
2409
2261
|
if (!valueNode.loc) {
|
|
2410
2262
|
return;
|
|
2411
2263
|
}
|
|
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
2264
|
const isMultiline = valueNode.loc.start.line !== valueNode.loc.end.line;
|
|
2420
2265
|
if (isMultiline) {
|
|
2421
2266
|
return;
|
|
2422
2267
|
}
|
|
2268
|
+
if (!containsNestedStructure(valueNode)) {
|
|
2269
|
+
return;
|
|
2270
|
+
}
|
|
2271
|
+
const elements = valueNode.type === AST_NODE_TYPES30.ObjectExpression ? valueNode.properties : valueNode.elements;
|
|
2423
2272
|
context.report({
|
|
2424
2273
|
node: valueNode,
|
|
2425
2274
|
messageId: "requireMultiline",
|
|
@@ -2432,7 +2281,7 @@ var noInlineNestedObject = createRule33({
|
|
|
2432
2281
|
const indent = " ".repeat(node.loc?.start.column ?? 0);
|
|
2433
2282
|
const innerIndent = `${indent} `;
|
|
2434
2283
|
const elementTexts = elements.filter((el) => el !== null).map((el) => sourceCode.getText(el));
|
|
2435
|
-
const isObject = valueNode.type ===
|
|
2284
|
+
const isObject = valueNode.type === AST_NODE_TYPES30.ObjectExpression;
|
|
2436
2285
|
const openChar = isObject ? "{" : "[";
|
|
2437
2286
|
const closeChar = isObject ? "}" : "]";
|
|
2438
2287
|
const formattedElements = elementTexts.map((text) => `${innerIndent}${text},`).join("\n");
|
|
@@ -2449,20 +2298,20 @@ ${indent}${closeChar}`;
|
|
|
2449
2298
|
var no_inline_nested_object_default = noInlineNestedObject;
|
|
2450
2299
|
|
|
2451
2300
|
// src/rules/no-inline-return-properties.ts
|
|
2452
|
-
import { AST_NODE_TYPES as
|
|
2453
|
-
var
|
|
2301
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31, ESLintUtils as ESLintUtils31 } from "@typescript-eslint/utils";
|
|
2302
|
+
var createRule31 = ESLintUtils31.RuleCreator(
|
|
2454
2303
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2455
2304
|
);
|
|
2456
2305
|
var isShorthandProperty = (property) => {
|
|
2457
|
-
if (property.type ===
|
|
2306
|
+
if (property.type === AST_NODE_TYPES31.SpreadElement) {
|
|
2458
2307
|
return true;
|
|
2459
2308
|
}
|
|
2460
|
-
if (property.type !==
|
|
2309
|
+
if (property.type !== AST_NODE_TYPES31.Property) {
|
|
2461
2310
|
return false;
|
|
2462
2311
|
}
|
|
2463
2312
|
return property.shorthand;
|
|
2464
2313
|
};
|
|
2465
|
-
var noInlineReturnProperties =
|
|
2314
|
+
var noInlineReturnProperties = createRule31({
|
|
2466
2315
|
name: "no-inline-return-properties",
|
|
2467
2316
|
meta: {
|
|
2468
2317
|
type: "suggestion",
|
|
@@ -2478,20 +2327,20 @@ var noInlineReturnProperties = createRule34({
|
|
|
2478
2327
|
create(context) {
|
|
2479
2328
|
return {
|
|
2480
2329
|
ReturnStatement(node) {
|
|
2481
|
-
if (!node.argument || node.argument.type !==
|
|
2330
|
+
if (!node.argument || node.argument.type !== AST_NODE_TYPES31.ObjectExpression) {
|
|
2482
2331
|
return;
|
|
2483
2332
|
}
|
|
2484
2333
|
node.argument.properties.forEach((property) => {
|
|
2485
2334
|
if (isShorthandProperty(property)) {
|
|
2486
2335
|
return;
|
|
2487
2336
|
}
|
|
2488
|
-
if (property.type !==
|
|
2337
|
+
if (property.type !== AST_NODE_TYPES31.Property) {
|
|
2489
2338
|
return;
|
|
2490
2339
|
}
|
|
2491
2340
|
let keyName = null;
|
|
2492
|
-
if (property.key.type ===
|
|
2341
|
+
if (property.key.type === AST_NODE_TYPES31.Identifier) {
|
|
2493
2342
|
keyName = property.key.name;
|
|
2494
|
-
} else if (property.key.type ===
|
|
2343
|
+
} else if (property.key.type === AST_NODE_TYPES31.Literal) {
|
|
2495
2344
|
keyName = String(property.key.value);
|
|
2496
2345
|
}
|
|
2497
2346
|
context.report({
|
|
@@ -2507,12 +2356,12 @@ var noInlineReturnProperties = createRule34({
|
|
|
2507
2356
|
var no_inline_return_properties_default = noInlineReturnProperties;
|
|
2508
2357
|
|
|
2509
2358
|
// src/rules/no-inline-type-import.ts
|
|
2510
|
-
import { AST_NODE_TYPES as
|
|
2511
|
-
var
|
|
2359
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32, ESLintUtils as ESLintUtils32 } from "@typescript-eslint/utils";
|
|
2360
|
+
var createRule32 = ESLintUtils32.RuleCreator(
|
|
2512
2361
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2513
2362
|
);
|
|
2514
|
-
var isInlineTypeSpecifier = (specifier) => specifier.type ===
|
|
2515
|
-
var noInlineTypeImport =
|
|
2363
|
+
var isInlineTypeSpecifier = (specifier) => specifier.type === AST_NODE_TYPES32.ImportSpecifier && specifier.importKind === "type";
|
|
2364
|
+
var noInlineTypeImport = createRule32({
|
|
2516
2365
|
name: "no-inline-type-import",
|
|
2517
2366
|
meta: {
|
|
2518
2367
|
type: "suggestion",
|
|
@@ -2549,7 +2398,7 @@ var noInlineTypeImport = createRule35({
|
|
|
2549
2398
|
);
|
|
2550
2399
|
const typeImport = `import type { ${typeSpecifierTexts.join(", ")} } from ${sourceText};`;
|
|
2551
2400
|
const valueSpecifiers = node.specifiers.filter(
|
|
2552
|
-
(specifier) => !(specifier.type ===
|
|
2401
|
+
(specifier) => !(specifier.type === AST_NODE_TYPES32.ImportSpecifier && specifier.importKind === "type")
|
|
2553
2402
|
);
|
|
2554
2403
|
if (valueSpecifiers.length === 0) {
|
|
2555
2404
|
return fixer.replaceText(node, typeImport);
|
|
@@ -2557,11 +2406,11 @@ var noInlineTypeImport = createRule35({
|
|
|
2557
2406
|
const parts = [];
|
|
2558
2407
|
const namedValueSpecifiers = [];
|
|
2559
2408
|
for (const specifier of valueSpecifiers) {
|
|
2560
|
-
if (specifier.type ===
|
|
2409
|
+
if (specifier.type === AST_NODE_TYPES32.ImportDefaultSpecifier) {
|
|
2561
2410
|
parts.push(specifier.local.name);
|
|
2562
|
-
} else if (specifier.type ===
|
|
2411
|
+
} else if (specifier.type === AST_NODE_TYPES32.ImportNamespaceSpecifier) {
|
|
2563
2412
|
parts.push(`* as ${specifier.local.name}`);
|
|
2564
|
-
} else if (specifier.type ===
|
|
2413
|
+
} else if (specifier.type === AST_NODE_TYPES32.ImportSpecifier) {
|
|
2565
2414
|
namedValueSpecifiers.push(specifier);
|
|
2566
2415
|
}
|
|
2567
2416
|
}
|
|
@@ -2581,8 +2430,8 @@ ${typeImport}`);
|
|
|
2581
2430
|
var no_inline_type_import_default = noInlineTypeImport;
|
|
2582
2431
|
|
|
2583
2432
|
// src/rules/no-lazy-identifiers.ts
|
|
2584
|
-
import { AST_NODE_TYPES as
|
|
2585
|
-
var
|
|
2433
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33, ESLintUtils as ESLintUtils33 } from "@typescript-eslint/utils";
|
|
2434
|
+
var createRule33 = ESLintUtils33.RuleCreator(
|
|
2586
2435
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2587
2436
|
);
|
|
2588
2437
|
var KEYBOARD_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm", "1234567890"];
|
|
@@ -2623,7 +2472,7 @@ var isLazyIdentifier = (name) => {
|
|
|
2623
2472
|
}
|
|
2624
2473
|
return false;
|
|
2625
2474
|
};
|
|
2626
|
-
var noLazyIdentifiers =
|
|
2475
|
+
var noLazyIdentifiers = createRule33({
|
|
2627
2476
|
name: "no-lazy-identifiers",
|
|
2628
2477
|
meta: {
|
|
2629
2478
|
type: "problem",
|
|
@@ -2649,27 +2498,27 @@ var noLazyIdentifiers = createRule36({
|
|
|
2649
2498
|
});
|
|
2650
2499
|
};
|
|
2651
2500
|
const checkPattern = (pattern) => {
|
|
2652
|
-
if (pattern.type ===
|
|
2501
|
+
if (pattern.type === AST_NODE_TYPES33.Identifier) {
|
|
2653
2502
|
checkIdentifier(pattern);
|
|
2654
|
-
} else if (pattern.type ===
|
|
2503
|
+
} else if (pattern.type === AST_NODE_TYPES33.ObjectPattern) {
|
|
2655
2504
|
pattern.properties.forEach((prop) => {
|
|
2656
|
-
if (prop.type ===
|
|
2505
|
+
if (prop.type === AST_NODE_TYPES33.Property && prop.value.type === AST_NODE_TYPES33.Identifier) {
|
|
2657
2506
|
checkIdentifier(prop.value);
|
|
2658
|
-
} else if (prop.type ===
|
|
2507
|
+
} else if (prop.type === AST_NODE_TYPES33.RestElement && prop.argument.type === AST_NODE_TYPES33.Identifier) {
|
|
2659
2508
|
checkIdentifier(prop.argument);
|
|
2660
2509
|
}
|
|
2661
2510
|
});
|
|
2662
|
-
} else if (pattern.type ===
|
|
2511
|
+
} else if (pattern.type === AST_NODE_TYPES33.ArrayPattern) {
|
|
2663
2512
|
pattern.elements.forEach((element) => {
|
|
2664
|
-
if (element?.type ===
|
|
2513
|
+
if (element?.type === AST_NODE_TYPES33.Identifier) {
|
|
2665
2514
|
checkIdentifier(element);
|
|
2666
|
-
} else if (element?.type ===
|
|
2515
|
+
} else if (element?.type === AST_NODE_TYPES33.RestElement && element.argument.type === AST_NODE_TYPES33.Identifier) {
|
|
2667
2516
|
checkIdentifier(element.argument);
|
|
2668
2517
|
}
|
|
2669
2518
|
});
|
|
2670
|
-
} else if (pattern.type ===
|
|
2519
|
+
} else if (pattern.type === AST_NODE_TYPES33.AssignmentPattern && pattern.left.type === AST_NODE_TYPES33.Identifier) {
|
|
2671
2520
|
checkIdentifier(pattern.left);
|
|
2672
|
-
} else if (pattern.type ===
|
|
2521
|
+
} else if (pattern.type === AST_NODE_TYPES33.RestElement && pattern.argument.type === AST_NODE_TYPES33.Identifier) {
|
|
2673
2522
|
checkIdentifier(pattern.argument);
|
|
2674
2523
|
}
|
|
2675
2524
|
};
|
|
@@ -2714,11 +2563,11 @@ var noLazyIdentifiers = createRule36({
|
|
|
2714
2563
|
var no_lazy_identifiers_default = noLazyIdentifiers;
|
|
2715
2564
|
|
|
2716
2565
|
// src/rules/no-logic-in-params.ts
|
|
2717
|
-
import { AST_NODE_TYPES as
|
|
2718
|
-
var
|
|
2566
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34, ESLintUtils as ESLintUtils34 } from "@typescript-eslint/utils";
|
|
2567
|
+
var createRule34 = ESLintUtils34.RuleCreator(
|
|
2719
2568
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2720
2569
|
);
|
|
2721
|
-
var noLogicInParams =
|
|
2570
|
+
var noLogicInParams = createRule34({
|
|
2722
2571
|
name: "no-logic-in-params",
|
|
2723
2572
|
meta: {
|
|
2724
2573
|
type: "suggestion",
|
|
@@ -2733,20 +2582,20 @@ var noLogicInParams = createRule37({
|
|
|
2733
2582
|
defaultOptions: [],
|
|
2734
2583
|
create(context) {
|
|
2735
2584
|
const isComplexExpression = (node) => {
|
|
2736
|
-
if (node.type ===
|
|
2585
|
+
if (node.type === AST_NODE_TYPES34.SpreadElement) {
|
|
2737
2586
|
return false;
|
|
2738
2587
|
}
|
|
2739
|
-
if (node.type ===
|
|
2588
|
+
if (node.type === AST_NODE_TYPES34.ConditionalExpression) {
|
|
2740
2589
|
return true;
|
|
2741
2590
|
}
|
|
2742
|
-
if (node.type ===
|
|
2591
|
+
if (node.type === AST_NODE_TYPES34.LogicalExpression) {
|
|
2743
2592
|
return true;
|
|
2744
2593
|
}
|
|
2745
|
-
if (node.type ===
|
|
2594
|
+
if (node.type === AST_NODE_TYPES34.BinaryExpression) {
|
|
2746
2595
|
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
2747
2596
|
return logicalOperators.includes(node.operator);
|
|
2748
2597
|
}
|
|
2749
|
-
if (node.type ===
|
|
2598
|
+
if (node.type === AST_NODE_TYPES34.UnaryExpression) {
|
|
2750
2599
|
return node.operator === "!";
|
|
2751
2600
|
}
|
|
2752
2601
|
return false;
|
|
@@ -2759,7 +2608,7 @@ var noLogicInParams = createRule37({
|
|
|
2759
2608
|
messageId: "noLogicInParams"
|
|
2760
2609
|
});
|
|
2761
2610
|
}
|
|
2762
|
-
if (arg.type ===
|
|
2611
|
+
if (arg.type === AST_NODE_TYPES34.ArrayExpression) {
|
|
2763
2612
|
arg.elements.forEach((element) => {
|
|
2764
2613
|
if (element && isComplexExpression(element)) {
|
|
2765
2614
|
context.report({
|
|
@@ -2784,46 +2633,46 @@ var noLogicInParams = createRule37({
|
|
|
2784
2633
|
var no_logic_in_params_default = noLogicInParams;
|
|
2785
2634
|
|
|
2786
2635
|
// src/rules/no-misleading-constant-case.ts
|
|
2787
|
-
import { AST_NODE_TYPES as
|
|
2788
|
-
var
|
|
2636
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35, ESLintUtils as ESLintUtils35 } from "@typescript-eslint/utils";
|
|
2637
|
+
var createRule35 = ESLintUtils35.RuleCreator(
|
|
2789
2638
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2790
2639
|
);
|
|
2791
2640
|
var SCREAMING_SNAKE_CASE_REGEX3 = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
2792
|
-
var isAsConstAssertion = (node) => node.type ===
|
|
2641
|
+
var isAsConstAssertion = (node) => node.type === AST_NODE_TYPES35.TSAsExpression && node.typeAnnotation.type === AST_NODE_TYPES35.TSTypeReference && node.typeAnnotation.typeName.type === AST_NODE_TYPES35.Identifier && node.typeAnnotation.typeName.name === "const";
|
|
2793
2642
|
var isStaticValue2 = (init) => {
|
|
2794
2643
|
if (isAsConstAssertion(init)) {
|
|
2795
2644
|
return true;
|
|
2796
2645
|
}
|
|
2797
|
-
if (init.type ===
|
|
2646
|
+
if (init.type === AST_NODE_TYPES35.Literal) {
|
|
2798
2647
|
return true;
|
|
2799
2648
|
}
|
|
2800
|
-
if (init.type ===
|
|
2649
|
+
if (init.type === AST_NODE_TYPES35.UnaryExpression && init.argument.type === AST_NODE_TYPES35.Literal) {
|
|
2801
2650
|
return true;
|
|
2802
2651
|
}
|
|
2803
|
-
if (init.type ===
|
|
2652
|
+
if (init.type === AST_NODE_TYPES35.TemplateLiteral && init.expressions.length === 0) {
|
|
2804
2653
|
return true;
|
|
2805
2654
|
}
|
|
2806
|
-
if (init.type ===
|
|
2807
|
-
return init.elements.every((el) => el !== null && el.type !==
|
|
2655
|
+
if (init.type === AST_NODE_TYPES35.ArrayExpression) {
|
|
2656
|
+
return init.elements.every((el) => el !== null && el.type !== AST_NODE_TYPES35.SpreadElement && isStaticValue2(el));
|
|
2808
2657
|
}
|
|
2809
|
-
if (init.type ===
|
|
2658
|
+
if (init.type === AST_NODE_TYPES35.ObjectExpression) {
|
|
2810
2659
|
return init.properties.every(
|
|
2811
|
-
(prop) => prop.type ===
|
|
2660
|
+
(prop) => prop.type === AST_NODE_TYPES35.Property && isStaticValue2(prop.value)
|
|
2812
2661
|
);
|
|
2813
2662
|
}
|
|
2814
2663
|
return false;
|
|
2815
2664
|
};
|
|
2816
2665
|
var isGlobalScope3 = (node) => {
|
|
2817
2666
|
const { parent } = node;
|
|
2818
|
-
if (parent.type ===
|
|
2667
|
+
if (parent.type === AST_NODE_TYPES35.Program) {
|
|
2819
2668
|
return true;
|
|
2820
2669
|
}
|
|
2821
|
-
if (parent.type ===
|
|
2670
|
+
if (parent.type === AST_NODE_TYPES35.ExportNamedDeclaration && parent.parent?.type === AST_NODE_TYPES35.Program) {
|
|
2822
2671
|
return true;
|
|
2823
2672
|
}
|
|
2824
2673
|
return false;
|
|
2825
2674
|
};
|
|
2826
|
-
var noMisleadingConstantCase =
|
|
2675
|
+
var noMisleadingConstantCase = createRule35({
|
|
2827
2676
|
name: "no-misleading-constant-case",
|
|
2828
2677
|
meta: {
|
|
2829
2678
|
type: "suggestion",
|
|
@@ -2842,7 +2691,7 @@ var noMisleadingConstantCase = createRule38({
|
|
|
2842
2691
|
return {
|
|
2843
2692
|
VariableDeclaration(node) {
|
|
2844
2693
|
node.declarations.forEach((declarator) => {
|
|
2845
|
-
if (declarator.id.type !==
|
|
2694
|
+
if (declarator.id.type !== AST_NODE_TYPES35.Identifier) {
|
|
2846
2695
|
return;
|
|
2847
2696
|
}
|
|
2848
2697
|
const { name } = declarator.id;
|
|
@@ -2883,11 +2732,11 @@ var noMisleadingConstantCase = createRule38({
|
|
|
2883
2732
|
var no_misleading_constant_case_default = noMisleadingConstantCase;
|
|
2884
2733
|
|
|
2885
2734
|
// src/rules/no-nested-interface-declaration.ts
|
|
2886
|
-
import { AST_NODE_TYPES as
|
|
2887
|
-
var
|
|
2735
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36, ESLintUtils as ESLintUtils36 } from "@typescript-eslint/utils";
|
|
2736
|
+
var createRule36 = ESLintUtils36.RuleCreator(
|
|
2888
2737
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2889
2738
|
);
|
|
2890
|
-
var noNestedInterfaceDeclaration =
|
|
2739
|
+
var noNestedInterfaceDeclaration = createRule36({
|
|
2891
2740
|
name: "no-nested-interface-declaration",
|
|
2892
2741
|
meta: {
|
|
2893
2742
|
type: "suggestion",
|
|
@@ -2908,15 +2757,15 @@ var noNestedInterfaceDeclaration = createRule39({
|
|
|
2908
2757
|
return;
|
|
2909
2758
|
}
|
|
2910
2759
|
const { typeAnnotation } = node.typeAnnotation;
|
|
2911
|
-
if (typeAnnotation.type ===
|
|
2760
|
+
if (typeAnnotation.type === AST_NODE_TYPES36.TSTypeLiteral) {
|
|
2912
2761
|
context.report({
|
|
2913
2762
|
node: typeAnnotation,
|
|
2914
2763
|
messageId: "noNestedInterface"
|
|
2915
2764
|
});
|
|
2916
2765
|
return;
|
|
2917
2766
|
}
|
|
2918
|
-
if (typeAnnotation.type ===
|
|
2919
|
-
if (typeAnnotation.elementType.type ===
|
|
2767
|
+
if (typeAnnotation.type === AST_NODE_TYPES36.TSArrayType) {
|
|
2768
|
+
if (typeAnnotation.elementType.type === AST_NODE_TYPES36.TSTypeLiteral) {
|
|
2920
2769
|
context.report({
|
|
2921
2770
|
node: typeAnnotation.elementType,
|
|
2922
2771
|
messageId: "noNestedInterface"
|
|
@@ -2924,9 +2773,9 @@ var noNestedInterfaceDeclaration = createRule39({
|
|
|
2924
2773
|
}
|
|
2925
2774
|
return;
|
|
2926
2775
|
}
|
|
2927
|
-
if (typeAnnotation.type ===
|
|
2776
|
+
if (typeAnnotation.type === AST_NODE_TYPES36.TSTypeReference && typeAnnotation.typeArguments) {
|
|
2928
2777
|
typeAnnotation.typeArguments.params.forEach((param) => {
|
|
2929
|
-
if (param.type ===
|
|
2778
|
+
if (param.type === AST_NODE_TYPES36.TSTypeLiteral) {
|
|
2930
2779
|
context.report({
|
|
2931
2780
|
node: param,
|
|
2932
2781
|
messageId: "noNestedInterface"
|
|
@@ -2941,11 +2790,11 @@ var noNestedInterfaceDeclaration = createRule39({
|
|
|
2941
2790
|
var no_nested_interface_declaration_default = noNestedInterfaceDeclaration;
|
|
2942
2791
|
|
|
2943
2792
|
// src/rules/no-nested-ternary.ts
|
|
2944
|
-
import { AST_NODE_TYPES as
|
|
2945
|
-
var
|
|
2793
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37, ESLintUtils as ESLintUtils37 } from "@typescript-eslint/utils";
|
|
2794
|
+
var createRule37 = ESLintUtils37.RuleCreator(
|
|
2946
2795
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2947
2796
|
);
|
|
2948
|
-
var noNestedTernary =
|
|
2797
|
+
var noNestedTernary = createRule37({
|
|
2949
2798
|
name: "no-nested-ternary",
|
|
2950
2799
|
meta: {
|
|
2951
2800
|
type: "suggestion",
|
|
@@ -2962,13 +2811,13 @@ var noNestedTernary = createRule40({
|
|
|
2962
2811
|
return {
|
|
2963
2812
|
ConditionalExpression(node) {
|
|
2964
2813
|
const { consequent, alternate } = node;
|
|
2965
|
-
if (consequent.type ===
|
|
2814
|
+
if (consequent.type === AST_NODE_TYPES37.ConditionalExpression) {
|
|
2966
2815
|
context.report({
|
|
2967
2816
|
node: consequent,
|
|
2968
2817
|
messageId: "noNestedTernary"
|
|
2969
2818
|
});
|
|
2970
2819
|
}
|
|
2971
|
-
if (alternate.type ===
|
|
2820
|
+
if (alternate.type === AST_NODE_TYPES37.ConditionalExpression) {
|
|
2972
2821
|
context.report({
|
|
2973
2822
|
node: alternate,
|
|
2974
2823
|
messageId: "noNestedTernary"
|
|
@@ -2980,12 +2829,86 @@ var noNestedTernary = createRule40({
|
|
|
2980
2829
|
});
|
|
2981
2830
|
var no_nested_ternary_default = noNestedTernary;
|
|
2982
2831
|
|
|
2832
|
+
// src/rules/no-redundant-fragment.ts
|
|
2833
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38, ESLintUtils as ESLintUtils38 } from "@typescript-eslint/utils";
|
|
2834
|
+
var createRule38 = ESLintUtils38.RuleCreator(
|
|
2835
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2836
|
+
);
|
|
2837
|
+
function isFragmentName(name) {
|
|
2838
|
+
if (name.type === AST_NODE_TYPES38.JSXIdentifier && name.name === "Fragment") {
|
|
2839
|
+
return true;
|
|
2840
|
+
}
|
|
2841
|
+
if (name.type === AST_NODE_TYPES38.JSXMemberExpression && name.object.type === AST_NODE_TYPES38.JSXIdentifier && name.object.name === "React" && name.property.type === AST_NODE_TYPES38.JSXIdentifier && name.property.name === "Fragment") {
|
|
2842
|
+
return true;
|
|
2843
|
+
}
|
|
2844
|
+
return false;
|
|
2845
|
+
}
|
|
2846
|
+
function hasKeyAttribute(attributes) {
|
|
2847
|
+
return attributes.some(
|
|
2848
|
+
(attribute) => attribute.type === AST_NODE_TYPES38.JSXAttribute && attribute.name.type === AST_NODE_TYPES38.JSXIdentifier && attribute.name.name === "key"
|
|
2849
|
+
);
|
|
2850
|
+
}
|
|
2851
|
+
function countMeaningfulChildren(children) {
|
|
2852
|
+
return children.filter((child) => {
|
|
2853
|
+
if (child.type === AST_NODE_TYPES38.JSXText) {
|
|
2854
|
+
return child.value.trim() !== "";
|
|
2855
|
+
}
|
|
2856
|
+
return true;
|
|
2857
|
+
}).length;
|
|
2858
|
+
}
|
|
2859
|
+
var noRedundantFragment = createRule38({
|
|
2860
|
+
name: "no-redundant-fragment",
|
|
2861
|
+
meta: {
|
|
2862
|
+
type: "problem",
|
|
2863
|
+
docs: {
|
|
2864
|
+
description: "Disallow Fragments that wrap zero or one child (unless a key prop is needed)"
|
|
2865
|
+
},
|
|
2866
|
+
schema: [],
|
|
2867
|
+
messages: {
|
|
2868
|
+
redundantFragment: "Fragment is redundant when wrapping {{ count }} child. Remove the Fragment or replace it with the child directly."
|
|
2869
|
+
}
|
|
2870
|
+
},
|
|
2871
|
+
defaultOptions: [],
|
|
2872
|
+
create(context) {
|
|
2873
|
+
return {
|
|
2874
|
+
JSXFragment(node) {
|
|
2875
|
+
const count = countMeaningfulChildren(node.children);
|
|
2876
|
+
if (count <= 1) {
|
|
2877
|
+
context.report({
|
|
2878
|
+
node,
|
|
2879
|
+
messageId: "redundantFragment",
|
|
2880
|
+
data: { count: String(count) }
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2883
|
+
},
|
|
2884
|
+
JSXElement(node) {
|
|
2885
|
+
const opening = node.openingElement;
|
|
2886
|
+
if (!isFragmentName(opening.name)) {
|
|
2887
|
+
return;
|
|
2888
|
+
}
|
|
2889
|
+
if (hasKeyAttribute(opening.attributes)) {
|
|
2890
|
+
return;
|
|
2891
|
+
}
|
|
2892
|
+
const count = countMeaningfulChildren(node.children);
|
|
2893
|
+
if (count <= 1) {
|
|
2894
|
+
context.report({
|
|
2895
|
+
node,
|
|
2896
|
+
messageId: "redundantFragment",
|
|
2897
|
+
data: { count: String(count) }
|
|
2898
|
+
});
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
};
|
|
2902
|
+
}
|
|
2903
|
+
});
|
|
2904
|
+
var no_redundant_fragment_default = noRedundantFragment;
|
|
2905
|
+
|
|
2983
2906
|
// src/rules/no-relative-imports.ts
|
|
2984
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES39, ESLintUtils as
|
|
2985
|
-
var
|
|
2907
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39, ESLintUtils as ESLintUtils39 } from "@typescript-eslint/utils";
|
|
2908
|
+
var createRule39 = ESLintUtils39.RuleCreator(
|
|
2986
2909
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2987
2910
|
);
|
|
2988
|
-
var noRelativeImports =
|
|
2911
|
+
var noRelativeImports = createRule39({
|
|
2989
2912
|
name: "no-relative-imports",
|
|
2990
2913
|
meta: {
|
|
2991
2914
|
type: "suggestion",
|
|
@@ -3034,8 +2957,8 @@ var noRelativeImports = createRule41({
|
|
|
3034
2957
|
var no_relative_imports_default = noRelativeImports;
|
|
3035
2958
|
|
|
3036
2959
|
// src/rules/no-single-char-variables.ts
|
|
3037
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES40, ESLintUtils as
|
|
3038
|
-
var
|
|
2960
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40, ESLintUtils as ESLintUtils40 } from "@typescript-eslint/utils";
|
|
2961
|
+
var createRule40 = ESLintUtils40.RuleCreator(
|
|
3039
2962
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3040
2963
|
);
|
|
3041
2964
|
var ALLOWED_IN_FOR_LOOPS = /* @__PURE__ */ new Set(["i", "j", "k", "n"]);
|
|
@@ -3066,7 +2989,7 @@ var isAllowedInContext = (name, node) => {
|
|
|
3066
2989
|
}
|
|
3067
2990
|
return false;
|
|
3068
2991
|
};
|
|
3069
|
-
var noSingleCharVariables =
|
|
2992
|
+
var noSingleCharVariables = createRule40({
|
|
3070
2993
|
name: "no-single-char-variables",
|
|
3071
2994
|
meta: {
|
|
3072
2995
|
type: "suggestion",
|
|
@@ -3149,11 +3072,11 @@ var noSingleCharVariables = createRule42({
|
|
|
3149
3072
|
var no_single_char_variables_default = noSingleCharVariables;
|
|
3150
3073
|
|
|
3151
3074
|
// src/rules/prefer-async-await.ts
|
|
3152
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES41, ESLintUtils as
|
|
3153
|
-
var
|
|
3075
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41, ESLintUtils as ESLintUtils41 } from "@typescript-eslint/utils";
|
|
3076
|
+
var createRule41 = ESLintUtils41.RuleCreator(
|
|
3154
3077
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3155
3078
|
);
|
|
3156
|
-
var preferAsyncAwait =
|
|
3079
|
+
var preferAsyncAwait = createRule41({
|
|
3157
3080
|
name: "prefer-async-await",
|
|
3158
3081
|
meta: {
|
|
3159
3082
|
type: "suggestion",
|
|
@@ -3182,11 +3105,11 @@ var preferAsyncAwait = createRule43({
|
|
|
3182
3105
|
var prefer_async_await_default = preferAsyncAwait;
|
|
3183
3106
|
|
|
3184
3107
|
// src/rules/prefer-destructuring-params.ts
|
|
3185
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES42, ESLintUtils as
|
|
3186
|
-
var
|
|
3108
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42, ESLintUtils as ESLintUtils42 } from "@typescript-eslint/utils";
|
|
3109
|
+
var createRule42 = ESLintUtils42.RuleCreator(
|
|
3187
3110
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3188
3111
|
);
|
|
3189
|
-
var preferDestructuringParams =
|
|
3112
|
+
var preferDestructuringParams = createRule42({
|
|
3190
3113
|
name: "prefer-destructuring-params",
|
|
3191
3114
|
meta: {
|
|
3192
3115
|
type: "suggestion",
|
|
@@ -3254,8 +3177,8 @@ var preferDestructuringParams = createRule44({
|
|
|
3254
3177
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
3255
3178
|
|
|
3256
3179
|
// src/rules/prefer-function-declaration.ts
|
|
3257
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES43, ESLintUtils as
|
|
3258
|
-
var
|
|
3180
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43, ESLintUtils as ESLintUtils43 } from "@typescript-eslint/utils";
|
|
3181
|
+
var createRule43 = ESLintUtils43.RuleCreator(
|
|
3259
3182
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3260
3183
|
);
|
|
3261
3184
|
var isTsFile = (filename) => filename.endsWith(".ts") && !filename.endsWith(".d.ts");
|
|
@@ -3290,7 +3213,7 @@ var isCallbackContext = (node) => {
|
|
|
3290
3213
|
}
|
|
3291
3214
|
return false;
|
|
3292
3215
|
};
|
|
3293
|
-
var preferFunctionDeclaration =
|
|
3216
|
+
var preferFunctionDeclaration = createRule43({
|
|
3294
3217
|
name: "prefer-function-declaration",
|
|
3295
3218
|
meta: {
|
|
3296
3219
|
type: "suggestion",
|
|
@@ -3345,11 +3268,11 @@ var preferFunctionDeclaration = createRule45({
|
|
|
3345
3268
|
var prefer_function_declaration_default = preferFunctionDeclaration;
|
|
3346
3269
|
|
|
3347
3270
|
// src/rules/prefer-guard-clause.ts
|
|
3348
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES44, ESLintUtils as
|
|
3349
|
-
var
|
|
3271
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44, ESLintUtils as ESLintUtils44 } from "@typescript-eslint/utils";
|
|
3272
|
+
var createRule44 = ESLintUtils44.RuleCreator(
|
|
3350
3273
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3351
3274
|
);
|
|
3352
|
-
var preferGuardClause =
|
|
3275
|
+
var preferGuardClause = createRule44({
|
|
3353
3276
|
name: "prefer-guard-clause",
|
|
3354
3277
|
meta: {
|
|
3355
3278
|
type: "suggestion",
|
|
@@ -3388,11 +3311,11 @@ var preferGuardClause = createRule46({
|
|
|
3388
3311
|
var prefer_guard_clause_default = preferGuardClause;
|
|
3389
3312
|
|
|
3390
3313
|
// src/rules/prefer-import-type.ts
|
|
3391
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES45, ESLintUtils as
|
|
3392
|
-
var
|
|
3314
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45, ESLintUtils as ESLintUtils45 } from "@typescript-eslint/utils";
|
|
3315
|
+
var createRule45 = ESLintUtils45.RuleCreator(
|
|
3393
3316
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3394
3317
|
);
|
|
3395
|
-
var preferImportType =
|
|
3318
|
+
var preferImportType = createRule45({
|
|
3396
3319
|
name: "prefer-import-type",
|
|
3397
3320
|
meta: {
|
|
3398
3321
|
type: "suggestion",
|
|
@@ -3487,6 +3410,12 @@ var preferImportType = createRule47({
|
|
|
3487
3410
|
if (node.importKind === "type") {
|
|
3488
3411
|
return;
|
|
3489
3412
|
}
|
|
3413
|
+
const hasInlineTypeSpecifier = node.specifiers.some(
|
|
3414
|
+
(specifier) => specifier.type === AST_NODE_TYPES45.ImportSpecifier && specifier.importKind === "type"
|
|
3415
|
+
);
|
|
3416
|
+
if (hasInlineTypeSpecifier) {
|
|
3417
|
+
return;
|
|
3418
|
+
}
|
|
3490
3419
|
if (context.filename.includes(".test.") || context.filename.includes(".spec.") || context.filename.includes("__tests__")) {
|
|
3491
3420
|
return;
|
|
3492
3421
|
}
|
|
@@ -3532,8 +3461,8 @@ var preferImportType = createRule47({
|
|
|
3532
3461
|
var prefer_import_type_default = preferImportType;
|
|
3533
3462
|
|
|
3534
3463
|
// src/rules/prefer-inline-literal-union.ts
|
|
3535
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES46, ESLintUtils as
|
|
3536
|
-
var
|
|
3464
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46, ESLintUtils as ESLintUtils46 } from "@typescript-eslint/utils";
|
|
3465
|
+
var createRule46 = ESLintUtils46.RuleCreator(
|
|
3537
3466
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3538
3467
|
);
|
|
3539
3468
|
function isLiteralUnionType(node) {
|
|
@@ -3544,7 +3473,7 @@ function isLiteralUnionType(node) {
|
|
|
3544
3473
|
(member) => member.type === AST_NODE_TYPES46.TSLiteralType || member.type === AST_NODE_TYPES46.TSNullKeyword || member.type === AST_NODE_TYPES46.TSUndefinedKeyword
|
|
3545
3474
|
);
|
|
3546
3475
|
}
|
|
3547
|
-
var preferInlineLiteralUnion =
|
|
3476
|
+
var preferInlineLiteralUnion = createRule46({
|
|
3548
3477
|
name: "prefer-inline-literal-union",
|
|
3549
3478
|
meta: {
|
|
3550
3479
|
type: "suggestion",
|
|
@@ -3598,12 +3527,12 @@ var preferInlineLiteralUnion = createRule48({
|
|
|
3598
3527
|
var prefer_inline_literal_union_default = preferInlineLiteralUnion;
|
|
3599
3528
|
|
|
3600
3529
|
// src/rules/prefer-inline-type-export.ts
|
|
3601
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES47, ESLintUtils as
|
|
3602
|
-
var
|
|
3530
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47, ESLintUtils as ESLintUtils47 } from "@typescript-eslint/utils";
|
|
3531
|
+
var createRule47 = ESLintUtils47.RuleCreator(
|
|
3603
3532
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3604
3533
|
);
|
|
3605
3534
|
var isTypeDeclaration = (node) => node.type === AST_NODE_TYPES47.TSInterfaceDeclaration || node.type === AST_NODE_TYPES47.TSTypeAliasDeclaration;
|
|
3606
|
-
var preferInlineTypeExport =
|
|
3535
|
+
var preferInlineTypeExport = createRule47({
|
|
3607
3536
|
name: "prefer-inline-type-export",
|
|
3608
3537
|
meta: {
|
|
3609
3538
|
type: "suggestion",
|
|
@@ -3683,12 +3612,69 @@ var preferInlineTypeExport = createRule49({
|
|
|
3683
3612
|
});
|
|
3684
3613
|
var prefer_inline_type_export_default = preferInlineTypeExport;
|
|
3685
3614
|
|
|
3615
|
+
// src/rules/prefer-interface-for-component-props.ts
|
|
3616
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48, ESLintUtils as ESLintUtils48 } from "@typescript-eslint/utils";
|
|
3617
|
+
var createRule48 = ESLintUtils48.RuleCreator(
|
|
3618
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3619
|
+
);
|
|
3620
|
+
var preferInterfaceForComponentProps = createRule48({
|
|
3621
|
+
name: "prefer-interface-for-component-props",
|
|
3622
|
+
meta: {
|
|
3623
|
+
type: "suggestion",
|
|
3624
|
+
docs: {
|
|
3625
|
+
description: "Enforce 'interface' over 'type' alias for component prop declarations in component files (*.tsx, *.jsx)"
|
|
3626
|
+
},
|
|
3627
|
+
fixable: "code",
|
|
3628
|
+
schema: [],
|
|
3629
|
+
messages: {
|
|
3630
|
+
preferInterface: "Component props '{{ name }}' should use 'interface' instead of 'type' alias."
|
|
3631
|
+
}
|
|
3632
|
+
},
|
|
3633
|
+
defaultOptions: [],
|
|
3634
|
+
create(context) {
|
|
3635
|
+
if (!isJsxFile(context.filename)) {
|
|
3636
|
+
return {};
|
|
3637
|
+
}
|
|
3638
|
+
return {
|
|
3639
|
+
TSTypeAliasDeclaration(node) {
|
|
3640
|
+
if (node.id.type !== AST_NODE_TYPES48.Identifier) {
|
|
3641
|
+
return;
|
|
3642
|
+
}
|
|
3643
|
+
if (!node.id.name.endsWith("Props")) {
|
|
3644
|
+
return;
|
|
3645
|
+
}
|
|
3646
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES48.TSTypeLiteral) {
|
|
3647
|
+
return;
|
|
3648
|
+
}
|
|
3649
|
+
const { name } = node.id;
|
|
3650
|
+
context.report({
|
|
3651
|
+
node: node.id,
|
|
3652
|
+
messageId: "preferInterface",
|
|
3653
|
+
data: { name },
|
|
3654
|
+
fix(fixer) {
|
|
3655
|
+
const { sourceCode } = context;
|
|
3656
|
+
const typeText = sourceCode.getText(node.typeAnnotation);
|
|
3657
|
+
const typeParamsText = node.typeParameters ? sourceCode.getText(node.typeParameters) : "";
|
|
3658
|
+
const newText = `interface ${name}${typeParamsText} ${typeText}`;
|
|
3659
|
+
const tokenAfter = sourceCode.getTokenAfter(node);
|
|
3660
|
+
if (tokenAfter && tokenAfter.value === ";") {
|
|
3661
|
+
return fixer.replaceTextRange([node.range[0], tokenAfter.range[1]], newText);
|
|
3662
|
+
}
|
|
3663
|
+
return fixer.replaceText(node, newText);
|
|
3664
|
+
}
|
|
3665
|
+
});
|
|
3666
|
+
}
|
|
3667
|
+
};
|
|
3668
|
+
}
|
|
3669
|
+
});
|
|
3670
|
+
var prefer_interface_for_component_props_default = preferInterfaceForComponentProps;
|
|
3671
|
+
|
|
3686
3672
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
3687
|
-
import { AST_NODE_TYPES as
|
|
3688
|
-
var
|
|
3673
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49, ESLintUtils as ESLintUtils49 } from "@typescript-eslint/utils";
|
|
3674
|
+
var createRule49 = ESLintUtils49.RuleCreator(
|
|
3689
3675
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3690
3676
|
);
|
|
3691
|
-
var preferInterfaceOverInlineTypes =
|
|
3677
|
+
var preferInterfaceOverInlineTypes = createRule49({
|
|
3692
3678
|
name: "prefer-interface-over-inline-types",
|
|
3693
3679
|
meta: {
|
|
3694
3680
|
type: "suggestion",
|
|
@@ -3704,54 +3690,54 @@ var preferInterfaceOverInlineTypes = createRule50({
|
|
|
3704
3690
|
defaultOptions: [],
|
|
3705
3691
|
create(context) {
|
|
3706
3692
|
function hasJSXInConditional(node) {
|
|
3707
|
-
return node.consequent.type ===
|
|
3693
|
+
return node.consequent.type === AST_NODE_TYPES49.JSXElement || node.consequent.type === AST_NODE_TYPES49.JSXFragment || node.alternate.type === AST_NODE_TYPES49.JSXElement || node.alternate.type === AST_NODE_TYPES49.JSXFragment;
|
|
3708
3694
|
}
|
|
3709
3695
|
function hasJSXInLogical(node) {
|
|
3710
|
-
return node.right.type ===
|
|
3696
|
+
return node.right.type === AST_NODE_TYPES49.JSXElement || node.right.type === AST_NODE_TYPES49.JSXFragment;
|
|
3711
3697
|
}
|
|
3712
3698
|
function hasJSXReturn(block) {
|
|
3713
3699
|
return block.body.some((stmt) => {
|
|
3714
|
-
if (stmt.type ===
|
|
3715
|
-
return stmt.argument.type ===
|
|
3700
|
+
if (stmt.type === AST_NODE_TYPES49.ReturnStatement && stmt.argument) {
|
|
3701
|
+
return stmt.argument.type === AST_NODE_TYPES49.JSXElement || stmt.argument.type === AST_NODE_TYPES49.JSXFragment || stmt.argument.type === AST_NODE_TYPES49.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES49.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
3716
3702
|
}
|
|
3717
3703
|
return false;
|
|
3718
3704
|
});
|
|
3719
3705
|
}
|
|
3720
3706
|
function isReactComponent2(node) {
|
|
3721
|
-
if (node.type ===
|
|
3722
|
-
if (node.body.type ===
|
|
3707
|
+
if (node.type === AST_NODE_TYPES49.ArrowFunctionExpression) {
|
|
3708
|
+
if (node.body.type === AST_NODE_TYPES49.JSXElement || node.body.type === AST_NODE_TYPES49.JSXFragment) {
|
|
3723
3709
|
return true;
|
|
3724
3710
|
}
|
|
3725
|
-
if (node.body.type ===
|
|
3711
|
+
if (node.body.type === AST_NODE_TYPES49.BlockStatement) {
|
|
3726
3712
|
return hasJSXReturn(node.body);
|
|
3727
3713
|
}
|
|
3728
|
-
} else if (node.type ===
|
|
3729
|
-
if (node.body && node.body.type ===
|
|
3714
|
+
} else if (node.type === AST_NODE_TYPES49.FunctionExpression || node.type === AST_NODE_TYPES49.FunctionDeclaration) {
|
|
3715
|
+
if (node.body && node.body.type === AST_NODE_TYPES49.BlockStatement) {
|
|
3730
3716
|
return hasJSXReturn(node.body);
|
|
3731
3717
|
}
|
|
3732
3718
|
}
|
|
3733
3719
|
return false;
|
|
3734
3720
|
}
|
|
3735
3721
|
function isInlineTypeAnnotation(node) {
|
|
3736
|
-
if (node.type ===
|
|
3722
|
+
if (node.type === AST_NODE_TYPES49.TSTypeLiteral) {
|
|
3737
3723
|
return true;
|
|
3738
3724
|
}
|
|
3739
|
-
if (node.type ===
|
|
3740
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3725
|
+
if (node.type === AST_NODE_TYPES49.TSTypeReference && node.typeArguments) {
|
|
3726
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES49.TSTypeLiteral);
|
|
3741
3727
|
}
|
|
3742
|
-
if (node.type ===
|
|
3728
|
+
if (node.type === AST_NODE_TYPES49.TSUnionType) {
|
|
3743
3729
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
3744
3730
|
}
|
|
3745
3731
|
return false;
|
|
3746
3732
|
}
|
|
3747
3733
|
function hasInlineObjectType(node) {
|
|
3748
|
-
if (node.type ===
|
|
3734
|
+
if (node.type === AST_NODE_TYPES49.TSTypeLiteral) {
|
|
3749
3735
|
return true;
|
|
3750
3736
|
}
|
|
3751
|
-
if (node.type ===
|
|
3752
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3737
|
+
if (node.type === AST_NODE_TYPES49.TSTypeReference && node.typeArguments) {
|
|
3738
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES49.TSTypeLiteral);
|
|
3753
3739
|
}
|
|
3754
|
-
if (node.type ===
|
|
3740
|
+
if (node.type === AST_NODE_TYPES49.TSUnionType) {
|
|
3755
3741
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
3756
3742
|
}
|
|
3757
3743
|
return false;
|
|
@@ -3764,7 +3750,7 @@ var preferInterfaceOverInlineTypes = createRule50({
|
|
|
3764
3750
|
return;
|
|
3765
3751
|
}
|
|
3766
3752
|
const param = node.params[0];
|
|
3767
|
-
if (param.type ===
|
|
3753
|
+
if (param.type === AST_NODE_TYPES49.Identifier && param.typeAnnotation) {
|
|
3768
3754
|
const { typeAnnotation } = param.typeAnnotation;
|
|
3769
3755
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
3770
3756
|
context.report({
|
|
@@ -3784,11 +3770,11 @@ var preferInterfaceOverInlineTypes = createRule50({
|
|
|
3784
3770
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
3785
3771
|
|
|
3786
3772
|
// src/rules/prefer-jsx-template-literals.ts
|
|
3787
|
-
import { AST_NODE_TYPES as
|
|
3788
|
-
var
|
|
3773
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50, ESLintUtils as ESLintUtils50 } from "@typescript-eslint/utils";
|
|
3774
|
+
var createRule50 = ESLintUtils50.RuleCreator(
|
|
3789
3775
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3790
3776
|
);
|
|
3791
|
-
var preferJSXTemplateLiterals =
|
|
3777
|
+
var preferJSXTemplateLiterals = createRule50({
|
|
3792
3778
|
name: "prefer-jsx-template-literals",
|
|
3793
3779
|
meta: {
|
|
3794
3780
|
type: "suggestion",
|
|
@@ -3857,9 +3843,9 @@ var preferJSXTemplateLiterals = createRule51({
|
|
|
3857
3843
|
if (!child || !nextChild) {
|
|
3858
3844
|
return;
|
|
3859
3845
|
}
|
|
3860
|
-
if (child.type ===
|
|
3846
|
+
if (child.type === AST_NODE_TYPES50.JSXText && nextChild.type === AST_NODE_TYPES50.JSXExpressionContainer) {
|
|
3861
3847
|
handleTextBeforeExpression(child, nextChild);
|
|
3862
|
-
} else if (child.type ===
|
|
3848
|
+
} else if (child.type === AST_NODE_TYPES50.JSXExpressionContainer && nextChild.type === AST_NODE_TYPES50.JSXText) {
|
|
3863
3849
|
handleExpressionBeforeText(child, nextChild);
|
|
3864
3850
|
}
|
|
3865
3851
|
}
|
|
@@ -3872,11 +3858,32 @@ var preferJSXTemplateLiterals = createRule51({
|
|
|
3872
3858
|
var prefer_jsx_template_literals_default = preferJSXTemplateLiterals;
|
|
3873
3859
|
|
|
3874
3860
|
// src/rules/prefer-named-param-types.ts
|
|
3875
|
-
import { AST_NODE_TYPES as
|
|
3876
|
-
var
|
|
3861
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ESLintUtils as ESLintUtils51 } from "@typescript-eslint/utils";
|
|
3862
|
+
var createRule51 = ESLintUtils51.RuleCreator(
|
|
3877
3863
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3878
3864
|
);
|
|
3879
|
-
var
|
|
3865
|
+
var returnsJsx2 = (node) => {
|
|
3866
|
+
if (node.type === AST_NODE_TYPES51.JSXElement || node.type === AST_NODE_TYPES51.JSXFragment) {
|
|
3867
|
+
return true;
|
|
3868
|
+
}
|
|
3869
|
+
if (node.type === AST_NODE_TYPES51.ConditionalExpression) {
|
|
3870
|
+
return returnsJsx2(node.consequent) || returnsJsx2(node.alternate);
|
|
3871
|
+
}
|
|
3872
|
+
if (node.type === AST_NODE_TYPES51.LogicalExpression) {
|
|
3873
|
+
return returnsJsx2(node.left) || returnsJsx2(node.right);
|
|
3874
|
+
}
|
|
3875
|
+
return false;
|
|
3876
|
+
};
|
|
3877
|
+
var bodyReturnsJsx2 = (body) => {
|
|
3878
|
+
if (body.type !== AST_NODE_TYPES51.BlockStatement) {
|
|
3879
|
+
return returnsJsx2(body);
|
|
3880
|
+
}
|
|
3881
|
+
return body.body.some(
|
|
3882
|
+
(stmt) => stmt.type === AST_NODE_TYPES51.ReturnStatement && stmt.argument !== null && returnsJsx2(stmt.argument)
|
|
3883
|
+
);
|
|
3884
|
+
};
|
|
3885
|
+
var isReactComponentFunction = (node) => bodyReturnsJsx2(node.body);
|
|
3886
|
+
var preferNamedParamTypes = createRule51({
|
|
3880
3887
|
name: "prefer-named-param-types",
|
|
3881
3888
|
meta: {
|
|
3882
3889
|
type: "suggestion",
|
|
@@ -3891,16 +3898,16 @@ var preferNamedParamTypes = createRule52({
|
|
|
3891
3898
|
defaultOptions: [],
|
|
3892
3899
|
create(context) {
|
|
3893
3900
|
function hasInlineObjectType(param) {
|
|
3894
|
-
if (param.type ===
|
|
3901
|
+
if (param.type === AST_NODE_TYPES51.AssignmentPattern) {
|
|
3895
3902
|
return hasInlineObjectType(param.left);
|
|
3896
3903
|
}
|
|
3897
|
-
if (param.type ===
|
|
3898
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3904
|
+
if (param.type === AST_NODE_TYPES51.ObjectPattern) {
|
|
3905
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES51.TSTypeLiteral) {
|
|
3899
3906
|
return true;
|
|
3900
3907
|
}
|
|
3901
3908
|
}
|
|
3902
|
-
if (param.type ===
|
|
3903
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3909
|
+
if (param.type === AST_NODE_TYPES51.Identifier) {
|
|
3910
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES51.TSTypeLiteral) {
|
|
3904
3911
|
return true;
|
|
3905
3912
|
}
|
|
3906
3913
|
}
|
|
@@ -3913,6 +3920,9 @@ var preferNamedParamTypes = createRule52({
|
|
|
3913
3920
|
} else if ("value" in node && node.value) {
|
|
3914
3921
|
params = node.value.params;
|
|
3915
3922
|
}
|
|
3923
|
+
if ((node.type === AST_NODE_TYPES51.FunctionDeclaration || node.type === AST_NODE_TYPES51.FunctionExpression || node.type === AST_NODE_TYPES51.ArrowFunctionExpression) && params.length === 1 && params[0].type === AST_NODE_TYPES51.Identifier && isReactComponentFunction(node)) {
|
|
3924
|
+
return;
|
|
3925
|
+
}
|
|
3916
3926
|
params.forEach((param) => {
|
|
3917
3927
|
if (hasInlineObjectType(param)) {
|
|
3918
3928
|
context.report({
|
|
@@ -3933,8 +3943,87 @@ var preferNamedParamTypes = createRule52({
|
|
|
3933
3943
|
});
|
|
3934
3944
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
3935
3945
|
|
|
3946
|
+
// src/rules/prefer-props-with-children.ts
|
|
3947
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES52, ESLintUtils as ESLintUtils52 } from "@typescript-eslint/utils";
|
|
3948
|
+
var createRule52 = ESLintUtils52.RuleCreator(
|
|
3949
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3950
|
+
);
|
|
3951
|
+
var preferPropsWithChildren = createRule52({
|
|
3952
|
+
name: "prefer-props-with-children",
|
|
3953
|
+
meta: {
|
|
3954
|
+
type: "suggestion",
|
|
3955
|
+
docs: {
|
|
3956
|
+
description: "Prefer PropsWithChildren<T> over manually declaring children: ReactNode in component props"
|
|
3957
|
+
},
|
|
3958
|
+
schema: [],
|
|
3959
|
+
messages: {
|
|
3960
|
+
usePropsWithChildren: "Use 'PropsWithChildren<T>' instead of manually declaring 'children: ReactNode'."
|
|
3961
|
+
}
|
|
3962
|
+
},
|
|
3963
|
+
defaultOptions: [],
|
|
3964
|
+
create(context) {
|
|
3965
|
+
function isReactNodeType(typeNode) {
|
|
3966
|
+
if (!typeNode) {
|
|
3967
|
+
return false;
|
|
3968
|
+
}
|
|
3969
|
+
if (typeNode.type !== AST_NODE_TYPES52.TSTypeReference) {
|
|
3970
|
+
return false;
|
|
3971
|
+
}
|
|
3972
|
+
const { typeName } = typeNode;
|
|
3973
|
+
if (typeName.type === AST_NODE_TYPES52.Identifier) {
|
|
3974
|
+
return typeName.name === "ReactNode";
|
|
3975
|
+
}
|
|
3976
|
+
if (typeName.type === AST_NODE_TYPES52.TSQualifiedName && typeName.left.type === AST_NODE_TYPES52.Identifier && typeName.left.name === "React" && typeName.right.type === AST_NODE_TYPES52.Identifier && typeName.right.name === "ReactNode") {
|
|
3977
|
+
return true;
|
|
3978
|
+
}
|
|
3979
|
+
return false;
|
|
3980
|
+
}
|
|
3981
|
+
function findChildrenReactNode(members) {
|
|
3982
|
+
for (const member of members) {
|
|
3983
|
+
if (member.type !== AST_NODE_TYPES52.TSPropertySignature) {
|
|
3984
|
+
continue;
|
|
3985
|
+
}
|
|
3986
|
+
if (member.key.type !== AST_NODE_TYPES52.Identifier) {
|
|
3987
|
+
continue;
|
|
3988
|
+
}
|
|
3989
|
+
if (member.key.name !== "children") {
|
|
3990
|
+
continue;
|
|
3991
|
+
}
|
|
3992
|
+
if (!member.typeAnnotation) {
|
|
3993
|
+
continue;
|
|
3994
|
+
}
|
|
3995
|
+
if (isReactNodeType(member.typeAnnotation.typeAnnotation)) {
|
|
3996
|
+
return member;
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
return void 0;
|
|
4000
|
+
}
|
|
4001
|
+
return {
|
|
4002
|
+
TSInterfaceDeclaration(node) {
|
|
4003
|
+
const childrenMember = findChildrenReactNode(node.body.body);
|
|
4004
|
+
if (childrenMember) {
|
|
4005
|
+
context.report({
|
|
4006
|
+
node: childrenMember,
|
|
4007
|
+
messageId: "usePropsWithChildren"
|
|
4008
|
+
});
|
|
4009
|
+
}
|
|
4010
|
+
},
|
|
4011
|
+
TSTypeLiteral(node) {
|
|
4012
|
+
const childrenMember = findChildrenReactNode(node.members);
|
|
4013
|
+
if (childrenMember) {
|
|
4014
|
+
context.report({
|
|
4015
|
+
node: childrenMember,
|
|
4016
|
+
messageId: "usePropsWithChildren"
|
|
4017
|
+
});
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
};
|
|
4021
|
+
}
|
|
4022
|
+
});
|
|
4023
|
+
var prefer_props_with_children_default = preferPropsWithChildren;
|
|
4024
|
+
|
|
3936
4025
|
// src/rules/prefer-react-import-types.ts
|
|
3937
|
-
import { AST_NODE_TYPES as
|
|
4026
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES53, ESLintUtils as ESLintUtils53 } from "@typescript-eslint/utils";
|
|
3938
4027
|
var createRule53 = ESLintUtils53.RuleCreator(
|
|
3939
4028
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3940
4029
|
);
|
|
@@ -4014,7 +4103,7 @@ var preferReactImportTypes = createRule53({
|
|
|
4014
4103
|
]);
|
|
4015
4104
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
4016
4105
|
function checkMemberExpression(node) {
|
|
4017
|
-
if (node.object.type ===
|
|
4106
|
+
if (node.object.type === AST_NODE_TYPES53.Identifier && node.object.name === "React" && node.property.type === AST_NODE_TYPES53.Identifier && allReactExports.has(node.property.name)) {
|
|
4018
4107
|
const typeName = node.property.name;
|
|
4019
4108
|
const isType = reactTypes.has(typeName);
|
|
4020
4109
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -4031,7 +4120,7 @@ var preferReactImportTypes = createRule53({
|
|
|
4031
4120
|
return {
|
|
4032
4121
|
MemberExpression: checkMemberExpression,
|
|
4033
4122
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
4034
|
-
if (node.left.type ===
|
|
4123
|
+
if (node.left.type === AST_NODE_TYPES53.Identifier && node.left.name === "React" && node.right.type === AST_NODE_TYPES53.Identifier && allReactExports.has(node.right.name)) {
|
|
4035
4124
|
const typeName = node.right.name;
|
|
4036
4125
|
const isType = reactTypes.has(typeName);
|
|
4037
4126
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -4051,7 +4140,7 @@ var preferReactImportTypes = createRule53({
|
|
|
4051
4140
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
4052
4141
|
|
|
4053
4142
|
// src/rules/react-props-destructure.ts
|
|
4054
|
-
import { AST_NODE_TYPES as
|
|
4143
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES54, ESLintUtils as ESLintUtils54 } from "@typescript-eslint/utils";
|
|
4055
4144
|
var createRule54 = ESLintUtils54.RuleCreator(
|
|
4056
4145
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4057
4146
|
);
|
|
@@ -4071,29 +4160,29 @@ var reactPropsDestructure = createRule54({
|
|
|
4071
4160
|
defaultOptions: [],
|
|
4072
4161
|
create(context) {
|
|
4073
4162
|
function hasJSXInConditional(node) {
|
|
4074
|
-
return node.consequent.type ===
|
|
4163
|
+
return node.consequent.type === AST_NODE_TYPES54.JSXElement || node.consequent.type === AST_NODE_TYPES54.JSXFragment || node.alternate.type === AST_NODE_TYPES54.JSXElement || node.alternate.type === AST_NODE_TYPES54.JSXFragment;
|
|
4075
4164
|
}
|
|
4076
4165
|
function hasJSXInLogical(node) {
|
|
4077
|
-
return node.right.type ===
|
|
4166
|
+
return node.right.type === AST_NODE_TYPES54.JSXElement || node.right.type === AST_NODE_TYPES54.JSXFragment;
|
|
4078
4167
|
}
|
|
4079
4168
|
function hasJSXReturn(block) {
|
|
4080
4169
|
return block.body.some((stmt) => {
|
|
4081
|
-
if (stmt.type ===
|
|
4082
|
-
return stmt.argument.type ===
|
|
4170
|
+
if (stmt.type === AST_NODE_TYPES54.ReturnStatement && stmt.argument) {
|
|
4171
|
+
return stmt.argument.type === AST_NODE_TYPES54.JSXElement || stmt.argument.type === AST_NODE_TYPES54.JSXFragment || stmt.argument.type === AST_NODE_TYPES54.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES54.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
4083
4172
|
}
|
|
4084
4173
|
return false;
|
|
4085
4174
|
});
|
|
4086
4175
|
}
|
|
4087
4176
|
function isReactComponent2(node) {
|
|
4088
|
-
if (node.type ===
|
|
4089
|
-
if (node.body.type ===
|
|
4177
|
+
if (node.type === AST_NODE_TYPES54.ArrowFunctionExpression) {
|
|
4178
|
+
if (node.body.type === AST_NODE_TYPES54.JSXElement || node.body.type === AST_NODE_TYPES54.JSXFragment) {
|
|
4090
4179
|
return true;
|
|
4091
4180
|
}
|
|
4092
|
-
if (node.body.type ===
|
|
4181
|
+
if (node.body.type === AST_NODE_TYPES54.BlockStatement) {
|
|
4093
4182
|
return hasJSXReturn(node.body);
|
|
4094
4183
|
}
|
|
4095
|
-
} else if (node.type ===
|
|
4096
|
-
if (node.body && node.body.type ===
|
|
4184
|
+
} else if (node.type === AST_NODE_TYPES54.FunctionExpression || node.type === AST_NODE_TYPES54.FunctionDeclaration) {
|
|
4185
|
+
if (node.body && node.body.type === AST_NODE_TYPES54.BlockStatement) {
|
|
4097
4186
|
return hasJSXReturn(node.body);
|
|
4098
4187
|
}
|
|
4099
4188
|
}
|
|
@@ -4107,9 +4196,9 @@ var reactPropsDestructure = createRule54({
|
|
|
4107
4196
|
return;
|
|
4108
4197
|
}
|
|
4109
4198
|
const param = node.params[0];
|
|
4110
|
-
if (param.type ===
|
|
4111
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
4112
|
-
if (prop.key.type ===
|
|
4199
|
+
if (param.type === AST_NODE_TYPES54.ObjectPattern) {
|
|
4200
|
+
const properties = param.properties.filter((prop) => prop.type === AST_NODE_TYPES54.Property).map((prop) => {
|
|
4201
|
+
if (prop.key.type === AST_NODE_TYPES54.Identifier) {
|
|
4113
4202
|
return prop.key.name;
|
|
4114
4203
|
}
|
|
4115
4204
|
return null;
|
|
@@ -4136,52 +4225,52 @@ var reactPropsDestructure = createRule54({
|
|
|
4136
4225
|
var react_props_destructure_default = reactPropsDestructure;
|
|
4137
4226
|
|
|
4138
4227
|
// src/rules/require-explicit-return-type.ts
|
|
4139
|
-
import { AST_NODE_TYPES as
|
|
4228
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55, ESLintUtils as ESLintUtils55 } from "@typescript-eslint/utils";
|
|
4140
4229
|
var createRule55 = ESLintUtils55.RuleCreator(
|
|
4141
4230
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4142
4231
|
);
|
|
4143
4232
|
var isReactComponent = (node) => {
|
|
4144
|
-
if (node.type ===
|
|
4233
|
+
if (node.type === AST_NODE_TYPES55.ArrowFunctionExpression) {
|
|
4145
4234
|
const { parent } = node;
|
|
4146
|
-
if (parent?.type ===
|
|
4235
|
+
if (parent?.type === AST_NODE_TYPES55.VariableDeclarator) {
|
|
4147
4236
|
const { id } = parent;
|
|
4148
|
-
if (id.type ===
|
|
4237
|
+
if (id.type === AST_NODE_TYPES55.Identifier) {
|
|
4149
4238
|
return /^[A-Z]/.test(id.name);
|
|
4150
4239
|
}
|
|
4151
4240
|
}
|
|
4152
4241
|
}
|
|
4153
|
-
if (node.type ===
|
|
4242
|
+
if (node.type === AST_NODE_TYPES55.FunctionDeclaration && node.id) {
|
|
4154
4243
|
return /^[A-Z]/.test(node.id.name);
|
|
4155
4244
|
}
|
|
4156
4245
|
return false;
|
|
4157
4246
|
};
|
|
4158
4247
|
var isCallbackFunction = (node) => {
|
|
4159
|
-
if (node.type ===
|
|
4248
|
+
if (node.type === AST_NODE_TYPES55.FunctionDeclaration) {
|
|
4160
4249
|
return false;
|
|
4161
4250
|
}
|
|
4162
4251
|
const { parent } = node;
|
|
4163
4252
|
if (!parent) {
|
|
4164
4253
|
return false;
|
|
4165
4254
|
}
|
|
4166
|
-
if (parent.type ===
|
|
4255
|
+
if (parent.type === AST_NODE_TYPES55.CallExpression && parent.arguments.includes(node)) {
|
|
4167
4256
|
return true;
|
|
4168
4257
|
}
|
|
4169
|
-
if (parent.type ===
|
|
4258
|
+
if (parent.type === AST_NODE_TYPES55.Property) {
|
|
4170
4259
|
return true;
|
|
4171
4260
|
}
|
|
4172
|
-
if (parent.type ===
|
|
4261
|
+
if (parent.type === AST_NODE_TYPES55.ArrayExpression) {
|
|
4173
4262
|
return true;
|
|
4174
4263
|
}
|
|
4175
4264
|
return false;
|
|
4176
4265
|
};
|
|
4177
4266
|
var getFunctionName = (node) => {
|
|
4178
|
-
if (node.type ===
|
|
4267
|
+
if (node.type === AST_NODE_TYPES55.FunctionDeclaration && node.id) {
|
|
4179
4268
|
return node.id.name;
|
|
4180
4269
|
}
|
|
4181
|
-
if (node.type ===
|
|
4270
|
+
if (node.type === AST_NODE_TYPES55.FunctionExpression && node.id) {
|
|
4182
4271
|
return node.id.name;
|
|
4183
4272
|
}
|
|
4184
|
-
if ((node.type ===
|
|
4273
|
+
if ((node.type === AST_NODE_TYPES55.ArrowFunctionExpression || node.type === AST_NODE_TYPES55.FunctionExpression) && node.parent?.type === AST_NODE_TYPES55.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES55.Identifier) {
|
|
4185
4274
|
return node.parent.id.name;
|
|
4186
4275
|
}
|
|
4187
4276
|
return null;
|
|
@@ -4235,7 +4324,7 @@ var requireExplicitReturnType = createRule55({
|
|
|
4235
4324
|
var require_explicit_return_type_default = requireExplicitReturnType;
|
|
4236
4325
|
|
|
4237
4326
|
// src/rules/sort-exports.ts
|
|
4238
|
-
import { AST_NODE_TYPES as
|
|
4327
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES56, ESLintUtils as ESLintUtils56 } from "@typescript-eslint/utils";
|
|
4239
4328
|
var createRule56 = ESLintUtils56.RuleCreator(
|
|
4240
4329
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4241
4330
|
);
|
|
@@ -4290,7 +4379,7 @@ var sortExports = createRule56({
|
|
|
4290
4379
|
Program(node) {
|
|
4291
4380
|
const exportGroups = [];
|
|
4292
4381
|
node.body.forEach((statement) => {
|
|
4293
|
-
if (statement.type !==
|
|
4382
|
+
if (statement.type !== AST_NODE_TYPES56.ExportNamedDeclaration || statement.declaration !== null) {
|
|
4294
4383
|
if (exportGroups.length > 0) {
|
|
4295
4384
|
checkOrder(exportGroups);
|
|
4296
4385
|
exportGroups.length = 0;
|
|
@@ -4309,7 +4398,7 @@ var sortExports = createRule56({
|
|
|
4309
4398
|
var sort_exports_default = sortExports;
|
|
4310
4399
|
|
|
4311
4400
|
// src/rules/sort-imports.ts
|
|
4312
|
-
import { AST_NODE_TYPES as
|
|
4401
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES57, ESLintUtils as ESLintUtils57 } from "@typescript-eslint/utils";
|
|
4313
4402
|
var createRule57 = ESLintUtils57.RuleCreator(
|
|
4314
4403
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4315
4404
|
);
|
|
@@ -4421,7 +4510,7 @@ var sortImports = createRule57({
|
|
|
4421
4510
|
Program(node) {
|
|
4422
4511
|
const importGroups = [];
|
|
4423
4512
|
node.body.forEach((statement) => {
|
|
4424
|
-
if (statement.type !==
|
|
4513
|
+
if (statement.type !== AST_NODE_TYPES57.ImportDeclaration) {
|
|
4425
4514
|
if (importGroups.length > 0) {
|
|
4426
4515
|
checkOrder(importGroups);
|
|
4427
4516
|
importGroups.length = 0;
|
|
@@ -4443,13 +4532,13 @@ var sortImports = createRule57({
|
|
|
4443
4532
|
var sort_imports_default = sortImports;
|
|
4444
4533
|
|
|
4445
4534
|
// src/rules/sort-type-alphabetically.ts
|
|
4446
|
-
import { AST_NODE_TYPES as
|
|
4535
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES58, ESLintUtils as ESLintUtils58 } from "@typescript-eslint/utils";
|
|
4447
4536
|
var createRule58 = ESLintUtils58.RuleCreator(
|
|
4448
4537
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4449
4538
|
);
|
|
4450
4539
|
function isAlphabeticallySortedWithinGroups(members) {
|
|
4451
4540
|
const properties = members.filter(
|
|
4452
|
-
(member) => member.type ===
|
|
4541
|
+
(member) => member.type === AST_NODE_TYPES58.TSPropertySignature && member.key.type === AST_NODE_TYPES58.Identifier
|
|
4453
4542
|
);
|
|
4454
4543
|
if (properties.length < 2) {
|
|
4455
4544
|
return true;
|
|
@@ -4478,7 +4567,7 @@ var sortTypeAlphabetically = createRule58({
|
|
|
4478
4567
|
function fixMembers(fixer, members) {
|
|
4479
4568
|
const { sourceCode } = context;
|
|
4480
4569
|
const properties = members.filter(
|
|
4481
|
-
(member) => member.type ===
|
|
4570
|
+
(member) => member.type === AST_NODE_TYPES58.TSPropertySignature && member.key.type === AST_NODE_TYPES58.Identifier
|
|
4482
4571
|
);
|
|
4483
4572
|
const required = properties.filter((prop) => !prop.optional);
|
|
4484
4573
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4515,7 +4604,7 @@ var sortTypeAlphabetically = createRule58({
|
|
|
4515
4604
|
}
|
|
4516
4605
|
},
|
|
4517
4606
|
TSTypeAliasDeclaration(node) {
|
|
4518
|
-
if (node.typeAnnotation.type !==
|
|
4607
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES58.TSTypeLiteral) {
|
|
4519
4608
|
return;
|
|
4520
4609
|
}
|
|
4521
4610
|
const { members } = node.typeAnnotation;
|
|
@@ -4535,13 +4624,13 @@ var sortTypeAlphabetically = createRule58({
|
|
|
4535
4624
|
var sort_type_alphabetically_default = sortTypeAlphabetically;
|
|
4536
4625
|
|
|
4537
4626
|
// src/rules/sort-type-required-first.ts
|
|
4538
|
-
import { AST_NODE_TYPES as
|
|
4627
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES59, ESLintUtils as ESLintUtils59 } from "@typescript-eslint/utils";
|
|
4539
4628
|
var createRule59 = ESLintUtils59.RuleCreator(
|
|
4540
4629
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4541
4630
|
);
|
|
4542
4631
|
function isRequiredBeforeOptional(members) {
|
|
4543
4632
|
const properties = members.filter(
|
|
4544
|
-
(member) => member.type ===
|
|
4633
|
+
(member) => member.type === AST_NODE_TYPES59.TSPropertySignature && member.key.type === AST_NODE_TYPES59.Identifier
|
|
4545
4634
|
);
|
|
4546
4635
|
if (properties.length < 2) {
|
|
4547
4636
|
return true;
|
|
@@ -4570,7 +4659,7 @@ var sortTypeRequiredFirst = createRule59({
|
|
|
4570
4659
|
function fixMembers(fixer, members) {
|
|
4571
4660
|
const { sourceCode } = context;
|
|
4572
4661
|
const properties = members.filter(
|
|
4573
|
-
(member) => member.type ===
|
|
4662
|
+
(member) => member.type === AST_NODE_TYPES59.TSPropertySignature && member.key.type === AST_NODE_TYPES59.Identifier
|
|
4574
4663
|
);
|
|
4575
4664
|
const required = properties.filter((prop) => !prop.optional);
|
|
4576
4665
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4591,7 +4680,7 @@ var sortTypeRequiredFirst = createRule59({
|
|
|
4591
4680
|
}
|
|
4592
4681
|
},
|
|
4593
4682
|
TSTypeAliasDeclaration(node) {
|
|
4594
|
-
if (node.typeAnnotation.type !==
|
|
4683
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES59.TSTypeLiteral) {
|
|
4595
4684
|
return;
|
|
4596
4685
|
}
|
|
4597
4686
|
const { members } = node.typeAnnotation;
|
|
@@ -4619,7 +4708,6 @@ var rules = {
|
|
|
4619
4708
|
"boolean-naming-prefix": boolean_naming_prefix_default,
|
|
4620
4709
|
"enforce-camel-case": enforce_camel_case_default,
|
|
4621
4710
|
"enforce-constant-case": enforce_constant_case_default,
|
|
4622
|
-
"enforce-curly-newline": enforce_curly_newline_default,
|
|
4623
4711
|
"enforce-hook-naming": enforce_hook_naming_default,
|
|
4624
4712
|
"enforce-property-case": enforce_property_case_default,
|
|
4625
4713
|
"enforce-props-suffix": enforce_props_suffix_default,
|
|
@@ -4627,7 +4715,6 @@ var rules = {
|
|
|
4627
4715
|
"enforce-service-naming": enforce_service_naming_default,
|
|
4628
4716
|
"enforce-sorted-destructuring": enforce_sorted_destructuring_default,
|
|
4629
4717
|
"enforce-type-declaration-order": enforce_type_declaration_order_default,
|
|
4630
|
-
"file-kebab-case": file_kebab_case_default,
|
|
4631
4718
|
"index-export-only": index_export_only_default,
|
|
4632
4719
|
"jsx-newline-between-elements": jsx_newline_between_elements_default,
|
|
4633
4720
|
"jsx-no-inline-object-prop": jsx_no_inline_object_prop_default,
|
|
@@ -4635,18 +4722,17 @@ var rules = {
|
|
|
4635
4722
|
"jsx-no-non-component-function": jsx_no_non_component_function_default,
|
|
4636
4723
|
"jsx-no-ternary-null": jsx_no_ternary_null_default,
|
|
4637
4724
|
"jsx-no-variable-in-callback": jsx_no_variable_in_callback_default,
|
|
4638
|
-
"jsx-pascal-case": jsx_pascal_case_default,
|
|
4639
4725
|
"jsx-require-suspense": jsx_require_suspense_default,
|
|
4640
4726
|
"jsx-simple-props": jsx_simple_props_default,
|
|
4641
4727
|
"jsx-sort-props": jsx_sort_props_default,
|
|
4642
4728
|
"jsx-spread-props-last": jsx_spread_props_last_default,
|
|
4643
4729
|
"newline-after-multiline-block": newline_after_multiline_block_default,
|
|
4644
4730
|
"newline-before-return": newline_before_return_default,
|
|
4645
|
-
"nextjs-require-public-env": nextjs_require_public_env_default,
|
|
4646
4731
|
"no-complex-inline-return": no_complex_inline_return_default,
|
|
4647
4732
|
"no-direct-date": no_direct_date_default,
|
|
4648
4733
|
"no-emoji": no_emoji_default,
|
|
4649
4734
|
"no-env-fallback": no_env_fallback_default,
|
|
4735
|
+
"no-ghost-wrapper": no_ghost_wrapper_default,
|
|
4650
4736
|
"no-inline-default-export": no_inline_default_export_default,
|
|
4651
4737
|
"no-inline-nested-object": no_inline_nested_object_default,
|
|
4652
4738
|
"no-inline-return-properties": no_inline_return_properties_default,
|
|
@@ -4656,6 +4742,7 @@ var rules = {
|
|
|
4656
4742
|
"no-misleading-constant-case": no_misleading_constant_case_default,
|
|
4657
4743
|
"no-nested-interface-declaration": no_nested_interface_declaration_default,
|
|
4658
4744
|
"no-nested-ternary": no_nested_ternary_default,
|
|
4745
|
+
"no-redundant-fragment": no_redundant_fragment_default,
|
|
4659
4746
|
"no-relative-imports": no_relative_imports_default,
|
|
4660
4747
|
"no-single-char-variables": no_single_char_variables_default,
|
|
4661
4748
|
"prefer-async-await": prefer_async_await_default,
|
|
@@ -4665,9 +4752,11 @@ var rules = {
|
|
|
4665
4752
|
"prefer-import-type": prefer_import_type_default,
|
|
4666
4753
|
"prefer-inline-literal-union": prefer_inline_literal_union_default,
|
|
4667
4754
|
"prefer-inline-type-export": prefer_inline_type_export_default,
|
|
4755
|
+
"prefer-interface-for-component-props": prefer_interface_for_component_props_default,
|
|
4668
4756
|
"prefer-interface-over-inline-types": prefer_interface_over_inline_types_default,
|
|
4669
4757
|
"prefer-jsx-template-literals": prefer_jsx_template_literals_default,
|
|
4670
4758
|
"prefer-named-param-types": prefer_named_param_types_default,
|
|
4759
|
+
"prefer-props-with-children": prefer_props_with_children_default,
|
|
4671
4760
|
"prefer-react-import-types": prefer_react_import_types_default,
|
|
4672
4761
|
"react-props-destructure": react_props_destructure_default,
|
|
4673
4762
|
"require-explicit-return-type": require_explicit_return_type_default,
|
|
@@ -4684,13 +4773,11 @@ var baseRules = {
|
|
|
4684
4773
|
"nextfriday/boolean-naming-prefix": "warn",
|
|
4685
4774
|
"nextfriday/enforce-camel-case": "warn",
|
|
4686
4775
|
"nextfriday/enforce-constant-case": "warn",
|
|
4687
|
-
"nextfriday/enforce-curly-newline": "warn",
|
|
4688
4776
|
"nextfriday/enforce-hook-naming": "warn",
|
|
4689
4777
|
"nextfriday/enforce-property-case": "warn",
|
|
4690
4778
|
"nextfriday/enforce-service-naming": "warn",
|
|
4691
4779
|
"nextfriday/enforce-sorted-destructuring": "warn",
|
|
4692
4780
|
"nextfriday/enforce-type-declaration-order": "warn",
|
|
4693
|
-
"nextfriday/file-kebab-case": "warn",
|
|
4694
4781
|
"nextfriday/index-export-only": "warn",
|
|
4695
4782
|
"nextfriday/newline-after-multiline-block": "warn",
|
|
4696
4783
|
"nextfriday/newline-before-return": "warn",
|
|
@@ -4728,13 +4815,11 @@ var baseRecommendedRules = {
|
|
|
4728
4815
|
"nextfriday/boolean-naming-prefix": "error",
|
|
4729
4816
|
"nextfriday/enforce-camel-case": "error",
|
|
4730
4817
|
"nextfriday/enforce-constant-case": "error",
|
|
4731
|
-
"nextfriday/enforce-curly-newline": "error",
|
|
4732
4818
|
"nextfriday/enforce-hook-naming": "error",
|
|
4733
4819
|
"nextfriday/enforce-property-case": "error",
|
|
4734
4820
|
"nextfriday/enforce-service-naming": "error",
|
|
4735
4821
|
"nextfriday/enforce-sorted-destructuring": "error",
|
|
4736
4822
|
"nextfriday/enforce-type-declaration-order": "error",
|
|
4737
|
-
"nextfriday/file-kebab-case": "error",
|
|
4738
4823
|
"nextfriday/index-export-only": "error",
|
|
4739
4824
|
"nextfriday/newline-after-multiline-block": "error",
|
|
4740
4825
|
"nextfriday/newline-before-return": "error",
|
|
@@ -4777,13 +4862,16 @@ var jsxRules = {
|
|
|
4777
4862
|
"nextfriday/jsx-no-non-component-function": "warn",
|
|
4778
4863
|
"nextfriday/jsx-no-ternary-null": "warn",
|
|
4779
4864
|
"nextfriday/jsx-no-variable-in-callback": "warn",
|
|
4780
|
-
"nextfriday/jsx-pascal-case": "warn",
|
|
4781
4865
|
"nextfriday/jsx-require-suspense": "warn",
|
|
4782
4866
|
"nextfriday/jsx-simple-props": "warn",
|
|
4783
4867
|
"nextfriday/jsx-sort-props": "warn",
|
|
4784
4868
|
"nextfriday/jsx-spread-props-last": "warn",
|
|
4869
|
+
"nextfriday/no-ghost-wrapper": "warn",
|
|
4870
|
+
"nextfriday/no-redundant-fragment": "warn",
|
|
4871
|
+
"nextfriday/prefer-interface-for-component-props": "warn",
|
|
4785
4872
|
"nextfriday/prefer-interface-over-inline-types": "warn",
|
|
4786
4873
|
"nextfriday/prefer-jsx-template-literals": "warn",
|
|
4874
|
+
"nextfriday/prefer-props-with-children": "warn",
|
|
4787
4875
|
"nextfriday/react-props-destructure": "warn"
|
|
4788
4876
|
};
|
|
4789
4877
|
var jsxRecommendedRules = {
|
|
@@ -4795,41 +4883,24 @@ var jsxRecommendedRules = {
|
|
|
4795
4883
|
"nextfriday/jsx-no-non-component-function": "error",
|
|
4796
4884
|
"nextfriday/jsx-no-ternary-null": "error",
|
|
4797
4885
|
"nextfriday/jsx-no-variable-in-callback": "error",
|
|
4798
|
-
"nextfriday/jsx-pascal-case": "error",
|
|
4799
4886
|
"nextfriday/jsx-require-suspense": "error",
|
|
4800
4887
|
"nextfriday/jsx-simple-props": "error",
|
|
4801
4888
|
"nextfriday/jsx-sort-props": "error",
|
|
4802
4889
|
"nextfriday/jsx-spread-props-last": "error",
|
|
4890
|
+
"nextfriday/no-ghost-wrapper": "error",
|
|
4891
|
+
"nextfriday/no-redundant-fragment": "error",
|
|
4892
|
+
"nextfriday/prefer-interface-for-component-props": "error",
|
|
4803
4893
|
"nextfriday/prefer-interface-over-inline-types": "error",
|
|
4804
4894
|
"nextfriday/prefer-jsx-template-literals": "error",
|
|
4895
|
+
"nextfriday/prefer-props-with-children": "error",
|
|
4805
4896
|
"nextfriday/react-props-destructure": "error"
|
|
4806
4897
|
};
|
|
4807
|
-
var nextjsOnlyRules = {
|
|
4808
|
-
"nextfriday/nextjs-require-public-env": "warn"
|
|
4809
|
-
};
|
|
4810
|
-
var nextjsOnlyRecommendedRules = {
|
|
4811
|
-
"nextfriday/nextjs-require-public-env": "error"
|
|
4812
|
-
};
|
|
4813
4898
|
var createConfig = (configRules) => ({
|
|
4814
4899
|
plugins: {
|
|
4815
4900
|
nextfriday: plugin
|
|
4816
4901
|
},
|
|
4817
4902
|
rules: configRules
|
|
4818
4903
|
});
|
|
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
4904
|
var configs = {
|
|
4834
4905
|
base: createConfig(baseRules),
|
|
4835
4906
|
"base/recommended": createConfig(baseRecommendedRules),
|
|
@@ -4841,15 +4912,13 @@ var configs = {
|
|
|
4841
4912
|
...baseRecommendedRules,
|
|
4842
4913
|
...jsxRecommendedRules
|
|
4843
4914
|
}),
|
|
4844
|
-
nextjs:
|
|
4915
|
+
nextjs: createConfig({
|
|
4845
4916
|
...baseRules,
|
|
4846
|
-
...jsxRules
|
|
4847
|
-
...nextjsOnlyRules
|
|
4917
|
+
...jsxRules
|
|
4848
4918
|
}),
|
|
4849
|
-
"nextjs/recommended":
|
|
4919
|
+
"nextjs/recommended": createConfig({
|
|
4850
4920
|
...baseRecommendedRules,
|
|
4851
|
-
...jsxRecommendedRules
|
|
4852
|
-
...nextjsOnlyRecommendedRules
|
|
4921
|
+
...jsxRecommendedRules
|
|
4853
4922
|
})
|
|
4854
4923
|
};
|
|
4855
4924
|
var nextfridayPlugin = {
|