eslint-plugin-nextfriday 1.7.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 +20 -0
- package/README.md +14 -8
- package/docs/rules/NO_INLINE_DEFAULT_EXPORT.md +78 -0
- package/docs/rules/NO_LAZY_IDENTIFIERS.md +106 -0
- package/lib/index.cjs +370 -162
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +28 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.js +370 -162
- 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;
|
|
@@ -1101,9 +1167,145 @@ var noLogicInParams = createRule14({
|
|
|
1101
1167
|
});
|
|
1102
1168
|
var no_logic_in_params_default = noLogicInParams;
|
|
1103
1169
|
|
|
1170
|
+
// src/rules/no-lazy-identifiers.ts
|
|
1171
|
+
import { ESLintUtils as ESLintUtils16, AST_NODE_TYPES as AST_NODE_TYPES13 } from "@typescript-eslint/utils";
|
|
1172
|
+
var createRule16 = ESLintUtils16.RuleCreator(
|
|
1173
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1174
|
+
);
|
|
1175
|
+
var KEYBOARD_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm", "1234567890"];
|
|
1176
|
+
var MIN_LENGTH = 3;
|
|
1177
|
+
var MIN_SEQUENCE_LENGTH = 4;
|
|
1178
|
+
var hasRepeatedChars = (name) => {
|
|
1179
|
+
const lowerName = name.toLowerCase();
|
|
1180
|
+
return lowerName.split("").some((char, index) => {
|
|
1181
|
+
if (index > lowerName.length - 3) {
|
|
1182
|
+
return false;
|
|
1183
|
+
}
|
|
1184
|
+
return char === lowerName[index + 1] && char === lowerName[index + 2];
|
|
1185
|
+
});
|
|
1186
|
+
};
|
|
1187
|
+
var hasKeyboardSequence = (name) => {
|
|
1188
|
+
const lowerName = name.toLowerCase();
|
|
1189
|
+
if (lowerName.length < MIN_SEQUENCE_LENGTH) {
|
|
1190
|
+
return false;
|
|
1191
|
+
}
|
|
1192
|
+
return KEYBOARD_ROWS.some((row) => {
|
|
1193
|
+
const positions = Array.from({ length: row.length - MIN_SEQUENCE_LENGTH + 1 }, (_, i) => i);
|
|
1194
|
+
return positions.some((start) => {
|
|
1195
|
+
const sequence = row.slice(start, start + MIN_SEQUENCE_LENGTH);
|
|
1196
|
+
const reverseSequence = sequence.split("").reverse().join("");
|
|
1197
|
+
return lowerName.includes(sequence) || lowerName.includes(reverseSequence);
|
|
1198
|
+
});
|
|
1199
|
+
});
|
|
1200
|
+
};
|
|
1201
|
+
var isLazyIdentifier = (name) => {
|
|
1202
|
+
if (name.length < MIN_LENGTH) {
|
|
1203
|
+
return false;
|
|
1204
|
+
}
|
|
1205
|
+
if (name.startsWith("_")) {
|
|
1206
|
+
return false;
|
|
1207
|
+
}
|
|
1208
|
+
if (hasRepeatedChars(name)) {
|
|
1209
|
+
return true;
|
|
1210
|
+
}
|
|
1211
|
+
if (hasKeyboardSequence(name)) {
|
|
1212
|
+
return true;
|
|
1213
|
+
}
|
|
1214
|
+
return false;
|
|
1215
|
+
};
|
|
1216
|
+
var noLazyIdentifiers = createRule16({
|
|
1217
|
+
name: "no-lazy-identifiers",
|
|
1218
|
+
meta: {
|
|
1219
|
+
type: "problem",
|
|
1220
|
+
docs: {
|
|
1221
|
+
description: "Disallow lazy, meaningless variable names that hurt code readability"
|
|
1222
|
+
},
|
|
1223
|
+
messages: {
|
|
1224
|
+
noLazyIdentifier: "Avoid lazy identifier '{{name}}'. Use a descriptive name that clearly indicates the purpose."
|
|
1225
|
+
},
|
|
1226
|
+
schema: []
|
|
1227
|
+
},
|
|
1228
|
+
defaultOptions: [],
|
|
1229
|
+
create(context) {
|
|
1230
|
+
const checkIdentifier = (node) => {
|
|
1231
|
+
const { name } = node;
|
|
1232
|
+
if (!isLazyIdentifier(name)) {
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
context.report({
|
|
1236
|
+
node,
|
|
1237
|
+
messageId: "noLazyIdentifier",
|
|
1238
|
+
data: { name }
|
|
1239
|
+
});
|
|
1240
|
+
};
|
|
1241
|
+
const checkPattern = (pattern) => {
|
|
1242
|
+
if (pattern.type === AST_NODE_TYPES13.Identifier) {
|
|
1243
|
+
checkIdentifier(pattern);
|
|
1244
|
+
} else if (pattern.type === AST_NODE_TYPES13.ObjectPattern) {
|
|
1245
|
+
pattern.properties.forEach((prop) => {
|
|
1246
|
+
if (prop.type === AST_NODE_TYPES13.Property && prop.value.type === AST_NODE_TYPES13.Identifier) {
|
|
1247
|
+
checkIdentifier(prop.value);
|
|
1248
|
+
} else if (prop.type === AST_NODE_TYPES13.RestElement && prop.argument.type === AST_NODE_TYPES13.Identifier) {
|
|
1249
|
+
checkIdentifier(prop.argument);
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
} else if (pattern.type === AST_NODE_TYPES13.ArrayPattern) {
|
|
1253
|
+
pattern.elements.forEach((element) => {
|
|
1254
|
+
if (element?.type === AST_NODE_TYPES13.Identifier) {
|
|
1255
|
+
checkIdentifier(element);
|
|
1256
|
+
} else if (element?.type === AST_NODE_TYPES13.RestElement && element.argument.type === AST_NODE_TYPES13.Identifier) {
|
|
1257
|
+
checkIdentifier(element.argument);
|
|
1258
|
+
}
|
|
1259
|
+
});
|
|
1260
|
+
} else if (pattern.type === AST_NODE_TYPES13.AssignmentPattern && pattern.left.type === AST_NODE_TYPES13.Identifier) {
|
|
1261
|
+
checkIdentifier(pattern.left);
|
|
1262
|
+
} else if (pattern.type === AST_NODE_TYPES13.RestElement && pattern.argument.type === AST_NODE_TYPES13.Identifier) {
|
|
1263
|
+
checkIdentifier(pattern.argument);
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
return {
|
|
1267
|
+
VariableDeclarator(node) {
|
|
1268
|
+
checkPattern(node.id);
|
|
1269
|
+
},
|
|
1270
|
+
FunctionDeclaration(node) {
|
|
1271
|
+
if (node.id) {
|
|
1272
|
+
checkIdentifier(node.id);
|
|
1273
|
+
}
|
|
1274
|
+
node.params.forEach((param) => checkPattern(param));
|
|
1275
|
+
},
|
|
1276
|
+
FunctionExpression(node) {
|
|
1277
|
+
if (node.id) {
|
|
1278
|
+
checkIdentifier(node.id);
|
|
1279
|
+
}
|
|
1280
|
+
node.params.forEach((param) => checkPattern(param));
|
|
1281
|
+
},
|
|
1282
|
+
ArrowFunctionExpression(node) {
|
|
1283
|
+
node.params.forEach((param) => checkPattern(param));
|
|
1284
|
+
},
|
|
1285
|
+
CatchClause(node) {
|
|
1286
|
+
if (node.param) {
|
|
1287
|
+
checkPattern(node.param);
|
|
1288
|
+
}
|
|
1289
|
+
},
|
|
1290
|
+
ClassDeclaration(node) {
|
|
1291
|
+
if (node.id) {
|
|
1292
|
+
checkIdentifier(node.id);
|
|
1293
|
+
}
|
|
1294
|
+
},
|
|
1295
|
+
TSTypeAliasDeclaration(node) {
|
|
1296
|
+
checkIdentifier(node.id);
|
|
1297
|
+
},
|
|
1298
|
+
TSInterfaceDeclaration(node) {
|
|
1299
|
+
checkIdentifier(node.id);
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
var no_lazy_identifiers_default = noLazyIdentifiers;
|
|
1305
|
+
|
|
1104
1306
|
// src/rules/no-single-char-variables.ts
|
|
1105
|
-
import { ESLintUtils as
|
|
1106
|
-
var
|
|
1307
|
+
import { ESLintUtils as ESLintUtils17, AST_NODE_TYPES as AST_NODE_TYPES14 } from "@typescript-eslint/utils";
|
|
1308
|
+
var createRule17 = ESLintUtils17.RuleCreator(
|
|
1107
1309
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1108
1310
|
);
|
|
1109
1311
|
var ALLOWED_IN_FOR_LOOPS = /* @__PURE__ */ new Set(["i", "j", "k", "n"]);
|
|
@@ -1115,7 +1317,7 @@ var isForLoopInit = (node) => {
|
|
|
1115
1317
|
if (!parentNode) {
|
|
1116
1318
|
return false;
|
|
1117
1319
|
}
|
|
1118
|
-
if (parentNode.type ===
|
|
1320
|
+
if (parentNode.type === AST_NODE_TYPES14.ForStatement) {
|
|
1119
1321
|
const { init } = parentNode;
|
|
1120
1322
|
if (init && init === current) {
|
|
1121
1323
|
return true;
|
|
@@ -1134,7 +1336,7 @@ var isAllowedInContext = (name, node) => {
|
|
|
1134
1336
|
}
|
|
1135
1337
|
return false;
|
|
1136
1338
|
};
|
|
1137
|
-
var noSingleCharVariables =
|
|
1339
|
+
var noSingleCharVariables = createRule17({
|
|
1138
1340
|
name: "no-single-char-variables",
|
|
1139
1341
|
meta: {
|
|
1140
1342
|
type: "suggestion",
|
|
@@ -1163,27 +1365,27 @@ var noSingleCharVariables = createRule15({
|
|
|
1163
1365
|
});
|
|
1164
1366
|
};
|
|
1165
1367
|
const checkPattern = (pattern, declarationNode) => {
|
|
1166
|
-
if (pattern.type ===
|
|
1368
|
+
if (pattern.type === AST_NODE_TYPES14.Identifier) {
|
|
1167
1369
|
checkIdentifier(pattern, declarationNode);
|
|
1168
|
-
} else if (pattern.type ===
|
|
1370
|
+
} else if (pattern.type === AST_NODE_TYPES14.ObjectPattern) {
|
|
1169
1371
|
pattern.properties.forEach((prop) => {
|
|
1170
|
-
if (prop.type ===
|
|
1372
|
+
if (prop.type === AST_NODE_TYPES14.Property && prop.value.type === AST_NODE_TYPES14.Identifier) {
|
|
1171
1373
|
checkIdentifier(prop.value, declarationNode);
|
|
1172
|
-
} else if (prop.type ===
|
|
1374
|
+
} else if (prop.type === AST_NODE_TYPES14.RestElement && prop.argument.type === AST_NODE_TYPES14.Identifier) {
|
|
1173
1375
|
checkIdentifier(prop.argument, declarationNode);
|
|
1174
1376
|
}
|
|
1175
1377
|
});
|
|
1176
|
-
} else if (pattern.type ===
|
|
1378
|
+
} else if (pattern.type === AST_NODE_TYPES14.ArrayPattern) {
|
|
1177
1379
|
pattern.elements.forEach((element) => {
|
|
1178
|
-
if (element?.type ===
|
|
1380
|
+
if (element?.type === AST_NODE_TYPES14.Identifier) {
|
|
1179
1381
|
checkIdentifier(element, declarationNode);
|
|
1180
|
-
} else if (element?.type ===
|
|
1382
|
+
} else if (element?.type === AST_NODE_TYPES14.RestElement && element.argument.type === AST_NODE_TYPES14.Identifier) {
|
|
1181
1383
|
checkIdentifier(element.argument, declarationNode);
|
|
1182
1384
|
}
|
|
1183
1385
|
});
|
|
1184
|
-
} else if (pattern.type ===
|
|
1386
|
+
} else if (pattern.type === AST_NODE_TYPES14.AssignmentPattern && pattern.left.type === AST_NODE_TYPES14.Identifier) {
|
|
1185
1387
|
checkIdentifier(pattern.left, declarationNode);
|
|
1186
|
-
} else if (pattern.type ===
|
|
1388
|
+
} else if (pattern.type === AST_NODE_TYPES14.RestElement && pattern.argument.type === AST_NODE_TYPES14.Identifier) {
|
|
1187
1389
|
checkIdentifier(pattern.argument, declarationNode);
|
|
1188
1390
|
}
|
|
1189
1391
|
};
|
|
@@ -1217,11 +1419,11 @@ var noSingleCharVariables = createRule15({
|
|
|
1217
1419
|
var no_single_char_variables_default = noSingleCharVariables;
|
|
1218
1420
|
|
|
1219
1421
|
// src/rules/prefer-destructuring-params.ts
|
|
1220
|
-
import { AST_NODE_TYPES as
|
|
1221
|
-
var
|
|
1422
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15, ESLintUtils as ESLintUtils18 } from "@typescript-eslint/utils";
|
|
1423
|
+
var createRule18 = ESLintUtils18.RuleCreator(
|
|
1222
1424
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1223
1425
|
);
|
|
1224
|
-
var preferDestructuringParams =
|
|
1426
|
+
var preferDestructuringParams = createRule18({
|
|
1225
1427
|
name: "prefer-destructuring-params",
|
|
1226
1428
|
meta: {
|
|
1227
1429
|
type: "suggestion",
|
|
@@ -1237,18 +1439,18 @@ var preferDestructuringParams = createRule16({
|
|
|
1237
1439
|
create(context) {
|
|
1238
1440
|
const isCallbackFunction2 = (node) => {
|
|
1239
1441
|
const { parent } = node;
|
|
1240
|
-
return parent?.type ===
|
|
1442
|
+
return parent?.type === AST_NODE_TYPES15.CallExpression;
|
|
1241
1443
|
};
|
|
1242
1444
|
const isDeveloperFunction = (node) => {
|
|
1243
|
-
if (node.type ===
|
|
1445
|
+
if (node.type === AST_NODE_TYPES15.FunctionDeclaration) {
|
|
1244
1446
|
return true;
|
|
1245
1447
|
}
|
|
1246
|
-
if (node.type ===
|
|
1448
|
+
if (node.type === AST_NODE_TYPES15.FunctionExpression || node.type === AST_NODE_TYPES15.ArrowFunctionExpression) {
|
|
1247
1449
|
if (isCallbackFunction2(node)) {
|
|
1248
1450
|
return false;
|
|
1249
1451
|
}
|
|
1250
1452
|
const { parent } = node;
|
|
1251
|
-
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;
|
|
1252
1454
|
}
|
|
1253
1455
|
return false;
|
|
1254
1456
|
};
|
|
@@ -1260,7 +1462,7 @@ var preferDestructuringParams = createRule16({
|
|
|
1260
1462
|
if (!isDeveloperFunction(node)) {
|
|
1261
1463
|
return;
|
|
1262
1464
|
}
|
|
1263
|
-
if (node.type ===
|
|
1465
|
+
if (node.type === AST_NODE_TYPES15.FunctionDeclaration && node.id) {
|
|
1264
1466
|
const functionName = node.id.name;
|
|
1265
1467
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
1266
1468
|
return;
|
|
@@ -1270,7 +1472,7 @@ var preferDestructuringParams = createRule16({
|
|
|
1270
1472
|
return;
|
|
1271
1473
|
}
|
|
1272
1474
|
const hasNonDestructuredParams = node.params.some(
|
|
1273
|
-
(param) => param.type !==
|
|
1475
|
+
(param) => param.type !== AST_NODE_TYPES15.ObjectPattern && param.type !== AST_NODE_TYPES15.RestElement
|
|
1274
1476
|
);
|
|
1275
1477
|
if (hasNonDestructuredParams) {
|
|
1276
1478
|
context.report({
|
|
@@ -1289,8 +1491,8 @@ var preferDestructuringParams = createRule16({
|
|
|
1289
1491
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
1290
1492
|
|
|
1291
1493
|
// src/rules/prefer-function-declaration.ts
|
|
1292
|
-
import { ESLintUtils as
|
|
1293
|
-
var
|
|
1494
|
+
import { ESLintUtils as ESLintUtils19, AST_NODE_TYPES as AST_NODE_TYPES16 } from "@typescript-eslint/utils";
|
|
1495
|
+
var createRule19 = ESLintUtils19.RuleCreator(
|
|
1294
1496
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1295
1497
|
);
|
|
1296
1498
|
var isTsFile = (filename) => filename.endsWith(".ts") && !filename.endsWith(".d.ts");
|
|
@@ -1299,33 +1501,33 @@ var isCallbackContext = (node) => {
|
|
|
1299
1501
|
if (!parent) {
|
|
1300
1502
|
return false;
|
|
1301
1503
|
}
|
|
1302
|
-
if (parent.type ===
|
|
1504
|
+
if (parent.type === AST_NODE_TYPES16.CallExpression && parent.arguments.includes(node)) {
|
|
1303
1505
|
return true;
|
|
1304
1506
|
}
|
|
1305
|
-
if (parent.type ===
|
|
1507
|
+
if (parent.type === AST_NODE_TYPES16.NewExpression && parent.arguments.includes(node)) {
|
|
1306
1508
|
return true;
|
|
1307
1509
|
}
|
|
1308
|
-
if (parent.type ===
|
|
1510
|
+
if (parent.type === AST_NODE_TYPES16.ReturnStatement) {
|
|
1309
1511
|
return true;
|
|
1310
1512
|
}
|
|
1311
|
-
if (parent.type ===
|
|
1513
|
+
if (parent.type === AST_NODE_TYPES16.Property) {
|
|
1312
1514
|
return true;
|
|
1313
1515
|
}
|
|
1314
|
-
if (parent.type ===
|
|
1516
|
+
if (parent.type === AST_NODE_TYPES16.ArrayExpression) {
|
|
1315
1517
|
return true;
|
|
1316
1518
|
}
|
|
1317
|
-
if (parent.type ===
|
|
1519
|
+
if (parent.type === AST_NODE_TYPES16.ConditionalExpression) {
|
|
1318
1520
|
return true;
|
|
1319
1521
|
}
|
|
1320
|
-
if (parent.type ===
|
|
1522
|
+
if (parent.type === AST_NODE_TYPES16.LogicalExpression) {
|
|
1321
1523
|
return true;
|
|
1322
1524
|
}
|
|
1323
|
-
if (parent.type ===
|
|
1525
|
+
if (parent.type === AST_NODE_TYPES16.AssignmentExpression && parent.left !== node) {
|
|
1324
1526
|
return true;
|
|
1325
1527
|
}
|
|
1326
1528
|
return false;
|
|
1327
1529
|
};
|
|
1328
|
-
var preferFunctionDeclaration =
|
|
1530
|
+
var preferFunctionDeclaration = createRule19({
|
|
1329
1531
|
name: "prefer-function-declaration",
|
|
1330
1532
|
meta: {
|
|
1331
1533
|
type: "suggestion",
|
|
@@ -1346,14 +1548,14 @@ var preferFunctionDeclaration = createRule17({
|
|
|
1346
1548
|
}
|
|
1347
1549
|
return {
|
|
1348
1550
|
VariableDeclarator(node) {
|
|
1349
|
-
if (node.id.type !==
|
|
1551
|
+
if (node.id.type !== AST_NODE_TYPES16.Identifier) {
|
|
1350
1552
|
return;
|
|
1351
1553
|
}
|
|
1352
1554
|
const { init } = node;
|
|
1353
1555
|
if (!init) {
|
|
1354
1556
|
return;
|
|
1355
1557
|
}
|
|
1356
|
-
if (init.type ===
|
|
1558
|
+
if (init.type === AST_NODE_TYPES16.ArrowFunctionExpression) {
|
|
1357
1559
|
if (isCallbackContext(init)) {
|
|
1358
1560
|
return;
|
|
1359
1561
|
}
|
|
@@ -1363,7 +1565,7 @@ var preferFunctionDeclaration = createRule17({
|
|
|
1363
1565
|
data: { name: node.id.name }
|
|
1364
1566
|
});
|
|
1365
1567
|
}
|
|
1366
|
-
if (init.type ===
|
|
1568
|
+
if (init.type === AST_NODE_TYPES16.FunctionExpression) {
|
|
1367
1569
|
if (isCallbackContext(init)) {
|
|
1368
1570
|
return;
|
|
1369
1571
|
}
|
|
@@ -1380,11 +1582,11 @@ var preferFunctionDeclaration = createRule17({
|
|
|
1380
1582
|
var prefer_function_declaration_default = preferFunctionDeclaration;
|
|
1381
1583
|
|
|
1382
1584
|
// src/rules/prefer-import-type.ts
|
|
1383
|
-
import { AST_NODE_TYPES as
|
|
1384
|
-
var
|
|
1585
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES17, ESLintUtils as ESLintUtils20 } from "@typescript-eslint/utils";
|
|
1586
|
+
var createRule20 = ESLintUtils20.RuleCreator(
|
|
1385
1587
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1386
1588
|
);
|
|
1387
|
-
var preferImportType =
|
|
1589
|
+
var preferImportType = createRule20({
|
|
1388
1590
|
name: "prefer-import-type",
|
|
1389
1591
|
meta: {
|
|
1390
1592
|
type: "suggestion",
|
|
@@ -1403,22 +1605,22 @@ var preferImportType = createRule18({
|
|
|
1403
1605
|
let current = node;
|
|
1404
1606
|
while (current) {
|
|
1405
1607
|
switch (current.type) {
|
|
1406
|
-
case
|
|
1407
|
-
case
|
|
1408
|
-
case
|
|
1409
|
-
case
|
|
1410
|
-
case
|
|
1411
|
-
case
|
|
1412
|
-
case
|
|
1413
|
-
case
|
|
1414
|
-
case
|
|
1415
|
-
case
|
|
1416
|
-
case
|
|
1417
|
-
case
|
|
1418
|
-
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:
|
|
1419
1621
|
return true;
|
|
1420
|
-
case
|
|
1421
|
-
case
|
|
1622
|
+
case AST_NODE_TYPES17.MemberExpression:
|
|
1623
|
+
case AST_NODE_TYPES17.Identifier:
|
|
1422
1624
|
current = current.parent;
|
|
1423
1625
|
break;
|
|
1424
1626
|
default:
|
|
@@ -1448,26 +1650,26 @@ var preferImportType = createRule18({
|
|
|
1448
1650
|
return false;
|
|
1449
1651
|
}
|
|
1450
1652
|
switch (parent.type) {
|
|
1451
|
-
case
|
|
1452
|
-
case
|
|
1453
|
-
case
|
|
1454
|
-
case
|
|
1455
|
-
case
|
|
1456
|
-
case
|
|
1457
|
-
case
|
|
1458
|
-
case
|
|
1459
|
-
case
|
|
1460
|
-
case
|
|
1461
|
-
case
|
|
1462
|
-
case
|
|
1463
|
-
case
|
|
1464
|
-
case
|
|
1465
|
-
case
|
|
1466
|
-
case
|
|
1467
|
-
case
|
|
1468
|
-
case
|
|
1469
|
-
case
|
|
1470
|
-
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:
|
|
1471
1673
|
return true;
|
|
1472
1674
|
default:
|
|
1473
1675
|
return false;
|
|
@@ -1491,13 +1693,13 @@ var preferImportType = createRule18({
|
|
|
1491
1693
|
}
|
|
1492
1694
|
const scope = context.sourceCode.getScope(node);
|
|
1493
1695
|
const isTypeOnlyImport = node.specifiers.every((specifier) => {
|
|
1494
|
-
if (specifier.type ===
|
|
1696
|
+
if (specifier.type === AST_NODE_TYPES17.ImportDefaultSpecifier) {
|
|
1495
1697
|
return false;
|
|
1496
1698
|
}
|
|
1497
|
-
if (specifier.type ===
|
|
1699
|
+
if (specifier.type === AST_NODE_TYPES17.ImportNamespaceSpecifier) {
|
|
1498
1700
|
return false;
|
|
1499
1701
|
}
|
|
1500
|
-
if (specifier.type ===
|
|
1702
|
+
if (specifier.type === AST_NODE_TYPES17.ImportSpecifier) {
|
|
1501
1703
|
const localName = specifier.local.name;
|
|
1502
1704
|
return !isUsedAsValue(localName, scope);
|
|
1503
1705
|
}
|
|
@@ -1523,11 +1725,11 @@ var preferImportType = createRule18({
|
|
|
1523
1725
|
var prefer_import_type_default = preferImportType;
|
|
1524
1726
|
|
|
1525
1727
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
1526
|
-
import { AST_NODE_TYPES as
|
|
1527
|
-
var
|
|
1728
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18, ESLintUtils as ESLintUtils21 } from "@typescript-eslint/utils";
|
|
1729
|
+
var createRule21 = ESLintUtils21.RuleCreator(
|
|
1528
1730
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1529
1731
|
);
|
|
1530
|
-
var preferInterfaceOverInlineTypes =
|
|
1732
|
+
var preferInterfaceOverInlineTypes = createRule21({
|
|
1531
1733
|
name: "prefer-interface-over-inline-types",
|
|
1532
1734
|
meta: {
|
|
1533
1735
|
type: "suggestion",
|
|
@@ -1543,54 +1745,54 @@ var preferInterfaceOverInlineTypes = createRule19({
|
|
|
1543
1745
|
defaultOptions: [],
|
|
1544
1746
|
create(context) {
|
|
1545
1747
|
function hasJSXInConditional(node) {
|
|
1546
|
-
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;
|
|
1547
1749
|
}
|
|
1548
1750
|
function hasJSXInLogical(node) {
|
|
1549
|
-
return node.right.type ===
|
|
1751
|
+
return node.right.type === AST_NODE_TYPES18.JSXElement || node.right.type === AST_NODE_TYPES18.JSXFragment;
|
|
1550
1752
|
}
|
|
1551
1753
|
function hasJSXReturn(block) {
|
|
1552
1754
|
return block.body.some((stmt) => {
|
|
1553
|
-
if (stmt.type ===
|
|
1554
|
-
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);
|
|
1555
1757
|
}
|
|
1556
1758
|
return false;
|
|
1557
1759
|
});
|
|
1558
1760
|
}
|
|
1559
1761
|
function isReactComponent2(node) {
|
|
1560
|
-
if (node.type ===
|
|
1561
|
-
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) {
|
|
1562
1764
|
return true;
|
|
1563
1765
|
}
|
|
1564
|
-
if (node.body.type ===
|
|
1766
|
+
if (node.body.type === AST_NODE_TYPES18.BlockStatement) {
|
|
1565
1767
|
return hasJSXReturn(node.body);
|
|
1566
1768
|
}
|
|
1567
|
-
} else if (node.type ===
|
|
1568
|
-
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) {
|
|
1569
1771
|
return hasJSXReturn(node.body);
|
|
1570
1772
|
}
|
|
1571
1773
|
}
|
|
1572
1774
|
return false;
|
|
1573
1775
|
}
|
|
1574
1776
|
function isInlineTypeAnnotation(node) {
|
|
1575
|
-
if (node.type ===
|
|
1777
|
+
if (node.type === AST_NODE_TYPES18.TSTypeLiteral) {
|
|
1576
1778
|
return true;
|
|
1577
1779
|
}
|
|
1578
|
-
if (node.type ===
|
|
1579
|
-
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);
|
|
1580
1782
|
}
|
|
1581
|
-
if (node.type ===
|
|
1783
|
+
if (node.type === AST_NODE_TYPES18.TSUnionType) {
|
|
1582
1784
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
1583
1785
|
}
|
|
1584
1786
|
return false;
|
|
1585
1787
|
}
|
|
1586
1788
|
function hasInlineObjectType(node) {
|
|
1587
|
-
if (node.type ===
|
|
1789
|
+
if (node.type === AST_NODE_TYPES18.TSTypeLiteral) {
|
|
1588
1790
|
return true;
|
|
1589
1791
|
}
|
|
1590
|
-
if (node.type ===
|
|
1591
|
-
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);
|
|
1592
1794
|
}
|
|
1593
|
-
if (node.type ===
|
|
1795
|
+
if (node.type === AST_NODE_TYPES18.TSUnionType) {
|
|
1594
1796
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
1595
1797
|
}
|
|
1596
1798
|
return false;
|
|
@@ -1603,7 +1805,7 @@ var preferInterfaceOverInlineTypes = createRule19({
|
|
|
1603
1805
|
return;
|
|
1604
1806
|
}
|
|
1605
1807
|
const param = node.params[0];
|
|
1606
|
-
if (param.type ===
|
|
1808
|
+
if (param.type === AST_NODE_TYPES18.Identifier && param.typeAnnotation) {
|
|
1607
1809
|
const { typeAnnotation } = param.typeAnnotation;
|
|
1608
1810
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
1609
1811
|
context.report({
|
|
@@ -1623,11 +1825,11 @@ var preferInterfaceOverInlineTypes = createRule19({
|
|
|
1623
1825
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
1624
1826
|
|
|
1625
1827
|
// src/rules/prefer-jsx-template-literals.ts
|
|
1626
|
-
import { AST_NODE_TYPES as
|
|
1627
|
-
var
|
|
1828
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES19, ESLintUtils as ESLintUtils22 } from "@typescript-eslint/utils";
|
|
1829
|
+
var createRule22 = ESLintUtils22.RuleCreator(
|
|
1628
1830
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1629
1831
|
);
|
|
1630
|
-
var preferJSXTemplateLiterals =
|
|
1832
|
+
var preferJSXTemplateLiterals = createRule22({
|
|
1631
1833
|
name: "prefer-jsx-template-literals",
|
|
1632
1834
|
meta: {
|
|
1633
1835
|
type: "suggestion",
|
|
@@ -1696,9 +1898,9 @@ var preferJSXTemplateLiterals = createRule20({
|
|
|
1696
1898
|
if (!child || !nextChild) {
|
|
1697
1899
|
return;
|
|
1698
1900
|
}
|
|
1699
|
-
if (child.type ===
|
|
1901
|
+
if (child.type === AST_NODE_TYPES19.JSXText && nextChild.type === AST_NODE_TYPES19.JSXExpressionContainer) {
|
|
1700
1902
|
handleTextBeforeExpression(child, nextChild);
|
|
1701
|
-
} else if (child.type ===
|
|
1903
|
+
} else if (child.type === AST_NODE_TYPES19.JSXExpressionContainer && nextChild.type === AST_NODE_TYPES19.JSXText) {
|
|
1702
1904
|
handleExpressionBeforeText(child, nextChild);
|
|
1703
1905
|
}
|
|
1704
1906
|
}
|
|
@@ -1711,11 +1913,11 @@ var preferJSXTemplateLiterals = createRule20({
|
|
|
1711
1913
|
var prefer_jsx_template_literals_default = preferJSXTemplateLiterals;
|
|
1712
1914
|
|
|
1713
1915
|
// src/rules/prefer-named-param-types.ts
|
|
1714
|
-
import { AST_NODE_TYPES as
|
|
1715
|
-
var
|
|
1916
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES20, ESLintUtils as ESLintUtils23 } from "@typescript-eslint/utils";
|
|
1917
|
+
var createRule23 = ESLintUtils23.RuleCreator(
|
|
1716
1918
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1717
1919
|
);
|
|
1718
|
-
var preferNamedParamTypes =
|
|
1920
|
+
var preferNamedParamTypes = createRule23({
|
|
1719
1921
|
name: "prefer-named-param-types",
|
|
1720
1922
|
meta: {
|
|
1721
1923
|
type: "suggestion",
|
|
@@ -1730,16 +1932,16 @@ var preferNamedParamTypes = createRule21({
|
|
|
1730
1932
|
defaultOptions: [],
|
|
1731
1933
|
create(context) {
|
|
1732
1934
|
function hasInlineObjectType(param) {
|
|
1733
|
-
if (param.type ===
|
|
1935
|
+
if (param.type === AST_NODE_TYPES20.AssignmentPattern) {
|
|
1734
1936
|
return hasInlineObjectType(param.left);
|
|
1735
1937
|
}
|
|
1736
|
-
if (param.type ===
|
|
1737
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
1938
|
+
if (param.type === AST_NODE_TYPES20.ObjectPattern) {
|
|
1939
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES20.TSTypeLiteral) {
|
|
1738
1940
|
return true;
|
|
1739
1941
|
}
|
|
1740
1942
|
}
|
|
1741
|
-
if (param.type ===
|
|
1742
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
1943
|
+
if (param.type === AST_NODE_TYPES20.Identifier) {
|
|
1944
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES20.TSTypeLiteral) {
|
|
1743
1945
|
return true;
|
|
1744
1946
|
}
|
|
1745
1947
|
}
|
|
@@ -1773,11 +1975,11 @@ var preferNamedParamTypes = createRule21({
|
|
|
1773
1975
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
1774
1976
|
|
|
1775
1977
|
// src/rules/prefer-react-import-types.ts
|
|
1776
|
-
import { AST_NODE_TYPES as
|
|
1777
|
-
var
|
|
1978
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21, ESLintUtils as ESLintUtils24 } from "@typescript-eslint/utils";
|
|
1979
|
+
var createRule24 = ESLintUtils24.RuleCreator(
|
|
1778
1980
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1779
1981
|
);
|
|
1780
|
-
var preferReactImportTypes =
|
|
1982
|
+
var preferReactImportTypes = createRule24({
|
|
1781
1983
|
name: "prefer-react-import-types",
|
|
1782
1984
|
meta: {
|
|
1783
1985
|
type: "suggestion",
|
|
@@ -1853,7 +2055,7 @@ var preferReactImportTypes = createRule22({
|
|
|
1853
2055
|
]);
|
|
1854
2056
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
1855
2057
|
function checkMemberExpression(node) {
|
|
1856
|
-
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)) {
|
|
1857
2059
|
const typeName = node.property.name;
|
|
1858
2060
|
const isType = reactTypes.has(typeName);
|
|
1859
2061
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -1870,7 +2072,7 @@ var preferReactImportTypes = createRule22({
|
|
|
1870
2072
|
return {
|
|
1871
2073
|
MemberExpression: checkMemberExpression,
|
|
1872
2074
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
1873
|
-
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)) {
|
|
1874
2076
|
const typeName = node.right.name;
|
|
1875
2077
|
const isType = reactTypes.has(typeName);
|
|
1876
2078
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -1890,11 +2092,11 @@ var preferReactImportTypes = createRule22({
|
|
|
1890
2092
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
1891
2093
|
|
|
1892
2094
|
// src/rules/react-props-destructure.ts
|
|
1893
|
-
import { AST_NODE_TYPES as
|
|
1894
|
-
var
|
|
2095
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22, ESLintUtils as ESLintUtils25 } from "@typescript-eslint/utils";
|
|
2096
|
+
var createRule25 = ESLintUtils25.RuleCreator(
|
|
1895
2097
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1896
2098
|
);
|
|
1897
|
-
var reactPropsDestructure =
|
|
2099
|
+
var reactPropsDestructure = createRule25({
|
|
1898
2100
|
name: "react-props-destructure",
|
|
1899
2101
|
meta: {
|
|
1900
2102
|
type: "suggestion",
|
|
@@ -1910,29 +2112,29 @@ var reactPropsDestructure = createRule23({
|
|
|
1910
2112
|
defaultOptions: [],
|
|
1911
2113
|
create(context) {
|
|
1912
2114
|
function hasJSXInConditional(node) {
|
|
1913
|
-
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;
|
|
1914
2116
|
}
|
|
1915
2117
|
function hasJSXInLogical(node) {
|
|
1916
|
-
return node.right.type ===
|
|
2118
|
+
return node.right.type === AST_NODE_TYPES22.JSXElement || node.right.type === AST_NODE_TYPES22.JSXFragment;
|
|
1917
2119
|
}
|
|
1918
2120
|
function hasJSXReturn(block) {
|
|
1919
2121
|
return block.body.some((stmt) => {
|
|
1920
|
-
if (stmt.type ===
|
|
1921
|
-
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);
|
|
1922
2124
|
}
|
|
1923
2125
|
return false;
|
|
1924
2126
|
});
|
|
1925
2127
|
}
|
|
1926
2128
|
function isReactComponent2(node) {
|
|
1927
|
-
if (node.type ===
|
|
1928
|
-
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) {
|
|
1929
2131
|
return true;
|
|
1930
2132
|
}
|
|
1931
|
-
if (node.body.type ===
|
|
2133
|
+
if (node.body.type === AST_NODE_TYPES22.BlockStatement) {
|
|
1932
2134
|
return hasJSXReturn(node.body);
|
|
1933
2135
|
}
|
|
1934
|
-
} else if (node.type ===
|
|
1935
|
-
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) {
|
|
1936
2138
|
return hasJSXReturn(node.body);
|
|
1937
2139
|
}
|
|
1938
2140
|
}
|
|
@@ -1946,9 +2148,9 @@ var reactPropsDestructure = createRule23({
|
|
|
1946
2148
|
return;
|
|
1947
2149
|
}
|
|
1948
2150
|
const param = node.params[0];
|
|
1949
|
-
if (param.type ===
|
|
1950
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
1951
|
-
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) {
|
|
1952
2154
|
return prop.key.name;
|
|
1953
2155
|
}
|
|
1954
2156
|
return null;
|
|
@@ -1992,7 +2194,9 @@ var rules = {
|
|
|
1992
2194
|
"no-direct-date": no_direct_date_default,
|
|
1993
2195
|
"no-emoji": no_emoji_default,
|
|
1994
2196
|
"no-env-fallback": no_env_fallback_default,
|
|
2197
|
+
"no-inline-default-export": no_inline_default_export_default,
|
|
1995
2198
|
"require-explicit-return-type": require_explicit_return_type_default,
|
|
2199
|
+
"no-lazy-identifiers": no_lazy_identifiers_default,
|
|
1996
2200
|
"no-logic-in-params": no_logic_in_params_default,
|
|
1997
2201
|
"no-single-char-variables": no_single_char_variables_default,
|
|
1998
2202
|
"prefer-destructuring-params": prefer_destructuring_params_default,
|
|
@@ -2024,6 +2228,8 @@ var baseRules = {
|
|
|
2024
2228
|
"nextfriday/no-direct-date": "warn",
|
|
2025
2229
|
"nextfriday/no-logic-in-params": "warn",
|
|
2026
2230
|
"nextfriday/no-env-fallback": "warn",
|
|
2231
|
+
"nextfriday/no-inline-default-export": "warn",
|
|
2232
|
+
"nextfriday/no-lazy-identifiers": "warn",
|
|
2027
2233
|
"nextfriday/no-single-char-variables": "warn"
|
|
2028
2234
|
};
|
|
2029
2235
|
var baseRecommendedRules = {
|
|
@@ -2042,6 +2248,8 @@ var baseRecommendedRules = {
|
|
|
2042
2248
|
"nextfriday/no-direct-date": "error",
|
|
2043
2249
|
"nextfriday/no-logic-in-params": "error",
|
|
2044
2250
|
"nextfriday/no-env-fallback": "error",
|
|
2251
|
+
"nextfriday/no-inline-default-export": "error",
|
|
2252
|
+
"nextfriday/no-lazy-identifiers": "error",
|
|
2045
2253
|
"nextfriday/no-single-char-variables": "error"
|
|
2046
2254
|
};
|
|
2047
2255
|
var jsxRules = {
|