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.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "eslint-plugin-nextfriday",
|
|
4
|
-
version: "1.
|
|
4
|
+
version: "1.5.0",
|
|
5
5
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
6
6
|
keywords: [
|
|
7
7
|
"eslint",
|
|
@@ -51,8 +51,8 @@ var package_default = {
|
|
|
51
51
|
"changeset:publish": "npm publish --provenance --access public",
|
|
52
52
|
"changeset:version": "changeset version",
|
|
53
53
|
clear: "rm -rf lib node_modules/.cache .eslintcache",
|
|
54
|
-
eslint: "eslint src --ext .js,.ts
|
|
55
|
-
"eslint:check": "eslint src --ext .js,.ts
|
|
54
|
+
eslint: "eslint src --ext .js,.ts --fix",
|
|
55
|
+
"eslint:check": "eslint src --ext .js,.ts",
|
|
56
56
|
preinstall: "npx only-allow pnpm",
|
|
57
57
|
prepare: "husky",
|
|
58
58
|
prepublishOnly: "pnpm run build",
|
|
@@ -341,13 +341,59 @@ var mdFilenameCaseRestriction = createRule4({
|
|
|
341
341
|
});
|
|
342
342
|
var md_filename_case_restriction_default = mdFilenameCaseRestriction;
|
|
343
343
|
|
|
344
|
+
// src/rules/no-complex-inline-return.ts
|
|
345
|
+
import { ESLintUtils as ESLintUtils5, AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/utils";
|
|
346
|
+
var createRule5 = ESLintUtils5.RuleCreator(
|
|
347
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
348
|
+
);
|
|
349
|
+
var noComplexInlineReturn = createRule5({
|
|
350
|
+
name: "no-complex-inline-return",
|
|
351
|
+
meta: {
|
|
352
|
+
type: "suggestion",
|
|
353
|
+
docs: {
|
|
354
|
+
description: "Disallow complex inline expressions in return statements - prefer extracting to a const first"
|
|
355
|
+
},
|
|
356
|
+
messages: {
|
|
357
|
+
noComplexInlineReturn: "Avoid returning complex expressions directly. Extract to a const variable first for better readability."
|
|
358
|
+
},
|
|
359
|
+
schema: []
|
|
360
|
+
},
|
|
361
|
+
defaultOptions: [],
|
|
362
|
+
create(context) {
|
|
363
|
+
const isComplexExpression = (node) => {
|
|
364
|
+
if (!node) return false;
|
|
365
|
+
if (node.type === AST_NODE_TYPES2.ConditionalExpression) {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
if (node.type === AST_NODE_TYPES2.LogicalExpression) {
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
if (node.type === AST_NODE_TYPES2.NewExpression) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
return false;
|
|
375
|
+
};
|
|
376
|
+
return {
|
|
377
|
+
ReturnStatement(node) {
|
|
378
|
+
if (node.argument && isComplexExpression(node.argument)) {
|
|
379
|
+
context.report({
|
|
380
|
+
node: node.argument,
|
|
381
|
+
messageId: "noComplexInlineReturn"
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
var no_complex_inline_return_default = noComplexInlineReturn;
|
|
389
|
+
|
|
344
390
|
// src/rules/no-emoji.ts
|
|
345
391
|
import emojiRegex from "emoji-regex";
|
|
346
|
-
import { ESLintUtils as
|
|
347
|
-
var
|
|
392
|
+
import { ESLintUtils as ESLintUtils6 } from "@typescript-eslint/utils";
|
|
393
|
+
var createRule6 = ESLintUtils6.RuleCreator(
|
|
348
394
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
349
395
|
);
|
|
350
|
-
var noEmoji =
|
|
396
|
+
var noEmoji = createRule6({
|
|
351
397
|
name: "no-emoji",
|
|
352
398
|
meta: {
|
|
353
399
|
type: "problem",
|
|
@@ -380,12 +426,65 @@ var noEmoji = createRule5({
|
|
|
380
426
|
});
|
|
381
427
|
var no_emoji_default = noEmoji;
|
|
382
428
|
|
|
429
|
+
// src/rules/no-env-fallback.ts
|
|
430
|
+
import { ESLintUtils as ESLintUtils7, AST_NODE_TYPES as AST_NODE_TYPES3 } from "@typescript-eslint/utils";
|
|
431
|
+
var createRule7 = ESLintUtils7.RuleCreator(
|
|
432
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
433
|
+
);
|
|
434
|
+
var noEnvFallback = createRule7({
|
|
435
|
+
name: "no-env-fallback",
|
|
436
|
+
meta: {
|
|
437
|
+
type: "problem",
|
|
438
|
+
docs: {
|
|
439
|
+
description: "Disallow fallback values for environment variables as they can be dangerous in production"
|
|
440
|
+
},
|
|
441
|
+
messages: {
|
|
442
|
+
noEnvFallback: "Avoid using fallback values with process.env. Environment variables should fail explicitly when missing rather than silently using a default value."
|
|
443
|
+
},
|
|
444
|
+
schema: []
|
|
445
|
+
},
|
|
446
|
+
defaultOptions: [],
|
|
447
|
+
create(context) {
|
|
448
|
+
const isProcessEnvAccess = (node) => {
|
|
449
|
+
if (node.type !== AST_NODE_TYPES3.MemberExpression) {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
const { object } = node;
|
|
453
|
+
if (object.type !== AST_NODE_TYPES3.MemberExpression) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
const processNode = object.object;
|
|
457
|
+
const envNode = object.property;
|
|
458
|
+
return processNode.type === AST_NODE_TYPES3.Identifier && processNode.name === "process" && envNode.type === AST_NODE_TYPES3.Identifier && envNode.name === "env";
|
|
459
|
+
};
|
|
460
|
+
return {
|
|
461
|
+
LogicalExpression(node) {
|
|
462
|
+
if ((node.operator === "||" || node.operator === "??") && isProcessEnvAccess(node.left)) {
|
|
463
|
+
context.report({
|
|
464
|
+
node,
|
|
465
|
+
messageId: "noEnvFallback"
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
ConditionalExpression(node) {
|
|
470
|
+
if (isProcessEnvAccess(node.test)) {
|
|
471
|
+
context.report({
|
|
472
|
+
node,
|
|
473
|
+
messageId: "noEnvFallback"
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
var no_env_fallback_default = noEnvFallback;
|
|
481
|
+
|
|
383
482
|
// src/rules/no-explicit-return-type.ts
|
|
384
|
-
import { ESLintUtils as
|
|
385
|
-
var
|
|
483
|
+
import { ESLintUtils as ESLintUtils8 } from "@typescript-eslint/utils";
|
|
484
|
+
var createRule8 = ESLintUtils8.RuleCreator(
|
|
386
485
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
387
486
|
);
|
|
388
|
-
var noExplicitReturnType =
|
|
487
|
+
var noExplicitReturnType = createRule8({
|
|
389
488
|
name: "no-explicit-return-type",
|
|
390
489
|
meta: {
|
|
391
490
|
type: "suggestion",
|
|
@@ -424,12 +523,76 @@ var noExplicitReturnType = createRule6({
|
|
|
424
523
|
});
|
|
425
524
|
var no_explicit_return_type_default = noExplicitReturnType;
|
|
426
525
|
|
|
526
|
+
// src/rules/no-logic-in-params.ts
|
|
527
|
+
import { ESLintUtils as ESLintUtils9, AST_NODE_TYPES as AST_NODE_TYPES4 } from "@typescript-eslint/utils";
|
|
528
|
+
var createRule9 = ESLintUtils9.RuleCreator(
|
|
529
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
530
|
+
);
|
|
531
|
+
var noLogicInParams = createRule9({
|
|
532
|
+
name: "no-logic-in-params",
|
|
533
|
+
meta: {
|
|
534
|
+
type: "suggestion",
|
|
535
|
+
docs: {
|
|
536
|
+
description: "Disallow logic or conditions in function parameters - extract to a const variable first"
|
|
537
|
+
},
|
|
538
|
+
messages: {
|
|
539
|
+
noLogicInParams: "Avoid logic or conditions in function parameters. Extract to a const variable first for better readability."
|
|
540
|
+
},
|
|
541
|
+
schema: []
|
|
542
|
+
},
|
|
543
|
+
defaultOptions: [],
|
|
544
|
+
create(context) {
|
|
545
|
+
const isComplexExpression = (node) => {
|
|
546
|
+
if (node.type === AST_NODE_TYPES4.SpreadElement) {
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
if (node.type === AST_NODE_TYPES4.ConditionalExpression) {
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
if (node.type === AST_NODE_TYPES4.LogicalExpression) {
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
if (node.type === AST_NODE_TYPES4.BinaryExpression) {
|
|
556
|
+
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
557
|
+
return logicalOperators.includes(node.operator);
|
|
558
|
+
}
|
|
559
|
+
if (node.type === AST_NODE_TYPES4.UnaryExpression) {
|
|
560
|
+
return node.operator === "!";
|
|
561
|
+
}
|
|
562
|
+
return false;
|
|
563
|
+
};
|
|
564
|
+
return {
|
|
565
|
+
CallExpression(node) {
|
|
566
|
+
node.arguments.forEach((arg) => {
|
|
567
|
+
if (isComplexExpression(arg)) {
|
|
568
|
+
context.report({
|
|
569
|
+
node: arg,
|
|
570
|
+
messageId: "noLogicInParams"
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
},
|
|
575
|
+
NewExpression(node) {
|
|
576
|
+
node.arguments.forEach((arg) => {
|
|
577
|
+
if (isComplexExpression(arg)) {
|
|
578
|
+
context.report({
|
|
579
|
+
node: arg,
|
|
580
|
+
messageId: "noLogicInParams"
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
var no_logic_in_params_default = noLogicInParams;
|
|
589
|
+
|
|
427
590
|
// src/rules/prefer-destructuring-params.ts
|
|
428
|
-
import { AST_NODE_TYPES as
|
|
429
|
-
var
|
|
591
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES5, ESLintUtils as ESLintUtils10 } from "@typescript-eslint/utils";
|
|
592
|
+
var createRule10 = ESLintUtils10.RuleCreator(
|
|
430
593
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
431
594
|
);
|
|
432
|
-
var preferDestructuringParams =
|
|
595
|
+
var preferDestructuringParams = createRule10({
|
|
433
596
|
name: "prefer-destructuring-params",
|
|
434
597
|
meta: {
|
|
435
598
|
type: "suggestion",
|
|
@@ -445,18 +608,18 @@ var preferDestructuringParams = createRule7({
|
|
|
445
608
|
create(context) {
|
|
446
609
|
const isCallbackFunction = (node) => {
|
|
447
610
|
const { parent } = node;
|
|
448
|
-
return parent?.type ===
|
|
611
|
+
return parent?.type === AST_NODE_TYPES5.CallExpression;
|
|
449
612
|
};
|
|
450
613
|
const isDeveloperFunction = (node) => {
|
|
451
|
-
if (node.type ===
|
|
614
|
+
if (node.type === AST_NODE_TYPES5.FunctionDeclaration) {
|
|
452
615
|
return true;
|
|
453
616
|
}
|
|
454
|
-
if (node.type ===
|
|
617
|
+
if (node.type === AST_NODE_TYPES5.FunctionExpression || node.type === AST_NODE_TYPES5.ArrowFunctionExpression) {
|
|
455
618
|
if (isCallbackFunction(node)) {
|
|
456
619
|
return false;
|
|
457
620
|
}
|
|
458
621
|
const { parent } = node;
|
|
459
|
-
return parent?.type ===
|
|
622
|
+
return parent?.type === AST_NODE_TYPES5.VariableDeclarator || parent?.type === AST_NODE_TYPES5.AssignmentExpression || parent?.type === AST_NODE_TYPES5.Property || parent?.type === AST_NODE_TYPES5.MethodDefinition;
|
|
460
623
|
}
|
|
461
624
|
return false;
|
|
462
625
|
};
|
|
@@ -468,7 +631,7 @@ var preferDestructuringParams = createRule7({
|
|
|
468
631
|
if (!isDeveloperFunction(node)) {
|
|
469
632
|
return;
|
|
470
633
|
}
|
|
471
|
-
if (node.type ===
|
|
634
|
+
if (node.type === AST_NODE_TYPES5.FunctionDeclaration && node.id) {
|
|
472
635
|
const functionName = node.id.name;
|
|
473
636
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
474
637
|
return;
|
|
@@ -478,7 +641,7 @@ var preferDestructuringParams = createRule7({
|
|
|
478
641
|
return;
|
|
479
642
|
}
|
|
480
643
|
const hasNonDestructuredParams = node.params.some(
|
|
481
|
-
(param) => param.type !==
|
|
644
|
+
(param) => param.type !== AST_NODE_TYPES5.ObjectPattern && param.type !== AST_NODE_TYPES5.RestElement
|
|
482
645
|
);
|
|
483
646
|
if (hasNonDestructuredParams) {
|
|
484
647
|
context.report({
|
|
@@ -497,11 +660,11 @@ var preferDestructuringParams = createRule7({
|
|
|
497
660
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
498
661
|
|
|
499
662
|
// src/rules/prefer-import-type.ts
|
|
500
|
-
import { AST_NODE_TYPES as
|
|
501
|
-
var
|
|
663
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES6, ESLintUtils as ESLintUtils11 } from "@typescript-eslint/utils";
|
|
664
|
+
var createRule11 = ESLintUtils11.RuleCreator(
|
|
502
665
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
503
666
|
);
|
|
504
|
-
var preferImportType =
|
|
667
|
+
var preferImportType = createRule11({
|
|
505
668
|
name: "prefer-import-type",
|
|
506
669
|
meta: {
|
|
507
670
|
type: "suggestion",
|
|
@@ -532,14 +695,14 @@ var preferImportType = createRule8({
|
|
|
532
695
|
return;
|
|
533
696
|
}
|
|
534
697
|
const isTypeOnlyImport = node.specifiers.every((specifier) => {
|
|
535
|
-
if (specifier.type ===
|
|
698
|
+
if (specifier.type === AST_NODE_TYPES6.ImportDefaultSpecifier) {
|
|
536
699
|
return false;
|
|
537
700
|
}
|
|
538
|
-
if (specifier.type ===
|
|
701
|
+
if (specifier.type === AST_NODE_TYPES6.ImportNamespaceSpecifier) {
|
|
539
702
|
return false;
|
|
540
703
|
}
|
|
541
|
-
if (specifier.type ===
|
|
542
|
-
const importedName = specifier.imported.type ===
|
|
704
|
+
if (specifier.type === AST_NODE_TYPES6.ImportSpecifier) {
|
|
705
|
+
const importedName = specifier.imported.type === AST_NODE_TYPES6.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
543
706
|
const isKnownTypeOnly = node.source.value === "@typescript-eslint/utils" && ["TSESTree", "RuleContext"].includes(importedName) || node.source.value === "react" && ["Component", "ComponentProps", "ReactNode", "FC", "JSX", "ReactElement", "PropsWithChildren"].includes(
|
|
544
707
|
importedName
|
|
545
708
|
) || importedName.endsWith("Type") || importedName.endsWith("Interface") || importedName.endsWith("Props");
|
|
@@ -567,11 +730,11 @@ var preferImportType = createRule8({
|
|
|
567
730
|
var prefer_import_type_default = preferImportType;
|
|
568
731
|
|
|
569
732
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
570
|
-
import { AST_NODE_TYPES as
|
|
571
|
-
var
|
|
733
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES7, ESLintUtils as ESLintUtils12 } from "@typescript-eslint/utils";
|
|
734
|
+
var createRule12 = ESLintUtils12.RuleCreator(
|
|
572
735
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
573
736
|
);
|
|
574
|
-
var preferInterfaceOverInlineTypes =
|
|
737
|
+
var preferInterfaceOverInlineTypes = createRule12({
|
|
575
738
|
name: "prefer-interface-over-inline-types",
|
|
576
739
|
meta: {
|
|
577
740
|
type: "suggestion",
|
|
@@ -587,54 +750,54 @@ var preferInterfaceOverInlineTypes = createRule9({
|
|
|
587
750
|
defaultOptions: [],
|
|
588
751
|
create(context) {
|
|
589
752
|
function hasJSXInConditional(node) {
|
|
590
|
-
return node.consequent.type ===
|
|
753
|
+
return node.consequent.type === AST_NODE_TYPES7.JSXElement || node.consequent.type === AST_NODE_TYPES7.JSXFragment || node.alternate.type === AST_NODE_TYPES7.JSXElement || node.alternate.type === AST_NODE_TYPES7.JSXFragment;
|
|
591
754
|
}
|
|
592
755
|
function hasJSXInLogical(node) {
|
|
593
|
-
return node.right.type ===
|
|
756
|
+
return node.right.type === AST_NODE_TYPES7.JSXElement || node.right.type === AST_NODE_TYPES7.JSXFragment;
|
|
594
757
|
}
|
|
595
758
|
function hasJSXReturn(block) {
|
|
596
759
|
return block.body.some((stmt) => {
|
|
597
|
-
if (stmt.type ===
|
|
598
|
-
return stmt.argument.type ===
|
|
760
|
+
if (stmt.type === AST_NODE_TYPES7.ReturnStatement && stmt.argument) {
|
|
761
|
+
return stmt.argument.type === AST_NODE_TYPES7.JSXElement || stmt.argument.type === AST_NODE_TYPES7.JSXFragment || stmt.argument.type === AST_NODE_TYPES7.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES7.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
599
762
|
}
|
|
600
763
|
return false;
|
|
601
764
|
});
|
|
602
765
|
}
|
|
603
766
|
function isReactComponent(node) {
|
|
604
|
-
if (node.type ===
|
|
605
|
-
if (node.body.type ===
|
|
767
|
+
if (node.type === AST_NODE_TYPES7.ArrowFunctionExpression) {
|
|
768
|
+
if (node.body.type === AST_NODE_TYPES7.JSXElement || node.body.type === AST_NODE_TYPES7.JSXFragment) {
|
|
606
769
|
return true;
|
|
607
770
|
}
|
|
608
|
-
if (node.body.type ===
|
|
771
|
+
if (node.body.type === AST_NODE_TYPES7.BlockStatement) {
|
|
609
772
|
return hasJSXReturn(node.body);
|
|
610
773
|
}
|
|
611
|
-
} else if (node.type ===
|
|
612
|
-
if (node.body && node.body.type ===
|
|
774
|
+
} else if (node.type === AST_NODE_TYPES7.FunctionExpression || node.type === AST_NODE_TYPES7.FunctionDeclaration) {
|
|
775
|
+
if (node.body && node.body.type === AST_NODE_TYPES7.BlockStatement) {
|
|
613
776
|
return hasJSXReturn(node.body);
|
|
614
777
|
}
|
|
615
778
|
}
|
|
616
779
|
return false;
|
|
617
780
|
}
|
|
618
781
|
function isInlineTypeAnnotation(node) {
|
|
619
|
-
if (node.type ===
|
|
782
|
+
if (node.type === AST_NODE_TYPES7.TSTypeLiteral) {
|
|
620
783
|
return true;
|
|
621
784
|
}
|
|
622
|
-
if (node.type ===
|
|
623
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
785
|
+
if (node.type === AST_NODE_TYPES7.TSTypeReference && node.typeArguments) {
|
|
786
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES7.TSTypeLiteral);
|
|
624
787
|
}
|
|
625
|
-
if (node.type ===
|
|
788
|
+
if (node.type === AST_NODE_TYPES7.TSUnionType) {
|
|
626
789
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
627
790
|
}
|
|
628
791
|
return false;
|
|
629
792
|
}
|
|
630
793
|
function hasInlineObjectType(node) {
|
|
631
|
-
if (node.type ===
|
|
794
|
+
if (node.type === AST_NODE_TYPES7.TSTypeLiteral) {
|
|
632
795
|
return true;
|
|
633
796
|
}
|
|
634
|
-
if (node.type ===
|
|
635
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
797
|
+
if (node.type === AST_NODE_TYPES7.TSTypeReference && node.typeArguments) {
|
|
798
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES7.TSTypeLiteral);
|
|
636
799
|
}
|
|
637
|
-
if (node.type ===
|
|
800
|
+
if (node.type === AST_NODE_TYPES7.TSUnionType) {
|
|
638
801
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
639
802
|
}
|
|
640
803
|
return false;
|
|
@@ -647,7 +810,7 @@ var preferInterfaceOverInlineTypes = createRule9({
|
|
|
647
810
|
return;
|
|
648
811
|
}
|
|
649
812
|
const param = node.params[0];
|
|
650
|
-
if (param.type ===
|
|
813
|
+
if (param.type === AST_NODE_TYPES7.Identifier && param.typeAnnotation) {
|
|
651
814
|
const { typeAnnotation } = param.typeAnnotation;
|
|
652
815
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
653
816
|
context.report({
|
|
@@ -667,11 +830,11 @@ var preferInterfaceOverInlineTypes = createRule9({
|
|
|
667
830
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
668
831
|
|
|
669
832
|
// src/rules/prefer-named-param-types.ts
|
|
670
|
-
import { AST_NODE_TYPES as
|
|
671
|
-
var
|
|
833
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES8, ESLintUtils as ESLintUtils13 } from "@typescript-eslint/utils";
|
|
834
|
+
var createRule13 = ESLintUtils13.RuleCreator(
|
|
672
835
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
673
836
|
);
|
|
674
|
-
var preferNamedParamTypes =
|
|
837
|
+
var preferNamedParamTypes = createRule13({
|
|
675
838
|
name: "prefer-named-param-types",
|
|
676
839
|
meta: {
|
|
677
840
|
type: "suggestion",
|
|
@@ -686,16 +849,16 @@ var preferNamedParamTypes = createRule10({
|
|
|
686
849
|
defaultOptions: [],
|
|
687
850
|
create(context) {
|
|
688
851
|
function hasInlineObjectType(param) {
|
|
689
|
-
if (param.type ===
|
|
852
|
+
if (param.type === AST_NODE_TYPES8.AssignmentPattern) {
|
|
690
853
|
return hasInlineObjectType(param.left);
|
|
691
854
|
}
|
|
692
|
-
if (param.type ===
|
|
693
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
855
|
+
if (param.type === AST_NODE_TYPES8.ObjectPattern) {
|
|
856
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES8.TSTypeLiteral) {
|
|
694
857
|
return true;
|
|
695
858
|
}
|
|
696
859
|
}
|
|
697
|
-
if (param.type ===
|
|
698
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
860
|
+
if (param.type === AST_NODE_TYPES8.Identifier) {
|
|
861
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES8.TSTypeLiteral) {
|
|
699
862
|
return true;
|
|
700
863
|
}
|
|
701
864
|
}
|
|
@@ -729,11 +892,11 @@ var preferNamedParamTypes = createRule10({
|
|
|
729
892
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
730
893
|
|
|
731
894
|
// src/rules/prefer-react-import-types.ts
|
|
732
|
-
import { AST_NODE_TYPES as
|
|
733
|
-
var
|
|
895
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES9, ESLintUtils as ESLintUtils14 } from "@typescript-eslint/utils";
|
|
896
|
+
var createRule14 = ESLintUtils14.RuleCreator(
|
|
734
897
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
735
898
|
);
|
|
736
|
-
var preferReactImportTypes =
|
|
899
|
+
var preferReactImportTypes = createRule14({
|
|
737
900
|
name: "prefer-react-import-types",
|
|
738
901
|
meta: {
|
|
739
902
|
type: "suggestion",
|
|
@@ -809,7 +972,7 @@ var preferReactImportTypes = createRule11({
|
|
|
809
972
|
]);
|
|
810
973
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
811
974
|
function checkMemberExpression(node) {
|
|
812
|
-
if (node.object.type ===
|
|
975
|
+
if (node.object.type === AST_NODE_TYPES9.Identifier && node.object.name === "React" && node.property.type === AST_NODE_TYPES9.Identifier && allReactExports.has(node.property.name)) {
|
|
813
976
|
const typeName = node.property.name;
|
|
814
977
|
const isType = reactTypes.has(typeName);
|
|
815
978
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -826,7 +989,7 @@ var preferReactImportTypes = createRule11({
|
|
|
826
989
|
return {
|
|
827
990
|
MemberExpression: checkMemberExpression,
|
|
828
991
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
829
|
-
if (node.left.type ===
|
|
992
|
+
if (node.left.type === AST_NODE_TYPES9.Identifier && node.left.name === "React" && node.right.type === AST_NODE_TYPES9.Identifier && allReactExports.has(node.right.name)) {
|
|
830
993
|
const typeName = node.right.name;
|
|
831
994
|
const isType = reactTypes.has(typeName);
|
|
832
995
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -846,11 +1009,11 @@ var preferReactImportTypes = createRule11({
|
|
|
846
1009
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
847
1010
|
|
|
848
1011
|
// src/rules/react-props-destructure.ts
|
|
849
|
-
import { AST_NODE_TYPES as
|
|
850
|
-
var
|
|
1012
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES10, ESLintUtils as ESLintUtils15 } from "@typescript-eslint/utils";
|
|
1013
|
+
var createRule15 = ESLintUtils15.RuleCreator(
|
|
851
1014
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
852
1015
|
);
|
|
853
|
-
var reactPropsDestructure =
|
|
1016
|
+
var reactPropsDestructure = createRule15({
|
|
854
1017
|
name: "react-props-destructure",
|
|
855
1018
|
meta: {
|
|
856
1019
|
type: "suggestion",
|
|
@@ -866,29 +1029,29 @@ var reactPropsDestructure = createRule12({
|
|
|
866
1029
|
defaultOptions: [],
|
|
867
1030
|
create(context) {
|
|
868
1031
|
function hasJSXInConditional(node) {
|
|
869
|
-
return node.consequent.type ===
|
|
1032
|
+
return node.consequent.type === AST_NODE_TYPES10.JSXElement || node.consequent.type === AST_NODE_TYPES10.JSXFragment || node.alternate.type === AST_NODE_TYPES10.JSXElement || node.alternate.type === AST_NODE_TYPES10.JSXFragment;
|
|
870
1033
|
}
|
|
871
1034
|
function hasJSXInLogical(node) {
|
|
872
|
-
return node.right.type ===
|
|
1035
|
+
return node.right.type === AST_NODE_TYPES10.JSXElement || node.right.type === AST_NODE_TYPES10.JSXFragment;
|
|
873
1036
|
}
|
|
874
1037
|
function hasJSXReturn(block) {
|
|
875
1038
|
return block.body.some((stmt) => {
|
|
876
|
-
if (stmt.type ===
|
|
877
|
-
return stmt.argument.type ===
|
|
1039
|
+
if (stmt.type === AST_NODE_TYPES10.ReturnStatement && stmt.argument) {
|
|
1040
|
+
return stmt.argument.type === AST_NODE_TYPES10.JSXElement || stmt.argument.type === AST_NODE_TYPES10.JSXFragment || stmt.argument.type === AST_NODE_TYPES10.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES10.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
878
1041
|
}
|
|
879
1042
|
return false;
|
|
880
1043
|
});
|
|
881
1044
|
}
|
|
882
1045
|
function isReactComponent(node) {
|
|
883
|
-
if (node.type ===
|
|
884
|
-
if (node.body.type ===
|
|
1046
|
+
if (node.type === AST_NODE_TYPES10.ArrowFunctionExpression) {
|
|
1047
|
+
if (node.body.type === AST_NODE_TYPES10.JSXElement || node.body.type === AST_NODE_TYPES10.JSXFragment) {
|
|
885
1048
|
return true;
|
|
886
1049
|
}
|
|
887
|
-
if (node.body.type ===
|
|
1050
|
+
if (node.body.type === AST_NODE_TYPES10.BlockStatement) {
|
|
888
1051
|
return hasJSXReturn(node.body);
|
|
889
1052
|
}
|
|
890
|
-
} else if (node.type ===
|
|
891
|
-
if (node.body && node.body.type ===
|
|
1053
|
+
} else if (node.type === AST_NODE_TYPES10.FunctionExpression || node.type === AST_NODE_TYPES10.FunctionDeclaration) {
|
|
1054
|
+
if (node.body && node.body.type === AST_NODE_TYPES10.BlockStatement) {
|
|
892
1055
|
return hasJSXReturn(node.body);
|
|
893
1056
|
}
|
|
894
1057
|
}
|
|
@@ -902,9 +1065,9 @@ var reactPropsDestructure = createRule12({
|
|
|
902
1065
|
return;
|
|
903
1066
|
}
|
|
904
1067
|
const param = node.params[0];
|
|
905
|
-
if (param.type ===
|
|
906
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
907
|
-
if (prop.key.type ===
|
|
1068
|
+
if (param.type === AST_NODE_TYPES10.ObjectPattern) {
|
|
1069
|
+
const properties = param.properties.filter((prop) => prop.type === AST_NODE_TYPES10.Property).map((prop) => {
|
|
1070
|
+
if (prop.key.type === AST_NODE_TYPES10.Identifier) {
|
|
908
1071
|
return prop.key.name;
|
|
909
1072
|
}
|
|
910
1073
|
return null;
|
|
@@ -940,8 +1103,11 @@ var rules = {
|
|
|
940
1103
|
"file-kebab-case": file_kebab_case_default,
|
|
941
1104
|
"jsx-pascal-case": jsx_pascal_case_default,
|
|
942
1105
|
"md-filename-case-restriction": md_filename_case_restriction_default,
|
|
1106
|
+
"no-complex-inline-return": no_complex_inline_return_default,
|
|
943
1107
|
"no-emoji": no_emoji_default,
|
|
1108
|
+
"no-env-fallback": no_env_fallback_default,
|
|
944
1109
|
"no-explicit-return-type": no_explicit_return_type_default,
|
|
1110
|
+
"no-logic-in-params": no_logic_in_params_default,
|
|
945
1111
|
"prefer-destructuring-params": prefer_destructuring_params_default,
|
|
946
1112
|
"prefer-import-type": prefer_import_type_default,
|
|
947
1113
|
"prefer-interface-over-inline-types": prefer_interface_over_inline_types_default,
|
|
@@ -961,7 +1127,10 @@ var baseRules = {
|
|
|
961
1127
|
"nextfriday/no-explicit-return-type": "warn",
|
|
962
1128
|
"nextfriday/prefer-import-type": "warn",
|
|
963
1129
|
"nextfriday/prefer-named-param-types": "warn",
|
|
964
|
-
"nextfriday/prefer-react-import-types": "warn"
|
|
1130
|
+
"nextfriday/prefer-react-import-types": "warn",
|
|
1131
|
+
"nextfriday/no-complex-inline-return": "warn",
|
|
1132
|
+
"nextfriday/no-logic-in-params": "warn",
|
|
1133
|
+
"nextfriday/no-env-fallback": "warn"
|
|
965
1134
|
};
|
|
966
1135
|
var baseRecommendedRules = {
|
|
967
1136
|
"nextfriday/no-emoji": "error",
|
|
@@ -971,7 +1140,10 @@ var baseRecommendedRules = {
|
|
|
971
1140
|
"nextfriday/no-explicit-return-type": "error",
|
|
972
1141
|
"nextfriday/prefer-import-type": "error",
|
|
973
1142
|
"nextfriday/prefer-named-param-types": "error",
|
|
974
|
-
"nextfriday/prefer-react-import-types": "error"
|
|
1143
|
+
"nextfriday/prefer-react-import-types": "error",
|
|
1144
|
+
"nextfriday/no-complex-inline-return": "error",
|
|
1145
|
+
"nextfriday/no-logic-in-params": "error",
|
|
1146
|
+
"nextfriday/no-env-fallback": "error"
|
|
975
1147
|
};
|
|
976
1148
|
var jsxRules = {
|
|
977
1149
|
"nextfriday/jsx-pascal-case": "warn",
|