eslint-plugin-nextfriday 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +9 -15
- package/docs/rules/NO_GHOST_WRAPPER.md +75 -0
- package/docs/rules/NO_REDUNDANT_FRAGMENT.md +56 -0
- package/lib/index.cjs +429 -303
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +84 -0
- package/lib/index.d.ts +84 -0
- package/lib/index.js +429 -303
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -40,7 +40,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
40
40
|
// package.json
|
|
41
41
|
var package_default = {
|
|
42
42
|
name: "eslint-plugin-nextfriday",
|
|
43
|
-
version: "4.
|
|
43
|
+
version: "4.1.0",
|
|
44
44
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
45
45
|
keywords: [
|
|
46
46
|
"eslint",
|
|
@@ -2109,12 +2109,58 @@ var noEnvFallback = createRule27({
|
|
|
2109
2109
|
});
|
|
2110
2110
|
var no_env_fallback_default = noEnvFallback;
|
|
2111
2111
|
|
|
2112
|
-
// src/rules/no-
|
|
2112
|
+
// src/rules/no-ghost-wrapper.ts
|
|
2113
2113
|
var import_utils32 = require("@typescript-eslint/utils");
|
|
2114
2114
|
var createRule28 = import_utils32.ESLintUtils.RuleCreator(
|
|
2115
2115
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2116
2116
|
);
|
|
2117
|
-
var
|
|
2117
|
+
var GHOST_TAGS = /* @__PURE__ */ new Set(["div", "span"]);
|
|
2118
|
+
function isKeyAttribute(attribute) {
|
|
2119
|
+
return attribute.type === import_utils32.AST_NODE_TYPES.JSXAttribute && attribute.name.type === import_utils32.AST_NODE_TYPES.JSXIdentifier && attribute.name.name === "key";
|
|
2120
|
+
}
|
|
2121
|
+
var noGhostWrapper = createRule28({
|
|
2122
|
+
name: "no-ghost-wrapper",
|
|
2123
|
+
meta: {
|
|
2124
|
+
type: "problem",
|
|
2125
|
+
docs: {
|
|
2126
|
+
description: "Disallow bare <div> and <span> elements that have no meaningful attributes (Divitis / ghost wrappers)"
|
|
2127
|
+
},
|
|
2128
|
+
schema: [],
|
|
2129
|
+
messages: {
|
|
2130
|
+
noGhostWrapper: "Ghost <{{ tag }}> has no meaningful attributes. Use a Fragment (<>...</>), a semantic element (section, article, header, etc.), or add a meaningful attribute (className, role, data-*, ref, etc.). Note: 'key' alone does not count as meaningful."
|
|
2131
|
+
}
|
|
2132
|
+
},
|
|
2133
|
+
defaultOptions: [],
|
|
2134
|
+
create(context) {
|
|
2135
|
+
return {
|
|
2136
|
+
JSXOpeningElement(node) {
|
|
2137
|
+
if (node.name.type !== import_utils32.AST_NODE_TYPES.JSXIdentifier) {
|
|
2138
|
+
return;
|
|
2139
|
+
}
|
|
2140
|
+
const tagName = node.name.name;
|
|
2141
|
+
if (!GHOST_TAGS.has(tagName)) {
|
|
2142
|
+
return;
|
|
2143
|
+
}
|
|
2144
|
+
const meaningfulAttributes = node.attributes.filter((attribute) => !isKeyAttribute(attribute));
|
|
2145
|
+
if (meaningfulAttributes.length === 0) {
|
|
2146
|
+
context.report({
|
|
2147
|
+
node,
|
|
2148
|
+
messageId: "noGhostWrapper",
|
|
2149
|
+
data: { tag: tagName }
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
};
|
|
2154
|
+
}
|
|
2155
|
+
});
|
|
2156
|
+
var no_ghost_wrapper_default = noGhostWrapper;
|
|
2157
|
+
|
|
2158
|
+
// src/rules/no-inline-default-export.ts
|
|
2159
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
2160
|
+
var createRule29 = import_utils33.ESLintUtils.RuleCreator(
|
|
2161
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2162
|
+
);
|
|
2163
|
+
var noInlineDefaultExport = createRule29({
|
|
2118
2164
|
name: "no-inline-default-export",
|
|
2119
2165
|
meta: {
|
|
2120
2166
|
type: "suggestion",
|
|
@@ -2133,7 +2179,7 @@ var noInlineDefaultExport = createRule28({
|
|
|
2133
2179
|
return {
|
|
2134
2180
|
ExportDefaultDeclaration(node) {
|
|
2135
2181
|
const { declaration } = node;
|
|
2136
|
-
if (declaration.type ===
|
|
2182
|
+
if (declaration.type === import_utils33.AST_NODE_TYPES.FunctionDeclaration) {
|
|
2137
2183
|
if (declaration.id) {
|
|
2138
2184
|
context.report({
|
|
2139
2185
|
node,
|
|
@@ -2148,7 +2194,7 @@ var noInlineDefaultExport = createRule28({
|
|
|
2148
2194
|
});
|
|
2149
2195
|
}
|
|
2150
2196
|
}
|
|
2151
|
-
if (declaration.type ===
|
|
2197
|
+
if (declaration.type === import_utils33.AST_NODE_TYPES.ClassDeclaration) {
|
|
2152
2198
|
if (declaration.id) {
|
|
2153
2199
|
context.report({
|
|
2154
2200
|
node,
|
|
@@ -2163,7 +2209,7 @@ var noInlineDefaultExport = createRule28({
|
|
|
2163
2209
|
});
|
|
2164
2210
|
}
|
|
2165
2211
|
}
|
|
2166
|
-
if (declaration.type ===
|
|
2212
|
+
if (declaration.type === import_utils33.AST_NODE_TYPES.ArrowFunctionExpression || declaration.type === import_utils33.AST_NODE_TYPES.FunctionExpression) {
|
|
2167
2213
|
context.report({
|
|
2168
2214
|
node,
|
|
2169
2215
|
messageId: "noAnonymousDefaultExport",
|
|
@@ -2176,14 +2222,14 @@ var noInlineDefaultExport = createRule28({
|
|
|
2176
2222
|
if (!declaration) {
|
|
2177
2223
|
return;
|
|
2178
2224
|
}
|
|
2179
|
-
if (declaration.type ===
|
|
2225
|
+
if (declaration.type === import_utils33.AST_NODE_TYPES.FunctionDeclaration && declaration.id) {
|
|
2180
2226
|
context.report({
|
|
2181
2227
|
node,
|
|
2182
2228
|
messageId: "noInlineNamedExport",
|
|
2183
2229
|
data: { type: "function", name: declaration.id.name }
|
|
2184
2230
|
});
|
|
2185
2231
|
}
|
|
2186
|
-
if (declaration.type ===
|
|
2232
|
+
if (declaration.type === import_utils33.AST_NODE_TYPES.ClassDeclaration && declaration.id) {
|
|
2187
2233
|
context.report({
|
|
2188
2234
|
node,
|
|
2189
2235
|
messageId: "noInlineNamedExport",
|
|
@@ -2197,27 +2243,27 @@ var noInlineDefaultExport = createRule28({
|
|
|
2197
2243
|
var no_inline_default_export_default = noInlineDefaultExport;
|
|
2198
2244
|
|
|
2199
2245
|
// src/rules/no-inline-nested-object.ts
|
|
2200
|
-
var
|
|
2201
|
-
var
|
|
2246
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
2247
|
+
var createRule30 = import_utils34.ESLintUtils.RuleCreator(
|
|
2202
2248
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2203
2249
|
);
|
|
2204
2250
|
function isObjectOrArray(node) {
|
|
2205
|
-
return node.type ===
|
|
2251
|
+
return node.type === import_utils34.AST_NODE_TYPES.ObjectExpression || node.type === import_utils34.AST_NODE_TYPES.ArrayExpression || node.type === import_utils34.AST_NODE_TYPES.TSAsExpression;
|
|
2206
2252
|
}
|
|
2207
2253
|
function getInnerExpression(node) {
|
|
2208
|
-
if (node.type ===
|
|
2254
|
+
if (node.type === import_utils34.AST_NODE_TYPES.TSAsExpression) {
|
|
2209
2255
|
return getInnerExpression(node.expression);
|
|
2210
2256
|
}
|
|
2211
2257
|
return node;
|
|
2212
2258
|
}
|
|
2213
2259
|
function isNestedStructure(node) {
|
|
2214
2260
|
const inner = getInnerExpression(node);
|
|
2215
|
-
return inner.type ===
|
|
2261
|
+
return inner.type === import_utils34.AST_NODE_TYPES.ObjectExpression || inner.type === import_utils34.AST_NODE_TYPES.ArrayExpression;
|
|
2216
2262
|
}
|
|
2217
2263
|
function containsNestedStructure(node) {
|
|
2218
|
-
if (node.type ===
|
|
2264
|
+
if (node.type === import_utils34.AST_NODE_TYPES.ObjectExpression) {
|
|
2219
2265
|
return node.properties.some((prop) => {
|
|
2220
|
-
if (prop.type !==
|
|
2266
|
+
if (prop.type !== import_utils34.AST_NODE_TYPES.Property) return false;
|
|
2221
2267
|
return isNestedStructure(prop.value);
|
|
2222
2268
|
});
|
|
2223
2269
|
}
|
|
@@ -2226,7 +2272,7 @@ function containsNestedStructure(node) {
|
|
|
2226
2272
|
return isNestedStructure(el);
|
|
2227
2273
|
});
|
|
2228
2274
|
}
|
|
2229
|
-
var noInlineNestedObject =
|
|
2275
|
+
var noInlineNestedObject = createRule30({
|
|
2230
2276
|
name: "no-inline-nested-object",
|
|
2231
2277
|
meta: {
|
|
2232
2278
|
type: "layout",
|
|
@@ -2248,7 +2294,7 @@ var noInlineNestedObject = createRule29({
|
|
|
2248
2294
|
return;
|
|
2249
2295
|
}
|
|
2250
2296
|
const valueNode = getInnerExpression(node.value);
|
|
2251
|
-
if (valueNode.type !==
|
|
2297
|
+
if (valueNode.type !== import_utils34.AST_NODE_TYPES.ObjectExpression && valueNode.type !== import_utils34.AST_NODE_TYPES.ArrayExpression) {
|
|
2252
2298
|
return;
|
|
2253
2299
|
}
|
|
2254
2300
|
if (!valueNode.loc) {
|
|
@@ -2261,7 +2307,7 @@ var noInlineNestedObject = createRule29({
|
|
|
2261
2307
|
if (!containsNestedStructure(valueNode)) {
|
|
2262
2308
|
return;
|
|
2263
2309
|
}
|
|
2264
|
-
const elements = valueNode.type ===
|
|
2310
|
+
const elements = valueNode.type === import_utils34.AST_NODE_TYPES.ObjectExpression ? valueNode.properties : valueNode.elements;
|
|
2265
2311
|
context.report({
|
|
2266
2312
|
node: valueNode,
|
|
2267
2313
|
messageId: "requireMultiline",
|
|
@@ -2274,7 +2320,7 @@ var noInlineNestedObject = createRule29({
|
|
|
2274
2320
|
const indent = " ".repeat(node.loc?.start.column ?? 0);
|
|
2275
2321
|
const innerIndent = `${indent} `;
|
|
2276
2322
|
const elementTexts = elements.filter((el) => el !== null).map((el) => sourceCode.getText(el));
|
|
2277
|
-
const isObject = valueNode.type ===
|
|
2323
|
+
const isObject = valueNode.type === import_utils34.AST_NODE_TYPES.ObjectExpression;
|
|
2278
2324
|
const openChar = isObject ? "{" : "[";
|
|
2279
2325
|
const closeChar = isObject ? "}" : "]";
|
|
2280
2326
|
const formattedElements = elementTexts.map((text) => `${innerIndent}${text},`).join("\n");
|
|
@@ -2291,20 +2337,20 @@ ${indent}${closeChar}`;
|
|
|
2291
2337
|
var no_inline_nested_object_default = noInlineNestedObject;
|
|
2292
2338
|
|
|
2293
2339
|
// src/rules/no-inline-return-properties.ts
|
|
2294
|
-
var
|
|
2295
|
-
var
|
|
2340
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
2341
|
+
var createRule31 = import_utils35.ESLintUtils.RuleCreator(
|
|
2296
2342
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2297
2343
|
);
|
|
2298
2344
|
var isShorthandProperty = (property) => {
|
|
2299
|
-
if (property.type ===
|
|
2345
|
+
if (property.type === import_utils35.AST_NODE_TYPES.SpreadElement) {
|
|
2300
2346
|
return true;
|
|
2301
2347
|
}
|
|
2302
|
-
if (property.type !==
|
|
2348
|
+
if (property.type !== import_utils35.AST_NODE_TYPES.Property) {
|
|
2303
2349
|
return false;
|
|
2304
2350
|
}
|
|
2305
2351
|
return property.shorthand;
|
|
2306
2352
|
};
|
|
2307
|
-
var noInlineReturnProperties =
|
|
2353
|
+
var noInlineReturnProperties = createRule31({
|
|
2308
2354
|
name: "no-inline-return-properties",
|
|
2309
2355
|
meta: {
|
|
2310
2356
|
type: "suggestion",
|
|
@@ -2320,20 +2366,20 @@ var noInlineReturnProperties = createRule30({
|
|
|
2320
2366
|
create(context) {
|
|
2321
2367
|
return {
|
|
2322
2368
|
ReturnStatement(node) {
|
|
2323
|
-
if (!node.argument || node.argument.type !==
|
|
2369
|
+
if (!node.argument || node.argument.type !== import_utils35.AST_NODE_TYPES.ObjectExpression) {
|
|
2324
2370
|
return;
|
|
2325
2371
|
}
|
|
2326
2372
|
node.argument.properties.forEach((property) => {
|
|
2327
2373
|
if (isShorthandProperty(property)) {
|
|
2328
2374
|
return;
|
|
2329
2375
|
}
|
|
2330
|
-
if (property.type !==
|
|
2376
|
+
if (property.type !== import_utils35.AST_NODE_TYPES.Property) {
|
|
2331
2377
|
return;
|
|
2332
2378
|
}
|
|
2333
2379
|
let keyName = null;
|
|
2334
|
-
if (property.key.type ===
|
|
2380
|
+
if (property.key.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
2335
2381
|
keyName = property.key.name;
|
|
2336
|
-
} else if (property.key.type ===
|
|
2382
|
+
} else if (property.key.type === import_utils35.AST_NODE_TYPES.Literal) {
|
|
2337
2383
|
keyName = String(property.key.value);
|
|
2338
2384
|
}
|
|
2339
2385
|
context.report({
|
|
@@ -2349,12 +2395,12 @@ var noInlineReturnProperties = createRule30({
|
|
|
2349
2395
|
var no_inline_return_properties_default = noInlineReturnProperties;
|
|
2350
2396
|
|
|
2351
2397
|
// src/rules/no-inline-type-import.ts
|
|
2352
|
-
var
|
|
2353
|
-
var
|
|
2398
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
2399
|
+
var createRule32 = import_utils36.ESLintUtils.RuleCreator(
|
|
2354
2400
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2355
2401
|
);
|
|
2356
|
-
var isInlineTypeSpecifier = (specifier) => specifier.type ===
|
|
2357
|
-
var noInlineTypeImport =
|
|
2402
|
+
var isInlineTypeSpecifier = (specifier) => specifier.type === import_utils36.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type";
|
|
2403
|
+
var noInlineTypeImport = createRule32({
|
|
2358
2404
|
name: "no-inline-type-import",
|
|
2359
2405
|
meta: {
|
|
2360
2406
|
type: "suggestion",
|
|
@@ -2391,7 +2437,7 @@ var noInlineTypeImport = createRule31({
|
|
|
2391
2437
|
);
|
|
2392
2438
|
const typeImport = `import type { ${typeSpecifierTexts.join(", ")} } from ${sourceText};`;
|
|
2393
2439
|
const valueSpecifiers = node.specifiers.filter(
|
|
2394
|
-
(specifier) => !(specifier.type ===
|
|
2440
|
+
(specifier) => !(specifier.type === import_utils36.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type")
|
|
2395
2441
|
);
|
|
2396
2442
|
if (valueSpecifiers.length === 0) {
|
|
2397
2443
|
return fixer.replaceText(node, typeImport);
|
|
@@ -2399,11 +2445,11 @@ var noInlineTypeImport = createRule31({
|
|
|
2399
2445
|
const parts = [];
|
|
2400
2446
|
const namedValueSpecifiers = [];
|
|
2401
2447
|
for (const specifier of valueSpecifiers) {
|
|
2402
|
-
if (specifier.type ===
|
|
2448
|
+
if (specifier.type === import_utils36.AST_NODE_TYPES.ImportDefaultSpecifier) {
|
|
2403
2449
|
parts.push(specifier.local.name);
|
|
2404
|
-
} else if (specifier.type ===
|
|
2450
|
+
} else if (specifier.type === import_utils36.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
2405
2451
|
parts.push(`* as ${specifier.local.name}`);
|
|
2406
|
-
} else if (specifier.type ===
|
|
2452
|
+
} else if (specifier.type === import_utils36.AST_NODE_TYPES.ImportSpecifier) {
|
|
2407
2453
|
namedValueSpecifiers.push(specifier);
|
|
2408
2454
|
}
|
|
2409
2455
|
}
|
|
@@ -2423,8 +2469,8 @@ ${typeImport}`);
|
|
|
2423
2469
|
var no_inline_type_import_default = noInlineTypeImport;
|
|
2424
2470
|
|
|
2425
2471
|
// src/rules/no-lazy-identifiers.ts
|
|
2426
|
-
var
|
|
2427
|
-
var
|
|
2472
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
2473
|
+
var createRule33 = import_utils37.ESLintUtils.RuleCreator(
|
|
2428
2474
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2429
2475
|
);
|
|
2430
2476
|
var KEYBOARD_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm", "1234567890"];
|
|
@@ -2465,7 +2511,7 @@ var isLazyIdentifier = (name) => {
|
|
|
2465
2511
|
}
|
|
2466
2512
|
return false;
|
|
2467
2513
|
};
|
|
2468
|
-
var noLazyIdentifiers =
|
|
2514
|
+
var noLazyIdentifiers = createRule33({
|
|
2469
2515
|
name: "no-lazy-identifiers",
|
|
2470
2516
|
meta: {
|
|
2471
2517
|
type: "problem",
|
|
@@ -2491,27 +2537,27 @@ var noLazyIdentifiers = createRule32({
|
|
|
2491
2537
|
});
|
|
2492
2538
|
};
|
|
2493
2539
|
const checkPattern = (pattern) => {
|
|
2494
|
-
if (pattern.type ===
|
|
2540
|
+
if (pattern.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
2495
2541
|
checkIdentifier(pattern);
|
|
2496
|
-
} else if (pattern.type ===
|
|
2542
|
+
} else if (pattern.type === import_utils37.AST_NODE_TYPES.ObjectPattern) {
|
|
2497
2543
|
pattern.properties.forEach((prop) => {
|
|
2498
|
-
if (prop.type ===
|
|
2544
|
+
if (prop.type === import_utils37.AST_NODE_TYPES.Property && prop.value.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
2499
2545
|
checkIdentifier(prop.value);
|
|
2500
|
-
} else if (prop.type ===
|
|
2546
|
+
} else if (prop.type === import_utils37.AST_NODE_TYPES.RestElement && prop.argument.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
2501
2547
|
checkIdentifier(prop.argument);
|
|
2502
2548
|
}
|
|
2503
2549
|
});
|
|
2504
|
-
} else if (pattern.type ===
|
|
2550
|
+
} else if (pattern.type === import_utils37.AST_NODE_TYPES.ArrayPattern) {
|
|
2505
2551
|
pattern.elements.forEach((element) => {
|
|
2506
|
-
if (element?.type ===
|
|
2552
|
+
if (element?.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
2507
2553
|
checkIdentifier(element);
|
|
2508
|
-
} else if (element?.type ===
|
|
2554
|
+
} else if (element?.type === import_utils37.AST_NODE_TYPES.RestElement && element.argument.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
2509
2555
|
checkIdentifier(element.argument);
|
|
2510
2556
|
}
|
|
2511
2557
|
});
|
|
2512
|
-
} else if (pattern.type ===
|
|
2558
|
+
} else if (pattern.type === import_utils37.AST_NODE_TYPES.AssignmentPattern && pattern.left.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
2513
2559
|
checkIdentifier(pattern.left);
|
|
2514
|
-
} else if (pattern.type ===
|
|
2560
|
+
} else if (pattern.type === import_utils37.AST_NODE_TYPES.RestElement && pattern.argument.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
2515
2561
|
checkIdentifier(pattern.argument);
|
|
2516
2562
|
}
|
|
2517
2563
|
};
|
|
@@ -2556,11 +2602,11 @@ var noLazyIdentifiers = createRule32({
|
|
|
2556
2602
|
var no_lazy_identifiers_default = noLazyIdentifiers;
|
|
2557
2603
|
|
|
2558
2604
|
// src/rules/no-logic-in-params.ts
|
|
2559
|
-
var
|
|
2560
|
-
var
|
|
2605
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
2606
|
+
var createRule34 = import_utils38.ESLintUtils.RuleCreator(
|
|
2561
2607
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2562
2608
|
);
|
|
2563
|
-
var noLogicInParams =
|
|
2609
|
+
var noLogicInParams = createRule34({
|
|
2564
2610
|
name: "no-logic-in-params",
|
|
2565
2611
|
meta: {
|
|
2566
2612
|
type: "suggestion",
|
|
@@ -2575,20 +2621,20 @@ var noLogicInParams = createRule33({
|
|
|
2575
2621
|
defaultOptions: [],
|
|
2576
2622
|
create(context) {
|
|
2577
2623
|
const isComplexExpression = (node) => {
|
|
2578
|
-
if (node.type ===
|
|
2624
|
+
if (node.type === import_utils38.AST_NODE_TYPES.SpreadElement) {
|
|
2579
2625
|
return false;
|
|
2580
2626
|
}
|
|
2581
|
-
if (node.type ===
|
|
2627
|
+
if (node.type === import_utils38.AST_NODE_TYPES.ConditionalExpression) {
|
|
2582
2628
|
return true;
|
|
2583
2629
|
}
|
|
2584
|
-
if (node.type ===
|
|
2630
|
+
if (node.type === import_utils38.AST_NODE_TYPES.LogicalExpression) {
|
|
2585
2631
|
return true;
|
|
2586
2632
|
}
|
|
2587
|
-
if (node.type ===
|
|
2633
|
+
if (node.type === import_utils38.AST_NODE_TYPES.BinaryExpression) {
|
|
2588
2634
|
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
2589
2635
|
return logicalOperators.includes(node.operator);
|
|
2590
2636
|
}
|
|
2591
|
-
if (node.type ===
|
|
2637
|
+
if (node.type === import_utils38.AST_NODE_TYPES.UnaryExpression) {
|
|
2592
2638
|
return node.operator === "!";
|
|
2593
2639
|
}
|
|
2594
2640
|
return false;
|
|
@@ -2601,7 +2647,7 @@ var noLogicInParams = createRule33({
|
|
|
2601
2647
|
messageId: "noLogicInParams"
|
|
2602
2648
|
});
|
|
2603
2649
|
}
|
|
2604
|
-
if (arg.type ===
|
|
2650
|
+
if (arg.type === import_utils38.AST_NODE_TYPES.ArrayExpression) {
|
|
2605
2651
|
arg.elements.forEach((element) => {
|
|
2606
2652
|
if (element && isComplexExpression(element)) {
|
|
2607
2653
|
context.report({
|
|
@@ -2626,46 +2672,46 @@ var noLogicInParams = createRule33({
|
|
|
2626
2672
|
var no_logic_in_params_default = noLogicInParams;
|
|
2627
2673
|
|
|
2628
2674
|
// src/rules/no-misleading-constant-case.ts
|
|
2629
|
-
var
|
|
2630
|
-
var
|
|
2675
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
2676
|
+
var createRule35 = import_utils39.ESLintUtils.RuleCreator(
|
|
2631
2677
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2632
2678
|
);
|
|
2633
2679
|
var SCREAMING_SNAKE_CASE_REGEX3 = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
2634
|
-
var isAsConstAssertion = (node) => node.type ===
|
|
2680
|
+
var isAsConstAssertion = (node) => node.type === import_utils39.AST_NODE_TYPES.TSAsExpression && node.typeAnnotation.type === import_utils39.AST_NODE_TYPES.TSTypeReference && node.typeAnnotation.typeName.type === import_utils39.AST_NODE_TYPES.Identifier && node.typeAnnotation.typeName.name === "const";
|
|
2635
2681
|
var isStaticValue2 = (init) => {
|
|
2636
2682
|
if (isAsConstAssertion(init)) {
|
|
2637
2683
|
return true;
|
|
2638
2684
|
}
|
|
2639
|
-
if (init.type ===
|
|
2685
|
+
if (init.type === import_utils39.AST_NODE_TYPES.Literal) {
|
|
2640
2686
|
return true;
|
|
2641
2687
|
}
|
|
2642
|
-
if (init.type ===
|
|
2688
|
+
if (init.type === import_utils39.AST_NODE_TYPES.UnaryExpression && init.argument.type === import_utils39.AST_NODE_TYPES.Literal) {
|
|
2643
2689
|
return true;
|
|
2644
2690
|
}
|
|
2645
|
-
if (init.type ===
|
|
2691
|
+
if (init.type === import_utils39.AST_NODE_TYPES.TemplateLiteral && init.expressions.length === 0) {
|
|
2646
2692
|
return true;
|
|
2647
2693
|
}
|
|
2648
|
-
if (init.type ===
|
|
2649
|
-
return init.elements.every((el) => el !== null && el.type !==
|
|
2694
|
+
if (init.type === import_utils39.AST_NODE_TYPES.ArrayExpression) {
|
|
2695
|
+
return init.elements.every((el) => el !== null && el.type !== import_utils39.AST_NODE_TYPES.SpreadElement && isStaticValue2(el));
|
|
2650
2696
|
}
|
|
2651
|
-
if (init.type ===
|
|
2697
|
+
if (init.type === import_utils39.AST_NODE_TYPES.ObjectExpression) {
|
|
2652
2698
|
return init.properties.every(
|
|
2653
|
-
(prop) => prop.type ===
|
|
2699
|
+
(prop) => prop.type === import_utils39.AST_NODE_TYPES.Property && isStaticValue2(prop.value)
|
|
2654
2700
|
);
|
|
2655
2701
|
}
|
|
2656
2702
|
return false;
|
|
2657
2703
|
};
|
|
2658
2704
|
var isGlobalScope3 = (node) => {
|
|
2659
2705
|
const { parent } = node;
|
|
2660
|
-
if (parent.type ===
|
|
2706
|
+
if (parent.type === import_utils39.AST_NODE_TYPES.Program) {
|
|
2661
2707
|
return true;
|
|
2662
2708
|
}
|
|
2663
|
-
if (parent.type ===
|
|
2709
|
+
if (parent.type === import_utils39.AST_NODE_TYPES.ExportNamedDeclaration && parent.parent?.type === import_utils39.AST_NODE_TYPES.Program) {
|
|
2664
2710
|
return true;
|
|
2665
2711
|
}
|
|
2666
2712
|
return false;
|
|
2667
2713
|
};
|
|
2668
|
-
var noMisleadingConstantCase =
|
|
2714
|
+
var noMisleadingConstantCase = createRule35({
|
|
2669
2715
|
name: "no-misleading-constant-case",
|
|
2670
2716
|
meta: {
|
|
2671
2717
|
type: "suggestion",
|
|
@@ -2684,7 +2730,7 @@ var noMisleadingConstantCase = createRule34({
|
|
|
2684
2730
|
return {
|
|
2685
2731
|
VariableDeclaration(node) {
|
|
2686
2732
|
node.declarations.forEach((declarator) => {
|
|
2687
|
-
if (declarator.id.type !==
|
|
2733
|
+
if (declarator.id.type !== import_utils39.AST_NODE_TYPES.Identifier) {
|
|
2688
2734
|
return;
|
|
2689
2735
|
}
|
|
2690
2736
|
const { name } = declarator.id;
|
|
@@ -2725,11 +2771,11 @@ var noMisleadingConstantCase = createRule34({
|
|
|
2725
2771
|
var no_misleading_constant_case_default = noMisleadingConstantCase;
|
|
2726
2772
|
|
|
2727
2773
|
// src/rules/no-nested-interface-declaration.ts
|
|
2728
|
-
var
|
|
2729
|
-
var
|
|
2774
|
+
var import_utils40 = require("@typescript-eslint/utils");
|
|
2775
|
+
var createRule36 = import_utils40.ESLintUtils.RuleCreator(
|
|
2730
2776
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2731
2777
|
);
|
|
2732
|
-
var noNestedInterfaceDeclaration =
|
|
2778
|
+
var noNestedInterfaceDeclaration = createRule36({
|
|
2733
2779
|
name: "no-nested-interface-declaration",
|
|
2734
2780
|
meta: {
|
|
2735
2781
|
type: "suggestion",
|
|
@@ -2750,15 +2796,15 @@ var noNestedInterfaceDeclaration = createRule35({
|
|
|
2750
2796
|
return;
|
|
2751
2797
|
}
|
|
2752
2798
|
const { typeAnnotation } = node.typeAnnotation;
|
|
2753
|
-
if (typeAnnotation.type ===
|
|
2799
|
+
if (typeAnnotation.type === import_utils40.AST_NODE_TYPES.TSTypeLiteral) {
|
|
2754
2800
|
context.report({
|
|
2755
2801
|
node: typeAnnotation,
|
|
2756
2802
|
messageId: "noNestedInterface"
|
|
2757
2803
|
});
|
|
2758
2804
|
return;
|
|
2759
2805
|
}
|
|
2760
|
-
if (typeAnnotation.type ===
|
|
2761
|
-
if (typeAnnotation.elementType.type ===
|
|
2806
|
+
if (typeAnnotation.type === import_utils40.AST_NODE_TYPES.TSArrayType) {
|
|
2807
|
+
if (typeAnnotation.elementType.type === import_utils40.AST_NODE_TYPES.TSTypeLiteral) {
|
|
2762
2808
|
context.report({
|
|
2763
2809
|
node: typeAnnotation.elementType,
|
|
2764
2810
|
messageId: "noNestedInterface"
|
|
@@ -2766,9 +2812,9 @@ var noNestedInterfaceDeclaration = createRule35({
|
|
|
2766
2812
|
}
|
|
2767
2813
|
return;
|
|
2768
2814
|
}
|
|
2769
|
-
if (typeAnnotation.type ===
|
|
2815
|
+
if (typeAnnotation.type === import_utils40.AST_NODE_TYPES.TSTypeReference && typeAnnotation.typeArguments) {
|
|
2770
2816
|
typeAnnotation.typeArguments.params.forEach((param) => {
|
|
2771
|
-
if (param.type ===
|
|
2817
|
+
if (param.type === import_utils40.AST_NODE_TYPES.TSTypeLiteral) {
|
|
2772
2818
|
context.report({
|
|
2773
2819
|
node: param,
|
|
2774
2820
|
messageId: "noNestedInterface"
|
|
@@ -2783,11 +2829,11 @@ var noNestedInterfaceDeclaration = createRule35({
|
|
|
2783
2829
|
var no_nested_interface_declaration_default = noNestedInterfaceDeclaration;
|
|
2784
2830
|
|
|
2785
2831
|
// src/rules/no-nested-ternary.ts
|
|
2786
|
-
var
|
|
2787
|
-
var
|
|
2832
|
+
var import_utils41 = require("@typescript-eslint/utils");
|
|
2833
|
+
var createRule37 = import_utils41.ESLintUtils.RuleCreator(
|
|
2788
2834
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2789
2835
|
);
|
|
2790
|
-
var noNestedTernary =
|
|
2836
|
+
var noNestedTernary = createRule37({
|
|
2791
2837
|
name: "no-nested-ternary",
|
|
2792
2838
|
meta: {
|
|
2793
2839
|
type: "suggestion",
|
|
@@ -2804,13 +2850,13 @@ var noNestedTernary = createRule36({
|
|
|
2804
2850
|
return {
|
|
2805
2851
|
ConditionalExpression(node) {
|
|
2806
2852
|
const { consequent, alternate } = node;
|
|
2807
|
-
if (consequent.type ===
|
|
2853
|
+
if (consequent.type === import_utils41.AST_NODE_TYPES.ConditionalExpression) {
|
|
2808
2854
|
context.report({
|
|
2809
2855
|
node: consequent,
|
|
2810
2856
|
messageId: "noNestedTernary"
|
|
2811
2857
|
});
|
|
2812
2858
|
}
|
|
2813
|
-
if (alternate.type ===
|
|
2859
|
+
if (alternate.type === import_utils41.AST_NODE_TYPES.ConditionalExpression) {
|
|
2814
2860
|
context.report({
|
|
2815
2861
|
node: alternate,
|
|
2816
2862
|
messageId: "noNestedTernary"
|
|
@@ -2822,12 +2868,86 @@ var noNestedTernary = createRule36({
|
|
|
2822
2868
|
});
|
|
2823
2869
|
var no_nested_ternary_default = noNestedTernary;
|
|
2824
2870
|
|
|
2871
|
+
// src/rules/no-redundant-fragment.ts
|
|
2872
|
+
var import_utils42 = require("@typescript-eslint/utils");
|
|
2873
|
+
var createRule38 = import_utils42.ESLintUtils.RuleCreator(
|
|
2874
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2875
|
+
);
|
|
2876
|
+
function isFragmentName(name) {
|
|
2877
|
+
if (name.type === import_utils42.AST_NODE_TYPES.JSXIdentifier && name.name === "Fragment") {
|
|
2878
|
+
return true;
|
|
2879
|
+
}
|
|
2880
|
+
if (name.type === import_utils42.AST_NODE_TYPES.JSXMemberExpression && name.object.type === import_utils42.AST_NODE_TYPES.JSXIdentifier && name.object.name === "React" && name.property.type === import_utils42.AST_NODE_TYPES.JSXIdentifier && name.property.name === "Fragment") {
|
|
2881
|
+
return true;
|
|
2882
|
+
}
|
|
2883
|
+
return false;
|
|
2884
|
+
}
|
|
2885
|
+
function hasKeyAttribute(attributes) {
|
|
2886
|
+
return attributes.some(
|
|
2887
|
+
(attribute) => attribute.type === import_utils42.AST_NODE_TYPES.JSXAttribute && attribute.name.type === import_utils42.AST_NODE_TYPES.JSXIdentifier && attribute.name.name === "key"
|
|
2888
|
+
);
|
|
2889
|
+
}
|
|
2890
|
+
function countMeaningfulChildren(children) {
|
|
2891
|
+
return children.filter((child) => {
|
|
2892
|
+
if (child.type === import_utils42.AST_NODE_TYPES.JSXText) {
|
|
2893
|
+
return child.value.trim() !== "";
|
|
2894
|
+
}
|
|
2895
|
+
return true;
|
|
2896
|
+
}).length;
|
|
2897
|
+
}
|
|
2898
|
+
var noRedundantFragment = createRule38({
|
|
2899
|
+
name: "no-redundant-fragment",
|
|
2900
|
+
meta: {
|
|
2901
|
+
type: "problem",
|
|
2902
|
+
docs: {
|
|
2903
|
+
description: "Disallow Fragments that wrap zero or one child (unless a key prop is needed)"
|
|
2904
|
+
},
|
|
2905
|
+
schema: [],
|
|
2906
|
+
messages: {
|
|
2907
|
+
redundantFragment: "Fragment is redundant when wrapping {{ count }} child. Remove the Fragment or replace it with the child directly."
|
|
2908
|
+
}
|
|
2909
|
+
},
|
|
2910
|
+
defaultOptions: [],
|
|
2911
|
+
create(context) {
|
|
2912
|
+
return {
|
|
2913
|
+
JSXFragment(node) {
|
|
2914
|
+
const count = countMeaningfulChildren(node.children);
|
|
2915
|
+
if (count <= 1) {
|
|
2916
|
+
context.report({
|
|
2917
|
+
node,
|
|
2918
|
+
messageId: "redundantFragment",
|
|
2919
|
+
data: { count: String(count) }
|
|
2920
|
+
});
|
|
2921
|
+
}
|
|
2922
|
+
},
|
|
2923
|
+
JSXElement(node) {
|
|
2924
|
+
const opening = node.openingElement;
|
|
2925
|
+
if (!isFragmentName(opening.name)) {
|
|
2926
|
+
return;
|
|
2927
|
+
}
|
|
2928
|
+
if (hasKeyAttribute(opening.attributes)) {
|
|
2929
|
+
return;
|
|
2930
|
+
}
|
|
2931
|
+
const count = countMeaningfulChildren(node.children);
|
|
2932
|
+
if (count <= 1) {
|
|
2933
|
+
context.report({
|
|
2934
|
+
node,
|
|
2935
|
+
messageId: "redundantFragment",
|
|
2936
|
+
data: { count: String(count) }
|
|
2937
|
+
});
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
};
|
|
2941
|
+
}
|
|
2942
|
+
});
|
|
2943
|
+
var no_redundant_fragment_default = noRedundantFragment;
|
|
2944
|
+
|
|
2825
2945
|
// src/rules/no-relative-imports.ts
|
|
2826
|
-
var
|
|
2827
|
-
var
|
|
2946
|
+
var import_utils43 = require("@typescript-eslint/utils");
|
|
2947
|
+
var createRule39 = import_utils43.ESLintUtils.RuleCreator(
|
|
2828
2948
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2829
2949
|
);
|
|
2830
|
-
var noRelativeImports =
|
|
2950
|
+
var noRelativeImports = createRule39({
|
|
2831
2951
|
name: "no-relative-imports",
|
|
2832
2952
|
meta: {
|
|
2833
2953
|
type: "suggestion",
|
|
@@ -2851,22 +2971,22 @@ var noRelativeImports = createRule37({
|
|
|
2851
2971
|
};
|
|
2852
2972
|
return {
|
|
2853
2973
|
ImportDeclaration(node) {
|
|
2854
|
-
if (node.source.type ===
|
|
2974
|
+
if (node.source.type === import_utils43.AST_NODE_TYPES.Literal && typeof node.source.value === "string") {
|
|
2855
2975
|
checkImportPath(node.source.value, node);
|
|
2856
2976
|
}
|
|
2857
2977
|
},
|
|
2858
2978
|
ImportExpression(node) {
|
|
2859
|
-
if (node.source.type ===
|
|
2979
|
+
if (node.source.type === import_utils43.AST_NODE_TYPES.Literal && typeof node.source.value === "string") {
|
|
2860
2980
|
checkImportPath(node.source.value, node);
|
|
2861
2981
|
}
|
|
2862
2982
|
},
|
|
2863
2983
|
ExportNamedDeclaration(node) {
|
|
2864
|
-
if (node.source?.type ===
|
|
2984
|
+
if (node.source?.type === import_utils43.AST_NODE_TYPES.Literal && typeof node.source.value === "string") {
|
|
2865
2985
|
checkImportPath(node.source.value, node);
|
|
2866
2986
|
}
|
|
2867
2987
|
},
|
|
2868
2988
|
ExportAllDeclaration(node) {
|
|
2869
|
-
if (node.source.type ===
|
|
2989
|
+
if (node.source.type === import_utils43.AST_NODE_TYPES.Literal && typeof node.source.value === "string") {
|
|
2870
2990
|
checkImportPath(node.source.value, node);
|
|
2871
2991
|
}
|
|
2872
2992
|
}
|
|
@@ -2876,8 +2996,8 @@ var noRelativeImports = createRule37({
|
|
|
2876
2996
|
var no_relative_imports_default = noRelativeImports;
|
|
2877
2997
|
|
|
2878
2998
|
// src/rules/no-single-char-variables.ts
|
|
2879
|
-
var
|
|
2880
|
-
var
|
|
2999
|
+
var import_utils44 = require("@typescript-eslint/utils");
|
|
3000
|
+
var createRule40 = import_utils44.ESLintUtils.RuleCreator(
|
|
2881
3001
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2882
3002
|
);
|
|
2883
3003
|
var ALLOWED_IN_FOR_LOOPS = /* @__PURE__ */ new Set(["i", "j", "k", "n"]);
|
|
@@ -2889,7 +3009,7 @@ var isForLoopInit = (node) => {
|
|
|
2889
3009
|
if (!parentNode) {
|
|
2890
3010
|
return false;
|
|
2891
3011
|
}
|
|
2892
|
-
if (parentNode.type ===
|
|
3012
|
+
if (parentNode.type === import_utils44.AST_NODE_TYPES.ForStatement) {
|
|
2893
3013
|
const { init } = parentNode;
|
|
2894
3014
|
if (init && init === current) {
|
|
2895
3015
|
return true;
|
|
@@ -2908,7 +3028,7 @@ var isAllowedInContext = (name, node) => {
|
|
|
2908
3028
|
}
|
|
2909
3029
|
return false;
|
|
2910
3030
|
};
|
|
2911
|
-
var noSingleCharVariables =
|
|
3031
|
+
var noSingleCharVariables = createRule40({
|
|
2912
3032
|
name: "no-single-char-variables",
|
|
2913
3033
|
meta: {
|
|
2914
3034
|
type: "suggestion",
|
|
@@ -2937,27 +3057,27 @@ var noSingleCharVariables = createRule38({
|
|
|
2937
3057
|
});
|
|
2938
3058
|
};
|
|
2939
3059
|
const checkPattern = (pattern, declarationNode) => {
|
|
2940
|
-
if (pattern.type ===
|
|
3060
|
+
if (pattern.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
2941
3061
|
checkIdentifier(pattern, declarationNode);
|
|
2942
|
-
} else if (pattern.type ===
|
|
3062
|
+
} else if (pattern.type === import_utils44.AST_NODE_TYPES.ObjectPattern) {
|
|
2943
3063
|
pattern.properties.forEach((prop) => {
|
|
2944
|
-
if (prop.type ===
|
|
3064
|
+
if (prop.type === import_utils44.AST_NODE_TYPES.Property && prop.value.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
2945
3065
|
checkIdentifier(prop.value, declarationNode);
|
|
2946
|
-
} else if (prop.type ===
|
|
3066
|
+
} else if (prop.type === import_utils44.AST_NODE_TYPES.RestElement && prop.argument.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
2947
3067
|
checkIdentifier(prop.argument, declarationNode);
|
|
2948
3068
|
}
|
|
2949
3069
|
});
|
|
2950
|
-
} else if (pattern.type ===
|
|
3070
|
+
} else if (pattern.type === import_utils44.AST_NODE_TYPES.ArrayPattern) {
|
|
2951
3071
|
pattern.elements.forEach((element) => {
|
|
2952
|
-
if (element?.type ===
|
|
3072
|
+
if (element?.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
2953
3073
|
checkIdentifier(element, declarationNode);
|
|
2954
|
-
} else if (element?.type ===
|
|
3074
|
+
} else if (element?.type === import_utils44.AST_NODE_TYPES.RestElement && element.argument.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
2955
3075
|
checkIdentifier(element.argument, declarationNode);
|
|
2956
3076
|
}
|
|
2957
3077
|
});
|
|
2958
|
-
} else if (pattern.type ===
|
|
3078
|
+
} else if (pattern.type === import_utils44.AST_NODE_TYPES.AssignmentPattern && pattern.left.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
2959
3079
|
checkIdentifier(pattern.left, declarationNode);
|
|
2960
|
-
} else if (pattern.type ===
|
|
3080
|
+
} else if (pattern.type === import_utils44.AST_NODE_TYPES.RestElement && pattern.argument.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
2961
3081
|
checkIdentifier(pattern.argument, declarationNode);
|
|
2962
3082
|
}
|
|
2963
3083
|
};
|
|
@@ -2991,11 +3111,11 @@ var noSingleCharVariables = createRule38({
|
|
|
2991
3111
|
var no_single_char_variables_default = noSingleCharVariables;
|
|
2992
3112
|
|
|
2993
3113
|
// src/rules/prefer-async-await.ts
|
|
2994
|
-
var
|
|
2995
|
-
var
|
|
3114
|
+
var import_utils45 = require("@typescript-eslint/utils");
|
|
3115
|
+
var createRule41 = import_utils45.ESLintUtils.RuleCreator(
|
|
2996
3116
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2997
3117
|
);
|
|
2998
|
-
var preferAsyncAwait =
|
|
3118
|
+
var preferAsyncAwait = createRule41({
|
|
2999
3119
|
name: "prefer-async-await",
|
|
3000
3120
|
meta: {
|
|
3001
3121
|
type: "suggestion",
|
|
@@ -3011,7 +3131,7 @@ var preferAsyncAwait = createRule39({
|
|
|
3011
3131
|
create(context) {
|
|
3012
3132
|
return {
|
|
3013
3133
|
CallExpression(node) {
|
|
3014
|
-
if (node.callee.type ===
|
|
3134
|
+
if (node.callee.type === import_utils45.AST_NODE_TYPES.MemberExpression && node.callee.property.type === import_utils45.AST_NODE_TYPES.Identifier && node.callee.property.name === "then") {
|
|
3015
3135
|
context.report({
|
|
3016
3136
|
node: node.callee.property,
|
|
3017
3137
|
messageId: "preferAsyncAwait"
|
|
@@ -3024,11 +3144,11 @@ var preferAsyncAwait = createRule39({
|
|
|
3024
3144
|
var prefer_async_await_default = preferAsyncAwait;
|
|
3025
3145
|
|
|
3026
3146
|
// src/rules/prefer-destructuring-params.ts
|
|
3027
|
-
var
|
|
3028
|
-
var
|
|
3147
|
+
var import_utils46 = require("@typescript-eslint/utils");
|
|
3148
|
+
var createRule42 = import_utils46.ESLintUtils.RuleCreator(
|
|
3029
3149
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3030
3150
|
);
|
|
3031
|
-
var preferDestructuringParams =
|
|
3151
|
+
var preferDestructuringParams = createRule42({
|
|
3032
3152
|
name: "prefer-destructuring-params",
|
|
3033
3153
|
meta: {
|
|
3034
3154
|
type: "suggestion",
|
|
@@ -3044,18 +3164,18 @@ var preferDestructuringParams = createRule40({
|
|
|
3044
3164
|
create(context) {
|
|
3045
3165
|
const isCallbackFunction2 = (node) => {
|
|
3046
3166
|
const { parent } = node;
|
|
3047
|
-
return parent?.type ===
|
|
3167
|
+
return parent?.type === import_utils46.AST_NODE_TYPES.CallExpression;
|
|
3048
3168
|
};
|
|
3049
3169
|
const isDeveloperFunction = (node) => {
|
|
3050
|
-
if (node.type ===
|
|
3170
|
+
if (node.type === import_utils46.AST_NODE_TYPES.FunctionDeclaration) {
|
|
3051
3171
|
return true;
|
|
3052
3172
|
}
|
|
3053
|
-
if (node.type ===
|
|
3173
|
+
if (node.type === import_utils46.AST_NODE_TYPES.FunctionExpression || node.type === import_utils46.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
3054
3174
|
if (isCallbackFunction2(node)) {
|
|
3055
3175
|
return false;
|
|
3056
3176
|
}
|
|
3057
3177
|
const { parent } = node;
|
|
3058
|
-
return parent?.type ===
|
|
3178
|
+
return parent?.type === import_utils46.AST_NODE_TYPES.VariableDeclarator || parent?.type === import_utils46.AST_NODE_TYPES.AssignmentExpression || parent?.type === import_utils46.AST_NODE_TYPES.Property || parent?.type === import_utils46.AST_NODE_TYPES.MethodDefinition;
|
|
3059
3179
|
}
|
|
3060
3180
|
return false;
|
|
3061
3181
|
};
|
|
@@ -3067,7 +3187,7 @@ var preferDestructuringParams = createRule40({
|
|
|
3067
3187
|
if (!isDeveloperFunction(node)) {
|
|
3068
3188
|
return;
|
|
3069
3189
|
}
|
|
3070
|
-
if (node.type ===
|
|
3190
|
+
if (node.type === import_utils46.AST_NODE_TYPES.FunctionDeclaration && node.id) {
|
|
3071
3191
|
const functionName = node.id.name;
|
|
3072
3192
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
3073
3193
|
return;
|
|
@@ -3077,7 +3197,7 @@ var preferDestructuringParams = createRule40({
|
|
|
3077
3197
|
return;
|
|
3078
3198
|
}
|
|
3079
3199
|
const hasNonDestructuredParams = node.params.some(
|
|
3080
|
-
(param) => param.type !==
|
|
3200
|
+
(param) => param.type !== import_utils46.AST_NODE_TYPES.ObjectPattern && param.type !== import_utils46.AST_NODE_TYPES.RestElement
|
|
3081
3201
|
);
|
|
3082
3202
|
if (hasNonDestructuredParams) {
|
|
3083
3203
|
context.report({
|
|
@@ -3096,8 +3216,8 @@ var preferDestructuringParams = createRule40({
|
|
|
3096
3216
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
3097
3217
|
|
|
3098
3218
|
// src/rules/prefer-function-declaration.ts
|
|
3099
|
-
var
|
|
3100
|
-
var
|
|
3219
|
+
var import_utils47 = require("@typescript-eslint/utils");
|
|
3220
|
+
var createRule43 = import_utils47.ESLintUtils.RuleCreator(
|
|
3101
3221
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3102
3222
|
);
|
|
3103
3223
|
var isTsFile = (filename) => filename.endsWith(".ts") && !filename.endsWith(".d.ts");
|
|
@@ -3106,33 +3226,33 @@ var isCallbackContext = (node) => {
|
|
|
3106
3226
|
if (!parent) {
|
|
3107
3227
|
return false;
|
|
3108
3228
|
}
|
|
3109
|
-
if (parent.type ===
|
|
3229
|
+
if (parent.type === import_utils47.AST_NODE_TYPES.CallExpression && parent.arguments.includes(node)) {
|
|
3110
3230
|
return true;
|
|
3111
3231
|
}
|
|
3112
|
-
if (parent.type ===
|
|
3232
|
+
if (parent.type === import_utils47.AST_NODE_TYPES.NewExpression && parent.arguments.includes(node)) {
|
|
3113
3233
|
return true;
|
|
3114
3234
|
}
|
|
3115
|
-
if (parent.type ===
|
|
3235
|
+
if (parent.type === import_utils47.AST_NODE_TYPES.ReturnStatement) {
|
|
3116
3236
|
return true;
|
|
3117
3237
|
}
|
|
3118
|
-
if (parent.type ===
|
|
3238
|
+
if (parent.type === import_utils47.AST_NODE_TYPES.Property) {
|
|
3119
3239
|
return true;
|
|
3120
3240
|
}
|
|
3121
|
-
if (parent.type ===
|
|
3241
|
+
if (parent.type === import_utils47.AST_NODE_TYPES.ArrayExpression) {
|
|
3122
3242
|
return true;
|
|
3123
3243
|
}
|
|
3124
|
-
if (parent.type ===
|
|
3244
|
+
if (parent.type === import_utils47.AST_NODE_TYPES.ConditionalExpression) {
|
|
3125
3245
|
return true;
|
|
3126
3246
|
}
|
|
3127
|
-
if (parent.type ===
|
|
3247
|
+
if (parent.type === import_utils47.AST_NODE_TYPES.LogicalExpression) {
|
|
3128
3248
|
return true;
|
|
3129
3249
|
}
|
|
3130
|
-
if (parent.type ===
|
|
3250
|
+
if (parent.type === import_utils47.AST_NODE_TYPES.AssignmentExpression && parent.left !== node) {
|
|
3131
3251
|
return true;
|
|
3132
3252
|
}
|
|
3133
3253
|
return false;
|
|
3134
3254
|
};
|
|
3135
|
-
var preferFunctionDeclaration =
|
|
3255
|
+
var preferFunctionDeclaration = createRule43({
|
|
3136
3256
|
name: "prefer-function-declaration",
|
|
3137
3257
|
meta: {
|
|
3138
3258
|
type: "suggestion",
|
|
@@ -3153,14 +3273,14 @@ var preferFunctionDeclaration = createRule41({
|
|
|
3153
3273
|
}
|
|
3154
3274
|
return {
|
|
3155
3275
|
VariableDeclarator(node) {
|
|
3156
|
-
if (node.id.type !==
|
|
3276
|
+
if (node.id.type !== import_utils47.AST_NODE_TYPES.Identifier) {
|
|
3157
3277
|
return;
|
|
3158
3278
|
}
|
|
3159
3279
|
const { init } = node;
|
|
3160
3280
|
if (!init) {
|
|
3161
3281
|
return;
|
|
3162
3282
|
}
|
|
3163
|
-
if (init.type ===
|
|
3283
|
+
if (init.type === import_utils47.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
3164
3284
|
if (isCallbackContext(init)) {
|
|
3165
3285
|
return;
|
|
3166
3286
|
}
|
|
@@ -3170,7 +3290,7 @@ var preferFunctionDeclaration = createRule41({
|
|
|
3170
3290
|
data: { name: node.id.name }
|
|
3171
3291
|
});
|
|
3172
3292
|
}
|
|
3173
|
-
if (init.type ===
|
|
3293
|
+
if (init.type === import_utils47.AST_NODE_TYPES.FunctionExpression) {
|
|
3174
3294
|
if (isCallbackContext(init)) {
|
|
3175
3295
|
return;
|
|
3176
3296
|
}
|
|
@@ -3187,11 +3307,11 @@ var preferFunctionDeclaration = createRule41({
|
|
|
3187
3307
|
var prefer_function_declaration_default = preferFunctionDeclaration;
|
|
3188
3308
|
|
|
3189
3309
|
// src/rules/prefer-guard-clause.ts
|
|
3190
|
-
var
|
|
3191
|
-
var
|
|
3310
|
+
var import_utils48 = require("@typescript-eslint/utils");
|
|
3311
|
+
var createRule44 = import_utils48.ESLintUtils.RuleCreator(
|
|
3192
3312
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3193
3313
|
);
|
|
3194
|
-
var preferGuardClause =
|
|
3314
|
+
var preferGuardClause = createRule44({
|
|
3195
3315
|
name: "prefer-guard-clause",
|
|
3196
3316
|
meta: {
|
|
3197
3317
|
type: "suggestion",
|
|
@@ -3208,8 +3328,8 @@ var preferGuardClause = createRule42({
|
|
|
3208
3328
|
return {
|
|
3209
3329
|
IfStatement(node) {
|
|
3210
3330
|
const { consequent } = node;
|
|
3211
|
-
if (consequent.type ===
|
|
3212
|
-
const hasNestedIf = consequent.body.some((statement) => statement.type ===
|
|
3331
|
+
if (consequent.type === import_utils48.AST_NODE_TYPES.BlockStatement) {
|
|
3332
|
+
const hasNestedIf = consequent.body.some((statement) => statement.type === import_utils48.AST_NODE_TYPES.IfStatement);
|
|
3213
3333
|
if (hasNestedIf && consequent.body.length === 1) {
|
|
3214
3334
|
context.report({
|
|
3215
3335
|
node,
|
|
@@ -3217,7 +3337,7 @@ var preferGuardClause = createRule42({
|
|
|
3217
3337
|
});
|
|
3218
3338
|
}
|
|
3219
3339
|
}
|
|
3220
|
-
if (consequent.type ===
|
|
3340
|
+
if (consequent.type === import_utils48.AST_NODE_TYPES.IfStatement) {
|
|
3221
3341
|
context.report({
|
|
3222
3342
|
node,
|
|
3223
3343
|
messageId: "preferGuardClause"
|
|
@@ -3230,11 +3350,11 @@ var preferGuardClause = createRule42({
|
|
|
3230
3350
|
var prefer_guard_clause_default = preferGuardClause;
|
|
3231
3351
|
|
|
3232
3352
|
// src/rules/prefer-import-type.ts
|
|
3233
|
-
var
|
|
3234
|
-
var
|
|
3353
|
+
var import_utils49 = require("@typescript-eslint/utils");
|
|
3354
|
+
var createRule45 = import_utils49.ESLintUtils.RuleCreator(
|
|
3235
3355
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3236
3356
|
);
|
|
3237
|
-
var preferImportType =
|
|
3357
|
+
var preferImportType = createRule45({
|
|
3238
3358
|
name: "prefer-import-type",
|
|
3239
3359
|
meta: {
|
|
3240
3360
|
type: "suggestion",
|
|
@@ -3253,22 +3373,22 @@ var preferImportType = createRule43({
|
|
|
3253
3373
|
let current = node;
|
|
3254
3374
|
while (current) {
|
|
3255
3375
|
switch (current.type) {
|
|
3256
|
-
case
|
|
3257
|
-
case
|
|
3258
|
-
case
|
|
3259
|
-
case
|
|
3260
|
-
case
|
|
3261
|
-
case
|
|
3262
|
-
case
|
|
3263
|
-
case
|
|
3264
|
-
case
|
|
3265
|
-
case
|
|
3266
|
-
case
|
|
3267
|
-
case
|
|
3268
|
-
case
|
|
3376
|
+
case import_utils49.AST_NODE_TYPES.TSTypeReference:
|
|
3377
|
+
case import_utils49.AST_NODE_TYPES.TSTypeAnnotation:
|
|
3378
|
+
case import_utils49.AST_NODE_TYPES.TSTypeParameterInstantiation:
|
|
3379
|
+
case import_utils49.AST_NODE_TYPES.TSInterfaceHeritage:
|
|
3380
|
+
case import_utils49.AST_NODE_TYPES.TSClassImplements:
|
|
3381
|
+
case import_utils49.AST_NODE_TYPES.TSTypeQuery:
|
|
3382
|
+
case import_utils49.AST_NODE_TYPES.TSTypeAssertion:
|
|
3383
|
+
case import_utils49.AST_NODE_TYPES.TSAsExpression:
|
|
3384
|
+
case import_utils49.AST_NODE_TYPES.TSSatisfiesExpression:
|
|
3385
|
+
case import_utils49.AST_NODE_TYPES.TSTypeAliasDeclaration:
|
|
3386
|
+
case import_utils49.AST_NODE_TYPES.TSInterfaceDeclaration:
|
|
3387
|
+
case import_utils49.AST_NODE_TYPES.TSTypeParameter:
|
|
3388
|
+
case import_utils49.AST_NODE_TYPES.TSQualifiedName:
|
|
3269
3389
|
return true;
|
|
3270
|
-
case
|
|
3271
|
-
case
|
|
3390
|
+
case import_utils49.AST_NODE_TYPES.MemberExpression:
|
|
3391
|
+
case import_utils49.AST_NODE_TYPES.Identifier:
|
|
3272
3392
|
current = current.parent;
|
|
3273
3393
|
break;
|
|
3274
3394
|
default:
|
|
@@ -3298,27 +3418,27 @@ var preferImportType = createRule43({
|
|
|
3298
3418
|
return false;
|
|
3299
3419
|
}
|
|
3300
3420
|
switch (parent.type) {
|
|
3301
|
-
case
|
|
3302
|
-
case
|
|
3303
|
-
case
|
|
3304
|
-
case
|
|
3305
|
-
case
|
|
3306
|
-
case
|
|
3307
|
-
case
|
|
3308
|
-
case
|
|
3309
|
-
case
|
|
3310
|
-
case
|
|
3311
|
-
case
|
|
3312
|
-
case
|
|
3313
|
-
case
|
|
3314
|
-
case
|
|
3315
|
-
case
|
|
3316
|
-
case
|
|
3317
|
-
case
|
|
3318
|
-
case
|
|
3319
|
-
case
|
|
3320
|
-
case
|
|
3321
|
-
case
|
|
3421
|
+
case import_utils49.AST_NODE_TYPES.CallExpression:
|
|
3422
|
+
case import_utils49.AST_NODE_TYPES.NewExpression:
|
|
3423
|
+
case import_utils49.AST_NODE_TYPES.JSXOpeningElement:
|
|
3424
|
+
case import_utils49.AST_NODE_TYPES.JSXClosingElement:
|
|
3425
|
+
case import_utils49.AST_NODE_TYPES.MemberExpression:
|
|
3426
|
+
case import_utils49.AST_NODE_TYPES.VariableDeclarator:
|
|
3427
|
+
case import_utils49.AST_NODE_TYPES.TaggedTemplateExpression:
|
|
3428
|
+
case import_utils49.AST_NODE_TYPES.SpreadElement:
|
|
3429
|
+
case import_utils49.AST_NODE_TYPES.ExportSpecifier:
|
|
3430
|
+
case import_utils49.AST_NODE_TYPES.ArrayExpression:
|
|
3431
|
+
case import_utils49.AST_NODE_TYPES.ObjectExpression:
|
|
3432
|
+
case import_utils49.AST_NODE_TYPES.BinaryExpression:
|
|
3433
|
+
case import_utils49.AST_NODE_TYPES.LogicalExpression:
|
|
3434
|
+
case import_utils49.AST_NODE_TYPES.UnaryExpression:
|
|
3435
|
+
case import_utils49.AST_NODE_TYPES.ReturnStatement:
|
|
3436
|
+
case import_utils49.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
3437
|
+
case import_utils49.AST_NODE_TYPES.ConditionalExpression:
|
|
3438
|
+
case import_utils49.AST_NODE_TYPES.AwaitExpression:
|
|
3439
|
+
case import_utils49.AST_NODE_TYPES.YieldExpression:
|
|
3440
|
+
case import_utils49.AST_NODE_TYPES.Property:
|
|
3441
|
+
case import_utils49.AST_NODE_TYPES.JSXExpressionContainer:
|
|
3322
3442
|
return true;
|
|
3323
3443
|
default:
|
|
3324
3444
|
return false;
|
|
@@ -3330,7 +3450,7 @@ var preferImportType = createRule43({
|
|
|
3330
3450
|
return;
|
|
3331
3451
|
}
|
|
3332
3452
|
const hasInlineTypeSpecifier = node.specifiers.some(
|
|
3333
|
-
(specifier) => specifier.type ===
|
|
3453
|
+
(specifier) => specifier.type === import_utils49.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
|
|
3334
3454
|
);
|
|
3335
3455
|
if (hasInlineTypeSpecifier) {
|
|
3336
3456
|
return;
|
|
@@ -3348,13 +3468,13 @@ var preferImportType = createRule43({
|
|
|
3348
3468
|
}
|
|
3349
3469
|
const scope = context.sourceCode.getScope(node);
|
|
3350
3470
|
const isTypeOnlyImport2 = node.specifiers.every((specifier) => {
|
|
3351
|
-
if (specifier.type ===
|
|
3471
|
+
if (specifier.type === import_utils49.AST_NODE_TYPES.ImportDefaultSpecifier) {
|
|
3352
3472
|
return false;
|
|
3353
3473
|
}
|
|
3354
|
-
if (specifier.type ===
|
|
3474
|
+
if (specifier.type === import_utils49.AST_NODE_TYPES.ImportNamespaceSpecifier) {
|
|
3355
3475
|
return false;
|
|
3356
3476
|
}
|
|
3357
|
-
if (specifier.type ===
|
|
3477
|
+
if (specifier.type === import_utils49.AST_NODE_TYPES.ImportSpecifier) {
|
|
3358
3478
|
const localName = specifier.local.name;
|
|
3359
3479
|
return !isUsedAsValue(localName, scope);
|
|
3360
3480
|
}
|
|
@@ -3380,19 +3500,19 @@ var preferImportType = createRule43({
|
|
|
3380
3500
|
var prefer_import_type_default = preferImportType;
|
|
3381
3501
|
|
|
3382
3502
|
// src/rules/prefer-inline-literal-union.ts
|
|
3383
|
-
var
|
|
3384
|
-
var
|
|
3503
|
+
var import_utils50 = require("@typescript-eslint/utils");
|
|
3504
|
+
var createRule46 = import_utils50.ESLintUtils.RuleCreator(
|
|
3385
3505
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3386
3506
|
);
|
|
3387
3507
|
function isLiteralUnionType(node) {
|
|
3388
|
-
if (node.type !==
|
|
3508
|
+
if (node.type !== import_utils50.AST_NODE_TYPES.TSUnionType) {
|
|
3389
3509
|
return false;
|
|
3390
3510
|
}
|
|
3391
3511
|
return node.types.every(
|
|
3392
|
-
(member) => member.type ===
|
|
3512
|
+
(member) => member.type === import_utils50.AST_NODE_TYPES.TSLiteralType || member.type === import_utils50.AST_NODE_TYPES.TSNullKeyword || member.type === import_utils50.AST_NODE_TYPES.TSUndefinedKeyword
|
|
3393
3513
|
);
|
|
3394
3514
|
}
|
|
3395
|
-
var preferInlineLiteralUnion =
|
|
3515
|
+
var preferInlineLiteralUnion = createRule46({
|
|
3396
3516
|
name: "prefer-inline-literal-union",
|
|
3397
3517
|
meta: {
|
|
3398
3518
|
type: "suggestion",
|
|
@@ -3419,10 +3539,10 @@ var preferInlineLiteralUnion = createRule44({
|
|
|
3419
3539
|
return;
|
|
3420
3540
|
}
|
|
3421
3541
|
const { typeAnnotation } = node.typeAnnotation;
|
|
3422
|
-
if (typeAnnotation.type !==
|
|
3542
|
+
if (typeAnnotation.type !== import_utils50.AST_NODE_TYPES.TSTypeReference) {
|
|
3423
3543
|
return;
|
|
3424
3544
|
}
|
|
3425
|
-
if (typeAnnotation.typeName.type !==
|
|
3545
|
+
if (typeAnnotation.typeName.type !== import_utils50.AST_NODE_TYPES.Identifier) {
|
|
3426
3546
|
return;
|
|
3427
3547
|
}
|
|
3428
3548
|
const aliasName = typeAnnotation.typeName.name;
|
|
@@ -3446,12 +3566,12 @@ var preferInlineLiteralUnion = createRule44({
|
|
|
3446
3566
|
var prefer_inline_literal_union_default = preferInlineLiteralUnion;
|
|
3447
3567
|
|
|
3448
3568
|
// src/rules/prefer-inline-type-export.ts
|
|
3449
|
-
var
|
|
3450
|
-
var
|
|
3569
|
+
var import_utils51 = require("@typescript-eslint/utils");
|
|
3570
|
+
var createRule47 = import_utils51.ESLintUtils.RuleCreator(
|
|
3451
3571
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3452
3572
|
);
|
|
3453
|
-
var isTypeDeclaration = (node) => node.type ===
|
|
3454
|
-
var preferInlineTypeExport =
|
|
3573
|
+
var isTypeDeclaration = (node) => node.type === import_utils51.AST_NODE_TYPES.TSInterfaceDeclaration || node.type === import_utils51.AST_NODE_TYPES.TSTypeAliasDeclaration;
|
|
3574
|
+
var preferInlineTypeExport = createRule47({
|
|
3455
3575
|
name: "prefer-inline-type-export",
|
|
3456
3576
|
meta: {
|
|
3457
3577
|
type: "suggestion",
|
|
@@ -3468,12 +3588,12 @@ var preferInlineTypeExport = createRule45({
|
|
|
3468
3588
|
create(context) {
|
|
3469
3589
|
const typeDeclarations = /* @__PURE__ */ new Map();
|
|
3470
3590
|
function collectDeclaration(node) {
|
|
3471
|
-
if (node.parent.type !==
|
|
3591
|
+
if (node.parent.type !== import_utils51.AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
3472
3592
|
typeDeclarations.set(node.id.name, node);
|
|
3473
3593
|
}
|
|
3474
3594
|
}
|
|
3475
3595
|
function reportSpecifier(specifier, statement, declarationNode) {
|
|
3476
|
-
if (specifier.local.type !==
|
|
3596
|
+
if (specifier.local.type !== import_utils51.AST_NODE_TYPES.Identifier) {
|
|
3477
3597
|
return;
|
|
3478
3598
|
}
|
|
3479
3599
|
const { name } = specifier.local;
|
|
@@ -3506,16 +3626,16 @@ var preferInlineTypeExport = createRule45({
|
|
|
3506
3626
|
return {
|
|
3507
3627
|
Program(node) {
|
|
3508
3628
|
node.body.forEach((statement) => {
|
|
3509
|
-
if (statement.type ===
|
|
3629
|
+
if (statement.type === import_utils51.AST_NODE_TYPES.TSInterfaceDeclaration || statement.type === import_utils51.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
3510
3630
|
collectDeclaration(statement);
|
|
3511
3631
|
}
|
|
3512
3632
|
});
|
|
3513
3633
|
node.body.forEach((statement) => {
|
|
3514
|
-
if (statement.type !==
|
|
3634
|
+
if (statement.type !== import_utils51.AST_NODE_TYPES.ExportNamedDeclaration || statement.declaration !== null) {
|
|
3515
3635
|
return;
|
|
3516
3636
|
}
|
|
3517
3637
|
statement.specifiers.forEach((specifier) => {
|
|
3518
|
-
if (specifier.local.type !==
|
|
3638
|
+
if (specifier.local.type !== import_utils51.AST_NODE_TYPES.Identifier) {
|
|
3519
3639
|
return;
|
|
3520
3640
|
}
|
|
3521
3641
|
const declarationNode = typeDeclarations.get(specifier.local.name);
|
|
@@ -3532,11 +3652,11 @@ var preferInlineTypeExport = createRule45({
|
|
|
3532
3652
|
var prefer_inline_type_export_default = preferInlineTypeExport;
|
|
3533
3653
|
|
|
3534
3654
|
// src/rules/prefer-interface-for-component-props.ts
|
|
3535
|
-
var
|
|
3536
|
-
var
|
|
3655
|
+
var import_utils52 = require("@typescript-eslint/utils");
|
|
3656
|
+
var createRule48 = import_utils52.ESLintUtils.RuleCreator(
|
|
3537
3657
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3538
3658
|
);
|
|
3539
|
-
var preferInterfaceForComponentProps =
|
|
3659
|
+
var preferInterfaceForComponentProps = createRule48({
|
|
3540
3660
|
name: "prefer-interface-for-component-props",
|
|
3541
3661
|
meta: {
|
|
3542
3662
|
type: "suggestion",
|
|
@@ -3556,13 +3676,13 @@ var preferInterfaceForComponentProps = createRule46({
|
|
|
3556
3676
|
}
|
|
3557
3677
|
return {
|
|
3558
3678
|
TSTypeAliasDeclaration(node) {
|
|
3559
|
-
if (node.id.type !==
|
|
3679
|
+
if (node.id.type !== import_utils52.AST_NODE_TYPES.Identifier) {
|
|
3560
3680
|
return;
|
|
3561
3681
|
}
|
|
3562
3682
|
if (!node.id.name.endsWith("Props")) {
|
|
3563
3683
|
return;
|
|
3564
3684
|
}
|
|
3565
|
-
if (node.typeAnnotation.type !==
|
|
3685
|
+
if (node.typeAnnotation.type !== import_utils52.AST_NODE_TYPES.TSTypeLiteral) {
|
|
3566
3686
|
return;
|
|
3567
3687
|
}
|
|
3568
3688
|
const { name } = node.id;
|
|
@@ -3589,11 +3709,11 @@ var preferInterfaceForComponentProps = createRule46({
|
|
|
3589
3709
|
var prefer_interface_for_component_props_default = preferInterfaceForComponentProps;
|
|
3590
3710
|
|
|
3591
3711
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
3592
|
-
var
|
|
3593
|
-
var
|
|
3712
|
+
var import_utils54 = require("@typescript-eslint/utils");
|
|
3713
|
+
var createRule49 = import_utils54.ESLintUtils.RuleCreator(
|
|
3594
3714
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3595
3715
|
);
|
|
3596
|
-
var preferInterfaceOverInlineTypes =
|
|
3716
|
+
var preferInterfaceOverInlineTypes = createRule49({
|
|
3597
3717
|
name: "prefer-interface-over-inline-types",
|
|
3598
3718
|
meta: {
|
|
3599
3719
|
type: "suggestion",
|
|
@@ -3609,54 +3729,54 @@ var preferInterfaceOverInlineTypes = createRule47({
|
|
|
3609
3729
|
defaultOptions: [],
|
|
3610
3730
|
create(context) {
|
|
3611
3731
|
function hasJSXInConditional(node) {
|
|
3612
|
-
return node.consequent.type ===
|
|
3732
|
+
return node.consequent.type === import_utils54.AST_NODE_TYPES.JSXElement || node.consequent.type === import_utils54.AST_NODE_TYPES.JSXFragment || node.alternate.type === import_utils54.AST_NODE_TYPES.JSXElement || node.alternate.type === import_utils54.AST_NODE_TYPES.JSXFragment;
|
|
3613
3733
|
}
|
|
3614
3734
|
function hasJSXInLogical(node) {
|
|
3615
|
-
return node.right.type ===
|
|
3735
|
+
return node.right.type === import_utils54.AST_NODE_TYPES.JSXElement || node.right.type === import_utils54.AST_NODE_TYPES.JSXFragment;
|
|
3616
3736
|
}
|
|
3617
3737
|
function hasJSXReturn(block) {
|
|
3618
3738
|
return block.body.some((stmt) => {
|
|
3619
|
-
if (stmt.type ===
|
|
3620
|
-
return stmt.argument.type ===
|
|
3739
|
+
if (stmt.type === import_utils54.AST_NODE_TYPES.ReturnStatement && stmt.argument) {
|
|
3740
|
+
return stmt.argument.type === import_utils54.AST_NODE_TYPES.JSXElement || stmt.argument.type === import_utils54.AST_NODE_TYPES.JSXFragment || stmt.argument.type === import_utils54.AST_NODE_TYPES.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === import_utils54.AST_NODE_TYPES.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
3621
3741
|
}
|
|
3622
3742
|
return false;
|
|
3623
3743
|
});
|
|
3624
3744
|
}
|
|
3625
3745
|
function isReactComponent2(node) {
|
|
3626
|
-
if (node.type ===
|
|
3627
|
-
if (node.body.type ===
|
|
3746
|
+
if (node.type === import_utils54.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
3747
|
+
if (node.body.type === import_utils54.AST_NODE_TYPES.JSXElement || node.body.type === import_utils54.AST_NODE_TYPES.JSXFragment) {
|
|
3628
3748
|
return true;
|
|
3629
3749
|
}
|
|
3630
|
-
if (node.body.type ===
|
|
3750
|
+
if (node.body.type === import_utils54.AST_NODE_TYPES.BlockStatement) {
|
|
3631
3751
|
return hasJSXReturn(node.body);
|
|
3632
3752
|
}
|
|
3633
|
-
} else if (node.type ===
|
|
3634
|
-
if (node.body && node.body.type ===
|
|
3753
|
+
} else if (node.type === import_utils54.AST_NODE_TYPES.FunctionExpression || node.type === import_utils54.AST_NODE_TYPES.FunctionDeclaration) {
|
|
3754
|
+
if (node.body && node.body.type === import_utils54.AST_NODE_TYPES.BlockStatement) {
|
|
3635
3755
|
return hasJSXReturn(node.body);
|
|
3636
3756
|
}
|
|
3637
3757
|
}
|
|
3638
3758
|
return false;
|
|
3639
3759
|
}
|
|
3640
3760
|
function isInlineTypeAnnotation(node) {
|
|
3641
|
-
if (node.type ===
|
|
3761
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSTypeLiteral) {
|
|
3642
3762
|
return true;
|
|
3643
3763
|
}
|
|
3644
|
-
if (node.type ===
|
|
3645
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3764
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSTypeReference && node.typeArguments) {
|
|
3765
|
+
return node.typeArguments.params.some((param) => param.type === import_utils54.AST_NODE_TYPES.TSTypeLiteral);
|
|
3646
3766
|
}
|
|
3647
|
-
if (node.type ===
|
|
3767
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSUnionType) {
|
|
3648
3768
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
3649
3769
|
}
|
|
3650
3770
|
return false;
|
|
3651
3771
|
}
|
|
3652
3772
|
function hasInlineObjectType(node) {
|
|
3653
|
-
if (node.type ===
|
|
3773
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSTypeLiteral) {
|
|
3654
3774
|
return true;
|
|
3655
3775
|
}
|
|
3656
|
-
if (node.type ===
|
|
3657
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3776
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSTypeReference && node.typeArguments) {
|
|
3777
|
+
return node.typeArguments.params.some((param) => param.type === import_utils54.AST_NODE_TYPES.TSTypeLiteral);
|
|
3658
3778
|
}
|
|
3659
|
-
if (node.type ===
|
|
3779
|
+
if (node.type === import_utils54.AST_NODE_TYPES.TSUnionType) {
|
|
3660
3780
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
3661
3781
|
}
|
|
3662
3782
|
return false;
|
|
@@ -3669,7 +3789,7 @@ var preferInterfaceOverInlineTypes = createRule47({
|
|
|
3669
3789
|
return;
|
|
3670
3790
|
}
|
|
3671
3791
|
const param = node.params[0];
|
|
3672
|
-
if (param.type ===
|
|
3792
|
+
if (param.type === import_utils54.AST_NODE_TYPES.Identifier && param.typeAnnotation) {
|
|
3673
3793
|
const { typeAnnotation } = param.typeAnnotation;
|
|
3674
3794
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
3675
3795
|
context.report({
|
|
@@ -3689,11 +3809,11 @@ var preferInterfaceOverInlineTypes = createRule47({
|
|
|
3689
3809
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
3690
3810
|
|
|
3691
3811
|
// src/rules/prefer-jsx-template-literals.ts
|
|
3692
|
-
var
|
|
3693
|
-
var
|
|
3812
|
+
var import_utils55 = require("@typescript-eslint/utils");
|
|
3813
|
+
var createRule50 = import_utils55.ESLintUtils.RuleCreator(
|
|
3694
3814
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3695
3815
|
);
|
|
3696
|
-
var preferJSXTemplateLiterals =
|
|
3816
|
+
var preferJSXTemplateLiterals = createRule50({
|
|
3697
3817
|
name: "prefer-jsx-template-literals",
|
|
3698
3818
|
meta: {
|
|
3699
3819
|
type: "suggestion",
|
|
@@ -3762,9 +3882,9 @@ var preferJSXTemplateLiterals = createRule48({
|
|
|
3762
3882
|
if (!child || !nextChild) {
|
|
3763
3883
|
return;
|
|
3764
3884
|
}
|
|
3765
|
-
if (child.type ===
|
|
3885
|
+
if (child.type === import_utils55.AST_NODE_TYPES.JSXText && nextChild.type === import_utils55.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
3766
3886
|
handleTextBeforeExpression(child, nextChild);
|
|
3767
|
-
} else if (child.type ===
|
|
3887
|
+
} else if (child.type === import_utils55.AST_NODE_TYPES.JSXExpressionContainer && nextChild.type === import_utils55.AST_NODE_TYPES.JSXText) {
|
|
3768
3888
|
handleExpressionBeforeText(child, nextChild);
|
|
3769
3889
|
}
|
|
3770
3890
|
}
|
|
@@ -3777,32 +3897,32 @@ var preferJSXTemplateLiterals = createRule48({
|
|
|
3777
3897
|
var prefer_jsx_template_literals_default = preferJSXTemplateLiterals;
|
|
3778
3898
|
|
|
3779
3899
|
// src/rules/prefer-named-param-types.ts
|
|
3780
|
-
var
|
|
3781
|
-
var
|
|
3900
|
+
var import_utils56 = require("@typescript-eslint/utils");
|
|
3901
|
+
var createRule51 = import_utils56.ESLintUtils.RuleCreator(
|
|
3782
3902
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3783
3903
|
);
|
|
3784
3904
|
var returnsJsx2 = (node) => {
|
|
3785
|
-
if (node.type ===
|
|
3905
|
+
if (node.type === import_utils56.AST_NODE_TYPES.JSXElement || node.type === import_utils56.AST_NODE_TYPES.JSXFragment) {
|
|
3786
3906
|
return true;
|
|
3787
3907
|
}
|
|
3788
|
-
if (node.type ===
|
|
3908
|
+
if (node.type === import_utils56.AST_NODE_TYPES.ConditionalExpression) {
|
|
3789
3909
|
return returnsJsx2(node.consequent) || returnsJsx2(node.alternate);
|
|
3790
3910
|
}
|
|
3791
|
-
if (node.type ===
|
|
3911
|
+
if (node.type === import_utils56.AST_NODE_TYPES.LogicalExpression) {
|
|
3792
3912
|
return returnsJsx2(node.left) || returnsJsx2(node.right);
|
|
3793
3913
|
}
|
|
3794
3914
|
return false;
|
|
3795
3915
|
};
|
|
3796
3916
|
var bodyReturnsJsx2 = (body) => {
|
|
3797
|
-
if (body.type !==
|
|
3917
|
+
if (body.type !== import_utils56.AST_NODE_TYPES.BlockStatement) {
|
|
3798
3918
|
return returnsJsx2(body);
|
|
3799
3919
|
}
|
|
3800
3920
|
return body.body.some(
|
|
3801
|
-
(stmt) => stmt.type ===
|
|
3921
|
+
(stmt) => stmt.type === import_utils56.AST_NODE_TYPES.ReturnStatement && stmt.argument !== null && returnsJsx2(stmt.argument)
|
|
3802
3922
|
);
|
|
3803
3923
|
};
|
|
3804
3924
|
var isReactComponentFunction = (node) => bodyReturnsJsx2(node.body);
|
|
3805
|
-
var preferNamedParamTypes =
|
|
3925
|
+
var preferNamedParamTypes = createRule51({
|
|
3806
3926
|
name: "prefer-named-param-types",
|
|
3807
3927
|
meta: {
|
|
3808
3928
|
type: "suggestion",
|
|
@@ -3817,16 +3937,16 @@ var preferNamedParamTypes = createRule49({
|
|
|
3817
3937
|
defaultOptions: [],
|
|
3818
3938
|
create(context) {
|
|
3819
3939
|
function hasInlineObjectType(param) {
|
|
3820
|
-
if (param.type ===
|
|
3940
|
+
if (param.type === import_utils56.AST_NODE_TYPES.AssignmentPattern) {
|
|
3821
3941
|
return hasInlineObjectType(param.left);
|
|
3822
3942
|
}
|
|
3823
|
-
if (param.type ===
|
|
3824
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3943
|
+
if (param.type === import_utils56.AST_NODE_TYPES.ObjectPattern) {
|
|
3944
|
+
if (param.typeAnnotation?.typeAnnotation.type === import_utils56.AST_NODE_TYPES.TSTypeLiteral) {
|
|
3825
3945
|
return true;
|
|
3826
3946
|
}
|
|
3827
3947
|
}
|
|
3828
|
-
if (param.type ===
|
|
3829
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3948
|
+
if (param.type === import_utils56.AST_NODE_TYPES.Identifier) {
|
|
3949
|
+
if (param.typeAnnotation?.typeAnnotation.type === import_utils56.AST_NODE_TYPES.TSTypeLiteral) {
|
|
3830
3950
|
return true;
|
|
3831
3951
|
}
|
|
3832
3952
|
}
|
|
@@ -3839,7 +3959,7 @@ var preferNamedParamTypes = createRule49({
|
|
|
3839
3959
|
} else if ("value" in node && node.value) {
|
|
3840
3960
|
params = node.value.params;
|
|
3841
3961
|
}
|
|
3842
|
-
if ((node.type ===
|
|
3962
|
+
if ((node.type === import_utils56.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils56.AST_NODE_TYPES.FunctionExpression || node.type === import_utils56.AST_NODE_TYPES.ArrowFunctionExpression) && params.length === 1 && params[0].type === import_utils56.AST_NODE_TYPES.Identifier && isReactComponentFunction(node)) {
|
|
3843
3963
|
return;
|
|
3844
3964
|
}
|
|
3845
3965
|
params.forEach((param) => {
|
|
@@ -3863,11 +3983,11 @@ var preferNamedParamTypes = createRule49({
|
|
|
3863
3983
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
3864
3984
|
|
|
3865
3985
|
// src/rules/prefer-props-with-children.ts
|
|
3866
|
-
var
|
|
3867
|
-
var
|
|
3986
|
+
var import_utils57 = require("@typescript-eslint/utils");
|
|
3987
|
+
var createRule52 = import_utils57.ESLintUtils.RuleCreator(
|
|
3868
3988
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3869
3989
|
);
|
|
3870
|
-
var preferPropsWithChildren =
|
|
3990
|
+
var preferPropsWithChildren = createRule52({
|
|
3871
3991
|
name: "prefer-props-with-children",
|
|
3872
3992
|
meta: {
|
|
3873
3993
|
type: "suggestion",
|
|
@@ -3885,24 +4005,24 @@ var preferPropsWithChildren = createRule50({
|
|
|
3885
4005
|
if (!typeNode) {
|
|
3886
4006
|
return false;
|
|
3887
4007
|
}
|
|
3888
|
-
if (typeNode.type !==
|
|
4008
|
+
if (typeNode.type !== import_utils57.AST_NODE_TYPES.TSTypeReference) {
|
|
3889
4009
|
return false;
|
|
3890
4010
|
}
|
|
3891
4011
|
const { typeName } = typeNode;
|
|
3892
|
-
if (typeName.type ===
|
|
4012
|
+
if (typeName.type === import_utils57.AST_NODE_TYPES.Identifier) {
|
|
3893
4013
|
return typeName.name === "ReactNode";
|
|
3894
4014
|
}
|
|
3895
|
-
if (typeName.type ===
|
|
4015
|
+
if (typeName.type === import_utils57.AST_NODE_TYPES.TSQualifiedName && typeName.left.type === import_utils57.AST_NODE_TYPES.Identifier && typeName.left.name === "React" && typeName.right.type === import_utils57.AST_NODE_TYPES.Identifier && typeName.right.name === "ReactNode") {
|
|
3896
4016
|
return true;
|
|
3897
4017
|
}
|
|
3898
4018
|
return false;
|
|
3899
4019
|
}
|
|
3900
4020
|
function findChildrenReactNode(members) {
|
|
3901
4021
|
for (const member of members) {
|
|
3902
|
-
if (member.type !==
|
|
4022
|
+
if (member.type !== import_utils57.AST_NODE_TYPES.TSPropertySignature) {
|
|
3903
4023
|
continue;
|
|
3904
4024
|
}
|
|
3905
|
-
if (member.key.type !==
|
|
4025
|
+
if (member.key.type !== import_utils57.AST_NODE_TYPES.Identifier) {
|
|
3906
4026
|
continue;
|
|
3907
4027
|
}
|
|
3908
4028
|
if (member.key.name !== "children") {
|
|
@@ -3942,11 +4062,11 @@ var preferPropsWithChildren = createRule50({
|
|
|
3942
4062
|
var prefer_props_with_children_default = preferPropsWithChildren;
|
|
3943
4063
|
|
|
3944
4064
|
// src/rules/prefer-react-import-types.ts
|
|
3945
|
-
var
|
|
3946
|
-
var
|
|
4065
|
+
var import_utils58 = require("@typescript-eslint/utils");
|
|
4066
|
+
var createRule53 = import_utils58.ESLintUtils.RuleCreator(
|
|
3947
4067
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3948
4068
|
);
|
|
3949
|
-
var preferReactImportTypes =
|
|
4069
|
+
var preferReactImportTypes = createRule53({
|
|
3950
4070
|
name: "prefer-react-import-types",
|
|
3951
4071
|
meta: {
|
|
3952
4072
|
type: "suggestion",
|
|
@@ -4022,7 +4142,7 @@ var preferReactImportTypes = createRule51({
|
|
|
4022
4142
|
]);
|
|
4023
4143
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
4024
4144
|
function checkMemberExpression(node) {
|
|
4025
|
-
if (node.object.type ===
|
|
4145
|
+
if (node.object.type === import_utils58.AST_NODE_TYPES.Identifier && node.object.name === "React" && node.property.type === import_utils58.AST_NODE_TYPES.Identifier && allReactExports.has(node.property.name)) {
|
|
4026
4146
|
const typeName = node.property.name;
|
|
4027
4147
|
const isType = reactTypes.has(typeName);
|
|
4028
4148
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -4039,7 +4159,7 @@ var preferReactImportTypes = createRule51({
|
|
|
4039
4159
|
return {
|
|
4040
4160
|
MemberExpression: checkMemberExpression,
|
|
4041
4161
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
4042
|
-
if (node.left.type ===
|
|
4162
|
+
if (node.left.type === import_utils58.AST_NODE_TYPES.Identifier && node.left.name === "React" && node.right.type === import_utils58.AST_NODE_TYPES.Identifier && allReactExports.has(node.right.name)) {
|
|
4043
4163
|
const typeName = node.right.name;
|
|
4044
4164
|
const isType = reactTypes.has(typeName);
|
|
4045
4165
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -4059,11 +4179,11 @@ var preferReactImportTypes = createRule51({
|
|
|
4059
4179
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
4060
4180
|
|
|
4061
4181
|
// src/rules/react-props-destructure.ts
|
|
4062
|
-
var
|
|
4063
|
-
var
|
|
4182
|
+
var import_utils59 = require("@typescript-eslint/utils");
|
|
4183
|
+
var createRule54 = import_utils59.ESLintUtils.RuleCreator(
|
|
4064
4184
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4065
4185
|
);
|
|
4066
|
-
var reactPropsDestructure =
|
|
4186
|
+
var reactPropsDestructure = createRule54({
|
|
4067
4187
|
name: "react-props-destructure",
|
|
4068
4188
|
meta: {
|
|
4069
4189
|
type: "suggestion",
|
|
@@ -4079,29 +4199,29 @@ var reactPropsDestructure = createRule52({
|
|
|
4079
4199
|
defaultOptions: [],
|
|
4080
4200
|
create(context) {
|
|
4081
4201
|
function hasJSXInConditional(node) {
|
|
4082
|
-
return node.consequent.type ===
|
|
4202
|
+
return node.consequent.type === import_utils59.AST_NODE_TYPES.JSXElement || node.consequent.type === import_utils59.AST_NODE_TYPES.JSXFragment || node.alternate.type === import_utils59.AST_NODE_TYPES.JSXElement || node.alternate.type === import_utils59.AST_NODE_TYPES.JSXFragment;
|
|
4083
4203
|
}
|
|
4084
4204
|
function hasJSXInLogical(node) {
|
|
4085
|
-
return node.right.type ===
|
|
4205
|
+
return node.right.type === import_utils59.AST_NODE_TYPES.JSXElement || node.right.type === import_utils59.AST_NODE_TYPES.JSXFragment;
|
|
4086
4206
|
}
|
|
4087
4207
|
function hasJSXReturn(block) {
|
|
4088
4208
|
return block.body.some((stmt) => {
|
|
4089
|
-
if (stmt.type ===
|
|
4090
|
-
return stmt.argument.type ===
|
|
4209
|
+
if (stmt.type === import_utils59.AST_NODE_TYPES.ReturnStatement && stmt.argument) {
|
|
4210
|
+
return stmt.argument.type === import_utils59.AST_NODE_TYPES.JSXElement || stmt.argument.type === import_utils59.AST_NODE_TYPES.JSXFragment || stmt.argument.type === import_utils59.AST_NODE_TYPES.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === import_utils59.AST_NODE_TYPES.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
4091
4211
|
}
|
|
4092
4212
|
return false;
|
|
4093
4213
|
});
|
|
4094
4214
|
}
|
|
4095
4215
|
function isReactComponent2(node) {
|
|
4096
|
-
if (node.type ===
|
|
4097
|
-
if (node.body.type ===
|
|
4216
|
+
if (node.type === import_utils59.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
4217
|
+
if (node.body.type === import_utils59.AST_NODE_TYPES.JSXElement || node.body.type === import_utils59.AST_NODE_TYPES.JSXFragment) {
|
|
4098
4218
|
return true;
|
|
4099
4219
|
}
|
|
4100
|
-
if (node.body.type ===
|
|
4220
|
+
if (node.body.type === import_utils59.AST_NODE_TYPES.BlockStatement) {
|
|
4101
4221
|
return hasJSXReturn(node.body);
|
|
4102
4222
|
}
|
|
4103
|
-
} else if (node.type ===
|
|
4104
|
-
if (node.body && node.body.type ===
|
|
4223
|
+
} else if (node.type === import_utils59.AST_NODE_TYPES.FunctionExpression || node.type === import_utils59.AST_NODE_TYPES.FunctionDeclaration) {
|
|
4224
|
+
if (node.body && node.body.type === import_utils59.AST_NODE_TYPES.BlockStatement) {
|
|
4105
4225
|
return hasJSXReturn(node.body);
|
|
4106
4226
|
}
|
|
4107
4227
|
}
|
|
@@ -4115,9 +4235,9 @@ var reactPropsDestructure = createRule52({
|
|
|
4115
4235
|
return;
|
|
4116
4236
|
}
|
|
4117
4237
|
const param = node.params[0];
|
|
4118
|
-
if (param.type ===
|
|
4119
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
4120
|
-
if (prop.key.type ===
|
|
4238
|
+
if (param.type === import_utils59.AST_NODE_TYPES.ObjectPattern) {
|
|
4239
|
+
const properties = param.properties.filter((prop) => prop.type === import_utils59.AST_NODE_TYPES.Property).map((prop) => {
|
|
4240
|
+
if (prop.key.type === import_utils59.AST_NODE_TYPES.Identifier) {
|
|
4121
4241
|
return prop.key.name;
|
|
4122
4242
|
}
|
|
4123
4243
|
return null;
|
|
@@ -4144,57 +4264,57 @@ var reactPropsDestructure = createRule52({
|
|
|
4144
4264
|
var react_props_destructure_default = reactPropsDestructure;
|
|
4145
4265
|
|
|
4146
4266
|
// src/rules/require-explicit-return-type.ts
|
|
4147
|
-
var
|
|
4148
|
-
var
|
|
4267
|
+
var import_utils60 = require("@typescript-eslint/utils");
|
|
4268
|
+
var createRule55 = import_utils60.ESLintUtils.RuleCreator(
|
|
4149
4269
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4150
4270
|
);
|
|
4151
4271
|
var isReactComponent = (node) => {
|
|
4152
|
-
if (node.type ===
|
|
4272
|
+
if (node.type === import_utils60.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
4153
4273
|
const { parent } = node;
|
|
4154
|
-
if (parent?.type ===
|
|
4274
|
+
if (parent?.type === import_utils60.AST_NODE_TYPES.VariableDeclarator) {
|
|
4155
4275
|
const { id } = parent;
|
|
4156
|
-
if (id.type ===
|
|
4276
|
+
if (id.type === import_utils60.AST_NODE_TYPES.Identifier) {
|
|
4157
4277
|
return /^[A-Z]/.test(id.name);
|
|
4158
4278
|
}
|
|
4159
4279
|
}
|
|
4160
4280
|
}
|
|
4161
|
-
if (node.type ===
|
|
4281
|
+
if (node.type === import_utils60.AST_NODE_TYPES.FunctionDeclaration && node.id) {
|
|
4162
4282
|
return /^[A-Z]/.test(node.id.name);
|
|
4163
4283
|
}
|
|
4164
4284
|
return false;
|
|
4165
4285
|
};
|
|
4166
4286
|
var isCallbackFunction = (node) => {
|
|
4167
|
-
if (node.type ===
|
|
4287
|
+
if (node.type === import_utils60.AST_NODE_TYPES.FunctionDeclaration) {
|
|
4168
4288
|
return false;
|
|
4169
4289
|
}
|
|
4170
4290
|
const { parent } = node;
|
|
4171
4291
|
if (!parent) {
|
|
4172
4292
|
return false;
|
|
4173
4293
|
}
|
|
4174
|
-
if (parent.type ===
|
|
4294
|
+
if (parent.type === import_utils60.AST_NODE_TYPES.CallExpression && parent.arguments.includes(node)) {
|
|
4175
4295
|
return true;
|
|
4176
4296
|
}
|
|
4177
|
-
if (parent.type ===
|
|
4297
|
+
if (parent.type === import_utils60.AST_NODE_TYPES.Property) {
|
|
4178
4298
|
return true;
|
|
4179
4299
|
}
|
|
4180
|
-
if (parent.type ===
|
|
4300
|
+
if (parent.type === import_utils60.AST_NODE_TYPES.ArrayExpression) {
|
|
4181
4301
|
return true;
|
|
4182
4302
|
}
|
|
4183
4303
|
return false;
|
|
4184
4304
|
};
|
|
4185
4305
|
var getFunctionName = (node) => {
|
|
4186
|
-
if (node.type ===
|
|
4306
|
+
if (node.type === import_utils60.AST_NODE_TYPES.FunctionDeclaration && node.id) {
|
|
4187
4307
|
return node.id.name;
|
|
4188
4308
|
}
|
|
4189
|
-
if (node.type ===
|
|
4309
|
+
if (node.type === import_utils60.AST_NODE_TYPES.FunctionExpression && node.id) {
|
|
4190
4310
|
return node.id.name;
|
|
4191
4311
|
}
|
|
4192
|
-
if ((node.type ===
|
|
4312
|
+
if ((node.type === import_utils60.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils60.AST_NODE_TYPES.FunctionExpression) && node.parent?.type === import_utils60.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils60.AST_NODE_TYPES.Identifier) {
|
|
4193
4313
|
return node.parent.id.name;
|
|
4194
4314
|
}
|
|
4195
4315
|
return null;
|
|
4196
4316
|
};
|
|
4197
|
-
var requireExplicitReturnType =
|
|
4317
|
+
var requireExplicitReturnType = createRule55({
|
|
4198
4318
|
name: "require-explicit-return-type",
|
|
4199
4319
|
meta: {
|
|
4200
4320
|
type: "suggestion",
|
|
@@ -4243,8 +4363,8 @@ var requireExplicitReturnType = createRule53({
|
|
|
4243
4363
|
var require_explicit_return_type_default = requireExplicitReturnType;
|
|
4244
4364
|
|
|
4245
4365
|
// src/rules/sort-exports.ts
|
|
4246
|
-
var
|
|
4247
|
-
var
|
|
4366
|
+
var import_utils61 = require("@typescript-eslint/utils");
|
|
4367
|
+
var createRule56 = import_utils61.ESLintUtils.RuleCreator(
|
|
4248
4368
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4249
4369
|
);
|
|
4250
4370
|
var GROUP_NAMES = ["", "external/alias re-export", "relative re-export", "local export"];
|
|
@@ -4258,7 +4378,7 @@ function getExportGroup(node) {
|
|
|
4258
4378
|
}
|
|
4259
4379
|
return 1;
|
|
4260
4380
|
}
|
|
4261
|
-
var sortExports =
|
|
4381
|
+
var sortExports = createRule56({
|
|
4262
4382
|
name: "sort-exports",
|
|
4263
4383
|
meta: {
|
|
4264
4384
|
type: "suggestion",
|
|
@@ -4298,7 +4418,7 @@ var sortExports = createRule54({
|
|
|
4298
4418
|
Program(node) {
|
|
4299
4419
|
const exportGroups = [];
|
|
4300
4420
|
node.body.forEach((statement) => {
|
|
4301
|
-
if (statement.type !==
|
|
4421
|
+
if (statement.type !== import_utils61.AST_NODE_TYPES.ExportNamedDeclaration || statement.declaration !== null) {
|
|
4302
4422
|
if (exportGroups.length > 0) {
|
|
4303
4423
|
checkOrder(exportGroups);
|
|
4304
4424
|
exportGroups.length = 0;
|
|
@@ -4317,8 +4437,8 @@ var sortExports = createRule54({
|
|
|
4317
4437
|
var sort_exports_default = sortExports;
|
|
4318
4438
|
|
|
4319
4439
|
// src/rules/sort-imports.ts
|
|
4320
|
-
var
|
|
4321
|
-
var
|
|
4440
|
+
var import_utils62 = require("@typescript-eslint/utils");
|
|
4441
|
+
var createRule57 = import_utils62.ESLintUtils.RuleCreator(
|
|
4322
4442
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4323
4443
|
);
|
|
4324
4444
|
var NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
@@ -4385,7 +4505,7 @@ function getImportGroup(node) {
|
|
|
4385
4505
|
function isTypeOnlyImport(node) {
|
|
4386
4506
|
return node.importKind === "type" && node.specifiers.length > 0;
|
|
4387
4507
|
}
|
|
4388
|
-
var sortImports =
|
|
4508
|
+
var sortImports = createRule57({
|
|
4389
4509
|
name: "sort-imports",
|
|
4390
4510
|
meta: {
|
|
4391
4511
|
type: "suggestion",
|
|
@@ -4429,7 +4549,7 @@ var sortImports = createRule55({
|
|
|
4429
4549
|
Program(node) {
|
|
4430
4550
|
const importGroups = [];
|
|
4431
4551
|
node.body.forEach((statement) => {
|
|
4432
|
-
if (statement.type !==
|
|
4552
|
+
if (statement.type !== import_utils62.AST_NODE_TYPES.ImportDeclaration) {
|
|
4433
4553
|
if (importGroups.length > 0) {
|
|
4434
4554
|
checkOrder(importGroups);
|
|
4435
4555
|
importGroups.length = 0;
|
|
@@ -4451,13 +4571,13 @@ var sortImports = createRule55({
|
|
|
4451
4571
|
var sort_imports_default = sortImports;
|
|
4452
4572
|
|
|
4453
4573
|
// src/rules/sort-type-alphabetically.ts
|
|
4454
|
-
var
|
|
4455
|
-
var
|
|
4574
|
+
var import_utils63 = require("@typescript-eslint/utils");
|
|
4575
|
+
var createRule58 = import_utils63.ESLintUtils.RuleCreator(
|
|
4456
4576
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4457
4577
|
);
|
|
4458
4578
|
function isAlphabeticallySortedWithinGroups(members) {
|
|
4459
4579
|
const properties = members.filter(
|
|
4460
|
-
(member) => member.type ===
|
|
4580
|
+
(member) => member.type === import_utils63.AST_NODE_TYPES.TSPropertySignature && member.key.type === import_utils63.AST_NODE_TYPES.Identifier
|
|
4461
4581
|
);
|
|
4462
4582
|
if (properties.length < 2) {
|
|
4463
4583
|
return true;
|
|
@@ -4468,7 +4588,7 @@ function isAlphabeticallySortedWithinGroups(members) {
|
|
|
4468
4588
|
const isOptionalSorted = optional.every((name, index) => index === 0 || optional[index - 1].localeCompare(name) <= 0);
|
|
4469
4589
|
return isRequiredSorted && isOptionalSorted;
|
|
4470
4590
|
}
|
|
4471
|
-
var sortTypeAlphabetically =
|
|
4591
|
+
var sortTypeAlphabetically = createRule58({
|
|
4472
4592
|
name: "sort-type-alphabetically",
|
|
4473
4593
|
meta: {
|
|
4474
4594
|
type: "suggestion",
|
|
@@ -4486,7 +4606,7 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4486
4606
|
function fixMembers(fixer, members) {
|
|
4487
4607
|
const { sourceCode } = context;
|
|
4488
4608
|
const properties = members.filter(
|
|
4489
|
-
(member) => member.type ===
|
|
4609
|
+
(member) => member.type === import_utils63.AST_NODE_TYPES.TSPropertySignature && member.key.type === import_utils63.AST_NODE_TYPES.Identifier
|
|
4490
4610
|
);
|
|
4491
4611
|
const required = properties.filter((prop) => !prop.optional);
|
|
4492
4612
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4523,7 +4643,7 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4523
4643
|
}
|
|
4524
4644
|
},
|
|
4525
4645
|
TSTypeAliasDeclaration(node) {
|
|
4526
|
-
if (node.typeAnnotation.type !==
|
|
4646
|
+
if (node.typeAnnotation.type !== import_utils63.AST_NODE_TYPES.TSTypeLiteral) {
|
|
4527
4647
|
return;
|
|
4528
4648
|
}
|
|
4529
4649
|
const { members } = node.typeAnnotation;
|
|
@@ -4543,13 +4663,13 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4543
4663
|
var sort_type_alphabetically_default = sortTypeAlphabetically;
|
|
4544
4664
|
|
|
4545
4665
|
// src/rules/sort-type-required-first.ts
|
|
4546
|
-
var
|
|
4547
|
-
var
|
|
4666
|
+
var import_utils64 = require("@typescript-eslint/utils");
|
|
4667
|
+
var createRule59 = import_utils64.ESLintUtils.RuleCreator(
|
|
4548
4668
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4549
4669
|
);
|
|
4550
4670
|
function isRequiredBeforeOptional(members) {
|
|
4551
4671
|
const properties = members.filter(
|
|
4552
|
-
(member) => member.type ===
|
|
4672
|
+
(member) => member.type === import_utils64.AST_NODE_TYPES.TSPropertySignature && member.key.type === import_utils64.AST_NODE_TYPES.Identifier
|
|
4553
4673
|
);
|
|
4554
4674
|
if (properties.length < 2) {
|
|
4555
4675
|
return true;
|
|
@@ -4560,7 +4680,7 @@ function isRequiredBeforeOptional(members) {
|
|
|
4560
4680
|
}
|
|
4561
4681
|
return properties.slice(firstOptionalIndex).every((prop) => prop.optional);
|
|
4562
4682
|
}
|
|
4563
|
-
var sortTypeRequiredFirst =
|
|
4683
|
+
var sortTypeRequiredFirst = createRule59({
|
|
4564
4684
|
name: "sort-type-required-first",
|
|
4565
4685
|
meta: {
|
|
4566
4686
|
type: "suggestion",
|
|
@@ -4578,7 +4698,7 @@ var sortTypeRequiredFirst = createRule57({
|
|
|
4578
4698
|
function fixMembers(fixer, members) {
|
|
4579
4699
|
const { sourceCode } = context;
|
|
4580
4700
|
const properties = members.filter(
|
|
4581
|
-
(member) => member.type ===
|
|
4701
|
+
(member) => member.type === import_utils64.AST_NODE_TYPES.TSPropertySignature && member.key.type === import_utils64.AST_NODE_TYPES.Identifier
|
|
4582
4702
|
);
|
|
4583
4703
|
const required = properties.filter((prop) => !prop.optional);
|
|
4584
4704
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4599,7 +4719,7 @@ var sortTypeRequiredFirst = createRule57({
|
|
|
4599
4719
|
}
|
|
4600
4720
|
},
|
|
4601
4721
|
TSTypeAliasDeclaration(node) {
|
|
4602
|
-
if (node.typeAnnotation.type !==
|
|
4722
|
+
if (node.typeAnnotation.type !== import_utils64.AST_NODE_TYPES.TSTypeLiteral) {
|
|
4603
4723
|
return;
|
|
4604
4724
|
}
|
|
4605
4725
|
const { members } = node.typeAnnotation;
|
|
@@ -4651,6 +4771,7 @@ var rules = {
|
|
|
4651
4771
|
"no-direct-date": no_direct_date_default,
|
|
4652
4772
|
"no-emoji": no_emoji_default,
|
|
4653
4773
|
"no-env-fallback": no_env_fallback_default,
|
|
4774
|
+
"no-ghost-wrapper": no_ghost_wrapper_default,
|
|
4654
4775
|
"no-inline-default-export": no_inline_default_export_default,
|
|
4655
4776
|
"no-inline-nested-object": no_inline_nested_object_default,
|
|
4656
4777
|
"no-inline-return-properties": no_inline_return_properties_default,
|
|
@@ -4660,6 +4781,7 @@ var rules = {
|
|
|
4660
4781
|
"no-misleading-constant-case": no_misleading_constant_case_default,
|
|
4661
4782
|
"no-nested-interface-declaration": no_nested_interface_declaration_default,
|
|
4662
4783
|
"no-nested-ternary": no_nested_ternary_default,
|
|
4784
|
+
"no-redundant-fragment": no_redundant_fragment_default,
|
|
4663
4785
|
"no-relative-imports": no_relative_imports_default,
|
|
4664
4786
|
"no-single-char-variables": no_single_char_variables_default,
|
|
4665
4787
|
"prefer-async-await": prefer_async_await_default,
|
|
@@ -4783,6 +4905,8 @@ var jsxRules = {
|
|
|
4783
4905
|
"nextfriday/jsx-simple-props": "warn",
|
|
4784
4906
|
"nextfriday/jsx-sort-props": "warn",
|
|
4785
4907
|
"nextfriday/jsx-spread-props-last": "warn",
|
|
4908
|
+
"nextfriday/no-ghost-wrapper": "warn",
|
|
4909
|
+
"nextfriday/no-redundant-fragment": "warn",
|
|
4786
4910
|
"nextfriday/prefer-interface-for-component-props": "warn",
|
|
4787
4911
|
"nextfriday/prefer-interface-over-inline-types": "warn",
|
|
4788
4912
|
"nextfriday/prefer-jsx-template-literals": "warn",
|
|
@@ -4802,6 +4926,8 @@ var jsxRecommendedRules = {
|
|
|
4802
4926
|
"nextfriday/jsx-simple-props": "error",
|
|
4803
4927
|
"nextfriday/jsx-sort-props": "error",
|
|
4804
4928
|
"nextfriday/jsx-spread-props-last": "error",
|
|
4929
|
+
"nextfriday/no-ghost-wrapper": "error",
|
|
4930
|
+
"nextfriday/no-redundant-fragment": "error",
|
|
4805
4931
|
"nextfriday/prefer-interface-for-component-props": "error",
|
|
4806
4932
|
"nextfriday/prefer-interface-over-inline-types": "error",
|
|
4807
4933
|
"nextfriday/prefer-jsx-template-literals": "error",
|