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.cjs
CHANGED
|
@@ -40,7 +40,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
40
40
|
// package.json
|
|
41
41
|
var package_default = {
|
|
42
42
|
name: "eslint-plugin-nextfriday",
|
|
43
|
-
version: "1.
|
|
43
|
+
version: "1.9.0",
|
|
44
44
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
45
45
|
keywords: [
|
|
46
46
|
"eslint",
|
|
@@ -892,58 +892,124 @@ var noEnvFallback = createRule11({
|
|
|
892
892
|
});
|
|
893
893
|
var no_env_fallback_default = noEnvFallback;
|
|
894
894
|
|
|
895
|
-
// src/rules/
|
|
895
|
+
// src/rules/no-inline-default-export.ts
|
|
896
896
|
var import_utils12 = require("@typescript-eslint/utils");
|
|
897
897
|
var createRule12 = import_utils12.ESLintUtils.RuleCreator(
|
|
898
898
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
899
899
|
);
|
|
900
|
+
var noInlineDefaultExport = createRule12({
|
|
901
|
+
name: "no-inline-default-export",
|
|
902
|
+
meta: {
|
|
903
|
+
type: "suggestion",
|
|
904
|
+
docs: {
|
|
905
|
+
description: "Disallow inline default exports. Prefer declaring first, then exporting separately."
|
|
906
|
+
},
|
|
907
|
+
messages: {
|
|
908
|
+
noInlineDefaultExport: "Avoid inline default export. Declare the {{type}} first, then export it separately: `export default {{name}};`",
|
|
909
|
+
noAnonymousDefaultExport: "Avoid anonymous default export. Declare a named {{type}} first, then export it separately."
|
|
910
|
+
},
|
|
911
|
+
schema: []
|
|
912
|
+
},
|
|
913
|
+
defaultOptions: [],
|
|
914
|
+
create(context) {
|
|
915
|
+
return {
|
|
916
|
+
ExportDefaultDeclaration(node) {
|
|
917
|
+
const { declaration } = node;
|
|
918
|
+
if (declaration.type === import_utils12.AST_NODE_TYPES.FunctionDeclaration) {
|
|
919
|
+
if (declaration.id) {
|
|
920
|
+
context.report({
|
|
921
|
+
node,
|
|
922
|
+
messageId: "noInlineDefaultExport",
|
|
923
|
+
data: { type: "function", name: declaration.id.name }
|
|
924
|
+
});
|
|
925
|
+
} else {
|
|
926
|
+
context.report({
|
|
927
|
+
node,
|
|
928
|
+
messageId: "noAnonymousDefaultExport",
|
|
929
|
+
data: { type: "function" }
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
if (declaration.type === import_utils12.AST_NODE_TYPES.ClassDeclaration) {
|
|
934
|
+
if (declaration.id) {
|
|
935
|
+
context.report({
|
|
936
|
+
node,
|
|
937
|
+
messageId: "noInlineDefaultExport",
|
|
938
|
+
data: { type: "class", name: declaration.id.name }
|
|
939
|
+
});
|
|
940
|
+
} else {
|
|
941
|
+
context.report({
|
|
942
|
+
node,
|
|
943
|
+
messageId: "noAnonymousDefaultExport",
|
|
944
|
+
data: { type: "class" }
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
if (declaration.type === import_utils12.AST_NODE_TYPES.ArrowFunctionExpression || declaration.type === import_utils12.AST_NODE_TYPES.FunctionExpression) {
|
|
949
|
+
context.report({
|
|
950
|
+
node,
|
|
951
|
+
messageId: "noAnonymousDefaultExport",
|
|
952
|
+
data: { type: "function" }
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
var no_inline_default_export_default = noInlineDefaultExport;
|
|
960
|
+
|
|
961
|
+
// src/rules/require-explicit-return-type.ts
|
|
962
|
+
var import_utils13 = require("@typescript-eslint/utils");
|
|
963
|
+
var createRule13 = import_utils13.ESLintUtils.RuleCreator(
|
|
964
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
965
|
+
);
|
|
900
966
|
var isReactComponent = (node) => {
|
|
901
|
-
if (node.type ===
|
|
967
|
+
if (node.type === import_utils13.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
902
968
|
const { parent } = node;
|
|
903
|
-
if (parent?.type ===
|
|
969
|
+
if (parent?.type === import_utils13.AST_NODE_TYPES.VariableDeclarator) {
|
|
904
970
|
const { id } = parent;
|
|
905
|
-
if (id.type ===
|
|
971
|
+
if (id.type === import_utils13.AST_NODE_TYPES.Identifier) {
|
|
906
972
|
return /^[A-Z]/.test(id.name);
|
|
907
973
|
}
|
|
908
974
|
}
|
|
909
975
|
}
|
|
910
|
-
if (node.type ===
|
|
976
|
+
if (node.type === import_utils13.AST_NODE_TYPES.FunctionDeclaration && node.id) {
|
|
911
977
|
return /^[A-Z]/.test(node.id.name);
|
|
912
978
|
}
|
|
913
979
|
return false;
|
|
914
980
|
};
|
|
915
981
|
var isCallbackFunction = (node) => {
|
|
916
|
-
if (node.type ===
|
|
982
|
+
if (node.type === import_utils13.AST_NODE_TYPES.FunctionDeclaration) {
|
|
917
983
|
return false;
|
|
918
984
|
}
|
|
919
985
|
const { parent } = node;
|
|
920
986
|
if (!parent) {
|
|
921
987
|
return false;
|
|
922
988
|
}
|
|
923
|
-
if (parent.type ===
|
|
989
|
+
if (parent.type === import_utils13.AST_NODE_TYPES.CallExpression && parent.arguments.includes(node)) {
|
|
924
990
|
return true;
|
|
925
991
|
}
|
|
926
|
-
if (parent.type ===
|
|
992
|
+
if (parent.type === import_utils13.AST_NODE_TYPES.Property) {
|
|
927
993
|
return true;
|
|
928
994
|
}
|
|
929
|
-
if (parent.type ===
|
|
995
|
+
if (parent.type === import_utils13.AST_NODE_TYPES.ArrayExpression) {
|
|
930
996
|
return true;
|
|
931
997
|
}
|
|
932
998
|
return false;
|
|
933
999
|
};
|
|
934
1000
|
var getFunctionName = (node) => {
|
|
935
|
-
if (node.type ===
|
|
1001
|
+
if (node.type === import_utils13.AST_NODE_TYPES.FunctionDeclaration && node.id) {
|
|
936
1002
|
return node.id.name;
|
|
937
1003
|
}
|
|
938
|
-
if (node.type ===
|
|
1004
|
+
if (node.type === import_utils13.AST_NODE_TYPES.FunctionExpression && node.id) {
|
|
939
1005
|
return node.id.name;
|
|
940
1006
|
}
|
|
941
|
-
if ((node.type ===
|
|
1007
|
+
if ((node.type === import_utils13.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils13.AST_NODE_TYPES.FunctionExpression) && node.parent?.type === import_utils13.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils13.AST_NODE_TYPES.Identifier) {
|
|
942
1008
|
return node.parent.id.name;
|
|
943
1009
|
}
|
|
944
1010
|
return null;
|
|
945
1011
|
};
|
|
946
|
-
var requireExplicitReturnType =
|
|
1012
|
+
var requireExplicitReturnType = createRule13({
|
|
947
1013
|
name: "require-explicit-return-type",
|
|
948
1014
|
meta: {
|
|
949
1015
|
type: "suggestion",
|
|
@@ -992,18 +1058,18 @@ var requireExplicitReturnType = createRule12({
|
|
|
992
1058
|
var require_explicit_return_type_default = requireExplicitReturnType;
|
|
993
1059
|
|
|
994
1060
|
// src/rules/jsx-no-non-component-function.ts
|
|
995
|
-
var
|
|
1061
|
+
var import_utils15 = require("@typescript-eslint/utils");
|
|
996
1062
|
|
|
997
1063
|
// src/utils.ts
|
|
998
1064
|
var import_node_path = require("path");
|
|
999
|
-
var
|
|
1065
|
+
var import_utils14 = require("@typescript-eslint/utils");
|
|
1000
1066
|
var getFileExtension = (filename) => (0, import_node_path.extname)(filename).slice(1);
|
|
1001
1067
|
|
|
1002
1068
|
// src/rules/jsx-no-non-component-function.ts
|
|
1003
|
-
var
|
|
1069
|
+
var createRule14 = import_utils15.ESLintUtils.RuleCreator(
|
|
1004
1070
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1005
1071
|
);
|
|
1006
|
-
var jsxNoNonComponentFunction =
|
|
1072
|
+
var jsxNoNonComponentFunction = createRule14({
|
|
1007
1073
|
name: "jsx-no-non-component-function",
|
|
1008
1074
|
meta: {
|
|
1009
1075
|
type: "problem",
|
|
@@ -1023,13 +1089,13 @@ var jsxNoNonComponentFunction = createRule13({
|
|
|
1023
1089
|
return {};
|
|
1024
1090
|
}
|
|
1025
1091
|
function isReactComponent2(node) {
|
|
1026
|
-
const functionName = node.type ===
|
|
1092
|
+
const functionName = node.type === import_utils15.AST_NODE_TYPES.FunctionDeclaration && node.id ? node.id.name : null;
|
|
1027
1093
|
if (functionName && /^[A-Z]/.test(functionName)) {
|
|
1028
1094
|
return true;
|
|
1029
1095
|
}
|
|
1030
1096
|
if (node.returnType?.typeAnnotation) {
|
|
1031
1097
|
const returnTypeNode = node.returnType.typeAnnotation;
|
|
1032
|
-
if (returnTypeNode.type ===
|
|
1098
|
+
if (returnTypeNode.type === import_utils15.AST_NODE_TYPES.TSTypeReference && returnTypeNode.typeName.type === import_utils15.AST_NODE_TYPES.Identifier) {
|
|
1033
1099
|
const typeName = returnTypeNode.typeName.name;
|
|
1034
1100
|
if (typeName === "JSX" || typeName === "ReactElement" || typeName === "ReactNode") {
|
|
1035
1101
|
return true;
|
|
@@ -1046,13 +1112,13 @@ var jsxNoNonComponentFunction = createRule13({
|
|
|
1046
1112
|
if (!parent) {
|
|
1047
1113
|
return;
|
|
1048
1114
|
}
|
|
1049
|
-
if (parent.type ===
|
|
1115
|
+
if (parent.type === import_utils15.AST_NODE_TYPES.ExportDefaultDeclaration || parent.type === import_utils15.AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
1050
1116
|
return;
|
|
1051
1117
|
}
|
|
1052
|
-
if (declaratorNode?.parent?.parent?.type ===
|
|
1118
|
+
if (declaratorNode?.parent?.parent?.type === import_utils15.AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
1053
1119
|
return;
|
|
1054
1120
|
}
|
|
1055
|
-
if (declaratorNode?.id.type ===
|
|
1121
|
+
if (declaratorNode?.id.type === import_utils15.AST_NODE_TYPES.Identifier) {
|
|
1056
1122
|
const varName = declaratorNode.id.name;
|
|
1057
1123
|
if (/^[A-Z]/.test(varName)) {
|
|
1058
1124
|
return;
|
|
@@ -1077,11 +1143,11 @@ var jsxNoNonComponentFunction = createRule13({
|
|
|
1077
1143
|
var jsx_no_non_component_function_default = jsxNoNonComponentFunction;
|
|
1078
1144
|
|
|
1079
1145
|
// src/rules/no-logic-in-params.ts
|
|
1080
|
-
var
|
|
1081
|
-
var
|
|
1146
|
+
var import_utils17 = require("@typescript-eslint/utils");
|
|
1147
|
+
var createRule15 = import_utils17.ESLintUtils.RuleCreator(
|
|
1082
1148
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1083
1149
|
);
|
|
1084
|
-
var noLogicInParams =
|
|
1150
|
+
var noLogicInParams = createRule15({
|
|
1085
1151
|
name: "no-logic-in-params",
|
|
1086
1152
|
meta: {
|
|
1087
1153
|
type: "suggestion",
|
|
@@ -1096,20 +1162,20 @@ var noLogicInParams = createRule14({
|
|
|
1096
1162
|
defaultOptions: [],
|
|
1097
1163
|
create(context) {
|
|
1098
1164
|
const isComplexExpression = (node) => {
|
|
1099
|
-
if (node.type ===
|
|
1165
|
+
if (node.type === import_utils17.AST_NODE_TYPES.SpreadElement) {
|
|
1100
1166
|
return false;
|
|
1101
1167
|
}
|
|
1102
|
-
if (node.type ===
|
|
1168
|
+
if (node.type === import_utils17.AST_NODE_TYPES.ConditionalExpression) {
|
|
1103
1169
|
return true;
|
|
1104
1170
|
}
|
|
1105
|
-
if (node.type ===
|
|
1171
|
+
if (node.type === import_utils17.AST_NODE_TYPES.LogicalExpression) {
|
|
1106
1172
|
return true;
|
|
1107
1173
|
}
|
|
1108
|
-
if (node.type ===
|
|
1174
|
+
if (node.type === import_utils17.AST_NODE_TYPES.BinaryExpression) {
|
|
1109
1175
|
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
1110
1176
|
return logicalOperators.includes(node.operator);
|
|
1111
1177
|
}
|
|
1112
|
-
if (node.type ===
|
|
1178
|
+
if (node.type === import_utils17.AST_NODE_TYPES.UnaryExpression) {
|
|
1113
1179
|
return node.operator === "!";
|
|
1114
1180
|
}
|
|
1115
1181
|
return false;
|
|
@@ -1140,9 +1206,145 @@ var noLogicInParams = createRule14({
|
|
|
1140
1206
|
});
|
|
1141
1207
|
var no_logic_in_params_default = noLogicInParams;
|
|
1142
1208
|
|
|
1209
|
+
// src/rules/no-lazy-identifiers.ts
|
|
1210
|
+
var import_utils18 = require("@typescript-eslint/utils");
|
|
1211
|
+
var createRule16 = import_utils18.ESLintUtils.RuleCreator(
|
|
1212
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1213
|
+
);
|
|
1214
|
+
var KEYBOARD_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm", "1234567890"];
|
|
1215
|
+
var MIN_LENGTH = 3;
|
|
1216
|
+
var MIN_SEQUENCE_LENGTH = 4;
|
|
1217
|
+
var hasRepeatedChars = (name) => {
|
|
1218
|
+
const lowerName = name.toLowerCase();
|
|
1219
|
+
return lowerName.split("").some((char, index) => {
|
|
1220
|
+
if (index > lowerName.length - 3) {
|
|
1221
|
+
return false;
|
|
1222
|
+
}
|
|
1223
|
+
return char === lowerName[index + 1] && char === lowerName[index + 2];
|
|
1224
|
+
});
|
|
1225
|
+
};
|
|
1226
|
+
var hasKeyboardSequence = (name) => {
|
|
1227
|
+
const lowerName = name.toLowerCase();
|
|
1228
|
+
if (lowerName.length < MIN_SEQUENCE_LENGTH) {
|
|
1229
|
+
return false;
|
|
1230
|
+
}
|
|
1231
|
+
return KEYBOARD_ROWS.some((row) => {
|
|
1232
|
+
const positions = Array.from({ length: row.length - MIN_SEQUENCE_LENGTH + 1 }, (_, i) => i);
|
|
1233
|
+
return positions.some((start) => {
|
|
1234
|
+
const sequence = row.slice(start, start + MIN_SEQUENCE_LENGTH);
|
|
1235
|
+
const reverseSequence = sequence.split("").reverse().join("");
|
|
1236
|
+
return lowerName.includes(sequence) || lowerName.includes(reverseSequence);
|
|
1237
|
+
});
|
|
1238
|
+
});
|
|
1239
|
+
};
|
|
1240
|
+
var isLazyIdentifier = (name) => {
|
|
1241
|
+
if (name.length < MIN_LENGTH) {
|
|
1242
|
+
return false;
|
|
1243
|
+
}
|
|
1244
|
+
if (name.startsWith("_")) {
|
|
1245
|
+
return false;
|
|
1246
|
+
}
|
|
1247
|
+
if (hasRepeatedChars(name)) {
|
|
1248
|
+
return true;
|
|
1249
|
+
}
|
|
1250
|
+
if (hasKeyboardSequence(name)) {
|
|
1251
|
+
return true;
|
|
1252
|
+
}
|
|
1253
|
+
return false;
|
|
1254
|
+
};
|
|
1255
|
+
var noLazyIdentifiers = createRule16({
|
|
1256
|
+
name: "no-lazy-identifiers",
|
|
1257
|
+
meta: {
|
|
1258
|
+
type: "problem",
|
|
1259
|
+
docs: {
|
|
1260
|
+
description: "Disallow lazy, meaningless variable names that hurt code readability"
|
|
1261
|
+
},
|
|
1262
|
+
messages: {
|
|
1263
|
+
noLazyIdentifier: "Avoid lazy identifier '{{name}}'. Use a descriptive name that clearly indicates the purpose."
|
|
1264
|
+
},
|
|
1265
|
+
schema: []
|
|
1266
|
+
},
|
|
1267
|
+
defaultOptions: [],
|
|
1268
|
+
create(context) {
|
|
1269
|
+
const checkIdentifier = (node) => {
|
|
1270
|
+
const { name } = node;
|
|
1271
|
+
if (!isLazyIdentifier(name)) {
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
context.report({
|
|
1275
|
+
node,
|
|
1276
|
+
messageId: "noLazyIdentifier",
|
|
1277
|
+
data: { name }
|
|
1278
|
+
});
|
|
1279
|
+
};
|
|
1280
|
+
const checkPattern = (pattern) => {
|
|
1281
|
+
if (pattern.type === import_utils18.AST_NODE_TYPES.Identifier) {
|
|
1282
|
+
checkIdentifier(pattern);
|
|
1283
|
+
} else if (pattern.type === import_utils18.AST_NODE_TYPES.ObjectPattern) {
|
|
1284
|
+
pattern.properties.forEach((prop) => {
|
|
1285
|
+
if (prop.type === import_utils18.AST_NODE_TYPES.Property && prop.value.type === import_utils18.AST_NODE_TYPES.Identifier) {
|
|
1286
|
+
checkIdentifier(prop.value);
|
|
1287
|
+
} else if (prop.type === import_utils18.AST_NODE_TYPES.RestElement && prop.argument.type === import_utils18.AST_NODE_TYPES.Identifier) {
|
|
1288
|
+
checkIdentifier(prop.argument);
|
|
1289
|
+
}
|
|
1290
|
+
});
|
|
1291
|
+
} else if (pattern.type === import_utils18.AST_NODE_TYPES.ArrayPattern) {
|
|
1292
|
+
pattern.elements.forEach((element) => {
|
|
1293
|
+
if (element?.type === import_utils18.AST_NODE_TYPES.Identifier) {
|
|
1294
|
+
checkIdentifier(element);
|
|
1295
|
+
} else if (element?.type === import_utils18.AST_NODE_TYPES.RestElement && element.argument.type === import_utils18.AST_NODE_TYPES.Identifier) {
|
|
1296
|
+
checkIdentifier(element.argument);
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
} else if (pattern.type === import_utils18.AST_NODE_TYPES.AssignmentPattern && pattern.left.type === import_utils18.AST_NODE_TYPES.Identifier) {
|
|
1300
|
+
checkIdentifier(pattern.left);
|
|
1301
|
+
} else if (pattern.type === import_utils18.AST_NODE_TYPES.RestElement && pattern.argument.type === import_utils18.AST_NODE_TYPES.Identifier) {
|
|
1302
|
+
checkIdentifier(pattern.argument);
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
return {
|
|
1306
|
+
VariableDeclarator(node) {
|
|
1307
|
+
checkPattern(node.id);
|
|
1308
|
+
},
|
|
1309
|
+
FunctionDeclaration(node) {
|
|
1310
|
+
if (node.id) {
|
|
1311
|
+
checkIdentifier(node.id);
|
|
1312
|
+
}
|
|
1313
|
+
node.params.forEach((param) => checkPattern(param));
|
|
1314
|
+
},
|
|
1315
|
+
FunctionExpression(node) {
|
|
1316
|
+
if (node.id) {
|
|
1317
|
+
checkIdentifier(node.id);
|
|
1318
|
+
}
|
|
1319
|
+
node.params.forEach((param) => checkPattern(param));
|
|
1320
|
+
},
|
|
1321
|
+
ArrowFunctionExpression(node) {
|
|
1322
|
+
node.params.forEach((param) => checkPattern(param));
|
|
1323
|
+
},
|
|
1324
|
+
CatchClause(node) {
|
|
1325
|
+
if (node.param) {
|
|
1326
|
+
checkPattern(node.param);
|
|
1327
|
+
}
|
|
1328
|
+
},
|
|
1329
|
+
ClassDeclaration(node) {
|
|
1330
|
+
if (node.id) {
|
|
1331
|
+
checkIdentifier(node.id);
|
|
1332
|
+
}
|
|
1333
|
+
},
|
|
1334
|
+
TSTypeAliasDeclaration(node) {
|
|
1335
|
+
checkIdentifier(node.id);
|
|
1336
|
+
},
|
|
1337
|
+
TSInterfaceDeclaration(node) {
|
|
1338
|
+
checkIdentifier(node.id);
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
});
|
|
1343
|
+
var no_lazy_identifiers_default = noLazyIdentifiers;
|
|
1344
|
+
|
|
1143
1345
|
// src/rules/no-single-char-variables.ts
|
|
1144
|
-
var
|
|
1145
|
-
var
|
|
1346
|
+
var import_utils19 = require("@typescript-eslint/utils");
|
|
1347
|
+
var createRule17 = import_utils19.ESLintUtils.RuleCreator(
|
|
1146
1348
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1147
1349
|
);
|
|
1148
1350
|
var ALLOWED_IN_FOR_LOOPS = /* @__PURE__ */ new Set(["i", "j", "k", "n"]);
|
|
@@ -1154,7 +1356,7 @@ var isForLoopInit = (node) => {
|
|
|
1154
1356
|
if (!parentNode) {
|
|
1155
1357
|
return false;
|
|
1156
1358
|
}
|
|
1157
|
-
if (parentNode.type ===
|
|
1359
|
+
if (parentNode.type === import_utils19.AST_NODE_TYPES.ForStatement) {
|
|
1158
1360
|
const { init } = parentNode;
|
|
1159
1361
|
if (init && init === current) {
|
|
1160
1362
|
return true;
|
|
@@ -1173,7 +1375,7 @@ var isAllowedInContext = (name, node) => {
|
|
|
1173
1375
|
}
|
|
1174
1376
|
return false;
|
|
1175
1377
|
};
|
|
1176
|
-
var noSingleCharVariables =
|
|
1378
|
+
var noSingleCharVariables = createRule17({
|
|
1177
1379
|
name: "no-single-char-variables",
|
|
1178
1380
|
meta: {
|
|
1179
1381
|
type: "suggestion",
|
|
@@ -1202,27 +1404,27 @@ var noSingleCharVariables = createRule15({
|
|
|
1202
1404
|
});
|
|
1203
1405
|
};
|
|
1204
1406
|
const checkPattern = (pattern, declarationNode) => {
|
|
1205
|
-
if (pattern.type ===
|
|
1407
|
+
if (pattern.type === import_utils19.AST_NODE_TYPES.Identifier) {
|
|
1206
1408
|
checkIdentifier(pattern, declarationNode);
|
|
1207
|
-
} else if (pattern.type ===
|
|
1409
|
+
} else if (pattern.type === import_utils19.AST_NODE_TYPES.ObjectPattern) {
|
|
1208
1410
|
pattern.properties.forEach((prop) => {
|
|
1209
|
-
if (prop.type ===
|
|
1411
|
+
if (prop.type === import_utils19.AST_NODE_TYPES.Property && prop.value.type === import_utils19.AST_NODE_TYPES.Identifier) {
|
|
1210
1412
|
checkIdentifier(prop.value, declarationNode);
|
|
1211
|
-
} else if (prop.type ===
|
|
1413
|
+
} else if (prop.type === import_utils19.AST_NODE_TYPES.RestElement && prop.argument.type === import_utils19.AST_NODE_TYPES.Identifier) {
|
|
1212
1414
|
checkIdentifier(prop.argument, declarationNode);
|
|
1213
1415
|
}
|
|
1214
1416
|
});
|
|
1215
|
-
} else if (pattern.type ===
|
|
1417
|
+
} else if (pattern.type === import_utils19.AST_NODE_TYPES.ArrayPattern) {
|
|
1216
1418
|
pattern.elements.forEach((element) => {
|
|
1217
|
-
if (element?.type ===
|
|
1419
|
+
if (element?.type === import_utils19.AST_NODE_TYPES.Identifier) {
|
|
1218
1420
|
checkIdentifier(element, declarationNode);
|
|
1219
|
-
} else if (element?.type ===
|
|
1421
|
+
} else if (element?.type === import_utils19.AST_NODE_TYPES.RestElement && element.argument.type === import_utils19.AST_NODE_TYPES.Identifier) {
|
|
1220
1422
|
checkIdentifier(element.argument, declarationNode);
|
|
1221
1423
|
}
|
|
1222
1424
|
});
|
|
1223
|
-
} else if (pattern.type ===
|
|
1425
|
+
} else if (pattern.type === import_utils19.AST_NODE_TYPES.AssignmentPattern && pattern.left.type === import_utils19.AST_NODE_TYPES.Identifier) {
|
|
1224
1426
|
checkIdentifier(pattern.left, declarationNode);
|
|
1225
|
-
} else if (pattern.type ===
|
|
1427
|
+
} else if (pattern.type === import_utils19.AST_NODE_TYPES.RestElement && pattern.argument.type === import_utils19.AST_NODE_TYPES.Identifier) {
|
|
1226
1428
|
checkIdentifier(pattern.argument, declarationNode);
|
|
1227
1429
|
}
|
|
1228
1430
|
};
|
|
@@ -1256,11 +1458,11 @@ var noSingleCharVariables = createRule15({
|
|
|
1256
1458
|
var no_single_char_variables_default = noSingleCharVariables;
|
|
1257
1459
|
|
|
1258
1460
|
// src/rules/prefer-destructuring-params.ts
|
|
1259
|
-
var
|
|
1260
|
-
var
|
|
1461
|
+
var import_utils20 = require("@typescript-eslint/utils");
|
|
1462
|
+
var createRule18 = import_utils20.ESLintUtils.RuleCreator(
|
|
1261
1463
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1262
1464
|
);
|
|
1263
|
-
var preferDestructuringParams =
|
|
1465
|
+
var preferDestructuringParams = createRule18({
|
|
1264
1466
|
name: "prefer-destructuring-params",
|
|
1265
1467
|
meta: {
|
|
1266
1468
|
type: "suggestion",
|
|
@@ -1276,18 +1478,18 @@ var preferDestructuringParams = createRule16({
|
|
|
1276
1478
|
create(context) {
|
|
1277
1479
|
const isCallbackFunction2 = (node) => {
|
|
1278
1480
|
const { parent } = node;
|
|
1279
|
-
return parent?.type ===
|
|
1481
|
+
return parent?.type === import_utils20.AST_NODE_TYPES.CallExpression;
|
|
1280
1482
|
};
|
|
1281
1483
|
const isDeveloperFunction = (node) => {
|
|
1282
|
-
if (node.type ===
|
|
1484
|
+
if (node.type === import_utils20.AST_NODE_TYPES.FunctionDeclaration) {
|
|
1283
1485
|
return true;
|
|
1284
1486
|
}
|
|
1285
|
-
if (node.type ===
|
|
1487
|
+
if (node.type === import_utils20.AST_NODE_TYPES.FunctionExpression || node.type === import_utils20.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
1286
1488
|
if (isCallbackFunction2(node)) {
|
|
1287
1489
|
return false;
|
|
1288
1490
|
}
|
|
1289
1491
|
const { parent } = node;
|
|
1290
|
-
return parent?.type ===
|
|
1492
|
+
return parent?.type === import_utils20.AST_NODE_TYPES.VariableDeclarator || parent?.type === import_utils20.AST_NODE_TYPES.AssignmentExpression || parent?.type === import_utils20.AST_NODE_TYPES.Property || parent?.type === import_utils20.AST_NODE_TYPES.MethodDefinition;
|
|
1291
1493
|
}
|
|
1292
1494
|
return false;
|
|
1293
1495
|
};
|
|
@@ -1299,7 +1501,7 @@ var preferDestructuringParams = createRule16({
|
|
|
1299
1501
|
if (!isDeveloperFunction(node)) {
|
|
1300
1502
|
return;
|
|
1301
1503
|
}
|
|
1302
|
-
if (node.type ===
|
|
1504
|
+
if (node.type === import_utils20.AST_NODE_TYPES.FunctionDeclaration && node.id) {
|
|
1303
1505
|
const functionName = node.id.name;
|
|
1304
1506
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
1305
1507
|
return;
|
|
@@ -1309,7 +1511,7 @@ var preferDestructuringParams = createRule16({
|
|
|
1309
1511
|
return;
|
|
1310
1512
|
}
|
|
1311
1513
|
const hasNonDestructuredParams = node.params.some(
|
|
1312
|
-
(param) => param.type !==
|
|
1514
|
+
(param) => param.type !== import_utils20.AST_NODE_TYPES.ObjectPattern && param.type !== import_utils20.AST_NODE_TYPES.RestElement
|
|
1313
1515
|
);
|
|
1314
1516
|
if (hasNonDestructuredParams) {
|
|
1315
1517
|
context.report({
|
|
@@ -1328,8 +1530,8 @@ var preferDestructuringParams = createRule16({
|
|
|
1328
1530
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
1329
1531
|
|
|
1330
1532
|
// src/rules/prefer-function-declaration.ts
|
|
1331
|
-
var
|
|
1332
|
-
var
|
|
1533
|
+
var import_utils21 = require("@typescript-eslint/utils");
|
|
1534
|
+
var createRule19 = import_utils21.ESLintUtils.RuleCreator(
|
|
1333
1535
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1334
1536
|
);
|
|
1335
1537
|
var isTsFile = (filename) => filename.endsWith(".ts") && !filename.endsWith(".d.ts");
|
|
@@ -1338,33 +1540,33 @@ var isCallbackContext = (node) => {
|
|
|
1338
1540
|
if (!parent) {
|
|
1339
1541
|
return false;
|
|
1340
1542
|
}
|
|
1341
|
-
if (parent.type ===
|
|
1543
|
+
if (parent.type === import_utils21.AST_NODE_TYPES.CallExpression && parent.arguments.includes(node)) {
|
|
1342
1544
|
return true;
|
|
1343
1545
|
}
|
|
1344
|
-
if (parent.type ===
|
|
1546
|
+
if (parent.type === import_utils21.AST_NODE_TYPES.NewExpression && parent.arguments.includes(node)) {
|
|
1345
1547
|
return true;
|
|
1346
1548
|
}
|
|
1347
|
-
if (parent.type ===
|
|
1549
|
+
if (parent.type === import_utils21.AST_NODE_TYPES.ReturnStatement) {
|
|
1348
1550
|
return true;
|
|
1349
1551
|
}
|
|
1350
|
-
if (parent.type ===
|
|
1552
|
+
if (parent.type === import_utils21.AST_NODE_TYPES.Property) {
|
|
1351
1553
|
return true;
|
|
1352
1554
|
}
|
|
1353
|
-
if (parent.type ===
|
|
1555
|
+
if (parent.type === import_utils21.AST_NODE_TYPES.ArrayExpression) {
|
|
1354
1556
|
return true;
|
|
1355
1557
|
}
|
|
1356
|
-
if (parent.type ===
|
|
1558
|
+
if (parent.type === import_utils21.AST_NODE_TYPES.ConditionalExpression) {
|
|
1357
1559
|
return true;
|
|
1358
1560
|
}
|
|
1359
|
-
if (parent.type ===
|
|
1561
|
+
if (parent.type === import_utils21.AST_NODE_TYPES.LogicalExpression) {
|
|
1360
1562
|
return true;
|
|
1361
1563
|
}
|
|
1362
|
-
if (parent.type ===
|
|
1564
|
+
if (parent.type === import_utils21.AST_NODE_TYPES.AssignmentExpression && parent.left !== node) {
|
|
1363
1565
|
return true;
|
|
1364
1566
|
}
|
|
1365
1567
|
return false;
|
|
1366
1568
|
};
|
|
1367
|
-
var preferFunctionDeclaration =
|
|
1569
|
+
var preferFunctionDeclaration = createRule19({
|
|
1368
1570
|
name: "prefer-function-declaration",
|
|
1369
1571
|
meta: {
|
|
1370
1572
|
type: "suggestion",
|
|
@@ -1385,14 +1587,14 @@ var preferFunctionDeclaration = createRule17({
|
|
|
1385
1587
|
}
|
|
1386
1588
|
return {
|
|
1387
1589
|
VariableDeclarator(node) {
|
|
1388
|
-
if (node.id.type !==
|
|
1590
|
+
if (node.id.type !== import_utils21.AST_NODE_TYPES.Identifier) {
|
|
1389
1591
|
return;
|
|
1390
1592
|
}
|
|
1391
1593
|
const { init } = node;
|
|
1392
1594
|
if (!init) {
|
|
1393
1595
|
return;
|
|
1394
1596
|
}
|
|
1395
|
-
if (init.type ===
|
|
1597
|
+
if (init.type === import_utils21.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
1396
1598
|
if (isCallbackContext(init)) {
|
|
1397
1599
|
return;
|
|
1398
1600
|
}
|
|
@@ -1402,7 +1604,7 @@ var preferFunctionDeclaration = createRule17({
|
|
|
1402
1604
|
data: { name: node.id.name }
|
|
1403
1605
|
});
|
|
1404
1606
|
}
|
|
1405
|
-
if (init.type ===
|
|
1607
|
+
if (init.type === import_utils21.AST_NODE_TYPES.FunctionExpression) {
|
|
1406
1608
|
if (isCallbackContext(init)) {
|
|
1407
1609
|
return;
|
|
1408
1610
|
}
|
|
@@ -1419,11 +1621,11 @@ var preferFunctionDeclaration = createRule17({
|
|
|
1419
1621
|
var prefer_function_declaration_default = preferFunctionDeclaration;
|
|
1420
1622
|
|
|
1421
1623
|
// src/rules/prefer-import-type.ts
|
|
1422
|
-
var
|
|
1423
|
-
var
|
|
1624
|
+
var import_utils22 = require("@typescript-eslint/utils");
|
|
1625
|
+
var createRule20 = import_utils22.ESLintUtils.RuleCreator(
|
|
1424
1626
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1425
1627
|
);
|
|
1426
|
-
var preferImportType =
|
|
1628
|
+
var preferImportType = createRule20({
|
|
1427
1629
|
name: "prefer-import-type",
|
|
1428
1630
|
meta: {
|
|
1429
1631
|
type: "suggestion",
|
|
@@ -1442,22 +1644,22 @@ var preferImportType = createRule18({
|
|
|
1442
1644
|
let current = node;
|
|
1443
1645
|
while (current) {
|
|
1444
1646
|
switch (current.type) {
|
|
1445
|
-
case
|
|
1446
|
-
case
|
|
1447
|
-
case
|
|
1448
|
-
case
|
|
1449
|
-
case
|
|
1450
|
-
case
|
|
1451
|
-
case
|
|
1452
|
-
case
|
|
1453
|
-
case
|
|
1454
|
-
case
|
|
1455
|
-
case
|
|
1456
|
-
case
|
|
1457
|
-
case
|
|
1647
|
+
case import_utils22.AST_NODE_TYPES.TSTypeReference:
|
|
1648
|
+
case import_utils22.AST_NODE_TYPES.TSTypeAnnotation:
|
|
1649
|
+
case import_utils22.AST_NODE_TYPES.TSTypeParameterInstantiation:
|
|
1650
|
+
case import_utils22.AST_NODE_TYPES.TSInterfaceHeritage:
|
|
1651
|
+
case import_utils22.AST_NODE_TYPES.TSClassImplements:
|
|
1652
|
+
case import_utils22.AST_NODE_TYPES.TSTypeQuery:
|
|
1653
|
+
case import_utils22.AST_NODE_TYPES.TSTypeAssertion:
|
|
1654
|
+
case import_utils22.AST_NODE_TYPES.TSAsExpression:
|
|
1655
|
+
case import_utils22.AST_NODE_TYPES.TSSatisfiesExpression:
|
|
1656
|
+
case import_utils22.AST_NODE_TYPES.TSTypeAliasDeclaration:
|
|
1657
|
+
case import_utils22.AST_NODE_TYPES.TSInterfaceDeclaration:
|
|
1658
|
+
case import_utils22.AST_NODE_TYPES.TSTypeParameter:
|
|
1659
|
+
case import_utils22.AST_NODE_TYPES.TSQualifiedName:
|
|
1458
1660
|
return true;
|
|
1459
|
-
case
|
|
1460
|
-
case
|
|
1661
|
+
case import_utils22.AST_NODE_TYPES.MemberExpression:
|
|
1662
|
+
case import_utils22.AST_NODE_TYPES.Identifier:
|
|
1461
1663
|
current = current.parent;
|
|
1462
1664
|
break;
|
|
1463
1665
|
default:
|
|
@@ -1487,26 +1689,26 @@ var preferImportType = createRule18({
|
|
|
1487
1689
|
return false;
|
|
1488
1690
|
}
|
|
1489
1691
|
switch (parent.type) {
|
|
1490
|
-
case
|
|
1491
|
-
case
|
|
1492
|
-
case
|
|
1493
|
-
case
|
|
1494
|
-
case
|
|
1495
|
-
case
|
|
1496
|
-
case
|
|
1497
|
-
case
|
|
1498
|
-
case
|
|
1499
|
-
case
|
|
1500
|
-
case
|
|
1501
|
-
case
|
|
1502
|
-
case
|
|
1503
|
-
case
|
|
1504
|
-
case
|
|
1505
|
-
case
|
|
1506
|
-
case
|
|
1507
|
-
case
|
|
1508
|
-
case
|
|
1509
|
-
case
|
|
1692
|
+
case import_utils22.AST_NODE_TYPES.CallExpression:
|
|
1693
|
+
case import_utils22.AST_NODE_TYPES.NewExpression:
|
|
1694
|
+
case import_utils22.AST_NODE_TYPES.JSXOpeningElement:
|
|
1695
|
+
case import_utils22.AST_NODE_TYPES.JSXClosingElement:
|
|
1696
|
+
case import_utils22.AST_NODE_TYPES.MemberExpression:
|
|
1697
|
+
case import_utils22.AST_NODE_TYPES.VariableDeclarator:
|
|
1698
|
+
case import_utils22.AST_NODE_TYPES.TaggedTemplateExpression:
|
|
1699
|
+
case import_utils22.AST_NODE_TYPES.SpreadElement:
|
|
1700
|
+
case import_utils22.AST_NODE_TYPES.ExportSpecifier:
|
|
1701
|
+
case import_utils22.AST_NODE_TYPES.ArrayExpression:
|
|
1702
|
+
case import_utils22.AST_NODE_TYPES.ObjectExpression:
|
|
1703
|
+
case import_utils22.AST_NODE_TYPES.BinaryExpression:
|
|
1704
|
+
case import_utils22.AST_NODE_TYPES.LogicalExpression:
|
|
1705
|
+
case import_utils22.AST_NODE_TYPES.UnaryExpression:
|
|
1706
|
+
case import_utils22.AST_NODE_TYPES.ReturnStatement:
|
|
1707
|
+
case import_utils22.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
1708
|
+
case import_utils22.AST_NODE_TYPES.ConditionalExpression:
|
|
1709
|
+
case import_utils22.AST_NODE_TYPES.AwaitExpression:
|
|
1710
|
+
case import_utils22.AST_NODE_TYPES.YieldExpression:
|
|
1711
|
+
case import_utils22.AST_NODE_TYPES.Property:
|
|
1510
1712
|
return true;
|
|
1511
1713
|
default:
|
|
1512
1714
|
return false;
|
|
@@ -1530,13 +1732,13 @@ var preferImportType = createRule18({
|
|
|
1530
1732
|
}
|
|
1531
1733
|
const scope = context.sourceCode.getScope(node);
|
|
1532
1734
|
const isTypeOnlyImport = node.specifiers.every((specifier) => {
|
|
1533
|
-
if (specifier.type ===
|
|
1735
|
+
if (specifier.type === import_utils22.AST_NODE_TYPES.ImportDefaultSpecifier) {
|
|
1534
1736
|
return false;
|
|
1535
1737
|
}
|
|
1536
|
-
if (specifier.type ===
|
|
1738
|
+
if (specifier.type === import_utils22.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
1537
1739
|
return false;
|
|
1538
1740
|
}
|
|
1539
|
-
if (specifier.type ===
|
|
1741
|
+
if (specifier.type === import_utils22.AST_NODE_TYPES.ImportSpecifier) {
|
|
1540
1742
|
const localName = specifier.local.name;
|
|
1541
1743
|
return !isUsedAsValue(localName, scope);
|
|
1542
1744
|
}
|
|
@@ -1562,11 +1764,11 @@ var preferImportType = createRule18({
|
|
|
1562
1764
|
var prefer_import_type_default = preferImportType;
|
|
1563
1765
|
|
|
1564
1766
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
1565
|
-
var
|
|
1566
|
-
var
|
|
1767
|
+
var import_utils23 = require("@typescript-eslint/utils");
|
|
1768
|
+
var createRule21 = import_utils23.ESLintUtils.RuleCreator(
|
|
1567
1769
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1568
1770
|
);
|
|
1569
|
-
var preferInterfaceOverInlineTypes =
|
|
1771
|
+
var preferInterfaceOverInlineTypes = createRule21({
|
|
1570
1772
|
name: "prefer-interface-over-inline-types",
|
|
1571
1773
|
meta: {
|
|
1572
1774
|
type: "suggestion",
|
|
@@ -1582,54 +1784,54 @@ var preferInterfaceOverInlineTypes = createRule19({
|
|
|
1582
1784
|
defaultOptions: [],
|
|
1583
1785
|
create(context) {
|
|
1584
1786
|
function hasJSXInConditional(node) {
|
|
1585
|
-
return node.consequent.type ===
|
|
1787
|
+
return node.consequent.type === import_utils23.AST_NODE_TYPES.JSXElement || node.consequent.type === import_utils23.AST_NODE_TYPES.JSXFragment || node.alternate.type === import_utils23.AST_NODE_TYPES.JSXElement || node.alternate.type === import_utils23.AST_NODE_TYPES.JSXFragment;
|
|
1586
1788
|
}
|
|
1587
1789
|
function hasJSXInLogical(node) {
|
|
1588
|
-
return node.right.type ===
|
|
1790
|
+
return node.right.type === import_utils23.AST_NODE_TYPES.JSXElement || node.right.type === import_utils23.AST_NODE_TYPES.JSXFragment;
|
|
1589
1791
|
}
|
|
1590
1792
|
function hasJSXReturn(block) {
|
|
1591
1793
|
return block.body.some((stmt) => {
|
|
1592
|
-
if (stmt.type ===
|
|
1593
|
-
return stmt.argument.type ===
|
|
1794
|
+
if (stmt.type === import_utils23.AST_NODE_TYPES.ReturnStatement && stmt.argument) {
|
|
1795
|
+
return stmt.argument.type === import_utils23.AST_NODE_TYPES.JSXElement || stmt.argument.type === import_utils23.AST_NODE_TYPES.JSXFragment || stmt.argument.type === import_utils23.AST_NODE_TYPES.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === import_utils23.AST_NODE_TYPES.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
1594
1796
|
}
|
|
1595
1797
|
return false;
|
|
1596
1798
|
});
|
|
1597
1799
|
}
|
|
1598
1800
|
function isReactComponent2(node) {
|
|
1599
|
-
if (node.type ===
|
|
1600
|
-
if (node.body.type ===
|
|
1801
|
+
if (node.type === import_utils23.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
1802
|
+
if (node.body.type === import_utils23.AST_NODE_TYPES.JSXElement || node.body.type === import_utils23.AST_NODE_TYPES.JSXFragment) {
|
|
1601
1803
|
return true;
|
|
1602
1804
|
}
|
|
1603
|
-
if (node.body.type ===
|
|
1805
|
+
if (node.body.type === import_utils23.AST_NODE_TYPES.BlockStatement) {
|
|
1604
1806
|
return hasJSXReturn(node.body);
|
|
1605
1807
|
}
|
|
1606
|
-
} else if (node.type ===
|
|
1607
|
-
if (node.body && node.body.type ===
|
|
1808
|
+
} else if (node.type === import_utils23.AST_NODE_TYPES.FunctionExpression || node.type === import_utils23.AST_NODE_TYPES.FunctionDeclaration) {
|
|
1809
|
+
if (node.body && node.body.type === import_utils23.AST_NODE_TYPES.BlockStatement) {
|
|
1608
1810
|
return hasJSXReturn(node.body);
|
|
1609
1811
|
}
|
|
1610
1812
|
}
|
|
1611
1813
|
return false;
|
|
1612
1814
|
}
|
|
1613
1815
|
function isInlineTypeAnnotation(node) {
|
|
1614
|
-
if (node.type ===
|
|
1816
|
+
if (node.type === import_utils23.AST_NODE_TYPES.TSTypeLiteral) {
|
|
1615
1817
|
return true;
|
|
1616
1818
|
}
|
|
1617
|
-
if (node.type ===
|
|
1618
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
1819
|
+
if (node.type === import_utils23.AST_NODE_TYPES.TSTypeReference && node.typeArguments) {
|
|
1820
|
+
return node.typeArguments.params.some((param) => param.type === import_utils23.AST_NODE_TYPES.TSTypeLiteral);
|
|
1619
1821
|
}
|
|
1620
|
-
if (node.type ===
|
|
1822
|
+
if (node.type === import_utils23.AST_NODE_TYPES.TSUnionType) {
|
|
1621
1823
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
1622
1824
|
}
|
|
1623
1825
|
return false;
|
|
1624
1826
|
}
|
|
1625
1827
|
function hasInlineObjectType(node) {
|
|
1626
|
-
if (node.type ===
|
|
1828
|
+
if (node.type === import_utils23.AST_NODE_TYPES.TSTypeLiteral) {
|
|
1627
1829
|
return true;
|
|
1628
1830
|
}
|
|
1629
|
-
if (node.type ===
|
|
1630
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
1831
|
+
if (node.type === import_utils23.AST_NODE_TYPES.TSTypeReference && node.typeArguments) {
|
|
1832
|
+
return node.typeArguments.params.some((param) => param.type === import_utils23.AST_NODE_TYPES.TSTypeLiteral);
|
|
1631
1833
|
}
|
|
1632
|
-
if (node.type ===
|
|
1834
|
+
if (node.type === import_utils23.AST_NODE_TYPES.TSUnionType) {
|
|
1633
1835
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
1634
1836
|
}
|
|
1635
1837
|
return false;
|
|
@@ -1642,7 +1844,7 @@ var preferInterfaceOverInlineTypes = createRule19({
|
|
|
1642
1844
|
return;
|
|
1643
1845
|
}
|
|
1644
1846
|
const param = node.params[0];
|
|
1645
|
-
if (param.type ===
|
|
1847
|
+
if (param.type === import_utils23.AST_NODE_TYPES.Identifier && param.typeAnnotation) {
|
|
1646
1848
|
const { typeAnnotation } = param.typeAnnotation;
|
|
1647
1849
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
1648
1850
|
context.report({
|
|
@@ -1662,11 +1864,11 @@ var preferInterfaceOverInlineTypes = createRule19({
|
|
|
1662
1864
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
1663
1865
|
|
|
1664
1866
|
// src/rules/prefer-jsx-template-literals.ts
|
|
1665
|
-
var
|
|
1666
|
-
var
|
|
1867
|
+
var import_utils24 = require("@typescript-eslint/utils");
|
|
1868
|
+
var createRule22 = import_utils24.ESLintUtils.RuleCreator(
|
|
1667
1869
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1668
1870
|
);
|
|
1669
|
-
var preferJSXTemplateLiterals =
|
|
1871
|
+
var preferJSXTemplateLiterals = createRule22({
|
|
1670
1872
|
name: "prefer-jsx-template-literals",
|
|
1671
1873
|
meta: {
|
|
1672
1874
|
type: "suggestion",
|
|
@@ -1735,9 +1937,9 @@ var preferJSXTemplateLiterals = createRule20({
|
|
|
1735
1937
|
if (!child || !nextChild) {
|
|
1736
1938
|
return;
|
|
1737
1939
|
}
|
|
1738
|
-
if (child.type ===
|
|
1940
|
+
if (child.type === import_utils24.AST_NODE_TYPES.JSXText && nextChild.type === import_utils24.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
1739
1941
|
handleTextBeforeExpression(child, nextChild);
|
|
1740
|
-
} else if (child.type ===
|
|
1942
|
+
} else if (child.type === import_utils24.AST_NODE_TYPES.JSXExpressionContainer && nextChild.type === import_utils24.AST_NODE_TYPES.JSXText) {
|
|
1741
1943
|
handleExpressionBeforeText(child, nextChild);
|
|
1742
1944
|
}
|
|
1743
1945
|
}
|
|
@@ -1750,11 +1952,11 @@ var preferJSXTemplateLiterals = createRule20({
|
|
|
1750
1952
|
var prefer_jsx_template_literals_default = preferJSXTemplateLiterals;
|
|
1751
1953
|
|
|
1752
1954
|
// src/rules/prefer-named-param-types.ts
|
|
1753
|
-
var
|
|
1754
|
-
var
|
|
1955
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
1956
|
+
var createRule23 = import_utils25.ESLintUtils.RuleCreator(
|
|
1755
1957
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1756
1958
|
);
|
|
1757
|
-
var preferNamedParamTypes =
|
|
1959
|
+
var preferNamedParamTypes = createRule23({
|
|
1758
1960
|
name: "prefer-named-param-types",
|
|
1759
1961
|
meta: {
|
|
1760
1962
|
type: "suggestion",
|
|
@@ -1769,16 +1971,16 @@ var preferNamedParamTypes = createRule21({
|
|
|
1769
1971
|
defaultOptions: [],
|
|
1770
1972
|
create(context) {
|
|
1771
1973
|
function hasInlineObjectType(param) {
|
|
1772
|
-
if (param.type ===
|
|
1974
|
+
if (param.type === import_utils25.AST_NODE_TYPES.AssignmentPattern) {
|
|
1773
1975
|
return hasInlineObjectType(param.left);
|
|
1774
1976
|
}
|
|
1775
|
-
if (param.type ===
|
|
1776
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
1977
|
+
if (param.type === import_utils25.AST_NODE_TYPES.ObjectPattern) {
|
|
1978
|
+
if (param.typeAnnotation?.typeAnnotation.type === import_utils25.AST_NODE_TYPES.TSTypeLiteral) {
|
|
1777
1979
|
return true;
|
|
1778
1980
|
}
|
|
1779
1981
|
}
|
|
1780
|
-
if (param.type ===
|
|
1781
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
1982
|
+
if (param.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
1983
|
+
if (param.typeAnnotation?.typeAnnotation.type === import_utils25.AST_NODE_TYPES.TSTypeLiteral) {
|
|
1782
1984
|
return true;
|
|
1783
1985
|
}
|
|
1784
1986
|
}
|
|
@@ -1812,11 +2014,11 @@ var preferNamedParamTypes = createRule21({
|
|
|
1812
2014
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
1813
2015
|
|
|
1814
2016
|
// src/rules/prefer-react-import-types.ts
|
|
1815
|
-
var
|
|
1816
|
-
var
|
|
2017
|
+
var import_utils26 = require("@typescript-eslint/utils");
|
|
2018
|
+
var createRule24 = import_utils26.ESLintUtils.RuleCreator(
|
|
1817
2019
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1818
2020
|
);
|
|
1819
|
-
var preferReactImportTypes =
|
|
2021
|
+
var preferReactImportTypes = createRule24({
|
|
1820
2022
|
name: "prefer-react-import-types",
|
|
1821
2023
|
meta: {
|
|
1822
2024
|
type: "suggestion",
|
|
@@ -1892,7 +2094,7 @@ var preferReactImportTypes = createRule22({
|
|
|
1892
2094
|
]);
|
|
1893
2095
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
1894
2096
|
function checkMemberExpression(node) {
|
|
1895
|
-
if (node.object.type ===
|
|
2097
|
+
if (node.object.type === import_utils26.AST_NODE_TYPES.Identifier && node.object.name === "React" && node.property.type === import_utils26.AST_NODE_TYPES.Identifier && allReactExports.has(node.property.name)) {
|
|
1896
2098
|
const typeName = node.property.name;
|
|
1897
2099
|
const isType = reactTypes.has(typeName);
|
|
1898
2100
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -1909,7 +2111,7 @@ var preferReactImportTypes = createRule22({
|
|
|
1909
2111
|
return {
|
|
1910
2112
|
MemberExpression: checkMemberExpression,
|
|
1911
2113
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
1912
|
-
if (node.left.type ===
|
|
2114
|
+
if (node.left.type === import_utils26.AST_NODE_TYPES.Identifier && node.left.name === "React" && node.right.type === import_utils26.AST_NODE_TYPES.Identifier && allReactExports.has(node.right.name)) {
|
|
1913
2115
|
const typeName = node.right.name;
|
|
1914
2116
|
const isType = reactTypes.has(typeName);
|
|
1915
2117
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -1929,11 +2131,11 @@ var preferReactImportTypes = createRule22({
|
|
|
1929
2131
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
1930
2132
|
|
|
1931
2133
|
// src/rules/react-props-destructure.ts
|
|
1932
|
-
var
|
|
1933
|
-
var
|
|
2134
|
+
var import_utils27 = require("@typescript-eslint/utils");
|
|
2135
|
+
var createRule25 = import_utils27.ESLintUtils.RuleCreator(
|
|
1934
2136
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1935
2137
|
);
|
|
1936
|
-
var reactPropsDestructure =
|
|
2138
|
+
var reactPropsDestructure = createRule25({
|
|
1937
2139
|
name: "react-props-destructure",
|
|
1938
2140
|
meta: {
|
|
1939
2141
|
type: "suggestion",
|
|
@@ -1949,29 +2151,29 @@ var reactPropsDestructure = createRule23({
|
|
|
1949
2151
|
defaultOptions: [],
|
|
1950
2152
|
create(context) {
|
|
1951
2153
|
function hasJSXInConditional(node) {
|
|
1952
|
-
return node.consequent.type ===
|
|
2154
|
+
return node.consequent.type === import_utils27.AST_NODE_TYPES.JSXElement || node.consequent.type === import_utils27.AST_NODE_TYPES.JSXFragment || node.alternate.type === import_utils27.AST_NODE_TYPES.JSXElement || node.alternate.type === import_utils27.AST_NODE_TYPES.JSXFragment;
|
|
1953
2155
|
}
|
|
1954
2156
|
function hasJSXInLogical(node) {
|
|
1955
|
-
return node.right.type ===
|
|
2157
|
+
return node.right.type === import_utils27.AST_NODE_TYPES.JSXElement || node.right.type === import_utils27.AST_NODE_TYPES.JSXFragment;
|
|
1956
2158
|
}
|
|
1957
2159
|
function hasJSXReturn(block) {
|
|
1958
2160
|
return block.body.some((stmt) => {
|
|
1959
|
-
if (stmt.type ===
|
|
1960
|
-
return stmt.argument.type ===
|
|
2161
|
+
if (stmt.type === import_utils27.AST_NODE_TYPES.ReturnStatement && stmt.argument) {
|
|
2162
|
+
return stmt.argument.type === import_utils27.AST_NODE_TYPES.JSXElement || stmt.argument.type === import_utils27.AST_NODE_TYPES.JSXFragment || stmt.argument.type === import_utils27.AST_NODE_TYPES.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === import_utils27.AST_NODE_TYPES.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
1961
2163
|
}
|
|
1962
2164
|
return false;
|
|
1963
2165
|
});
|
|
1964
2166
|
}
|
|
1965
2167
|
function isReactComponent2(node) {
|
|
1966
|
-
if (node.type ===
|
|
1967
|
-
if (node.body.type ===
|
|
2168
|
+
if (node.type === import_utils27.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
2169
|
+
if (node.body.type === import_utils27.AST_NODE_TYPES.JSXElement || node.body.type === import_utils27.AST_NODE_TYPES.JSXFragment) {
|
|
1968
2170
|
return true;
|
|
1969
2171
|
}
|
|
1970
|
-
if (node.body.type ===
|
|
2172
|
+
if (node.body.type === import_utils27.AST_NODE_TYPES.BlockStatement) {
|
|
1971
2173
|
return hasJSXReturn(node.body);
|
|
1972
2174
|
}
|
|
1973
|
-
} else if (node.type ===
|
|
1974
|
-
if (node.body && node.body.type ===
|
|
2175
|
+
} else if (node.type === import_utils27.AST_NODE_TYPES.FunctionExpression || node.type === import_utils27.AST_NODE_TYPES.FunctionDeclaration) {
|
|
2176
|
+
if (node.body && node.body.type === import_utils27.AST_NODE_TYPES.BlockStatement) {
|
|
1975
2177
|
return hasJSXReturn(node.body);
|
|
1976
2178
|
}
|
|
1977
2179
|
}
|
|
@@ -1985,9 +2187,9 @@ var reactPropsDestructure = createRule23({
|
|
|
1985
2187
|
return;
|
|
1986
2188
|
}
|
|
1987
2189
|
const param = node.params[0];
|
|
1988
|
-
if (param.type ===
|
|
1989
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
1990
|
-
if (prop.key.type ===
|
|
2190
|
+
if (param.type === import_utils27.AST_NODE_TYPES.ObjectPattern) {
|
|
2191
|
+
const properties = param.properties.filter((prop) => prop.type === import_utils27.AST_NODE_TYPES.Property).map((prop) => {
|
|
2192
|
+
if (prop.key.type === import_utils27.AST_NODE_TYPES.Identifier) {
|
|
1991
2193
|
return prop.key.name;
|
|
1992
2194
|
}
|
|
1993
2195
|
return null;
|
|
@@ -2031,7 +2233,9 @@ var rules = {
|
|
|
2031
2233
|
"no-direct-date": no_direct_date_default,
|
|
2032
2234
|
"no-emoji": no_emoji_default,
|
|
2033
2235
|
"no-env-fallback": no_env_fallback_default,
|
|
2236
|
+
"no-inline-default-export": no_inline_default_export_default,
|
|
2034
2237
|
"require-explicit-return-type": require_explicit_return_type_default,
|
|
2238
|
+
"no-lazy-identifiers": no_lazy_identifiers_default,
|
|
2035
2239
|
"no-logic-in-params": no_logic_in_params_default,
|
|
2036
2240
|
"no-single-char-variables": no_single_char_variables_default,
|
|
2037
2241
|
"prefer-destructuring-params": prefer_destructuring_params_default,
|
|
@@ -2063,6 +2267,8 @@ var baseRules = {
|
|
|
2063
2267
|
"nextfriday/no-direct-date": "warn",
|
|
2064
2268
|
"nextfriday/no-logic-in-params": "warn",
|
|
2065
2269
|
"nextfriday/no-env-fallback": "warn",
|
|
2270
|
+
"nextfriday/no-inline-default-export": "warn",
|
|
2271
|
+
"nextfriday/no-lazy-identifiers": "warn",
|
|
2066
2272
|
"nextfriday/no-single-char-variables": "warn"
|
|
2067
2273
|
};
|
|
2068
2274
|
var baseRecommendedRules = {
|
|
@@ -2081,6 +2287,8 @@ var baseRecommendedRules = {
|
|
|
2081
2287
|
"nextfriday/no-direct-date": "error",
|
|
2082
2288
|
"nextfriday/no-logic-in-params": "error",
|
|
2083
2289
|
"nextfriday/no-env-fallback": "error",
|
|
2290
|
+
"nextfriday/no-inline-default-export": "error",
|
|
2291
|
+
"nextfriday/no-lazy-identifiers": "error",
|
|
2084
2292
|
"nextfriday/no-single-char-variables": "error"
|
|
2085
2293
|
};
|
|
2086
2294
|
var jsxRules = {
|