eslint-plugin-nextfriday 3.0.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +153 -26
- package/docs/rules/ENFORCE_CONSTANT_CASE.md +65 -3
- package/docs/rules/FILE_KEBAB_CASE.md +7 -1
- package/docs/rules/INDEX_EXPORT_ONLY.md +88 -0
- package/docs/rules/JSX_PASCAL_CASE.md +6 -2
- package/docs/rules/NO_INLINE_TYPE_IMPORT.md +86 -0
- package/lib/index.cjs +536 -393
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +88 -0
- package/lib/index.d.ts +88 -0
- package/lib/index.js +536 -393
- 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.
|
|
4
|
+
version: "3.2.0",
|
|
5
5
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
6
6
|
keywords: [
|
|
7
7
|
"eslint",
|
|
@@ -1141,12 +1141,74 @@ var fileKebabCase = createRule12({
|
|
|
1141
1141
|
});
|
|
1142
1142
|
var file_kebab_case_default = fileKebabCase;
|
|
1143
1143
|
|
|
1144
|
-
// src/rules/
|
|
1144
|
+
// src/rules/index-export-only.ts
|
|
1145
1145
|
import { AST_NODE_TYPES as AST_NODE_TYPES13, ESLintUtils as ESLintUtils13 } from "@typescript-eslint/utils";
|
|
1146
1146
|
var createRule13 = ESLintUtils13.RuleCreator(
|
|
1147
1147
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1148
1148
|
);
|
|
1149
|
-
var
|
|
1149
|
+
var isIndexFile = (filename) => getBaseName(filename) === "index";
|
|
1150
|
+
var isAllowedExportNamed = (node) => {
|
|
1151
|
+
if (!node.declaration) {
|
|
1152
|
+
return true;
|
|
1153
|
+
}
|
|
1154
|
+
return node.declaration.type === AST_NODE_TYPES13.TSTypeAliasDeclaration || node.declaration.type === AST_NODE_TYPES13.TSInterfaceDeclaration;
|
|
1155
|
+
};
|
|
1156
|
+
var isAllowedExportDefault = (node) => node.declaration.type === AST_NODE_TYPES13.Identifier;
|
|
1157
|
+
var isAllowedTopLevel = (node) => {
|
|
1158
|
+
switch (node.type) {
|
|
1159
|
+
case AST_NODE_TYPES13.ImportDeclaration:
|
|
1160
|
+
case AST_NODE_TYPES13.ExportAllDeclaration:
|
|
1161
|
+
case AST_NODE_TYPES13.TSTypeAliasDeclaration:
|
|
1162
|
+
case AST_NODE_TYPES13.TSInterfaceDeclaration:
|
|
1163
|
+
case AST_NODE_TYPES13.TSImportEqualsDeclaration:
|
|
1164
|
+
return true;
|
|
1165
|
+
case AST_NODE_TYPES13.ExportNamedDeclaration:
|
|
1166
|
+
return isAllowedExportNamed(node);
|
|
1167
|
+
case AST_NODE_TYPES13.ExportDefaultDeclaration:
|
|
1168
|
+
return isAllowedExportDefault(node);
|
|
1169
|
+
default:
|
|
1170
|
+
return false;
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
var indexExportOnly = createRule13({
|
|
1174
|
+
name: "index-export-only",
|
|
1175
|
+
meta: {
|
|
1176
|
+
type: "suggestion",
|
|
1177
|
+
docs: {
|
|
1178
|
+
description: "Restrict index files to imports, re-exports, and type declarations only."
|
|
1179
|
+
},
|
|
1180
|
+
messages: {
|
|
1181
|
+
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."
|
|
1182
|
+
},
|
|
1183
|
+
schema: []
|
|
1184
|
+
},
|
|
1185
|
+
defaultOptions: [],
|
|
1186
|
+
create(context) {
|
|
1187
|
+
if (!isIndexFile(context.filename)) {
|
|
1188
|
+
return {};
|
|
1189
|
+
}
|
|
1190
|
+
return {
|
|
1191
|
+
Program(node) {
|
|
1192
|
+
for (const statement of node.body) {
|
|
1193
|
+
if (!isAllowedTopLevel(statement)) {
|
|
1194
|
+
context.report({
|
|
1195
|
+
node: statement,
|
|
1196
|
+
messageId: "indexExportOnly"
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
var index_export_only_default = indexExportOnly;
|
|
1205
|
+
|
|
1206
|
+
// src/rules/jsx-newline-between-elements.ts
|
|
1207
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES14, ESLintUtils as ESLintUtils14 } from "@typescript-eslint/utils";
|
|
1208
|
+
var createRule14 = ESLintUtils14.RuleCreator(
|
|
1209
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1210
|
+
);
|
|
1211
|
+
var jsxNewlineBetweenElements = createRule14({
|
|
1150
1212
|
name: "jsx-newline-between-elements",
|
|
1151
1213
|
meta: {
|
|
1152
1214
|
type: "layout",
|
|
@@ -1164,7 +1226,7 @@ var jsxNewlineBetweenElements = createRule13({
|
|
|
1164
1226
|
create(context) {
|
|
1165
1227
|
const { sourceCode } = context;
|
|
1166
1228
|
function isSignificantJSXChild(node) {
|
|
1167
|
-
return node.type ===
|
|
1229
|
+
return node.type === AST_NODE_TYPES14.JSXElement || node.type === AST_NODE_TYPES14.JSXFragment || node.type === AST_NODE_TYPES14.JSXExpressionContainer;
|
|
1168
1230
|
}
|
|
1169
1231
|
function isMultiLine(node) {
|
|
1170
1232
|
return node.loc.start.line !== node.loc.end.line;
|
|
@@ -1214,11 +1276,11 @@ var jsxNewlineBetweenElements = createRule13({
|
|
|
1214
1276
|
var jsx_newline_between_elements_default = jsxNewlineBetweenElements;
|
|
1215
1277
|
|
|
1216
1278
|
// src/rules/jsx-no-inline-object-prop.ts
|
|
1217
|
-
import { AST_NODE_TYPES as
|
|
1218
|
-
var
|
|
1279
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15, ESLintUtils as ESLintUtils15 } from "@typescript-eslint/utils";
|
|
1280
|
+
var createRule15 = ESLintUtils15.RuleCreator(
|
|
1219
1281
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1220
1282
|
);
|
|
1221
|
-
var jsxNoInlineObjectProp =
|
|
1283
|
+
var jsxNoInlineObjectProp = createRule15({
|
|
1222
1284
|
name: "jsx-no-inline-object-prop",
|
|
1223
1285
|
meta: {
|
|
1224
1286
|
type: "suggestion",
|
|
@@ -1234,7 +1296,7 @@ var jsxNoInlineObjectProp = createRule14({
|
|
|
1234
1296
|
create(context) {
|
|
1235
1297
|
return {
|
|
1236
1298
|
JSXAttribute(node) {
|
|
1237
|
-
if (node.value?.type ===
|
|
1299
|
+
if (node.value?.type === AST_NODE_TYPES15.JSXExpressionContainer && node.value.expression.type === AST_NODE_TYPES15.ObjectExpression) {
|
|
1238
1300
|
context.report({
|
|
1239
1301
|
node: node.value,
|
|
1240
1302
|
messageId: "noInlineObject"
|
|
@@ -1247,17 +1309,17 @@ var jsxNoInlineObjectProp = createRule14({
|
|
|
1247
1309
|
var jsx_no_inline_object_prop_default = jsxNoInlineObjectProp;
|
|
1248
1310
|
|
|
1249
1311
|
// src/rules/jsx-no-newline-single-line-elements.ts
|
|
1250
|
-
import { AST_NODE_TYPES as
|
|
1251
|
-
var
|
|
1312
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES16, ESLintUtils as ESLintUtils16 } from "@typescript-eslint/utils";
|
|
1313
|
+
var createRule16 = ESLintUtils16.RuleCreator(
|
|
1252
1314
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1253
1315
|
);
|
|
1254
1316
|
function isJSXElementOrFragment(node) {
|
|
1255
|
-
return node.type ===
|
|
1317
|
+
return node.type === AST_NODE_TYPES16.JSXElement || node.type === AST_NODE_TYPES16.JSXFragment;
|
|
1256
1318
|
}
|
|
1257
1319
|
function isSingleLine(node) {
|
|
1258
1320
|
return node.loc.start.line === node.loc.end.line;
|
|
1259
1321
|
}
|
|
1260
|
-
var jsxNoNewlineSingleLineElements =
|
|
1322
|
+
var jsxNoNewlineSingleLineElements = createRule16({
|
|
1261
1323
|
name: "jsx-no-newline-single-line-elements",
|
|
1262
1324
|
meta: {
|
|
1263
1325
|
type: "layout",
|
|
@@ -1275,7 +1337,7 @@ var jsxNoNewlineSingleLineElements = createRule15({
|
|
|
1275
1337
|
const { sourceCode } = context;
|
|
1276
1338
|
function checkSiblings(children) {
|
|
1277
1339
|
const nonWhitespace = children.filter(
|
|
1278
|
-
(child) => !(child.type ===
|
|
1340
|
+
(child) => !(child.type === AST_NODE_TYPES16.JSXText && child.value.trim() === "")
|
|
1279
1341
|
);
|
|
1280
1342
|
nonWhitespace.forEach((next, index) => {
|
|
1281
1343
|
if (index === 0) {
|
|
@@ -1326,11 +1388,11 @@ ${indent}`);
|
|
|
1326
1388
|
var jsx_no_newline_single_line_elements_default = jsxNoNewlineSingleLineElements;
|
|
1327
1389
|
|
|
1328
1390
|
// src/rules/jsx-no-non-component-function.ts
|
|
1329
|
-
import { AST_NODE_TYPES as
|
|
1330
|
-
var
|
|
1391
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES17, ESLintUtils as ESLintUtils17 } from "@typescript-eslint/utils";
|
|
1392
|
+
var createRule17 = ESLintUtils17.RuleCreator(
|
|
1331
1393
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1332
1394
|
);
|
|
1333
|
-
var jsxNoNonComponentFunction =
|
|
1395
|
+
var jsxNoNonComponentFunction = createRule17({
|
|
1334
1396
|
name: "jsx-no-non-component-function",
|
|
1335
1397
|
meta: {
|
|
1336
1398
|
type: "problem",
|
|
@@ -1350,13 +1412,13 @@ var jsxNoNonComponentFunction = createRule16({
|
|
|
1350
1412
|
return {};
|
|
1351
1413
|
}
|
|
1352
1414
|
function isReactComponent2(node) {
|
|
1353
|
-
const functionName = node.type ===
|
|
1415
|
+
const functionName = node.type === AST_NODE_TYPES17.FunctionDeclaration && node.id ? node.id.name : null;
|
|
1354
1416
|
if (functionName && /^[A-Z]/.test(functionName)) {
|
|
1355
1417
|
return true;
|
|
1356
1418
|
}
|
|
1357
1419
|
if (node.returnType?.typeAnnotation) {
|
|
1358
1420
|
const returnTypeNode = node.returnType.typeAnnotation;
|
|
1359
|
-
if (returnTypeNode.type ===
|
|
1421
|
+
if (returnTypeNode.type === AST_NODE_TYPES17.TSTypeReference && returnTypeNode.typeName.type === AST_NODE_TYPES17.Identifier) {
|
|
1360
1422
|
const typeName = returnTypeNode.typeName.name;
|
|
1361
1423
|
if (typeName === "JSX" || typeName === "ReactElement" || typeName === "ReactNode") {
|
|
1362
1424
|
return true;
|
|
@@ -1373,13 +1435,13 @@ var jsxNoNonComponentFunction = createRule16({
|
|
|
1373
1435
|
if (!parent) {
|
|
1374
1436
|
return;
|
|
1375
1437
|
}
|
|
1376
|
-
if (parent.type ===
|
|
1438
|
+
if (parent.type === AST_NODE_TYPES17.ExportDefaultDeclaration || parent.type === AST_NODE_TYPES17.ExportNamedDeclaration) {
|
|
1377
1439
|
return;
|
|
1378
1440
|
}
|
|
1379
|
-
if (declaratorNode?.parent?.parent?.type ===
|
|
1441
|
+
if (declaratorNode?.parent?.parent?.type === AST_NODE_TYPES17.ExportNamedDeclaration) {
|
|
1380
1442
|
return;
|
|
1381
1443
|
}
|
|
1382
|
-
if (declaratorNode?.id.type ===
|
|
1444
|
+
if (declaratorNode?.id.type === AST_NODE_TYPES17.Identifier) {
|
|
1383
1445
|
const varName = declaratorNode.id.name;
|
|
1384
1446
|
if (/^[A-Z]/.test(varName)) {
|
|
1385
1447
|
return;
|
|
@@ -1404,20 +1466,20 @@ var jsxNoNonComponentFunction = createRule16({
|
|
|
1404
1466
|
var jsx_no_non_component_function_default = jsxNoNonComponentFunction;
|
|
1405
1467
|
|
|
1406
1468
|
// src/rules/jsx-no-ternary-null.ts
|
|
1407
|
-
import { AST_NODE_TYPES as
|
|
1408
|
-
var
|
|
1469
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18, ESLintUtils as ESLintUtils18 } from "@typescript-eslint/utils";
|
|
1470
|
+
var createRule18 = ESLintUtils18.RuleCreator(
|
|
1409
1471
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1410
1472
|
);
|
|
1411
1473
|
function isNullOrUndefined(node) {
|
|
1412
|
-
if (node.type ===
|
|
1474
|
+
if (node.type === AST_NODE_TYPES18.Literal && node.value === null) {
|
|
1413
1475
|
return true;
|
|
1414
1476
|
}
|
|
1415
|
-
if (node.type ===
|
|
1477
|
+
if (node.type === AST_NODE_TYPES18.Identifier && node.name === "undefined") {
|
|
1416
1478
|
return true;
|
|
1417
1479
|
}
|
|
1418
1480
|
return false;
|
|
1419
1481
|
}
|
|
1420
|
-
var jsxNoTernaryNull =
|
|
1482
|
+
var jsxNoTernaryNull = createRule18({
|
|
1421
1483
|
name: "jsx-no-ternary-null",
|
|
1422
1484
|
meta: {
|
|
1423
1485
|
type: "suggestion",
|
|
@@ -1435,7 +1497,7 @@ var jsxNoTernaryNull = createRule17({
|
|
|
1435
1497
|
return {
|
|
1436
1498
|
JSXExpressionContainer(node) {
|
|
1437
1499
|
const { expression } = node;
|
|
1438
|
-
if (expression.type !==
|
|
1500
|
+
if (expression.type !== AST_NODE_TYPES18.ConditionalExpression) {
|
|
1439
1501
|
return;
|
|
1440
1502
|
}
|
|
1441
1503
|
const { test, consequent, alternate } = expression;
|
|
@@ -1467,11 +1529,11 @@ var jsxNoTernaryNull = createRule17({
|
|
|
1467
1529
|
var jsx_no_ternary_null_default = jsxNoTernaryNull;
|
|
1468
1530
|
|
|
1469
1531
|
// src/rules/jsx-no-variable-in-callback.ts
|
|
1470
|
-
import { AST_NODE_TYPES as
|
|
1471
|
-
var
|
|
1532
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES19, ESLintUtils as ESLintUtils19 } from "@typescript-eslint/utils";
|
|
1533
|
+
var createRule19 = ESLintUtils19.RuleCreator(
|
|
1472
1534
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1473
1535
|
);
|
|
1474
|
-
var jsxNoVariableInCallback =
|
|
1536
|
+
var jsxNoVariableInCallback = createRule19({
|
|
1475
1537
|
name: "jsx-no-variable-in-callback",
|
|
1476
1538
|
meta: {
|
|
1477
1539
|
type: "suggestion",
|
|
@@ -1488,7 +1550,7 @@ var jsxNoVariableInCallback = createRule18({
|
|
|
1488
1550
|
function isInsideJSX(node) {
|
|
1489
1551
|
let current = node.parent;
|
|
1490
1552
|
while (current) {
|
|
1491
|
-
if (current.type ===
|
|
1553
|
+
if (current.type === AST_NODE_TYPES19.JSXElement || current.type === AST_NODE_TYPES19.JSXFragment) {
|
|
1492
1554
|
return true;
|
|
1493
1555
|
}
|
|
1494
1556
|
current = current.parent;
|
|
@@ -1502,11 +1564,11 @@ var jsxNoVariableInCallback = createRule18({
|
|
|
1502
1564
|
if (!isInsideJSX(node)) {
|
|
1503
1565
|
return false;
|
|
1504
1566
|
}
|
|
1505
|
-
if (node.parent.type ===
|
|
1567
|
+
if (node.parent.type === AST_NODE_TYPES19.CallExpression || node.parent.type === AST_NODE_TYPES19.JSXExpressionContainer) {
|
|
1506
1568
|
return true;
|
|
1507
1569
|
}
|
|
1508
|
-
if (node.parent.type ===
|
|
1509
|
-
if (node.parent.parent.type ===
|
|
1570
|
+
if (node.parent.type === AST_NODE_TYPES19.ArrayExpression && node.parent.parent) {
|
|
1571
|
+
if (node.parent.parent.type === AST_NODE_TYPES19.CallExpression || node.parent.parent.type === AST_NODE_TYPES19.JSXExpressionContainer) {
|
|
1510
1572
|
return true;
|
|
1511
1573
|
}
|
|
1512
1574
|
}
|
|
@@ -1517,11 +1579,11 @@ var jsxNoVariableInCallback = createRule18({
|
|
|
1517
1579
|
return;
|
|
1518
1580
|
}
|
|
1519
1581
|
const { body } = node;
|
|
1520
|
-
if (body.type !==
|
|
1582
|
+
if (body.type !== AST_NODE_TYPES19.BlockStatement) {
|
|
1521
1583
|
return;
|
|
1522
1584
|
}
|
|
1523
1585
|
body.body.forEach((statement) => {
|
|
1524
|
-
if (statement.type ===
|
|
1586
|
+
if (statement.type === AST_NODE_TYPES19.VariableDeclaration) {
|
|
1525
1587
|
context.report({
|
|
1526
1588
|
node: statement,
|
|
1527
1589
|
messageId: "noVariableInCallback"
|
|
@@ -1539,12 +1601,12 @@ var jsx_no_variable_in_callback_default = jsxNoVariableInCallback;
|
|
|
1539
1601
|
|
|
1540
1602
|
// src/rules/jsx-pascal-case.ts
|
|
1541
1603
|
import path4 from "path";
|
|
1542
|
-
import { ESLintUtils as
|
|
1543
|
-
var
|
|
1604
|
+
import { ESLintUtils as ESLintUtils20 } from "@typescript-eslint/utils";
|
|
1605
|
+
var createRule20 = ESLintUtils20.RuleCreator(
|
|
1544
1606
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1545
1607
|
);
|
|
1546
1608
|
var isPascalCase = (str) => /^[A-Z][a-zA-Z0-9]*$/.test(str) && !/^[A-Z]+$/.test(str);
|
|
1547
|
-
var jsxPascalCase =
|
|
1609
|
+
var jsxPascalCase = createRule20({
|
|
1548
1610
|
name: "jsx-pascal-case",
|
|
1549
1611
|
meta: {
|
|
1550
1612
|
type: "problem",
|
|
@@ -1579,11 +1641,11 @@ var jsxPascalCase = createRule19({
|
|
|
1579
1641
|
var jsx_pascal_case_default = jsxPascalCase;
|
|
1580
1642
|
|
|
1581
1643
|
// src/rules/jsx-require-suspense.ts
|
|
1582
|
-
import { AST_NODE_TYPES as
|
|
1583
|
-
var
|
|
1644
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES20, ESLintUtils as ESLintUtils21 } from "@typescript-eslint/utils";
|
|
1645
|
+
var createRule21 = ESLintUtils21.RuleCreator(
|
|
1584
1646
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1585
1647
|
);
|
|
1586
|
-
var jsxRequireSuspense =
|
|
1648
|
+
var jsxRequireSuspense = createRule21({
|
|
1587
1649
|
name: "jsx-require-suspense",
|
|
1588
1650
|
meta: {
|
|
1589
1651
|
type: "problem",
|
|
@@ -1601,7 +1663,7 @@ var jsxRequireSuspense = createRule20({
|
|
|
1601
1663
|
const isInsideSuspense = (node) => {
|
|
1602
1664
|
let current = node.parent;
|
|
1603
1665
|
while (current) {
|
|
1604
|
-
if (current.type ===
|
|
1666
|
+
if (current.type === AST_NODE_TYPES20.JSXElement && current.openingElement.name.type === AST_NODE_TYPES20.JSXIdentifier && current.openingElement.name.name === "Suspense") {
|
|
1605
1667
|
return true;
|
|
1606
1668
|
}
|
|
1607
1669
|
current = current.parent;
|
|
@@ -1610,16 +1672,16 @@ var jsxRequireSuspense = createRule20({
|
|
|
1610
1672
|
};
|
|
1611
1673
|
return {
|
|
1612
1674
|
VariableDeclarator(node) {
|
|
1613
|
-
if (node.id.type ===
|
|
1675
|
+
if (node.id.type === AST_NODE_TYPES20.Identifier && node.init?.type === AST_NODE_TYPES20.CallExpression) {
|
|
1614
1676
|
const { callee } = node.init;
|
|
1615
|
-
const isLazyCall = callee.type ===
|
|
1677
|
+
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
1678
|
if (isLazyCall) {
|
|
1617
1679
|
lazyComponents.add(node.id.name);
|
|
1618
1680
|
}
|
|
1619
1681
|
}
|
|
1620
1682
|
},
|
|
1621
1683
|
JSXOpeningElement(node) {
|
|
1622
|
-
if (node.name.type ===
|
|
1684
|
+
if (node.name.type === AST_NODE_TYPES20.JSXIdentifier) {
|
|
1623
1685
|
const componentName = node.name.name;
|
|
1624
1686
|
if (lazyComponents.has(componentName) && !isInsideSuspense(node)) {
|
|
1625
1687
|
context.report({
|
|
@@ -1638,11 +1700,11 @@ var jsxRequireSuspense = createRule20({
|
|
|
1638
1700
|
var jsx_require_suspense_default = jsxRequireSuspense;
|
|
1639
1701
|
|
|
1640
1702
|
// src/rules/jsx-simple-props.ts
|
|
1641
|
-
import { AST_NODE_TYPES as
|
|
1642
|
-
var
|
|
1703
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21, ESLintUtils as ESLintUtils22 } from "@typescript-eslint/utils";
|
|
1704
|
+
var createRule22 = ESLintUtils22.RuleCreator(
|
|
1643
1705
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1644
1706
|
);
|
|
1645
|
-
var jsxSimpleProps =
|
|
1707
|
+
var jsxSimpleProps = createRule22({
|
|
1646
1708
|
name: "jsx-simple-props",
|
|
1647
1709
|
meta: {
|
|
1648
1710
|
type: "suggestion",
|
|
@@ -1657,25 +1719,25 @@ var jsxSimpleProps = createRule21({
|
|
|
1657
1719
|
defaultOptions: [],
|
|
1658
1720
|
create(context) {
|
|
1659
1721
|
const allowedExpressionTypes = /* @__PURE__ */ new Set([
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1722
|
+
AST_NODE_TYPES21.Identifier,
|
|
1723
|
+
AST_NODE_TYPES21.Literal,
|
|
1724
|
+
AST_NODE_TYPES21.JSXElement,
|
|
1725
|
+
AST_NODE_TYPES21.JSXFragment,
|
|
1726
|
+
AST_NODE_TYPES21.MemberExpression,
|
|
1727
|
+
AST_NODE_TYPES21.ArrowFunctionExpression,
|
|
1728
|
+
AST_NODE_TYPES21.FunctionExpression
|
|
1667
1729
|
]);
|
|
1668
1730
|
return {
|
|
1669
1731
|
JSXAttribute(node) {
|
|
1670
1732
|
if (!node.value) {
|
|
1671
1733
|
return;
|
|
1672
1734
|
}
|
|
1673
|
-
if (node.value.type ===
|
|
1735
|
+
if (node.value.type === AST_NODE_TYPES21.Literal) {
|
|
1674
1736
|
return;
|
|
1675
1737
|
}
|
|
1676
|
-
if (node.value.type ===
|
|
1738
|
+
if (node.value.type === AST_NODE_TYPES21.JSXExpressionContainer) {
|
|
1677
1739
|
const { expression } = node.value;
|
|
1678
|
-
if (expression.type ===
|
|
1740
|
+
if (expression.type === AST_NODE_TYPES21.JSXEmptyExpression) {
|
|
1679
1741
|
return;
|
|
1680
1742
|
}
|
|
1681
1743
|
if (!allowedExpressionTypes.has(expression.type)) {
|
|
@@ -1692,8 +1754,8 @@ var jsxSimpleProps = createRule21({
|
|
|
1692
1754
|
var jsx_simple_props_default = jsxSimpleProps;
|
|
1693
1755
|
|
|
1694
1756
|
// src/rules/jsx-sort-props.ts
|
|
1695
|
-
import { AST_NODE_TYPES as
|
|
1696
|
-
var
|
|
1757
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22, ESLintUtils as ESLintUtils23 } from "@typescript-eslint/utils";
|
|
1758
|
+
var createRule23 = ESLintUtils23.RuleCreator(
|
|
1697
1759
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1698
1760
|
);
|
|
1699
1761
|
var TYPE_GROUP = {
|
|
@@ -1707,15 +1769,15 @@ var TYPE_GROUP = {
|
|
|
1707
1769
|
SHORTHAND: 8
|
|
1708
1770
|
};
|
|
1709
1771
|
var EXPRESSION_TYPE_TO_GROUP = /* @__PURE__ */ new Map([
|
|
1710
|
-
[
|
|
1711
|
-
[
|
|
1712
|
-
[
|
|
1713
|
-
[
|
|
1714
|
-
[
|
|
1715
|
-
[
|
|
1772
|
+
[AST_NODE_TYPES22.ObjectExpression, TYPE_GROUP.OBJECT_ARRAY],
|
|
1773
|
+
[AST_NODE_TYPES22.ArrayExpression, TYPE_GROUP.OBJECT_ARRAY],
|
|
1774
|
+
[AST_NODE_TYPES22.ArrowFunctionExpression, TYPE_GROUP.FUNCTION],
|
|
1775
|
+
[AST_NODE_TYPES22.FunctionExpression, TYPE_GROUP.FUNCTION],
|
|
1776
|
+
[AST_NODE_TYPES22.JSXElement, TYPE_GROUP.JSX],
|
|
1777
|
+
[AST_NODE_TYPES22.JSXFragment, TYPE_GROUP.JSX]
|
|
1716
1778
|
]);
|
|
1717
1779
|
function isHyphenatedName(node) {
|
|
1718
|
-
return node.name.type ===
|
|
1780
|
+
return node.name.type === AST_NODE_TYPES22.JSXIdentifier && node.name.name.includes("-");
|
|
1719
1781
|
}
|
|
1720
1782
|
function getStringGroup(node) {
|
|
1721
1783
|
return isHyphenatedName(node) ? TYPE_GROUP.HYPHENATED_STRING : TYPE_GROUP.STRING;
|
|
@@ -1727,13 +1789,13 @@ function getLiteralValueGroup(value) {
|
|
|
1727
1789
|
return TYPE_GROUP.NUMBER_BOOLEAN_NULL;
|
|
1728
1790
|
}
|
|
1729
1791
|
function getExpressionGroup(expression) {
|
|
1730
|
-
if (expression.type ===
|
|
1792
|
+
if (expression.type === AST_NODE_TYPES22.Literal) {
|
|
1731
1793
|
return getLiteralValueGroup(expression.value);
|
|
1732
1794
|
}
|
|
1733
|
-
if (expression.type ===
|
|
1795
|
+
if (expression.type === AST_NODE_TYPES22.TemplateLiteral) {
|
|
1734
1796
|
return null;
|
|
1735
1797
|
}
|
|
1736
|
-
if (expression.type ===
|
|
1798
|
+
if (expression.type === AST_NODE_TYPES22.Identifier && expression.name === "undefined") {
|
|
1737
1799
|
return TYPE_GROUP.NUMBER_BOOLEAN_NULL;
|
|
1738
1800
|
}
|
|
1739
1801
|
return EXPRESSION_TYPE_TO_GROUP.get(expression.type) ?? TYPE_GROUP.EXPRESSION;
|
|
@@ -1742,17 +1804,17 @@ function getTypeGroup(node) {
|
|
|
1742
1804
|
if (node.value === null) {
|
|
1743
1805
|
return TYPE_GROUP.SHORTHAND;
|
|
1744
1806
|
}
|
|
1745
|
-
if (node.value.type ===
|
|
1807
|
+
if (node.value.type === AST_NODE_TYPES22.Literal) {
|
|
1746
1808
|
if (typeof node.value.value === "string") {
|
|
1747
1809
|
return getStringGroup(node);
|
|
1748
1810
|
}
|
|
1749
1811
|
return TYPE_GROUP.NUMBER_BOOLEAN_NULL;
|
|
1750
1812
|
}
|
|
1751
|
-
if (node.value.type !==
|
|
1813
|
+
if (node.value.type !== AST_NODE_TYPES22.JSXExpressionContainer) {
|
|
1752
1814
|
return null;
|
|
1753
1815
|
}
|
|
1754
1816
|
const { expression } = node.value;
|
|
1755
|
-
if (expression.type ===
|
|
1817
|
+
if (expression.type === AST_NODE_TYPES22.JSXEmptyExpression) {
|
|
1756
1818
|
return null;
|
|
1757
1819
|
}
|
|
1758
1820
|
const group = getExpressionGroup(expression);
|
|
@@ -1764,7 +1826,7 @@ function getTypeGroup(node) {
|
|
|
1764
1826
|
function hasUnsortedProps(attributes) {
|
|
1765
1827
|
let lastGroup = 0;
|
|
1766
1828
|
return attributes.some((attribute) => {
|
|
1767
|
-
if (attribute.type ===
|
|
1829
|
+
if (attribute.type === AST_NODE_TYPES22.JSXSpreadAttribute) {
|
|
1768
1830
|
lastGroup = 0;
|
|
1769
1831
|
return false;
|
|
1770
1832
|
}
|
|
@@ -1788,7 +1850,7 @@ function getSegments(attributes) {
|
|
|
1788
1850
|
const result = [];
|
|
1789
1851
|
let current = [];
|
|
1790
1852
|
attributes.forEach((attr) => {
|
|
1791
|
-
if (attr.type ===
|
|
1853
|
+
if (attr.type === AST_NODE_TYPES22.JSXSpreadAttribute) {
|
|
1792
1854
|
if (current.length > 0) {
|
|
1793
1855
|
result.push(current);
|
|
1794
1856
|
current = [];
|
|
@@ -1802,7 +1864,7 @@ function getSegments(attributes) {
|
|
|
1802
1864
|
}
|
|
1803
1865
|
return result;
|
|
1804
1866
|
}
|
|
1805
|
-
var jsxSortProps =
|
|
1867
|
+
var jsxSortProps = createRule23({
|
|
1806
1868
|
name: "jsx-sort-props",
|
|
1807
1869
|
meta: {
|
|
1808
1870
|
type: "suggestion",
|
|
@@ -1837,11 +1899,11 @@ var jsxSortProps = createRule22({
|
|
|
1837
1899
|
var jsx_sort_props_default = jsxSortProps;
|
|
1838
1900
|
|
|
1839
1901
|
// src/rules/jsx-spread-props-last.ts
|
|
1840
|
-
import { AST_NODE_TYPES as
|
|
1841
|
-
var
|
|
1902
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23, ESLintUtils as ESLintUtils24 } from "@typescript-eslint/utils";
|
|
1903
|
+
var createRule24 = ESLintUtils24.RuleCreator(
|
|
1842
1904
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1843
1905
|
);
|
|
1844
|
-
var jsxSpreadPropsLast =
|
|
1906
|
+
var jsxSpreadPropsLast = createRule24({
|
|
1845
1907
|
name: "jsx-spread-props-last",
|
|
1846
1908
|
meta: {
|
|
1847
1909
|
type: "suggestion",
|
|
@@ -1860,12 +1922,12 @@ var jsxSpreadPropsLast = createRule23({
|
|
|
1860
1922
|
const { attributes } = node;
|
|
1861
1923
|
let lastNonSpreadIndex = -1;
|
|
1862
1924
|
attributes.forEach((attribute, index) => {
|
|
1863
|
-
if (attribute.type !==
|
|
1925
|
+
if (attribute.type !== AST_NODE_TYPES23.JSXSpreadAttribute) {
|
|
1864
1926
|
lastNonSpreadIndex = index;
|
|
1865
1927
|
}
|
|
1866
1928
|
});
|
|
1867
1929
|
attributes.forEach((attribute, index) => {
|
|
1868
|
-
if (attribute.type ===
|
|
1930
|
+
if (attribute.type === AST_NODE_TYPES23.JSXSpreadAttribute && index < lastNonSpreadIndex) {
|
|
1869
1931
|
context.report({
|
|
1870
1932
|
node: attribute,
|
|
1871
1933
|
messageId: "spreadNotLast"
|
|
@@ -1879,12 +1941,12 @@ var jsxSpreadPropsLast = createRule23({
|
|
|
1879
1941
|
var jsx_spread_props_last_default = jsxSpreadPropsLast;
|
|
1880
1942
|
|
|
1881
1943
|
// src/rules/newline-after-multiline-block.ts
|
|
1882
|
-
import { AST_NODE_TYPES as
|
|
1883
|
-
var
|
|
1944
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24, ESLintUtils as ESLintUtils25 } from "@typescript-eslint/utils";
|
|
1945
|
+
var createRule25 = ESLintUtils25.RuleCreator(
|
|
1884
1946
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1885
1947
|
);
|
|
1886
1948
|
function isImportDeclaration(node) {
|
|
1887
|
-
return node.type ===
|
|
1949
|
+
return node.type === AST_NODE_TYPES24.ImportDeclaration;
|
|
1888
1950
|
}
|
|
1889
1951
|
function checkStatements(statements, context) {
|
|
1890
1952
|
const { sourceCode } = context;
|
|
@@ -1919,7 +1981,7 @@ function checkStatements(statements, context) {
|
|
|
1919
1981
|
}
|
|
1920
1982
|
});
|
|
1921
1983
|
}
|
|
1922
|
-
var newlineAfterMultilineBlock =
|
|
1984
|
+
var newlineAfterMultilineBlock = createRule25({
|
|
1923
1985
|
name: "newline-after-multiline-block",
|
|
1924
1986
|
meta: {
|
|
1925
1987
|
type: "layout",
|
|
@@ -1947,11 +2009,11 @@ var newlineAfterMultilineBlock = createRule24({
|
|
|
1947
2009
|
var newline_after_multiline_block_default = newlineAfterMultilineBlock;
|
|
1948
2010
|
|
|
1949
2011
|
// src/rules/newline-before-return.ts
|
|
1950
|
-
import { AST_NODE_TYPES as
|
|
1951
|
-
var
|
|
2012
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25, ESLintUtils as ESLintUtils26 } from "@typescript-eslint/utils";
|
|
2013
|
+
var createRule26 = ESLintUtils26.RuleCreator(
|
|
1952
2014
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1953
2015
|
);
|
|
1954
|
-
var newlineBeforeReturn =
|
|
2016
|
+
var newlineBeforeReturn = createRule26({
|
|
1955
2017
|
name: "newline-before-return",
|
|
1956
2018
|
meta: {
|
|
1957
2019
|
type: "layout",
|
|
@@ -1969,7 +2031,7 @@ var newlineBeforeReturn = createRule25({
|
|
|
1969
2031
|
const { sourceCode } = context;
|
|
1970
2032
|
function checkReturnStatement(node) {
|
|
1971
2033
|
const { parent } = node;
|
|
1972
|
-
if (!parent || parent.type !==
|
|
2034
|
+
if (!parent || parent.type !== AST_NODE_TYPES25.BlockStatement) {
|
|
1973
2035
|
return;
|
|
1974
2036
|
}
|
|
1975
2037
|
const { body: statements } = parent;
|
|
@@ -2006,11 +2068,11 @@ var newlineBeforeReturn = createRule25({
|
|
|
2006
2068
|
var newline_before_return_default = newlineBeforeReturn;
|
|
2007
2069
|
|
|
2008
2070
|
// src/rules/nextjs-require-public-env.ts
|
|
2009
|
-
import { AST_NODE_TYPES as
|
|
2010
|
-
var
|
|
2071
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26, ESLintUtils as ESLintUtils27 } from "@typescript-eslint/utils";
|
|
2072
|
+
var createRule27 = ESLintUtils27.RuleCreator(
|
|
2011
2073
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2012
2074
|
);
|
|
2013
|
-
var nextjsRequirePublicEnv =
|
|
2075
|
+
var nextjsRequirePublicEnv = createRule27({
|
|
2014
2076
|
name: "nextjs-require-public-env",
|
|
2015
2077
|
meta: {
|
|
2016
2078
|
type: "problem",
|
|
@@ -2028,7 +2090,7 @@ var nextjsRequirePublicEnv = createRule26({
|
|
|
2028
2090
|
return {
|
|
2029
2091
|
Program(node) {
|
|
2030
2092
|
const firstStatement = node.body[0];
|
|
2031
|
-
if (firstStatement?.type ===
|
|
2093
|
+
if (firstStatement?.type === AST_NODE_TYPES26.ExpressionStatement && firstStatement.expression.type === AST_NODE_TYPES26.Literal && firstStatement.expression.value === "use client") {
|
|
2032
2094
|
isClientComponent = true;
|
|
2033
2095
|
}
|
|
2034
2096
|
},
|
|
@@ -2036,7 +2098,7 @@ var nextjsRequirePublicEnv = createRule26({
|
|
|
2036
2098
|
if (!isClientComponent) {
|
|
2037
2099
|
return;
|
|
2038
2100
|
}
|
|
2039
|
-
if (node.object.type ===
|
|
2101
|
+
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
2102
|
const envVarName = node.property.name;
|
|
2041
2103
|
if (!envVarName.startsWith("NEXT_PUBLIC_") && envVarName !== "NODE_ENV") {
|
|
2042
2104
|
context.report({
|
|
@@ -2055,11 +2117,11 @@ var nextjsRequirePublicEnv = createRule26({
|
|
|
2055
2117
|
var nextjs_require_public_env_default = nextjsRequirePublicEnv;
|
|
2056
2118
|
|
|
2057
2119
|
// src/rules/no-complex-inline-return.ts
|
|
2058
|
-
import { AST_NODE_TYPES as
|
|
2059
|
-
var
|
|
2120
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27, ESLintUtils as ESLintUtils28 } from "@typescript-eslint/utils";
|
|
2121
|
+
var createRule28 = ESLintUtils28.RuleCreator(
|
|
2060
2122
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2061
2123
|
);
|
|
2062
|
-
var noComplexInlineReturn =
|
|
2124
|
+
var noComplexInlineReturn = createRule28({
|
|
2063
2125
|
name: "no-complex-inline-return",
|
|
2064
2126
|
meta: {
|
|
2065
2127
|
type: "suggestion",
|
|
@@ -2075,13 +2137,13 @@ var noComplexInlineReturn = createRule27({
|
|
|
2075
2137
|
create(context) {
|
|
2076
2138
|
const isComplexExpression = (node) => {
|
|
2077
2139
|
if (!node) return false;
|
|
2078
|
-
if (node.type ===
|
|
2140
|
+
if (node.type === AST_NODE_TYPES27.ConditionalExpression) {
|
|
2079
2141
|
return true;
|
|
2080
2142
|
}
|
|
2081
|
-
if (node.type ===
|
|
2143
|
+
if (node.type === AST_NODE_TYPES27.LogicalExpression) {
|
|
2082
2144
|
return true;
|
|
2083
2145
|
}
|
|
2084
|
-
if (node.type ===
|
|
2146
|
+
if (node.type === AST_NODE_TYPES27.NewExpression) {
|
|
2085
2147
|
return true;
|
|
2086
2148
|
}
|
|
2087
2149
|
return false;
|
|
@@ -2101,11 +2163,11 @@ var noComplexInlineReturn = createRule27({
|
|
|
2101
2163
|
var no_complex_inline_return_default = noComplexInlineReturn;
|
|
2102
2164
|
|
|
2103
2165
|
// src/rules/no-direct-date.ts
|
|
2104
|
-
import { AST_NODE_TYPES as
|
|
2105
|
-
var
|
|
2166
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28, ESLintUtils as ESLintUtils29 } from "@typescript-eslint/utils";
|
|
2167
|
+
var createRule29 = ESLintUtils29.RuleCreator(
|
|
2106
2168
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2107
2169
|
);
|
|
2108
|
-
var noDirectDate =
|
|
2170
|
+
var noDirectDate = createRule29({
|
|
2109
2171
|
name: "no-direct-date",
|
|
2110
2172
|
meta: {
|
|
2111
2173
|
type: "problem",
|
|
@@ -2123,7 +2185,7 @@ var noDirectDate = createRule28({
|
|
|
2123
2185
|
create(context) {
|
|
2124
2186
|
return {
|
|
2125
2187
|
NewExpression(node) {
|
|
2126
|
-
if (node.callee.type ===
|
|
2188
|
+
if (node.callee.type === AST_NODE_TYPES28.Identifier && node.callee.name === "Date") {
|
|
2127
2189
|
context.report({
|
|
2128
2190
|
node,
|
|
2129
2191
|
messageId: "noNewDate"
|
|
@@ -2131,7 +2193,7 @@ var noDirectDate = createRule28({
|
|
|
2131
2193
|
}
|
|
2132
2194
|
},
|
|
2133
2195
|
CallExpression(node) {
|
|
2134
|
-
if (node.callee.type ===
|
|
2196
|
+
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
2197
|
const methodName = node.callee.property.name;
|
|
2136
2198
|
if (methodName === "now") {
|
|
2137
2199
|
context.report({
|
|
@@ -2154,11 +2216,11 @@ var no_direct_date_default = noDirectDate;
|
|
|
2154
2216
|
|
|
2155
2217
|
// src/rules/no-emoji.ts
|
|
2156
2218
|
import emojiRegex from "emoji-regex";
|
|
2157
|
-
import { ESLintUtils as
|
|
2158
|
-
var
|
|
2219
|
+
import { ESLintUtils as ESLintUtils30 } from "@typescript-eslint/utils";
|
|
2220
|
+
var createRule30 = ESLintUtils30.RuleCreator(
|
|
2159
2221
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2160
2222
|
);
|
|
2161
|
-
var noEmoji =
|
|
2223
|
+
var noEmoji = createRule30({
|
|
2162
2224
|
name: "no-emoji",
|
|
2163
2225
|
meta: {
|
|
2164
2226
|
type: "problem",
|
|
@@ -2192,11 +2254,11 @@ var noEmoji = createRule29({
|
|
|
2192
2254
|
var no_emoji_default = noEmoji;
|
|
2193
2255
|
|
|
2194
2256
|
// src/rules/no-env-fallback.ts
|
|
2195
|
-
import { AST_NODE_TYPES as
|
|
2196
|
-
var
|
|
2257
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29, ESLintUtils as ESLintUtils31 } from "@typescript-eslint/utils";
|
|
2258
|
+
var createRule31 = ESLintUtils31.RuleCreator(
|
|
2197
2259
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2198
2260
|
);
|
|
2199
|
-
var noEnvFallback =
|
|
2261
|
+
var noEnvFallback = createRule31({
|
|
2200
2262
|
name: "no-env-fallback",
|
|
2201
2263
|
meta: {
|
|
2202
2264
|
type: "problem",
|
|
@@ -2211,16 +2273,16 @@ var noEnvFallback = createRule30({
|
|
|
2211
2273
|
defaultOptions: [],
|
|
2212
2274
|
create(context) {
|
|
2213
2275
|
const isProcessEnvAccess = (node) => {
|
|
2214
|
-
if (node.type !==
|
|
2276
|
+
if (node.type !== AST_NODE_TYPES29.MemberExpression) {
|
|
2215
2277
|
return false;
|
|
2216
2278
|
}
|
|
2217
2279
|
const { object } = node;
|
|
2218
|
-
if (object.type !==
|
|
2280
|
+
if (object.type !== AST_NODE_TYPES29.MemberExpression) {
|
|
2219
2281
|
return false;
|
|
2220
2282
|
}
|
|
2221
2283
|
const processNode = object.object;
|
|
2222
2284
|
const envNode = object.property;
|
|
2223
|
-
return processNode.type ===
|
|
2285
|
+
return processNode.type === AST_NODE_TYPES29.Identifier && processNode.name === "process" && envNode.type === AST_NODE_TYPES29.Identifier && envNode.name === "env";
|
|
2224
2286
|
};
|
|
2225
2287
|
return {
|
|
2226
2288
|
LogicalExpression(node) {
|
|
@@ -2245,11 +2307,11 @@ var noEnvFallback = createRule30({
|
|
|
2245
2307
|
var no_env_fallback_default = noEnvFallback;
|
|
2246
2308
|
|
|
2247
2309
|
// src/rules/no-inline-default-export.ts
|
|
2248
|
-
import { AST_NODE_TYPES as
|
|
2249
|
-
var
|
|
2310
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30, ESLintUtils as ESLintUtils32 } from "@typescript-eslint/utils";
|
|
2311
|
+
var createRule32 = ESLintUtils32.RuleCreator(
|
|
2250
2312
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2251
2313
|
);
|
|
2252
|
-
var noInlineDefaultExport =
|
|
2314
|
+
var noInlineDefaultExport = createRule32({
|
|
2253
2315
|
name: "no-inline-default-export",
|
|
2254
2316
|
meta: {
|
|
2255
2317
|
type: "suggestion",
|
|
@@ -2268,7 +2330,7 @@ var noInlineDefaultExport = createRule31({
|
|
|
2268
2330
|
return {
|
|
2269
2331
|
ExportDefaultDeclaration(node) {
|
|
2270
2332
|
const { declaration } = node;
|
|
2271
|
-
if (declaration.type ===
|
|
2333
|
+
if (declaration.type === AST_NODE_TYPES30.FunctionDeclaration) {
|
|
2272
2334
|
if (declaration.id) {
|
|
2273
2335
|
context.report({
|
|
2274
2336
|
node,
|
|
@@ -2283,7 +2345,7 @@ var noInlineDefaultExport = createRule31({
|
|
|
2283
2345
|
});
|
|
2284
2346
|
}
|
|
2285
2347
|
}
|
|
2286
|
-
if (declaration.type ===
|
|
2348
|
+
if (declaration.type === AST_NODE_TYPES30.ClassDeclaration) {
|
|
2287
2349
|
if (declaration.id) {
|
|
2288
2350
|
context.report({
|
|
2289
2351
|
node,
|
|
@@ -2298,7 +2360,7 @@ var noInlineDefaultExport = createRule31({
|
|
|
2298
2360
|
});
|
|
2299
2361
|
}
|
|
2300
2362
|
}
|
|
2301
|
-
if (declaration.type ===
|
|
2363
|
+
if (declaration.type === AST_NODE_TYPES30.ArrowFunctionExpression || declaration.type === AST_NODE_TYPES30.FunctionExpression) {
|
|
2302
2364
|
context.report({
|
|
2303
2365
|
node,
|
|
2304
2366
|
messageId: "noAnonymousDefaultExport",
|
|
@@ -2311,14 +2373,14 @@ var noInlineDefaultExport = createRule31({
|
|
|
2311
2373
|
if (!declaration) {
|
|
2312
2374
|
return;
|
|
2313
2375
|
}
|
|
2314
|
-
if (declaration.type ===
|
|
2376
|
+
if (declaration.type === AST_NODE_TYPES30.FunctionDeclaration && declaration.id) {
|
|
2315
2377
|
context.report({
|
|
2316
2378
|
node,
|
|
2317
2379
|
messageId: "noInlineNamedExport",
|
|
2318
2380
|
data: { type: "function", name: declaration.id.name }
|
|
2319
2381
|
});
|
|
2320
2382
|
}
|
|
2321
|
-
if (declaration.type ===
|
|
2383
|
+
if (declaration.type === AST_NODE_TYPES30.ClassDeclaration && declaration.id) {
|
|
2322
2384
|
context.report({
|
|
2323
2385
|
node,
|
|
2324
2386
|
messageId: "noInlineNamedExport",
|
|
@@ -2332,15 +2394,15 @@ var noInlineDefaultExport = createRule31({
|
|
|
2332
2394
|
var no_inline_default_export_default = noInlineDefaultExport;
|
|
2333
2395
|
|
|
2334
2396
|
// src/rules/no-inline-nested-object.ts
|
|
2335
|
-
import { AST_NODE_TYPES as
|
|
2336
|
-
var
|
|
2397
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31, ESLintUtils as ESLintUtils33 } from "@typescript-eslint/utils";
|
|
2398
|
+
var createRule33 = ESLintUtils33.RuleCreator(
|
|
2337
2399
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2338
2400
|
);
|
|
2339
2401
|
function isObjectOrArray(node) {
|
|
2340
|
-
return node.type ===
|
|
2402
|
+
return node.type === AST_NODE_TYPES31.ObjectExpression || node.type === AST_NODE_TYPES31.ArrayExpression || node.type === AST_NODE_TYPES31.TSAsExpression;
|
|
2341
2403
|
}
|
|
2342
2404
|
function getInnerExpression(node) {
|
|
2343
|
-
if (node.type ===
|
|
2405
|
+
if (node.type === AST_NODE_TYPES31.TSAsExpression) {
|
|
2344
2406
|
return getInnerExpression(node.expression);
|
|
2345
2407
|
}
|
|
2346
2408
|
return node;
|
|
@@ -2349,10 +2411,10 @@ function arrayContainsOnlyPrimitives(node) {
|
|
|
2349
2411
|
return node.elements.every((el) => {
|
|
2350
2412
|
if (el === null) return true;
|
|
2351
2413
|
const inner = getInnerExpression(el);
|
|
2352
|
-
return inner.type ===
|
|
2414
|
+
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
2415
|
});
|
|
2354
2416
|
}
|
|
2355
|
-
var noInlineNestedObject =
|
|
2417
|
+
var noInlineNestedObject = createRule33({
|
|
2356
2418
|
name: "no-inline-nested-object",
|
|
2357
2419
|
meta: {
|
|
2358
2420
|
type: "layout",
|
|
@@ -2374,17 +2436,17 @@ var noInlineNestedObject = createRule32({
|
|
|
2374
2436
|
return;
|
|
2375
2437
|
}
|
|
2376
2438
|
const valueNode = getInnerExpression(node.value);
|
|
2377
|
-
if (valueNode.type !==
|
|
2439
|
+
if (valueNode.type !== AST_NODE_TYPES31.ObjectExpression && valueNode.type !== AST_NODE_TYPES31.ArrayExpression) {
|
|
2378
2440
|
return;
|
|
2379
2441
|
}
|
|
2380
2442
|
if (!valueNode.loc) {
|
|
2381
2443
|
return;
|
|
2382
2444
|
}
|
|
2383
|
-
const elements = valueNode.type ===
|
|
2445
|
+
const elements = valueNode.type === AST_NODE_TYPES31.ObjectExpression ? valueNode.properties : valueNode.elements;
|
|
2384
2446
|
if (elements.length <= 1) {
|
|
2385
2447
|
return;
|
|
2386
2448
|
}
|
|
2387
|
-
if (valueNode.type ===
|
|
2449
|
+
if (valueNode.type === AST_NODE_TYPES31.ArrayExpression && arrayContainsOnlyPrimitives(valueNode)) {
|
|
2388
2450
|
return;
|
|
2389
2451
|
}
|
|
2390
2452
|
const isMultiline = valueNode.loc.start.line !== valueNode.loc.end.line;
|
|
@@ -2403,7 +2465,7 @@ var noInlineNestedObject = createRule32({
|
|
|
2403
2465
|
const indent = " ".repeat(node.loc?.start.column ?? 0);
|
|
2404
2466
|
const innerIndent = `${indent} `;
|
|
2405
2467
|
const elementTexts = elements.filter((el) => el !== null).map((el) => sourceCode.getText(el));
|
|
2406
|
-
const isObject = valueNode.type ===
|
|
2468
|
+
const isObject = valueNode.type === AST_NODE_TYPES31.ObjectExpression;
|
|
2407
2469
|
const openChar = isObject ? "{" : "[";
|
|
2408
2470
|
const closeChar = isObject ? "}" : "]";
|
|
2409
2471
|
const formattedElements = elementTexts.map((text) => `${innerIndent}${text},`).join("\n");
|
|
@@ -2420,20 +2482,20 @@ ${indent}${closeChar}`;
|
|
|
2420
2482
|
var no_inline_nested_object_default = noInlineNestedObject;
|
|
2421
2483
|
|
|
2422
2484
|
// src/rules/no-inline-return-properties.ts
|
|
2423
|
-
import { AST_NODE_TYPES as
|
|
2424
|
-
var
|
|
2485
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32, ESLintUtils as ESLintUtils34 } from "@typescript-eslint/utils";
|
|
2486
|
+
var createRule34 = ESLintUtils34.RuleCreator(
|
|
2425
2487
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2426
2488
|
);
|
|
2427
2489
|
var isShorthandProperty = (property) => {
|
|
2428
|
-
if (property.type ===
|
|
2490
|
+
if (property.type === AST_NODE_TYPES32.SpreadElement) {
|
|
2429
2491
|
return true;
|
|
2430
2492
|
}
|
|
2431
|
-
if (property.type !==
|
|
2493
|
+
if (property.type !== AST_NODE_TYPES32.Property) {
|
|
2432
2494
|
return false;
|
|
2433
2495
|
}
|
|
2434
2496
|
return property.shorthand;
|
|
2435
2497
|
};
|
|
2436
|
-
var noInlineReturnProperties =
|
|
2498
|
+
var noInlineReturnProperties = createRule34({
|
|
2437
2499
|
name: "no-inline-return-properties",
|
|
2438
2500
|
meta: {
|
|
2439
2501
|
type: "suggestion",
|
|
@@ -2449,20 +2511,20 @@ var noInlineReturnProperties = createRule33({
|
|
|
2449
2511
|
create(context) {
|
|
2450
2512
|
return {
|
|
2451
2513
|
ReturnStatement(node) {
|
|
2452
|
-
if (!node.argument || node.argument.type !==
|
|
2514
|
+
if (!node.argument || node.argument.type !== AST_NODE_TYPES32.ObjectExpression) {
|
|
2453
2515
|
return;
|
|
2454
2516
|
}
|
|
2455
2517
|
node.argument.properties.forEach((property) => {
|
|
2456
2518
|
if (isShorthandProperty(property)) {
|
|
2457
2519
|
return;
|
|
2458
2520
|
}
|
|
2459
|
-
if (property.type !==
|
|
2521
|
+
if (property.type !== AST_NODE_TYPES32.Property) {
|
|
2460
2522
|
return;
|
|
2461
2523
|
}
|
|
2462
2524
|
let keyName = null;
|
|
2463
|
-
if (property.key.type ===
|
|
2525
|
+
if (property.key.type === AST_NODE_TYPES32.Identifier) {
|
|
2464
2526
|
keyName = property.key.name;
|
|
2465
|
-
} else if (property.key.type ===
|
|
2527
|
+
} else if (property.key.type === AST_NODE_TYPES32.Literal) {
|
|
2466
2528
|
keyName = String(property.key.value);
|
|
2467
2529
|
}
|
|
2468
2530
|
context.report({
|
|
@@ -2477,9 +2539,83 @@ var noInlineReturnProperties = createRule33({
|
|
|
2477
2539
|
});
|
|
2478
2540
|
var no_inline_return_properties_default = noInlineReturnProperties;
|
|
2479
2541
|
|
|
2542
|
+
// src/rules/no-inline-type-import.ts
|
|
2543
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33, ESLintUtils as ESLintUtils35 } from "@typescript-eslint/utils";
|
|
2544
|
+
var createRule35 = ESLintUtils35.RuleCreator(
|
|
2545
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2546
|
+
);
|
|
2547
|
+
var isInlineTypeSpecifier = (specifier) => specifier.type === AST_NODE_TYPES33.ImportSpecifier && specifier.importKind === "type";
|
|
2548
|
+
var noInlineTypeImport = createRule35({
|
|
2549
|
+
name: "no-inline-type-import",
|
|
2550
|
+
meta: {
|
|
2551
|
+
type: "suggestion",
|
|
2552
|
+
docs: {
|
|
2553
|
+
description: "Disallow inline 'type' markers on import specifiers. Use 'import type' or split into a separate type-only import statement."
|
|
2554
|
+
},
|
|
2555
|
+
fixable: "code",
|
|
2556
|
+
messages: {
|
|
2557
|
+
noInlineTypeImport: "Avoid inline 'type' markers on import specifiers. Hoist to 'import type' or split into a separate type-only import statement."
|
|
2558
|
+
},
|
|
2559
|
+
schema: []
|
|
2560
|
+
},
|
|
2561
|
+
defaultOptions: [],
|
|
2562
|
+
create(context) {
|
|
2563
|
+
return {
|
|
2564
|
+
ImportDeclaration(node) {
|
|
2565
|
+
const inlineTypeSpecifiers = node.specifiers.filter(isInlineTypeSpecifier);
|
|
2566
|
+
if (inlineTypeSpecifiers.length === 0) {
|
|
2567
|
+
return;
|
|
2568
|
+
}
|
|
2569
|
+
context.report({
|
|
2570
|
+
node,
|
|
2571
|
+
messageId: "noInlineTypeImport",
|
|
2572
|
+
fix(fixer) {
|
|
2573
|
+
if (node.importKind === "type") {
|
|
2574
|
+
return inlineTypeSpecifiers.map(
|
|
2575
|
+
(specifier) => fixer.removeRange([specifier.range[0], specifier.imported.range[0]])
|
|
2576
|
+
);
|
|
2577
|
+
}
|
|
2578
|
+
const sourceText = context.sourceCode.getText(node.source);
|
|
2579
|
+
const fileText = context.sourceCode.text;
|
|
2580
|
+
const typeSpecifierTexts = inlineTypeSpecifiers.map(
|
|
2581
|
+
(specifier) => fileText.slice(specifier.imported.range[0], specifier.range[1])
|
|
2582
|
+
);
|
|
2583
|
+
const typeImport = `import type { ${typeSpecifierTexts.join(", ")} } from ${sourceText};`;
|
|
2584
|
+
const valueSpecifiers = node.specifiers.filter(
|
|
2585
|
+
(specifier) => !(specifier.type === AST_NODE_TYPES33.ImportSpecifier && specifier.importKind === "type")
|
|
2586
|
+
);
|
|
2587
|
+
if (valueSpecifiers.length === 0) {
|
|
2588
|
+
return fixer.replaceText(node, typeImport);
|
|
2589
|
+
}
|
|
2590
|
+
const parts = [];
|
|
2591
|
+
const namedValueSpecifiers = [];
|
|
2592
|
+
for (const specifier of valueSpecifiers) {
|
|
2593
|
+
if (specifier.type === AST_NODE_TYPES33.ImportDefaultSpecifier) {
|
|
2594
|
+
parts.push(specifier.local.name);
|
|
2595
|
+
} else if (specifier.type === AST_NODE_TYPES33.ImportNamespaceSpecifier) {
|
|
2596
|
+
parts.push(`* as ${specifier.local.name}`);
|
|
2597
|
+
} else if (specifier.type === AST_NODE_TYPES33.ImportSpecifier) {
|
|
2598
|
+
namedValueSpecifiers.push(specifier);
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
if (namedValueSpecifiers.length > 0) {
|
|
2602
|
+
const namedTexts = namedValueSpecifiers.map((specifier) => context.sourceCode.getText(specifier));
|
|
2603
|
+
parts.push(`{ ${namedTexts.join(", ")} }`);
|
|
2604
|
+
}
|
|
2605
|
+
const valueImport = `import ${parts.join(", ")} from ${sourceText};`;
|
|
2606
|
+
return fixer.replaceText(node, `${valueImport}
|
|
2607
|
+
${typeImport}`);
|
|
2608
|
+
}
|
|
2609
|
+
});
|
|
2610
|
+
}
|
|
2611
|
+
};
|
|
2612
|
+
}
|
|
2613
|
+
});
|
|
2614
|
+
var no_inline_type_import_default = noInlineTypeImport;
|
|
2615
|
+
|
|
2480
2616
|
// src/rules/no-lazy-identifiers.ts
|
|
2481
|
-
import { AST_NODE_TYPES as
|
|
2482
|
-
var
|
|
2617
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34, ESLintUtils as ESLintUtils36 } from "@typescript-eslint/utils";
|
|
2618
|
+
var createRule36 = ESLintUtils36.RuleCreator(
|
|
2483
2619
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2484
2620
|
);
|
|
2485
2621
|
var KEYBOARD_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm", "1234567890"];
|
|
@@ -2520,7 +2656,7 @@ var isLazyIdentifier = (name) => {
|
|
|
2520
2656
|
}
|
|
2521
2657
|
return false;
|
|
2522
2658
|
};
|
|
2523
|
-
var noLazyIdentifiers =
|
|
2659
|
+
var noLazyIdentifiers = createRule36({
|
|
2524
2660
|
name: "no-lazy-identifiers",
|
|
2525
2661
|
meta: {
|
|
2526
2662
|
type: "problem",
|
|
@@ -2546,27 +2682,27 @@ var noLazyIdentifiers = createRule34({
|
|
|
2546
2682
|
});
|
|
2547
2683
|
};
|
|
2548
2684
|
const checkPattern = (pattern) => {
|
|
2549
|
-
if (pattern.type ===
|
|
2685
|
+
if (pattern.type === AST_NODE_TYPES34.Identifier) {
|
|
2550
2686
|
checkIdentifier(pattern);
|
|
2551
|
-
} else if (pattern.type ===
|
|
2687
|
+
} else if (pattern.type === AST_NODE_TYPES34.ObjectPattern) {
|
|
2552
2688
|
pattern.properties.forEach((prop) => {
|
|
2553
|
-
if (prop.type ===
|
|
2689
|
+
if (prop.type === AST_NODE_TYPES34.Property && prop.value.type === AST_NODE_TYPES34.Identifier) {
|
|
2554
2690
|
checkIdentifier(prop.value);
|
|
2555
|
-
} else if (prop.type ===
|
|
2691
|
+
} else if (prop.type === AST_NODE_TYPES34.RestElement && prop.argument.type === AST_NODE_TYPES34.Identifier) {
|
|
2556
2692
|
checkIdentifier(prop.argument);
|
|
2557
2693
|
}
|
|
2558
2694
|
});
|
|
2559
|
-
} else if (pattern.type ===
|
|
2695
|
+
} else if (pattern.type === AST_NODE_TYPES34.ArrayPattern) {
|
|
2560
2696
|
pattern.elements.forEach((element) => {
|
|
2561
|
-
if (element?.type ===
|
|
2697
|
+
if (element?.type === AST_NODE_TYPES34.Identifier) {
|
|
2562
2698
|
checkIdentifier(element);
|
|
2563
|
-
} else if (element?.type ===
|
|
2699
|
+
} else if (element?.type === AST_NODE_TYPES34.RestElement && element.argument.type === AST_NODE_TYPES34.Identifier) {
|
|
2564
2700
|
checkIdentifier(element.argument);
|
|
2565
2701
|
}
|
|
2566
2702
|
});
|
|
2567
|
-
} else if (pattern.type ===
|
|
2703
|
+
} else if (pattern.type === AST_NODE_TYPES34.AssignmentPattern && pattern.left.type === AST_NODE_TYPES34.Identifier) {
|
|
2568
2704
|
checkIdentifier(pattern.left);
|
|
2569
|
-
} else if (pattern.type ===
|
|
2705
|
+
} else if (pattern.type === AST_NODE_TYPES34.RestElement && pattern.argument.type === AST_NODE_TYPES34.Identifier) {
|
|
2570
2706
|
checkIdentifier(pattern.argument);
|
|
2571
2707
|
}
|
|
2572
2708
|
};
|
|
@@ -2611,11 +2747,11 @@ var noLazyIdentifiers = createRule34({
|
|
|
2611
2747
|
var no_lazy_identifiers_default = noLazyIdentifiers;
|
|
2612
2748
|
|
|
2613
2749
|
// src/rules/no-logic-in-params.ts
|
|
2614
|
-
import { AST_NODE_TYPES as
|
|
2615
|
-
var
|
|
2750
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35, ESLintUtils as ESLintUtils37 } from "@typescript-eslint/utils";
|
|
2751
|
+
var createRule37 = ESLintUtils37.RuleCreator(
|
|
2616
2752
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2617
2753
|
);
|
|
2618
|
-
var noLogicInParams =
|
|
2754
|
+
var noLogicInParams = createRule37({
|
|
2619
2755
|
name: "no-logic-in-params",
|
|
2620
2756
|
meta: {
|
|
2621
2757
|
type: "suggestion",
|
|
@@ -2630,20 +2766,20 @@ var noLogicInParams = createRule35({
|
|
|
2630
2766
|
defaultOptions: [],
|
|
2631
2767
|
create(context) {
|
|
2632
2768
|
const isComplexExpression = (node) => {
|
|
2633
|
-
if (node.type ===
|
|
2769
|
+
if (node.type === AST_NODE_TYPES35.SpreadElement) {
|
|
2634
2770
|
return false;
|
|
2635
2771
|
}
|
|
2636
|
-
if (node.type ===
|
|
2772
|
+
if (node.type === AST_NODE_TYPES35.ConditionalExpression) {
|
|
2637
2773
|
return true;
|
|
2638
2774
|
}
|
|
2639
|
-
if (node.type ===
|
|
2775
|
+
if (node.type === AST_NODE_TYPES35.LogicalExpression) {
|
|
2640
2776
|
return true;
|
|
2641
2777
|
}
|
|
2642
|
-
if (node.type ===
|
|
2778
|
+
if (node.type === AST_NODE_TYPES35.BinaryExpression) {
|
|
2643
2779
|
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
2644
2780
|
return logicalOperators.includes(node.operator);
|
|
2645
2781
|
}
|
|
2646
|
-
if (node.type ===
|
|
2782
|
+
if (node.type === AST_NODE_TYPES35.UnaryExpression) {
|
|
2647
2783
|
return node.operator === "!";
|
|
2648
2784
|
}
|
|
2649
2785
|
return false;
|
|
@@ -2656,7 +2792,7 @@ var noLogicInParams = createRule35({
|
|
|
2656
2792
|
messageId: "noLogicInParams"
|
|
2657
2793
|
});
|
|
2658
2794
|
}
|
|
2659
|
-
if (arg.type ===
|
|
2795
|
+
if (arg.type === AST_NODE_TYPES35.ArrayExpression) {
|
|
2660
2796
|
arg.elements.forEach((element) => {
|
|
2661
2797
|
if (element && isComplexExpression(element)) {
|
|
2662
2798
|
context.report({
|
|
@@ -2681,46 +2817,46 @@ var noLogicInParams = createRule35({
|
|
|
2681
2817
|
var no_logic_in_params_default = noLogicInParams;
|
|
2682
2818
|
|
|
2683
2819
|
// src/rules/no-misleading-constant-case.ts
|
|
2684
|
-
import { AST_NODE_TYPES as
|
|
2685
|
-
var
|
|
2820
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36, ESLintUtils as ESLintUtils38 } from "@typescript-eslint/utils";
|
|
2821
|
+
var createRule38 = ESLintUtils38.RuleCreator(
|
|
2686
2822
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2687
2823
|
);
|
|
2688
2824
|
var SCREAMING_SNAKE_CASE_REGEX3 = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
2689
|
-
var isAsConstAssertion2 = (node) => node.type ===
|
|
2825
|
+
var isAsConstAssertion2 = (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";
|
|
2690
2826
|
var isStaticValue3 = (init) => {
|
|
2691
2827
|
if (isAsConstAssertion2(init)) {
|
|
2692
2828
|
return true;
|
|
2693
2829
|
}
|
|
2694
|
-
if (init.type ===
|
|
2830
|
+
if (init.type === AST_NODE_TYPES36.Literal) {
|
|
2695
2831
|
return true;
|
|
2696
2832
|
}
|
|
2697
|
-
if (init.type ===
|
|
2833
|
+
if (init.type === AST_NODE_TYPES36.UnaryExpression && init.argument.type === AST_NODE_TYPES36.Literal) {
|
|
2698
2834
|
return true;
|
|
2699
2835
|
}
|
|
2700
|
-
if (init.type ===
|
|
2836
|
+
if (init.type === AST_NODE_TYPES36.TemplateLiteral && init.expressions.length === 0) {
|
|
2701
2837
|
return true;
|
|
2702
2838
|
}
|
|
2703
|
-
if (init.type ===
|
|
2704
|
-
return init.elements.every((el) => el !== null && el.type !==
|
|
2839
|
+
if (init.type === AST_NODE_TYPES36.ArrayExpression) {
|
|
2840
|
+
return init.elements.every((el) => el !== null && el.type !== AST_NODE_TYPES36.SpreadElement && isStaticValue3(el));
|
|
2705
2841
|
}
|
|
2706
|
-
if (init.type ===
|
|
2842
|
+
if (init.type === AST_NODE_TYPES36.ObjectExpression) {
|
|
2707
2843
|
return init.properties.every(
|
|
2708
|
-
(prop) => prop.type ===
|
|
2844
|
+
(prop) => prop.type === AST_NODE_TYPES36.Property && isStaticValue3(prop.value)
|
|
2709
2845
|
);
|
|
2710
2846
|
}
|
|
2711
2847
|
return false;
|
|
2712
2848
|
};
|
|
2713
2849
|
var isGlobalScope3 = (node) => {
|
|
2714
2850
|
const { parent } = node;
|
|
2715
|
-
if (parent.type ===
|
|
2851
|
+
if (parent.type === AST_NODE_TYPES36.Program) {
|
|
2716
2852
|
return true;
|
|
2717
2853
|
}
|
|
2718
|
-
if (parent.type ===
|
|
2854
|
+
if (parent.type === AST_NODE_TYPES36.ExportNamedDeclaration && parent.parent?.type === AST_NODE_TYPES36.Program) {
|
|
2719
2855
|
return true;
|
|
2720
2856
|
}
|
|
2721
2857
|
return false;
|
|
2722
2858
|
};
|
|
2723
|
-
var noMisleadingConstantCase =
|
|
2859
|
+
var noMisleadingConstantCase = createRule38({
|
|
2724
2860
|
name: "no-misleading-constant-case",
|
|
2725
2861
|
meta: {
|
|
2726
2862
|
type: "suggestion",
|
|
@@ -2739,7 +2875,7 @@ var noMisleadingConstantCase = createRule36({
|
|
|
2739
2875
|
return {
|
|
2740
2876
|
VariableDeclaration(node) {
|
|
2741
2877
|
node.declarations.forEach((declarator) => {
|
|
2742
|
-
if (declarator.id.type !==
|
|
2878
|
+
if (declarator.id.type !== AST_NODE_TYPES36.Identifier) {
|
|
2743
2879
|
return;
|
|
2744
2880
|
}
|
|
2745
2881
|
const { name } = declarator.id;
|
|
@@ -2780,11 +2916,11 @@ var noMisleadingConstantCase = createRule36({
|
|
|
2780
2916
|
var no_misleading_constant_case_default = noMisleadingConstantCase;
|
|
2781
2917
|
|
|
2782
2918
|
// src/rules/no-nested-interface-declaration.ts
|
|
2783
|
-
import { AST_NODE_TYPES as
|
|
2784
|
-
var
|
|
2919
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37, ESLintUtils as ESLintUtils39 } from "@typescript-eslint/utils";
|
|
2920
|
+
var createRule39 = ESLintUtils39.RuleCreator(
|
|
2785
2921
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2786
2922
|
);
|
|
2787
|
-
var noNestedInterfaceDeclaration =
|
|
2923
|
+
var noNestedInterfaceDeclaration = createRule39({
|
|
2788
2924
|
name: "no-nested-interface-declaration",
|
|
2789
2925
|
meta: {
|
|
2790
2926
|
type: "suggestion",
|
|
@@ -2805,15 +2941,15 @@ var noNestedInterfaceDeclaration = createRule37({
|
|
|
2805
2941
|
return;
|
|
2806
2942
|
}
|
|
2807
2943
|
const { typeAnnotation } = node.typeAnnotation;
|
|
2808
|
-
if (typeAnnotation.type ===
|
|
2944
|
+
if (typeAnnotation.type === AST_NODE_TYPES37.TSTypeLiteral) {
|
|
2809
2945
|
context.report({
|
|
2810
2946
|
node: typeAnnotation,
|
|
2811
2947
|
messageId: "noNestedInterface"
|
|
2812
2948
|
});
|
|
2813
2949
|
return;
|
|
2814
2950
|
}
|
|
2815
|
-
if (typeAnnotation.type ===
|
|
2816
|
-
if (typeAnnotation.elementType.type ===
|
|
2951
|
+
if (typeAnnotation.type === AST_NODE_TYPES37.TSArrayType) {
|
|
2952
|
+
if (typeAnnotation.elementType.type === AST_NODE_TYPES37.TSTypeLiteral) {
|
|
2817
2953
|
context.report({
|
|
2818
2954
|
node: typeAnnotation.elementType,
|
|
2819
2955
|
messageId: "noNestedInterface"
|
|
@@ -2821,9 +2957,9 @@ var noNestedInterfaceDeclaration = createRule37({
|
|
|
2821
2957
|
}
|
|
2822
2958
|
return;
|
|
2823
2959
|
}
|
|
2824
|
-
if (typeAnnotation.type ===
|
|
2960
|
+
if (typeAnnotation.type === AST_NODE_TYPES37.TSTypeReference && typeAnnotation.typeArguments) {
|
|
2825
2961
|
typeAnnotation.typeArguments.params.forEach((param) => {
|
|
2826
|
-
if (param.type ===
|
|
2962
|
+
if (param.type === AST_NODE_TYPES37.TSTypeLiteral) {
|
|
2827
2963
|
context.report({
|
|
2828
2964
|
node: param,
|
|
2829
2965
|
messageId: "noNestedInterface"
|
|
@@ -2838,11 +2974,11 @@ var noNestedInterfaceDeclaration = createRule37({
|
|
|
2838
2974
|
var no_nested_interface_declaration_default = noNestedInterfaceDeclaration;
|
|
2839
2975
|
|
|
2840
2976
|
// src/rules/no-nested-ternary.ts
|
|
2841
|
-
import { AST_NODE_TYPES as
|
|
2842
|
-
var
|
|
2977
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38, ESLintUtils as ESLintUtils40 } from "@typescript-eslint/utils";
|
|
2978
|
+
var createRule40 = ESLintUtils40.RuleCreator(
|
|
2843
2979
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2844
2980
|
);
|
|
2845
|
-
var noNestedTernary =
|
|
2981
|
+
var noNestedTernary = createRule40({
|
|
2846
2982
|
name: "no-nested-ternary",
|
|
2847
2983
|
meta: {
|
|
2848
2984
|
type: "suggestion",
|
|
@@ -2859,13 +2995,13 @@ var noNestedTernary = createRule38({
|
|
|
2859
2995
|
return {
|
|
2860
2996
|
ConditionalExpression(node) {
|
|
2861
2997
|
const { consequent, alternate } = node;
|
|
2862
|
-
if (consequent.type ===
|
|
2998
|
+
if (consequent.type === AST_NODE_TYPES38.ConditionalExpression) {
|
|
2863
2999
|
context.report({
|
|
2864
3000
|
node: consequent,
|
|
2865
3001
|
messageId: "noNestedTernary"
|
|
2866
3002
|
});
|
|
2867
3003
|
}
|
|
2868
|
-
if (alternate.type ===
|
|
3004
|
+
if (alternate.type === AST_NODE_TYPES38.ConditionalExpression) {
|
|
2869
3005
|
context.report({
|
|
2870
3006
|
node: alternate,
|
|
2871
3007
|
messageId: "noNestedTernary"
|
|
@@ -2878,11 +3014,11 @@ var noNestedTernary = createRule38({
|
|
|
2878
3014
|
var no_nested_ternary_default = noNestedTernary;
|
|
2879
3015
|
|
|
2880
3016
|
// src/rules/no-relative-imports.ts
|
|
2881
|
-
import { AST_NODE_TYPES as
|
|
2882
|
-
var
|
|
3017
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39, ESLintUtils as ESLintUtils41 } from "@typescript-eslint/utils";
|
|
3018
|
+
var createRule41 = ESLintUtils41.RuleCreator(
|
|
2883
3019
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2884
3020
|
);
|
|
2885
|
-
var noRelativeImports =
|
|
3021
|
+
var noRelativeImports = createRule41({
|
|
2886
3022
|
name: "no-relative-imports",
|
|
2887
3023
|
meta: {
|
|
2888
3024
|
type: "suggestion",
|
|
@@ -2906,22 +3042,22 @@ var noRelativeImports = createRule39({
|
|
|
2906
3042
|
};
|
|
2907
3043
|
return {
|
|
2908
3044
|
ImportDeclaration(node) {
|
|
2909
|
-
if (node.source.type ===
|
|
3045
|
+
if (node.source.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2910
3046
|
checkImportPath(node.source.value, node);
|
|
2911
3047
|
}
|
|
2912
3048
|
},
|
|
2913
3049
|
ImportExpression(node) {
|
|
2914
|
-
if (node.source.type ===
|
|
3050
|
+
if (node.source.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2915
3051
|
checkImportPath(node.source.value, node);
|
|
2916
3052
|
}
|
|
2917
3053
|
},
|
|
2918
3054
|
ExportNamedDeclaration(node) {
|
|
2919
|
-
if (node.source?.type ===
|
|
3055
|
+
if (node.source?.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2920
3056
|
checkImportPath(node.source.value, node);
|
|
2921
3057
|
}
|
|
2922
3058
|
},
|
|
2923
3059
|
ExportAllDeclaration(node) {
|
|
2924
|
-
if (node.source.type ===
|
|
3060
|
+
if (node.source.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2925
3061
|
checkImportPath(node.source.value, node);
|
|
2926
3062
|
}
|
|
2927
3063
|
}
|
|
@@ -2931,8 +3067,8 @@ var noRelativeImports = createRule39({
|
|
|
2931
3067
|
var no_relative_imports_default = noRelativeImports;
|
|
2932
3068
|
|
|
2933
3069
|
// src/rules/no-single-char-variables.ts
|
|
2934
|
-
import { AST_NODE_TYPES as
|
|
2935
|
-
var
|
|
3070
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40, ESLintUtils as ESLintUtils42 } from "@typescript-eslint/utils";
|
|
3071
|
+
var createRule42 = ESLintUtils42.RuleCreator(
|
|
2936
3072
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2937
3073
|
);
|
|
2938
3074
|
var ALLOWED_IN_FOR_LOOPS = /* @__PURE__ */ new Set(["i", "j", "k", "n"]);
|
|
@@ -2944,7 +3080,7 @@ var isForLoopInit = (node) => {
|
|
|
2944
3080
|
if (!parentNode) {
|
|
2945
3081
|
return false;
|
|
2946
3082
|
}
|
|
2947
|
-
if (parentNode.type ===
|
|
3083
|
+
if (parentNode.type === AST_NODE_TYPES40.ForStatement) {
|
|
2948
3084
|
const { init } = parentNode;
|
|
2949
3085
|
if (init && init === current) {
|
|
2950
3086
|
return true;
|
|
@@ -2963,7 +3099,7 @@ var isAllowedInContext = (name, node) => {
|
|
|
2963
3099
|
}
|
|
2964
3100
|
return false;
|
|
2965
3101
|
};
|
|
2966
|
-
var noSingleCharVariables =
|
|
3102
|
+
var noSingleCharVariables = createRule42({
|
|
2967
3103
|
name: "no-single-char-variables",
|
|
2968
3104
|
meta: {
|
|
2969
3105
|
type: "suggestion",
|
|
@@ -2992,27 +3128,27 @@ var noSingleCharVariables = createRule40({
|
|
|
2992
3128
|
});
|
|
2993
3129
|
};
|
|
2994
3130
|
const checkPattern = (pattern, declarationNode) => {
|
|
2995
|
-
if (pattern.type ===
|
|
3131
|
+
if (pattern.type === AST_NODE_TYPES40.Identifier) {
|
|
2996
3132
|
checkIdentifier(pattern, declarationNode);
|
|
2997
|
-
} else if (pattern.type ===
|
|
3133
|
+
} else if (pattern.type === AST_NODE_TYPES40.ObjectPattern) {
|
|
2998
3134
|
pattern.properties.forEach((prop) => {
|
|
2999
|
-
if (prop.type ===
|
|
3135
|
+
if (prop.type === AST_NODE_TYPES40.Property && prop.value.type === AST_NODE_TYPES40.Identifier) {
|
|
3000
3136
|
checkIdentifier(prop.value, declarationNode);
|
|
3001
|
-
} else if (prop.type ===
|
|
3137
|
+
} else if (prop.type === AST_NODE_TYPES40.RestElement && prop.argument.type === AST_NODE_TYPES40.Identifier) {
|
|
3002
3138
|
checkIdentifier(prop.argument, declarationNode);
|
|
3003
3139
|
}
|
|
3004
3140
|
});
|
|
3005
|
-
} else if (pattern.type ===
|
|
3141
|
+
} else if (pattern.type === AST_NODE_TYPES40.ArrayPattern) {
|
|
3006
3142
|
pattern.elements.forEach((element) => {
|
|
3007
|
-
if (element?.type ===
|
|
3143
|
+
if (element?.type === AST_NODE_TYPES40.Identifier) {
|
|
3008
3144
|
checkIdentifier(element, declarationNode);
|
|
3009
|
-
} else if (element?.type ===
|
|
3145
|
+
} else if (element?.type === AST_NODE_TYPES40.RestElement && element.argument.type === AST_NODE_TYPES40.Identifier) {
|
|
3010
3146
|
checkIdentifier(element.argument, declarationNode);
|
|
3011
3147
|
}
|
|
3012
3148
|
});
|
|
3013
|
-
} else if (pattern.type ===
|
|
3149
|
+
} else if (pattern.type === AST_NODE_TYPES40.AssignmentPattern && pattern.left.type === AST_NODE_TYPES40.Identifier) {
|
|
3014
3150
|
checkIdentifier(pattern.left, declarationNode);
|
|
3015
|
-
} else if (pattern.type ===
|
|
3151
|
+
} else if (pattern.type === AST_NODE_TYPES40.RestElement && pattern.argument.type === AST_NODE_TYPES40.Identifier) {
|
|
3016
3152
|
checkIdentifier(pattern.argument, declarationNode);
|
|
3017
3153
|
}
|
|
3018
3154
|
};
|
|
@@ -3046,11 +3182,11 @@ var noSingleCharVariables = createRule40({
|
|
|
3046
3182
|
var no_single_char_variables_default = noSingleCharVariables;
|
|
3047
3183
|
|
|
3048
3184
|
// src/rules/prefer-async-await.ts
|
|
3049
|
-
import { AST_NODE_TYPES as
|
|
3050
|
-
var
|
|
3185
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41, ESLintUtils as ESLintUtils43 } from "@typescript-eslint/utils";
|
|
3186
|
+
var createRule43 = ESLintUtils43.RuleCreator(
|
|
3051
3187
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3052
3188
|
);
|
|
3053
|
-
var preferAsyncAwait =
|
|
3189
|
+
var preferAsyncAwait = createRule43({
|
|
3054
3190
|
name: "prefer-async-await",
|
|
3055
3191
|
meta: {
|
|
3056
3192
|
type: "suggestion",
|
|
@@ -3066,7 +3202,7 @@ var preferAsyncAwait = createRule41({
|
|
|
3066
3202
|
create(context) {
|
|
3067
3203
|
return {
|
|
3068
3204
|
CallExpression(node) {
|
|
3069
|
-
if (node.callee.type ===
|
|
3205
|
+
if (node.callee.type === AST_NODE_TYPES41.MemberExpression && node.callee.property.type === AST_NODE_TYPES41.Identifier && node.callee.property.name === "then") {
|
|
3070
3206
|
context.report({
|
|
3071
3207
|
node: node.callee.property,
|
|
3072
3208
|
messageId: "preferAsyncAwait"
|
|
@@ -3079,11 +3215,11 @@ var preferAsyncAwait = createRule41({
|
|
|
3079
3215
|
var prefer_async_await_default = preferAsyncAwait;
|
|
3080
3216
|
|
|
3081
3217
|
// src/rules/prefer-destructuring-params.ts
|
|
3082
|
-
import { AST_NODE_TYPES as
|
|
3083
|
-
var
|
|
3218
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42, ESLintUtils as ESLintUtils44 } from "@typescript-eslint/utils";
|
|
3219
|
+
var createRule44 = ESLintUtils44.RuleCreator(
|
|
3084
3220
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3085
3221
|
);
|
|
3086
|
-
var preferDestructuringParams =
|
|
3222
|
+
var preferDestructuringParams = createRule44({
|
|
3087
3223
|
name: "prefer-destructuring-params",
|
|
3088
3224
|
meta: {
|
|
3089
3225
|
type: "suggestion",
|
|
@@ -3099,18 +3235,18 @@ var preferDestructuringParams = createRule42({
|
|
|
3099
3235
|
create(context) {
|
|
3100
3236
|
const isCallbackFunction2 = (node) => {
|
|
3101
3237
|
const { parent } = node;
|
|
3102
|
-
return parent?.type ===
|
|
3238
|
+
return parent?.type === AST_NODE_TYPES42.CallExpression;
|
|
3103
3239
|
};
|
|
3104
3240
|
const isDeveloperFunction = (node) => {
|
|
3105
|
-
if (node.type ===
|
|
3241
|
+
if (node.type === AST_NODE_TYPES42.FunctionDeclaration) {
|
|
3106
3242
|
return true;
|
|
3107
3243
|
}
|
|
3108
|
-
if (node.type ===
|
|
3244
|
+
if (node.type === AST_NODE_TYPES42.FunctionExpression || node.type === AST_NODE_TYPES42.ArrowFunctionExpression) {
|
|
3109
3245
|
if (isCallbackFunction2(node)) {
|
|
3110
3246
|
return false;
|
|
3111
3247
|
}
|
|
3112
3248
|
const { parent } = node;
|
|
3113
|
-
return parent?.type ===
|
|
3249
|
+
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
3250
|
}
|
|
3115
3251
|
return false;
|
|
3116
3252
|
};
|
|
@@ -3122,7 +3258,7 @@ var preferDestructuringParams = createRule42({
|
|
|
3122
3258
|
if (!isDeveloperFunction(node)) {
|
|
3123
3259
|
return;
|
|
3124
3260
|
}
|
|
3125
|
-
if (node.type ===
|
|
3261
|
+
if (node.type === AST_NODE_TYPES42.FunctionDeclaration && node.id) {
|
|
3126
3262
|
const functionName = node.id.name;
|
|
3127
3263
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
3128
3264
|
return;
|
|
@@ -3132,7 +3268,7 @@ var preferDestructuringParams = createRule42({
|
|
|
3132
3268
|
return;
|
|
3133
3269
|
}
|
|
3134
3270
|
const hasNonDestructuredParams = node.params.some(
|
|
3135
|
-
(param) => param.type !==
|
|
3271
|
+
(param) => param.type !== AST_NODE_TYPES42.ObjectPattern && param.type !== AST_NODE_TYPES42.RestElement
|
|
3136
3272
|
);
|
|
3137
3273
|
if (hasNonDestructuredParams) {
|
|
3138
3274
|
context.report({
|
|
@@ -3151,8 +3287,8 @@ var preferDestructuringParams = createRule42({
|
|
|
3151
3287
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
3152
3288
|
|
|
3153
3289
|
// src/rules/prefer-function-declaration.ts
|
|
3154
|
-
import { AST_NODE_TYPES as
|
|
3155
|
-
var
|
|
3290
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43, ESLintUtils as ESLintUtils45 } from "@typescript-eslint/utils";
|
|
3291
|
+
var createRule45 = ESLintUtils45.RuleCreator(
|
|
3156
3292
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3157
3293
|
);
|
|
3158
3294
|
var isTsFile = (filename) => filename.endsWith(".ts") && !filename.endsWith(".d.ts");
|
|
@@ -3161,33 +3297,33 @@ var isCallbackContext = (node) => {
|
|
|
3161
3297
|
if (!parent) {
|
|
3162
3298
|
return false;
|
|
3163
3299
|
}
|
|
3164
|
-
if (parent.type ===
|
|
3300
|
+
if (parent.type === AST_NODE_TYPES43.CallExpression && parent.arguments.includes(node)) {
|
|
3165
3301
|
return true;
|
|
3166
3302
|
}
|
|
3167
|
-
if (parent.type ===
|
|
3303
|
+
if (parent.type === AST_NODE_TYPES43.NewExpression && parent.arguments.includes(node)) {
|
|
3168
3304
|
return true;
|
|
3169
3305
|
}
|
|
3170
|
-
if (parent.type ===
|
|
3306
|
+
if (parent.type === AST_NODE_TYPES43.ReturnStatement) {
|
|
3171
3307
|
return true;
|
|
3172
3308
|
}
|
|
3173
|
-
if (parent.type ===
|
|
3309
|
+
if (parent.type === AST_NODE_TYPES43.Property) {
|
|
3174
3310
|
return true;
|
|
3175
3311
|
}
|
|
3176
|
-
if (parent.type ===
|
|
3312
|
+
if (parent.type === AST_NODE_TYPES43.ArrayExpression) {
|
|
3177
3313
|
return true;
|
|
3178
3314
|
}
|
|
3179
|
-
if (parent.type ===
|
|
3315
|
+
if (parent.type === AST_NODE_TYPES43.ConditionalExpression) {
|
|
3180
3316
|
return true;
|
|
3181
3317
|
}
|
|
3182
|
-
if (parent.type ===
|
|
3318
|
+
if (parent.type === AST_NODE_TYPES43.LogicalExpression) {
|
|
3183
3319
|
return true;
|
|
3184
3320
|
}
|
|
3185
|
-
if (parent.type ===
|
|
3321
|
+
if (parent.type === AST_NODE_TYPES43.AssignmentExpression && parent.left !== node) {
|
|
3186
3322
|
return true;
|
|
3187
3323
|
}
|
|
3188
3324
|
return false;
|
|
3189
3325
|
};
|
|
3190
|
-
var preferFunctionDeclaration =
|
|
3326
|
+
var preferFunctionDeclaration = createRule45({
|
|
3191
3327
|
name: "prefer-function-declaration",
|
|
3192
3328
|
meta: {
|
|
3193
3329
|
type: "suggestion",
|
|
@@ -3208,14 +3344,14 @@ var preferFunctionDeclaration = createRule43({
|
|
|
3208
3344
|
}
|
|
3209
3345
|
return {
|
|
3210
3346
|
VariableDeclarator(node) {
|
|
3211
|
-
if (node.id.type !==
|
|
3347
|
+
if (node.id.type !== AST_NODE_TYPES43.Identifier) {
|
|
3212
3348
|
return;
|
|
3213
3349
|
}
|
|
3214
3350
|
const { init } = node;
|
|
3215
3351
|
if (!init) {
|
|
3216
3352
|
return;
|
|
3217
3353
|
}
|
|
3218
|
-
if (init.type ===
|
|
3354
|
+
if (init.type === AST_NODE_TYPES43.ArrowFunctionExpression) {
|
|
3219
3355
|
if (isCallbackContext(init)) {
|
|
3220
3356
|
return;
|
|
3221
3357
|
}
|
|
@@ -3225,7 +3361,7 @@ var preferFunctionDeclaration = createRule43({
|
|
|
3225
3361
|
data: { name: node.id.name }
|
|
3226
3362
|
});
|
|
3227
3363
|
}
|
|
3228
|
-
if (init.type ===
|
|
3364
|
+
if (init.type === AST_NODE_TYPES43.FunctionExpression) {
|
|
3229
3365
|
if (isCallbackContext(init)) {
|
|
3230
3366
|
return;
|
|
3231
3367
|
}
|
|
@@ -3242,11 +3378,11 @@ var preferFunctionDeclaration = createRule43({
|
|
|
3242
3378
|
var prefer_function_declaration_default = preferFunctionDeclaration;
|
|
3243
3379
|
|
|
3244
3380
|
// src/rules/prefer-guard-clause.ts
|
|
3245
|
-
import { AST_NODE_TYPES as
|
|
3246
|
-
var
|
|
3381
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44, ESLintUtils as ESLintUtils46 } from "@typescript-eslint/utils";
|
|
3382
|
+
var createRule46 = ESLintUtils46.RuleCreator(
|
|
3247
3383
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3248
3384
|
);
|
|
3249
|
-
var preferGuardClause =
|
|
3385
|
+
var preferGuardClause = createRule46({
|
|
3250
3386
|
name: "prefer-guard-clause",
|
|
3251
3387
|
meta: {
|
|
3252
3388
|
type: "suggestion",
|
|
@@ -3263,8 +3399,8 @@ var preferGuardClause = createRule44({
|
|
|
3263
3399
|
return {
|
|
3264
3400
|
IfStatement(node) {
|
|
3265
3401
|
const { consequent } = node;
|
|
3266
|
-
if (consequent.type ===
|
|
3267
|
-
const hasNestedIf = consequent.body.some((statement) => statement.type ===
|
|
3402
|
+
if (consequent.type === AST_NODE_TYPES44.BlockStatement) {
|
|
3403
|
+
const hasNestedIf = consequent.body.some((statement) => statement.type === AST_NODE_TYPES44.IfStatement);
|
|
3268
3404
|
if (hasNestedIf && consequent.body.length === 1) {
|
|
3269
3405
|
context.report({
|
|
3270
3406
|
node,
|
|
@@ -3272,7 +3408,7 @@ var preferGuardClause = createRule44({
|
|
|
3272
3408
|
});
|
|
3273
3409
|
}
|
|
3274
3410
|
}
|
|
3275
|
-
if (consequent.type ===
|
|
3411
|
+
if (consequent.type === AST_NODE_TYPES44.IfStatement) {
|
|
3276
3412
|
context.report({
|
|
3277
3413
|
node,
|
|
3278
3414
|
messageId: "preferGuardClause"
|
|
@@ -3285,11 +3421,11 @@ var preferGuardClause = createRule44({
|
|
|
3285
3421
|
var prefer_guard_clause_default = preferGuardClause;
|
|
3286
3422
|
|
|
3287
3423
|
// src/rules/prefer-import-type.ts
|
|
3288
|
-
import { AST_NODE_TYPES as
|
|
3289
|
-
var
|
|
3424
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45, ESLintUtils as ESLintUtils47 } from "@typescript-eslint/utils";
|
|
3425
|
+
var createRule47 = ESLintUtils47.RuleCreator(
|
|
3290
3426
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3291
3427
|
);
|
|
3292
|
-
var preferImportType =
|
|
3428
|
+
var preferImportType = createRule47({
|
|
3293
3429
|
name: "prefer-import-type",
|
|
3294
3430
|
meta: {
|
|
3295
3431
|
type: "suggestion",
|
|
@@ -3308,22 +3444,22 @@ var preferImportType = createRule45({
|
|
|
3308
3444
|
let current = node;
|
|
3309
3445
|
while (current) {
|
|
3310
3446
|
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
|
|
3447
|
+
case AST_NODE_TYPES45.TSTypeReference:
|
|
3448
|
+
case AST_NODE_TYPES45.TSTypeAnnotation:
|
|
3449
|
+
case AST_NODE_TYPES45.TSTypeParameterInstantiation:
|
|
3450
|
+
case AST_NODE_TYPES45.TSInterfaceHeritage:
|
|
3451
|
+
case AST_NODE_TYPES45.TSClassImplements:
|
|
3452
|
+
case AST_NODE_TYPES45.TSTypeQuery:
|
|
3453
|
+
case AST_NODE_TYPES45.TSTypeAssertion:
|
|
3454
|
+
case AST_NODE_TYPES45.TSAsExpression:
|
|
3455
|
+
case AST_NODE_TYPES45.TSSatisfiesExpression:
|
|
3456
|
+
case AST_NODE_TYPES45.TSTypeAliasDeclaration:
|
|
3457
|
+
case AST_NODE_TYPES45.TSInterfaceDeclaration:
|
|
3458
|
+
case AST_NODE_TYPES45.TSTypeParameter:
|
|
3459
|
+
case AST_NODE_TYPES45.TSQualifiedName:
|
|
3324
3460
|
return true;
|
|
3325
|
-
case
|
|
3326
|
-
case
|
|
3461
|
+
case AST_NODE_TYPES45.MemberExpression:
|
|
3462
|
+
case AST_NODE_TYPES45.Identifier:
|
|
3327
3463
|
current = current.parent;
|
|
3328
3464
|
break;
|
|
3329
3465
|
default:
|
|
@@ -3353,27 +3489,27 @@ var preferImportType = createRule45({
|
|
|
3353
3489
|
return false;
|
|
3354
3490
|
}
|
|
3355
3491
|
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
|
|
3492
|
+
case AST_NODE_TYPES45.CallExpression:
|
|
3493
|
+
case AST_NODE_TYPES45.NewExpression:
|
|
3494
|
+
case AST_NODE_TYPES45.JSXOpeningElement:
|
|
3495
|
+
case AST_NODE_TYPES45.JSXClosingElement:
|
|
3496
|
+
case AST_NODE_TYPES45.MemberExpression:
|
|
3497
|
+
case AST_NODE_TYPES45.VariableDeclarator:
|
|
3498
|
+
case AST_NODE_TYPES45.TaggedTemplateExpression:
|
|
3499
|
+
case AST_NODE_TYPES45.SpreadElement:
|
|
3500
|
+
case AST_NODE_TYPES45.ExportSpecifier:
|
|
3501
|
+
case AST_NODE_TYPES45.ArrayExpression:
|
|
3502
|
+
case AST_NODE_TYPES45.ObjectExpression:
|
|
3503
|
+
case AST_NODE_TYPES45.BinaryExpression:
|
|
3504
|
+
case AST_NODE_TYPES45.LogicalExpression:
|
|
3505
|
+
case AST_NODE_TYPES45.UnaryExpression:
|
|
3506
|
+
case AST_NODE_TYPES45.ReturnStatement:
|
|
3507
|
+
case AST_NODE_TYPES45.ArrowFunctionExpression:
|
|
3508
|
+
case AST_NODE_TYPES45.ConditionalExpression:
|
|
3509
|
+
case AST_NODE_TYPES45.AwaitExpression:
|
|
3510
|
+
case AST_NODE_TYPES45.YieldExpression:
|
|
3511
|
+
case AST_NODE_TYPES45.Property:
|
|
3512
|
+
case AST_NODE_TYPES45.JSXExpressionContainer:
|
|
3377
3513
|
return true;
|
|
3378
3514
|
default:
|
|
3379
3515
|
return false;
|
|
@@ -3397,13 +3533,13 @@ var preferImportType = createRule45({
|
|
|
3397
3533
|
}
|
|
3398
3534
|
const scope = context.sourceCode.getScope(node);
|
|
3399
3535
|
const isTypeOnlyImport2 = node.specifiers.every((specifier) => {
|
|
3400
|
-
if (specifier.type ===
|
|
3536
|
+
if (specifier.type === AST_NODE_TYPES45.ImportDefaultSpecifier) {
|
|
3401
3537
|
return false;
|
|
3402
3538
|
}
|
|
3403
|
-
if (specifier.type ===
|
|
3539
|
+
if (specifier.type === AST_NODE_TYPES45.ImportNamespaceSpecifier) {
|
|
3404
3540
|
return false;
|
|
3405
3541
|
}
|
|
3406
|
-
if (specifier.type ===
|
|
3542
|
+
if (specifier.type === AST_NODE_TYPES45.ImportSpecifier) {
|
|
3407
3543
|
const localName = specifier.local.name;
|
|
3408
3544
|
return !isUsedAsValue(localName, scope);
|
|
3409
3545
|
}
|
|
@@ -3429,19 +3565,19 @@ var preferImportType = createRule45({
|
|
|
3429
3565
|
var prefer_import_type_default = preferImportType;
|
|
3430
3566
|
|
|
3431
3567
|
// src/rules/prefer-inline-literal-union.ts
|
|
3432
|
-
import { AST_NODE_TYPES as
|
|
3433
|
-
var
|
|
3568
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46, ESLintUtils as ESLintUtils48 } from "@typescript-eslint/utils";
|
|
3569
|
+
var createRule48 = ESLintUtils48.RuleCreator(
|
|
3434
3570
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3435
3571
|
);
|
|
3436
3572
|
function isLiteralUnionType(node) {
|
|
3437
|
-
if (node.type !==
|
|
3573
|
+
if (node.type !== AST_NODE_TYPES46.TSUnionType) {
|
|
3438
3574
|
return false;
|
|
3439
3575
|
}
|
|
3440
3576
|
return node.types.every(
|
|
3441
|
-
(member) => member.type ===
|
|
3577
|
+
(member) => member.type === AST_NODE_TYPES46.TSLiteralType || member.type === AST_NODE_TYPES46.TSNullKeyword || member.type === AST_NODE_TYPES46.TSUndefinedKeyword
|
|
3442
3578
|
);
|
|
3443
3579
|
}
|
|
3444
|
-
var preferInlineLiteralUnion =
|
|
3580
|
+
var preferInlineLiteralUnion = createRule48({
|
|
3445
3581
|
name: "prefer-inline-literal-union",
|
|
3446
3582
|
meta: {
|
|
3447
3583
|
type: "suggestion",
|
|
@@ -3468,10 +3604,10 @@ var preferInlineLiteralUnion = createRule46({
|
|
|
3468
3604
|
return;
|
|
3469
3605
|
}
|
|
3470
3606
|
const { typeAnnotation } = node.typeAnnotation;
|
|
3471
|
-
if (typeAnnotation.type !==
|
|
3607
|
+
if (typeAnnotation.type !== AST_NODE_TYPES46.TSTypeReference) {
|
|
3472
3608
|
return;
|
|
3473
3609
|
}
|
|
3474
|
-
if (typeAnnotation.typeName.type !==
|
|
3610
|
+
if (typeAnnotation.typeName.type !== AST_NODE_TYPES46.Identifier) {
|
|
3475
3611
|
return;
|
|
3476
3612
|
}
|
|
3477
3613
|
const aliasName = typeAnnotation.typeName.name;
|
|
@@ -3495,12 +3631,12 @@ var preferInlineLiteralUnion = createRule46({
|
|
|
3495
3631
|
var prefer_inline_literal_union_default = preferInlineLiteralUnion;
|
|
3496
3632
|
|
|
3497
3633
|
// src/rules/prefer-inline-type-export.ts
|
|
3498
|
-
import { AST_NODE_TYPES as
|
|
3499
|
-
var
|
|
3634
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47, ESLintUtils as ESLintUtils49 } from "@typescript-eslint/utils";
|
|
3635
|
+
var createRule49 = ESLintUtils49.RuleCreator(
|
|
3500
3636
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3501
3637
|
);
|
|
3502
|
-
var isTypeDeclaration = (node) => node.type ===
|
|
3503
|
-
var preferInlineTypeExport =
|
|
3638
|
+
var isTypeDeclaration = (node) => node.type === AST_NODE_TYPES47.TSInterfaceDeclaration || node.type === AST_NODE_TYPES47.TSTypeAliasDeclaration;
|
|
3639
|
+
var preferInlineTypeExport = createRule49({
|
|
3504
3640
|
name: "prefer-inline-type-export",
|
|
3505
3641
|
meta: {
|
|
3506
3642
|
type: "suggestion",
|
|
@@ -3517,12 +3653,12 @@ var preferInlineTypeExport = createRule47({
|
|
|
3517
3653
|
create(context) {
|
|
3518
3654
|
const typeDeclarations = /* @__PURE__ */ new Map();
|
|
3519
3655
|
function collectDeclaration(node) {
|
|
3520
|
-
if (node.parent.type !==
|
|
3656
|
+
if (node.parent.type !== AST_NODE_TYPES47.ExportNamedDeclaration) {
|
|
3521
3657
|
typeDeclarations.set(node.id.name, node);
|
|
3522
3658
|
}
|
|
3523
3659
|
}
|
|
3524
3660
|
function reportSpecifier(specifier, statement, declarationNode) {
|
|
3525
|
-
if (specifier.local.type !==
|
|
3661
|
+
if (specifier.local.type !== AST_NODE_TYPES47.Identifier) {
|
|
3526
3662
|
return;
|
|
3527
3663
|
}
|
|
3528
3664
|
const { name } = specifier.local;
|
|
@@ -3555,16 +3691,16 @@ var preferInlineTypeExport = createRule47({
|
|
|
3555
3691
|
return {
|
|
3556
3692
|
Program(node) {
|
|
3557
3693
|
node.body.forEach((statement) => {
|
|
3558
|
-
if (statement.type ===
|
|
3694
|
+
if (statement.type === AST_NODE_TYPES47.TSInterfaceDeclaration || statement.type === AST_NODE_TYPES47.TSTypeAliasDeclaration) {
|
|
3559
3695
|
collectDeclaration(statement);
|
|
3560
3696
|
}
|
|
3561
3697
|
});
|
|
3562
3698
|
node.body.forEach((statement) => {
|
|
3563
|
-
if (statement.type !==
|
|
3699
|
+
if (statement.type !== AST_NODE_TYPES47.ExportNamedDeclaration || statement.declaration !== null) {
|
|
3564
3700
|
return;
|
|
3565
3701
|
}
|
|
3566
3702
|
statement.specifiers.forEach((specifier) => {
|
|
3567
|
-
if (specifier.local.type !==
|
|
3703
|
+
if (specifier.local.type !== AST_NODE_TYPES47.Identifier) {
|
|
3568
3704
|
return;
|
|
3569
3705
|
}
|
|
3570
3706
|
const declarationNode = typeDeclarations.get(specifier.local.name);
|
|
@@ -3581,11 +3717,11 @@ var preferInlineTypeExport = createRule47({
|
|
|
3581
3717
|
var prefer_inline_type_export_default = preferInlineTypeExport;
|
|
3582
3718
|
|
|
3583
3719
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
3584
|
-
import { AST_NODE_TYPES as
|
|
3585
|
-
var
|
|
3720
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48, ESLintUtils as ESLintUtils50 } from "@typescript-eslint/utils";
|
|
3721
|
+
var createRule50 = ESLintUtils50.RuleCreator(
|
|
3586
3722
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3587
3723
|
);
|
|
3588
|
-
var preferInterfaceOverInlineTypes =
|
|
3724
|
+
var preferInterfaceOverInlineTypes = createRule50({
|
|
3589
3725
|
name: "prefer-interface-over-inline-types",
|
|
3590
3726
|
meta: {
|
|
3591
3727
|
type: "suggestion",
|
|
@@ -3601,54 +3737,54 @@ var preferInterfaceOverInlineTypes = createRule48({
|
|
|
3601
3737
|
defaultOptions: [],
|
|
3602
3738
|
create(context) {
|
|
3603
3739
|
function hasJSXInConditional(node) {
|
|
3604
|
-
return node.consequent.type ===
|
|
3740
|
+
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
3741
|
}
|
|
3606
3742
|
function hasJSXInLogical(node) {
|
|
3607
|
-
return node.right.type ===
|
|
3743
|
+
return node.right.type === AST_NODE_TYPES48.JSXElement || node.right.type === AST_NODE_TYPES48.JSXFragment;
|
|
3608
3744
|
}
|
|
3609
3745
|
function hasJSXReturn(block) {
|
|
3610
3746
|
return block.body.some((stmt) => {
|
|
3611
|
-
if (stmt.type ===
|
|
3612
|
-
return stmt.argument.type ===
|
|
3747
|
+
if (stmt.type === AST_NODE_TYPES48.ReturnStatement && stmt.argument) {
|
|
3748
|
+
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
3749
|
}
|
|
3614
3750
|
return false;
|
|
3615
3751
|
});
|
|
3616
3752
|
}
|
|
3617
3753
|
function isReactComponent2(node) {
|
|
3618
|
-
if (node.type ===
|
|
3619
|
-
if (node.body.type ===
|
|
3754
|
+
if (node.type === AST_NODE_TYPES48.ArrowFunctionExpression) {
|
|
3755
|
+
if (node.body.type === AST_NODE_TYPES48.JSXElement || node.body.type === AST_NODE_TYPES48.JSXFragment) {
|
|
3620
3756
|
return true;
|
|
3621
3757
|
}
|
|
3622
|
-
if (node.body.type ===
|
|
3758
|
+
if (node.body.type === AST_NODE_TYPES48.BlockStatement) {
|
|
3623
3759
|
return hasJSXReturn(node.body);
|
|
3624
3760
|
}
|
|
3625
|
-
} else if (node.type ===
|
|
3626
|
-
if (node.body && node.body.type ===
|
|
3761
|
+
} else if (node.type === AST_NODE_TYPES48.FunctionExpression || node.type === AST_NODE_TYPES48.FunctionDeclaration) {
|
|
3762
|
+
if (node.body && node.body.type === AST_NODE_TYPES48.BlockStatement) {
|
|
3627
3763
|
return hasJSXReturn(node.body);
|
|
3628
3764
|
}
|
|
3629
3765
|
}
|
|
3630
3766
|
return false;
|
|
3631
3767
|
}
|
|
3632
3768
|
function isInlineTypeAnnotation(node) {
|
|
3633
|
-
if (node.type ===
|
|
3769
|
+
if (node.type === AST_NODE_TYPES48.TSTypeLiteral) {
|
|
3634
3770
|
return true;
|
|
3635
3771
|
}
|
|
3636
|
-
if (node.type ===
|
|
3637
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3772
|
+
if (node.type === AST_NODE_TYPES48.TSTypeReference && node.typeArguments) {
|
|
3773
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES48.TSTypeLiteral);
|
|
3638
3774
|
}
|
|
3639
|
-
if (node.type ===
|
|
3775
|
+
if (node.type === AST_NODE_TYPES48.TSUnionType) {
|
|
3640
3776
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
3641
3777
|
}
|
|
3642
3778
|
return false;
|
|
3643
3779
|
}
|
|
3644
3780
|
function hasInlineObjectType(node) {
|
|
3645
|
-
if (node.type ===
|
|
3781
|
+
if (node.type === AST_NODE_TYPES48.TSTypeLiteral) {
|
|
3646
3782
|
return true;
|
|
3647
3783
|
}
|
|
3648
|
-
if (node.type ===
|
|
3649
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3784
|
+
if (node.type === AST_NODE_TYPES48.TSTypeReference && node.typeArguments) {
|
|
3785
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES48.TSTypeLiteral);
|
|
3650
3786
|
}
|
|
3651
|
-
if (node.type ===
|
|
3787
|
+
if (node.type === AST_NODE_TYPES48.TSUnionType) {
|
|
3652
3788
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
3653
3789
|
}
|
|
3654
3790
|
return false;
|
|
@@ -3661,7 +3797,7 @@ var preferInterfaceOverInlineTypes = createRule48({
|
|
|
3661
3797
|
return;
|
|
3662
3798
|
}
|
|
3663
3799
|
const param = node.params[0];
|
|
3664
|
-
if (param.type ===
|
|
3800
|
+
if (param.type === AST_NODE_TYPES48.Identifier && param.typeAnnotation) {
|
|
3665
3801
|
const { typeAnnotation } = param.typeAnnotation;
|
|
3666
3802
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
3667
3803
|
context.report({
|
|
@@ -3681,11 +3817,11 @@ var preferInterfaceOverInlineTypes = createRule48({
|
|
|
3681
3817
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
3682
3818
|
|
|
3683
3819
|
// src/rules/prefer-jsx-template-literals.ts
|
|
3684
|
-
import { AST_NODE_TYPES as
|
|
3685
|
-
var
|
|
3820
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49, ESLintUtils as ESLintUtils51 } from "@typescript-eslint/utils";
|
|
3821
|
+
var createRule51 = ESLintUtils51.RuleCreator(
|
|
3686
3822
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3687
3823
|
);
|
|
3688
|
-
var preferJSXTemplateLiterals =
|
|
3824
|
+
var preferJSXTemplateLiterals = createRule51({
|
|
3689
3825
|
name: "prefer-jsx-template-literals",
|
|
3690
3826
|
meta: {
|
|
3691
3827
|
type: "suggestion",
|
|
@@ -3754,9 +3890,9 @@ var preferJSXTemplateLiterals = createRule49({
|
|
|
3754
3890
|
if (!child || !nextChild) {
|
|
3755
3891
|
return;
|
|
3756
3892
|
}
|
|
3757
|
-
if (child.type ===
|
|
3893
|
+
if (child.type === AST_NODE_TYPES49.JSXText && nextChild.type === AST_NODE_TYPES49.JSXExpressionContainer) {
|
|
3758
3894
|
handleTextBeforeExpression(child, nextChild);
|
|
3759
|
-
} else if (child.type ===
|
|
3895
|
+
} else if (child.type === AST_NODE_TYPES49.JSXExpressionContainer && nextChild.type === AST_NODE_TYPES49.JSXText) {
|
|
3760
3896
|
handleExpressionBeforeText(child, nextChild);
|
|
3761
3897
|
}
|
|
3762
3898
|
}
|
|
@@ -3769,11 +3905,11 @@ var preferJSXTemplateLiterals = createRule49({
|
|
|
3769
3905
|
var prefer_jsx_template_literals_default = preferJSXTemplateLiterals;
|
|
3770
3906
|
|
|
3771
3907
|
// src/rules/prefer-named-param-types.ts
|
|
3772
|
-
import { AST_NODE_TYPES as
|
|
3773
|
-
var
|
|
3908
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50, ESLintUtils as ESLintUtils52 } from "@typescript-eslint/utils";
|
|
3909
|
+
var createRule52 = ESLintUtils52.RuleCreator(
|
|
3774
3910
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3775
3911
|
);
|
|
3776
|
-
var preferNamedParamTypes =
|
|
3912
|
+
var preferNamedParamTypes = createRule52({
|
|
3777
3913
|
name: "prefer-named-param-types",
|
|
3778
3914
|
meta: {
|
|
3779
3915
|
type: "suggestion",
|
|
@@ -3788,16 +3924,16 @@ var preferNamedParamTypes = createRule50({
|
|
|
3788
3924
|
defaultOptions: [],
|
|
3789
3925
|
create(context) {
|
|
3790
3926
|
function hasInlineObjectType(param) {
|
|
3791
|
-
if (param.type ===
|
|
3927
|
+
if (param.type === AST_NODE_TYPES50.AssignmentPattern) {
|
|
3792
3928
|
return hasInlineObjectType(param.left);
|
|
3793
3929
|
}
|
|
3794
|
-
if (param.type ===
|
|
3795
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3930
|
+
if (param.type === AST_NODE_TYPES50.ObjectPattern) {
|
|
3931
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES50.TSTypeLiteral) {
|
|
3796
3932
|
return true;
|
|
3797
3933
|
}
|
|
3798
3934
|
}
|
|
3799
|
-
if (param.type ===
|
|
3800
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3935
|
+
if (param.type === AST_NODE_TYPES50.Identifier) {
|
|
3936
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES50.TSTypeLiteral) {
|
|
3801
3937
|
return true;
|
|
3802
3938
|
}
|
|
3803
3939
|
}
|
|
@@ -3831,11 +3967,11 @@ var preferNamedParamTypes = createRule50({
|
|
|
3831
3967
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
3832
3968
|
|
|
3833
3969
|
// src/rules/prefer-react-import-types.ts
|
|
3834
|
-
import { AST_NODE_TYPES as
|
|
3835
|
-
var
|
|
3970
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ESLintUtils as ESLintUtils53 } from "@typescript-eslint/utils";
|
|
3971
|
+
var createRule53 = ESLintUtils53.RuleCreator(
|
|
3836
3972
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3837
3973
|
);
|
|
3838
|
-
var preferReactImportTypes =
|
|
3974
|
+
var preferReactImportTypes = createRule53({
|
|
3839
3975
|
name: "prefer-react-import-types",
|
|
3840
3976
|
meta: {
|
|
3841
3977
|
type: "suggestion",
|
|
@@ -3911,7 +4047,7 @@ var preferReactImportTypes = createRule51({
|
|
|
3911
4047
|
]);
|
|
3912
4048
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
3913
4049
|
function checkMemberExpression(node) {
|
|
3914
|
-
if (node.object.type ===
|
|
4050
|
+
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
4051
|
const typeName = node.property.name;
|
|
3916
4052
|
const isType = reactTypes.has(typeName);
|
|
3917
4053
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -3928,7 +4064,7 @@ var preferReactImportTypes = createRule51({
|
|
|
3928
4064
|
return {
|
|
3929
4065
|
MemberExpression: checkMemberExpression,
|
|
3930
4066
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
3931
|
-
if (node.left.type ===
|
|
4067
|
+
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
4068
|
const typeName = node.right.name;
|
|
3933
4069
|
const isType = reactTypes.has(typeName);
|
|
3934
4070
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -3948,11 +4084,11 @@ var preferReactImportTypes = createRule51({
|
|
|
3948
4084
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
3949
4085
|
|
|
3950
4086
|
// src/rules/react-props-destructure.ts
|
|
3951
|
-
import { AST_NODE_TYPES as
|
|
3952
|
-
var
|
|
4087
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES52, ESLintUtils as ESLintUtils54 } from "@typescript-eslint/utils";
|
|
4088
|
+
var createRule54 = ESLintUtils54.RuleCreator(
|
|
3953
4089
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3954
4090
|
);
|
|
3955
|
-
var reactPropsDestructure =
|
|
4091
|
+
var reactPropsDestructure = createRule54({
|
|
3956
4092
|
name: "react-props-destructure",
|
|
3957
4093
|
meta: {
|
|
3958
4094
|
type: "suggestion",
|
|
@@ -3968,29 +4104,29 @@ var reactPropsDestructure = createRule52({
|
|
|
3968
4104
|
defaultOptions: [],
|
|
3969
4105
|
create(context) {
|
|
3970
4106
|
function hasJSXInConditional(node) {
|
|
3971
|
-
return node.consequent.type ===
|
|
4107
|
+
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
4108
|
}
|
|
3973
4109
|
function hasJSXInLogical(node) {
|
|
3974
|
-
return node.right.type ===
|
|
4110
|
+
return node.right.type === AST_NODE_TYPES52.JSXElement || node.right.type === AST_NODE_TYPES52.JSXFragment;
|
|
3975
4111
|
}
|
|
3976
4112
|
function hasJSXReturn(block) {
|
|
3977
4113
|
return block.body.some((stmt) => {
|
|
3978
|
-
if (stmt.type ===
|
|
3979
|
-
return stmt.argument.type ===
|
|
4114
|
+
if (stmt.type === AST_NODE_TYPES52.ReturnStatement && stmt.argument) {
|
|
4115
|
+
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
4116
|
}
|
|
3981
4117
|
return false;
|
|
3982
4118
|
});
|
|
3983
4119
|
}
|
|
3984
4120
|
function isReactComponent2(node) {
|
|
3985
|
-
if (node.type ===
|
|
3986
|
-
if (node.body.type ===
|
|
4121
|
+
if (node.type === AST_NODE_TYPES52.ArrowFunctionExpression) {
|
|
4122
|
+
if (node.body.type === AST_NODE_TYPES52.JSXElement || node.body.type === AST_NODE_TYPES52.JSXFragment) {
|
|
3987
4123
|
return true;
|
|
3988
4124
|
}
|
|
3989
|
-
if (node.body.type ===
|
|
4125
|
+
if (node.body.type === AST_NODE_TYPES52.BlockStatement) {
|
|
3990
4126
|
return hasJSXReturn(node.body);
|
|
3991
4127
|
}
|
|
3992
|
-
} else if (node.type ===
|
|
3993
|
-
if (node.body && node.body.type ===
|
|
4128
|
+
} else if (node.type === AST_NODE_TYPES52.FunctionExpression || node.type === AST_NODE_TYPES52.FunctionDeclaration) {
|
|
4129
|
+
if (node.body && node.body.type === AST_NODE_TYPES52.BlockStatement) {
|
|
3994
4130
|
return hasJSXReturn(node.body);
|
|
3995
4131
|
}
|
|
3996
4132
|
}
|
|
@@ -4004,9 +4140,9 @@ var reactPropsDestructure = createRule52({
|
|
|
4004
4140
|
return;
|
|
4005
4141
|
}
|
|
4006
4142
|
const param = node.params[0];
|
|
4007
|
-
if (param.type ===
|
|
4008
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
4009
|
-
if (prop.key.type ===
|
|
4143
|
+
if (param.type === AST_NODE_TYPES52.ObjectPattern) {
|
|
4144
|
+
const properties = param.properties.filter((prop) => prop.type === AST_NODE_TYPES52.Property).map((prop) => {
|
|
4145
|
+
if (prop.key.type === AST_NODE_TYPES52.Identifier) {
|
|
4010
4146
|
return prop.key.name;
|
|
4011
4147
|
}
|
|
4012
4148
|
return null;
|
|
@@ -4033,57 +4169,57 @@ var reactPropsDestructure = createRule52({
|
|
|
4033
4169
|
var react_props_destructure_default = reactPropsDestructure;
|
|
4034
4170
|
|
|
4035
4171
|
// src/rules/require-explicit-return-type.ts
|
|
4036
|
-
import { AST_NODE_TYPES as
|
|
4037
|
-
var
|
|
4172
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES53, ESLintUtils as ESLintUtils55 } from "@typescript-eslint/utils";
|
|
4173
|
+
var createRule55 = ESLintUtils55.RuleCreator(
|
|
4038
4174
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4039
4175
|
);
|
|
4040
4176
|
var isReactComponent = (node) => {
|
|
4041
|
-
if (node.type ===
|
|
4177
|
+
if (node.type === AST_NODE_TYPES53.ArrowFunctionExpression) {
|
|
4042
4178
|
const { parent } = node;
|
|
4043
|
-
if (parent?.type ===
|
|
4179
|
+
if (parent?.type === AST_NODE_TYPES53.VariableDeclarator) {
|
|
4044
4180
|
const { id } = parent;
|
|
4045
|
-
if (id.type ===
|
|
4181
|
+
if (id.type === AST_NODE_TYPES53.Identifier) {
|
|
4046
4182
|
return /^[A-Z]/.test(id.name);
|
|
4047
4183
|
}
|
|
4048
4184
|
}
|
|
4049
4185
|
}
|
|
4050
|
-
if (node.type ===
|
|
4186
|
+
if (node.type === AST_NODE_TYPES53.FunctionDeclaration && node.id) {
|
|
4051
4187
|
return /^[A-Z]/.test(node.id.name);
|
|
4052
4188
|
}
|
|
4053
4189
|
return false;
|
|
4054
4190
|
};
|
|
4055
4191
|
var isCallbackFunction = (node) => {
|
|
4056
|
-
if (node.type ===
|
|
4192
|
+
if (node.type === AST_NODE_TYPES53.FunctionDeclaration) {
|
|
4057
4193
|
return false;
|
|
4058
4194
|
}
|
|
4059
4195
|
const { parent } = node;
|
|
4060
4196
|
if (!parent) {
|
|
4061
4197
|
return false;
|
|
4062
4198
|
}
|
|
4063
|
-
if (parent.type ===
|
|
4199
|
+
if (parent.type === AST_NODE_TYPES53.CallExpression && parent.arguments.includes(node)) {
|
|
4064
4200
|
return true;
|
|
4065
4201
|
}
|
|
4066
|
-
if (parent.type ===
|
|
4202
|
+
if (parent.type === AST_NODE_TYPES53.Property) {
|
|
4067
4203
|
return true;
|
|
4068
4204
|
}
|
|
4069
|
-
if (parent.type ===
|
|
4205
|
+
if (parent.type === AST_NODE_TYPES53.ArrayExpression) {
|
|
4070
4206
|
return true;
|
|
4071
4207
|
}
|
|
4072
4208
|
return false;
|
|
4073
4209
|
};
|
|
4074
4210
|
var getFunctionName = (node) => {
|
|
4075
|
-
if (node.type ===
|
|
4211
|
+
if (node.type === AST_NODE_TYPES53.FunctionDeclaration && node.id) {
|
|
4076
4212
|
return node.id.name;
|
|
4077
4213
|
}
|
|
4078
|
-
if (node.type ===
|
|
4214
|
+
if (node.type === AST_NODE_TYPES53.FunctionExpression && node.id) {
|
|
4079
4215
|
return node.id.name;
|
|
4080
4216
|
}
|
|
4081
|
-
if ((node.type ===
|
|
4217
|
+
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
4218
|
return node.parent.id.name;
|
|
4083
4219
|
}
|
|
4084
4220
|
return null;
|
|
4085
4221
|
};
|
|
4086
|
-
var requireExplicitReturnType =
|
|
4222
|
+
var requireExplicitReturnType = createRule55({
|
|
4087
4223
|
name: "require-explicit-return-type",
|
|
4088
4224
|
meta: {
|
|
4089
4225
|
type: "suggestion",
|
|
@@ -4132,8 +4268,8 @@ var requireExplicitReturnType = createRule53({
|
|
|
4132
4268
|
var require_explicit_return_type_default = requireExplicitReturnType;
|
|
4133
4269
|
|
|
4134
4270
|
// src/rules/sort-exports.ts
|
|
4135
|
-
import { AST_NODE_TYPES as
|
|
4136
|
-
var
|
|
4271
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES54, ESLintUtils as ESLintUtils56 } from "@typescript-eslint/utils";
|
|
4272
|
+
var createRule56 = ESLintUtils56.RuleCreator(
|
|
4137
4273
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4138
4274
|
);
|
|
4139
4275
|
var GROUP_NAMES = ["", "external/alias re-export", "relative re-export", "local export"];
|
|
@@ -4147,7 +4283,7 @@ function getExportGroup(node) {
|
|
|
4147
4283
|
}
|
|
4148
4284
|
return 1;
|
|
4149
4285
|
}
|
|
4150
|
-
var sortExports =
|
|
4286
|
+
var sortExports = createRule56({
|
|
4151
4287
|
name: "sort-exports",
|
|
4152
4288
|
meta: {
|
|
4153
4289
|
type: "suggestion",
|
|
@@ -4187,7 +4323,7 @@ var sortExports = createRule54({
|
|
|
4187
4323
|
Program(node) {
|
|
4188
4324
|
const exportGroups = [];
|
|
4189
4325
|
node.body.forEach((statement) => {
|
|
4190
|
-
if (statement.type !==
|
|
4326
|
+
if (statement.type !== AST_NODE_TYPES54.ExportNamedDeclaration || statement.declaration !== null) {
|
|
4191
4327
|
if (exportGroups.length > 0) {
|
|
4192
4328
|
checkOrder(exportGroups);
|
|
4193
4329
|
exportGroups.length = 0;
|
|
@@ -4206,8 +4342,8 @@ var sortExports = createRule54({
|
|
|
4206
4342
|
var sort_exports_default = sortExports;
|
|
4207
4343
|
|
|
4208
4344
|
// src/rules/sort-imports.ts
|
|
4209
|
-
import { AST_NODE_TYPES as
|
|
4210
|
-
var
|
|
4345
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55, ESLintUtils as ESLintUtils57 } from "@typescript-eslint/utils";
|
|
4346
|
+
var createRule57 = ESLintUtils57.RuleCreator(
|
|
4211
4347
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4212
4348
|
);
|
|
4213
4349
|
var NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
@@ -4274,7 +4410,7 @@ function getImportGroup(node) {
|
|
|
4274
4410
|
function isTypeOnlyImport(node) {
|
|
4275
4411
|
return node.importKind === "type" && node.specifiers.length > 0;
|
|
4276
4412
|
}
|
|
4277
|
-
var sortImports =
|
|
4413
|
+
var sortImports = createRule57({
|
|
4278
4414
|
name: "sort-imports",
|
|
4279
4415
|
meta: {
|
|
4280
4416
|
type: "suggestion",
|
|
@@ -4318,7 +4454,7 @@ var sortImports = createRule55({
|
|
|
4318
4454
|
Program(node) {
|
|
4319
4455
|
const importGroups = [];
|
|
4320
4456
|
node.body.forEach((statement) => {
|
|
4321
|
-
if (statement.type !==
|
|
4457
|
+
if (statement.type !== AST_NODE_TYPES55.ImportDeclaration) {
|
|
4322
4458
|
if (importGroups.length > 0) {
|
|
4323
4459
|
checkOrder(importGroups);
|
|
4324
4460
|
importGroups.length = 0;
|
|
@@ -4340,13 +4476,13 @@ var sortImports = createRule55({
|
|
|
4340
4476
|
var sort_imports_default = sortImports;
|
|
4341
4477
|
|
|
4342
4478
|
// src/rules/sort-type-alphabetically.ts
|
|
4343
|
-
import { AST_NODE_TYPES as
|
|
4344
|
-
var
|
|
4479
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES56, ESLintUtils as ESLintUtils58 } from "@typescript-eslint/utils";
|
|
4480
|
+
var createRule58 = ESLintUtils58.RuleCreator(
|
|
4345
4481
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4346
4482
|
);
|
|
4347
4483
|
function isAlphabeticallySortedWithinGroups(members) {
|
|
4348
4484
|
const properties = members.filter(
|
|
4349
|
-
(member) => member.type ===
|
|
4485
|
+
(member) => member.type === AST_NODE_TYPES56.TSPropertySignature && member.key.type === AST_NODE_TYPES56.Identifier
|
|
4350
4486
|
);
|
|
4351
4487
|
if (properties.length < 2) {
|
|
4352
4488
|
return true;
|
|
@@ -4357,7 +4493,7 @@ function isAlphabeticallySortedWithinGroups(members) {
|
|
|
4357
4493
|
const isOptionalSorted = optional.every((name, index) => index === 0 || optional[index - 1].localeCompare(name) <= 0);
|
|
4358
4494
|
return isRequiredSorted && isOptionalSorted;
|
|
4359
4495
|
}
|
|
4360
|
-
var sortTypeAlphabetically =
|
|
4496
|
+
var sortTypeAlphabetically = createRule58({
|
|
4361
4497
|
name: "sort-type-alphabetically",
|
|
4362
4498
|
meta: {
|
|
4363
4499
|
type: "suggestion",
|
|
@@ -4375,7 +4511,7 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4375
4511
|
function fixMembers(fixer, members) {
|
|
4376
4512
|
const { sourceCode } = context;
|
|
4377
4513
|
const properties = members.filter(
|
|
4378
|
-
(member) => member.type ===
|
|
4514
|
+
(member) => member.type === AST_NODE_TYPES56.TSPropertySignature && member.key.type === AST_NODE_TYPES56.Identifier
|
|
4379
4515
|
);
|
|
4380
4516
|
const required = properties.filter((prop) => !prop.optional);
|
|
4381
4517
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4412,7 +4548,7 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4412
4548
|
}
|
|
4413
4549
|
},
|
|
4414
4550
|
TSTypeAliasDeclaration(node) {
|
|
4415
|
-
if (node.typeAnnotation.type !==
|
|
4551
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES56.TSTypeLiteral) {
|
|
4416
4552
|
return;
|
|
4417
4553
|
}
|
|
4418
4554
|
const { members } = node.typeAnnotation;
|
|
@@ -4432,13 +4568,13 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4432
4568
|
var sort_type_alphabetically_default = sortTypeAlphabetically;
|
|
4433
4569
|
|
|
4434
4570
|
// src/rules/sort-type-required-first.ts
|
|
4435
|
-
import { AST_NODE_TYPES as
|
|
4436
|
-
var
|
|
4571
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES57, ESLintUtils as ESLintUtils59 } from "@typescript-eslint/utils";
|
|
4572
|
+
var createRule59 = ESLintUtils59.RuleCreator(
|
|
4437
4573
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4438
4574
|
);
|
|
4439
4575
|
function isRequiredBeforeOptional(members) {
|
|
4440
4576
|
const properties = members.filter(
|
|
4441
|
-
(member) => member.type ===
|
|
4577
|
+
(member) => member.type === AST_NODE_TYPES57.TSPropertySignature && member.key.type === AST_NODE_TYPES57.Identifier
|
|
4442
4578
|
);
|
|
4443
4579
|
if (properties.length < 2) {
|
|
4444
4580
|
return true;
|
|
@@ -4449,7 +4585,7 @@ function isRequiredBeforeOptional(members) {
|
|
|
4449
4585
|
}
|
|
4450
4586
|
return properties.slice(firstOptionalIndex).every((prop) => prop.optional);
|
|
4451
4587
|
}
|
|
4452
|
-
var sortTypeRequiredFirst =
|
|
4588
|
+
var sortTypeRequiredFirst = createRule59({
|
|
4453
4589
|
name: "sort-type-required-first",
|
|
4454
4590
|
meta: {
|
|
4455
4591
|
type: "suggestion",
|
|
@@ -4467,7 +4603,7 @@ var sortTypeRequiredFirst = createRule57({
|
|
|
4467
4603
|
function fixMembers(fixer, members) {
|
|
4468
4604
|
const { sourceCode } = context;
|
|
4469
4605
|
const properties = members.filter(
|
|
4470
|
-
(member) => member.type ===
|
|
4606
|
+
(member) => member.type === AST_NODE_TYPES57.TSPropertySignature && member.key.type === AST_NODE_TYPES57.Identifier
|
|
4471
4607
|
);
|
|
4472
4608
|
const required = properties.filter((prop) => !prop.optional);
|
|
4473
4609
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4488,7 +4624,7 @@ var sortTypeRequiredFirst = createRule57({
|
|
|
4488
4624
|
}
|
|
4489
4625
|
},
|
|
4490
4626
|
TSTypeAliasDeclaration(node) {
|
|
4491
|
-
if (node.typeAnnotation.type !==
|
|
4627
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES57.TSTypeLiteral) {
|
|
4492
4628
|
return;
|
|
4493
4629
|
}
|
|
4494
4630
|
const { members } = node.typeAnnotation;
|
|
@@ -4525,6 +4661,7 @@ var rules = {
|
|
|
4525
4661
|
"enforce-sorted-destructuring": enforce_sorted_destructuring_default,
|
|
4526
4662
|
"enforce-type-declaration-order": enforce_type_declaration_order_default,
|
|
4527
4663
|
"file-kebab-case": file_kebab_case_default,
|
|
4664
|
+
"index-export-only": index_export_only_default,
|
|
4528
4665
|
"jsx-newline-between-elements": jsx_newline_between_elements_default,
|
|
4529
4666
|
"jsx-no-inline-object-prop": jsx_no_inline_object_prop_default,
|
|
4530
4667
|
"jsx-no-newline-single-line-elements": jsx_no_newline_single_line_elements_default,
|
|
@@ -4546,6 +4683,7 @@ var rules = {
|
|
|
4546
4683
|
"no-inline-default-export": no_inline_default_export_default,
|
|
4547
4684
|
"no-inline-nested-object": no_inline_nested_object_default,
|
|
4548
4685
|
"no-inline-return-properties": no_inline_return_properties_default,
|
|
4686
|
+
"no-inline-type-import": no_inline_type_import_default,
|
|
4549
4687
|
"no-lazy-identifiers": no_lazy_identifiers_default,
|
|
4550
4688
|
"no-logic-in-params": no_logic_in_params_default,
|
|
4551
4689
|
"no-misleading-constant-case": no_misleading_constant_case_default,
|
|
@@ -4586,6 +4724,7 @@ var baseRules = {
|
|
|
4586
4724
|
"nextfriday/enforce-sorted-destructuring": "warn",
|
|
4587
4725
|
"nextfriday/enforce-type-declaration-order": "warn",
|
|
4588
4726
|
"nextfriday/file-kebab-case": "warn",
|
|
4727
|
+
"nextfriday/index-export-only": "warn",
|
|
4589
4728
|
"nextfriday/newline-after-multiline-block": "warn",
|
|
4590
4729
|
"nextfriday/newline-before-return": "warn",
|
|
4591
4730
|
"nextfriday/no-complex-inline-return": "warn",
|
|
@@ -4595,6 +4734,7 @@ var baseRules = {
|
|
|
4595
4734
|
"nextfriday/no-inline-default-export": "warn",
|
|
4596
4735
|
"nextfriday/no-inline-nested-object": "warn",
|
|
4597
4736
|
"nextfriday/no-inline-return-properties": "warn",
|
|
4737
|
+
"nextfriday/no-inline-type-import": "warn",
|
|
4598
4738
|
"nextfriday/no-lazy-identifiers": "warn",
|
|
4599
4739
|
"nextfriday/no-logic-in-params": "warn",
|
|
4600
4740
|
"nextfriday/no-misleading-constant-case": "warn",
|
|
@@ -4628,6 +4768,7 @@ var baseRecommendedRules = {
|
|
|
4628
4768
|
"nextfriday/enforce-sorted-destructuring": "error",
|
|
4629
4769
|
"nextfriday/enforce-type-declaration-order": "error",
|
|
4630
4770
|
"nextfriday/file-kebab-case": "error",
|
|
4771
|
+
"nextfriday/index-export-only": "error",
|
|
4631
4772
|
"nextfriday/newline-after-multiline-block": "error",
|
|
4632
4773
|
"nextfriday/newline-before-return": "error",
|
|
4633
4774
|
"nextfriday/no-complex-inline-return": "error",
|
|
@@ -4637,6 +4778,7 @@ var baseRecommendedRules = {
|
|
|
4637
4778
|
"nextfriday/no-inline-default-export": "error",
|
|
4638
4779
|
"nextfriday/no-inline-nested-object": "error",
|
|
4639
4780
|
"nextfriday/no-inline-return-properties": "error",
|
|
4781
|
+
"nextfriday/no-inline-type-import": "error",
|
|
4640
4782
|
"nextfriday/no-lazy-identifiers": "error",
|
|
4641
4783
|
"nextfriday/no-logic-in-params": "error",
|
|
4642
4784
|
"nextfriday/no-misleading-constant-case": "error",
|
|
@@ -4708,14 +4850,15 @@ var createConfig = (configRules) => ({
|
|
|
4708
4850
|
rules: configRules
|
|
4709
4851
|
});
|
|
4710
4852
|
var NEXTJS_ROUTING_GLOBS = [
|
|
4711
|
-
"app/**/*.{jsx,tsx}",
|
|
4712
|
-
"src/app/**/*.{jsx,tsx}",
|
|
4713
|
-
"pages/**/*.{jsx,tsx}",
|
|
4714
|
-
"src/pages/**/*.{jsx,tsx}"
|
|
4853
|
+
"app/**/*.{js,jsx,ts,tsx}",
|
|
4854
|
+
"src/app/**/*.{js,jsx,ts,tsx}",
|
|
4855
|
+
"pages/**/*.{js,jsx,ts,tsx}",
|
|
4856
|
+
"src/pages/**/*.{js,jsx,ts,tsx}"
|
|
4715
4857
|
];
|
|
4716
4858
|
var nextjsRoutingOverride = {
|
|
4717
4859
|
files: NEXTJS_ROUTING_GLOBS,
|
|
4718
4860
|
rules: {
|
|
4861
|
+
"nextfriday/file-kebab-case": "off",
|
|
4719
4862
|
"nextfriday/jsx-pascal-case": "off"
|
|
4720
4863
|
}
|
|
4721
4864
|
};
|