eslint-plugin-nextfriday 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +23 -14
- package/docs/rules/NO_COMPLEX_INLINE_RETURN.md +136 -0
- package/docs/rules/NO_ENV_FALLBACK.md +53 -0
- package/docs/rules/NO_LOGIC_IN_PARAMS.md +122 -0
- package/lib/index.cjs +248 -76
- 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 +248 -76
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
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.5.0",
|
|
44
44
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
45
45
|
keywords: [
|
|
46
46
|
"eslint",
|
|
@@ -90,8 +90,8 @@ var package_default = {
|
|
|
90
90
|
"changeset:publish": "npm publish --provenance --access public",
|
|
91
91
|
"changeset:version": "changeset version",
|
|
92
92
|
clear: "rm -rf lib node_modules/.cache .eslintcache",
|
|
93
|
-
eslint: "eslint src --ext .js,.ts
|
|
94
|
-
"eslint:check": "eslint src --ext .js,.ts
|
|
93
|
+
eslint: "eslint src --ext .js,.ts --fix",
|
|
94
|
+
"eslint:check": "eslint src --ext .js,.ts",
|
|
95
95
|
preinstall: "npx only-allow pnpm",
|
|
96
96
|
prepare: "husky",
|
|
97
97
|
prepublishOnly: "pnpm run build",
|
|
@@ -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",
|
|
@@ -419,12 +465,65 @@ var noEmoji = createRule5({
|
|
|
419
465
|
});
|
|
420
466
|
var no_emoji_default = noEmoji;
|
|
421
467
|
|
|
468
|
+
// src/rules/no-env-fallback.ts
|
|
469
|
+
var import_utils7 = require("@typescript-eslint/utils");
|
|
470
|
+
var createRule7 = import_utils7.ESLintUtils.RuleCreator(
|
|
471
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
472
|
+
);
|
|
473
|
+
var noEnvFallback = createRule7({
|
|
474
|
+
name: "no-env-fallback",
|
|
475
|
+
meta: {
|
|
476
|
+
type: "problem",
|
|
477
|
+
docs: {
|
|
478
|
+
description: "Disallow fallback values for environment variables as they can be dangerous in production"
|
|
479
|
+
},
|
|
480
|
+
messages: {
|
|
481
|
+
noEnvFallback: "Avoid using fallback values with process.env. Environment variables should fail explicitly when missing rather than silently using a default value."
|
|
482
|
+
},
|
|
483
|
+
schema: []
|
|
484
|
+
},
|
|
485
|
+
defaultOptions: [],
|
|
486
|
+
create(context) {
|
|
487
|
+
const isProcessEnvAccess = (node) => {
|
|
488
|
+
if (node.type !== import_utils7.AST_NODE_TYPES.MemberExpression) {
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
const { object } = node;
|
|
492
|
+
if (object.type !== import_utils7.AST_NODE_TYPES.MemberExpression) {
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
const processNode = object.object;
|
|
496
|
+
const envNode = object.property;
|
|
497
|
+
return processNode.type === import_utils7.AST_NODE_TYPES.Identifier && processNode.name === "process" && envNode.type === import_utils7.AST_NODE_TYPES.Identifier && envNode.name === "env";
|
|
498
|
+
};
|
|
499
|
+
return {
|
|
500
|
+
LogicalExpression(node) {
|
|
501
|
+
if ((node.operator === "||" || node.operator === "??") && isProcessEnvAccess(node.left)) {
|
|
502
|
+
context.report({
|
|
503
|
+
node,
|
|
504
|
+
messageId: "noEnvFallback"
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
ConditionalExpression(node) {
|
|
509
|
+
if (isProcessEnvAccess(node.test)) {
|
|
510
|
+
context.report({
|
|
511
|
+
node,
|
|
512
|
+
messageId: "noEnvFallback"
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
var no_env_fallback_default = noEnvFallback;
|
|
520
|
+
|
|
422
521
|
// src/rules/no-explicit-return-type.ts
|
|
423
|
-
var
|
|
424
|
-
var
|
|
522
|
+
var import_utils8 = require("@typescript-eslint/utils");
|
|
523
|
+
var createRule8 = import_utils8.ESLintUtils.RuleCreator(
|
|
425
524
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
426
525
|
);
|
|
427
|
-
var noExplicitReturnType =
|
|
526
|
+
var noExplicitReturnType = createRule8({
|
|
428
527
|
name: "no-explicit-return-type",
|
|
429
528
|
meta: {
|
|
430
529
|
type: "suggestion",
|
|
@@ -463,12 +562,76 @@ var noExplicitReturnType = createRule6({
|
|
|
463
562
|
});
|
|
464
563
|
var no_explicit_return_type_default = noExplicitReturnType;
|
|
465
564
|
|
|
565
|
+
// src/rules/no-logic-in-params.ts
|
|
566
|
+
var import_utils9 = require("@typescript-eslint/utils");
|
|
567
|
+
var createRule9 = import_utils9.ESLintUtils.RuleCreator(
|
|
568
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
569
|
+
);
|
|
570
|
+
var noLogicInParams = createRule9({
|
|
571
|
+
name: "no-logic-in-params",
|
|
572
|
+
meta: {
|
|
573
|
+
type: "suggestion",
|
|
574
|
+
docs: {
|
|
575
|
+
description: "Disallow logic or conditions in function parameters - extract to a const variable first"
|
|
576
|
+
},
|
|
577
|
+
messages: {
|
|
578
|
+
noLogicInParams: "Avoid logic or conditions in function parameters. Extract to a const variable first for better readability."
|
|
579
|
+
},
|
|
580
|
+
schema: []
|
|
581
|
+
},
|
|
582
|
+
defaultOptions: [],
|
|
583
|
+
create(context) {
|
|
584
|
+
const isComplexExpression = (node) => {
|
|
585
|
+
if (node.type === import_utils9.AST_NODE_TYPES.SpreadElement) {
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
if (node.type === import_utils9.AST_NODE_TYPES.ConditionalExpression) {
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
591
|
+
if (node.type === import_utils9.AST_NODE_TYPES.LogicalExpression) {
|
|
592
|
+
return true;
|
|
593
|
+
}
|
|
594
|
+
if (node.type === import_utils9.AST_NODE_TYPES.BinaryExpression) {
|
|
595
|
+
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
596
|
+
return logicalOperators.includes(node.operator);
|
|
597
|
+
}
|
|
598
|
+
if (node.type === import_utils9.AST_NODE_TYPES.UnaryExpression) {
|
|
599
|
+
return node.operator === "!";
|
|
600
|
+
}
|
|
601
|
+
return false;
|
|
602
|
+
};
|
|
603
|
+
return {
|
|
604
|
+
CallExpression(node) {
|
|
605
|
+
node.arguments.forEach((arg) => {
|
|
606
|
+
if (isComplexExpression(arg)) {
|
|
607
|
+
context.report({
|
|
608
|
+
node: arg,
|
|
609
|
+
messageId: "noLogicInParams"
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
},
|
|
614
|
+
NewExpression(node) {
|
|
615
|
+
node.arguments.forEach((arg) => {
|
|
616
|
+
if (isComplexExpression(arg)) {
|
|
617
|
+
context.report({
|
|
618
|
+
node: arg,
|
|
619
|
+
messageId: "noLogicInParams"
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
var no_logic_in_params_default = noLogicInParams;
|
|
628
|
+
|
|
466
629
|
// src/rules/prefer-destructuring-params.ts
|
|
467
|
-
var
|
|
468
|
-
var
|
|
630
|
+
var import_utils10 = require("@typescript-eslint/utils");
|
|
631
|
+
var createRule10 = import_utils10.ESLintUtils.RuleCreator(
|
|
469
632
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
470
633
|
);
|
|
471
|
-
var preferDestructuringParams =
|
|
634
|
+
var preferDestructuringParams = createRule10({
|
|
472
635
|
name: "prefer-destructuring-params",
|
|
473
636
|
meta: {
|
|
474
637
|
type: "suggestion",
|
|
@@ -484,18 +647,18 @@ var preferDestructuringParams = createRule7({
|
|
|
484
647
|
create(context) {
|
|
485
648
|
const isCallbackFunction = (node) => {
|
|
486
649
|
const { parent } = node;
|
|
487
|
-
return parent?.type ===
|
|
650
|
+
return parent?.type === import_utils10.AST_NODE_TYPES.CallExpression;
|
|
488
651
|
};
|
|
489
652
|
const isDeveloperFunction = (node) => {
|
|
490
|
-
if (node.type ===
|
|
653
|
+
if (node.type === import_utils10.AST_NODE_TYPES.FunctionDeclaration) {
|
|
491
654
|
return true;
|
|
492
655
|
}
|
|
493
|
-
if (node.type ===
|
|
656
|
+
if (node.type === import_utils10.AST_NODE_TYPES.FunctionExpression || node.type === import_utils10.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
494
657
|
if (isCallbackFunction(node)) {
|
|
495
658
|
return false;
|
|
496
659
|
}
|
|
497
660
|
const { parent } = node;
|
|
498
|
-
return parent?.type ===
|
|
661
|
+
return parent?.type === import_utils10.AST_NODE_TYPES.VariableDeclarator || parent?.type === import_utils10.AST_NODE_TYPES.AssignmentExpression || parent?.type === import_utils10.AST_NODE_TYPES.Property || parent?.type === import_utils10.AST_NODE_TYPES.MethodDefinition;
|
|
499
662
|
}
|
|
500
663
|
return false;
|
|
501
664
|
};
|
|
@@ -507,7 +670,7 @@ var preferDestructuringParams = createRule7({
|
|
|
507
670
|
if (!isDeveloperFunction(node)) {
|
|
508
671
|
return;
|
|
509
672
|
}
|
|
510
|
-
if (node.type ===
|
|
673
|
+
if (node.type === import_utils10.AST_NODE_TYPES.FunctionDeclaration && node.id) {
|
|
511
674
|
const functionName = node.id.name;
|
|
512
675
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
513
676
|
return;
|
|
@@ -517,7 +680,7 @@ var preferDestructuringParams = createRule7({
|
|
|
517
680
|
return;
|
|
518
681
|
}
|
|
519
682
|
const hasNonDestructuredParams = node.params.some(
|
|
520
|
-
(param) => param.type !==
|
|
683
|
+
(param) => param.type !== import_utils10.AST_NODE_TYPES.ObjectPattern && param.type !== import_utils10.AST_NODE_TYPES.RestElement
|
|
521
684
|
);
|
|
522
685
|
if (hasNonDestructuredParams) {
|
|
523
686
|
context.report({
|
|
@@ -536,11 +699,11 @@ var preferDestructuringParams = createRule7({
|
|
|
536
699
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
537
700
|
|
|
538
701
|
// src/rules/prefer-import-type.ts
|
|
539
|
-
var
|
|
540
|
-
var
|
|
702
|
+
var import_utils11 = require("@typescript-eslint/utils");
|
|
703
|
+
var createRule11 = import_utils11.ESLintUtils.RuleCreator(
|
|
541
704
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
542
705
|
);
|
|
543
|
-
var preferImportType =
|
|
706
|
+
var preferImportType = createRule11({
|
|
544
707
|
name: "prefer-import-type",
|
|
545
708
|
meta: {
|
|
546
709
|
type: "suggestion",
|
|
@@ -571,14 +734,14 @@ var preferImportType = createRule8({
|
|
|
571
734
|
return;
|
|
572
735
|
}
|
|
573
736
|
const isTypeOnlyImport = node.specifiers.every((specifier) => {
|
|
574
|
-
if (specifier.type ===
|
|
737
|
+
if (specifier.type === import_utils11.AST_NODE_TYPES.ImportDefaultSpecifier) {
|
|
575
738
|
return false;
|
|
576
739
|
}
|
|
577
|
-
if (specifier.type ===
|
|
740
|
+
if (specifier.type === import_utils11.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
578
741
|
return false;
|
|
579
742
|
}
|
|
580
|
-
if (specifier.type ===
|
|
581
|
-
const importedName = specifier.imported.type ===
|
|
743
|
+
if (specifier.type === import_utils11.AST_NODE_TYPES.ImportSpecifier) {
|
|
744
|
+
const importedName = specifier.imported.type === import_utils11.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
582
745
|
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
746
|
importedName
|
|
584
747
|
) || importedName.endsWith("Type") || importedName.endsWith("Interface") || importedName.endsWith("Props");
|
|
@@ -606,11 +769,11 @@ var preferImportType = createRule8({
|
|
|
606
769
|
var prefer_import_type_default = preferImportType;
|
|
607
770
|
|
|
608
771
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
609
|
-
var
|
|
610
|
-
var
|
|
772
|
+
var import_utils12 = require("@typescript-eslint/utils");
|
|
773
|
+
var createRule12 = import_utils12.ESLintUtils.RuleCreator(
|
|
611
774
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
612
775
|
);
|
|
613
|
-
var preferInterfaceOverInlineTypes =
|
|
776
|
+
var preferInterfaceOverInlineTypes = createRule12({
|
|
614
777
|
name: "prefer-interface-over-inline-types",
|
|
615
778
|
meta: {
|
|
616
779
|
type: "suggestion",
|
|
@@ -626,54 +789,54 @@ var preferInterfaceOverInlineTypes = createRule9({
|
|
|
626
789
|
defaultOptions: [],
|
|
627
790
|
create(context) {
|
|
628
791
|
function hasJSXInConditional(node) {
|
|
629
|
-
return node.consequent.type ===
|
|
792
|
+
return node.consequent.type === import_utils12.AST_NODE_TYPES.JSXElement || node.consequent.type === import_utils12.AST_NODE_TYPES.JSXFragment || node.alternate.type === import_utils12.AST_NODE_TYPES.JSXElement || node.alternate.type === import_utils12.AST_NODE_TYPES.JSXFragment;
|
|
630
793
|
}
|
|
631
794
|
function hasJSXInLogical(node) {
|
|
632
|
-
return node.right.type ===
|
|
795
|
+
return node.right.type === import_utils12.AST_NODE_TYPES.JSXElement || node.right.type === import_utils12.AST_NODE_TYPES.JSXFragment;
|
|
633
796
|
}
|
|
634
797
|
function hasJSXReturn(block) {
|
|
635
798
|
return block.body.some((stmt) => {
|
|
636
|
-
if (stmt.type ===
|
|
637
|
-
return stmt.argument.type ===
|
|
799
|
+
if (stmt.type === import_utils12.AST_NODE_TYPES.ReturnStatement && stmt.argument) {
|
|
800
|
+
return stmt.argument.type === import_utils12.AST_NODE_TYPES.JSXElement || stmt.argument.type === import_utils12.AST_NODE_TYPES.JSXFragment || stmt.argument.type === import_utils12.AST_NODE_TYPES.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === import_utils12.AST_NODE_TYPES.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
638
801
|
}
|
|
639
802
|
return false;
|
|
640
803
|
});
|
|
641
804
|
}
|
|
642
805
|
function isReactComponent(node) {
|
|
643
|
-
if (node.type ===
|
|
644
|
-
if (node.body.type ===
|
|
806
|
+
if (node.type === import_utils12.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
807
|
+
if (node.body.type === import_utils12.AST_NODE_TYPES.JSXElement || node.body.type === import_utils12.AST_NODE_TYPES.JSXFragment) {
|
|
645
808
|
return true;
|
|
646
809
|
}
|
|
647
|
-
if (node.body.type ===
|
|
810
|
+
if (node.body.type === import_utils12.AST_NODE_TYPES.BlockStatement) {
|
|
648
811
|
return hasJSXReturn(node.body);
|
|
649
812
|
}
|
|
650
|
-
} else if (node.type ===
|
|
651
|
-
if (node.body && node.body.type ===
|
|
813
|
+
} else if (node.type === import_utils12.AST_NODE_TYPES.FunctionExpression || node.type === import_utils12.AST_NODE_TYPES.FunctionDeclaration) {
|
|
814
|
+
if (node.body && node.body.type === import_utils12.AST_NODE_TYPES.BlockStatement) {
|
|
652
815
|
return hasJSXReturn(node.body);
|
|
653
816
|
}
|
|
654
817
|
}
|
|
655
818
|
return false;
|
|
656
819
|
}
|
|
657
820
|
function isInlineTypeAnnotation(node) {
|
|
658
|
-
if (node.type ===
|
|
821
|
+
if (node.type === import_utils12.AST_NODE_TYPES.TSTypeLiteral) {
|
|
659
822
|
return true;
|
|
660
823
|
}
|
|
661
|
-
if (node.type ===
|
|
662
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
824
|
+
if (node.type === import_utils12.AST_NODE_TYPES.TSTypeReference && node.typeArguments) {
|
|
825
|
+
return node.typeArguments.params.some((param) => param.type === import_utils12.AST_NODE_TYPES.TSTypeLiteral);
|
|
663
826
|
}
|
|
664
|
-
if (node.type ===
|
|
827
|
+
if (node.type === import_utils12.AST_NODE_TYPES.TSUnionType) {
|
|
665
828
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
666
829
|
}
|
|
667
830
|
return false;
|
|
668
831
|
}
|
|
669
832
|
function hasInlineObjectType(node) {
|
|
670
|
-
if (node.type ===
|
|
833
|
+
if (node.type === import_utils12.AST_NODE_TYPES.TSTypeLiteral) {
|
|
671
834
|
return true;
|
|
672
835
|
}
|
|
673
|
-
if (node.type ===
|
|
674
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
836
|
+
if (node.type === import_utils12.AST_NODE_TYPES.TSTypeReference && node.typeArguments) {
|
|
837
|
+
return node.typeArguments.params.some((param) => param.type === import_utils12.AST_NODE_TYPES.TSTypeLiteral);
|
|
675
838
|
}
|
|
676
|
-
if (node.type ===
|
|
839
|
+
if (node.type === import_utils12.AST_NODE_TYPES.TSUnionType) {
|
|
677
840
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
678
841
|
}
|
|
679
842
|
return false;
|
|
@@ -686,7 +849,7 @@ var preferInterfaceOverInlineTypes = createRule9({
|
|
|
686
849
|
return;
|
|
687
850
|
}
|
|
688
851
|
const param = node.params[0];
|
|
689
|
-
if (param.type ===
|
|
852
|
+
if (param.type === import_utils12.AST_NODE_TYPES.Identifier && param.typeAnnotation) {
|
|
690
853
|
const { typeAnnotation } = param.typeAnnotation;
|
|
691
854
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
692
855
|
context.report({
|
|
@@ -706,11 +869,11 @@ var preferInterfaceOverInlineTypes = createRule9({
|
|
|
706
869
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
707
870
|
|
|
708
871
|
// src/rules/prefer-named-param-types.ts
|
|
709
|
-
var
|
|
710
|
-
var
|
|
872
|
+
var import_utils13 = require("@typescript-eslint/utils");
|
|
873
|
+
var createRule13 = import_utils13.ESLintUtils.RuleCreator(
|
|
711
874
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
712
875
|
);
|
|
713
|
-
var preferNamedParamTypes =
|
|
876
|
+
var preferNamedParamTypes = createRule13({
|
|
714
877
|
name: "prefer-named-param-types",
|
|
715
878
|
meta: {
|
|
716
879
|
type: "suggestion",
|
|
@@ -725,16 +888,16 @@ var preferNamedParamTypes = createRule10({
|
|
|
725
888
|
defaultOptions: [],
|
|
726
889
|
create(context) {
|
|
727
890
|
function hasInlineObjectType(param) {
|
|
728
|
-
if (param.type ===
|
|
891
|
+
if (param.type === import_utils13.AST_NODE_TYPES.AssignmentPattern) {
|
|
729
892
|
return hasInlineObjectType(param.left);
|
|
730
893
|
}
|
|
731
|
-
if (param.type ===
|
|
732
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
894
|
+
if (param.type === import_utils13.AST_NODE_TYPES.ObjectPattern) {
|
|
895
|
+
if (param.typeAnnotation?.typeAnnotation.type === import_utils13.AST_NODE_TYPES.TSTypeLiteral) {
|
|
733
896
|
return true;
|
|
734
897
|
}
|
|
735
898
|
}
|
|
736
|
-
if (param.type ===
|
|
737
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
899
|
+
if (param.type === import_utils13.AST_NODE_TYPES.Identifier) {
|
|
900
|
+
if (param.typeAnnotation?.typeAnnotation.type === import_utils13.AST_NODE_TYPES.TSTypeLiteral) {
|
|
738
901
|
return true;
|
|
739
902
|
}
|
|
740
903
|
}
|
|
@@ -768,11 +931,11 @@ var preferNamedParamTypes = createRule10({
|
|
|
768
931
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
769
932
|
|
|
770
933
|
// src/rules/prefer-react-import-types.ts
|
|
771
|
-
var
|
|
772
|
-
var
|
|
934
|
+
var import_utils14 = require("@typescript-eslint/utils");
|
|
935
|
+
var createRule14 = import_utils14.ESLintUtils.RuleCreator(
|
|
773
936
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
774
937
|
);
|
|
775
|
-
var preferReactImportTypes =
|
|
938
|
+
var preferReactImportTypes = createRule14({
|
|
776
939
|
name: "prefer-react-import-types",
|
|
777
940
|
meta: {
|
|
778
941
|
type: "suggestion",
|
|
@@ -848,7 +1011,7 @@ var preferReactImportTypes = createRule11({
|
|
|
848
1011
|
]);
|
|
849
1012
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
850
1013
|
function checkMemberExpression(node) {
|
|
851
|
-
if (node.object.type ===
|
|
1014
|
+
if (node.object.type === import_utils14.AST_NODE_TYPES.Identifier && node.object.name === "React" && node.property.type === import_utils14.AST_NODE_TYPES.Identifier && allReactExports.has(node.property.name)) {
|
|
852
1015
|
const typeName = node.property.name;
|
|
853
1016
|
const isType = reactTypes.has(typeName);
|
|
854
1017
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -865,7 +1028,7 @@ var preferReactImportTypes = createRule11({
|
|
|
865
1028
|
return {
|
|
866
1029
|
MemberExpression: checkMemberExpression,
|
|
867
1030
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
868
|
-
if (node.left.type ===
|
|
1031
|
+
if (node.left.type === import_utils14.AST_NODE_TYPES.Identifier && node.left.name === "React" && node.right.type === import_utils14.AST_NODE_TYPES.Identifier && allReactExports.has(node.right.name)) {
|
|
869
1032
|
const typeName = node.right.name;
|
|
870
1033
|
const isType = reactTypes.has(typeName);
|
|
871
1034
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -885,11 +1048,11 @@ var preferReactImportTypes = createRule11({
|
|
|
885
1048
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
886
1049
|
|
|
887
1050
|
// src/rules/react-props-destructure.ts
|
|
888
|
-
var
|
|
889
|
-
var
|
|
1051
|
+
var import_utils15 = require("@typescript-eslint/utils");
|
|
1052
|
+
var createRule15 = import_utils15.ESLintUtils.RuleCreator(
|
|
890
1053
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
891
1054
|
);
|
|
892
|
-
var reactPropsDestructure =
|
|
1055
|
+
var reactPropsDestructure = createRule15({
|
|
893
1056
|
name: "react-props-destructure",
|
|
894
1057
|
meta: {
|
|
895
1058
|
type: "suggestion",
|
|
@@ -905,29 +1068,29 @@ var reactPropsDestructure = createRule12({
|
|
|
905
1068
|
defaultOptions: [],
|
|
906
1069
|
create(context) {
|
|
907
1070
|
function hasJSXInConditional(node) {
|
|
908
|
-
return node.consequent.type ===
|
|
1071
|
+
return node.consequent.type === import_utils15.AST_NODE_TYPES.JSXElement || node.consequent.type === import_utils15.AST_NODE_TYPES.JSXFragment || node.alternate.type === import_utils15.AST_NODE_TYPES.JSXElement || node.alternate.type === import_utils15.AST_NODE_TYPES.JSXFragment;
|
|
909
1072
|
}
|
|
910
1073
|
function hasJSXInLogical(node) {
|
|
911
|
-
return node.right.type ===
|
|
1074
|
+
return node.right.type === import_utils15.AST_NODE_TYPES.JSXElement || node.right.type === import_utils15.AST_NODE_TYPES.JSXFragment;
|
|
912
1075
|
}
|
|
913
1076
|
function hasJSXReturn(block) {
|
|
914
1077
|
return block.body.some((stmt) => {
|
|
915
|
-
if (stmt.type ===
|
|
916
|
-
return stmt.argument.type ===
|
|
1078
|
+
if (stmt.type === import_utils15.AST_NODE_TYPES.ReturnStatement && stmt.argument) {
|
|
1079
|
+
return stmt.argument.type === import_utils15.AST_NODE_TYPES.JSXElement || stmt.argument.type === import_utils15.AST_NODE_TYPES.JSXFragment || stmt.argument.type === import_utils15.AST_NODE_TYPES.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === import_utils15.AST_NODE_TYPES.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
917
1080
|
}
|
|
918
1081
|
return false;
|
|
919
1082
|
});
|
|
920
1083
|
}
|
|
921
1084
|
function isReactComponent(node) {
|
|
922
|
-
if (node.type ===
|
|
923
|
-
if (node.body.type ===
|
|
1085
|
+
if (node.type === import_utils15.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
1086
|
+
if (node.body.type === import_utils15.AST_NODE_TYPES.JSXElement || node.body.type === import_utils15.AST_NODE_TYPES.JSXFragment) {
|
|
924
1087
|
return true;
|
|
925
1088
|
}
|
|
926
|
-
if (node.body.type ===
|
|
1089
|
+
if (node.body.type === import_utils15.AST_NODE_TYPES.BlockStatement) {
|
|
927
1090
|
return hasJSXReturn(node.body);
|
|
928
1091
|
}
|
|
929
|
-
} else if (node.type ===
|
|
930
|
-
if (node.body && node.body.type ===
|
|
1092
|
+
} else if (node.type === import_utils15.AST_NODE_TYPES.FunctionExpression || node.type === import_utils15.AST_NODE_TYPES.FunctionDeclaration) {
|
|
1093
|
+
if (node.body && node.body.type === import_utils15.AST_NODE_TYPES.BlockStatement) {
|
|
931
1094
|
return hasJSXReturn(node.body);
|
|
932
1095
|
}
|
|
933
1096
|
}
|
|
@@ -941,9 +1104,9 @@ var reactPropsDestructure = createRule12({
|
|
|
941
1104
|
return;
|
|
942
1105
|
}
|
|
943
1106
|
const param = node.params[0];
|
|
944
|
-
if (param.type ===
|
|
945
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
946
|
-
if (prop.key.type ===
|
|
1107
|
+
if (param.type === import_utils15.AST_NODE_TYPES.ObjectPattern) {
|
|
1108
|
+
const properties = param.properties.filter((prop) => prop.type === import_utils15.AST_NODE_TYPES.Property).map((prop) => {
|
|
1109
|
+
if (prop.key.type === import_utils15.AST_NODE_TYPES.Identifier) {
|
|
947
1110
|
return prop.key.name;
|
|
948
1111
|
}
|
|
949
1112
|
return null;
|
|
@@ -979,8 +1142,11 @@ var rules = {
|
|
|
979
1142
|
"file-kebab-case": file_kebab_case_default,
|
|
980
1143
|
"jsx-pascal-case": jsx_pascal_case_default,
|
|
981
1144
|
"md-filename-case-restriction": md_filename_case_restriction_default,
|
|
1145
|
+
"no-complex-inline-return": no_complex_inline_return_default,
|
|
982
1146
|
"no-emoji": no_emoji_default,
|
|
1147
|
+
"no-env-fallback": no_env_fallback_default,
|
|
983
1148
|
"no-explicit-return-type": no_explicit_return_type_default,
|
|
1149
|
+
"no-logic-in-params": no_logic_in_params_default,
|
|
984
1150
|
"prefer-destructuring-params": prefer_destructuring_params_default,
|
|
985
1151
|
"prefer-import-type": prefer_import_type_default,
|
|
986
1152
|
"prefer-interface-over-inline-types": prefer_interface_over_inline_types_default,
|
|
@@ -1000,7 +1166,10 @@ var baseRules = {
|
|
|
1000
1166
|
"nextfriday/no-explicit-return-type": "warn",
|
|
1001
1167
|
"nextfriday/prefer-import-type": "warn",
|
|
1002
1168
|
"nextfriday/prefer-named-param-types": "warn",
|
|
1003
|
-
"nextfriday/prefer-react-import-types": "warn"
|
|
1169
|
+
"nextfriday/prefer-react-import-types": "warn",
|
|
1170
|
+
"nextfriday/no-complex-inline-return": "warn",
|
|
1171
|
+
"nextfriday/no-logic-in-params": "warn",
|
|
1172
|
+
"nextfriday/no-env-fallback": "warn"
|
|
1004
1173
|
};
|
|
1005
1174
|
var baseRecommendedRules = {
|
|
1006
1175
|
"nextfriday/no-emoji": "error",
|
|
@@ -1010,7 +1179,10 @@ var baseRecommendedRules = {
|
|
|
1010
1179
|
"nextfriday/no-explicit-return-type": "error",
|
|
1011
1180
|
"nextfriday/prefer-import-type": "error",
|
|
1012
1181
|
"nextfriday/prefer-named-param-types": "error",
|
|
1013
|
-
"nextfriday/prefer-react-import-types": "error"
|
|
1182
|
+
"nextfriday/prefer-react-import-types": "error",
|
|
1183
|
+
"nextfriday/no-complex-inline-return": "error",
|
|
1184
|
+
"nextfriday/no-logic-in-params": "error",
|
|
1185
|
+
"nextfriday/no-env-fallback": "error"
|
|
1014
1186
|
};
|
|
1015
1187
|
var jsxRules = {
|
|
1016
1188
|
"nextfriday/jsx-pascal-case": "warn",
|