eslint-plugin-nextfriday 3.1.0 → 3.2.1
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 +14 -0
- package/README.md +11 -7
- package/docs/rules/ENFORCE_CONSTANT_CASE.md +28 -17
- package/docs/rules/INDEX_EXPORT_ONLY.md +88 -0
- package/docs/rules/NO_INLINE_TYPE_IMPORT.md +86 -0
- package/lib/index.cjs +541 -432
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +84 -0
- package/lib/index.d.ts +84 -0
- package/lib/index.js +541 -432
- 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: "3.1
|
|
4
|
+
version: "3.2.1",
|
|
5
5
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
6
6
|
keywords: [
|
|
7
7
|
"eslint",
|
|
@@ -408,40 +408,14 @@ var createRule3 = ESLintUtils3.RuleCreator(
|
|
|
408
408
|
);
|
|
409
409
|
var SCREAMING_SNAKE_CASE_REGEX = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
410
410
|
var SNAKE_CASE_REGEX2 = /^[a-z]+_[a-z0-9_]*$/;
|
|
411
|
-
var BOOLEAN_PREFIXES2 = ["is", "has", "should", "can", "did", "will", "was", "are", "does", "had"];
|
|
412
411
|
var toScreamingSnakeCase = (str) => str.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toUpperCase();
|
|
413
|
-
var
|
|
414
|
-
if (!name.startsWith(prefix)) {
|
|
415
|
-
return false;
|
|
416
|
-
}
|
|
417
|
-
if (name.length === prefix.length) {
|
|
418
|
-
return true;
|
|
419
|
-
}
|
|
420
|
-
const nextChar = name.charAt(prefix.length);
|
|
421
|
-
return nextChar === nextChar.toUpperCase() && nextChar !== nextChar.toLowerCase();
|
|
422
|
-
});
|
|
423
|
-
var isBooleanLiteral2 = (init) => init.type === AST_NODE_TYPES4.Literal && typeof init.value === "boolean";
|
|
424
|
-
var isAsConstAssertion = (node) => node.type === AST_NODE_TYPES4.TSAsExpression && node.typeAnnotation.type === AST_NODE_TYPES4.TSTypeReference && node.typeAnnotation.typeName.type === AST_NODE_TYPES4.Identifier && node.typeAnnotation.typeName.name === "const";
|
|
425
|
-
var isStaticValue2 = (init) => {
|
|
426
|
-
if (isAsConstAssertion(init)) {
|
|
427
|
-
return true;
|
|
428
|
-
}
|
|
412
|
+
var isMagicLiteral = (init) => {
|
|
429
413
|
if (init.type === AST_NODE_TYPES4.Literal) {
|
|
430
|
-
return
|
|
431
|
-
}
|
|
432
|
-
if (init.type === AST_NODE_TYPES4.UnaryExpression && init.argument.type === AST_NODE_TYPES4.Literal) {
|
|
433
|
-
return true;
|
|
434
|
-
}
|
|
435
|
-
if (init.type === AST_NODE_TYPES4.TemplateLiteral && init.expressions.length === 0) {
|
|
436
|
-
return true;
|
|
414
|
+
return typeof init.value === "string" || typeof init.value === "number";
|
|
437
415
|
}
|
|
438
|
-
if (init.type === AST_NODE_TYPES4.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
if (init.type === AST_NODE_TYPES4.ObjectExpression) {
|
|
442
|
-
return init.properties.every(
|
|
443
|
-
(prop) => prop.type === AST_NODE_TYPES4.Property && isStaticValue2(prop.value)
|
|
444
|
-
);
|
|
416
|
+
if (init.type === AST_NODE_TYPES4.UnaryExpression) {
|
|
417
|
+
const { argument, operator } = init;
|
|
418
|
+
return (operator === "-" || operator === "+") && argument.type === AST_NODE_TYPES4.Literal && typeof argument.value === "number";
|
|
445
419
|
}
|
|
446
420
|
return false;
|
|
447
421
|
};
|
|
@@ -455,13 +429,12 @@ var isGlobalScope2 = (node) => {
|
|
|
455
429
|
}
|
|
456
430
|
return false;
|
|
457
431
|
};
|
|
458
|
-
var isFunctionOrComponent = (init) => init.type === AST_NODE_TYPES4.ArrowFunctionExpression || init.type === AST_NODE_TYPES4.FunctionExpression;
|
|
459
432
|
var enforceConstantCase = createRule3({
|
|
460
433
|
name: "enforce-constant-case",
|
|
461
434
|
meta: {
|
|
462
435
|
type: "suggestion",
|
|
463
436
|
docs: {
|
|
464
|
-
description: "Enforce SCREAMING_SNAKE_CASE for global
|
|
437
|
+
description: "Enforce SCREAMING_SNAKE_CASE for global magic-number and magic-text constants"
|
|
465
438
|
},
|
|
466
439
|
messages: {
|
|
467
440
|
useScreamingSnakeCase: "Constant '{{ name }}' should use SCREAMING_SNAKE_CASE. Rename to '{{ suggestion }}'.",
|
|
@@ -483,16 +456,10 @@ var enforceConstantCase = createRule3({
|
|
|
483
456
|
if (declarator.id.type !== AST_NODE_TYPES4.Identifier || !declarator.init) {
|
|
484
457
|
return;
|
|
485
458
|
}
|
|
486
|
-
if (
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
if (!isStaticValue2(declarator.init)) {
|
|
459
|
+
if (!isMagicLiteral(declarator.init)) {
|
|
490
460
|
return;
|
|
491
461
|
}
|
|
492
462
|
const { name } = declarator.id;
|
|
493
|
-
if (isBooleanLiteral2(declarator.init) && startsWithBooleanPrefix2(name)) {
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
463
|
if (SNAKE_CASE_REGEX2.test(name)) {
|
|
497
464
|
context.report({
|
|
498
465
|
node: declarator.id,
|
|
@@ -1141,12 +1108,74 @@ var fileKebabCase = createRule12({
|
|
|
1141
1108
|
});
|
|
1142
1109
|
var file_kebab_case_default = fileKebabCase;
|
|
1143
1110
|
|
|
1144
|
-
// src/rules/
|
|
1111
|
+
// src/rules/index-export-only.ts
|
|
1145
1112
|
import { AST_NODE_TYPES as AST_NODE_TYPES13, ESLintUtils as ESLintUtils13 } from "@typescript-eslint/utils";
|
|
1146
1113
|
var createRule13 = ESLintUtils13.RuleCreator(
|
|
1147
1114
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1148
1115
|
);
|
|
1149
|
-
var
|
|
1116
|
+
var isIndexFile = (filename) => getBaseName(filename) === "index";
|
|
1117
|
+
var isAllowedExportNamed = (node) => {
|
|
1118
|
+
if (!node.declaration) {
|
|
1119
|
+
return true;
|
|
1120
|
+
}
|
|
1121
|
+
return node.declaration.type === AST_NODE_TYPES13.TSTypeAliasDeclaration || node.declaration.type === AST_NODE_TYPES13.TSInterfaceDeclaration;
|
|
1122
|
+
};
|
|
1123
|
+
var isAllowedExportDefault = (node) => node.declaration.type === AST_NODE_TYPES13.Identifier;
|
|
1124
|
+
var isAllowedTopLevel = (node) => {
|
|
1125
|
+
switch (node.type) {
|
|
1126
|
+
case AST_NODE_TYPES13.ImportDeclaration:
|
|
1127
|
+
case AST_NODE_TYPES13.ExportAllDeclaration:
|
|
1128
|
+
case AST_NODE_TYPES13.TSTypeAliasDeclaration:
|
|
1129
|
+
case AST_NODE_TYPES13.TSInterfaceDeclaration:
|
|
1130
|
+
case AST_NODE_TYPES13.TSImportEqualsDeclaration:
|
|
1131
|
+
return true;
|
|
1132
|
+
case AST_NODE_TYPES13.ExportNamedDeclaration:
|
|
1133
|
+
return isAllowedExportNamed(node);
|
|
1134
|
+
case AST_NODE_TYPES13.ExportDefaultDeclaration:
|
|
1135
|
+
return isAllowedExportDefault(node);
|
|
1136
|
+
default:
|
|
1137
|
+
return false;
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
var indexExportOnly = createRule13({
|
|
1141
|
+
name: "index-export-only",
|
|
1142
|
+
meta: {
|
|
1143
|
+
type: "suggestion",
|
|
1144
|
+
docs: {
|
|
1145
|
+
description: "Restrict index files to imports, re-exports, and type declarations only."
|
|
1146
|
+
},
|
|
1147
|
+
messages: {
|
|
1148
|
+
indexExportOnly: "Index files must contain only imports, re-exports, and type declarations. Move runtime code to a separate module and re-export it from here."
|
|
1149
|
+
},
|
|
1150
|
+
schema: []
|
|
1151
|
+
},
|
|
1152
|
+
defaultOptions: [],
|
|
1153
|
+
create(context) {
|
|
1154
|
+
if (!isIndexFile(context.filename)) {
|
|
1155
|
+
return {};
|
|
1156
|
+
}
|
|
1157
|
+
return {
|
|
1158
|
+
Program(node) {
|
|
1159
|
+
for (const statement of node.body) {
|
|
1160
|
+
if (!isAllowedTopLevel(statement)) {
|
|
1161
|
+
context.report({
|
|
1162
|
+
node: statement,
|
|
1163
|
+
messageId: "indexExportOnly"
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
});
|
|
1171
|
+
var index_export_only_default = indexExportOnly;
|
|
1172
|
+
|
|
1173
|
+
// src/rules/jsx-newline-between-elements.ts
|
|
1174
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES14, ESLintUtils as ESLintUtils14 } from "@typescript-eslint/utils";
|
|
1175
|
+
var createRule14 = ESLintUtils14.RuleCreator(
|
|
1176
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1177
|
+
);
|
|
1178
|
+
var jsxNewlineBetweenElements = createRule14({
|
|
1150
1179
|
name: "jsx-newline-between-elements",
|
|
1151
1180
|
meta: {
|
|
1152
1181
|
type: "layout",
|
|
@@ -1164,7 +1193,7 @@ var jsxNewlineBetweenElements = createRule13({
|
|
|
1164
1193
|
create(context) {
|
|
1165
1194
|
const { sourceCode } = context;
|
|
1166
1195
|
function isSignificantJSXChild(node) {
|
|
1167
|
-
return node.type ===
|
|
1196
|
+
return node.type === AST_NODE_TYPES14.JSXElement || node.type === AST_NODE_TYPES14.JSXFragment || node.type === AST_NODE_TYPES14.JSXExpressionContainer;
|
|
1168
1197
|
}
|
|
1169
1198
|
function isMultiLine(node) {
|
|
1170
1199
|
return node.loc.start.line !== node.loc.end.line;
|
|
@@ -1214,11 +1243,11 @@ var jsxNewlineBetweenElements = createRule13({
|
|
|
1214
1243
|
var jsx_newline_between_elements_default = jsxNewlineBetweenElements;
|
|
1215
1244
|
|
|
1216
1245
|
// src/rules/jsx-no-inline-object-prop.ts
|
|
1217
|
-
import { AST_NODE_TYPES as
|
|
1218
|
-
var
|
|
1246
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15, ESLintUtils as ESLintUtils15 } from "@typescript-eslint/utils";
|
|
1247
|
+
var createRule15 = ESLintUtils15.RuleCreator(
|
|
1219
1248
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1220
1249
|
);
|
|
1221
|
-
var jsxNoInlineObjectProp =
|
|
1250
|
+
var jsxNoInlineObjectProp = createRule15({
|
|
1222
1251
|
name: "jsx-no-inline-object-prop",
|
|
1223
1252
|
meta: {
|
|
1224
1253
|
type: "suggestion",
|
|
@@ -1234,7 +1263,7 @@ var jsxNoInlineObjectProp = createRule14({
|
|
|
1234
1263
|
create(context) {
|
|
1235
1264
|
return {
|
|
1236
1265
|
JSXAttribute(node) {
|
|
1237
|
-
if (node.value?.type ===
|
|
1266
|
+
if (node.value?.type === AST_NODE_TYPES15.JSXExpressionContainer && node.value.expression.type === AST_NODE_TYPES15.ObjectExpression) {
|
|
1238
1267
|
context.report({
|
|
1239
1268
|
node: node.value,
|
|
1240
1269
|
messageId: "noInlineObject"
|
|
@@ -1247,17 +1276,17 @@ var jsxNoInlineObjectProp = createRule14({
|
|
|
1247
1276
|
var jsx_no_inline_object_prop_default = jsxNoInlineObjectProp;
|
|
1248
1277
|
|
|
1249
1278
|
// src/rules/jsx-no-newline-single-line-elements.ts
|
|
1250
|
-
import { AST_NODE_TYPES as
|
|
1251
|
-
var
|
|
1279
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES16, ESLintUtils as ESLintUtils16 } from "@typescript-eslint/utils";
|
|
1280
|
+
var createRule16 = ESLintUtils16.RuleCreator(
|
|
1252
1281
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1253
1282
|
);
|
|
1254
1283
|
function isJSXElementOrFragment(node) {
|
|
1255
|
-
return node.type ===
|
|
1284
|
+
return node.type === AST_NODE_TYPES16.JSXElement || node.type === AST_NODE_TYPES16.JSXFragment;
|
|
1256
1285
|
}
|
|
1257
1286
|
function isSingleLine(node) {
|
|
1258
1287
|
return node.loc.start.line === node.loc.end.line;
|
|
1259
1288
|
}
|
|
1260
|
-
var jsxNoNewlineSingleLineElements =
|
|
1289
|
+
var jsxNoNewlineSingleLineElements = createRule16({
|
|
1261
1290
|
name: "jsx-no-newline-single-line-elements",
|
|
1262
1291
|
meta: {
|
|
1263
1292
|
type: "layout",
|
|
@@ -1275,7 +1304,7 @@ var jsxNoNewlineSingleLineElements = createRule15({
|
|
|
1275
1304
|
const { sourceCode } = context;
|
|
1276
1305
|
function checkSiblings(children) {
|
|
1277
1306
|
const nonWhitespace = children.filter(
|
|
1278
|
-
(child) => !(child.type ===
|
|
1307
|
+
(child) => !(child.type === AST_NODE_TYPES16.JSXText && child.value.trim() === "")
|
|
1279
1308
|
);
|
|
1280
1309
|
nonWhitespace.forEach((next, index) => {
|
|
1281
1310
|
if (index === 0) {
|
|
@@ -1326,11 +1355,11 @@ ${indent}`);
|
|
|
1326
1355
|
var jsx_no_newline_single_line_elements_default = jsxNoNewlineSingleLineElements;
|
|
1327
1356
|
|
|
1328
1357
|
// src/rules/jsx-no-non-component-function.ts
|
|
1329
|
-
import { AST_NODE_TYPES as
|
|
1330
|
-
var
|
|
1358
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES17, ESLintUtils as ESLintUtils17 } from "@typescript-eslint/utils";
|
|
1359
|
+
var createRule17 = ESLintUtils17.RuleCreator(
|
|
1331
1360
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1332
1361
|
);
|
|
1333
|
-
var jsxNoNonComponentFunction =
|
|
1362
|
+
var jsxNoNonComponentFunction = createRule17({
|
|
1334
1363
|
name: "jsx-no-non-component-function",
|
|
1335
1364
|
meta: {
|
|
1336
1365
|
type: "problem",
|
|
@@ -1350,13 +1379,13 @@ var jsxNoNonComponentFunction = createRule16({
|
|
|
1350
1379
|
return {};
|
|
1351
1380
|
}
|
|
1352
1381
|
function isReactComponent2(node) {
|
|
1353
|
-
const functionName = node.type ===
|
|
1382
|
+
const functionName = node.type === AST_NODE_TYPES17.FunctionDeclaration && node.id ? node.id.name : null;
|
|
1354
1383
|
if (functionName && /^[A-Z]/.test(functionName)) {
|
|
1355
1384
|
return true;
|
|
1356
1385
|
}
|
|
1357
1386
|
if (node.returnType?.typeAnnotation) {
|
|
1358
1387
|
const returnTypeNode = node.returnType.typeAnnotation;
|
|
1359
|
-
if (returnTypeNode.type ===
|
|
1388
|
+
if (returnTypeNode.type === AST_NODE_TYPES17.TSTypeReference && returnTypeNode.typeName.type === AST_NODE_TYPES17.Identifier) {
|
|
1360
1389
|
const typeName = returnTypeNode.typeName.name;
|
|
1361
1390
|
if (typeName === "JSX" || typeName === "ReactElement" || typeName === "ReactNode") {
|
|
1362
1391
|
return true;
|
|
@@ -1373,13 +1402,13 @@ var jsxNoNonComponentFunction = createRule16({
|
|
|
1373
1402
|
if (!parent) {
|
|
1374
1403
|
return;
|
|
1375
1404
|
}
|
|
1376
|
-
if (parent.type ===
|
|
1405
|
+
if (parent.type === AST_NODE_TYPES17.ExportDefaultDeclaration || parent.type === AST_NODE_TYPES17.ExportNamedDeclaration) {
|
|
1377
1406
|
return;
|
|
1378
1407
|
}
|
|
1379
|
-
if (declaratorNode?.parent?.parent?.type ===
|
|
1408
|
+
if (declaratorNode?.parent?.parent?.type === AST_NODE_TYPES17.ExportNamedDeclaration) {
|
|
1380
1409
|
return;
|
|
1381
1410
|
}
|
|
1382
|
-
if (declaratorNode?.id.type ===
|
|
1411
|
+
if (declaratorNode?.id.type === AST_NODE_TYPES17.Identifier) {
|
|
1383
1412
|
const varName = declaratorNode.id.name;
|
|
1384
1413
|
if (/^[A-Z]/.test(varName)) {
|
|
1385
1414
|
return;
|
|
@@ -1404,20 +1433,20 @@ var jsxNoNonComponentFunction = createRule16({
|
|
|
1404
1433
|
var jsx_no_non_component_function_default = jsxNoNonComponentFunction;
|
|
1405
1434
|
|
|
1406
1435
|
// src/rules/jsx-no-ternary-null.ts
|
|
1407
|
-
import { AST_NODE_TYPES as
|
|
1408
|
-
var
|
|
1436
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18, ESLintUtils as ESLintUtils18 } from "@typescript-eslint/utils";
|
|
1437
|
+
var createRule18 = ESLintUtils18.RuleCreator(
|
|
1409
1438
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1410
1439
|
);
|
|
1411
1440
|
function isNullOrUndefined(node) {
|
|
1412
|
-
if (node.type ===
|
|
1441
|
+
if (node.type === AST_NODE_TYPES18.Literal && node.value === null) {
|
|
1413
1442
|
return true;
|
|
1414
1443
|
}
|
|
1415
|
-
if (node.type ===
|
|
1444
|
+
if (node.type === AST_NODE_TYPES18.Identifier && node.name === "undefined") {
|
|
1416
1445
|
return true;
|
|
1417
1446
|
}
|
|
1418
1447
|
return false;
|
|
1419
1448
|
}
|
|
1420
|
-
var jsxNoTernaryNull =
|
|
1449
|
+
var jsxNoTernaryNull = createRule18({
|
|
1421
1450
|
name: "jsx-no-ternary-null",
|
|
1422
1451
|
meta: {
|
|
1423
1452
|
type: "suggestion",
|
|
@@ -1435,7 +1464,7 @@ var jsxNoTernaryNull = createRule17({
|
|
|
1435
1464
|
return {
|
|
1436
1465
|
JSXExpressionContainer(node) {
|
|
1437
1466
|
const { expression } = node;
|
|
1438
|
-
if (expression.type !==
|
|
1467
|
+
if (expression.type !== AST_NODE_TYPES18.ConditionalExpression) {
|
|
1439
1468
|
return;
|
|
1440
1469
|
}
|
|
1441
1470
|
const { test, consequent, alternate } = expression;
|
|
@@ -1467,11 +1496,11 @@ var jsxNoTernaryNull = createRule17({
|
|
|
1467
1496
|
var jsx_no_ternary_null_default = jsxNoTernaryNull;
|
|
1468
1497
|
|
|
1469
1498
|
// src/rules/jsx-no-variable-in-callback.ts
|
|
1470
|
-
import { AST_NODE_TYPES as
|
|
1471
|
-
var
|
|
1499
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES19, ESLintUtils as ESLintUtils19 } from "@typescript-eslint/utils";
|
|
1500
|
+
var createRule19 = ESLintUtils19.RuleCreator(
|
|
1472
1501
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1473
1502
|
);
|
|
1474
|
-
var jsxNoVariableInCallback =
|
|
1503
|
+
var jsxNoVariableInCallback = createRule19({
|
|
1475
1504
|
name: "jsx-no-variable-in-callback",
|
|
1476
1505
|
meta: {
|
|
1477
1506
|
type: "suggestion",
|
|
@@ -1488,7 +1517,7 @@ var jsxNoVariableInCallback = createRule18({
|
|
|
1488
1517
|
function isInsideJSX(node) {
|
|
1489
1518
|
let current = node.parent;
|
|
1490
1519
|
while (current) {
|
|
1491
|
-
if (current.type ===
|
|
1520
|
+
if (current.type === AST_NODE_TYPES19.JSXElement || current.type === AST_NODE_TYPES19.JSXFragment) {
|
|
1492
1521
|
return true;
|
|
1493
1522
|
}
|
|
1494
1523
|
current = current.parent;
|
|
@@ -1502,11 +1531,11 @@ var jsxNoVariableInCallback = createRule18({
|
|
|
1502
1531
|
if (!isInsideJSX(node)) {
|
|
1503
1532
|
return false;
|
|
1504
1533
|
}
|
|
1505
|
-
if (node.parent.type ===
|
|
1534
|
+
if (node.parent.type === AST_NODE_TYPES19.CallExpression || node.parent.type === AST_NODE_TYPES19.JSXExpressionContainer) {
|
|
1506
1535
|
return true;
|
|
1507
1536
|
}
|
|
1508
|
-
if (node.parent.type ===
|
|
1509
|
-
if (node.parent.parent.type ===
|
|
1537
|
+
if (node.parent.type === AST_NODE_TYPES19.ArrayExpression && node.parent.parent) {
|
|
1538
|
+
if (node.parent.parent.type === AST_NODE_TYPES19.CallExpression || node.parent.parent.type === AST_NODE_TYPES19.JSXExpressionContainer) {
|
|
1510
1539
|
return true;
|
|
1511
1540
|
}
|
|
1512
1541
|
}
|
|
@@ -1517,11 +1546,11 @@ var jsxNoVariableInCallback = createRule18({
|
|
|
1517
1546
|
return;
|
|
1518
1547
|
}
|
|
1519
1548
|
const { body } = node;
|
|
1520
|
-
if (body.type !==
|
|
1549
|
+
if (body.type !== AST_NODE_TYPES19.BlockStatement) {
|
|
1521
1550
|
return;
|
|
1522
1551
|
}
|
|
1523
1552
|
body.body.forEach((statement) => {
|
|
1524
|
-
if (statement.type ===
|
|
1553
|
+
if (statement.type === AST_NODE_TYPES19.VariableDeclaration) {
|
|
1525
1554
|
context.report({
|
|
1526
1555
|
node: statement,
|
|
1527
1556
|
messageId: "noVariableInCallback"
|
|
@@ -1539,12 +1568,12 @@ var jsx_no_variable_in_callback_default = jsxNoVariableInCallback;
|
|
|
1539
1568
|
|
|
1540
1569
|
// src/rules/jsx-pascal-case.ts
|
|
1541
1570
|
import path4 from "path";
|
|
1542
|
-
import { ESLintUtils as
|
|
1543
|
-
var
|
|
1571
|
+
import { ESLintUtils as ESLintUtils20 } from "@typescript-eslint/utils";
|
|
1572
|
+
var createRule20 = ESLintUtils20.RuleCreator(
|
|
1544
1573
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1545
1574
|
);
|
|
1546
1575
|
var isPascalCase = (str) => /^[A-Z][a-zA-Z0-9]*$/.test(str) && !/^[A-Z]+$/.test(str);
|
|
1547
|
-
var jsxPascalCase =
|
|
1576
|
+
var jsxPascalCase = createRule20({
|
|
1548
1577
|
name: "jsx-pascal-case",
|
|
1549
1578
|
meta: {
|
|
1550
1579
|
type: "problem",
|
|
@@ -1579,11 +1608,11 @@ var jsxPascalCase = createRule19({
|
|
|
1579
1608
|
var jsx_pascal_case_default = jsxPascalCase;
|
|
1580
1609
|
|
|
1581
1610
|
// src/rules/jsx-require-suspense.ts
|
|
1582
|
-
import { AST_NODE_TYPES as
|
|
1583
|
-
var
|
|
1611
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES20, ESLintUtils as ESLintUtils21 } from "@typescript-eslint/utils";
|
|
1612
|
+
var createRule21 = ESLintUtils21.RuleCreator(
|
|
1584
1613
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1585
1614
|
);
|
|
1586
|
-
var jsxRequireSuspense =
|
|
1615
|
+
var jsxRequireSuspense = createRule21({
|
|
1587
1616
|
name: "jsx-require-suspense",
|
|
1588
1617
|
meta: {
|
|
1589
1618
|
type: "problem",
|
|
@@ -1601,7 +1630,7 @@ var jsxRequireSuspense = createRule20({
|
|
|
1601
1630
|
const isInsideSuspense = (node) => {
|
|
1602
1631
|
let current = node.parent;
|
|
1603
1632
|
while (current) {
|
|
1604
|
-
if (current.type ===
|
|
1633
|
+
if (current.type === AST_NODE_TYPES20.JSXElement && current.openingElement.name.type === AST_NODE_TYPES20.JSXIdentifier && current.openingElement.name.name === "Suspense") {
|
|
1605
1634
|
return true;
|
|
1606
1635
|
}
|
|
1607
1636
|
current = current.parent;
|
|
@@ -1610,16 +1639,16 @@ var jsxRequireSuspense = createRule20({
|
|
|
1610
1639
|
};
|
|
1611
1640
|
return {
|
|
1612
1641
|
VariableDeclarator(node) {
|
|
1613
|
-
if (node.id.type ===
|
|
1642
|
+
if (node.id.type === AST_NODE_TYPES20.Identifier && node.init?.type === AST_NODE_TYPES20.CallExpression) {
|
|
1614
1643
|
const { callee } = node.init;
|
|
1615
|
-
const isLazyCall = callee.type ===
|
|
1644
|
+
const isLazyCall = callee.type === AST_NODE_TYPES20.Identifier && callee.name === "lazy" || callee.type === AST_NODE_TYPES20.MemberExpression && callee.object.type === AST_NODE_TYPES20.Identifier && callee.object.name === "React" && callee.property.type === AST_NODE_TYPES20.Identifier && callee.property.name === "lazy";
|
|
1616
1645
|
if (isLazyCall) {
|
|
1617
1646
|
lazyComponents.add(node.id.name);
|
|
1618
1647
|
}
|
|
1619
1648
|
}
|
|
1620
1649
|
},
|
|
1621
1650
|
JSXOpeningElement(node) {
|
|
1622
|
-
if (node.name.type ===
|
|
1651
|
+
if (node.name.type === AST_NODE_TYPES20.JSXIdentifier) {
|
|
1623
1652
|
const componentName = node.name.name;
|
|
1624
1653
|
if (lazyComponents.has(componentName) && !isInsideSuspense(node)) {
|
|
1625
1654
|
context.report({
|
|
@@ -1638,11 +1667,11 @@ var jsxRequireSuspense = createRule20({
|
|
|
1638
1667
|
var jsx_require_suspense_default = jsxRequireSuspense;
|
|
1639
1668
|
|
|
1640
1669
|
// src/rules/jsx-simple-props.ts
|
|
1641
|
-
import { AST_NODE_TYPES as
|
|
1642
|
-
var
|
|
1670
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21, ESLintUtils as ESLintUtils22 } from "@typescript-eslint/utils";
|
|
1671
|
+
var createRule22 = ESLintUtils22.RuleCreator(
|
|
1643
1672
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1644
1673
|
);
|
|
1645
|
-
var jsxSimpleProps =
|
|
1674
|
+
var jsxSimpleProps = createRule22({
|
|
1646
1675
|
name: "jsx-simple-props",
|
|
1647
1676
|
meta: {
|
|
1648
1677
|
type: "suggestion",
|
|
@@ -1657,25 +1686,25 @@ var jsxSimpleProps = createRule21({
|
|
|
1657
1686
|
defaultOptions: [],
|
|
1658
1687
|
create(context) {
|
|
1659
1688
|
const allowedExpressionTypes = /* @__PURE__ */ new Set([
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1689
|
+
AST_NODE_TYPES21.Identifier,
|
|
1690
|
+
AST_NODE_TYPES21.Literal,
|
|
1691
|
+
AST_NODE_TYPES21.JSXElement,
|
|
1692
|
+
AST_NODE_TYPES21.JSXFragment,
|
|
1693
|
+
AST_NODE_TYPES21.MemberExpression,
|
|
1694
|
+
AST_NODE_TYPES21.ArrowFunctionExpression,
|
|
1695
|
+
AST_NODE_TYPES21.FunctionExpression
|
|
1667
1696
|
]);
|
|
1668
1697
|
return {
|
|
1669
1698
|
JSXAttribute(node) {
|
|
1670
1699
|
if (!node.value) {
|
|
1671
1700
|
return;
|
|
1672
1701
|
}
|
|
1673
|
-
if (node.value.type ===
|
|
1702
|
+
if (node.value.type === AST_NODE_TYPES21.Literal) {
|
|
1674
1703
|
return;
|
|
1675
1704
|
}
|
|
1676
|
-
if (node.value.type ===
|
|
1705
|
+
if (node.value.type === AST_NODE_TYPES21.JSXExpressionContainer) {
|
|
1677
1706
|
const { expression } = node.value;
|
|
1678
|
-
if (expression.type ===
|
|
1707
|
+
if (expression.type === AST_NODE_TYPES21.JSXEmptyExpression) {
|
|
1679
1708
|
return;
|
|
1680
1709
|
}
|
|
1681
1710
|
if (!allowedExpressionTypes.has(expression.type)) {
|
|
@@ -1692,8 +1721,8 @@ var jsxSimpleProps = createRule21({
|
|
|
1692
1721
|
var jsx_simple_props_default = jsxSimpleProps;
|
|
1693
1722
|
|
|
1694
1723
|
// src/rules/jsx-sort-props.ts
|
|
1695
|
-
import { AST_NODE_TYPES as
|
|
1696
|
-
var
|
|
1724
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22, ESLintUtils as ESLintUtils23 } from "@typescript-eslint/utils";
|
|
1725
|
+
var createRule23 = ESLintUtils23.RuleCreator(
|
|
1697
1726
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1698
1727
|
);
|
|
1699
1728
|
var TYPE_GROUP = {
|
|
@@ -1707,15 +1736,15 @@ var TYPE_GROUP = {
|
|
|
1707
1736
|
SHORTHAND: 8
|
|
1708
1737
|
};
|
|
1709
1738
|
var EXPRESSION_TYPE_TO_GROUP = /* @__PURE__ */ new Map([
|
|
1710
|
-
[
|
|
1711
|
-
[
|
|
1712
|
-
[
|
|
1713
|
-
[
|
|
1714
|
-
[
|
|
1715
|
-
[
|
|
1739
|
+
[AST_NODE_TYPES22.ObjectExpression, TYPE_GROUP.OBJECT_ARRAY],
|
|
1740
|
+
[AST_NODE_TYPES22.ArrayExpression, TYPE_GROUP.OBJECT_ARRAY],
|
|
1741
|
+
[AST_NODE_TYPES22.ArrowFunctionExpression, TYPE_GROUP.FUNCTION],
|
|
1742
|
+
[AST_NODE_TYPES22.FunctionExpression, TYPE_GROUP.FUNCTION],
|
|
1743
|
+
[AST_NODE_TYPES22.JSXElement, TYPE_GROUP.JSX],
|
|
1744
|
+
[AST_NODE_TYPES22.JSXFragment, TYPE_GROUP.JSX]
|
|
1716
1745
|
]);
|
|
1717
1746
|
function isHyphenatedName(node) {
|
|
1718
|
-
return node.name.type ===
|
|
1747
|
+
return node.name.type === AST_NODE_TYPES22.JSXIdentifier && node.name.name.includes("-");
|
|
1719
1748
|
}
|
|
1720
1749
|
function getStringGroup(node) {
|
|
1721
1750
|
return isHyphenatedName(node) ? TYPE_GROUP.HYPHENATED_STRING : TYPE_GROUP.STRING;
|
|
@@ -1727,13 +1756,13 @@ function getLiteralValueGroup(value) {
|
|
|
1727
1756
|
return TYPE_GROUP.NUMBER_BOOLEAN_NULL;
|
|
1728
1757
|
}
|
|
1729
1758
|
function getExpressionGroup(expression) {
|
|
1730
|
-
if (expression.type ===
|
|
1759
|
+
if (expression.type === AST_NODE_TYPES22.Literal) {
|
|
1731
1760
|
return getLiteralValueGroup(expression.value);
|
|
1732
1761
|
}
|
|
1733
|
-
if (expression.type ===
|
|
1762
|
+
if (expression.type === AST_NODE_TYPES22.TemplateLiteral) {
|
|
1734
1763
|
return null;
|
|
1735
1764
|
}
|
|
1736
|
-
if (expression.type ===
|
|
1765
|
+
if (expression.type === AST_NODE_TYPES22.Identifier && expression.name === "undefined") {
|
|
1737
1766
|
return TYPE_GROUP.NUMBER_BOOLEAN_NULL;
|
|
1738
1767
|
}
|
|
1739
1768
|
return EXPRESSION_TYPE_TO_GROUP.get(expression.type) ?? TYPE_GROUP.EXPRESSION;
|
|
@@ -1742,17 +1771,17 @@ function getTypeGroup(node) {
|
|
|
1742
1771
|
if (node.value === null) {
|
|
1743
1772
|
return TYPE_GROUP.SHORTHAND;
|
|
1744
1773
|
}
|
|
1745
|
-
if (node.value.type ===
|
|
1774
|
+
if (node.value.type === AST_NODE_TYPES22.Literal) {
|
|
1746
1775
|
if (typeof node.value.value === "string") {
|
|
1747
1776
|
return getStringGroup(node);
|
|
1748
1777
|
}
|
|
1749
1778
|
return TYPE_GROUP.NUMBER_BOOLEAN_NULL;
|
|
1750
1779
|
}
|
|
1751
|
-
if (node.value.type !==
|
|
1780
|
+
if (node.value.type !== AST_NODE_TYPES22.JSXExpressionContainer) {
|
|
1752
1781
|
return null;
|
|
1753
1782
|
}
|
|
1754
1783
|
const { expression } = node.value;
|
|
1755
|
-
if (expression.type ===
|
|
1784
|
+
if (expression.type === AST_NODE_TYPES22.JSXEmptyExpression) {
|
|
1756
1785
|
return null;
|
|
1757
1786
|
}
|
|
1758
1787
|
const group = getExpressionGroup(expression);
|
|
@@ -1764,7 +1793,7 @@ function getTypeGroup(node) {
|
|
|
1764
1793
|
function hasUnsortedProps(attributes) {
|
|
1765
1794
|
let lastGroup = 0;
|
|
1766
1795
|
return attributes.some((attribute) => {
|
|
1767
|
-
if (attribute.type ===
|
|
1796
|
+
if (attribute.type === AST_NODE_TYPES22.JSXSpreadAttribute) {
|
|
1768
1797
|
lastGroup = 0;
|
|
1769
1798
|
return false;
|
|
1770
1799
|
}
|
|
@@ -1788,7 +1817,7 @@ function getSegments(attributes) {
|
|
|
1788
1817
|
const result = [];
|
|
1789
1818
|
let current = [];
|
|
1790
1819
|
attributes.forEach((attr) => {
|
|
1791
|
-
if (attr.type ===
|
|
1820
|
+
if (attr.type === AST_NODE_TYPES22.JSXSpreadAttribute) {
|
|
1792
1821
|
if (current.length > 0) {
|
|
1793
1822
|
result.push(current);
|
|
1794
1823
|
current = [];
|
|
@@ -1802,7 +1831,7 @@ function getSegments(attributes) {
|
|
|
1802
1831
|
}
|
|
1803
1832
|
return result;
|
|
1804
1833
|
}
|
|
1805
|
-
var jsxSortProps =
|
|
1834
|
+
var jsxSortProps = createRule23({
|
|
1806
1835
|
name: "jsx-sort-props",
|
|
1807
1836
|
meta: {
|
|
1808
1837
|
type: "suggestion",
|
|
@@ -1837,11 +1866,11 @@ var jsxSortProps = createRule22({
|
|
|
1837
1866
|
var jsx_sort_props_default = jsxSortProps;
|
|
1838
1867
|
|
|
1839
1868
|
// src/rules/jsx-spread-props-last.ts
|
|
1840
|
-
import { AST_NODE_TYPES as
|
|
1841
|
-
var
|
|
1869
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23, ESLintUtils as ESLintUtils24 } from "@typescript-eslint/utils";
|
|
1870
|
+
var createRule24 = ESLintUtils24.RuleCreator(
|
|
1842
1871
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1843
1872
|
);
|
|
1844
|
-
var jsxSpreadPropsLast =
|
|
1873
|
+
var jsxSpreadPropsLast = createRule24({
|
|
1845
1874
|
name: "jsx-spread-props-last",
|
|
1846
1875
|
meta: {
|
|
1847
1876
|
type: "suggestion",
|
|
@@ -1860,12 +1889,12 @@ var jsxSpreadPropsLast = createRule23({
|
|
|
1860
1889
|
const { attributes } = node;
|
|
1861
1890
|
let lastNonSpreadIndex = -1;
|
|
1862
1891
|
attributes.forEach((attribute, index) => {
|
|
1863
|
-
if (attribute.type !==
|
|
1892
|
+
if (attribute.type !== AST_NODE_TYPES23.JSXSpreadAttribute) {
|
|
1864
1893
|
lastNonSpreadIndex = index;
|
|
1865
1894
|
}
|
|
1866
1895
|
});
|
|
1867
1896
|
attributes.forEach((attribute, index) => {
|
|
1868
|
-
if (attribute.type ===
|
|
1897
|
+
if (attribute.type === AST_NODE_TYPES23.JSXSpreadAttribute && index < lastNonSpreadIndex) {
|
|
1869
1898
|
context.report({
|
|
1870
1899
|
node: attribute,
|
|
1871
1900
|
messageId: "spreadNotLast"
|
|
@@ -1879,12 +1908,12 @@ var jsxSpreadPropsLast = createRule23({
|
|
|
1879
1908
|
var jsx_spread_props_last_default = jsxSpreadPropsLast;
|
|
1880
1909
|
|
|
1881
1910
|
// src/rules/newline-after-multiline-block.ts
|
|
1882
|
-
import { AST_NODE_TYPES as
|
|
1883
|
-
var
|
|
1911
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24, ESLintUtils as ESLintUtils25 } from "@typescript-eslint/utils";
|
|
1912
|
+
var createRule25 = ESLintUtils25.RuleCreator(
|
|
1884
1913
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1885
1914
|
);
|
|
1886
1915
|
function isImportDeclaration(node) {
|
|
1887
|
-
return node.type ===
|
|
1916
|
+
return node.type === AST_NODE_TYPES24.ImportDeclaration;
|
|
1888
1917
|
}
|
|
1889
1918
|
function checkStatements(statements, context) {
|
|
1890
1919
|
const { sourceCode } = context;
|
|
@@ -1919,7 +1948,7 @@ function checkStatements(statements, context) {
|
|
|
1919
1948
|
}
|
|
1920
1949
|
});
|
|
1921
1950
|
}
|
|
1922
|
-
var newlineAfterMultilineBlock =
|
|
1951
|
+
var newlineAfterMultilineBlock = createRule25({
|
|
1923
1952
|
name: "newline-after-multiline-block",
|
|
1924
1953
|
meta: {
|
|
1925
1954
|
type: "layout",
|
|
@@ -1947,11 +1976,11 @@ var newlineAfterMultilineBlock = createRule24({
|
|
|
1947
1976
|
var newline_after_multiline_block_default = newlineAfterMultilineBlock;
|
|
1948
1977
|
|
|
1949
1978
|
// src/rules/newline-before-return.ts
|
|
1950
|
-
import { AST_NODE_TYPES as
|
|
1951
|
-
var
|
|
1979
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25, ESLintUtils as ESLintUtils26 } from "@typescript-eslint/utils";
|
|
1980
|
+
var createRule26 = ESLintUtils26.RuleCreator(
|
|
1952
1981
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1953
1982
|
);
|
|
1954
|
-
var newlineBeforeReturn =
|
|
1983
|
+
var newlineBeforeReturn = createRule26({
|
|
1955
1984
|
name: "newline-before-return",
|
|
1956
1985
|
meta: {
|
|
1957
1986
|
type: "layout",
|
|
@@ -1969,7 +1998,7 @@ var newlineBeforeReturn = createRule25({
|
|
|
1969
1998
|
const { sourceCode } = context;
|
|
1970
1999
|
function checkReturnStatement(node) {
|
|
1971
2000
|
const { parent } = node;
|
|
1972
|
-
if (!parent || parent.type !==
|
|
2001
|
+
if (!parent || parent.type !== AST_NODE_TYPES25.BlockStatement) {
|
|
1973
2002
|
return;
|
|
1974
2003
|
}
|
|
1975
2004
|
const { body: statements } = parent;
|
|
@@ -2006,11 +2035,11 @@ var newlineBeforeReturn = createRule25({
|
|
|
2006
2035
|
var newline_before_return_default = newlineBeforeReturn;
|
|
2007
2036
|
|
|
2008
2037
|
// src/rules/nextjs-require-public-env.ts
|
|
2009
|
-
import { AST_NODE_TYPES as
|
|
2010
|
-
var
|
|
2038
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26, ESLintUtils as ESLintUtils27 } from "@typescript-eslint/utils";
|
|
2039
|
+
var createRule27 = ESLintUtils27.RuleCreator(
|
|
2011
2040
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2012
2041
|
);
|
|
2013
|
-
var nextjsRequirePublicEnv =
|
|
2042
|
+
var nextjsRequirePublicEnv = createRule27({
|
|
2014
2043
|
name: "nextjs-require-public-env",
|
|
2015
2044
|
meta: {
|
|
2016
2045
|
type: "problem",
|
|
@@ -2028,7 +2057,7 @@ var nextjsRequirePublicEnv = createRule26({
|
|
|
2028
2057
|
return {
|
|
2029
2058
|
Program(node) {
|
|
2030
2059
|
const firstStatement = node.body[0];
|
|
2031
|
-
if (firstStatement?.type ===
|
|
2060
|
+
if (firstStatement?.type === AST_NODE_TYPES26.ExpressionStatement && firstStatement.expression.type === AST_NODE_TYPES26.Literal && firstStatement.expression.value === "use client") {
|
|
2032
2061
|
isClientComponent = true;
|
|
2033
2062
|
}
|
|
2034
2063
|
},
|
|
@@ -2036,7 +2065,7 @@ var nextjsRequirePublicEnv = createRule26({
|
|
|
2036
2065
|
if (!isClientComponent) {
|
|
2037
2066
|
return;
|
|
2038
2067
|
}
|
|
2039
|
-
if (node.object.type ===
|
|
2068
|
+
if (node.object.type === AST_NODE_TYPES26.MemberExpression && node.object.object.type === AST_NODE_TYPES26.Identifier && node.object.object.name === "process" && node.object.property.type === AST_NODE_TYPES26.Identifier && node.object.property.name === "env" && node.property.type === AST_NODE_TYPES26.Identifier) {
|
|
2040
2069
|
const envVarName = node.property.name;
|
|
2041
2070
|
if (!envVarName.startsWith("NEXT_PUBLIC_") && envVarName !== "NODE_ENV") {
|
|
2042
2071
|
context.report({
|
|
@@ -2055,11 +2084,11 @@ var nextjsRequirePublicEnv = createRule26({
|
|
|
2055
2084
|
var nextjs_require_public_env_default = nextjsRequirePublicEnv;
|
|
2056
2085
|
|
|
2057
2086
|
// src/rules/no-complex-inline-return.ts
|
|
2058
|
-
import { AST_NODE_TYPES as
|
|
2059
|
-
var
|
|
2087
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27, ESLintUtils as ESLintUtils28 } from "@typescript-eslint/utils";
|
|
2088
|
+
var createRule28 = ESLintUtils28.RuleCreator(
|
|
2060
2089
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2061
2090
|
);
|
|
2062
|
-
var noComplexInlineReturn =
|
|
2091
|
+
var noComplexInlineReturn = createRule28({
|
|
2063
2092
|
name: "no-complex-inline-return",
|
|
2064
2093
|
meta: {
|
|
2065
2094
|
type: "suggestion",
|
|
@@ -2075,13 +2104,13 @@ var noComplexInlineReturn = createRule27({
|
|
|
2075
2104
|
create(context) {
|
|
2076
2105
|
const isComplexExpression = (node) => {
|
|
2077
2106
|
if (!node) return false;
|
|
2078
|
-
if (node.type ===
|
|
2107
|
+
if (node.type === AST_NODE_TYPES27.ConditionalExpression) {
|
|
2079
2108
|
return true;
|
|
2080
2109
|
}
|
|
2081
|
-
if (node.type ===
|
|
2110
|
+
if (node.type === AST_NODE_TYPES27.LogicalExpression) {
|
|
2082
2111
|
return true;
|
|
2083
2112
|
}
|
|
2084
|
-
if (node.type ===
|
|
2113
|
+
if (node.type === AST_NODE_TYPES27.NewExpression) {
|
|
2085
2114
|
return true;
|
|
2086
2115
|
}
|
|
2087
2116
|
return false;
|
|
@@ -2101,11 +2130,11 @@ var noComplexInlineReturn = createRule27({
|
|
|
2101
2130
|
var no_complex_inline_return_default = noComplexInlineReturn;
|
|
2102
2131
|
|
|
2103
2132
|
// src/rules/no-direct-date.ts
|
|
2104
|
-
import { AST_NODE_TYPES as
|
|
2105
|
-
var
|
|
2133
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28, ESLintUtils as ESLintUtils29 } from "@typescript-eslint/utils";
|
|
2134
|
+
var createRule29 = ESLintUtils29.RuleCreator(
|
|
2106
2135
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2107
2136
|
);
|
|
2108
|
-
var noDirectDate =
|
|
2137
|
+
var noDirectDate = createRule29({
|
|
2109
2138
|
name: "no-direct-date",
|
|
2110
2139
|
meta: {
|
|
2111
2140
|
type: "problem",
|
|
@@ -2123,7 +2152,7 @@ var noDirectDate = createRule28({
|
|
|
2123
2152
|
create(context) {
|
|
2124
2153
|
return {
|
|
2125
2154
|
NewExpression(node) {
|
|
2126
|
-
if (node.callee.type ===
|
|
2155
|
+
if (node.callee.type === AST_NODE_TYPES28.Identifier && node.callee.name === "Date") {
|
|
2127
2156
|
context.report({
|
|
2128
2157
|
node,
|
|
2129
2158
|
messageId: "noNewDate"
|
|
@@ -2131,7 +2160,7 @@ var noDirectDate = createRule28({
|
|
|
2131
2160
|
}
|
|
2132
2161
|
},
|
|
2133
2162
|
CallExpression(node) {
|
|
2134
|
-
if (node.callee.type ===
|
|
2163
|
+
if (node.callee.type === AST_NODE_TYPES28.MemberExpression && node.callee.object.type === AST_NODE_TYPES28.Identifier && node.callee.object.name === "Date" && node.callee.property.type === AST_NODE_TYPES28.Identifier) {
|
|
2135
2164
|
const methodName = node.callee.property.name;
|
|
2136
2165
|
if (methodName === "now") {
|
|
2137
2166
|
context.report({
|
|
@@ -2154,11 +2183,11 @@ var no_direct_date_default = noDirectDate;
|
|
|
2154
2183
|
|
|
2155
2184
|
// src/rules/no-emoji.ts
|
|
2156
2185
|
import emojiRegex from "emoji-regex";
|
|
2157
|
-
import { ESLintUtils as
|
|
2158
|
-
var
|
|
2186
|
+
import { ESLintUtils as ESLintUtils30 } from "@typescript-eslint/utils";
|
|
2187
|
+
var createRule30 = ESLintUtils30.RuleCreator(
|
|
2159
2188
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2160
2189
|
);
|
|
2161
|
-
var noEmoji =
|
|
2190
|
+
var noEmoji = createRule30({
|
|
2162
2191
|
name: "no-emoji",
|
|
2163
2192
|
meta: {
|
|
2164
2193
|
type: "problem",
|
|
@@ -2192,11 +2221,11 @@ var noEmoji = createRule29({
|
|
|
2192
2221
|
var no_emoji_default = noEmoji;
|
|
2193
2222
|
|
|
2194
2223
|
// src/rules/no-env-fallback.ts
|
|
2195
|
-
import { AST_NODE_TYPES as
|
|
2196
|
-
var
|
|
2224
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29, ESLintUtils as ESLintUtils31 } from "@typescript-eslint/utils";
|
|
2225
|
+
var createRule31 = ESLintUtils31.RuleCreator(
|
|
2197
2226
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2198
2227
|
);
|
|
2199
|
-
var noEnvFallback =
|
|
2228
|
+
var noEnvFallback = createRule31({
|
|
2200
2229
|
name: "no-env-fallback",
|
|
2201
2230
|
meta: {
|
|
2202
2231
|
type: "problem",
|
|
@@ -2211,16 +2240,16 @@ var noEnvFallback = createRule30({
|
|
|
2211
2240
|
defaultOptions: [],
|
|
2212
2241
|
create(context) {
|
|
2213
2242
|
const isProcessEnvAccess = (node) => {
|
|
2214
|
-
if (node.type !==
|
|
2243
|
+
if (node.type !== AST_NODE_TYPES29.MemberExpression) {
|
|
2215
2244
|
return false;
|
|
2216
2245
|
}
|
|
2217
2246
|
const { object } = node;
|
|
2218
|
-
if (object.type !==
|
|
2247
|
+
if (object.type !== AST_NODE_TYPES29.MemberExpression) {
|
|
2219
2248
|
return false;
|
|
2220
2249
|
}
|
|
2221
2250
|
const processNode = object.object;
|
|
2222
2251
|
const envNode = object.property;
|
|
2223
|
-
return processNode.type ===
|
|
2252
|
+
return processNode.type === AST_NODE_TYPES29.Identifier && processNode.name === "process" && envNode.type === AST_NODE_TYPES29.Identifier && envNode.name === "env";
|
|
2224
2253
|
};
|
|
2225
2254
|
return {
|
|
2226
2255
|
LogicalExpression(node) {
|
|
@@ -2245,11 +2274,11 @@ var noEnvFallback = createRule30({
|
|
|
2245
2274
|
var no_env_fallback_default = noEnvFallback;
|
|
2246
2275
|
|
|
2247
2276
|
// src/rules/no-inline-default-export.ts
|
|
2248
|
-
import { AST_NODE_TYPES as
|
|
2249
|
-
var
|
|
2277
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30, ESLintUtils as ESLintUtils32 } from "@typescript-eslint/utils";
|
|
2278
|
+
var createRule32 = ESLintUtils32.RuleCreator(
|
|
2250
2279
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2251
2280
|
);
|
|
2252
|
-
var noInlineDefaultExport =
|
|
2281
|
+
var noInlineDefaultExport = createRule32({
|
|
2253
2282
|
name: "no-inline-default-export",
|
|
2254
2283
|
meta: {
|
|
2255
2284
|
type: "suggestion",
|
|
@@ -2268,7 +2297,7 @@ var noInlineDefaultExport = createRule31({
|
|
|
2268
2297
|
return {
|
|
2269
2298
|
ExportDefaultDeclaration(node) {
|
|
2270
2299
|
const { declaration } = node;
|
|
2271
|
-
if (declaration.type ===
|
|
2300
|
+
if (declaration.type === AST_NODE_TYPES30.FunctionDeclaration) {
|
|
2272
2301
|
if (declaration.id) {
|
|
2273
2302
|
context.report({
|
|
2274
2303
|
node,
|
|
@@ -2283,7 +2312,7 @@ var noInlineDefaultExport = createRule31({
|
|
|
2283
2312
|
});
|
|
2284
2313
|
}
|
|
2285
2314
|
}
|
|
2286
|
-
if (declaration.type ===
|
|
2315
|
+
if (declaration.type === AST_NODE_TYPES30.ClassDeclaration) {
|
|
2287
2316
|
if (declaration.id) {
|
|
2288
2317
|
context.report({
|
|
2289
2318
|
node,
|
|
@@ -2298,7 +2327,7 @@ var noInlineDefaultExport = createRule31({
|
|
|
2298
2327
|
});
|
|
2299
2328
|
}
|
|
2300
2329
|
}
|
|
2301
|
-
if (declaration.type ===
|
|
2330
|
+
if (declaration.type === AST_NODE_TYPES30.ArrowFunctionExpression || declaration.type === AST_NODE_TYPES30.FunctionExpression) {
|
|
2302
2331
|
context.report({
|
|
2303
2332
|
node,
|
|
2304
2333
|
messageId: "noAnonymousDefaultExport",
|
|
@@ -2311,14 +2340,14 @@ var noInlineDefaultExport = createRule31({
|
|
|
2311
2340
|
if (!declaration) {
|
|
2312
2341
|
return;
|
|
2313
2342
|
}
|
|
2314
|
-
if (declaration.type ===
|
|
2343
|
+
if (declaration.type === AST_NODE_TYPES30.FunctionDeclaration && declaration.id) {
|
|
2315
2344
|
context.report({
|
|
2316
2345
|
node,
|
|
2317
2346
|
messageId: "noInlineNamedExport",
|
|
2318
2347
|
data: { type: "function", name: declaration.id.name }
|
|
2319
2348
|
});
|
|
2320
2349
|
}
|
|
2321
|
-
if (declaration.type ===
|
|
2350
|
+
if (declaration.type === AST_NODE_TYPES30.ClassDeclaration && declaration.id) {
|
|
2322
2351
|
context.report({
|
|
2323
2352
|
node,
|
|
2324
2353
|
messageId: "noInlineNamedExport",
|
|
@@ -2332,15 +2361,15 @@ var noInlineDefaultExport = createRule31({
|
|
|
2332
2361
|
var no_inline_default_export_default = noInlineDefaultExport;
|
|
2333
2362
|
|
|
2334
2363
|
// src/rules/no-inline-nested-object.ts
|
|
2335
|
-
import { AST_NODE_TYPES as
|
|
2336
|
-
var
|
|
2364
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31, ESLintUtils as ESLintUtils33 } from "@typescript-eslint/utils";
|
|
2365
|
+
var createRule33 = ESLintUtils33.RuleCreator(
|
|
2337
2366
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2338
2367
|
);
|
|
2339
2368
|
function isObjectOrArray(node) {
|
|
2340
|
-
return node.type ===
|
|
2369
|
+
return node.type === AST_NODE_TYPES31.ObjectExpression || node.type === AST_NODE_TYPES31.ArrayExpression || node.type === AST_NODE_TYPES31.TSAsExpression;
|
|
2341
2370
|
}
|
|
2342
2371
|
function getInnerExpression(node) {
|
|
2343
|
-
if (node.type ===
|
|
2372
|
+
if (node.type === AST_NODE_TYPES31.TSAsExpression) {
|
|
2344
2373
|
return getInnerExpression(node.expression);
|
|
2345
2374
|
}
|
|
2346
2375
|
return node;
|
|
@@ -2349,10 +2378,10 @@ function arrayContainsOnlyPrimitives(node) {
|
|
|
2349
2378
|
return node.elements.every((el) => {
|
|
2350
2379
|
if (el === null) return true;
|
|
2351
2380
|
const inner = getInnerExpression(el);
|
|
2352
|
-
return inner.type ===
|
|
2381
|
+
return inner.type === AST_NODE_TYPES31.Literal || inner.type === AST_NODE_TYPES31.Identifier || inner.type === AST_NODE_TYPES31.TemplateLiteral || inner.type === AST_NODE_TYPES31.UnaryExpression;
|
|
2353
2382
|
});
|
|
2354
2383
|
}
|
|
2355
|
-
var noInlineNestedObject =
|
|
2384
|
+
var noInlineNestedObject = createRule33({
|
|
2356
2385
|
name: "no-inline-nested-object",
|
|
2357
2386
|
meta: {
|
|
2358
2387
|
type: "layout",
|
|
@@ -2374,17 +2403,17 @@ var noInlineNestedObject = createRule32({
|
|
|
2374
2403
|
return;
|
|
2375
2404
|
}
|
|
2376
2405
|
const valueNode = getInnerExpression(node.value);
|
|
2377
|
-
if (valueNode.type !==
|
|
2406
|
+
if (valueNode.type !== AST_NODE_TYPES31.ObjectExpression && valueNode.type !== AST_NODE_TYPES31.ArrayExpression) {
|
|
2378
2407
|
return;
|
|
2379
2408
|
}
|
|
2380
2409
|
if (!valueNode.loc) {
|
|
2381
2410
|
return;
|
|
2382
2411
|
}
|
|
2383
|
-
const elements = valueNode.type ===
|
|
2412
|
+
const elements = valueNode.type === AST_NODE_TYPES31.ObjectExpression ? valueNode.properties : valueNode.elements;
|
|
2384
2413
|
if (elements.length <= 1) {
|
|
2385
2414
|
return;
|
|
2386
2415
|
}
|
|
2387
|
-
if (valueNode.type ===
|
|
2416
|
+
if (valueNode.type === AST_NODE_TYPES31.ArrayExpression && arrayContainsOnlyPrimitives(valueNode)) {
|
|
2388
2417
|
return;
|
|
2389
2418
|
}
|
|
2390
2419
|
const isMultiline = valueNode.loc.start.line !== valueNode.loc.end.line;
|
|
@@ -2403,7 +2432,7 @@ var noInlineNestedObject = createRule32({
|
|
|
2403
2432
|
const indent = " ".repeat(node.loc?.start.column ?? 0);
|
|
2404
2433
|
const innerIndent = `${indent} `;
|
|
2405
2434
|
const elementTexts = elements.filter((el) => el !== null).map((el) => sourceCode.getText(el));
|
|
2406
|
-
const isObject = valueNode.type ===
|
|
2435
|
+
const isObject = valueNode.type === AST_NODE_TYPES31.ObjectExpression;
|
|
2407
2436
|
const openChar = isObject ? "{" : "[";
|
|
2408
2437
|
const closeChar = isObject ? "}" : "]";
|
|
2409
2438
|
const formattedElements = elementTexts.map((text) => `${innerIndent}${text},`).join("\n");
|
|
@@ -2420,20 +2449,20 @@ ${indent}${closeChar}`;
|
|
|
2420
2449
|
var no_inline_nested_object_default = noInlineNestedObject;
|
|
2421
2450
|
|
|
2422
2451
|
// src/rules/no-inline-return-properties.ts
|
|
2423
|
-
import { AST_NODE_TYPES as
|
|
2424
|
-
var
|
|
2452
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32, ESLintUtils as ESLintUtils34 } from "@typescript-eslint/utils";
|
|
2453
|
+
var createRule34 = ESLintUtils34.RuleCreator(
|
|
2425
2454
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2426
2455
|
);
|
|
2427
2456
|
var isShorthandProperty = (property) => {
|
|
2428
|
-
if (property.type ===
|
|
2457
|
+
if (property.type === AST_NODE_TYPES32.SpreadElement) {
|
|
2429
2458
|
return true;
|
|
2430
2459
|
}
|
|
2431
|
-
if (property.type !==
|
|
2460
|
+
if (property.type !== AST_NODE_TYPES32.Property) {
|
|
2432
2461
|
return false;
|
|
2433
2462
|
}
|
|
2434
2463
|
return property.shorthand;
|
|
2435
2464
|
};
|
|
2436
|
-
var noInlineReturnProperties =
|
|
2465
|
+
var noInlineReturnProperties = createRule34({
|
|
2437
2466
|
name: "no-inline-return-properties",
|
|
2438
2467
|
meta: {
|
|
2439
2468
|
type: "suggestion",
|
|
@@ -2449,20 +2478,20 @@ var noInlineReturnProperties = createRule33({
|
|
|
2449
2478
|
create(context) {
|
|
2450
2479
|
return {
|
|
2451
2480
|
ReturnStatement(node) {
|
|
2452
|
-
if (!node.argument || node.argument.type !==
|
|
2481
|
+
if (!node.argument || node.argument.type !== AST_NODE_TYPES32.ObjectExpression) {
|
|
2453
2482
|
return;
|
|
2454
2483
|
}
|
|
2455
2484
|
node.argument.properties.forEach((property) => {
|
|
2456
2485
|
if (isShorthandProperty(property)) {
|
|
2457
2486
|
return;
|
|
2458
2487
|
}
|
|
2459
|
-
if (property.type !==
|
|
2488
|
+
if (property.type !== AST_NODE_TYPES32.Property) {
|
|
2460
2489
|
return;
|
|
2461
2490
|
}
|
|
2462
2491
|
let keyName = null;
|
|
2463
|
-
if (property.key.type ===
|
|
2492
|
+
if (property.key.type === AST_NODE_TYPES32.Identifier) {
|
|
2464
2493
|
keyName = property.key.name;
|
|
2465
|
-
} else if (property.key.type ===
|
|
2494
|
+
} else if (property.key.type === AST_NODE_TYPES32.Literal) {
|
|
2466
2495
|
keyName = String(property.key.value);
|
|
2467
2496
|
}
|
|
2468
2497
|
context.report({
|
|
@@ -2477,9 +2506,83 @@ var noInlineReturnProperties = createRule33({
|
|
|
2477
2506
|
});
|
|
2478
2507
|
var no_inline_return_properties_default = noInlineReturnProperties;
|
|
2479
2508
|
|
|
2509
|
+
// src/rules/no-inline-type-import.ts
|
|
2510
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33, ESLintUtils as ESLintUtils35 } from "@typescript-eslint/utils";
|
|
2511
|
+
var createRule35 = ESLintUtils35.RuleCreator(
|
|
2512
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2513
|
+
);
|
|
2514
|
+
var isInlineTypeSpecifier = (specifier) => specifier.type === AST_NODE_TYPES33.ImportSpecifier && specifier.importKind === "type";
|
|
2515
|
+
var noInlineTypeImport = createRule35({
|
|
2516
|
+
name: "no-inline-type-import",
|
|
2517
|
+
meta: {
|
|
2518
|
+
type: "suggestion",
|
|
2519
|
+
docs: {
|
|
2520
|
+
description: "Disallow inline 'type' markers on import specifiers. Use 'import type' or split into a separate type-only import statement."
|
|
2521
|
+
},
|
|
2522
|
+
fixable: "code",
|
|
2523
|
+
messages: {
|
|
2524
|
+
noInlineTypeImport: "Avoid inline 'type' markers on import specifiers. Hoist to 'import type' or split into a separate type-only import statement."
|
|
2525
|
+
},
|
|
2526
|
+
schema: []
|
|
2527
|
+
},
|
|
2528
|
+
defaultOptions: [],
|
|
2529
|
+
create(context) {
|
|
2530
|
+
return {
|
|
2531
|
+
ImportDeclaration(node) {
|
|
2532
|
+
const inlineTypeSpecifiers = node.specifiers.filter(isInlineTypeSpecifier);
|
|
2533
|
+
if (inlineTypeSpecifiers.length === 0) {
|
|
2534
|
+
return;
|
|
2535
|
+
}
|
|
2536
|
+
context.report({
|
|
2537
|
+
node,
|
|
2538
|
+
messageId: "noInlineTypeImport",
|
|
2539
|
+
fix(fixer) {
|
|
2540
|
+
if (node.importKind === "type") {
|
|
2541
|
+
return inlineTypeSpecifiers.map(
|
|
2542
|
+
(specifier) => fixer.removeRange([specifier.range[0], specifier.imported.range[0]])
|
|
2543
|
+
);
|
|
2544
|
+
}
|
|
2545
|
+
const sourceText = context.sourceCode.getText(node.source);
|
|
2546
|
+
const fileText = context.sourceCode.text;
|
|
2547
|
+
const typeSpecifierTexts = inlineTypeSpecifiers.map(
|
|
2548
|
+
(specifier) => fileText.slice(specifier.imported.range[0], specifier.range[1])
|
|
2549
|
+
);
|
|
2550
|
+
const typeImport = `import type { ${typeSpecifierTexts.join(", ")} } from ${sourceText};`;
|
|
2551
|
+
const valueSpecifiers = node.specifiers.filter(
|
|
2552
|
+
(specifier) => !(specifier.type === AST_NODE_TYPES33.ImportSpecifier && specifier.importKind === "type")
|
|
2553
|
+
);
|
|
2554
|
+
if (valueSpecifiers.length === 0) {
|
|
2555
|
+
return fixer.replaceText(node, typeImport);
|
|
2556
|
+
}
|
|
2557
|
+
const parts = [];
|
|
2558
|
+
const namedValueSpecifiers = [];
|
|
2559
|
+
for (const specifier of valueSpecifiers) {
|
|
2560
|
+
if (specifier.type === AST_NODE_TYPES33.ImportDefaultSpecifier) {
|
|
2561
|
+
parts.push(specifier.local.name);
|
|
2562
|
+
} else if (specifier.type === AST_NODE_TYPES33.ImportNamespaceSpecifier) {
|
|
2563
|
+
parts.push(`* as ${specifier.local.name}`);
|
|
2564
|
+
} else if (specifier.type === AST_NODE_TYPES33.ImportSpecifier) {
|
|
2565
|
+
namedValueSpecifiers.push(specifier);
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
if (namedValueSpecifiers.length > 0) {
|
|
2569
|
+
const namedTexts = namedValueSpecifiers.map((specifier) => context.sourceCode.getText(specifier));
|
|
2570
|
+
parts.push(`{ ${namedTexts.join(", ")} }`);
|
|
2571
|
+
}
|
|
2572
|
+
const valueImport = `import ${parts.join(", ")} from ${sourceText};`;
|
|
2573
|
+
return fixer.replaceText(node, `${valueImport}
|
|
2574
|
+
${typeImport}`);
|
|
2575
|
+
}
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
});
|
|
2581
|
+
var no_inline_type_import_default = noInlineTypeImport;
|
|
2582
|
+
|
|
2480
2583
|
// src/rules/no-lazy-identifiers.ts
|
|
2481
|
-
import { AST_NODE_TYPES as
|
|
2482
|
-
var
|
|
2584
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34, ESLintUtils as ESLintUtils36 } from "@typescript-eslint/utils";
|
|
2585
|
+
var createRule36 = ESLintUtils36.RuleCreator(
|
|
2483
2586
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2484
2587
|
);
|
|
2485
2588
|
var KEYBOARD_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm", "1234567890"];
|
|
@@ -2520,7 +2623,7 @@ var isLazyIdentifier = (name) => {
|
|
|
2520
2623
|
}
|
|
2521
2624
|
return false;
|
|
2522
2625
|
};
|
|
2523
|
-
var noLazyIdentifiers =
|
|
2626
|
+
var noLazyIdentifiers = createRule36({
|
|
2524
2627
|
name: "no-lazy-identifiers",
|
|
2525
2628
|
meta: {
|
|
2526
2629
|
type: "problem",
|
|
@@ -2546,27 +2649,27 @@ var noLazyIdentifiers = createRule34({
|
|
|
2546
2649
|
});
|
|
2547
2650
|
};
|
|
2548
2651
|
const checkPattern = (pattern) => {
|
|
2549
|
-
if (pattern.type ===
|
|
2652
|
+
if (pattern.type === AST_NODE_TYPES34.Identifier) {
|
|
2550
2653
|
checkIdentifier(pattern);
|
|
2551
|
-
} else if (pattern.type ===
|
|
2654
|
+
} else if (pattern.type === AST_NODE_TYPES34.ObjectPattern) {
|
|
2552
2655
|
pattern.properties.forEach((prop) => {
|
|
2553
|
-
if (prop.type ===
|
|
2656
|
+
if (prop.type === AST_NODE_TYPES34.Property && prop.value.type === AST_NODE_TYPES34.Identifier) {
|
|
2554
2657
|
checkIdentifier(prop.value);
|
|
2555
|
-
} else if (prop.type ===
|
|
2658
|
+
} else if (prop.type === AST_NODE_TYPES34.RestElement && prop.argument.type === AST_NODE_TYPES34.Identifier) {
|
|
2556
2659
|
checkIdentifier(prop.argument);
|
|
2557
2660
|
}
|
|
2558
2661
|
});
|
|
2559
|
-
} else if (pattern.type ===
|
|
2662
|
+
} else if (pattern.type === AST_NODE_TYPES34.ArrayPattern) {
|
|
2560
2663
|
pattern.elements.forEach((element) => {
|
|
2561
|
-
if (element?.type ===
|
|
2664
|
+
if (element?.type === AST_NODE_TYPES34.Identifier) {
|
|
2562
2665
|
checkIdentifier(element);
|
|
2563
|
-
} else if (element?.type ===
|
|
2666
|
+
} else if (element?.type === AST_NODE_TYPES34.RestElement && element.argument.type === AST_NODE_TYPES34.Identifier) {
|
|
2564
2667
|
checkIdentifier(element.argument);
|
|
2565
2668
|
}
|
|
2566
2669
|
});
|
|
2567
|
-
} else if (pattern.type ===
|
|
2670
|
+
} else if (pattern.type === AST_NODE_TYPES34.AssignmentPattern && pattern.left.type === AST_NODE_TYPES34.Identifier) {
|
|
2568
2671
|
checkIdentifier(pattern.left);
|
|
2569
|
-
} else if (pattern.type ===
|
|
2672
|
+
} else if (pattern.type === AST_NODE_TYPES34.RestElement && pattern.argument.type === AST_NODE_TYPES34.Identifier) {
|
|
2570
2673
|
checkIdentifier(pattern.argument);
|
|
2571
2674
|
}
|
|
2572
2675
|
};
|
|
@@ -2611,11 +2714,11 @@ var noLazyIdentifiers = createRule34({
|
|
|
2611
2714
|
var no_lazy_identifiers_default = noLazyIdentifiers;
|
|
2612
2715
|
|
|
2613
2716
|
// src/rules/no-logic-in-params.ts
|
|
2614
|
-
import { AST_NODE_TYPES as
|
|
2615
|
-
var
|
|
2717
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35, ESLintUtils as ESLintUtils37 } from "@typescript-eslint/utils";
|
|
2718
|
+
var createRule37 = ESLintUtils37.RuleCreator(
|
|
2616
2719
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2617
2720
|
);
|
|
2618
|
-
var noLogicInParams =
|
|
2721
|
+
var noLogicInParams = createRule37({
|
|
2619
2722
|
name: "no-logic-in-params",
|
|
2620
2723
|
meta: {
|
|
2621
2724
|
type: "suggestion",
|
|
@@ -2630,20 +2733,20 @@ var noLogicInParams = createRule35({
|
|
|
2630
2733
|
defaultOptions: [],
|
|
2631
2734
|
create(context) {
|
|
2632
2735
|
const isComplexExpression = (node) => {
|
|
2633
|
-
if (node.type ===
|
|
2736
|
+
if (node.type === AST_NODE_TYPES35.SpreadElement) {
|
|
2634
2737
|
return false;
|
|
2635
2738
|
}
|
|
2636
|
-
if (node.type ===
|
|
2739
|
+
if (node.type === AST_NODE_TYPES35.ConditionalExpression) {
|
|
2637
2740
|
return true;
|
|
2638
2741
|
}
|
|
2639
|
-
if (node.type ===
|
|
2742
|
+
if (node.type === AST_NODE_TYPES35.LogicalExpression) {
|
|
2640
2743
|
return true;
|
|
2641
2744
|
}
|
|
2642
|
-
if (node.type ===
|
|
2745
|
+
if (node.type === AST_NODE_TYPES35.BinaryExpression) {
|
|
2643
2746
|
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
2644
2747
|
return logicalOperators.includes(node.operator);
|
|
2645
2748
|
}
|
|
2646
|
-
if (node.type ===
|
|
2749
|
+
if (node.type === AST_NODE_TYPES35.UnaryExpression) {
|
|
2647
2750
|
return node.operator === "!";
|
|
2648
2751
|
}
|
|
2649
2752
|
return false;
|
|
@@ -2656,7 +2759,7 @@ var noLogicInParams = createRule35({
|
|
|
2656
2759
|
messageId: "noLogicInParams"
|
|
2657
2760
|
});
|
|
2658
2761
|
}
|
|
2659
|
-
if (arg.type ===
|
|
2762
|
+
if (arg.type === AST_NODE_TYPES35.ArrayExpression) {
|
|
2660
2763
|
arg.elements.forEach((element) => {
|
|
2661
2764
|
if (element && isComplexExpression(element)) {
|
|
2662
2765
|
context.report({
|
|
@@ -2681,46 +2784,46 @@ var noLogicInParams = createRule35({
|
|
|
2681
2784
|
var no_logic_in_params_default = noLogicInParams;
|
|
2682
2785
|
|
|
2683
2786
|
// src/rules/no-misleading-constant-case.ts
|
|
2684
|
-
import { AST_NODE_TYPES as
|
|
2685
|
-
var
|
|
2787
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36, ESLintUtils as ESLintUtils38 } from "@typescript-eslint/utils";
|
|
2788
|
+
var createRule38 = ESLintUtils38.RuleCreator(
|
|
2686
2789
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2687
2790
|
);
|
|
2688
2791
|
var SCREAMING_SNAKE_CASE_REGEX3 = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
2689
|
-
var
|
|
2690
|
-
var
|
|
2691
|
-
if (
|
|
2792
|
+
var isAsConstAssertion = (node) => node.type === AST_NODE_TYPES36.TSAsExpression && node.typeAnnotation.type === AST_NODE_TYPES36.TSTypeReference && node.typeAnnotation.typeName.type === AST_NODE_TYPES36.Identifier && node.typeAnnotation.typeName.name === "const";
|
|
2793
|
+
var isStaticValue2 = (init) => {
|
|
2794
|
+
if (isAsConstAssertion(init)) {
|
|
2692
2795
|
return true;
|
|
2693
2796
|
}
|
|
2694
|
-
if (init.type ===
|
|
2797
|
+
if (init.type === AST_NODE_TYPES36.Literal) {
|
|
2695
2798
|
return true;
|
|
2696
2799
|
}
|
|
2697
|
-
if (init.type ===
|
|
2800
|
+
if (init.type === AST_NODE_TYPES36.UnaryExpression && init.argument.type === AST_NODE_TYPES36.Literal) {
|
|
2698
2801
|
return true;
|
|
2699
2802
|
}
|
|
2700
|
-
if (init.type ===
|
|
2803
|
+
if (init.type === AST_NODE_TYPES36.TemplateLiteral && init.expressions.length === 0) {
|
|
2701
2804
|
return true;
|
|
2702
2805
|
}
|
|
2703
|
-
if (init.type ===
|
|
2704
|
-
return init.elements.every((el) => el !== null && el.type !==
|
|
2806
|
+
if (init.type === AST_NODE_TYPES36.ArrayExpression) {
|
|
2807
|
+
return init.elements.every((el) => el !== null && el.type !== AST_NODE_TYPES36.SpreadElement && isStaticValue2(el));
|
|
2705
2808
|
}
|
|
2706
|
-
if (init.type ===
|
|
2809
|
+
if (init.type === AST_NODE_TYPES36.ObjectExpression) {
|
|
2707
2810
|
return init.properties.every(
|
|
2708
|
-
(prop) => prop.type ===
|
|
2811
|
+
(prop) => prop.type === AST_NODE_TYPES36.Property && isStaticValue2(prop.value)
|
|
2709
2812
|
);
|
|
2710
2813
|
}
|
|
2711
2814
|
return false;
|
|
2712
2815
|
};
|
|
2713
2816
|
var isGlobalScope3 = (node) => {
|
|
2714
2817
|
const { parent } = node;
|
|
2715
|
-
if (parent.type ===
|
|
2818
|
+
if (parent.type === AST_NODE_TYPES36.Program) {
|
|
2716
2819
|
return true;
|
|
2717
2820
|
}
|
|
2718
|
-
if (parent.type ===
|
|
2821
|
+
if (parent.type === AST_NODE_TYPES36.ExportNamedDeclaration && parent.parent?.type === AST_NODE_TYPES36.Program) {
|
|
2719
2822
|
return true;
|
|
2720
2823
|
}
|
|
2721
2824
|
return false;
|
|
2722
2825
|
};
|
|
2723
|
-
var noMisleadingConstantCase =
|
|
2826
|
+
var noMisleadingConstantCase = createRule38({
|
|
2724
2827
|
name: "no-misleading-constant-case",
|
|
2725
2828
|
meta: {
|
|
2726
2829
|
type: "suggestion",
|
|
@@ -2739,7 +2842,7 @@ var noMisleadingConstantCase = createRule36({
|
|
|
2739
2842
|
return {
|
|
2740
2843
|
VariableDeclaration(node) {
|
|
2741
2844
|
node.declarations.forEach((declarator) => {
|
|
2742
|
-
if (declarator.id.type !==
|
|
2845
|
+
if (declarator.id.type !== AST_NODE_TYPES36.Identifier) {
|
|
2743
2846
|
return;
|
|
2744
2847
|
}
|
|
2745
2848
|
const { name } = declarator.id;
|
|
@@ -2765,7 +2868,7 @@ var noMisleadingConstantCase = createRule36({
|
|
|
2765
2868
|
if (!declarator.init) {
|
|
2766
2869
|
return;
|
|
2767
2870
|
}
|
|
2768
|
-
if (!
|
|
2871
|
+
if (!isStaticValue2(declarator.init)) {
|
|
2769
2872
|
context.report({
|
|
2770
2873
|
node: declarator.id,
|
|
2771
2874
|
messageId: "dynamicScreamingCase",
|
|
@@ -2780,11 +2883,11 @@ var noMisleadingConstantCase = createRule36({
|
|
|
2780
2883
|
var no_misleading_constant_case_default = noMisleadingConstantCase;
|
|
2781
2884
|
|
|
2782
2885
|
// src/rules/no-nested-interface-declaration.ts
|
|
2783
|
-
import { AST_NODE_TYPES as
|
|
2784
|
-
var
|
|
2886
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37, ESLintUtils as ESLintUtils39 } from "@typescript-eslint/utils";
|
|
2887
|
+
var createRule39 = ESLintUtils39.RuleCreator(
|
|
2785
2888
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2786
2889
|
);
|
|
2787
|
-
var noNestedInterfaceDeclaration =
|
|
2890
|
+
var noNestedInterfaceDeclaration = createRule39({
|
|
2788
2891
|
name: "no-nested-interface-declaration",
|
|
2789
2892
|
meta: {
|
|
2790
2893
|
type: "suggestion",
|
|
@@ -2805,15 +2908,15 @@ var noNestedInterfaceDeclaration = createRule37({
|
|
|
2805
2908
|
return;
|
|
2806
2909
|
}
|
|
2807
2910
|
const { typeAnnotation } = node.typeAnnotation;
|
|
2808
|
-
if (typeAnnotation.type ===
|
|
2911
|
+
if (typeAnnotation.type === AST_NODE_TYPES37.TSTypeLiteral) {
|
|
2809
2912
|
context.report({
|
|
2810
2913
|
node: typeAnnotation,
|
|
2811
2914
|
messageId: "noNestedInterface"
|
|
2812
2915
|
});
|
|
2813
2916
|
return;
|
|
2814
2917
|
}
|
|
2815
|
-
if (typeAnnotation.type ===
|
|
2816
|
-
if (typeAnnotation.elementType.type ===
|
|
2918
|
+
if (typeAnnotation.type === AST_NODE_TYPES37.TSArrayType) {
|
|
2919
|
+
if (typeAnnotation.elementType.type === AST_NODE_TYPES37.TSTypeLiteral) {
|
|
2817
2920
|
context.report({
|
|
2818
2921
|
node: typeAnnotation.elementType,
|
|
2819
2922
|
messageId: "noNestedInterface"
|
|
@@ -2821,9 +2924,9 @@ var noNestedInterfaceDeclaration = createRule37({
|
|
|
2821
2924
|
}
|
|
2822
2925
|
return;
|
|
2823
2926
|
}
|
|
2824
|
-
if (typeAnnotation.type ===
|
|
2927
|
+
if (typeAnnotation.type === AST_NODE_TYPES37.TSTypeReference && typeAnnotation.typeArguments) {
|
|
2825
2928
|
typeAnnotation.typeArguments.params.forEach((param) => {
|
|
2826
|
-
if (param.type ===
|
|
2929
|
+
if (param.type === AST_NODE_TYPES37.TSTypeLiteral) {
|
|
2827
2930
|
context.report({
|
|
2828
2931
|
node: param,
|
|
2829
2932
|
messageId: "noNestedInterface"
|
|
@@ -2838,11 +2941,11 @@ var noNestedInterfaceDeclaration = createRule37({
|
|
|
2838
2941
|
var no_nested_interface_declaration_default = noNestedInterfaceDeclaration;
|
|
2839
2942
|
|
|
2840
2943
|
// src/rules/no-nested-ternary.ts
|
|
2841
|
-
import { AST_NODE_TYPES as
|
|
2842
|
-
var
|
|
2944
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38, ESLintUtils as ESLintUtils40 } from "@typescript-eslint/utils";
|
|
2945
|
+
var createRule40 = ESLintUtils40.RuleCreator(
|
|
2843
2946
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2844
2947
|
);
|
|
2845
|
-
var noNestedTernary =
|
|
2948
|
+
var noNestedTernary = createRule40({
|
|
2846
2949
|
name: "no-nested-ternary",
|
|
2847
2950
|
meta: {
|
|
2848
2951
|
type: "suggestion",
|
|
@@ -2859,13 +2962,13 @@ var noNestedTernary = createRule38({
|
|
|
2859
2962
|
return {
|
|
2860
2963
|
ConditionalExpression(node) {
|
|
2861
2964
|
const { consequent, alternate } = node;
|
|
2862
|
-
if (consequent.type ===
|
|
2965
|
+
if (consequent.type === AST_NODE_TYPES38.ConditionalExpression) {
|
|
2863
2966
|
context.report({
|
|
2864
2967
|
node: consequent,
|
|
2865
2968
|
messageId: "noNestedTernary"
|
|
2866
2969
|
});
|
|
2867
2970
|
}
|
|
2868
|
-
if (alternate.type ===
|
|
2971
|
+
if (alternate.type === AST_NODE_TYPES38.ConditionalExpression) {
|
|
2869
2972
|
context.report({
|
|
2870
2973
|
node: alternate,
|
|
2871
2974
|
messageId: "noNestedTernary"
|
|
@@ -2878,11 +2981,11 @@ var noNestedTernary = createRule38({
|
|
|
2878
2981
|
var no_nested_ternary_default = noNestedTernary;
|
|
2879
2982
|
|
|
2880
2983
|
// src/rules/no-relative-imports.ts
|
|
2881
|
-
import { AST_NODE_TYPES as
|
|
2882
|
-
var
|
|
2984
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39, ESLintUtils as ESLintUtils41 } from "@typescript-eslint/utils";
|
|
2985
|
+
var createRule41 = ESLintUtils41.RuleCreator(
|
|
2883
2986
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2884
2987
|
);
|
|
2885
|
-
var noRelativeImports =
|
|
2988
|
+
var noRelativeImports = createRule41({
|
|
2886
2989
|
name: "no-relative-imports",
|
|
2887
2990
|
meta: {
|
|
2888
2991
|
type: "suggestion",
|
|
@@ -2906,22 +3009,22 @@ var noRelativeImports = createRule39({
|
|
|
2906
3009
|
};
|
|
2907
3010
|
return {
|
|
2908
3011
|
ImportDeclaration(node) {
|
|
2909
|
-
if (node.source.type ===
|
|
3012
|
+
if (node.source.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2910
3013
|
checkImportPath(node.source.value, node);
|
|
2911
3014
|
}
|
|
2912
3015
|
},
|
|
2913
3016
|
ImportExpression(node) {
|
|
2914
|
-
if (node.source.type ===
|
|
3017
|
+
if (node.source.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2915
3018
|
checkImportPath(node.source.value, node);
|
|
2916
3019
|
}
|
|
2917
3020
|
},
|
|
2918
3021
|
ExportNamedDeclaration(node) {
|
|
2919
|
-
if (node.source?.type ===
|
|
3022
|
+
if (node.source?.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2920
3023
|
checkImportPath(node.source.value, node);
|
|
2921
3024
|
}
|
|
2922
3025
|
},
|
|
2923
3026
|
ExportAllDeclaration(node) {
|
|
2924
|
-
if (node.source.type ===
|
|
3027
|
+
if (node.source.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2925
3028
|
checkImportPath(node.source.value, node);
|
|
2926
3029
|
}
|
|
2927
3030
|
}
|
|
@@ -2931,8 +3034,8 @@ var noRelativeImports = createRule39({
|
|
|
2931
3034
|
var no_relative_imports_default = noRelativeImports;
|
|
2932
3035
|
|
|
2933
3036
|
// src/rules/no-single-char-variables.ts
|
|
2934
|
-
import { AST_NODE_TYPES as
|
|
2935
|
-
var
|
|
3037
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40, ESLintUtils as ESLintUtils42 } from "@typescript-eslint/utils";
|
|
3038
|
+
var createRule42 = ESLintUtils42.RuleCreator(
|
|
2936
3039
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2937
3040
|
);
|
|
2938
3041
|
var ALLOWED_IN_FOR_LOOPS = /* @__PURE__ */ new Set(["i", "j", "k", "n"]);
|
|
@@ -2944,7 +3047,7 @@ var isForLoopInit = (node) => {
|
|
|
2944
3047
|
if (!parentNode) {
|
|
2945
3048
|
return false;
|
|
2946
3049
|
}
|
|
2947
|
-
if (parentNode.type ===
|
|
3050
|
+
if (parentNode.type === AST_NODE_TYPES40.ForStatement) {
|
|
2948
3051
|
const { init } = parentNode;
|
|
2949
3052
|
if (init && init === current) {
|
|
2950
3053
|
return true;
|
|
@@ -2963,7 +3066,7 @@ var isAllowedInContext = (name, node) => {
|
|
|
2963
3066
|
}
|
|
2964
3067
|
return false;
|
|
2965
3068
|
};
|
|
2966
|
-
var noSingleCharVariables =
|
|
3069
|
+
var noSingleCharVariables = createRule42({
|
|
2967
3070
|
name: "no-single-char-variables",
|
|
2968
3071
|
meta: {
|
|
2969
3072
|
type: "suggestion",
|
|
@@ -2992,27 +3095,27 @@ var noSingleCharVariables = createRule40({
|
|
|
2992
3095
|
});
|
|
2993
3096
|
};
|
|
2994
3097
|
const checkPattern = (pattern, declarationNode) => {
|
|
2995
|
-
if (pattern.type ===
|
|
3098
|
+
if (pattern.type === AST_NODE_TYPES40.Identifier) {
|
|
2996
3099
|
checkIdentifier(pattern, declarationNode);
|
|
2997
|
-
} else if (pattern.type ===
|
|
3100
|
+
} else if (pattern.type === AST_NODE_TYPES40.ObjectPattern) {
|
|
2998
3101
|
pattern.properties.forEach((prop) => {
|
|
2999
|
-
if (prop.type ===
|
|
3102
|
+
if (prop.type === AST_NODE_TYPES40.Property && prop.value.type === AST_NODE_TYPES40.Identifier) {
|
|
3000
3103
|
checkIdentifier(prop.value, declarationNode);
|
|
3001
|
-
} else if (prop.type ===
|
|
3104
|
+
} else if (prop.type === AST_NODE_TYPES40.RestElement && prop.argument.type === AST_NODE_TYPES40.Identifier) {
|
|
3002
3105
|
checkIdentifier(prop.argument, declarationNode);
|
|
3003
3106
|
}
|
|
3004
3107
|
});
|
|
3005
|
-
} else if (pattern.type ===
|
|
3108
|
+
} else if (pattern.type === AST_NODE_TYPES40.ArrayPattern) {
|
|
3006
3109
|
pattern.elements.forEach((element) => {
|
|
3007
|
-
if (element?.type ===
|
|
3110
|
+
if (element?.type === AST_NODE_TYPES40.Identifier) {
|
|
3008
3111
|
checkIdentifier(element, declarationNode);
|
|
3009
|
-
} else if (element?.type ===
|
|
3112
|
+
} else if (element?.type === AST_NODE_TYPES40.RestElement && element.argument.type === AST_NODE_TYPES40.Identifier) {
|
|
3010
3113
|
checkIdentifier(element.argument, declarationNode);
|
|
3011
3114
|
}
|
|
3012
3115
|
});
|
|
3013
|
-
} else if (pattern.type ===
|
|
3116
|
+
} else if (pattern.type === AST_NODE_TYPES40.AssignmentPattern && pattern.left.type === AST_NODE_TYPES40.Identifier) {
|
|
3014
3117
|
checkIdentifier(pattern.left, declarationNode);
|
|
3015
|
-
} else if (pattern.type ===
|
|
3118
|
+
} else if (pattern.type === AST_NODE_TYPES40.RestElement && pattern.argument.type === AST_NODE_TYPES40.Identifier) {
|
|
3016
3119
|
checkIdentifier(pattern.argument, declarationNode);
|
|
3017
3120
|
}
|
|
3018
3121
|
};
|
|
@@ -3046,11 +3149,11 @@ var noSingleCharVariables = createRule40({
|
|
|
3046
3149
|
var no_single_char_variables_default = noSingleCharVariables;
|
|
3047
3150
|
|
|
3048
3151
|
// src/rules/prefer-async-await.ts
|
|
3049
|
-
import { AST_NODE_TYPES as
|
|
3050
|
-
var
|
|
3152
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41, ESLintUtils as ESLintUtils43 } from "@typescript-eslint/utils";
|
|
3153
|
+
var createRule43 = ESLintUtils43.RuleCreator(
|
|
3051
3154
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3052
3155
|
);
|
|
3053
|
-
var preferAsyncAwait =
|
|
3156
|
+
var preferAsyncAwait = createRule43({
|
|
3054
3157
|
name: "prefer-async-await",
|
|
3055
3158
|
meta: {
|
|
3056
3159
|
type: "suggestion",
|
|
@@ -3066,7 +3169,7 @@ var preferAsyncAwait = createRule41({
|
|
|
3066
3169
|
create(context) {
|
|
3067
3170
|
return {
|
|
3068
3171
|
CallExpression(node) {
|
|
3069
|
-
if (node.callee.type ===
|
|
3172
|
+
if (node.callee.type === AST_NODE_TYPES41.MemberExpression && node.callee.property.type === AST_NODE_TYPES41.Identifier && node.callee.property.name === "then") {
|
|
3070
3173
|
context.report({
|
|
3071
3174
|
node: node.callee.property,
|
|
3072
3175
|
messageId: "preferAsyncAwait"
|
|
@@ -3079,11 +3182,11 @@ var preferAsyncAwait = createRule41({
|
|
|
3079
3182
|
var prefer_async_await_default = preferAsyncAwait;
|
|
3080
3183
|
|
|
3081
3184
|
// src/rules/prefer-destructuring-params.ts
|
|
3082
|
-
import { AST_NODE_TYPES as
|
|
3083
|
-
var
|
|
3185
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42, ESLintUtils as ESLintUtils44 } from "@typescript-eslint/utils";
|
|
3186
|
+
var createRule44 = ESLintUtils44.RuleCreator(
|
|
3084
3187
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3085
3188
|
);
|
|
3086
|
-
var preferDestructuringParams =
|
|
3189
|
+
var preferDestructuringParams = createRule44({
|
|
3087
3190
|
name: "prefer-destructuring-params",
|
|
3088
3191
|
meta: {
|
|
3089
3192
|
type: "suggestion",
|
|
@@ -3099,18 +3202,18 @@ var preferDestructuringParams = createRule42({
|
|
|
3099
3202
|
create(context) {
|
|
3100
3203
|
const isCallbackFunction2 = (node) => {
|
|
3101
3204
|
const { parent } = node;
|
|
3102
|
-
return parent?.type ===
|
|
3205
|
+
return parent?.type === AST_NODE_TYPES42.CallExpression;
|
|
3103
3206
|
};
|
|
3104
3207
|
const isDeveloperFunction = (node) => {
|
|
3105
|
-
if (node.type ===
|
|
3208
|
+
if (node.type === AST_NODE_TYPES42.FunctionDeclaration) {
|
|
3106
3209
|
return true;
|
|
3107
3210
|
}
|
|
3108
|
-
if (node.type ===
|
|
3211
|
+
if (node.type === AST_NODE_TYPES42.FunctionExpression || node.type === AST_NODE_TYPES42.ArrowFunctionExpression) {
|
|
3109
3212
|
if (isCallbackFunction2(node)) {
|
|
3110
3213
|
return false;
|
|
3111
3214
|
}
|
|
3112
3215
|
const { parent } = node;
|
|
3113
|
-
return parent?.type ===
|
|
3216
|
+
return parent?.type === AST_NODE_TYPES42.VariableDeclarator || parent?.type === AST_NODE_TYPES42.AssignmentExpression || parent?.type === AST_NODE_TYPES42.Property || parent?.type === AST_NODE_TYPES42.MethodDefinition;
|
|
3114
3217
|
}
|
|
3115
3218
|
return false;
|
|
3116
3219
|
};
|
|
@@ -3122,7 +3225,7 @@ var preferDestructuringParams = createRule42({
|
|
|
3122
3225
|
if (!isDeveloperFunction(node)) {
|
|
3123
3226
|
return;
|
|
3124
3227
|
}
|
|
3125
|
-
if (node.type ===
|
|
3228
|
+
if (node.type === AST_NODE_TYPES42.FunctionDeclaration && node.id) {
|
|
3126
3229
|
const functionName = node.id.name;
|
|
3127
3230
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
3128
3231
|
return;
|
|
@@ -3132,7 +3235,7 @@ var preferDestructuringParams = createRule42({
|
|
|
3132
3235
|
return;
|
|
3133
3236
|
}
|
|
3134
3237
|
const hasNonDestructuredParams = node.params.some(
|
|
3135
|
-
(param) => param.type !==
|
|
3238
|
+
(param) => param.type !== AST_NODE_TYPES42.ObjectPattern && param.type !== AST_NODE_TYPES42.RestElement
|
|
3136
3239
|
);
|
|
3137
3240
|
if (hasNonDestructuredParams) {
|
|
3138
3241
|
context.report({
|
|
@@ -3151,8 +3254,8 @@ var preferDestructuringParams = createRule42({
|
|
|
3151
3254
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
3152
3255
|
|
|
3153
3256
|
// src/rules/prefer-function-declaration.ts
|
|
3154
|
-
import { AST_NODE_TYPES as
|
|
3155
|
-
var
|
|
3257
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43, ESLintUtils as ESLintUtils45 } from "@typescript-eslint/utils";
|
|
3258
|
+
var createRule45 = ESLintUtils45.RuleCreator(
|
|
3156
3259
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3157
3260
|
);
|
|
3158
3261
|
var isTsFile = (filename) => filename.endsWith(".ts") && !filename.endsWith(".d.ts");
|
|
@@ -3161,33 +3264,33 @@ var isCallbackContext = (node) => {
|
|
|
3161
3264
|
if (!parent) {
|
|
3162
3265
|
return false;
|
|
3163
3266
|
}
|
|
3164
|
-
if (parent.type ===
|
|
3267
|
+
if (parent.type === AST_NODE_TYPES43.CallExpression && parent.arguments.includes(node)) {
|
|
3165
3268
|
return true;
|
|
3166
3269
|
}
|
|
3167
|
-
if (parent.type ===
|
|
3270
|
+
if (parent.type === AST_NODE_TYPES43.NewExpression && parent.arguments.includes(node)) {
|
|
3168
3271
|
return true;
|
|
3169
3272
|
}
|
|
3170
|
-
if (parent.type ===
|
|
3273
|
+
if (parent.type === AST_NODE_TYPES43.ReturnStatement) {
|
|
3171
3274
|
return true;
|
|
3172
3275
|
}
|
|
3173
|
-
if (parent.type ===
|
|
3276
|
+
if (parent.type === AST_NODE_TYPES43.Property) {
|
|
3174
3277
|
return true;
|
|
3175
3278
|
}
|
|
3176
|
-
if (parent.type ===
|
|
3279
|
+
if (parent.type === AST_NODE_TYPES43.ArrayExpression) {
|
|
3177
3280
|
return true;
|
|
3178
3281
|
}
|
|
3179
|
-
if (parent.type ===
|
|
3282
|
+
if (parent.type === AST_NODE_TYPES43.ConditionalExpression) {
|
|
3180
3283
|
return true;
|
|
3181
3284
|
}
|
|
3182
|
-
if (parent.type ===
|
|
3285
|
+
if (parent.type === AST_NODE_TYPES43.LogicalExpression) {
|
|
3183
3286
|
return true;
|
|
3184
3287
|
}
|
|
3185
|
-
if (parent.type ===
|
|
3288
|
+
if (parent.type === AST_NODE_TYPES43.AssignmentExpression && parent.left !== node) {
|
|
3186
3289
|
return true;
|
|
3187
3290
|
}
|
|
3188
3291
|
return false;
|
|
3189
3292
|
};
|
|
3190
|
-
var preferFunctionDeclaration =
|
|
3293
|
+
var preferFunctionDeclaration = createRule45({
|
|
3191
3294
|
name: "prefer-function-declaration",
|
|
3192
3295
|
meta: {
|
|
3193
3296
|
type: "suggestion",
|
|
@@ -3208,14 +3311,14 @@ var preferFunctionDeclaration = createRule43({
|
|
|
3208
3311
|
}
|
|
3209
3312
|
return {
|
|
3210
3313
|
VariableDeclarator(node) {
|
|
3211
|
-
if (node.id.type !==
|
|
3314
|
+
if (node.id.type !== AST_NODE_TYPES43.Identifier) {
|
|
3212
3315
|
return;
|
|
3213
3316
|
}
|
|
3214
3317
|
const { init } = node;
|
|
3215
3318
|
if (!init) {
|
|
3216
3319
|
return;
|
|
3217
3320
|
}
|
|
3218
|
-
if (init.type ===
|
|
3321
|
+
if (init.type === AST_NODE_TYPES43.ArrowFunctionExpression) {
|
|
3219
3322
|
if (isCallbackContext(init)) {
|
|
3220
3323
|
return;
|
|
3221
3324
|
}
|
|
@@ -3225,7 +3328,7 @@ var preferFunctionDeclaration = createRule43({
|
|
|
3225
3328
|
data: { name: node.id.name }
|
|
3226
3329
|
});
|
|
3227
3330
|
}
|
|
3228
|
-
if (init.type ===
|
|
3331
|
+
if (init.type === AST_NODE_TYPES43.FunctionExpression) {
|
|
3229
3332
|
if (isCallbackContext(init)) {
|
|
3230
3333
|
return;
|
|
3231
3334
|
}
|
|
@@ -3242,11 +3345,11 @@ var preferFunctionDeclaration = createRule43({
|
|
|
3242
3345
|
var prefer_function_declaration_default = preferFunctionDeclaration;
|
|
3243
3346
|
|
|
3244
3347
|
// src/rules/prefer-guard-clause.ts
|
|
3245
|
-
import { AST_NODE_TYPES as
|
|
3246
|
-
var
|
|
3348
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44, ESLintUtils as ESLintUtils46 } from "@typescript-eslint/utils";
|
|
3349
|
+
var createRule46 = ESLintUtils46.RuleCreator(
|
|
3247
3350
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3248
3351
|
);
|
|
3249
|
-
var preferGuardClause =
|
|
3352
|
+
var preferGuardClause = createRule46({
|
|
3250
3353
|
name: "prefer-guard-clause",
|
|
3251
3354
|
meta: {
|
|
3252
3355
|
type: "suggestion",
|
|
@@ -3263,8 +3366,8 @@ var preferGuardClause = createRule44({
|
|
|
3263
3366
|
return {
|
|
3264
3367
|
IfStatement(node) {
|
|
3265
3368
|
const { consequent } = node;
|
|
3266
|
-
if (consequent.type ===
|
|
3267
|
-
const hasNestedIf = consequent.body.some((statement) => statement.type ===
|
|
3369
|
+
if (consequent.type === AST_NODE_TYPES44.BlockStatement) {
|
|
3370
|
+
const hasNestedIf = consequent.body.some((statement) => statement.type === AST_NODE_TYPES44.IfStatement);
|
|
3268
3371
|
if (hasNestedIf && consequent.body.length === 1) {
|
|
3269
3372
|
context.report({
|
|
3270
3373
|
node,
|
|
@@ -3272,7 +3375,7 @@ var preferGuardClause = createRule44({
|
|
|
3272
3375
|
});
|
|
3273
3376
|
}
|
|
3274
3377
|
}
|
|
3275
|
-
if (consequent.type ===
|
|
3378
|
+
if (consequent.type === AST_NODE_TYPES44.IfStatement) {
|
|
3276
3379
|
context.report({
|
|
3277
3380
|
node,
|
|
3278
3381
|
messageId: "preferGuardClause"
|
|
@@ -3285,11 +3388,11 @@ var preferGuardClause = createRule44({
|
|
|
3285
3388
|
var prefer_guard_clause_default = preferGuardClause;
|
|
3286
3389
|
|
|
3287
3390
|
// src/rules/prefer-import-type.ts
|
|
3288
|
-
import { AST_NODE_TYPES as
|
|
3289
|
-
var
|
|
3391
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45, ESLintUtils as ESLintUtils47 } from "@typescript-eslint/utils";
|
|
3392
|
+
var createRule47 = ESLintUtils47.RuleCreator(
|
|
3290
3393
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3291
3394
|
);
|
|
3292
|
-
var preferImportType =
|
|
3395
|
+
var preferImportType = createRule47({
|
|
3293
3396
|
name: "prefer-import-type",
|
|
3294
3397
|
meta: {
|
|
3295
3398
|
type: "suggestion",
|
|
@@ -3308,22 +3411,22 @@ var preferImportType = createRule45({
|
|
|
3308
3411
|
let current = node;
|
|
3309
3412
|
while (current) {
|
|
3310
3413
|
switch (current.type) {
|
|
3311
|
-
case
|
|
3312
|
-
case
|
|
3313
|
-
case
|
|
3314
|
-
case
|
|
3315
|
-
case
|
|
3316
|
-
case
|
|
3317
|
-
case
|
|
3318
|
-
case
|
|
3319
|
-
case
|
|
3320
|
-
case
|
|
3321
|
-
case
|
|
3322
|
-
case
|
|
3323
|
-
case
|
|
3414
|
+
case AST_NODE_TYPES45.TSTypeReference:
|
|
3415
|
+
case AST_NODE_TYPES45.TSTypeAnnotation:
|
|
3416
|
+
case AST_NODE_TYPES45.TSTypeParameterInstantiation:
|
|
3417
|
+
case AST_NODE_TYPES45.TSInterfaceHeritage:
|
|
3418
|
+
case AST_NODE_TYPES45.TSClassImplements:
|
|
3419
|
+
case AST_NODE_TYPES45.TSTypeQuery:
|
|
3420
|
+
case AST_NODE_TYPES45.TSTypeAssertion:
|
|
3421
|
+
case AST_NODE_TYPES45.TSAsExpression:
|
|
3422
|
+
case AST_NODE_TYPES45.TSSatisfiesExpression:
|
|
3423
|
+
case AST_NODE_TYPES45.TSTypeAliasDeclaration:
|
|
3424
|
+
case AST_NODE_TYPES45.TSInterfaceDeclaration:
|
|
3425
|
+
case AST_NODE_TYPES45.TSTypeParameter:
|
|
3426
|
+
case AST_NODE_TYPES45.TSQualifiedName:
|
|
3324
3427
|
return true;
|
|
3325
|
-
case
|
|
3326
|
-
case
|
|
3428
|
+
case AST_NODE_TYPES45.MemberExpression:
|
|
3429
|
+
case AST_NODE_TYPES45.Identifier:
|
|
3327
3430
|
current = current.parent;
|
|
3328
3431
|
break;
|
|
3329
3432
|
default:
|
|
@@ -3353,27 +3456,27 @@ var preferImportType = createRule45({
|
|
|
3353
3456
|
return false;
|
|
3354
3457
|
}
|
|
3355
3458
|
switch (parent.type) {
|
|
3356
|
-
case
|
|
3357
|
-
case
|
|
3358
|
-
case
|
|
3359
|
-
case
|
|
3360
|
-
case
|
|
3361
|
-
case
|
|
3362
|
-
case
|
|
3363
|
-
case
|
|
3364
|
-
case
|
|
3365
|
-
case
|
|
3366
|
-
case
|
|
3367
|
-
case
|
|
3368
|
-
case
|
|
3369
|
-
case
|
|
3370
|
-
case
|
|
3371
|
-
case
|
|
3372
|
-
case
|
|
3373
|
-
case
|
|
3374
|
-
case
|
|
3375
|
-
case
|
|
3376
|
-
case
|
|
3459
|
+
case AST_NODE_TYPES45.CallExpression:
|
|
3460
|
+
case AST_NODE_TYPES45.NewExpression:
|
|
3461
|
+
case AST_NODE_TYPES45.JSXOpeningElement:
|
|
3462
|
+
case AST_NODE_TYPES45.JSXClosingElement:
|
|
3463
|
+
case AST_NODE_TYPES45.MemberExpression:
|
|
3464
|
+
case AST_NODE_TYPES45.VariableDeclarator:
|
|
3465
|
+
case AST_NODE_TYPES45.TaggedTemplateExpression:
|
|
3466
|
+
case AST_NODE_TYPES45.SpreadElement:
|
|
3467
|
+
case AST_NODE_TYPES45.ExportSpecifier:
|
|
3468
|
+
case AST_NODE_TYPES45.ArrayExpression:
|
|
3469
|
+
case AST_NODE_TYPES45.ObjectExpression:
|
|
3470
|
+
case AST_NODE_TYPES45.BinaryExpression:
|
|
3471
|
+
case AST_NODE_TYPES45.LogicalExpression:
|
|
3472
|
+
case AST_NODE_TYPES45.UnaryExpression:
|
|
3473
|
+
case AST_NODE_TYPES45.ReturnStatement:
|
|
3474
|
+
case AST_NODE_TYPES45.ArrowFunctionExpression:
|
|
3475
|
+
case AST_NODE_TYPES45.ConditionalExpression:
|
|
3476
|
+
case AST_NODE_TYPES45.AwaitExpression:
|
|
3477
|
+
case AST_NODE_TYPES45.YieldExpression:
|
|
3478
|
+
case AST_NODE_TYPES45.Property:
|
|
3479
|
+
case AST_NODE_TYPES45.JSXExpressionContainer:
|
|
3377
3480
|
return true;
|
|
3378
3481
|
default:
|
|
3379
3482
|
return false;
|
|
@@ -3397,13 +3500,13 @@ var preferImportType = createRule45({
|
|
|
3397
3500
|
}
|
|
3398
3501
|
const scope = context.sourceCode.getScope(node);
|
|
3399
3502
|
const isTypeOnlyImport2 = node.specifiers.every((specifier) => {
|
|
3400
|
-
if (specifier.type ===
|
|
3503
|
+
if (specifier.type === AST_NODE_TYPES45.ImportDefaultSpecifier) {
|
|
3401
3504
|
return false;
|
|
3402
3505
|
}
|
|
3403
|
-
if (specifier.type ===
|
|
3506
|
+
if (specifier.type === AST_NODE_TYPES45.ImportNamespaceSpecifier) {
|
|
3404
3507
|
return false;
|
|
3405
3508
|
}
|
|
3406
|
-
if (specifier.type ===
|
|
3509
|
+
if (specifier.type === AST_NODE_TYPES45.ImportSpecifier) {
|
|
3407
3510
|
const localName = specifier.local.name;
|
|
3408
3511
|
return !isUsedAsValue(localName, scope);
|
|
3409
3512
|
}
|
|
@@ -3429,19 +3532,19 @@ var preferImportType = createRule45({
|
|
|
3429
3532
|
var prefer_import_type_default = preferImportType;
|
|
3430
3533
|
|
|
3431
3534
|
// src/rules/prefer-inline-literal-union.ts
|
|
3432
|
-
import { AST_NODE_TYPES as
|
|
3433
|
-
var
|
|
3535
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46, ESLintUtils as ESLintUtils48 } from "@typescript-eslint/utils";
|
|
3536
|
+
var createRule48 = ESLintUtils48.RuleCreator(
|
|
3434
3537
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3435
3538
|
);
|
|
3436
3539
|
function isLiteralUnionType(node) {
|
|
3437
|
-
if (node.type !==
|
|
3540
|
+
if (node.type !== AST_NODE_TYPES46.TSUnionType) {
|
|
3438
3541
|
return false;
|
|
3439
3542
|
}
|
|
3440
3543
|
return node.types.every(
|
|
3441
|
-
(member) => member.type ===
|
|
3544
|
+
(member) => member.type === AST_NODE_TYPES46.TSLiteralType || member.type === AST_NODE_TYPES46.TSNullKeyword || member.type === AST_NODE_TYPES46.TSUndefinedKeyword
|
|
3442
3545
|
);
|
|
3443
3546
|
}
|
|
3444
|
-
var preferInlineLiteralUnion =
|
|
3547
|
+
var preferInlineLiteralUnion = createRule48({
|
|
3445
3548
|
name: "prefer-inline-literal-union",
|
|
3446
3549
|
meta: {
|
|
3447
3550
|
type: "suggestion",
|
|
@@ -3468,10 +3571,10 @@ var preferInlineLiteralUnion = createRule46({
|
|
|
3468
3571
|
return;
|
|
3469
3572
|
}
|
|
3470
3573
|
const { typeAnnotation } = node.typeAnnotation;
|
|
3471
|
-
if (typeAnnotation.type !==
|
|
3574
|
+
if (typeAnnotation.type !== AST_NODE_TYPES46.TSTypeReference) {
|
|
3472
3575
|
return;
|
|
3473
3576
|
}
|
|
3474
|
-
if (typeAnnotation.typeName.type !==
|
|
3577
|
+
if (typeAnnotation.typeName.type !== AST_NODE_TYPES46.Identifier) {
|
|
3475
3578
|
return;
|
|
3476
3579
|
}
|
|
3477
3580
|
const aliasName = typeAnnotation.typeName.name;
|
|
@@ -3495,12 +3598,12 @@ var preferInlineLiteralUnion = createRule46({
|
|
|
3495
3598
|
var prefer_inline_literal_union_default = preferInlineLiteralUnion;
|
|
3496
3599
|
|
|
3497
3600
|
// src/rules/prefer-inline-type-export.ts
|
|
3498
|
-
import { AST_NODE_TYPES as
|
|
3499
|
-
var
|
|
3601
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47, ESLintUtils as ESLintUtils49 } from "@typescript-eslint/utils";
|
|
3602
|
+
var createRule49 = ESLintUtils49.RuleCreator(
|
|
3500
3603
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3501
3604
|
);
|
|
3502
|
-
var isTypeDeclaration = (node) => node.type ===
|
|
3503
|
-
var preferInlineTypeExport =
|
|
3605
|
+
var isTypeDeclaration = (node) => node.type === AST_NODE_TYPES47.TSInterfaceDeclaration || node.type === AST_NODE_TYPES47.TSTypeAliasDeclaration;
|
|
3606
|
+
var preferInlineTypeExport = createRule49({
|
|
3504
3607
|
name: "prefer-inline-type-export",
|
|
3505
3608
|
meta: {
|
|
3506
3609
|
type: "suggestion",
|
|
@@ -3517,12 +3620,12 @@ var preferInlineTypeExport = createRule47({
|
|
|
3517
3620
|
create(context) {
|
|
3518
3621
|
const typeDeclarations = /* @__PURE__ */ new Map();
|
|
3519
3622
|
function collectDeclaration(node) {
|
|
3520
|
-
if (node.parent.type !==
|
|
3623
|
+
if (node.parent.type !== AST_NODE_TYPES47.ExportNamedDeclaration) {
|
|
3521
3624
|
typeDeclarations.set(node.id.name, node);
|
|
3522
3625
|
}
|
|
3523
3626
|
}
|
|
3524
3627
|
function reportSpecifier(specifier, statement, declarationNode) {
|
|
3525
|
-
if (specifier.local.type !==
|
|
3628
|
+
if (specifier.local.type !== AST_NODE_TYPES47.Identifier) {
|
|
3526
3629
|
return;
|
|
3527
3630
|
}
|
|
3528
3631
|
const { name } = specifier.local;
|
|
@@ -3555,16 +3658,16 @@ var preferInlineTypeExport = createRule47({
|
|
|
3555
3658
|
return {
|
|
3556
3659
|
Program(node) {
|
|
3557
3660
|
node.body.forEach((statement) => {
|
|
3558
|
-
if (statement.type ===
|
|
3661
|
+
if (statement.type === AST_NODE_TYPES47.TSInterfaceDeclaration || statement.type === AST_NODE_TYPES47.TSTypeAliasDeclaration) {
|
|
3559
3662
|
collectDeclaration(statement);
|
|
3560
3663
|
}
|
|
3561
3664
|
});
|
|
3562
3665
|
node.body.forEach((statement) => {
|
|
3563
|
-
if (statement.type !==
|
|
3666
|
+
if (statement.type !== AST_NODE_TYPES47.ExportNamedDeclaration || statement.declaration !== null) {
|
|
3564
3667
|
return;
|
|
3565
3668
|
}
|
|
3566
3669
|
statement.specifiers.forEach((specifier) => {
|
|
3567
|
-
if (specifier.local.type !==
|
|
3670
|
+
if (specifier.local.type !== AST_NODE_TYPES47.Identifier) {
|
|
3568
3671
|
return;
|
|
3569
3672
|
}
|
|
3570
3673
|
const declarationNode = typeDeclarations.get(specifier.local.name);
|
|
@@ -3581,11 +3684,11 @@ var preferInlineTypeExport = createRule47({
|
|
|
3581
3684
|
var prefer_inline_type_export_default = preferInlineTypeExport;
|
|
3582
3685
|
|
|
3583
3686
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
3584
|
-
import { AST_NODE_TYPES as
|
|
3585
|
-
var
|
|
3687
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48, ESLintUtils as ESLintUtils50 } from "@typescript-eslint/utils";
|
|
3688
|
+
var createRule50 = ESLintUtils50.RuleCreator(
|
|
3586
3689
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3587
3690
|
);
|
|
3588
|
-
var preferInterfaceOverInlineTypes =
|
|
3691
|
+
var preferInterfaceOverInlineTypes = createRule50({
|
|
3589
3692
|
name: "prefer-interface-over-inline-types",
|
|
3590
3693
|
meta: {
|
|
3591
3694
|
type: "suggestion",
|
|
@@ -3601,54 +3704,54 @@ var preferInterfaceOverInlineTypes = createRule48({
|
|
|
3601
3704
|
defaultOptions: [],
|
|
3602
3705
|
create(context) {
|
|
3603
3706
|
function hasJSXInConditional(node) {
|
|
3604
|
-
return node.consequent.type ===
|
|
3707
|
+
return node.consequent.type === AST_NODE_TYPES48.JSXElement || node.consequent.type === AST_NODE_TYPES48.JSXFragment || node.alternate.type === AST_NODE_TYPES48.JSXElement || node.alternate.type === AST_NODE_TYPES48.JSXFragment;
|
|
3605
3708
|
}
|
|
3606
3709
|
function hasJSXInLogical(node) {
|
|
3607
|
-
return node.right.type ===
|
|
3710
|
+
return node.right.type === AST_NODE_TYPES48.JSXElement || node.right.type === AST_NODE_TYPES48.JSXFragment;
|
|
3608
3711
|
}
|
|
3609
3712
|
function hasJSXReturn(block) {
|
|
3610
3713
|
return block.body.some((stmt) => {
|
|
3611
|
-
if (stmt.type ===
|
|
3612
|
-
return stmt.argument.type ===
|
|
3714
|
+
if (stmt.type === AST_NODE_TYPES48.ReturnStatement && stmt.argument) {
|
|
3715
|
+
return stmt.argument.type === AST_NODE_TYPES48.JSXElement || stmt.argument.type === AST_NODE_TYPES48.JSXFragment || stmt.argument.type === AST_NODE_TYPES48.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES48.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
3613
3716
|
}
|
|
3614
3717
|
return false;
|
|
3615
3718
|
});
|
|
3616
3719
|
}
|
|
3617
3720
|
function isReactComponent2(node) {
|
|
3618
|
-
if (node.type ===
|
|
3619
|
-
if (node.body.type ===
|
|
3721
|
+
if (node.type === AST_NODE_TYPES48.ArrowFunctionExpression) {
|
|
3722
|
+
if (node.body.type === AST_NODE_TYPES48.JSXElement || node.body.type === AST_NODE_TYPES48.JSXFragment) {
|
|
3620
3723
|
return true;
|
|
3621
3724
|
}
|
|
3622
|
-
if (node.body.type ===
|
|
3725
|
+
if (node.body.type === AST_NODE_TYPES48.BlockStatement) {
|
|
3623
3726
|
return hasJSXReturn(node.body);
|
|
3624
3727
|
}
|
|
3625
|
-
} else if (node.type ===
|
|
3626
|
-
if (node.body && node.body.type ===
|
|
3728
|
+
} else if (node.type === AST_NODE_TYPES48.FunctionExpression || node.type === AST_NODE_TYPES48.FunctionDeclaration) {
|
|
3729
|
+
if (node.body && node.body.type === AST_NODE_TYPES48.BlockStatement) {
|
|
3627
3730
|
return hasJSXReturn(node.body);
|
|
3628
3731
|
}
|
|
3629
3732
|
}
|
|
3630
3733
|
return false;
|
|
3631
3734
|
}
|
|
3632
3735
|
function isInlineTypeAnnotation(node) {
|
|
3633
|
-
if (node.type ===
|
|
3736
|
+
if (node.type === AST_NODE_TYPES48.TSTypeLiteral) {
|
|
3634
3737
|
return true;
|
|
3635
3738
|
}
|
|
3636
|
-
if (node.type ===
|
|
3637
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3739
|
+
if (node.type === AST_NODE_TYPES48.TSTypeReference && node.typeArguments) {
|
|
3740
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES48.TSTypeLiteral);
|
|
3638
3741
|
}
|
|
3639
|
-
if (node.type ===
|
|
3742
|
+
if (node.type === AST_NODE_TYPES48.TSUnionType) {
|
|
3640
3743
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
3641
3744
|
}
|
|
3642
3745
|
return false;
|
|
3643
3746
|
}
|
|
3644
3747
|
function hasInlineObjectType(node) {
|
|
3645
|
-
if (node.type ===
|
|
3748
|
+
if (node.type === AST_NODE_TYPES48.TSTypeLiteral) {
|
|
3646
3749
|
return true;
|
|
3647
3750
|
}
|
|
3648
|
-
if (node.type ===
|
|
3649
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3751
|
+
if (node.type === AST_NODE_TYPES48.TSTypeReference && node.typeArguments) {
|
|
3752
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES48.TSTypeLiteral);
|
|
3650
3753
|
}
|
|
3651
|
-
if (node.type ===
|
|
3754
|
+
if (node.type === AST_NODE_TYPES48.TSUnionType) {
|
|
3652
3755
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
3653
3756
|
}
|
|
3654
3757
|
return false;
|
|
@@ -3661,7 +3764,7 @@ var preferInterfaceOverInlineTypes = createRule48({
|
|
|
3661
3764
|
return;
|
|
3662
3765
|
}
|
|
3663
3766
|
const param = node.params[0];
|
|
3664
|
-
if (param.type ===
|
|
3767
|
+
if (param.type === AST_NODE_TYPES48.Identifier && param.typeAnnotation) {
|
|
3665
3768
|
const { typeAnnotation } = param.typeAnnotation;
|
|
3666
3769
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
3667
3770
|
context.report({
|
|
@@ -3681,11 +3784,11 @@ var preferInterfaceOverInlineTypes = createRule48({
|
|
|
3681
3784
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
3682
3785
|
|
|
3683
3786
|
// src/rules/prefer-jsx-template-literals.ts
|
|
3684
|
-
import { AST_NODE_TYPES as
|
|
3685
|
-
var
|
|
3787
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49, ESLintUtils as ESLintUtils51 } from "@typescript-eslint/utils";
|
|
3788
|
+
var createRule51 = ESLintUtils51.RuleCreator(
|
|
3686
3789
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3687
3790
|
);
|
|
3688
|
-
var preferJSXTemplateLiterals =
|
|
3791
|
+
var preferJSXTemplateLiterals = createRule51({
|
|
3689
3792
|
name: "prefer-jsx-template-literals",
|
|
3690
3793
|
meta: {
|
|
3691
3794
|
type: "suggestion",
|
|
@@ -3754,9 +3857,9 @@ var preferJSXTemplateLiterals = createRule49({
|
|
|
3754
3857
|
if (!child || !nextChild) {
|
|
3755
3858
|
return;
|
|
3756
3859
|
}
|
|
3757
|
-
if (child.type ===
|
|
3860
|
+
if (child.type === AST_NODE_TYPES49.JSXText && nextChild.type === AST_NODE_TYPES49.JSXExpressionContainer) {
|
|
3758
3861
|
handleTextBeforeExpression(child, nextChild);
|
|
3759
|
-
} else if (child.type ===
|
|
3862
|
+
} else if (child.type === AST_NODE_TYPES49.JSXExpressionContainer && nextChild.type === AST_NODE_TYPES49.JSXText) {
|
|
3760
3863
|
handleExpressionBeforeText(child, nextChild);
|
|
3761
3864
|
}
|
|
3762
3865
|
}
|
|
@@ -3769,11 +3872,11 @@ var preferJSXTemplateLiterals = createRule49({
|
|
|
3769
3872
|
var prefer_jsx_template_literals_default = preferJSXTemplateLiterals;
|
|
3770
3873
|
|
|
3771
3874
|
// src/rules/prefer-named-param-types.ts
|
|
3772
|
-
import { AST_NODE_TYPES as
|
|
3773
|
-
var
|
|
3875
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50, ESLintUtils as ESLintUtils52 } from "@typescript-eslint/utils";
|
|
3876
|
+
var createRule52 = ESLintUtils52.RuleCreator(
|
|
3774
3877
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3775
3878
|
);
|
|
3776
|
-
var preferNamedParamTypes =
|
|
3879
|
+
var preferNamedParamTypes = createRule52({
|
|
3777
3880
|
name: "prefer-named-param-types",
|
|
3778
3881
|
meta: {
|
|
3779
3882
|
type: "suggestion",
|
|
@@ -3788,16 +3891,16 @@ var preferNamedParamTypes = createRule50({
|
|
|
3788
3891
|
defaultOptions: [],
|
|
3789
3892
|
create(context) {
|
|
3790
3893
|
function hasInlineObjectType(param) {
|
|
3791
|
-
if (param.type ===
|
|
3894
|
+
if (param.type === AST_NODE_TYPES50.AssignmentPattern) {
|
|
3792
3895
|
return hasInlineObjectType(param.left);
|
|
3793
3896
|
}
|
|
3794
|
-
if (param.type ===
|
|
3795
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3897
|
+
if (param.type === AST_NODE_TYPES50.ObjectPattern) {
|
|
3898
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES50.TSTypeLiteral) {
|
|
3796
3899
|
return true;
|
|
3797
3900
|
}
|
|
3798
3901
|
}
|
|
3799
|
-
if (param.type ===
|
|
3800
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3902
|
+
if (param.type === AST_NODE_TYPES50.Identifier) {
|
|
3903
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES50.TSTypeLiteral) {
|
|
3801
3904
|
return true;
|
|
3802
3905
|
}
|
|
3803
3906
|
}
|
|
@@ -3831,11 +3934,11 @@ var preferNamedParamTypes = createRule50({
|
|
|
3831
3934
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
3832
3935
|
|
|
3833
3936
|
// src/rules/prefer-react-import-types.ts
|
|
3834
|
-
import { AST_NODE_TYPES as
|
|
3835
|
-
var
|
|
3937
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ESLintUtils as ESLintUtils53 } from "@typescript-eslint/utils";
|
|
3938
|
+
var createRule53 = ESLintUtils53.RuleCreator(
|
|
3836
3939
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3837
3940
|
);
|
|
3838
|
-
var preferReactImportTypes =
|
|
3941
|
+
var preferReactImportTypes = createRule53({
|
|
3839
3942
|
name: "prefer-react-import-types",
|
|
3840
3943
|
meta: {
|
|
3841
3944
|
type: "suggestion",
|
|
@@ -3911,7 +4014,7 @@ var preferReactImportTypes = createRule51({
|
|
|
3911
4014
|
]);
|
|
3912
4015
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
3913
4016
|
function checkMemberExpression(node) {
|
|
3914
|
-
if (node.object.type ===
|
|
4017
|
+
if (node.object.type === AST_NODE_TYPES51.Identifier && node.object.name === "React" && node.property.type === AST_NODE_TYPES51.Identifier && allReactExports.has(node.property.name)) {
|
|
3915
4018
|
const typeName = node.property.name;
|
|
3916
4019
|
const isType = reactTypes.has(typeName);
|
|
3917
4020
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -3928,7 +4031,7 @@ var preferReactImportTypes = createRule51({
|
|
|
3928
4031
|
return {
|
|
3929
4032
|
MemberExpression: checkMemberExpression,
|
|
3930
4033
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
3931
|
-
if (node.left.type ===
|
|
4034
|
+
if (node.left.type === AST_NODE_TYPES51.Identifier && node.left.name === "React" && node.right.type === AST_NODE_TYPES51.Identifier && allReactExports.has(node.right.name)) {
|
|
3932
4035
|
const typeName = node.right.name;
|
|
3933
4036
|
const isType = reactTypes.has(typeName);
|
|
3934
4037
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -3948,11 +4051,11 @@ var preferReactImportTypes = createRule51({
|
|
|
3948
4051
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
3949
4052
|
|
|
3950
4053
|
// src/rules/react-props-destructure.ts
|
|
3951
|
-
import { AST_NODE_TYPES as
|
|
3952
|
-
var
|
|
4054
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES52, ESLintUtils as ESLintUtils54 } from "@typescript-eslint/utils";
|
|
4055
|
+
var createRule54 = ESLintUtils54.RuleCreator(
|
|
3953
4056
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3954
4057
|
);
|
|
3955
|
-
var reactPropsDestructure =
|
|
4058
|
+
var reactPropsDestructure = createRule54({
|
|
3956
4059
|
name: "react-props-destructure",
|
|
3957
4060
|
meta: {
|
|
3958
4061
|
type: "suggestion",
|
|
@@ -3968,29 +4071,29 @@ var reactPropsDestructure = createRule52({
|
|
|
3968
4071
|
defaultOptions: [],
|
|
3969
4072
|
create(context) {
|
|
3970
4073
|
function hasJSXInConditional(node) {
|
|
3971
|
-
return node.consequent.type ===
|
|
4074
|
+
return node.consequent.type === AST_NODE_TYPES52.JSXElement || node.consequent.type === AST_NODE_TYPES52.JSXFragment || node.alternate.type === AST_NODE_TYPES52.JSXElement || node.alternate.type === AST_NODE_TYPES52.JSXFragment;
|
|
3972
4075
|
}
|
|
3973
4076
|
function hasJSXInLogical(node) {
|
|
3974
|
-
return node.right.type ===
|
|
4077
|
+
return node.right.type === AST_NODE_TYPES52.JSXElement || node.right.type === AST_NODE_TYPES52.JSXFragment;
|
|
3975
4078
|
}
|
|
3976
4079
|
function hasJSXReturn(block) {
|
|
3977
4080
|
return block.body.some((stmt) => {
|
|
3978
|
-
if (stmt.type ===
|
|
3979
|
-
return stmt.argument.type ===
|
|
4081
|
+
if (stmt.type === AST_NODE_TYPES52.ReturnStatement && stmt.argument) {
|
|
4082
|
+
return stmt.argument.type === AST_NODE_TYPES52.JSXElement || stmt.argument.type === AST_NODE_TYPES52.JSXFragment || stmt.argument.type === AST_NODE_TYPES52.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES52.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
3980
4083
|
}
|
|
3981
4084
|
return false;
|
|
3982
4085
|
});
|
|
3983
4086
|
}
|
|
3984
4087
|
function isReactComponent2(node) {
|
|
3985
|
-
if (node.type ===
|
|
3986
|
-
if (node.body.type ===
|
|
4088
|
+
if (node.type === AST_NODE_TYPES52.ArrowFunctionExpression) {
|
|
4089
|
+
if (node.body.type === AST_NODE_TYPES52.JSXElement || node.body.type === AST_NODE_TYPES52.JSXFragment) {
|
|
3987
4090
|
return true;
|
|
3988
4091
|
}
|
|
3989
|
-
if (node.body.type ===
|
|
4092
|
+
if (node.body.type === AST_NODE_TYPES52.BlockStatement) {
|
|
3990
4093
|
return hasJSXReturn(node.body);
|
|
3991
4094
|
}
|
|
3992
|
-
} else if (node.type ===
|
|
3993
|
-
if (node.body && node.body.type ===
|
|
4095
|
+
} else if (node.type === AST_NODE_TYPES52.FunctionExpression || node.type === AST_NODE_TYPES52.FunctionDeclaration) {
|
|
4096
|
+
if (node.body && node.body.type === AST_NODE_TYPES52.BlockStatement) {
|
|
3994
4097
|
return hasJSXReturn(node.body);
|
|
3995
4098
|
}
|
|
3996
4099
|
}
|
|
@@ -4004,9 +4107,9 @@ var reactPropsDestructure = createRule52({
|
|
|
4004
4107
|
return;
|
|
4005
4108
|
}
|
|
4006
4109
|
const param = node.params[0];
|
|
4007
|
-
if (param.type ===
|
|
4008
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
4009
|
-
if (prop.key.type ===
|
|
4110
|
+
if (param.type === AST_NODE_TYPES52.ObjectPattern) {
|
|
4111
|
+
const properties = param.properties.filter((prop) => prop.type === AST_NODE_TYPES52.Property).map((prop) => {
|
|
4112
|
+
if (prop.key.type === AST_NODE_TYPES52.Identifier) {
|
|
4010
4113
|
return prop.key.name;
|
|
4011
4114
|
}
|
|
4012
4115
|
return null;
|
|
@@ -4033,57 +4136,57 @@ var reactPropsDestructure = createRule52({
|
|
|
4033
4136
|
var react_props_destructure_default = reactPropsDestructure;
|
|
4034
4137
|
|
|
4035
4138
|
// src/rules/require-explicit-return-type.ts
|
|
4036
|
-
import { AST_NODE_TYPES as
|
|
4037
|
-
var
|
|
4139
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES53, ESLintUtils as ESLintUtils55 } from "@typescript-eslint/utils";
|
|
4140
|
+
var createRule55 = ESLintUtils55.RuleCreator(
|
|
4038
4141
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4039
4142
|
);
|
|
4040
4143
|
var isReactComponent = (node) => {
|
|
4041
|
-
if (node.type ===
|
|
4144
|
+
if (node.type === AST_NODE_TYPES53.ArrowFunctionExpression) {
|
|
4042
4145
|
const { parent } = node;
|
|
4043
|
-
if (parent?.type ===
|
|
4146
|
+
if (parent?.type === AST_NODE_TYPES53.VariableDeclarator) {
|
|
4044
4147
|
const { id } = parent;
|
|
4045
|
-
if (id.type ===
|
|
4148
|
+
if (id.type === AST_NODE_TYPES53.Identifier) {
|
|
4046
4149
|
return /^[A-Z]/.test(id.name);
|
|
4047
4150
|
}
|
|
4048
4151
|
}
|
|
4049
4152
|
}
|
|
4050
|
-
if (node.type ===
|
|
4153
|
+
if (node.type === AST_NODE_TYPES53.FunctionDeclaration && node.id) {
|
|
4051
4154
|
return /^[A-Z]/.test(node.id.name);
|
|
4052
4155
|
}
|
|
4053
4156
|
return false;
|
|
4054
4157
|
};
|
|
4055
4158
|
var isCallbackFunction = (node) => {
|
|
4056
|
-
if (node.type ===
|
|
4159
|
+
if (node.type === AST_NODE_TYPES53.FunctionDeclaration) {
|
|
4057
4160
|
return false;
|
|
4058
4161
|
}
|
|
4059
4162
|
const { parent } = node;
|
|
4060
4163
|
if (!parent) {
|
|
4061
4164
|
return false;
|
|
4062
4165
|
}
|
|
4063
|
-
if (parent.type ===
|
|
4166
|
+
if (parent.type === AST_NODE_TYPES53.CallExpression && parent.arguments.includes(node)) {
|
|
4064
4167
|
return true;
|
|
4065
4168
|
}
|
|
4066
|
-
if (parent.type ===
|
|
4169
|
+
if (parent.type === AST_NODE_TYPES53.Property) {
|
|
4067
4170
|
return true;
|
|
4068
4171
|
}
|
|
4069
|
-
if (parent.type ===
|
|
4172
|
+
if (parent.type === AST_NODE_TYPES53.ArrayExpression) {
|
|
4070
4173
|
return true;
|
|
4071
4174
|
}
|
|
4072
4175
|
return false;
|
|
4073
4176
|
};
|
|
4074
4177
|
var getFunctionName = (node) => {
|
|
4075
|
-
if (node.type ===
|
|
4178
|
+
if (node.type === AST_NODE_TYPES53.FunctionDeclaration && node.id) {
|
|
4076
4179
|
return node.id.name;
|
|
4077
4180
|
}
|
|
4078
|
-
if (node.type ===
|
|
4181
|
+
if (node.type === AST_NODE_TYPES53.FunctionExpression && node.id) {
|
|
4079
4182
|
return node.id.name;
|
|
4080
4183
|
}
|
|
4081
|
-
if ((node.type ===
|
|
4184
|
+
if ((node.type === AST_NODE_TYPES53.ArrowFunctionExpression || node.type === AST_NODE_TYPES53.FunctionExpression) && node.parent?.type === AST_NODE_TYPES53.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES53.Identifier) {
|
|
4082
4185
|
return node.parent.id.name;
|
|
4083
4186
|
}
|
|
4084
4187
|
return null;
|
|
4085
4188
|
};
|
|
4086
|
-
var requireExplicitReturnType =
|
|
4189
|
+
var requireExplicitReturnType = createRule55({
|
|
4087
4190
|
name: "require-explicit-return-type",
|
|
4088
4191
|
meta: {
|
|
4089
4192
|
type: "suggestion",
|
|
@@ -4132,8 +4235,8 @@ var requireExplicitReturnType = createRule53({
|
|
|
4132
4235
|
var require_explicit_return_type_default = requireExplicitReturnType;
|
|
4133
4236
|
|
|
4134
4237
|
// src/rules/sort-exports.ts
|
|
4135
|
-
import { AST_NODE_TYPES as
|
|
4136
|
-
var
|
|
4238
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES54, ESLintUtils as ESLintUtils56 } from "@typescript-eslint/utils";
|
|
4239
|
+
var createRule56 = ESLintUtils56.RuleCreator(
|
|
4137
4240
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4138
4241
|
);
|
|
4139
4242
|
var GROUP_NAMES = ["", "external/alias re-export", "relative re-export", "local export"];
|
|
@@ -4147,7 +4250,7 @@ function getExportGroup(node) {
|
|
|
4147
4250
|
}
|
|
4148
4251
|
return 1;
|
|
4149
4252
|
}
|
|
4150
|
-
var sortExports =
|
|
4253
|
+
var sortExports = createRule56({
|
|
4151
4254
|
name: "sort-exports",
|
|
4152
4255
|
meta: {
|
|
4153
4256
|
type: "suggestion",
|
|
@@ -4187,7 +4290,7 @@ var sortExports = createRule54({
|
|
|
4187
4290
|
Program(node) {
|
|
4188
4291
|
const exportGroups = [];
|
|
4189
4292
|
node.body.forEach((statement) => {
|
|
4190
|
-
if (statement.type !==
|
|
4293
|
+
if (statement.type !== AST_NODE_TYPES54.ExportNamedDeclaration || statement.declaration !== null) {
|
|
4191
4294
|
if (exportGroups.length > 0) {
|
|
4192
4295
|
checkOrder(exportGroups);
|
|
4193
4296
|
exportGroups.length = 0;
|
|
@@ -4206,8 +4309,8 @@ var sortExports = createRule54({
|
|
|
4206
4309
|
var sort_exports_default = sortExports;
|
|
4207
4310
|
|
|
4208
4311
|
// src/rules/sort-imports.ts
|
|
4209
|
-
import { AST_NODE_TYPES as
|
|
4210
|
-
var
|
|
4312
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55, ESLintUtils as ESLintUtils57 } from "@typescript-eslint/utils";
|
|
4313
|
+
var createRule57 = ESLintUtils57.RuleCreator(
|
|
4211
4314
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4212
4315
|
);
|
|
4213
4316
|
var NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
@@ -4274,7 +4377,7 @@ function getImportGroup(node) {
|
|
|
4274
4377
|
function isTypeOnlyImport(node) {
|
|
4275
4378
|
return node.importKind === "type" && node.specifiers.length > 0;
|
|
4276
4379
|
}
|
|
4277
|
-
var sortImports =
|
|
4380
|
+
var sortImports = createRule57({
|
|
4278
4381
|
name: "sort-imports",
|
|
4279
4382
|
meta: {
|
|
4280
4383
|
type: "suggestion",
|
|
@@ -4318,7 +4421,7 @@ var sortImports = createRule55({
|
|
|
4318
4421
|
Program(node) {
|
|
4319
4422
|
const importGroups = [];
|
|
4320
4423
|
node.body.forEach((statement) => {
|
|
4321
|
-
if (statement.type !==
|
|
4424
|
+
if (statement.type !== AST_NODE_TYPES55.ImportDeclaration) {
|
|
4322
4425
|
if (importGroups.length > 0) {
|
|
4323
4426
|
checkOrder(importGroups);
|
|
4324
4427
|
importGroups.length = 0;
|
|
@@ -4340,13 +4443,13 @@ var sortImports = createRule55({
|
|
|
4340
4443
|
var sort_imports_default = sortImports;
|
|
4341
4444
|
|
|
4342
4445
|
// src/rules/sort-type-alphabetically.ts
|
|
4343
|
-
import { AST_NODE_TYPES as
|
|
4344
|
-
var
|
|
4446
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES56, ESLintUtils as ESLintUtils58 } from "@typescript-eslint/utils";
|
|
4447
|
+
var createRule58 = ESLintUtils58.RuleCreator(
|
|
4345
4448
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4346
4449
|
);
|
|
4347
4450
|
function isAlphabeticallySortedWithinGroups(members) {
|
|
4348
4451
|
const properties = members.filter(
|
|
4349
|
-
(member) => member.type ===
|
|
4452
|
+
(member) => member.type === AST_NODE_TYPES56.TSPropertySignature && member.key.type === AST_NODE_TYPES56.Identifier
|
|
4350
4453
|
);
|
|
4351
4454
|
if (properties.length < 2) {
|
|
4352
4455
|
return true;
|
|
@@ -4357,7 +4460,7 @@ function isAlphabeticallySortedWithinGroups(members) {
|
|
|
4357
4460
|
const isOptionalSorted = optional.every((name, index) => index === 0 || optional[index - 1].localeCompare(name) <= 0);
|
|
4358
4461
|
return isRequiredSorted && isOptionalSorted;
|
|
4359
4462
|
}
|
|
4360
|
-
var sortTypeAlphabetically =
|
|
4463
|
+
var sortTypeAlphabetically = createRule58({
|
|
4361
4464
|
name: "sort-type-alphabetically",
|
|
4362
4465
|
meta: {
|
|
4363
4466
|
type: "suggestion",
|
|
@@ -4375,7 +4478,7 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4375
4478
|
function fixMembers(fixer, members) {
|
|
4376
4479
|
const { sourceCode } = context;
|
|
4377
4480
|
const properties = members.filter(
|
|
4378
|
-
(member) => member.type ===
|
|
4481
|
+
(member) => member.type === AST_NODE_TYPES56.TSPropertySignature && member.key.type === AST_NODE_TYPES56.Identifier
|
|
4379
4482
|
);
|
|
4380
4483
|
const required = properties.filter((prop) => !prop.optional);
|
|
4381
4484
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4412,7 +4515,7 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4412
4515
|
}
|
|
4413
4516
|
},
|
|
4414
4517
|
TSTypeAliasDeclaration(node) {
|
|
4415
|
-
if (node.typeAnnotation.type !==
|
|
4518
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES56.TSTypeLiteral) {
|
|
4416
4519
|
return;
|
|
4417
4520
|
}
|
|
4418
4521
|
const { members } = node.typeAnnotation;
|
|
@@ -4432,13 +4535,13 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4432
4535
|
var sort_type_alphabetically_default = sortTypeAlphabetically;
|
|
4433
4536
|
|
|
4434
4537
|
// src/rules/sort-type-required-first.ts
|
|
4435
|
-
import { AST_NODE_TYPES as
|
|
4436
|
-
var
|
|
4538
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES57, ESLintUtils as ESLintUtils59 } from "@typescript-eslint/utils";
|
|
4539
|
+
var createRule59 = ESLintUtils59.RuleCreator(
|
|
4437
4540
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4438
4541
|
);
|
|
4439
4542
|
function isRequiredBeforeOptional(members) {
|
|
4440
4543
|
const properties = members.filter(
|
|
4441
|
-
(member) => member.type ===
|
|
4544
|
+
(member) => member.type === AST_NODE_TYPES57.TSPropertySignature && member.key.type === AST_NODE_TYPES57.Identifier
|
|
4442
4545
|
);
|
|
4443
4546
|
if (properties.length < 2) {
|
|
4444
4547
|
return true;
|
|
@@ -4449,7 +4552,7 @@ function isRequiredBeforeOptional(members) {
|
|
|
4449
4552
|
}
|
|
4450
4553
|
return properties.slice(firstOptionalIndex).every((prop) => prop.optional);
|
|
4451
4554
|
}
|
|
4452
|
-
var sortTypeRequiredFirst =
|
|
4555
|
+
var sortTypeRequiredFirst = createRule59({
|
|
4453
4556
|
name: "sort-type-required-first",
|
|
4454
4557
|
meta: {
|
|
4455
4558
|
type: "suggestion",
|
|
@@ -4467,7 +4570,7 @@ var sortTypeRequiredFirst = createRule57({
|
|
|
4467
4570
|
function fixMembers(fixer, members) {
|
|
4468
4571
|
const { sourceCode } = context;
|
|
4469
4572
|
const properties = members.filter(
|
|
4470
|
-
(member) => member.type ===
|
|
4573
|
+
(member) => member.type === AST_NODE_TYPES57.TSPropertySignature && member.key.type === AST_NODE_TYPES57.Identifier
|
|
4471
4574
|
);
|
|
4472
4575
|
const required = properties.filter((prop) => !prop.optional);
|
|
4473
4576
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4488,7 +4591,7 @@ var sortTypeRequiredFirst = createRule57({
|
|
|
4488
4591
|
}
|
|
4489
4592
|
},
|
|
4490
4593
|
TSTypeAliasDeclaration(node) {
|
|
4491
|
-
if (node.typeAnnotation.type !==
|
|
4594
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES57.TSTypeLiteral) {
|
|
4492
4595
|
return;
|
|
4493
4596
|
}
|
|
4494
4597
|
const { members } = node.typeAnnotation;
|
|
@@ -4525,6 +4628,7 @@ var rules = {
|
|
|
4525
4628
|
"enforce-sorted-destructuring": enforce_sorted_destructuring_default,
|
|
4526
4629
|
"enforce-type-declaration-order": enforce_type_declaration_order_default,
|
|
4527
4630
|
"file-kebab-case": file_kebab_case_default,
|
|
4631
|
+
"index-export-only": index_export_only_default,
|
|
4528
4632
|
"jsx-newline-between-elements": jsx_newline_between_elements_default,
|
|
4529
4633
|
"jsx-no-inline-object-prop": jsx_no_inline_object_prop_default,
|
|
4530
4634
|
"jsx-no-newline-single-line-elements": jsx_no_newline_single_line_elements_default,
|
|
@@ -4546,6 +4650,7 @@ var rules = {
|
|
|
4546
4650
|
"no-inline-default-export": no_inline_default_export_default,
|
|
4547
4651
|
"no-inline-nested-object": no_inline_nested_object_default,
|
|
4548
4652
|
"no-inline-return-properties": no_inline_return_properties_default,
|
|
4653
|
+
"no-inline-type-import": no_inline_type_import_default,
|
|
4549
4654
|
"no-lazy-identifiers": no_lazy_identifiers_default,
|
|
4550
4655
|
"no-logic-in-params": no_logic_in_params_default,
|
|
4551
4656
|
"no-misleading-constant-case": no_misleading_constant_case_default,
|
|
@@ -4586,6 +4691,7 @@ var baseRules = {
|
|
|
4586
4691
|
"nextfriday/enforce-sorted-destructuring": "warn",
|
|
4587
4692
|
"nextfriday/enforce-type-declaration-order": "warn",
|
|
4588
4693
|
"nextfriday/file-kebab-case": "warn",
|
|
4694
|
+
"nextfriday/index-export-only": "warn",
|
|
4589
4695
|
"nextfriday/newline-after-multiline-block": "warn",
|
|
4590
4696
|
"nextfriday/newline-before-return": "warn",
|
|
4591
4697
|
"nextfriday/no-complex-inline-return": "warn",
|
|
@@ -4595,6 +4701,7 @@ var baseRules = {
|
|
|
4595
4701
|
"nextfriday/no-inline-default-export": "warn",
|
|
4596
4702
|
"nextfriday/no-inline-nested-object": "warn",
|
|
4597
4703
|
"nextfriday/no-inline-return-properties": "warn",
|
|
4704
|
+
"nextfriday/no-inline-type-import": "warn",
|
|
4598
4705
|
"nextfriday/no-lazy-identifiers": "warn",
|
|
4599
4706
|
"nextfriday/no-logic-in-params": "warn",
|
|
4600
4707
|
"nextfriday/no-misleading-constant-case": "warn",
|
|
@@ -4628,6 +4735,7 @@ var baseRecommendedRules = {
|
|
|
4628
4735
|
"nextfriday/enforce-sorted-destructuring": "error",
|
|
4629
4736
|
"nextfriday/enforce-type-declaration-order": "error",
|
|
4630
4737
|
"nextfriday/file-kebab-case": "error",
|
|
4738
|
+
"nextfriday/index-export-only": "error",
|
|
4631
4739
|
"nextfriday/newline-after-multiline-block": "error",
|
|
4632
4740
|
"nextfriday/newline-before-return": "error",
|
|
4633
4741
|
"nextfriday/no-complex-inline-return": "error",
|
|
@@ -4637,6 +4745,7 @@ var baseRecommendedRules = {
|
|
|
4637
4745
|
"nextfriday/no-inline-default-export": "error",
|
|
4638
4746
|
"nextfriday/no-inline-nested-object": "error",
|
|
4639
4747
|
"nextfriday/no-inline-return-properties": "error",
|
|
4748
|
+
"nextfriday/no-inline-type-import": "error",
|
|
4640
4749
|
"nextfriday/no-lazy-identifiers": "error",
|
|
4641
4750
|
"nextfriday/no-logic-in-params": "error",
|
|
4642
4751
|
"nextfriday/no-misleading-constant-case": "error",
|