eslint-plugin-nextfriday 1.8.0 → 1.9.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 +10 -0
- package/README.md +10 -7
- package/docs/rules/NO_INLINE_DEFAULT_EXPORT.md +78 -0
- package/lib/index.cjs +243 -174
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +14 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +243 -174
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
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.9.0",
|
|
5
5
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
6
6
|
keywords: [
|
|
7
7
|
"eslint",
|
|
@@ -853,58 +853,124 @@ var noEnvFallback = createRule11({
|
|
|
853
853
|
});
|
|
854
854
|
var no_env_fallback_default = noEnvFallback;
|
|
855
855
|
|
|
856
|
-
// src/rules/
|
|
856
|
+
// src/rules/no-inline-default-export.ts
|
|
857
857
|
import { ESLintUtils as ESLintUtils12, AST_NODE_TYPES as AST_NODE_TYPES8 } from "@typescript-eslint/utils";
|
|
858
858
|
var createRule12 = ESLintUtils12.RuleCreator(
|
|
859
859
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
860
860
|
);
|
|
861
|
+
var noInlineDefaultExport = createRule12({
|
|
862
|
+
name: "no-inline-default-export",
|
|
863
|
+
meta: {
|
|
864
|
+
type: "suggestion",
|
|
865
|
+
docs: {
|
|
866
|
+
description: "Disallow inline default exports. Prefer declaring first, then exporting separately."
|
|
867
|
+
},
|
|
868
|
+
messages: {
|
|
869
|
+
noInlineDefaultExport: "Avoid inline default export. Declare the {{type}} first, then export it separately: `export default {{name}};`",
|
|
870
|
+
noAnonymousDefaultExport: "Avoid anonymous default export. Declare a named {{type}} first, then export it separately."
|
|
871
|
+
},
|
|
872
|
+
schema: []
|
|
873
|
+
},
|
|
874
|
+
defaultOptions: [],
|
|
875
|
+
create(context) {
|
|
876
|
+
return {
|
|
877
|
+
ExportDefaultDeclaration(node) {
|
|
878
|
+
const { declaration } = node;
|
|
879
|
+
if (declaration.type === AST_NODE_TYPES8.FunctionDeclaration) {
|
|
880
|
+
if (declaration.id) {
|
|
881
|
+
context.report({
|
|
882
|
+
node,
|
|
883
|
+
messageId: "noInlineDefaultExport",
|
|
884
|
+
data: { type: "function", name: declaration.id.name }
|
|
885
|
+
});
|
|
886
|
+
} else {
|
|
887
|
+
context.report({
|
|
888
|
+
node,
|
|
889
|
+
messageId: "noAnonymousDefaultExport",
|
|
890
|
+
data: { type: "function" }
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
if (declaration.type === AST_NODE_TYPES8.ClassDeclaration) {
|
|
895
|
+
if (declaration.id) {
|
|
896
|
+
context.report({
|
|
897
|
+
node,
|
|
898
|
+
messageId: "noInlineDefaultExport",
|
|
899
|
+
data: { type: "class", name: declaration.id.name }
|
|
900
|
+
});
|
|
901
|
+
} else {
|
|
902
|
+
context.report({
|
|
903
|
+
node,
|
|
904
|
+
messageId: "noAnonymousDefaultExport",
|
|
905
|
+
data: { type: "class" }
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
if (declaration.type === AST_NODE_TYPES8.ArrowFunctionExpression || declaration.type === AST_NODE_TYPES8.FunctionExpression) {
|
|
910
|
+
context.report({
|
|
911
|
+
node,
|
|
912
|
+
messageId: "noAnonymousDefaultExport",
|
|
913
|
+
data: { type: "function" }
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
});
|
|
920
|
+
var no_inline_default_export_default = noInlineDefaultExport;
|
|
921
|
+
|
|
922
|
+
// src/rules/require-explicit-return-type.ts
|
|
923
|
+
import { ESLintUtils as ESLintUtils13, AST_NODE_TYPES as AST_NODE_TYPES9 } from "@typescript-eslint/utils";
|
|
924
|
+
var createRule13 = ESLintUtils13.RuleCreator(
|
|
925
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
926
|
+
);
|
|
861
927
|
var isReactComponent = (node) => {
|
|
862
|
-
if (node.type ===
|
|
928
|
+
if (node.type === AST_NODE_TYPES9.ArrowFunctionExpression) {
|
|
863
929
|
const { parent } = node;
|
|
864
|
-
if (parent?.type ===
|
|
930
|
+
if (parent?.type === AST_NODE_TYPES9.VariableDeclarator) {
|
|
865
931
|
const { id } = parent;
|
|
866
|
-
if (id.type ===
|
|
932
|
+
if (id.type === AST_NODE_TYPES9.Identifier) {
|
|
867
933
|
return /^[A-Z]/.test(id.name);
|
|
868
934
|
}
|
|
869
935
|
}
|
|
870
936
|
}
|
|
871
|
-
if (node.type ===
|
|
937
|
+
if (node.type === AST_NODE_TYPES9.FunctionDeclaration && node.id) {
|
|
872
938
|
return /^[A-Z]/.test(node.id.name);
|
|
873
939
|
}
|
|
874
940
|
return false;
|
|
875
941
|
};
|
|
876
942
|
var isCallbackFunction = (node) => {
|
|
877
|
-
if (node.type ===
|
|
943
|
+
if (node.type === AST_NODE_TYPES9.FunctionDeclaration) {
|
|
878
944
|
return false;
|
|
879
945
|
}
|
|
880
946
|
const { parent } = node;
|
|
881
947
|
if (!parent) {
|
|
882
948
|
return false;
|
|
883
949
|
}
|
|
884
|
-
if (parent.type ===
|
|
950
|
+
if (parent.type === AST_NODE_TYPES9.CallExpression && parent.arguments.includes(node)) {
|
|
885
951
|
return true;
|
|
886
952
|
}
|
|
887
|
-
if (parent.type ===
|
|
953
|
+
if (parent.type === AST_NODE_TYPES9.Property) {
|
|
888
954
|
return true;
|
|
889
955
|
}
|
|
890
|
-
if (parent.type ===
|
|
956
|
+
if (parent.type === AST_NODE_TYPES9.ArrayExpression) {
|
|
891
957
|
return true;
|
|
892
958
|
}
|
|
893
959
|
return false;
|
|
894
960
|
};
|
|
895
961
|
var getFunctionName = (node) => {
|
|
896
|
-
if (node.type ===
|
|
962
|
+
if (node.type === AST_NODE_TYPES9.FunctionDeclaration && node.id) {
|
|
897
963
|
return node.id.name;
|
|
898
964
|
}
|
|
899
|
-
if (node.type ===
|
|
965
|
+
if (node.type === AST_NODE_TYPES9.FunctionExpression && node.id) {
|
|
900
966
|
return node.id.name;
|
|
901
967
|
}
|
|
902
|
-
if ((node.type ===
|
|
968
|
+
if ((node.type === AST_NODE_TYPES9.ArrowFunctionExpression || node.type === AST_NODE_TYPES9.FunctionExpression) && node.parent?.type === AST_NODE_TYPES9.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES9.Identifier) {
|
|
903
969
|
return node.parent.id.name;
|
|
904
970
|
}
|
|
905
971
|
return null;
|
|
906
972
|
};
|
|
907
|
-
var requireExplicitReturnType =
|
|
973
|
+
var requireExplicitReturnType = createRule13({
|
|
908
974
|
name: "require-explicit-return-type",
|
|
909
975
|
meta: {
|
|
910
976
|
type: "suggestion",
|
|
@@ -953,18 +1019,18 @@ var requireExplicitReturnType = createRule12({
|
|
|
953
1019
|
var require_explicit_return_type_default = requireExplicitReturnType;
|
|
954
1020
|
|
|
955
1021
|
// src/rules/jsx-no-non-component-function.ts
|
|
956
|
-
import { AST_NODE_TYPES as
|
|
1022
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES11, ESLintUtils as ESLintUtils14 } from "@typescript-eslint/utils";
|
|
957
1023
|
|
|
958
1024
|
// src/utils.ts
|
|
959
1025
|
import { basename, extname } from "path";
|
|
960
|
-
import { AST_NODE_TYPES as
|
|
1026
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES10 } from "@typescript-eslint/utils";
|
|
961
1027
|
var getFileExtension = (filename) => extname(filename).slice(1);
|
|
962
1028
|
|
|
963
1029
|
// src/rules/jsx-no-non-component-function.ts
|
|
964
|
-
var
|
|
1030
|
+
var createRule14 = ESLintUtils14.RuleCreator(
|
|
965
1031
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
966
1032
|
);
|
|
967
|
-
var jsxNoNonComponentFunction =
|
|
1033
|
+
var jsxNoNonComponentFunction = createRule14({
|
|
968
1034
|
name: "jsx-no-non-component-function",
|
|
969
1035
|
meta: {
|
|
970
1036
|
type: "problem",
|
|
@@ -984,13 +1050,13 @@ var jsxNoNonComponentFunction = createRule13({
|
|
|
984
1050
|
return {};
|
|
985
1051
|
}
|
|
986
1052
|
function isReactComponent2(node) {
|
|
987
|
-
const functionName = node.type ===
|
|
1053
|
+
const functionName = node.type === AST_NODE_TYPES11.FunctionDeclaration && node.id ? node.id.name : null;
|
|
988
1054
|
if (functionName && /^[A-Z]/.test(functionName)) {
|
|
989
1055
|
return true;
|
|
990
1056
|
}
|
|
991
1057
|
if (node.returnType?.typeAnnotation) {
|
|
992
1058
|
const returnTypeNode = node.returnType.typeAnnotation;
|
|
993
|
-
if (returnTypeNode.type ===
|
|
1059
|
+
if (returnTypeNode.type === AST_NODE_TYPES11.TSTypeReference && returnTypeNode.typeName.type === AST_NODE_TYPES11.Identifier) {
|
|
994
1060
|
const typeName = returnTypeNode.typeName.name;
|
|
995
1061
|
if (typeName === "JSX" || typeName === "ReactElement" || typeName === "ReactNode") {
|
|
996
1062
|
return true;
|
|
@@ -1007,13 +1073,13 @@ var jsxNoNonComponentFunction = createRule13({
|
|
|
1007
1073
|
if (!parent) {
|
|
1008
1074
|
return;
|
|
1009
1075
|
}
|
|
1010
|
-
if (parent.type ===
|
|
1076
|
+
if (parent.type === AST_NODE_TYPES11.ExportDefaultDeclaration || parent.type === AST_NODE_TYPES11.ExportNamedDeclaration) {
|
|
1011
1077
|
return;
|
|
1012
1078
|
}
|
|
1013
|
-
if (declaratorNode?.parent?.parent?.type ===
|
|
1079
|
+
if (declaratorNode?.parent?.parent?.type === AST_NODE_TYPES11.ExportNamedDeclaration) {
|
|
1014
1080
|
return;
|
|
1015
1081
|
}
|
|
1016
|
-
if (declaratorNode?.id.type ===
|
|
1082
|
+
if (declaratorNode?.id.type === AST_NODE_TYPES11.Identifier) {
|
|
1017
1083
|
const varName = declaratorNode.id.name;
|
|
1018
1084
|
if (/^[A-Z]/.test(varName)) {
|
|
1019
1085
|
return;
|
|
@@ -1038,11 +1104,11 @@ var jsxNoNonComponentFunction = createRule13({
|
|
|
1038
1104
|
var jsx_no_non_component_function_default = jsxNoNonComponentFunction;
|
|
1039
1105
|
|
|
1040
1106
|
// src/rules/no-logic-in-params.ts
|
|
1041
|
-
import { ESLintUtils as
|
|
1042
|
-
var
|
|
1107
|
+
import { ESLintUtils as ESLintUtils15, AST_NODE_TYPES as AST_NODE_TYPES12 } from "@typescript-eslint/utils";
|
|
1108
|
+
var createRule15 = ESLintUtils15.RuleCreator(
|
|
1043
1109
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1044
1110
|
);
|
|
1045
|
-
var noLogicInParams =
|
|
1111
|
+
var noLogicInParams = createRule15({
|
|
1046
1112
|
name: "no-logic-in-params",
|
|
1047
1113
|
meta: {
|
|
1048
1114
|
type: "suggestion",
|
|
@@ -1057,20 +1123,20 @@ var noLogicInParams = createRule14({
|
|
|
1057
1123
|
defaultOptions: [],
|
|
1058
1124
|
create(context) {
|
|
1059
1125
|
const isComplexExpression = (node) => {
|
|
1060
|
-
if (node.type ===
|
|
1126
|
+
if (node.type === AST_NODE_TYPES12.SpreadElement) {
|
|
1061
1127
|
return false;
|
|
1062
1128
|
}
|
|
1063
|
-
if (node.type ===
|
|
1129
|
+
if (node.type === AST_NODE_TYPES12.ConditionalExpression) {
|
|
1064
1130
|
return true;
|
|
1065
1131
|
}
|
|
1066
|
-
if (node.type ===
|
|
1132
|
+
if (node.type === AST_NODE_TYPES12.LogicalExpression) {
|
|
1067
1133
|
return true;
|
|
1068
1134
|
}
|
|
1069
|
-
if (node.type ===
|
|
1135
|
+
if (node.type === AST_NODE_TYPES12.BinaryExpression) {
|
|
1070
1136
|
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
1071
1137
|
return logicalOperators.includes(node.operator);
|
|
1072
1138
|
}
|
|
1073
|
-
if (node.type ===
|
|
1139
|
+
if (node.type === AST_NODE_TYPES12.UnaryExpression) {
|
|
1074
1140
|
return node.operator === "!";
|
|
1075
1141
|
}
|
|
1076
1142
|
return false;
|
|
@@ -1102,8 +1168,8 @@ var noLogicInParams = createRule14({
|
|
|
1102
1168
|
var no_logic_in_params_default = noLogicInParams;
|
|
1103
1169
|
|
|
1104
1170
|
// src/rules/no-lazy-identifiers.ts
|
|
1105
|
-
import { ESLintUtils as
|
|
1106
|
-
var
|
|
1171
|
+
import { ESLintUtils as ESLintUtils16, AST_NODE_TYPES as AST_NODE_TYPES13 } from "@typescript-eslint/utils";
|
|
1172
|
+
var createRule16 = ESLintUtils16.RuleCreator(
|
|
1107
1173
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1108
1174
|
);
|
|
1109
1175
|
var KEYBOARD_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm", "1234567890"];
|
|
@@ -1147,7 +1213,7 @@ var isLazyIdentifier = (name) => {
|
|
|
1147
1213
|
}
|
|
1148
1214
|
return false;
|
|
1149
1215
|
};
|
|
1150
|
-
var noLazyIdentifiers =
|
|
1216
|
+
var noLazyIdentifiers = createRule16({
|
|
1151
1217
|
name: "no-lazy-identifiers",
|
|
1152
1218
|
meta: {
|
|
1153
1219
|
type: "problem",
|
|
@@ -1173,27 +1239,27 @@ var noLazyIdentifiers = createRule15({
|
|
|
1173
1239
|
});
|
|
1174
1240
|
};
|
|
1175
1241
|
const checkPattern = (pattern) => {
|
|
1176
|
-
if (pattern.type ===
|
|
1242
|
+
if (pattern.type === AST_NODE_TYPES13.Identifier) {
|
|
1177
1243
|
checkIdentifier(pattern);
|
|
1178
|
-
} else if (pattern.type ===
|
|
1244
|
+
} else if (pattern.type === AST_NODE_TYPES13.ObjectPattern) {
|
|
1179
1245
|
pattern.properties.forEach((prop) => {
|
|
1180
|
-
if (prop.type ===
|
|
1246
|
+
if (prop.type === AST_NODE_TYPES13.Property && prop.value.type === AST_NODE_TYPES13.Identifier) {
|
|
1181
1247
|
checkIdentifier(prop.value);
|
|
1182
|
-
} else if (prop.type ===
|
|
1248
|
+
} else if (prop.type === AST_NODE_TYPES13.RestElement && prop.argument.type === AST_NODE_TYPES13.Identifier) {
|
|
1183
1249
|
checkIdentifier(prop.argument);
|
|
1184
1250
|
}
|
|
1185
1251
|
});
|
|
1186
|
-
} else if (pattern.type ===
|
|
1252
|
+
} else if (pattern.type === AST_NODE_TYPES13.ArrayPattern) {
|
|
1187
1253
|
pattern.elements.forEach((element) => {
|
|
1188
|
-
if (element?.type ===
|
|
1254
|
+
if (element?.type === AST_NODE_TYPES13.Identifier) {
|
|
1189
1255
|
checkIdentifier(element);
|
|
1190
|
-
} else if (element?.type ===
|
|
1256
|
+
} else if (element?.type === AST_NODE_TYPES13.RestElement && element.argument.type === AST_NODE_TYPES13.Identifier) {
|
|
1191
1257
|
checkIdentifier(element.argument);
|
|
1192
1258
|
}
|
|
1193
1259
|
});
|
|
1194
|
-
} else if (pattern.type ===
|
|
1260
|
+
} else if (pattern.type === AST_NODE_TYPES13.AssignmentPattern && pattern.left.type === AST_NODE_TYPES13.Identifier) {
|
|
1195
1261
|
checkIdentifier(pattern.left);
|
|
1196
|
-
} else if (pattern.type ===
|
|
1262
|
+
} else if (pattern.type === AST_NODE_TYPES13.RestElement && pattern.argument.type === AST_NODE_TYPES13.Identifier) {
|
|
1197
1263
|
checkIdentifier(pattern.argument);
|
|
1198
1264
|
}
|
|
1199
1265
|
};
|
|
@@ -1238,8 +1304,8 @@ var noLazyIdentifiers = createRule15({
|
|
|
1238
1304
|
var no_lazy_identifiers_default = noLazyIdentifiers;
|
|
1239
1305
|
|
|
1240
1306
|
// src/rules/no-single-char-variables.ts
|
|
1241
|
-
import { ESLintUtils as
|
|
1242
|
-
var
|
|
1307
|
+
import { ESLintUtils as ESLintUtils17, AST_NODE_TYPES as AST_NODE_TYPES14 } from "@typescript-eslint/utils";
|
|
1308
|
+
var createRule17 = ESLintUtils17.RuleCreator(
|
|
1243
1309
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1244
1310
|
);
|
|
1245
1311
|
var ALLOWED_IN_FOR_LOOPS = /* @__PURE__ */ new Set(["i", "j", "k", "n"]);
|
|
@@ -1251,7 +1317,7 @@ var isForLoopInit = (node) => {
|
|
|
1251
1317
|
if (!parentNode) {
|
|
1252
1318
|
return false;
|
|
1253
1319
|
}
|
|
1254
|
-
if (parentNode.type ===
|
|
1320
|
+
if (parentNode.type === AST_NODE_TYPES14.ForStatement) {
|
|
1255
1321
|
const { init } = parentNode;
|
|
1256
1322
|
if (init && init === current) {
|
|
1257
1323
|
return true;
|
|
@@ -1270,7 +1336,7 @@ var isAllowedInContext = (name, node) => {
|
|
|
1270
1336
|
}
|
|
1271
1337
|
return false;
|
|
1272
1338
|
};
|
|
1273
|
-
var noSingleCharVariables =
|
|
1339
|
+
var noSingleCharVariables = createRule17({
|
|
1274
1340
|
name: "no-single-char-variables",
|
|
1275
1341
|
meta: {
|
|
1276
1342
|
type: "suggestion",
|
|
@@ -1299,27 +1365,27 @@ var noSingleCharVariables = createRule16({
|
|
|
1299
1365
|
});
|
|
1300
1366
|
};
|
|
1301
1367
|
const checkPattern = (pattern, declarationNode) => {
|
|
1302
|
-
if (pattern.type ===
|
|
1368
|
+
if (pattern.type === AST_NODE_TYPES14.Identifier) {
|
|
1303
1369
|
checkIdentifier(pattern, declarationNode);
|
|
1304
|
-
} else if (pattern.type ===
|
|
1370
|
+
} else if (pattern.type === AST_NODE_TYPES14.ObjectPattern) {
|
|
1305
1371
|
pattern.properties.forEach((prop) => {
|
|
1306
|
-
if (prop.type ===
|
|
1372
|
+
if (prop.type === AST_NODE_TYPES14.Property && prop.value.type === AST_NODE_TYPES14.Identifier) {
|
|
1307
1373
|
checkIdentifier(prop.value, declarationNode);
|
|
1308
|
-
} else if (prop.type ===
|
|
1374
|
+
} else if (prop.type === AST_NODE_TYPES14.RestElement && prop.argument.type === AST_NODE_TYPES14.Identifier) {
|
|
1309
1375
|
checkIdentifier(prop.argument, declarationNode);
|
|
1310
1376
|
}
|
|
1311
1377
|
});
|
|
1312
|
-
} else if (pattern.type ===
|
|
1378
|
+
} else if (pattern.type === AST_NODE_TYPES14.ArrayPattern) {
|
|
1313
1379
|
pattern.elements.forEach((element) => {
|
|
1314
|
-
if (element?.type ===
|
|
1380
|
+
if (element?.type === AST_NODE_TYPES14.Identifier) {
|
|
1315
1381
|
checkIdentifier(element, declarationNode);
|
|
1316
|
-
} else if (element?.type ===
|
|
1382
|
+
} else if (element?.type === AST_NODE_TYPES14.RestElement && element.argument.type === AST_NODE_TYPES14.Identifier) {
|
|
1317
1383
|
checkIdentifier(element.argument, declarationNode);
|
|
1318
1384
|
}
|
|
1319
1385
|
});
|
|
1320
|
-
} else if (pattern.type ===
|
|
1386
|
+
} else if (pattern.type === AST_NODE_TYPES14.AssignmentPattern && pattern.left.type === AST_NODE_TYPES14.Identifier) {
|
|
1321
1387
|
checkIdentifier(pattern.left, declarationNode);
|
|
1322
|
-
} else if (pattern.type ===
|
|
1388
|
+
} else if (pattern.type === AST_NODE_TYPES14.RestElement && pattern.argument.type === AST_NODE_TYPES14.Identifier) {
|
|
1323
1389
|
checkIdentifier(pattern.argument, declarationNode);
|
|
1324
1390
|
}
|
|
1325
1391
|
};
|
|
@@ -1353,11 +1419,11 @@ var noSingleCharVariables = createRule16({
|
|
|
1353
1419
|
var no_single_char_variables_default = noSingleCharVariables;
|
|
1354
1420
|
|
|
1355
1421
|
// src/rules/prefer-destructuring-params.ts
|
|
1356
|
-
import { AST_NODE_TYPES as
|
|
1357
|
-
var
|
|
1422
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15, ESLintUtils as ESLintUtils18 } from "@typescript-eslint/utils";
|
|
1423
|
+
var createRule18 = ESLintUtils18.RuleCreator(
|
|
1358
1424
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1359
1425
|
);
|
|
1360
|
-
var preferDestructuringParams =
|
|
1426
|
+
var preferDestructuringParams = createRule18({
|
|
1361
1427
|
name: "prefer-destructuring-params",
|
|
1362
1428
|
meta: {
|
|
1363
1429
|
type: "suggestion",
|
|
@@ -1373,18 +1439,18 @@ var preferDestructuringParams = createRule17({
|
|
|
1373
1439
|
create(context) {
|
|
1374
1440
|
const isCallbackFunction2 = (node) => {
|
|
1375
1441
|
const { parent } = node;
|
|
1376
|
-
return parent?.type ===
|
|
1442
|
+
return parent?.type === AST_NODE_TYPES15.CallExpression;
|
|
1377
1443
|
};
|
|
1378
1444
|
const isDeveloperFunction = (node) => {
|
|
1379
|
-
if (node.type ===
|
|
1445
|
+
if (node.type === AST_NODE_TYPES15.FunctionDeclaration) {
|
|
1380
1446
|
return true;
|
|
1381
1447
|
}
|
|
1382
|
-
if (node.type ===
|
|
1448
|
+
if (node.type === AST_NODE_TYPES15.FunctionExpression || node.type === AST_NODE_TYPES15.ArrowFunctionExpression) {
|
|
1383
1449
|
if (isCallbackFunction2(node)) {
|
|
1384
1450
|
return false;
|
|
1385
1451
|
}
|
|
1386
1452
|
const { parent } = node;
|
|
1387
|
-
return parent?.type ===
|
|
1453
|
+
return parent?.type === AST_NODE_TYPES15.VariableDeclarator || parent?.type === AST_NODE_TYPES15.AssignmentExpression || parent?.type === AST_NODE_TYPES15.Property || parent?.type === AST_NODE_TYPES15.MethodDefinition;
|
|
1388
1454
|
}
|
|
1389
1455
|
return false;
|
|
1390
1456
|
};
|
|
@@ -1396,7 +1462,7 @@ var preferDestructuringParams = createRule17({
|
|
|
1396
1462
|
if (!isDeveloperFunction(node)) {
|
|
1397
1463
|
return;
|
|
1398
1464
|
}
|
|
1399
|
-
if (node.type ===
|
|
1465
|
+
if (node.type === AST_NODE_TYPES15.FunctionDeclaration && node.id) {
|
|
1400
1466
|
const functionName = node.id.name;
|
|
1401
1467
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
1402
1468
|
return;
|
|
@@ -1406,7 +1472,7 @@ var preferDestructuringParams = createRule17({
|
|
|
1406
1472
|
return;
|
|
1407
1473
|
}
|
|
1408
1474
|
const hasNonDestructuredParams = node.params.some(
|
|
1409
|
-
(param) => param.type !==
|
|
1475
|
+
(param) => param.type !== AST_NODE_TYPES15.ObjectPattern && param.type !== AST_NODE_TYPES15.RestElement
|
|
1410
1476
|
);
|
|
1411
1477
|
if (hasNonDestructuredParams) {
|
|
1412
1478
|
context.report({
|
|
@@ -1425,8 +1491,8 @@ var preferDestructuringParams = createRule17({
|
|
|
1425
1491
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
1426
1492
|
|
|
1427
1493
|
// src/rules/prefer-function-declaration.ts
|
|
1428
|
-
import { ESLintUtils as
|
|
1429
|
-
var
|
|
1494
|
+
import { ESLintUtils as ESLintUtils19, AST_NODE_TYPES as AST_NODE_TYPES16 } from "@typescript-eslint/utils";
|
|
1495
|
+
var createRule19 = ESLintUtils19.RuleCreator(
|
|
1430
1496
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1431
1497
|
);
|
|
1432
1498
|
var isTsFile = (filename) => filename.endsWith(".ts") && !filename.endsWith(".d.ts");
|
|
@@ -1435,33 +1501,33 @@ var isCallbackContext = (node) => {
|
|
|
1435
1501
|
if (!parent) {
|
|
1436
1502
|
return false;
|
|
1437
1503
|
}
|
|
1438
|
-
if (parent.type ===
|
|
1504
|
+
if (parent.type === AST_NODE_TYPES16.CallExpression && parent.arguments.includes(node)) {
|
|
1439
1505
|
return true;
|
|
1440
1506
|
}
|
|
1441
|
-
if (parent.type ===
|
|
1507
|
+
if (parent.type === AST_NODE_TYPES16.NewExpression && parent.arguments.includes(node)) {
|
|
1442
1508
|
return true;
|
|
1443
1509
|
}
|
|
1444
|
-
if (parent.type ===
|
|
1510
|
+
if (parent.type === AST_NODE_TYPES16.ReturnStatement) {
|
|
1445
1511
|
return true;
|
|
1446
1512
|
}
|
|
1447
|
-
if (parent.type ===
|
|
1513
|
+
if (parent.type === AST_NODE_TYPES16.Property) {
|
|
1448
1514
|
return true;
|
|
1449
1515
|
}
|
|
1450
|
-
if (parent.type ===
|
|
1516
|
+
if (parent.type === AST_NODE_TYPES16.ArrayExpression) {
|
|
1451
1517
|
return true;
|
|
1452
1518
|
}
|
|
1453
|
-
if (parent.type ===
|
|
1519
|
+
if (parent.type === AST_NODE_TYPES16.ConditionalExpression) {
|
|
1454
1520
|
return true;
|
|
1455
1521
|
}
|
|
1456
|
-
if (parent.type ===
|
|
1522
|
+
if (parent.type === AST_NODE_TYPES16.LogicalExpression) {
|
|
1457
1523
|
return true;
|
|
1458
1524
|
}
|
|
1459
|
-
if (parent.type ===
|
|
1525
|
+
if (parent.type === AST_NODE_TYPES16.AssignmentExpression && parent.left !== node) {
|
|
1460
1526
|
return true;
|
|
1461
1527
|
}
|
|
1462
1528
|
return false;
|
|
1463
1529
|
};
|
|
1464
|
-
var preferFunctionDeclaration =
|
|
1530
|
+
var preferFunctionDeclaration = createRule19({
|
|
1465
1531
|
name: "prefer-function-declaration",
|
|
1466
1532
|
meta: {
|
|
1467
1533
|
type: "suggestion",
|
|
@@ -1482,14 +1548,14 @@ var preferFunctionDeclaration = createRule18({
|
|
|
1482
1548
|
}
|
|
1483
1549
|
return {
|
|
1484
1550
|
VariableDeclarator(node) {
|
|
1485
|
-
if (node.id.type !==
|
|
1551
|
+
if (node.id.type !== AST_NODE_TYPES16.Identifier) {
|
|
1486
1552
|
return;
|
|
1487
1553
|
}
|
|
1488
1554
|
const { init } = node;
|
|
1489
1555
|
if (!init) {
|
|
1490
1556
|
return;
|
|
1491
1557
|
}
|
|
1492
|
-
if (init.type ===
|
|
1558
|
+
if (init.type === AST_NODE_TYPES16.ArrowFunctionExpression) {
|
|
1493
1559
|
if (isCallbackContext(init)) {
|
|
1494
1560
|
return;
|
|
1495
1561
|
}
|
|
@@ -1499,7 +1565,7 @@ var preferFunctionDeclaration = createRule18({
|
|
|
1499
1565
|
data: { name: node.id.name }
|
|
1500
1566
|
});
|
|
1501
1567
|
}
|
|
1502
|
-
if (init.type ===
|
|
1568
|
+
if (init.type === AST_NODE_TYPES16.FunctionExpression) {
|
|
1503
1569
|
if (isCallbackContext(init)) {
|
|
1504
1570
|
return;
|
|
1505
1571
|
}
|
|
@@ -1516,11 +1582,11 @@ var preferFunctionDeclaration = createRule18({
|
|
|
1516
1582
|
var prefer_function_declaration_default = preferFunctionDeclaration;
|
|
1517
1583
|
|
|
1518
1584
|
// src/rules/prefer-import-type.ts
|
|
1519
|
-
import { AST_NODE_TYPES as
|
|
1520
|
-
var
|
|
1585
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES17, ESLintUtils as ESLintUtils20 } from "@typescript-eslint/utils";
|
|
1586
|
+
var createRule20 = ESLintUtils20.RuleCreator(
|
|
1521
1587
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1522
1588
|
);
|
|
1523
|
-
var preferImportType =
|
|
1589
|
+
var preferImportType = createRule20({
|
|
1524
1590
|
name: "prefer-import-type",
|
|
1525
1591
|
meta: {
|
|
1526
1592
|
type: "suggestion",
|
|
@@ -1539,22 +1605,22 @@ var preferImportType = createRule19({
|
|
|
1539
1605
|
let current = node;
|
|
1540
1606
|
while (current) {
|
|
1541
1607
|
switch (current.type) {
|
|
1542
|
-
case
|
|
1543
|
-
case
|
|
1544
|
-
case
|
|
1545
|
-
case
|
|
1546
|
-
case
|
|
1547
|
-
case
|
|
1548
|
-
case
|
|
1549
|
-
case
|
|
1550
|
-
case
|
|
1551
|
-
case
|
|
1552
|
-
case
|
|
1553
|
-
case
|
|
1554
|
-
case
|
|
1608
|
+
case AST_NODE_TYPES17.TSTypeReference:
|
|
1609
|
+
case AST_NODE_TYPES17.TSTypeAnnotation:
|
|
1610
|
+
case AST_NODE_TYPES17.TSTypeParameterInstantiation:
|
|
1611
|
+
case AST_NODE_TYPES17.TSInterfaceHeritage:
|
|
1612
|
+
case AST_NODE_TYPES17.TSClassImplements:
|
|
1613
|
+
case AST_NODE_TYPES17.TSTypeQuery:
|
|
1614
|
+
case AST_NODE_TYPES17.TSTypeAssertion:
|
|
1615
|
+
case AST_NODE_TYPES17.TSAsExpression:
|
|
1616
|
+
case AST_NODE_TYPES17.TSSatisfiesExpression:
|
|
1617
|
+
case AST_NODE_TYPES17.TSTypeAliasDeclaration:
|
|
1618
|
+
case AST_NODE_TYPES17.TSInterfaceDeclaration:
|
|
1619
|
+
case AST_NODE_TYPES17.TSTypeParameter:
|
|
1620
|
+
case AST_NODE_TYPES17.TSQualifiedName:
|
|
1555
1621
|
return true;
|
|
1556
|
-
case
|
|
1557
|
-
case
|
|
1622
|
+
case AST_NODE_TYPES17.MemberExpression:
|
|
1623
|
+
case AST_NODE_TYPES17.Identifier:
|
|
1558
1624
|
current = current.parent;
|
|
1559
1625
|
break;
|
|
1560
1626
|
default:
|
|
@@ -1584,26 +1650,26 @@ var preferImportType = createRule19({
|
|
|
1584
1650
|
return false;
|
|
1585
1651
|
}
|
|
1586
1652
|
switch (parent.type) {
|
|
1587
|
-
case
|
|
1588
|
-
case
|
|
1589
|
-
case
|
|
1590
|
-
case
|
|
1591
|
-
case
|
|
1592
|
-
case
|
|
1593
|
-
case
|
|
1594
|
-
case
|
|
1595
|
-
case
|
|
1596
|
-
case
|
|
1597
|
-
case
|
|
1598
|
-
case
|
|
1599
|
-
case
|
|
1600
|
-
case
|
|
1601
|
-
case
|
|
1602
|
-
case
|
|
1603
|
-
case
|
|
1604
|
-
case
|
|
1605
|
-
case
|
|
1606
|
-
case
|
|
1653
|
+
case AST_NODE_TYPES17.CallExpression:
|
|
1654
|
+
case AST_NODE_TYPES17.NewExpression:
|
|
1655
|
+
case AST_NODE_TYPES17.JSXOpeningElement:
|
|
1656
|
+
case AST_NODE_TYPES17.JSXClosingElement:
|
|
1657
|
+
case AST_NODE_TYPES17.MemberExpression:
|
|
1658
|
+
case AST_NODE_TYPES17.VariableDeclarator:
|
|
1659
|
+
case AST_NODE_TYPES17.TaggedTemplateExpression:
|
|
1660
|
+
case AST_NODE_TYPES17.SpreadElement:
|
|
1661
|
+
case AST_NODE_TYPES17.ExportSpecifier:
|
|
1662
|
+
case AST_NODE_TYPES17.ArrayExpression:
|
|
1663
|
+
case AST_NODE_TYPES17.ObjectExpression:
|
|
1664
|
+
case AST_NODE_TYPES17.BinaryExpression:
|
|
1665
|
+
case AST_NODE_TYPES17.LogicalExpression:
|
|
1666
|
+
case AST_NODE_TYPES17.UnaryExpression:
|
|
1667
|
+
case AST_NODE_TYPES17.ReturnStatement:
|
|
1668
|
+
case AST_NODE_TYPES17.ArrowFunctionExpression:
|
|
1669
|
+
case AST_NODE_TYPES17.ConditionalExpression:
|
|
1670
|
+
case AST_NODE_TYPES17.AwaitExpression:
|
|
1671
|
+
case AST_NODE_TYPES17.YieldExpression:
|
|
1672
|
+
case AST_NODE_TYPES17.Property:
|
|
1607
1673
|
return true;
|
|
1608
1674
|
default:
|
|
1609
1675
|
return false;
|
|
@@ -1627,13 +1693,13 @@ var preferImportType = createRule19({
|
|
|
1627
1693
|
}
|
|
1628
1694
|
const scope = context.sourceCode.getScope(node);
|
|
1629
1695
|
const isTypeOnlyImport = node.specifiers.every((specifier) => {
|
|
1630
|
-
if (specifier.type ===
|
|
1696
|
+
if (specifier.type === AST_NODE_TYPES17.ImportDefaultSpecifier) {
|
|
1631
1697
|
return false;
|
|
1632
1698
|
}
|
|
1633
|
-
if (specifier.type ===
|
|
1699
|
+
if (specifier.type === AST_NODE_TYPES17.ImportNamespaceSpecifier) {
|
|
1634
1700
|
return false;
|
|
1635
1701
|
}
|
|
1636
|
-
if (specifier.type ===
|
|
1702
|
+
if (specifier.type === AST_NODE_TYPES17.ImportSpecifier) {
|
|
1637
1703
|
const localName = specifier.local.name;
|
|
1638
1704
|
return !isUsedAsValue(localName, scope);
|
|
1639
1705
|
}
|
|
@@ -1659,11 +1725,11 @@ var preferImportType = createRule19({
|
|
|
1659
1725
|
var prefer_import_type_default = preferImportType;
|
|
1660
1726
|
|
|
1661
1727
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
1662
|
-
import { AST_NODE_TYPES as
|
|
1663
|
-
var
|
|
1728
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18, ESLintUtils as ESLintUtils21 } from "@typescript-eslint/utils";
|
|
1729
|
+
var createRule21 = ESLintUtils21.RuleCreator(
|
|
1664
1730
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1665
1731
|
);
|
|
1666
|
-
var preferInterfaceOverInlineTypes =
|
|
1732
|
+
var preferInterfaceOverInlineTypes = createRule21({
|
|
1667
1733
|
name: "prefer-interface-over-inline-types",
|
|
1668
1734
|
meta: {
|
|
1669
1735
|
type: "suggestion",
|
|
@@ -1679,54 +1745,54 @@ var preferInterfaceOverInlineTypes = createRule20({
|
|
|
1679
1745
|
defaultOptions: [],
|
|
1680
1746
|
create(context) {
|
|
1681
1747
|
function hasJSXInConditional(node) {
|
|
1682
|
-
return node.consequent.type ===
|
|
1748
|
+
return node.consequent.type === AST_NODE_TYPES18.JSXElement || node.consequent.type === AST_NODE_TYPES18.JSXFragment || node.alternate.type === AST_NODE_TYPES18.JSXElement || node.alternate.type === AST_NODE_TYPES18.JSXFragment;
|
|
1683
1749
|
}
|
|
1684
1750
|
function hasJSXInLogical(node) {
|
|
1685
|
-
return node.right.type ===
|
|
1751
|
+
return node.right.type === AST_NODE_TYPES18.JSXElement || node.right.type === AST_NODE_TYPES18.JSXFragment;
|
|
1686
1752
|
}
|
|
1687
1753
|
function hasJSXReturn(block) {
|
|
1688
1754
|
return block.body.some((stmt) => {
|
|
1689
|
-
if (stmt.type ===
|
|
1690
|
-
return stmt.argument.type ===
|
|
1755
|
+
if (stmt.type === AST_NODE_TYPES18.ReturnStatement && stmt.argument) {
|
|
1756
|
+
return stmt.argument.type === AST_NODE_TYPES18.JSXElement || stmt.argument.type === AST_NODE_TYPES18.JSXFragment || stmt.argument.type === AST_NODE_TYPES18.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES18.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
1691
1757
|
}
|
|
1692
1758
|
return false;
|
|
1693
1759
|
});
|
|
1694
1760
|
}
|
|
1695
1761
|
function isReactComponent2(node) {
|
|
1696
|
-
if (node.type ===
|
|
1697
|
-
if (node.body.type ===
|
|
1762
|
+
if (node.type === AST_NODE_TYPES18.ArrowFunctionExpression) {
|
|
1763
|
+
if (node.body.type === AST_NODE_TYPES18.JSXElement || node.body.type === AST_NODE_TYPES18.JSXFragment) {
|
|
1698
1764
|
return true;
|
|
1699
1765
|
}
|
|
1700
|
-
if (node.body.type ===
|
|
1766
|
+
if (node.body.type === AST_NODE_TYPES18.BlockStatement) {
|
|
1701
1767
|
return hasJSXReturn(node.body);
|
|
1702
1768
|
}
|
|
1703
|
-
} else if (node.type ===
|
|
1704
|
-
if (node.body && node.body.type ===
|
|
1769
|
+
} else if (node.type === AST_NODE_TYPES18.FunctionExpression || node.type === AST_NODE_TYPES18.FunctionDeclaration) {
|
|
1770
|
+
if (node.body && node.body.type === AST_NODE_TYPES18.BlockStatement) {
|
|
1705
1771
|
return hasJSXReturn(node.body);
|
|
1706
1772
|
}
|
|
1707
1773
|
}
|
|
1708
1774
|
return false;
|
|
1709
1775
|
}
|
|
1710
1776
|
function isInlineTypeAnnotation(node) {
|
|
1711
|
-
if (node.type ===
|
|
1777
|
+
if (node.type === AST_NODE_TYPES18.TSTypeLiteral) {
|
|
1712
1778
|
return true;
|
|
1713
1779
|
}
|
|
1714
|
-
if (node.type ===
|
|
1715
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
1780
|
+
if (node.type === AST_NODE_TYPES18.TSTypeReference && node.typeArguments) {
|
|
1781
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES18.TSTypeLiteral);
|
|
1716
1782
|
}
|
|
1717
|
-
if (node.type ===
|
|
1783
|
+
if (node.type === AST_NODE_TYPES18.TSUnionType) {
|
|
1718
1784
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
1719
1785
|
}
|
|
1720
1786
|
return false;
|
|
1721
1787
|
}
|
|
1722
1788
|
function hasInlineObjectType(node) {
|
|
1723
|
-
if (node.type ===
|
|
1789
|
+
if (node.type === AST_NODE_TYPES18.TSTypeLiteral) {
|
|
1724
1790
|
return true;
|
|
1725
1791
|
}
|
|
1726
|
-
if (node.type ===
|
|
1727
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
1792
|
+
if (node.type === AST_NODE_TYPES18.TSTypeReference && node.typeArguments) {
|
|
1793
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES18.TSTypeLiteral);
|
|
1728
1794
|
}
|
|
1729
|
-
if (node.type ===
|
|
1795
|
+
if (node.type === AST_NODE_TYPES18.TSUnionType) {
|
|
1730
1796
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
1731
1797
|
}
|
|
1732
1798
|
return false;
|
|
@@ -1739,7 +1805,7 @@ var preferInterfaceOverInlineTypes = createRule20({
|
|
|
1739
1805
|
return;
|
|
1740
1806
|
}
|
|
1741
1807
|
const param = node.params[0];
|
|
1742
|
-
if (param.type ===
|
|
1808
|
+
if (param.type === AST_NODE_TYPES18.Identifier && param.typeAnnotation) {
|
|
1743
1809
|
const { typeAnnotation } = param.typeAnnotation;
|
|
1744
1810
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
1745
1811
|
context.report({
|
|
@@ -1759,11 +1825,11 @@ var preferInterfaceOverInlineTypes = createRule20({
|
|
|
1759
1825
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
1760
1826
|
|
|
1761
1827
|
// src/rules/prefer-jsx-template-literals.ts
|
|
1762
|
-
import { AST_NODE_TYPES as
|
|
1763
|
-
var
|
|
1828
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES19, ESLintUtils as ESLintUtils22 } from "@typescript-eslint/utils";
|
|
1829
|
+
var createRule22 = ESLintUtils22.RuleCreator(
|
|
1764
1830
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1765
1831
|
);
|
|
1766
|
-
var preferJSXTemplateLiterals =
|
|
1832
|
+
var preferJSXTemplateLiterals = createRule22({
|
|
1767
1833
|
name: "prefer-jsx-template-literals",
|
|
1768
1834
|
meta: {
|
|
1769
1835
|
type: "suggestion",
|
|
@@ -1832,9 +1898,9 @@ var preferJSXTemplateLiterals = createRule21({
|
|
|
1832
1898
|
if (!child || !nextChild) {
|
|
1833
1899
|
return;
|
|
1834
1900
|
}
|
|
1835
|
-
if (child.type ===
|
|
1901
|
+
if (child.type === AST_NODE_TYPES19.JSXText && nextChild.type === AST_NODE_TYPES19.JSXExpressionContainer) {
|
|
1836
1902
|
handleTextBeforeExpression(child, nextChild);
|
|
1837
|
-
} else if (child.type ===
|
|
1903
|
+
} else if (child.type === AST_NODE_TYPES19.JSXExpressionContainer && nextChild.type === AST_NODE_TYPES19.JSXText) {
|
|
1838
1904
|
handleExpressionBeforeText(child, nextChild);
|
|
1839
1905
|
}
|
|
1840
1906
|
}
|
|
@@ -1847,11 +1913,11 @@ var preferJSXTemplateLiterals = createRule21({
|
|
|
1847
1913
|
var prefer_jsx_template_literals_default = preferJSXTemplateLiterals;
|
|
1848
1914
|
|
|
1849
1915
|
// src/rules/prefer-named-param-types.ts
|
|
1850
|
-
import { AST_NODE_TYPES as
|
|
1851
|
-
var
|
|
1916
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES20, ESLintUtils as ESLintUtils23 } from "@typescript-eslint/utils";
|
|
1917
|
+
var createRule23 = ESLintUtils23.RuleCreator(
|
|
1852
1918
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1853
1919
|
);
|
|
1854
|
-
var preferNamedParamTypes =
|
|
1920
|
+
var preferNamedParamTypes = createRule23({
|
|
1855
1921
|
name: "prefer-named-param-types",
|
|
1856
1922
|
meta: {
|
|
1857
1923
|
type: "suggestion",
|
|
@@ -1866,16 +1932,16 @@ var preferNamedParamTypes = createRule22({
|
|
|
1866
1932
|
defaultOptions: [],
|
|
1867
1933
|
create(context) {
|
|
1868
1934
|
function hasInlineObjectType(param) {
|
|
1869
|
-
if (param.type ===
|
|
1935
|
+
if (param.type === AST_NODE_TYPES20.AssignmentPattern) {
|
|
1870
1936
|
return hasInlineObjectType(param.left);
|
|
1871
1937
|
}
|
|
1872
|
-
if (param.type ===
|
|
1873
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
1938
|
+
if (param.type === AST_NODE_TYPES20.ObjectPattern) {
|
|
1939
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES20.TSTypeLiteral) {
|
|
1874
1940
|
return true;
|
|
1875
1941
|
}
|
|
1876
1942
|
}
|
|
1877
|
-
if (param.type ===
|
|
1878
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
1943
|
+
if (param.type === AST_NODE_TYPES20.Identifier) {
|
|
1944
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES20.TSTypeLiteral) {
|
|
1879
1945
|
return true;
|
|
1880
1946
|
}
|
|
1881
1947
|
}
|
|
@@ -1909,11 +1975,11 @@ var preferNamedParamTypes = createRule22({
|
|
|
1909
1975
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
1910
1976
|
|
|
1911
1977
|
// src/rules/prefer-react-import-types.ts
|
|
1912
|
-
import { AST_NODE_TYPES as
|
|
1913
|
-
var
|
|
1978
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21, ESLintUtils as ESLintUtils24 } from "@typescript-eslint/utils";
|
|
1979
|
+
var createRule24 = ESLintUtils24.RuleCreator(
|
|
1914
1980
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1915
1981
|
);
|
|
1916
|
-
var preferReactImportTypes =
|
|
1982
|
+
var preferReactImportTypes = createRule24({
|
|
1917
1983
|
name: "prefer-react-import-types",
|
|
1918
1984
|
meta: {
|
|
1919
1985
|
type: "suggestion",
|
|
@@ -1989,7 +2055,7 @@ var preferReactImportTypes = createRule23({
|
|
|
1989
2055
|
]);
|
|
1990
2056
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
1991
2057
|
function checkMemberExpression(node) {
|
|
1992
|
-
if (node.object.type ===
|
|
2058
|
+
if (node.object.type === AST_NODE_TYPES21.Identifier && node.object.name === "React" && node.property.type === AST_NODE_TYPES21.Identifier && allReactExports.has(node.property.name)) {
|
|
1993
2059
|
const typeName = node.property.name;
|
|
1994
2060
|
const isType = reactTypes.has(typeName);
|
|
1995
2061
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -2006,7 +2072,7 @@ var preferReactImportTypes = createRule23({
|
|
|
2006
2072
|
return {
|
|
2007
2073
|
MemberExpression: checkMemberExpression,
|
|
2008
2074
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
2009
|
-
if (node.left.type ===
|
|
2075
|
+
if (node.left.type === AST_NODE_TYPES21.Identifier && node.left.name === "React" && node.right.type === AST_NODE_TYPES21.Identifier && allReactExports.has(node.right.name)) {
|
|
2010
2076
|
const typeName = node.right.name;
|
|
2011
2077
|
const isType = reactTypes.has(typeName);
|
|
2012
2078
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -2026,11 +2092,11 @@ var preferReactImportTypes = createRule23({
|
|
|
2026
2092
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
2027
2093
|
|
|
2028
2094
|
// src/rules/react-props-destructure.ts
|
|
2029
|
-
import { AST_NODE_TYPES as
|
|
2030
|
-
var
|
|
2095
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22, ESLintUtils as ESLintUtils25 } from "@typescript-eslint/utils";
|
|
2096
|
+
var createRule25 = ESLintUtils25.RuleCreator(
|
|
2031
2097
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2032
2098
|
);
|
|
2033
|
-
var reactPropsDestructure =
|
|
2099
|
+
var reactPropsDestructure = createRule25({
|
|
2034
2100
|
name: "react-props-destructure",
|
|
2035
2101
|
meta: {
|
|
2036
2102
|
type: "suggestion",
|
|
@@ -2046,29 +2112,29 @@ var reactPropsDestructure = createRule24({
|
|
|
2046
2112
|
defaultOptions: [],
|
|
2047
2113
|
create(context) {
|
|
2048
2114
|
function hasJSXInConditional(node) {
|
|
2049
|
-
return node.consequent.type ===
|
|
2115
|
+
return node.consequent.type === AST_NODE_TYPES22.JSXElement || node.consequent.type === AST_NODE_TYPES22.JSXFragment || node.alternate.type === AST_NODE_TYPES22.JSXElement || node.alternate.type === AST_NODE_TYPES22.JSXFragment;
|
|
2050
2116
|
}
|
|
2051
2117
|
function hasJSXInLogical(node) {
|
|
2052
|
-
return node.right.type ===
|
|
2118
|
+
return node.right.type === AST_NODE_TYPES22.JSXElement || node.right.type === AST_NODE_TYPES22.JSXFragment;
|
|
2053
2119
|
}
|
|
2054
2120
|
function hasJSXReturn(block) {
|
|
2055
2121
|
return block.body.some((stmt) => {
|
|
2056
|
-
if (stmt.type ===
|
|
2057
|
-
return stmt.argument.type ===
|
|
2122
|
+
if (stmt.type === AST_NODE_TYPES22.ReturnStatement && stmt.argument) {
|
|
2123
|
+
return stmt.argument.type === AST_NODE_TYPES22.JSXElement || stmt.argument.type === AST_NODE_TYPES22.JSXFragment || stmt.argument.type === AST_NODE_TYPES22.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES22.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
2058
2124
|
}
|
|
2059
2125
|
return false;
|
|
2060
2126
|
});
|
|
2061
2127
|
}
|
|
2062
2128
|
function isReactComponent2(node) {
|
|
2063
|
-
if (node.type ===
|
|
2064
|
-
if (node.body.type ===
|
|
2129
|
+
if (node.type === AST_NODE_TYPES22.ArrowFunctionExpression) {
|
|
2130
|
+
if (node.body.type === AST_NODE_TYPES22.JSXElement || node.body.type === AST_NODE_TYPES22.JSXFragment) {
|
|
2065
2131
|
return true;
|
|
2066
2132
|
}
|
|
2067
|
-
if (node.body.type ===
|
|
2133
|
+
if (node.body.type === AST_NODE_TYPES22.BlockStatement) {
|
|
2068
2134
|
return hasJSXReturn(node.body);
|
|
2069
2135
|
}
|
|
2070
|
-
} else if (node.type ===
|
|
2071
|
-
if (node.body && node.body.type ===
|
|
2136
|
+
} else if (node.type === AST_NODE_TYPES22.FunctionExpression || node.type === AST_NODE_TYPES22.FunctionDeclaration) {
|
|
2137
|
+
if (node.body && node.body.type === AST_NODE_TYPES22.BlockStatement) {
|
|
2072
2138
|
return hasJSXReturn(node.body);
|
|
2073
2139
|
}
|
|
2074
2140
|
}
|
|
@@ -2082,9 +2148,9 @@ var reactPropsDestructure = createRule24({
|
|
|
2082
2148
|
return;
|
|
2083
2149
|
}
|
|
2084
2150
|
const param = node.params[0];
|
|
2085
|
-
if (param.type ===
|
|
2086
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
2087
|
-
if (prop.key.type ===
|
|
2151
|
+
if (param.type === AST_NODE_TYPES22.ObjectPattern) {
|
|
2152
|
+
const properties = param.properties.filter((prop) => prop.type === AST_NODE_TYPES22.Property).map((prop) => {
|
|
2153
|
+
if (prop.key.type === AST_NODE_TYPES22.Identifier) {
|
|
2088
2154
|
return prop.key.name;
|
|
2089
2155
|
}
|
|
2090
2156
|
return null;
|
|
@@ -2128,6 +2194,7 @@ var rules = {
|
|
|
2128
2194
|
"no-direct-date": no_direct_date_default,
|
|
2129
2195
|
"no-emoji": no_emoji_default,
|
|
2130
2196
|
"no-env-fallback": no_env_fallback_default,
|
|
2197
|
+
"no-inline-default-export": no_inline_default_export_default,
|
|
2131
2198
|
"require-explicit-return-type": require_explicit_return_type_default,
|
|
2132
2199
|
"no-lazy-identifiers": no_lazy_identifiers_default,
|
|
2133
2200
|
"no-logic-in-params": no_logic_in_params_default,
|
|
@@ -2161,6 +2228,7 @@ var baseRules = {
|
|
|
2161
2228
|
"nextfriday/no-direct-date": "warn",
|
|
2162
2229
|
"nextfriday/no-logic-in-params": "warn",
|
|
2163
2230
|
"nextfriday/no-env-fallback": "warn",
|
|
2231
|
+
"nextfriday/no-inline-default-export": "warn",
|
|
2164
2232
|
"nextfriday/no-lazy-identifiers": "warn",
|
|
2165
2233
|
"nextfriday/no-single-char-variables": "warn"
|
|
2166
2234
|
};
|
|
@@ -2180,6 +2248,7 @@ var baseRecommendedRules = {
|
|
|
2180
2248
|
"nextfriday/no-direct-date": "error",
|
|
2181
2249
|
"nextfriday/no-logic-in-params": "error",
|
|
2182
2250
|
"nextfriday/no-env-fallback": "error",
|
|
2251
|
+
"nextfriday/no-inline-default-export": "error",
|
|
2183
2252
|
"nextfriday/no-lazy-identifiers": "error",
|
|
2184
2253
|
"nextfriday/no-single-char-variables": "error"
|
|
2185
2254
|
};
|