eslint-plugin-nextfriday 1.2.3 → 1.4.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 +12 -0
- package/README.md +22 -13
- package/docs/rules/NO_COMPLEX_INLINE_RETURN.md +136 -0
- package/docs/rules/NO_LOGIC_IN_PARAMS.md +122 -0
- package/docs/rules/PREFER_NAMED_PARAM_TYPES.md +172 -0
- package/lib/index.cjs +247 -66
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +42 -0
- package/lib/index.d.ts +42 -0
- package/lib/index.js +247 -66
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -40,7 +40,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
40
40
|
// package.json
|
|
41
41
|
var package_default = {
|
|
42
42
|
name: "eslint-plugin-nextfriday",
|
|
43
|
-
version: "1.
|
|
43
|
+
version: "1.4.0",
|
|
44
44
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
45
45
|
keywords: [
|
|
46
46
|
"eslint",
|
|
@@ -380,13 +380,59 @@ var mdFilenameCaseRestriction = createRule4({
|
|
|
380
380
|
});
|
|
381
381
|
var md_filename_case_restriction_default = mdFilenameCaseRestriction;
|
|
382
382
|
|
|
383
|
-
// src/rules/no-
|
|
384
|
-
var import_emoji_regex = __toESM(require("emoji-regex"), 1);
|
|
383
|
+
// src/rules/no-complex-inline-return.ts
|
|
385
384
|
var import_utils5 = require("@typescript-eslint/utils");
|
|
386
385
|
var createRule5 = import_utils5.ESLintUtils.RuleCreator(
|
|
387
386
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
388
387
|
);
|
|
389
|
-
var
|
|
388
|
+
var noComplexInlineReturn = createRule5({
|
|
389
|
+
name: "no-complex-inline-return",
|
|
390
|
+
meta: {
|
|
391
|
+
type: "suggestion",
|
|
392
|
+
docs: {
|
|
393
|
+
description: "Disallow complex inline expressions in return statements - prefer extracting to a const first"
|
|
394
|
+
},
|
|
395
|
+
messages: {
|
|
396
|
+
noComplexInlineReturn: "Avoid returning complex expressions directly. Extract to a const variable first for better readability."
|
|
397
|
+
},
|
|
398
|
+
schema: []
|
|
399
|
+
},
|
|
400
|
+
defaultOptions: [],
|
|
401
|
+
create(context) {
|
|
402
|
+
const isComplexExpression = (node) => {
|
|
403
|
+
if (!node) return false;
|
|
404
|
+
if (node.type === import_utils5.AST_NODE_TYPES.ConditionalExpression) {
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
if (node.type === import_utils5.AST_NODE_TYPES.LogicalExpression) {
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
if (node.type === import_utils5.AST_NODE_TYPES.NewExpression) {
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
return false;
|
|
414
|
+
};
|
|
415
|
+
return {
|
|
416
|
+
ReturnStatement(node) {
|
|
417
|
+
if (node.argument && isComplexExpression(node.argument)) {
|
|
418
|
+
context.report({
|
|
419
|
+
node: node.argument,
|
|
420
|
+
messageId: "noComplexInlineReturn"
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
var no_complex_inline_return_default = noComplexInlineReturn;
|
|
428
|
+
|
|
429
|
+
// src/rules/no-emoji.ts
|
|
430
|
+
var import_emoji_regex = __toESM(require("emoji-regex"), 1);
|
|
431
|
+
var import_utils6 = require("@typescript-eslint/utils");
|
|
432
|
+
var createRule6 = import_utils6.ESLintUtils.RuleCreator(
|
|
433
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
434
|
+
);
|
|
435
|
+
var noEmoji = createRule6({
|
|
390
436
|
name: "no-emoji",
|
|
391
437
|
meta: {
|
|
392
438
|
type: "problem",
|
|
@@ -420,11 +466,11 @@ var noEmoji = createRule5({
|
|
|
420
466
|
var no_emoji_default = noEmoji;
|
|
421
467
|
|
|
422
468
|
// src/rules/no-explicit-return-type.ts
|
|
423
|
-
var
|
|
424
|
-
var
|
|
469
|
+
var import_utils7 = require("@typescript-eslint/utils");
|
|
470
|
+
var createRule7 = import_utils7.ESLintUtils.RuleCreator(
|
|
425
471
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
426
472
|
);
|
|
427
|
-
var noExplicitReturnType =
|
|
473
|
+
var noExplicitReturnType = createRule7({
|
|
428
474
|
name: "no-explicit-return-type",
|
|
429
475
|
meta: {
|
|
430
476
|
type: "suggestion",
|
|
@@ -463,12 +509,76 @@ var noExplicitReturnType = createRule6({
|
|
|
463
509
|
});
|
|
464
510
|
var no_explicit_return_type_default = noExplicitReturnType;
|
|
465
511
|
|
|
512
|
+
// src/rules/no-logic-in-params.ts
|
|
513
|
+
var import_utils8 = require("@typescript-eslint/utils");
|
|
514
|
+
var createRule8 = import_utils8.ESLintUtils.RuleCreator(
|
|
515
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
516
|
+
);
|
|
517
|
+
var noLogicInParams = createRule8({
|
|
518
|
+
name: "no-logic-in-params",
|
|
519
|
+
meta: {
|
|
520
|
+
type: "suggestion",
|
|
521
|
+
docs: {
|
|
522
|
+
description: "Disallow logic or conditions in function parameters - extract to a const variable first"
|
|
523
|
+
},
|
|
524
|
+
messages: {
|
|
525
|
+
noLogicInParams: "Avoid logic or conditions in function parameters. Extract to a const variable first for better readability."
|
|
526
|
+
},
|
|
527
|
+
schema: []
|
|
528
|
+
},
|
|
529
|
+
defaultOptions: [],
|
|
530
|
+
create(context) {
|
|
531
|
+
const isComplexExpression = (node) => {
|
|
532
|
+
if (node.type === import_utils8.AST_NODE_TYPES.SpreadElement) {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
if (node.type === import_utils8.AST_NODE_TYPES.ConditionalExpression) {
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
if (node.type === import_utils8.AST_NODE_TYPES.LogicalExpression) {
|
|
539
|
+
return true;
|
|
540
|
+
}
|
|
541
|
+
if (node.type === import_utils8.AST_NODE_TYPES.BinaryExpression) {
|
|
542
|
+
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
543
|
+
return logicalOperators.includes(node.operator);
|
|
544
|
+
}
|
|
545
|
+
if (node.type === import_utils8.AST_NODE_TYPES.UnaryExpression) {
|
|
546
|
+
return node.operator === "!";
|
|
547
|
+
}
|
|
548
|
+
return false;
|
|
549
|
+
};
|
|
550
|
+
return {
|
|
551
|
+
CallExpression(node) {
|
|
552
|
+
node.arguments.forEach((arg) => {
|
|
553
|
+
if (isComplexExpression(arg)) {
|
|
554
|
+
context.report({
|
|
555
|
+
node: arg,
|
|
556
|
+
messageId: "noLogicInParams"
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
},
|
|
561
|
+
NewExpression(node) {
|
|
562
|
+
node.arguments.forEach((arg) => {
|
|
563
|
+
if (isComplexExpression(arg)) {
|
|
564
|
+
context.report({
|
|
565
|
+
node: arg,
|
|
566
|
+
messageId: "noLogicInParams"
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
var no_logic_in_params_default = noLogicInParams;
|
|
575
|
+
|
|
466
576
|
// src/rules/prefer-destructuring-params.ts
|
|
467
|
-
var
|
|
468
|
-
var
|
|
577
|
+
var import_utils9 = require("@typescript-eslint/utils");
|
|
578
|
+
var createRule9 = import_utils9.ESLintUtils.RuleCreator(
|
|
469
579
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
470
580
|
);
|
|
471
|
-
var preferDestructuringParams =
|
|
581
|
+
var preferDestructuringParams = createRule9({
|
|
472
582
|
name: "prefer-destructuring-params",
|
|
473
583
|
meta: {
|
|
474
584
|
type: "suggestion",
|
|
@@ -484,18 +594,18 @@ var preferDestructuringParams = createRule7({
|
|
|
484
594
|
create(context) {
|
|
485
595
|
const isCallbackFunction = (node) => {
|
|
486
596
|
const { parent } = node;
|
|
487
|
-
return parent?.type ===
|
|
597
|
+
return parent?.type === import_utils9.AST_NODE_TYPES.CallExpression;
|
|
488
598
|
};
|
|
489
599
|
const isDeveloperFunction = (node) => {
|
|
490
|
-
if (node.type ===
|
|
600
|
+
if (node.type === import_utils9.AST_NODE_TYPES.FunctionDeclaration) {
|
|
491
601
|
return true;
|
|
492
602
|
}
|
|
493
|
-
if (node.type ===
|
|
603
|
+
if (node.type === import_utils9.AST_NODE_TYPES.FunctionExpression || node.type === import_utils9.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
494
604
|
if (isCallbackFunction(node)) {
|
|
495
605
|
return false;
|
|
496
606
|
}
|
|
497
607
|
const { parent } = node;
|
|
498
|
-
return parent?.type ===
|
|
608
|
+
return parent?.type === import_utils9.AST_NODE_TYPES.VariableDeclarator || parent?.type === import_utils9.AST_NODE_TYPES.AssignmentExpression || parent?.type === import_utils9.AST_NODE_TYPES.Property || parent?.type === import_utils9.AST_NODE_TYPES.MethodDefinition;
|
|
499
609
|
}
|
|
500
610
|
return false;
|
|
501
611
|
};
|
|
@@ -507,7 +617,7 @@ var preferDestructuringParams = createRule7({
|
|
|
507
617
|
if (!isDeveloperFunction(node)) {
|
|
508
618
|
return;
|
|
509
619
|
}
|
|
510
|
-
if (node.type ===
|
|
620
|
+
if (node.type === import_utils9.AST_NODE_TYPES.FunctionDeclaration && node.id) {
|
|
511
621
|
const functionName = node.id.name;
|
|
512
622
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
513
623
|
return;
|
|
@@ -517,7 +627,7 @@ var preferDestructuringParams = createRule7({
|
|
|
517
627
|
return;
|
|
518
628
|
}
|
|
519
629
|
const hasNonDestructuredParams = node.params.some(
|
|
520
|
-
(param) => param.type !==
|
|
630
|
+
(param) => param.type !== import_utils9.AST_NODE_TYPES.ObjectPattern && param.type !== import_utils9.AST_NODE_TYPES.RestElement
|
|
521
631
|
);
|
|
522
632
|
if (hasNonDestructuredParams) {
|
|
523
633
|
context.report({
|
|
@@ -536,11 +646,11 @@ var preferDestructuringParams = createRule7({
|
|
|
536
646
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
537
647
|
|
|
538
648
|
// src/rules/prefer-import-type.ts
|
|
539
|
-
var
|
|
540
|
-
var
|
|
649
|
+
var import_utils10 = require("@typescript-eslint/utils");
|
|
650
|
+
var createRule10 = import_utils10.ESLintUtils.RuleCreator(
|
|
541
651
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
542
652
|
);
|
|
543
|
-
var preferImportType =
|
|
653
|
+
var preferImportType = createRule10({
|
|
544
654
|
name: "prefer-import-type",
|
|
545
655
|
meta: {
|
|
546
656
|
type: "suggestion",
|
|
@@ -571,14 +681,14 @@ var preferImportType = createRule8({
|
|
|
571
681
|
return;
|
|
572
682
|
}
|
|
573
683
|
const isTypeOnlyImport = node.specifiers.every((specifier) => {
|
|
574
|
-
if (specifier.type ===
|
|
684
|
+
if (specifier.type === import_utils10.AST_NODE_TYPES.ImportDefaultSpecifier) {
|
|
575
685
|
return false;
|
|
576
686
|
}
|
|
577
|
-
if (specifier.type ===
|
|
687
|
+
if (specifier.type === import_utils10.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
578
688
|
return false;
|
|
579
689
|
}
|
|
580
|
-
if (specifier.type ===
|
|
581
|
-
const importedName = specifier.imported.type ===
|
|
690
|
+
if (specifier.type === import_utils10.AST_NODE_TYPES.ImportSpecifier) {
|
|
691
|
+
const importedName = specifier.imported.type === import_utils10.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
582
692
|
const isKnownTypeOnly = node.source.value === "@typescript-eslint/utils" && ["TSESTree", "RuleContext"].includes(importedName) || node.source.value === "react" && ["Component", "ComponentProps", "ReactNode", "FC", "JSX", "ReactElement", "PropsWithChildren"].includes(
|
|
583
693
|
importedName
|
|
584
694
|
) || importedName.endsWith("Type") || importedName.endsWith("Interface") || importedName.endsWith("Props");
|
|
@@ -606,11 +716,11 @@ var preferImportType = createRule8({
|
|
|
606
716
|
var prefer_import_type_default = preferImportType;
|
|
607
717
|
|
|
608
718
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
609
|
-
var
|
|
610
|
-
var
|
|
719
|
+
var import_utils11 = require("@typescript-eslint/utils");
|
|
720
|
+
var createRule11 = import_utils11.ESLintUtils.RuleCreator(
|
|
611
721
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
612
722
|
);
|
|
613
|
-
var preferInterfaceOverInlineTypes =
|
|
723
|
+
var preferInterfaceOverInlineTypes = createRule11({
|
|
614
724
|
name: "prefer-interface-over-inline-types",
|
|
615
725
|
meta: {
|
|
616
726
|
type: "suggestion",
|
|
@@ -626,54 +736,54 @@ var preferInterfaceOverInlineTypes = createRule9({
|
|
|
626
736
|
defaultOptions: [],
|
|
627
737
|
create(context) {
|
|
628
738
|
function hasJSXInConditional(node) {
|
|
629
|
-
return node.consequent.type ===
|
|
739
|
+
return node.consequent.type === import_utils11.AST_NODE_TYPES.JSXElement || node.consequent.type === import_utils11.AST_NODE_TYPES.JSXFragment || node.alternate.type === import_utils11.AST_NODE_TYPES.JSXElement || node.alternate.type === import_utils11.AST_NODE_TYPES.JSXFragment;
|
|
630
740
|
}
|
|
631
741
|
function hasJSXInLogical(node) {
|
|
632
|
-
return node.right.type ===
|
|
742
|
+
return node.right.type === import_utils11.AST_NODE_TYPES.JSXElement || node.right.type === import_utils11.AST_NODE_TYPES.JSXFragment;
|
|
633
743
|
}
|
|
634
744
|
function hasJSXReturn(block) {
|
|
635
745
|
return block.body.some((stmt) => {
|
|
636
|
-
if (stmt.type ===
|
|
637
|
-
return stmt.argument.type ===
|
|
746
|
+
if (stmt.type === import_utils11.AST_NODE_TYPES.ReturnStatement && stmt.argument) {
|
|
747
|
+
return stmt.argument.type === import_utils11.AST_NODE_TYPES.JSXElement || stmt.argument.type === import_utils11.AST_NODE_TYPES.JSXFragment || stmt.argument.type === import_utils11.AST_NODE_TYPES.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === import_utils11.AST_NODE_TYPES.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
638
748
|
}
|
|
639
749
|
return false;
|
|
640
750
|
});
|
|
641
751
|
}
|
|
642
752
|
function isReactComponent(node) {
|
|
643
|
-
if (node.type ===
|
|
644
|
-
if (node.body.type ===
|
|
753
|
+
if (node.type === import_utils11.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
754
|
+
if (node.body.type === import_utils11.AST_NODE_TYPES.JSXElement || node.body.type === import_utils11.AST_NODE_TYPES.JSXFragment) {
|
|
645
755
|
return true;
|
|
646
756
|
}
|
|
647
|
-
if (node.body.type ===
|
|
757
|
+
if (node.body.type === import_utils11.AST_NODE_TYPES.BlockStatement) {
|
|
648
758
|
return hasJSXReturn(node.body);
|
|
649
759
|
}
|
|
650
|
-
} else if (node.type ===
|
|
651
|
-
if (node.body && node.body.type ===
|
|
760
|
+
} else if (node.type === import_utils11.AST_NODE_TYPES.FunctionExpression || node.type === import_utils11.AST_NODE_TYPES.FunctionDeclaration) {
|
|
761
|
+
if (node.body && node.body.type === import_utils11.AST_NODE_TYPES.BlockStatement) {
|
|
652
762
|
return hasJSXReturn(node.body);
|
|
653
763
|
}
|
|
654
764
|
}
|
|
655
765
|
return false;
|
|
656
766
|
}
|
|
657
767
|
function isInlineTypeAnnotation(node) {
|
|
658
|
-
if (node.type ===
|
|
768
|
+
if (node.type === import_utils11.AST_NODE_TYPES.TSTypeLiteral) {
|
|
659
769
|
return true;
|
|
660
770
|
}
|
|
661
|
-
if (node.type ===
|
|
662
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
771
|
+
if (node.type === import_utils11.AST_NODE_TYPES.TSTypeReference && node.typeArguments) {
|
|
772
|
+
return node.typeArguments.params.some((param) => param.type === import_utils11.AST_NODE_TYPES.TSTypeLiteral);
|
|
663
773
|
}
|
|
664
|
-
if (node.type ===
|
|
774
|
+
if (node.type === import_utils11.AST_NODE_TYPES.TSUnionType) {
|
|
665
775
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
666
776
|
}
|
|
667
777
|
return false;
|
|
668
778
|
}
|
|
669
779
|
function hasInlineObjectType(node) {
|
|
670
|
-
if (node.type ===
|
|
780
|
+
if (node.type === import_utils11.AST_NODE_TYPES.TSTypeLiteral) {
|
|
671
781
|
return true;
|
|
672
782
|
}
|
|
673
|
-
if (node.type ===
|
|
674
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
783
|
+
if (node.type === import_utils11.AST_NODE_TYPES.TSTypeReference && node.typeArguments) {
|
|
784
|
+
return node.typeArguments.params.some((param) => param.type === import_utils11.AST_NODE_TYPES.TSTypeLiteral);
|
|
675
785
|
}
|
|
676
|
-
if (node.type ===
|
|
786
|
+
if (node.type === import_utils11.AST_NODE_TYPES.TSUnionType) {
|
|
677
787
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
678
788
|
}
|
|
679
789
|
return false;
|
|
@@ -686,7 +796,7 @@ var preferInterfaceOverInlineTypes = createRule9({
|
|
|
686
796
|
return;
|
|
687
797
|
}
|
|
688
798
|
const param = node.params[0];
|
|
689
|
-
if (param.type ===
|
|
799
|
+
if (param.type === import_utils11.AST_NODE_TYPES.Identifier && param.typeAnnotation) {
|
|
690
800
|
const { typeAnnotation } = param.typeAnnotation;
|
|
691
801
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
692
802
|
context.report({
|
|
@@ -705,12 +815,74 @@ var preferInterfaceOverInlineTypes = createRule9({
|
|
|
705
815
|
});
|
|
706
816
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
707
817
|
|
|
818
|
+
// src/rules/prefer-named-param-types.ts
|
|
819
|
+
var import_utils12 = require("@typescript-eslint/utils");
|
|
820
|
+
var createRule12 = import_utils12.ESLintUtils.RuleCreator(
|
|
821
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
822
|
+
);
|
|
823
|
+
var preferNamedParamTypes = createRule12({
|
|
824
|
+
name: "prefer-named-param-types",
|
|
825
|
+
meta: {
|
|
826
|
+
type: "suggestion",
|
|
827
|
+
docs: {
|
|
828
|
+
description: "Enforce named interfaces/types instead of inline object types for function parameters"
|
|
829
|
+
},
|
|
830
|
+
messages: {
|
|
831
|
+
preferNamedParamTypes: "Use a named interface or type for object parameter types instead of inline type annotations"
|
|
832
|
+
},
|
|
833
|
+
schema: []
|
|
834
|
+
},
|
|
835
|
+
defaultOptions: [],
|
|
836
|
+
create(context) {
|
|
837
|
+
function hasInlineObjectType(param) {
|
|
838
|
+
if (param.type === import_utils12.AST_NODE_TYPES.AssignmentPattern) {
|
|
839
|
+
return hasInlineObjectType(param.left);
|
|
840
|
+
}
|
|
841
|
+
if (param.type === import_utils12.AST_NODE_TYPES.ObjectPattern) {
|
|
842
|
+
if (param.typeAnnotation?.typeAnnotation.type === import_utils12.AST_NODE_TYPES.TSTypeLiteral) {
|
|
843
|
+
return true;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (param.type === import_utils12.AST_NODE_TYPES.Identifier) {
|
|
847
|
+
if (param.typeAnnotation?.typeAnnotation.type === import_utils12.AST_NODE_TYPES.TSTypeLiteral) {
|
|
848
|
+
return true;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return false;
|
|
852
|
+
}
|
|
853
|
+
function checkFunction(node) {
|
|
854
|
+
let params = [];
|
|
855
|
+
if ("params" in node) {
|
|
856
|
+
params = node.params;
|
|
857
|
+
} else if ("value" in node && node.value) {
|
|
858
|
+
params = node.value.params;
|
|
859
|
+
}
|
|
860
|
+
params.forEach((param) => {
|
|
861
|
+
if (hasInlineObjectType(param)) {
|
|
862
|
+
context.report({
|
|
863
|
+
node: param,
|
|
864
|
+
messageId: "preferNamedParamTypes"
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
return {
|
|
870
|
+
FunctionDeclaration: checkFunction,
|
|
871
|
+
FunctionExpression: checkFunction,
|
|
872
|
+
ArrowFunctionExpression: checkFunction,
|
|
873
|
+
TSMethodSignature: checkFunction,
|
|
874
|
+
MethodDefinition: checkFunction
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
879
|
+
|
|
708
880
|
// src/rules/prefer-react-import-types.ts
|
|
709
|
-
var
|
|
710
|
-
var
|
|
881
|
+
var import_utils13 = require("@typescript-eslint/utils");
|
|
882
|
+
var createRule13 = import_utils13.ESLintUtils.RuleCreator(
|
|
711
883
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
712
884
|
);
|
|
713
|
-
var preferReactImportTypes =
|
|
885
|
+
var preferReactImportTypes = createRule13({
|
|
714
886
|
name: "prefer-react-import-types",
|
|
715
887
|
meta: {
|
|
716
888
|
type: "suggestion",
|
|
@@ -786,7 +958,7 @@ var preferReactImportTypes = createRule10({
|
|
|
786
958
|
]);
|
|
787
959
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
788
960
|
function checkMemberExpression(node) {
|
|
789
|
-
if (node.object.type ===
|
|
961
|
+
if (node.object.type === import_utils13.AST_NODE_TYPES.Identifier && node.object.name === "React" && node.property.type === import_utils13.AST_NODE_TYPES.Identifier && allReactExports.has(node.property.name)) {
|
|
790
962
|
const typeName = node.property.name;
|
|
791
963
|
const isType = reactTypes.has(typeName);
|
|
792
964
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -803,7 +975,7 @@ var preferReactImportTypes = createRule10({
|
|
|
803
975
|
return {
|
|
804
976
|
MemberExpression: checkMemberExpression,
|
|
805
977
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
806
|
-
if (node.left.type ===
|
|
978
|
+
if (node.left.type === import_utils13.AST_NODE_TYPES.Identifier && node.left.name === "React" && node.right.type === import_utils13.AST_NODE_TYPES.Identifier && allReactExports.has(node.right.name)) {
|
|
807
979
|
const typeName = node.right.name;
|
|
808
980
|
const isType = reactTypes.has(typeName);
|
|
809
981
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -823,11 +995,11 @@ var preferReactImportTypes = createRule10({
|
|
|
823
995
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
824
996
|
|
|
825
997
|
// src/rules/react-props-destructure.ts
|
|
826
|
-
var
|
|
827
|
-
var
|
|
998
|
+
var import_utils14 = require("@typescript-eslint/utils");
|
|
999
|
+
var createRule14 = import_utils14.ESLintUtils.RuleCreator(
|
|
828
1000
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
829
1001
|
);
|
|
830
|
-
var reactPropsDestructure =
|
|
1002
|
+
var reactPropsDestructure = createRule14({
|
|
831
1003
|
name: "react-props-destructure",
|
|
832
1004
|
meta: {
|
|
833
1005
|
type: "suggestion",
|
|
@@ -843,29 +1015,29 @@ var reactPropsDestructure = createRule11({
|
|
|
843
1015
|
defaultOptions: [],
|
|
844
1016
|
create(context) {
|
|
845
1017
|
function hasJSXInConditional(node) {
|
|
846
|
-
return node.consequent.type ===
|
|
1018
|
+
return node.consequent.type === import_utils14.AST_NODE_TYPES.JSXElement || node.consequent.type === import_utils14.AST_NODE_TYPES.JSXFragment || node.alternate.type === import_utils14.AST_NODE_TYPES.JSXElement || node.alternate.type === import_utils14.AST_NODE_TYPES.JSXFragment;
|
|
847
1019
|
}
|
|
848
1020
|
function hasJSXInLogical(node) {
|
|
849
|
-
return node.right.type ===
|
|
1021
|
+
return node.right.type === import_utils14.AST_NODE_TYPES.JSXElement || node.right.type === import_utils14.AST_NODE_TYPES.JSXFragment;
|
|
850
1022
|
}
|
|
851
1023
|
function hasJSXReturn(block) {
|
|
852
1024
|
return block.body.some((stmt) => {
|
|
853
|
-
if (stmt.type ===
|
|
854
|
-
return stmt.argument.type ===
|
|
1025
|
+
if (stmt.type === import_utils14.AST_NODE_TYPES.ReturnStatement && stmt.argument) {
|
|
1026
|
+
return stmt.argument.type === import_utils14.AST_NODE_TYPES.JSXElement || stmt.argument.type === import_utils14.AST_NODE_TYPES.JSXFragment || stmt.argument.type === import_utils14.AST_NODE_TYPES.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === import_utils14.AST_NODE_TYPES.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
855
1027
|
}
|
|
856
1028
|
return false;
|
|
857
1029
|
});
|
|
858
1030
|
}
|
|
859
1031
|
function isReactComponent(node) {
|
|
860
|
-
if (node.type ===
|
|
861
|
-
if (node.body.type ===
|
|
1032
|
+
if (node.type === import_utils14.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
1033
|
+
if (node.body.type === import_utils14.AST_NODE_TYPES.JSXElement || node.body.type === import_utils14.AST_NODE_TYPES.JSXFragment) {
|
|
862
1034
|
return true;
|
|
863
1035
|
}
|
|
864
|
-
if (node.body.type ===
|
|
1036
|
+
if (node.body.type === import_utils14.AST_NODE_TYPES.BlockStatement) {
|
|
865
1037
|
return hasJSXReturn(node.body);
|
|
866
1038
|
}
|
|
867
|
-
} else if (node.type ===
|
|
868
|
-
if (node.body && node.body.type ===
|
|
1039
|
+
} else if (node.type === import_utils14.AST_NODE_TYPES.FunctionExpression || node.type === import_utils14.AST_NODE_TYPES.FunctionDeclaration) {
|
|
1040
|
+
if (node.body && node.body.type === import_utils14.AST_NODE_TYPES.BlockStatement) {
|
|
869
1041
|
return hasJSXReturn(node.body);
|
|
870
1042
|
}
|
|
871
1043
|
}
|
|
@@ -879,9 +1051,9 @@ var reactPropsDestructure = createRule11({
|
|
|
879
1051
|
return;
|
|
880
1052
|
}
|
|
881
1053
|
const param = node.params[0];
|
|
882
|
-
if (param.type ===
|
|
883
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
884
|
-
if (prop.key.type ===
|
|
1054
|
+
if (param.type === import_utils14.AST_NODE_TYPES.ObjectPattern) {
|
|
1055
|
+
const properties = param.properties.filter((prop) => prop.type === import_utils14.AST_NODE_TYPES.Property).map((prop) => {
|
|
1056
|
+
if (prop.key.type === import_utils14.AST_NODE_TYPES.Identifier) {
|
|
885
1057
|
return prop.key.name;
|
|
886
1058
|
}
|
|
887
1059
|
return null;
|
|
@@ -917,11 +1089,14 @@ var rules = {
|
|
|
917
1089
|
"file-kebab-case": file_kebab_case_default,
|
|
918
1090
|
"jsx-pascal-case": jsx_pascal_case_default,
|
|
919
1091
|
"md-filename-case-restriction": md_filename_case_restriction_default,
|
|
1092
|
+
"no-complex-inline-return": no_complex_inline_return_default,
|
|
920
1093
|
"no-emoji": no_emoji_default,
|
|
921
1094
|
"no-explicit-return-type": no_explicit_return_type_default,
|
|
1095
|
+
"no-logic-in-params": no_logic_in_params_default,
|
|
922
1096
|
"prefer-destructuring-params": prefer_destructuring_params_default,
|
|
923
1097
|
"prefer-import-type": prefer_import_type_default,
|
|
924
1098
|
"prefer-interface-over-inline-types": prefer_interface_over_inline_types_default,
|
|
1099
|
+
"prefer-named-param-types": prefer_named_param_types_default,
|
|
925
1100
|
"prefer-react-import-types": prefer_react_import_types_default,
|
|
926
1101
|
"react-props-destructure": react_props_destructure_default
|
|
927
1102
|
};
|
|
@@ -936,7 +1111,10 @@ var baseRules = {
|
|
|
936
1111
|
"nextfriday/prefer-destructuring-params": "warn",
|
|
937
1112
|
"nextfriday/no-explicit-return-type": "warn",
|
|
938
1113
|
"nextfriday/prefer-import-type": "warn",
|
|
939
|
-
"nextfriday/prefer-
|
|
1114
|
+
"nextfriday/prefer-named-param-types": "warn",
|
|
1115
|
+
"nextfriday/prefer-react-import-types": "warn",
|
|
1116
|
+
"nextfriday/no-complex-inline-return": "warn",
|
|
1117
|
+
"nextfriday/no-logic-in-params": "warn"
|
|
940
1118
|
};
|
|
941
1119
|
var baseRecommendedRules = {
|
|
942
1120
|
"nextfriday/no-emoji": "error",
|
|
@@ -945,7 +1123,10 @@ var baseRecommendedRules = {
|
|
|
945
1123
|
"nextfriday/prefer-destructuring-params": "error",
|
|
946
1124
|
"nextfriday/no-explicit-return-type": "error",
|
|
947
1125
|
"nextfriday/prefer-import-type": "error",
|
|
948
|
-
"nextfriday/prefer-
|
|
1126
|
+
"nextfriday/prefer-named-param-types": "error",
|
|
1127
|
+
"nextfriday/prefer-react-import-types": "error",
|
|
1128
|
+
"nextfriday/no-complex-inline-return": "error",
|
|
1129
|
+
"nextfriday/no-logic-in-params": "error"
|
|
949
1130
|
};
|
|
950
1131
|
var jsxRules = {
|
|
951
1132
|
"nextfriday/jsx-pascal-case": "warn",
|