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.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "eslint-plugin-nextfriday",
|
|
4
|
-
version: "4.
|
|
4
|
+
version: "4.1.0",
|
|
5
5
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
6
6
|
keywords: [
|
|
7
7
|
"eslint",
|
|
@@ -2070,12 +2070,58 @@ var noEnvFallback = createRule27({
|
|
|
2070
2070
|
});
|
|
2071
2071
|
var no_env_fallback_default = noEnvFallback;
|
|
2072
2072
|
|
|
2073
|
-
// src/rules/no-
|
|
2073
|
+
// src/rules/no-ghost-wrapper.ts
|
|
2074
2074
|
import { AST_NODE_TYPES as AST_NODE_TYPES28, ESLintUtils as ESLintUtils28 } from "@typescript-eslint/utils";
|
|
2075
2075
|
var createRule28 = ESLintUtils28.RuleCreator(
|
|
2076
2076
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2077
2077
|
);
|
|
2078
|
-
var
|
|
2078
|
+
var GHOST_TAGS = /* @__PURE__ */ new Set(["div", "span"]);
|
|
2079
|
+
function isKeyAttribute(attribute) {
|
|
2080
|
+
return attribute.type === AST_NODE_TYPES28.JSXAttribute && attribute.name.type === AST_NODE_TYPES28.JSXIdentifier && attribute.name.name === "key";
|
|
2081
|
+
}
|
|
2082
|
+
var noGhostWrapper = createRule28({
|
|
2083
|
+
name: "no-ghost-wrapper",
|
|
2084
|
+
meta: {
|
|
2085
|
+
type: "problem",
|
|
2086
|
+
docs: {
|
|
2087
|
+
description: "Disallow bare <div> and <span> elements that have no meaningful attributes (Divitis / ghost wrappers)"
|
|
2088
|
+
},
|
|
2089
|
+
schema: [],
|
|
2090
|
+
messages: {
|
|
2091
|
+
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."
|
|
2092
|
+
}
|
|
2093
|
+
},
|
|
2094
|
+
defaultOptions: [],
|
|
2095
|
+
create(context) {
|
|
2096
|
+
return {
|
|
2097
|
+
JSXOpeningElement(node) {
|
|
2098
|
+
if (node.name.type !== AST_NODE_TYPES28.JSXIdentifier) {
|
|
2099
|
+
return;
|
|
2100
|
+
}
|
|
2101
|
+
const tagName = node.name.name;
|
|
2102
|
+
if (!GHOST_TAGS.has(tagName)) {
|
|
2103
|
+
return;
|
|
2104
|
+
}
|
|
2105
|
+
const meaningfulAttributes = node.attributes.filter((attribute) => !isKeyAttribute(attribute));
|
|
2106
|
+
if (meaningfulAttributes.length === 0) {
|
|
2107
|
+
context.report({
|
|
2108
|
+
node,
|
|
2109
|
+
messageId: "noGhostWrapper",
|
|
2110
|
+
data: { tag: tagName }
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
});
|
|
2117
|
+
var no_ghost_wrapper_default = noGhostWrapper;
|
|
2118
|
+
|
|
2119
|
+
// src/rules/no-inline-default-export.ts
|
|
2120
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29, ESLintUtils as ESLintUtils29 } from "@typescript-eslint/utils";
|
|
2121
|
+
var createRule29 = ESLintUtils29.RuleCreator(
|
|
2122
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2123
|
+
);
|
|
2124
|
+
var noInlineDefaultExport = createRule29({
|
|
2079
2125
|
name: "no-inline-default-export",
|
|
2080
2126
|
meta: {
|
|
2081
2127
|
type: "suggestion",
|
|
@@ -2094,7 +2140,7 @@ var noInlineDefaultExport = createRule28({
|
|
|
2094
2140
|
return {
|
|
2095
2141
|
ExportDefaultDeclaration(node) {
|
|
2096
2142
|
const { declaration } = node;
|
|
2097
|
-
if (declaration.type ===
|
|
2143
|
+
if (declaration.type === AST_NODE_TYPES29.FunctionDeclaration) {
|
|
2098
2144
|
if (declaration.id) {
|
|
2099
2145
|
context.report({
|
|
2100
2146
|
node,
|
|
@@ -2109,7 +2155,7 @@ var noInlineDefaultExport = createRule28({
|
|
|
2109
2155
|
});
|
|
2110
2156
|
}
|
|
2111
2157
|
}
|
|
2112
|
-
if (declaration.type ===
|
|
2158
|
+
if (declaration.type === AST_NODE_TYPES29.ClassDeclaration) {
|
|
2113
2159
|
if (declaration.id) {
|
|
2114
2160
|
context.report({
|
|
2115
2161
|
node,
|
|
@@ -2124,7 +2170,7 @@ var noInlineDefaultExport = createRule28({
|
|
|
2124
2170
|
});
|
|
2125
2171
|
}
|
|
2126
2172
|
}
|
|
2127
|
-
if (declaration.type ===
|
|
2173
|
+
if (declaration.type === AST_NODE_TYPES29.ArrowFunctionExpression || declaration.type === AST_NODE_TYPES29.FunctionExpression) {
|
|
2128
2174
|
context.report({
|
|
2129
2175
|
node,
|
|
2130
2176
|
messageId: "noAnonymousDefaultExport",
|
|
@@ -2137,14 +2183,14 @@ var noInlineDefaultExport = createRule28({
|
|
|
2137
2183
|
if (!declaration) {
|
|
2138
2184
|
return;
|
|
2139
2185
|
}
|
|
2140
|
-
if (declaration.type ===
|
|
2186
|
+
if (declaration.type === AST_NODE_TYPES29.FunctionDeclaration && declaration.id) {
|
|
2141
2187
|
context.report({
|
|
2142
2188
|
node,
|
|
2143
2189
|
messageId: "noInlineNamedExport",
|
|
2144
2190
|
data: { type: "function", name: declaration.id.name }
|
|
2145
2191
|
});
|
|
2146
2192
|
}
|
|
2147
|
-
if (declaration.type ===
|
|
2193
|
+
if (declaration.type === AST_NODE_TYPES29.ClassDeclaration && declaration.id) {
|
|
2148
2194
|
context.report({
|
|
2149
2195
|
node,
|
|
2150
2196
|
messageId: "noInlineNamedExport",
|
|
@@ -2158,27 +2204,27 @@ var noInlineDefaultExport = createRule28({
|
|
|
2158
2204
|
var no_inline_default_export_default = noInlineDefaultExport;
|
|
2159
2205
|
|
|
2160
2206
|
// src/rules/no-inline-nested-object.ts
|
|
2161
|
-
import { AST_NODE_TYPES as
|
|
2162
|
-
var
|
|
2207
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30, ESLintUtils as ESLintUtils30 } from "@typescript-eslint/utils";
|
|
2208
|
+
var createRule30 = ESLintUtils30.RuleCreator(
|
|
2163
2209
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2164
2210
|
);
|
|
2165
2211
|
function isObjectOrArray(node) {
|
|
2166
|
-
return node.type ===
|
|
2212
|
+
return node.type === AST_NODE_TYPES30.ObjectExpression || node.type === AST_NODE_TYPES30.ArrayExpression || node.type === AST_NODE_TYPES30.TSAsExpression;
|
|
2167
2213
|
}
|
|
2168
2214
|
function getInnerExpression(node) {
|
|
2169
|
-
if (node.type ===
|
|
2215
|
+
if (node.type === AST_NODE_TYPES30.TSAsExpression) {
|
|
2170
2216
|
return getInnerExpression(node.expression);
|
|
2171
2217
|
}
|
|
2172
2218
|
return node;
|
|
2173
2219
|
}
|
|
2174
2220
|
function isNestedStructure(node) {
|
|
2175
2221
|
const inner = getInnerExpression(node);
|
|
2176
|
-
return inner.type ===
|
|
2222
|
+
return inner.type === AST_NODE_TYPES30.ObjectExpression || inner.type === AST_NODE_TYPES30.ArrayExpression;
|
|
2177
2223
|
}
|
|
2178
2224
|
function containsNestedStructure(node) {
|
|
2179
|
-
if (node.type ===
|
|
2225
|
+
if (node.type === AST_NODE_TYPES30.ObjectExpression) {
|
|
2180
2226
|
return node.properties.some((prop) => {
|
|
2181
|
-
if (prop.type !==
|
|
2227
|
+
if (prop.type !== AST_NODE_TYPES30.Property) return false;
|
|
2182
2228
|
return isNestedStructure(prop.value);
|
|
2183
2229
|
});
|
|
2184
2230
|
}
|
|
@@ -2187,7 +2233,7 @@ function containsNestedStructure(node) {
|
|
|
2187
2233
|
return isNestedStructure(el);
|
|
2188
2234
|
});
|
|
2189
2235
|
}
|
|
2190
|
-
var noInlineNestedObject =
|
|
2236
|
+
var noInlineNestedObject = createRule30({
|
|
2191
2237
|
name: "no-inline-nested-object",
|
|
2192
2238
|
meta: {
|
|
2193
2239
|
type: "layout",
|
|
@@ -2209,7 +2255,7 @@ var noInlineNestedObject = createRule29({
|
|
|
2209
2255
|
return;
|
|
2210
2256
|
}
|
|
2211
2257
|
const valueNode = getInnerExpression(node.value);
|
|
2212
|
-
if (valueNode.type !==
|
|
2258
|
+
if (valueNode.type !== AST_NODE_TYPES30.ObjectExpression && valueNode.type !== AST_NODE_TYPES30.ArrayExpression) {
|
|
2213
2259
|
return;
|
|
2214
2260
|
}
|
|
2215
2261
|
if (!valueNode.loc) {
|
|
@@ -2222,7 +2268,7 @@ var noInlineNestedObject = createRule29({
|
|
|
2222
2268
|
if (!containsNestedStructure(valueNode)) {
|
|
2223
2269
|
return;
|
|
2224
2270
|
}
|
|
2225
|
-
const elements = valueNode.type ===
|
|
2271
|
+
const elements = valueNode.type === AST_NODE_TYPES30.ObjectExpression ? valueNode.properties : valueNode.elements;
|
|
2226
2272
|
context.report({
|
|
2227
2273
|
node: valueNode,
|
|
2228
2274
|
messageId: "requireMultiline",
|
|
@@ -2235,7 +2281,7 @@ var noInlineNestedObject = createRule29({
|
|
|
2235
2281
|
const indent = " ".repeat(node.loc?.start.column ?? 0);
|
|
2236
2282
|
const innerIndent = `${indent} `;
|
|
2237
2283
|
const elementTexts = elements.filter((el) => el !== null).map((el) => sourceCode.getText(el));
|
|
2238
|
-
const isObject = valueNode.type ===
|
|
2284
|
+
const isObject = valueNode.type === AST_NODE_TYPES30.ObjectExpression;
|
|
2239
2285
|
const openChar = isObject ? "{" : "[";
|
|
2240
2286
|
const closeChar = isObject ? "}" : "]";
|
|
2241
2287
|
const formattedElements = elementTexts.map((text) => `${innerIndent}${text},`).join("\n");
|
|
@@ -2252,20 +2298,20 @@ ${indent}${closeChar}`;
|
|
|
2252
2298
|
var no_inline_nested_object_default = noInlineNestedObject;
|
|
2253
2299
|
|
|
2254
2300
|
// src/rules/no-inline-return-properties.ts
|
|
2255
|
-
import { AST_NODE_TYPES as
|
|
2256
|
-
var
|
|
2301
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31, ESLintUtils as ESLintUtils31 } from "@typescript-eslint/utils";
|
|
2302
|
+
var createRule31 = ESLintUtils31.RuleCreator(
|
|
2257
2303
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2258
2304
|
);
|
|
2259
2305
|
var isShorthandProperty = (property) => {
|
|
2260
|
-
if (property.type ===
|
|
2306
|
+
if (property.type === AST_NODE_TYPES31.SpreadElement) {
|
|
2261
2307
|
return true;
|
|
2262
2308
|
}
|
|
2263
|
-
if (property.type !==
|
|
2309
|
+
if (property.type !== AST_NODE_TYPES31.Property) {
|
|
2264
2310
|
return false;
|
|
2265
2311
|
}
|
|
2266
2312
|
return property.shorthand;
|
|
2267
2313
|
};
|
|
2268
|
-
var noInlineReturnProperties =
|
|
2314
|
+
var noInlineReturnProperties = createRule31({
|
|
2269
2315
|
name: "no-inline-return-properties",
|
|
2270
2316
|
meta: {
|
|
2271
2317
|
type: "suggestion",
|
|
@@ -2281,20 +2327,20 @@ var noInlineReturnProperties = createRule30({
|
|
|
2281
2327
|
create(context) {
|
|
2282
2328
|
return {
|
|
2283
2329
|
ReturnStatement(node) {
|
|
2284
|
-
if (!node.argument || node.argument.type !==
|
|
2330
|
+
if (!node.argument || node.argument.type !== AST_NODE_TYPES31.ObjectExpression) {
|
|
2285
2331
|
return;
|
|
2286
2332
|
}
|
|
2287
2333
|
node.argument.properties.forEach((property) => {
|
|
2288
2334
|
if (isShorthandProperty(property)) {
|
|
2289
2335
|
return;
|
|
2290
2336
|
}
|
|
2291
|
-
if (property.type !==
|
|
2337
|
+
if (property.type !== AST_NODE_TYPES31.Property) {
|
|
2292
2338
|
return;
|
|
2293
2339
|
}
|
|
2294
2340
|
let keyName = null;
|
|
2295
|
-
if (property.key.type ===
|
|
2341
|
+
if (property.key.type === AST_NODE_TYPES31.Identifier) {
|
|
2296
2342
|
keyName = property.key.name;
|
|
2297
|
-
} else if (property.key.type ===
|
|
2343
|
+
} else if (property.key.type === AST_NODE_TYPES31.Literal) {
|
|
2298
2344
|
keyName = String(property.key.value);
|
|
2299
2345
|
}
|
|
2300
2346
|
context.report({
|
|
@@ -2310,12 +2356,12 @@ var noInlineReturnProperties = createRule30({
|
|
|
2310
2356
|
var no_inline_return_properties_default = noInlineReturnProperties;
|
|
2311
2357
|
|
|
2312
2358
|
// src/rules/no-inline-type-import.ts
|
|
2313
|
-
import { AST_NODE_TYPES as
|
|
2314
|
-
var
|
|
2359
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32, ESLintUtils as ESLintUtils32 } from "@typescript-eslint/utils";
|
|
2360
|
+
var createRule32 = ESLintUtils32.RuleCreator(
|
|
2315
2361
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2316
2362
|
);
|
|
2317
|
-
var isInlineTypeSpecifier = (specifier) => specifier.type ===
|
|
2318
|
-
var noInlineTypeImport =
|
|
2363
|
+
var isInlineTypeSpecifier = (specifier) => specifier.type === AST_NODE_TYPES32.ImportSpecifier && specifier.importKind === "type";
|
|
2364
|
+
var noInlineTypeImport = createRule32({
|
|
2319
2365
|
name: "no-inline-type-import",
|
|
2320
2366
|
meta: {
|
|
2321
2367
|
type: "suggestion",
|
|
@@ -2352,7 +2398,7 @@ var noInlineTypeImport = createRule31({
|
|
|
2352
2398
|
);
|
|
2353
2399
|
const typeImport = `import type { ${typeSpecifierTexts.join(", ")} } from ${sourceText};`;
|
|
2354
2400
|
const valueSpecifiers = node.specifiers.filter(
|
|
2355
|
-
(specifier) => !(specifier.type ===
|
|
2401
|
+
(specifier) => !(specifier.type === AST_NODE_TYPES32.ImportSpecifier && specifier.importKind === "type")
|
|
2356
2402
|
);
|
|
2357
2403
|
if (valueSpecifiers.length === 0) {
|
|
2358
2404
|
return fixer.replaceText(node, typeImport);
|
|
@@ -2360,11 +2406,11 @@ var noInlineTypeImport = createRule31({
|
|
|
2360
2406
|
const parts = [];
|
|
2361
2407
|
const namedValueSpecifiers = [];
|
|
2362
2408
|
for (const specifier of valueSpecifiers) {
|
|
2363
|
-
if (specifier.type ===
|
|
2409
|
+
if (specifier.type === AST_NODE_TYPES32.ImportDefaultSpecifier) {
|
|
2364
2410
|
parts.push(specifier.local.name);
|
|
2365
|
-
} else if (specifier.type ===
|
|
2411
|
+
} else if (specifier.type === AST_NODE_TYPES32.ImportNamespaceSpecifier) {
|
|
2366
2412
|
parts.push(`* as ${specifier.local.name}`);
|
|
2367
|
-
} else if (specifier.type ===
|
|
2413
|
+
} else if (specifier.type === AST_NODE_TYPES32.ImportSpecifier) {
|
|
2368
2414
|
namedValueSpecifiers.push(specifier);
|
|
2369
2415
|
}
|
|
2370
2416
|
}
|
|
@@ -2384,8 +2430,8 @@ ${typeImport}`);
|
|
|
2384
2430
|
var no_inline_type_import_default = noInlineTypeImport;
|
|
2385
2431
|
|
|
2386
2432
|
// src/rules/no-lazy-identifiers.ts
|
|
2387
|
-
import { AST_NODE_TYPES as
|
|
2388
|
-
var
|
|
2433
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33, ESLintUtils as ESLintUtils33 } from "@typescript-eslint/utils";
|
|
2434
|
+
var createRule33 = ESLintUtils33.RuleCreator(
|
|
2389
2435
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2390
2436
|
);
|
|
2391
2437
|
var KEYBOARD_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm", "1234567890"];
|
|
@@ -2426,7 +2472,7 @@ var isLazyIdentifier = (name) => {
|
|
|
2426
2472
|
}
|
|
2427
2473
|
return false;
|
|
2428
2474
|
};
|
|
2429
|
-
var noLazyIdentifiers =
|
|
2475
|
+
var noLazyIdentifiers = createRule33({
|
|
2430
2476
|
name: "no-lazy-identifiers",
|
|
2431
2477
|
meta: {
|
|
2432
2478
|
type: "problem",
|
|
@@ -2452,27 +2498,27 @@ var noLazyIdentifiers = createRule32({
|
|
|
2452
2498
|
});
|
|
2453
2499
|
};
|
|
2454
2500
|
const checkPattern = (pattern) => {
|
|
2455
|
-
if (pattern.type ===
|
|
2501
|
+
if (pattern.type === AST_NODE_TYPES33.Identifier) {
|
|
2456
2502
|
checkIdentifier(pattern);
|
|
2457
|
-
} else if (pattern.type ===
|
|
2503
|
+
} else if (pattern.type === AST_NODE_TYPES33.ObjectPattern) {
|
|
2458
2504
|
pattern.properties.forEach((prop) => {
|
|
2459
|
-
if (prop.type ===
|
|
2505
|
+
if (prop.type === AST_NODE_TYPES33.Property && prop.value.type === AST_NODE_TYPES33.Identifier) {
|
|
2460
2506
|
checkIdentifier(prop.value);
|
|
2461
|
-
} else if (prop.type ===
|
|
2507
|
+
} else if (prop.type === AST_NODE_TYPES33.RestElement && prop.argument.type === AST_NODE_TYPES33.Identifier) {
|
|
2462
2508
|
checkIdentifier(prop.argument);
|
|
2463
2509
|
}
|
|
2464
2510
|
});
|
|
2465
|
-
} else if (pattern.type ===
|
|
2511
|
+
} else if (pattern.type === AST_NODE_TYPES33.ArrayPattern) {
|
|
2466
2512
|
pattern.elements.forEach((element) => {
|
|
2467
|
-
if (element?.type ===
|
|
2513
|
+
if (element?.type === AST_NODE_TYPES33.Identifier) {
|
|
2468
2514
|
checkIdentifier(element);
|
|
2469
|
-
} else if (element?.type ===
|
|
2515
|
+
} else if (element?.type === AST_NODE_TYPES33.RestElement && element.argument.type === AST_NODE_TYPES33.Identifier) {
|
|
2470
2516
|
checkIdentifier(element.argument);
|
|
2471
2517
|
}
|
|
2472
2518
|
});
|
|
2473
|
-
} else if (pattern.type ===
|
|
2519
|
+
} else if (pattern.type === AST_NODE_TYPES33.AssignmentPattern && pattern.left.type === AST_NODE_TYPES33.Identifier) {
|
|
2474
2520
|
checkIdentifier(pattern.left);
|
|
2475
|
-
} else if (pattern.type ===
|
|
2521
|
+
} else if (pattern.type === AST_NODE_TYPES33.RestElement && pattern.argument.type === AST_NODE_TYPES33.Identifier) {
|
|
2476
2522
|
checkIdentifier(pattern.argument);
|
|
2477
2523
|
}
|
|
2478
2524
|
};
|
|
@@ -2517,11 +2563,11 @@ var noLazyIdentifiers = createRule32({
|
|
|
2517
2563
|
var no_lazy_identifiers_default = noLazyIdentifiers;
|
|
2518
2564
|
|
|
2519
2565
|
// src/rules/no-logic-in-params.ts
|
|
2520
|
-
import { AST_NODE_TYPES as
|
|
2521
|
-
var
|
|
2566
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34, ESLintUtils as ESLintUtils34 } from "@typescript-eslint/utils";
|
|
2567
|
+
var createRule34 = ESLintUtils34.RuleCreator(
|
|
2522
2568
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2523
2569
|
);
|
|
2524
|
-
var noLogicInParams =
|
|
2570
|
+
var noLogicInParams = createRule34({
|
|
2525
2571
|
name: "no-logic-in-params",
|
|
2526
2572
|
meta: {
|
|
2527
2573
|
type: "suggestion",
|
|
@@ -2536,20 +2582,20 @@ var noLogicInParams = createRule33({
|
|
|
2536
2582
|
defaultOptions: [],
|
|
2537
2583
|
create(context) {
|
|
2538
2584
|
const isComplexExpression = (node) => {
|
|
2539
|
-
if (node.type ===
|
|
2585
|
+
if (node.type === AST_NODE_TYPES34.SpreadElement) {
|
|
2540
2586
|
return false;
|
|
2541
2587
|
}
|
|
2542
|
-
if (node.type ===
|
|
2588
|
+
if (node.type === AST_NODE_TYPES34.ConditionalExpression) {
|
|
2543
2589
|
return true;
|
|
2544
2590
|
}
|
|
2545
|
-
if (node.type ===
|
|
2591
|
+
if (node.type === AST_NODE_TYPES34.LogicalExpression) {
|
|
2546
2592
|
return true;
|
|
2547
2593
|
}
|
|
2548
|
-
if (node.type ===
|
|
2594
|
+
if (node.type === AST_NODE_TYPES34.BinaryExpression) {
|
|
2549
2595
|
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
2550
2596
|
return logicalOperators.includes(node.operator);
|
|
2551
2597
|
}
|
|
2552
|
-
if (node.type ===
|
|
2598
|
+
if (node.type === AST_NODE_TYPES34.UnaryExpression) {
|
|
2553
2599
|
return node.operator === "!";
|
|
2554
2600
|
}
|
|
2555
2601
|
return false;
|
|
@@ -2562,7 +2608,7 @@ var noLogicInParams = createRule33({
|
|
|
2562
2608
|
messageId: "noLogicInParams"
|
|
2563
2609
|
});
|
|
2564
2610
|
}
|
|
2565
|
-
if (arg.type ===
|
|
2611
|
+
if (arg.type === AST_NODE_TYPES34.ArrayExpression) {
|
|
2566
2612
|
arg.elements.forEach((element) => {
|
|
2567
2613
|
if (element && isComplexExpression(element)) {
|
|
2568
2614
|
context.report({
|
|
@@ -2587,46 +2633,46 @@ var noLogicInParams = createRule33({
|
|
|
2587
2633
|
var no_logic_in_params_default = noLogicInParams;
|
|
2588
2634
|
|
|
2589
2635
|
// src/rules/no-misleading-constant-case.ts
|
|
2590
|
-
import { AST_NODE_TYPES as
|
|
2591
|
-
var
|
|
2636
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35, ESLintUtils as ESLintUtils35 } from "@typescript-eslint/utils";
|
|
2637
|
+
var createRule35 = ESLintUtils35.RuleCreator(
|
|
2592
2638
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2593
2639
|
);
|
|
2594
2640
|
var SCREAMING_SNAKE_CASE_REGEX3 = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
2595
|
-
var isAsConstAssertion = (node) => node.type ===
|
|
2641
|
+
var isAsConstAssertion = (node) => node.type === AST_NODE_TYPES35.TSAsExpression && node.typeAnnotation.type === AST_NODE_TYPES35.TSTypeReference && node.typeAnnotation.typeName.type === AST_NODE_TYPES35.Identifier && node.typeAnnotation.typeName.name === "const";
|
|
2596
2642
|
var isStaticValue2 = (init) => {
|
|
2597
2643
|
if (isAsConstAssertion(init)) {
|
|
2598
2644
|
return true;
|
|
2599
2645
|
}
|
|
2600
|
-
if (init.type ===
|
|
2646
|
+
if (init.type === AST_NODE_TYPES35.Literal) {
|
|
2601
2647
|
return true;
|
|
2602
2648
|
}
|
|
2603
|
-
if (init.type ===
|
|
2649
|
+
if (init.type === AST_NODE_TYPES35.UnaryExpression && init.argument.type === AST_NODE_TYPES35.Literal) {
|
|
2604
2650
|
return true;
|
|
2605
2651
|
}
|
|
2606
|
-
if (init.type ===
|
|
2652
|
+
if (init.type === AST_NODE_TYPES35.TemplateLiteral && init.expressions.length === 0) {
|
|
2607
2653
|
return true;
|
|
2608
2654
|
}
|
|
2609
|
-
if (init.type ===
|
|
2610
|
-
return init.elements.every((el) => el !== null && el.type !==
|
|
2655
|
+
if (init.type === AST_NODE_TYPES35.ArrayExpression) {
|
|
2656
|
+
return init.elements.every((el) => el !== null && el.type !== AST_NODE_TYPES35.SpreadElement && isStaticValue2(el));
|
|
2611
2657
|
}
|
|
2612
|
-
if (init.type ===
|
|
2658
|
+
if (init.type === AST_NODE_TYPES35.ObjectExpression) {
|
|
2613
2659
|
return init.properties.every(
|
|
2614
|
-
(prop) => prop.type ===
|
|
2660
|
+
(prop) => prop.type === AST_NODE_TYPES35.Property && isStaticValue2(prop.value)
|
|
2615
2661
|
);
|
|
2616
2662
|
}
|
|
2617
2663
|
return false;
|
|
2618
2664
|
};
|
|
2619
2665
|
var isGlobalScope3 = (node) => {
|
|
2620
2666
|
const { parent } = node;
|
|
2621
|
-
if (parent.type ===
|
|
2667
|
+
if (parent.type === AST_NODE_TYPES35.Program) {
|
|
2622
2668
|
return true;
|
|
2623
2669
|
}
|
|
2624
|
-
if (parent.type ===
|
|
2670
|
+
if (parent.type === AST_NODE_TYPES35.ExportNamedDeclaration && parent.parent?.type === AST_NODE_TYPES35.Program) {
|
|
2625
2671
|
return true;
|
|
2626
2672
|
}
|
|
2627
2673
|
return false;
|
|
2628
2674
|
};
|
|
2629
|
-
var noMisleadingConstantCase =
|
|
2675
|
+
var noMisleadingConstantCase = createRule35({
|
|
2630
2676
|
name: "no-misleading-constant-case",
|
|
2631
2677
|
meta: {
|
|
2632
2678
|
type: "suggestion",
|
|
@@ -2645,7 +2691,7 @@ var noMisleadingConstantCase = createRule34({
|
|
|
2645
2691
|
return {
|
|
2646
2692
|
VariableDeclaration(node) {
|
|
2647
2693
|
node.declarations.forEach((declarator) => {
|
|
2648
|
-
if (declarator.id.type !==
|
|
2694
|
+
if (declarator.id.type !== AST_NODE_TYPES35.Identifier) {
|
|
2649
2695
|
return;
|
|
2650
2696
|
}
|
|
2651
2697
|
const { name } = declarator.id;
|
|
@@ -2686,11 +2732,11 @@ var noMisleadingConstantCase = createRule34({
|
|
|
2686
2732
|
var no_misleading_constant_case_default = noMisleadingConstantCase;
|
|
2687
2733
|
|
|
2688
2734
|
// src/rules/no-nested-interface-declaration.ts
|
|
2689
|
-
import { AST_NODE_TYPES as
|
|
2690
|
-
var
|
|
2735
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36, ESLintUtils as ESLintUtils36 } from "@typescript-eslint/utils";
|
|
2736
|
+
var createRule36 = ESLintUtils36.RuleCreator(
|
|
2691
2737
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2692
2738
|
);
|
|
2693
|
-
var noNestedInterfaceDeclaration =
|
|
2739
|
+
var noNestedInterfaceDeclaration = createRule36({
|
|
2694
2740
|
name: "no-nested-interface-declaration",
|
|
2695
2741
|
meta: {
|
|
2696
2742
|
type: "suggestion",
|
|
@@ -2711,15 +2757,15 @@ var noNestedInterfaceDeclaration = createRule35({
|
|
|
2711
2757
|
return;
|
|
2712
2758
|
}
|
|
2713
2759
|
const { typeAnnotation } = node.typeAnnotation;
|
|
2714
|
-
if (typeAnnotation.type ===
|
|
2760
|
+
if (typeAnnotation.type === AST_NODE_TYPES36.TSTypeLiteral) {
|
|
2715
2761
|
context.report({
|
|
2716
2762
|
node: typeAnnotation,
|
|
2717
2763
|
messageId: "noNestedInterface"
|
|
2718
2764
|
});
|
|
2719
2765
|
return;
|
|
2720
2766
|
}
|
|
2721
|
-
if (typeAnnotation.type ===
|
|
2722
|
-
if (typeAnnotation.elementType.type ===
|
|
2767
|
+
if (typeAnnotation.type === AST_NODE_TYPES36.TSArrayType) {
|
|
2768
|
+
if (typeAnnotation.elementType.type === AST_NODE_TYPES36.TSTypeLiteral) {
|
|
2723
2769
|
context.report({
|
|
2724
2770
|
node: typeAnnotation.elementType,
|
|
2725
2771
|
messageId: "noNestedInterface"
|
|
@@ -2727,9 +2773,9 @@ var noNestedInterfaceDeclaration = createRule35({
|
|
|
2727
2773
|
}
|
|
2728
2774
|
return;
|
|
2729
2775
|
}
|
|
2730
|
-
if (typeAnnotation.type ===
|
|
2776
|
+
if (typeAnnotation.type === AST_NODE_TYPES36.TSTypeReference && typeAnnotation.typeArguments) {
|
|
2731
2777
|
typeAnnotation.typeArguments.params.forEach((param) => {
|
|
2732
|
-
if (param.type ===
|
|
2778
|
+
if (param.type === AST_NODE_TYPES36.TSTypeLiteral) {
|
|
2733
2779
|
context.report({
|
|
2734
2780
|
node: param,
|
|
2735
2781
|
messageId: "noNestedInterface"
|
|
@@ -2744,11 +2790,11 @@ var noNestedInterfaceDeclaration = createRule35({
|
|
|
2744
2790
|
var no_nested_interface_declaration_default = noNestedInterfaceDeclaration;
|
|
2745
2791
|
|
|
2746
2792
|
// src/rules/no-nested-ternary.ts
|
|
2747
|
-
import { AST_NODE_TYPES as
|
|
2748
|
-
var
|
|
2793
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37, ESLintUtils as ESLintUtils37 } from "@typescript-eslint/utils";
|
|
2794
|
+
var createRule37 = ESLintUtils37.RuleCreator(
|
|
2749
2795
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2750
2796
|
);
|
|
2751
|
-
var noNestedTernary =
|
|
2797
|
+
var noNestedTernary = createRule37({
|
|
2752
2798
|
name: "no-nested-ternary",
|
|
2753
2799
|
meta: {
|
|
2754
2800
|
type: "suggestion",
|
|
@@ -2765,13 +2811,13 @@ var noNestedTernary = createRule36({
|
|
|
2765
2811
|
return {
|
|
2766
2812
|
ConditionalExpression(node) {
|
|
2767
2813
|
const { consequent, alternate } = node;
|
|
2768
|
-
if (consequent.type ===
|
|
2814
|
+
if (consequent.type === AST_NODE_TYPES37.ConditionalExpression) {
|
|
2769
2815
|
context.report({
|
|
2770
2816
|
node: consequent,
|
|
2771
2817
|
messageId: "noNestedTernary"
|
|
2772
2818
|
});
|
|
2773
2819
|
}
|
|
2774
|
-
if (alternate.type ===
|
|
2820
|
+
if (alternate.type === AST_NODE_TYPES37.ConditionalExpression) {
|
|
2775
2821
|
context.report({
|
|
2776
2822
|
node: alternate,
|
|
2777
2823
|
messageId: "noNestedTernary"
|
|
@@ -2783,12 +2829,86 @@ var noNestedTernary = createRule36({
|
|
|
2783
2829
|
});
|
|
2784
2830
|
var no_nested_ternary_default = noNestedTernary;
|
|
2785
2831
|
|
|
2832
|
+
// src/rules/no-redundant-fragment.ts
|
|
2833
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38, ESLintUtils as ESLintUtils38 } from "@typescript-eslint/utils";
|
|
2834
|
+
var createRule38 = ESLintUtils38.RuleCreator(
|
|
2835
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2836
|
+
);
|
|
2837
|
+
function isFragmentName(name) {
|
|
2838
|
+
if (name.type === AST_NODE_TYPES38.JSXIdentifier && name.name === "Fragment") {
|
|
2839
|
+
return true;
|
|
2840
|
+
}
|
|
2841
|
+
if (name.type === AST_NODE_TYPES38.JSXMemberExpression && name.object.type === AST_NODE_TYPES38.JSXIdentifier && name.object.name === "React" && name.property.type === AST_NODE_TYPES38.JSXIdentifier && name.property.name === "Fragment") {
|
|
2842
|
+
return true;
|
|
2843
|
+
}
|
|
2844
|
+
return false;
|
|
2845
|
+
}
|
|
2846
|
+
function hasKeyAttribute(attributes) {
|
|
2847
|
+
return attributes.some(
|
|
2848
|
+
(attribute) => attribute.type === AST_NODE_TYPES38.JSXAttribute && attribute.name.type === AST_NODE_TYPES38.JSXIdentifier && attribute.name.name === "key"
|
|
2849
|
+
);
|
|
2850
|
+
}
|
|
2851
|
+
function countMeaningfulChildren(children) {
|
|
2852
|
+
return children.filter((child) => {
|
|
2853
|
+
if (child.type === AST_NODE_TYPES38.JSXText) {
|
|
2854
|
+
return child.value.trim() !== "";
|
|
2855
|
+
}
|
|
2856
|
+
return true;
|
|
2857
|
+
}).length;
|
|
2858
|
+
}
|
|
2859
|
+
var noRedundantFragment = createRule38({
|
|
2860
|
+
name: "no-redundant-fragment",
|
|
2861
|
+
meta: {
|
|
2862
|
+
type: "problem",
|
|
2863
|
+
docs: {
|
|
2864
|
+
description: "Disallow Fragments that wrap zero or one child (unless a key prop is needed)"
|
|
2865
|
+
},
|
|
2866
|
+
schema: [],
|
|
2867
|
+
messages: {
|
|
2868
|
+
redundantFragment: "Fragment is redundant when wrapping {{ count }} child. Remove the Fragment or replace it with the child directly."
|
|
2869
|
+
}
|
|
2870
|
+
},
|
|
2871
|
+
defaultOptions: [],
|
|
2872
|
+
create(context) {
|
|
2873
|
+
return {
|
|
2874
|
+
JSXFragment(node) {
|
|
2875
|
+
const count = countMeaningfulChildren(node.children);
|
|
2876
|
+
if (count <= 1) {
|
|
2877
|
+
context.report({
|
|
2878
|
+
node,
|
|
2879
|
+
messageId: "redundantFragment",
|
|
2880
|
+
data: { count: String(count) }
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2883
|
+
},
|
|
2884
|
+
JSXElement(node) {
|
|
2885
|
+
const opening = node.openingElement;
|
|
2886
|
+
if (!isFragmentName(opening.name)) {
|
|
2887
|
+
return;
|
|
2888
|
+
}
|
|
2889
|
+
if (hasKeyAttribute(opening.attributes)) {
|
|
2890
|
+
return;
|
|
2891
|
+
}
|
|
2892
|
+
const count = countMeaningfulChildren(node.children);
|
|
2893
|
+
if (count <= 1) {
|
|
2894
|
+
context.report({
|
|
2895
|
+
node,
|
|
2896
|
+
messageId: "redundantFragment",
|
|
2897
|
+
data: { count: String(count) }
|
|
2898
|
+
});
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
};
|
|
2902
|
+
}
|
|
2903
|
+
});
|
|
2904
|
+
var no_redundant_fragment_default = noRedundantFragment;
|
|
2905
|
+
|
|
2786
2906
|
// src/rules/no-relative-imports.ts
|
|
2787
|
-
import { AST_NODE_TYPES as
|
|
2788
|
-
var
|
|
2907
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39, ESLintUtils as ESLintUtils39 } from "@typescript-eslint/utils";
|
|
2908
|
+
var createRule39 = ESLintUtils39.RuleCreator(
|
|
2789
2909
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2790
2910
|
);
|
|
2791
|
-
var noRelativeImports =
|
|
2911
|
+
var noRelativeImports = createRule39({
|
|
2792
2912
|
name: "no-relative-imports",
|
|
2793
2913
|
meta: {
|
|
2794
2914
|
type: "suggestion",
|
|
@@ -2812,22 +2932,22 @@ var noRelativeImports = createRule37({
|
|
|
2812
2932
|
};
|
|
2813
2933
|
return {
|
|
2814
2934
|
ImportDeclaration(node) {
|
|
2815
|
-
if (node.source.type ===
|
|
2935
|
+
if (node.source.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2816
2936
|
checkImportPath(node.source.value, node);
|
|
2817
2937
|
}
|
|
2818
2938
|
},
|
|
2819
2939
|
ImportExpression(node) {
|
|
2820
|
-
if (node.source.type ===
|
|
2940
|
+
if (node.source.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2821
2941
|
checkImportPath(node.source.value, node);
|
|
2822
2942
|
}
|
|
2823
2943
|
},
|
|
2824
2944
|
ExportNamedDeclaration(node) {
|
|
2825
|
-
if (node.source?.type ===
|
|
2945
|
+
if (node.source?.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2826
2946
|
checkImportPath(node.source.value, node);
|
|
2827
2947
|
}
|
|
2828
2948
|
},
|
|
2829
2949
|
ExportAllDeclaration(node) {
|
|
2830
|
-
if (node.source.type ===
|
|
2950
|
+
if (node.source.type === AST_NODE_TYPES39.Literal && typeof node.source.value === "string") {
|
|
2831
2951
|
checkImportPath(node.source.value, node);
|
|
2832
2952
|
}
|
|
2833
2953
|
}
|
|
@@ -2837,8 +2957,8 @@ var noRelativeImports = createRule37({
|
|
|
2837
2957
|
var no_relative_imports_default = noRelativeImports;
|
|
2838
2958
|
|
|
2839
2959
|
// src/rules/no-single-char-variables.ts
|
|
2840
|
-
import { AST_NODE_TYPES as
|
|
2841
|
-
var
|
|
2960
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40, ESLintUtils as ESLintUtils40 } from "@typescript-eslint/utils";
|
|
2961
|
+
var createRule40 = ESLintUtils40.RuleCreator(
|
|
2842
2962
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2843
2963
|
);
|
|
2844
2964
|
var ALLOWED_IN_FOR_LOOPS = /* @__PURE__ */ new Set(["i", "j", "k", "n"]);
|
|
@@ -2850,7 +2970,7 @@ var isForLoopInit = (node) => {
|
|
|
2850
2970
|
if (!parentNode) {
|
|
2851
2971
|
return false;
|
|
2852
2972
|
}
|
|
2853
|
-
if (parentNode.type ===
|
|
2973
|
+
if (parentNode.type === AST_NODE_TYPES40.ForStatement) {
|
|
2854
2974
|
const { init } = parentNode;
|
|
2855
2975
|
if (init && init === current) {
|
|
2856
2976
|
return true;
|
|
@@ -2869,7 +2989,7 @@ var isAllowedInContext = (name, node) => {
|
|
|
2869
2989
|
}
|
|
2870
2990
|
return false;
|
|
2871
2991
|
};
|
|
2872
|
-
var noSingleCharVariables =
|
|
2992
|
+
var noSingleCharVariables = createRule40({
|
|
2873
2993
|
name: "no-single-char-variables",
|
|
2874
2994
|
meta: {
|
|
2875
2995
|
type: "suggestion",
|
|
@@ -2898,27 +3018,27 @@ var noSingleCharVariables = createRule38({
|
|
|
2898
3018
|
});
|
|
2899
3019
|
};
|
|
2900
3020
|
const checkPattern = (pattern, declarationNode) => {
|
|
2901
|
-
if (pattern.type ===
|
|
3021
|
+
if (pattern.type === AST_NODE_TYPES40.Identifier) {
|
|
2902
3022
|
checkIdentifier(pattern, declarationNode);
|
|
2903
|
-
} else if (pattern.type ===
|
|
3023
|
+
} else if (pattern.type === AST_NODE_TYPES40.ObjectPattern) {
|
|
2904
3024
|
pattern.properties.forEach((prop) => {
|
|
2905
|
-
if (prop.type ===
|
|
3025
|
+
if (prop.type === AST_NODE_TYPES40.Property && prop.value.type === AST_NODE_TYPES40.Identifier) {
|
|
2906
3026
|
checkIdentifier(prop.value, declarationNode);
|
|
2907
|
-
} else if (prop.type ===
|
|
3027
|
+
} else if (prop.type === AST_NODE_TYPES40.RestElement && prop.argument.type === AST_NODE_TYPES40.Identifier) {
|
|
2908
3028
|
checkIdentifier(prop.argument, declarationNode);
|
|
2909
3029
|
}
|
|
2910
3030
|
});
|
|
2911
|
-
} else if (pattern.type ===
|
|
3031
|
+
} else if (pattern.type === AST_NODE_TYPES40.ArrayPattern) {
|
|
2912
3032
|
pattern.elements.forEach((element) => {
|
|
2913
|
-
if (element?.type ===
|
|
3033
|
+
if (element?.type === AST_NODE_TYPES40.Identifier) {
|
|
2914
3034
|
checkIdentifier(element, declarationNode);
|
|
2915
|
-
} else if (element?.type ===
|
|
3035
|
+
} else if (element?.type === AST_NODE_TYPES40.RestElement && element.argument.type === AST_NODE_TYPES40.Identifier) {
|
|
2916
3036
|
checkIdentifier(element.argument, declarationNode);
|
|
2917
3037
|
}
|
|
2918
3038
|
});
|
|
2919
|
-
} else if (pattern.type ===
|
|
3039
|
+
} else if (pattern.type === AST_NODE_TYPES40.AssignmentPattern && pattern.left.type === AST_NODE_TYPES40.Identifier) {
|
|
2920
3040
|
checkIdentifier(pattern.left, declarationNode);
|
|
2921
|
-
} else if (pattern.type ===
|
|
3041
|
+
} else if (pattern.type === AST_NODE_TYPES40.RestElement && pattern.argument.type === AST_NODE_TYPES40.Identifier) {
|
|
2922
3042
|
checkIdentifier(pattern.argument, declarationNode);
|
|
2923
3043
|
}
|
|
2924
3044
|
};
|
|
@@ -2952,11 +3072,11 @@ var noSingleCharVariables = createRule38({
|
|
|
2952
3072
|
var no_single_char_variables_default = noSingleCharVariables;
|
|
2953
3073
|
|
|
2954
3074
|
// src/rules/prefer-async-await.ts
|
|
2955
|
-
import { AST_NODE_TYPES as
|
|
2956
|
-
var
|
|
3075
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41, ESLintUtils as ESLintUtils41 } from "@typescript-eslint/utils";
|
|
3076
|
+
var createRule41 = ESLintUtils41.RuleCreator(
|
|
2957
3077
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2958
3078
|
);
|
|
2959
|
-
var preferAsyncAwait =
|
|
3079
|
+
var preferAsyncAwait = createRule41({
|
|
2960
3080
|
name: "prefer-async-await",
|
|
2961
3081
|
meta: {
|
|
2962
3082
|
type: "suggestion",
|
|
@@ -2972,7 +3092,7 @@ var preferAsyncAwait = createRule39({
|
|
|
2972
3092
|
create(context) {
|
|
2973
3093
|
return {
|
|
2974
3094
|
CallExpression(node) {
|
|
2975
|
-
if (node.callee.type ===
|
|
3095
|
+
if (node.callee.type === AST_NODE_TYPES41.MemberExpression && node.callee.property.type === AST_NODE_TYPES41.Identifier && node.callee.property.name === "then") {
|
|
2976
3096
|
context.report({
|
|
2977
3097
|
node: node.callee.property,
|
|
2978
3098
|
messageId: "preferAsyncAwait"
|
|
@@ -2985,11 +3105,11 @@ var preferAsyncAwait = createRule39({
|
|
|
2985
3105
|
var prefer_async_await_default = preferAsyncAwait;
|
|
2986
3106
|
|
|
2987
3107
|
// src/rules/prefer-destructuring-params.ts
|
|
2988
|
-
import { AST_NODE_TYPES as
|
|
2989
|
-
var
|
|
3108
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42, ESLintUtils as ESLintUtils42 } from "@typescript-eslint/utils";
|
|
3109
|
+
var createRule42 = ESLintUtils42.RuleCreator(
|
|
2990
3110
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2991
3111
|
);
|
|
2992
|
-
var preferDestructuringParams =
|
|
3112
|
+
var preferDestructuringParams = createRule42({
|
|
2993
3113
|
name: "prefer-destructuring-params",
|
|
2994
3114
|
meta: {
|
|
2995
3115
|
type: "suggestion",
|
|
@@ -3005,18 +3125,18 @@ var preferDestructuringParams = createRule40({
|
|
|
3005
3125
|
create(context) {
|
|
3006
3126
|
const isCallbackFunction2 = (node) => {
|
|
3007
3127
|
const { parent } = node;
|
|
3008
|
-
return parent?.type ===
|
|
3128
|
+
return parent?.type === AST_NODE_TYPES42.CallExpression;
|
|
3009
3129
|
};
|
|
3010
3130
|
const isDeveloperFunction = (node) => {
|
|
3011
|
-
if (node.type ===
|
|
3131
|
+
if (node.type === AST_NODE_TYPES42.FunctionDeclaration) {
|
|
3012
3132
|
return true;
|
|
3013
3133
|
}
|
|
3014
|
-
if (node.type ===
|
|
3134
|
+
if (node.type === AST_NODE_TYPES42.FunctionExpression || node.type === AST_NODE_TYPES42.ArrowFunctionExpression) {
|
|
3015
3135
|
if (isCallbackFunction2(node)) {
|
|
3016
3136
|
return false;
|
|
3017
3137
|
}
|
|
3018
3138
|
const { parent } = node;
|
|
3019
|
-
return parent?.type ===
|
|
3139
|
+
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;
|
|
3020
3140
|
}
|
|
3021
3141
|
return false;
|
|
3022
3142
|
};
|
|
@@ -3028,7 +3148,7 @@ var preferDestructuringParams = createRule40({
|
|
|
3028
3148
|
if (!isDeveloperFunction(node)) {
|
|
3029
3149
|
return;
|
|
3030
3150
|
}
|
|
3031
|
-
if (node.type ===
|
|
3151
|
+
if (node.type === AST_NODE_TYPES42.FunctionDeclaration && node.id) {
|
|
3032
3152
|
const functionName = node.id.name;
|
|
3033
3153
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
3034
3154
|
return;
|
|
@@ -3038,7 +3158,7 @@ var preferDestructuringParams = createRule40({
|
|
|
3038
3158
|
return;
|
|
3039
3159
|
}
|
|
3040
3160
|
const hasNonDestructuredParams = node.params.some(
|
|
3041
|
-
(param) => param.type !==
|
|
3161
|
+
(param) => param.type !== AST_NODE_TYPES42.ObjectPattern && param.type !== AST_NODE_TYPES42.RestElement
|
|
3042
3162
|
);
|
|
3043
3163
|
if (hasNonDestructuredParams) {
|
|
3044
3164
|
context.report({
|
|
@@ -3057,8 +3177,8 @@ var preferDestructuringParams = createRule40({
|
|
|
3057
3177
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
3058
3178
|
|
|
3059
3179
|
// src/rules/prefer-function-declaration.ts
|
|
3060
|
-
import { AST_NODE_TYPES as
|
|
3061
|
-
var
|
|
3180
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43, ESLintUtils as ESLintUtils43 } from "@typescript-eslint/utils";
|
|
3181
|
+
var createRule43 = ESLintUtils43.RuleCreator(
|
|
3062
3182
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3063
3183
|
);
|
|
3064
3184
|
var isTsFile = (filename) => filename.endsWith(".ts") && !filename.endsWith(".d.ts");
|
|
@@ -3067,33 +3187,33 @@ var isCallbackContext = (node) => {
|
|
|
3067
3187
|
if (!parent) {
|
|
3068
3188
|
return false;
|
|
3069
3189
|
}
|
|
3070
|
-
if (parent.type ===
|
|
3190
|
+
if (parent.type === AST_NODE_TYPES43.CallExpression && parent.arguments.includes(node)) {
|
|
3071
3191
|
return true;
|
|
3072
3192
|
}
|
|
3073
|
-
if (parent.type ===
|
|
3193
|
+
if (parent.type === AST_NODE_TYPES43.NewExpression && parent.arguments.includes(node)) {
|
|
3074
3194
|
return true;
|
|
3075
3195
|
}
|
|
3076
|
-
if (parent.type ===
|
|
3196
|
+
if (parent.type === AST_NODE_TYPES43.ReturnStatement) {
|
|
3077
3197
|
return true;
|
|
3078
3198
|
}
|
|
3079
|
-
if (parent.type ===
|
|
3199
|
+
if (parent.type === AST_NODE_TYPES43.Property) {
|
|
3080
3200
|
return true;
|
|
3081
3201
|
}
|
|
3082
|
-
if (parent.type ===
|
|
3202
|
+
if (parent.type === AST_NODE_TYPES43.ArrayExpression) {
|
|
3083
3203
|
return true;
|
|
3084
3204
|
}
|
|
3085
|
-
if (parent.type ===
|
|
3205
|
+
if (parent.type === AST_NODE_TYPES43.ConditionalExpression) {
|
|
3086
3206
|
return true;
|
|
3087
3207
|
}
|
|
3088
|
-
if (parent.type ===
|
|
3208
|
+
if (parent.type === AST_NODE_TYPES43.LogicalExpression) {
|
|
3089
3209
|
return true;
|
|
3090
3210
|
}
|
|
3091
|
-
if (parent.type ===
|
|
3211
|
+
if (parent.type === AST_NODE_TYPES43.AssignmentExpression && parent.left !== node) {
|
|
3092
3212
|
return true;
|
|
3093
3213
|
}
|
|
3094
3214
|
return false;
|
|
3095
3215
|
};
|
|
3096
|
-
var preferFunctionDeclaration =
|
|
3216
|
+
var preferFunctionDeclaration = createRule43({
|
|
3097
3217
|
name: "prefer-function-declaration",
|
|
3098
3218
|
meta: {
|
|
3099
3219
|
type: "suggestion",
|
|
@@ -3114,14 +3234,14 @@ var preferFunctionDeclaration = createRule41({
|
|
|
3114
3234
|
}
|
|
3115
3235
|
return {
|
|
3116
3236
|
VariableDeclarator(node) {
|
|
3117
|
-
if (node.id.type !==
|
|
3237
|
+
if (node.id.type !== AST_NODE_TYPES43.Identifier) {
|
|
3118
3238
|
return;
|
|
3119
3239
|
}
|
|
3120
3240
|
const { init } = node;
|
|
3121
3241
|
if (!init) {
|
|
3122
3242
|
return;
|
|
3123
3243
|
}
|
|
3124
|
-
if (init.type ===
|
|
3244
|
+
if (init.type === AST_NODE_TYPES43.ArrowFunctionExpression) {
|
|
3125
3245
|
if (isCallbackContext(init)) {
|
|
3126
3246
|
return;
|
|
3127
3247
|
}
|
|
@@ -3131,7 +3251,7 @@ var preferFunctionDeclaration = createRule41({
|
|
|
3131
3251
|
data: { name: node.id.name }
|
|
3132
3252
|
});
|
|
3133
3253
|
}
|
|
3134
|
-
if (init.type ===
|
|
3254
|
+
if (init.type === AST_NODE_TYPES43.FunctionExpression) {
|
|
3135
3255
|
if (isCallbackContext(init)) {
|
|
3136
3256
|
return;
|
|
3137
3257
|
}
|
|
@@ -3148,11 +3268,11 @@ var preferFunctionDeclaration = createRule41({
|
|
|
3148
3268
|
var prefer_function_declaration_default = preferFunctionDeclaration;
|
|
3149
3269
|
|
|
3150
3270
|
// src/rules/prefer-guard-clause.ts
|
|
3151
|
-
import { AST_NODE_TYPES as
|
|
3152
|
-
var
|
|
3271
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44, ESLintUtils as ESLintUtils44 } from "@typescript-eslint/utils";
|
|
3272
|
+
var createRule44 = ESLintUtils44.RuleCreator(
|
|
3153
3273
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3154
3274
|
);
|
|
3155
|
-
var preferGuardClause =
|
|
3275
|
+
var preferGuardClause = createRule44({
|
|
3156
3276
|
name: "prefer-guard-clause",
|
|
3157
3277
|
meta: {
|
|
3158
3278
|
type: "suggestion",
|
|
@@ -3169,8 +3289,8 @@ var preferGuardClause = createRule42({
|
|
|
3169
3289
|
return {
|
|
3170
3290
|
IfStatement(node) {
|
|
3171
3291
|
const { consequent } = node;
|
|
3172
|
-
if (consequent.type ===
|
|
3173
|
-
const hasNestedIf = consequent.body.some((statement) => statement.type ===
|
|
3292
|
+
if (consequent.type === AST_NODE_TYPES44.BlockStatement) {
|
|
3293
|
+
const hasNestedIf = consequent.body.some((statement) => statement.type === AST_NODE_TYPES44.IfStatement);
|
|
3174
3294
|
if (hasNestedIf && consequent.body.length === 1) {
|
|
3175
3295
|
context.report({
|
|
3176
3296
|
node,
|
|
@@ -3178,7 +3298,7 @@ var preferGuardClause = createRule42({
|
|
|
3178
3298
|
});
|
|
3179
3299
|
}
|
|
3180
3300
|
}
|
|
3181
|
-
if (consequent.type ===
|
|
3301
|
+
if (consequent.type === AST_NODE_TYPES44.IfStatement) {
|
|
3182
3302
|
context.report({
|
|
3183
3303
|
node,
|
|
3184
3304
|
messageId: "preferGuardClause"
|
|
@@ -3191,11 +3311,11 @@ var preferGuardClause = createRule42({
|
|
|
3191
3311
|
var prefer_guard_clause_default = preferGuardClause;
|
|
3192
3312
|
|
|
3193
3313
|
// src/rules/prefer-import-type.ts
|
|
3194
|
-
import { AST_NODE_TYPES as
|
|
3195
|
-
var
|
|
3314
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45, ESLintUtils as ESLintUtils45 } from "@typescript-eslint/utils";
|
|
3315
|
+
var createRule45 = ESLintUtils45.RuleCreator(
|
|
3196
3316
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3197
3317
|
);
|
|
3198
|
-
var preferImportType =
|
|
3318
|
+
var preferImportType = createRule45({
|
|
3199
3319
|
name: "prefer-import-type",
|
|
3200
3320
|
meta: {
|
|
3201
3321
|
type: "suggestion",
|
|
@@ -3214,22 +3334,22 @@ var preferImportType = createRule43({
|
|
|
3214
3334
|
let current = node;
|
|
3215
3335
|
while (current) {
|
|
3216
3336
|
switch (current.type) {
|
|
3217
|
-
case
|
|
3218
|
-
case
|
|
3219
|
-
case
|
|
3220
|
-
case
|
|
3221
|
-
case
|
|
3222
|
-
case
|
|
3223
|
-
case
|
|
3224
|
-
case
|
|
3225
|
-
case
|
|
3226
|
-
case
|
|
3227
|
-
case
|
|
3228
|
-
case
|
|
3229
|
-
case
|
|
3337
|
+
case AST_NODE_TYPES45.TSTypeReference:
|
|
3338
|
+
case AST_NODE_TYPES45.TSTypeAnnotation:
|
|
3339
|
+
case AST_NODE_TYPES45.TSTypeParameterInstantiation:
|
|
3340
|
+
case AST_NODE_TYPES45.TSInterfaceHeritage:
|
|
3341
|
+
case AST_NODE_TYPES45.TSClassImplements:
|
|
3342
|
+
case AST_NODE_TYPES45.TSTypeQuery:
|
|
3343
|
+
case AST_NODE_TYPES45.TSTypeAssertion:
|
|
3344
|
+
case AST_NODE_TYPES45.TSAsExpression:
|
|
3345
|
+
case AST_NODE_TYPES45.TSSatisfiesExpression:
|
|
3346
|
+
case AST_NODE_TYPES45.TSTypeAliasDeclaration:
|
|
3347
|
+
case AST_NODE_TYPES45.TSInterfaceDeclaration:
|
|
3348
|
+
case AST_NODE_TYPES45.TSTypeParameter:
|
|
3349
|
+
case AST_NODE_TYPES45.TSQualifiedName:
|
|
3230
3350
|
return true;
|
|
3231
|
-
case
|
|
3232
|
-
case
|
|
3351
|
+
case AST_NODE_TYPES45.MemberExpression:
|
|
3352
|
+
case AST_NODE_TYPES45.Identifier:
|
|
3233
3353
|
current = current.parent;
|
|
3234
3354
|
break;
|
|
3235
3355
|
default:
|
|
@@ -3259,27 +3379,27 @@ var preferImportType = createRule43({
|
|
|
3259
3379
|
return false;
|
|
3260
3380
|
}
|
|
3261
3381
|
switch (parent.type) {
|
|
3262
|
-
case
|
|
3263
|
-
case
|
|
3264
|
-
case
|
|
3265
|
-
case
|
|
3266
|
-
case
|
|
3267
|
-
case
|
|
3268
|
-
case
|
|
3269
|
-
case
|
|
3270
|
-
case
|
|
3271
|
-
case
|
|
3272
|
-
case
|
|
3273
|
-
case
|
|
3274
|
-
case
|
|
3275
|
-
case
|
|
3276
|
-
case
|
|
3277
|
-
case
|
|
3278
|
-
case
|
|
3279
|
-
case
|
|
3280
|
-
case
|
|
3281
|
-
case
|
|
3282
|
-
case
|
|
3382
|
+
case AST_NODE_TYPES45.CallExpression:
|
|
3383
|
+
case AST_NODE_TYPES45.NewExpression:
|
|
3384
|
+
case AST_NODE_TYPES45.JSXOpeningElement:
|
|
3385
|
+
case AST_NODE_TYPES45.JSXClosingElement:
|
|
3386
|
+
case AST_NODE_TYPES45.MemberExpression:
|
|
3387
|
+
case AST_NODE_TYPES45.VariableDeclarator:
|
|
3388
|
+
case AST_NODE_TYPES45.TaggedTemplateExpression:
|
|
3389
|
+
case AST_NODE_TYPES45.SpreadElement:
|
|
3390
|
+
case AST_NODE_TYPES45.ExportSpecifier:
|
|
3391
|
+
case AST_NODE_TYPES45.ArrayExpression:
|
|
3392
|
+
case AST_NODE_TYPES45.ObjectExpression:
|
|
3393
|
+
case AST_NODE_TYPES45.BinaryExpression:
|
|
3394
|
+
case AST_NODE_TYPES45.LogicalExpression:
|
|
3395
|
+
case AST_NODE_TYPES45.UnaryExpression:
|
|
3396
|
+
case AST_NODE_TYPES45.ReturnStatement:
|
|
3397
|
+
case AST_NODE_TYPES45.ArrowFunctionExpression:
|
|
3398
|
+
case AST_NODE_TYPES45.ConditionalExpression:
|
|
3399
|
+
case AST_NODE_TYPES45.AwaitExpression:
|
|
3400
|
+
case AST_NODE_TYPES45.YieldExpression:
|
|
3401
|
+
case AST_NODE_TYPES45.Property:
|
|
3402
|
+
case AST_NODE_TYPES45.JSXExpressionContainer:
|
|
3283
3403
|
return true;
|
|
3284
3404
|
default:
|
|
3285
3405
|
return false;
|
|
@@ -3291,7 +3411,7 @@ var preferImportType = createRule43({
|
|
|
3291
3411
|
return;
|
|
3292
3412
|
}
|
|
3293
3413
|
const hasInlineTypeSpecifier = node.specifiers.some(
|
|
3294
|
-
(specifier) => specifier.type ===
|
|
3414
|
+
(specifier) => specifier.type === AST_NODE_TYPES45.ImportSpecifier && specifier.importKind === "type"
|
|
3295
3415
|
);
|
|
3296
3416
|
if (hasInlineTypeSpecifier) {
|
|
3297
3417
|
return;
|
|
@@ -3309,13 +3429,13 @@ var preferImportType = createRule43({
|
|
|
3309
3429
|
}
|
|
3310
3430
|
const scope = context.sourceCode.getScope(node);
|
|
3311
3431
|
const isTypeOnlyImport2 = node.specifiers.every((specifier) => {
|
|
3312
|
-
if (specifier.type ===
|
|
3432
|
+
if (specifier.type === AST_NODE_TYPES45.ImportDefaultSpecifier) {
|
|
3313
3433
|
return false;
|
|
3314
3434
|
}
|
|
3315
|
-
if (specifier.type ===
|
|
3435
|
+
if (specifier.type === AST_NODE_TYPES45.ImportNamespaceSpecifier) {
|
|
3316
3436
|
return false;
|
|
3317
3437
|
}
|
|
3318
|
-
if (specifier.type ===
|
|
3438
|
+
if (specifier.type === AST_NODE_TYPES45.ImportSpecifier) {
|
|
3319
3439
|
const localName = specifier.local.name;
|
|
3320
3440
|
return !isUsedAsValue(localName, scope);
|
|
3321
3441
|
}
|
|
@@ -3341,19 +3461,19 @@ var preferImportType = createRule43({
|
|
|
3341
3461
|
var prefer_import_type_default = preferImportType;
|
|
3342
3462
|
|
|
3343
3463
|
// src/rules/prefer-inline-literal-union.ts
|
|
3344
|
-
import { AST_NODE_TYPES as
|
|
3345
|
-
var
|
|
3464
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46, ESLintUtils as ESLintUtils46 } from "@typescript-eslint/utils";
|
|
3465
|
+
var createRule46 = ESLintUtils46.RuleCreator(
|
|
3346
3466
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3347
3467
|
);
|
|
3348
3468
|
function isLiteralUnionType(node) {
|
|
3349
|
-
if (node.type !==
|
|
3469
|
+
if (node.type !== AST_NODE_TYPES46.TSUnionType) {
|
|
3350
3470
|
return false;
|
|
3351
3471
|
}
|
|
3352
3472
|
return node.types.every(
|
|
3353
|
-
(member) => member.type ===
|
|
3473
|
+
(member) => member.type === AST_NODE_TYPES46.TSLiteralType || member.type === AST_NODE_TYPES46.TSNullKeyword || member.type === AST_NODE_TYPES46.TSUndefinedKeyword
|
|
3354
3474
|
);
|
|
3355
3475
|
}
|
|
3356
|
-
var preferInlineLiteralUnion =
|
|
3476
|
+
var preferInlineLiteralUnion = createRule46({
|
|
3357
3477
|
name: "prefer-inline-literal-union",
|
|
3358
3478
|
meta: {
|
|
3359
3479
|
type: "suggestion",
|
|
@@ -3380,10 +3500,10 @@ var preferInlineLiteralUnion = createRule44({
|
|
|
3380
3500
|
return;
|
|
3381
3501
|
}
|
|
3382
3502
|
const { typeAnnotation } = node.typeAnnotation;
|
|
3383
|
-
if (typeAnnotation.type !==
|
|
3503
|
+
if (typeAnnotation.type !== AST_NODE_TYPES46.TSTypeReference) {
|
|
3384
3504
|
return;
|
|
3385
3505
|
}
|
|
3386
|
-
if (typeAnnotation.typeName.type !==
|
|
3506
|
+
if (typeAnnotation.typeName.type !== AST_NODE_TYPES46.Identifier) {
|
|
3387
3507
|
return;
|
|
3388
3508
|
}
|
|
3389
3509
|
const aliasName = typeAnnotation.typeName.name;
|
|
@@ -3407,12 +3527,12 @@ var preferInlineLiteralUnion = createRule44({
|
|
|
3407
3527
|
var prefer_inline_literal_union_default = preferInlineLiteralUnion;
|
|
3408
3528
|
|
|
3409
3529
|
// src/rules/prefer-inline-type-export.ts
|
|
3410
|
-
import { AST_NODE_TYPES as
|
|
3411
|
-
var
|
|
3530
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47, ESLintUtils as ESLintUtils47 } from "@typescript-eslint/utils";
|
|
3531
|
+
var createRule47 = ESLintUtils47.RuleCreator(
|
|
3412
3532
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3413
3533
|
);
|
|
3414
|
-
var isTypeDeclaration = (node) => node.type ===
|
|
3415
|
-
var preferInlineTypeExport =
|
|
3534
|
+
var isTypeDeclaration = (node) => node.type === AST_NODE_TYPES47.TSInterfaceDeclaration || node.type === AST_NODE_TYPES47.TSTypeAliasDeclaration;
|
|
3535
|
+
var preferInlineTypeExport = createRule47({
|
|
3416
3536
|
name: "prefer-inline-type-export",
|
|
3417
3537
|
meta: {
|
|
3418
3538
|
type: "suggestion",
|
|
@@ -3429,12 +3549,12 @@ var preferInlineTypeExport = createRule45({
|
|
|
3429
3549
|
create(context) {
|
|
3430
3550
|
const typeDeclarations = /* @__PURE__ */ new Map();
|
|
3431
3551
|
function collectDeclaration(node) {
|
|
3432
|
-
if (node.parent.type !==
|
|
3552
|
+
if (node.parent.type !== AST_NODE_TYPES47.ExportNamedDeclaration) {
|
|
3433
3553
|
typeDeclarations.set(node.id.name, node);
|
|
3434
3554
|
}
|
|
3435
3555
|
}
|
|
3436
3556
|
function reportSpecifier(specifier, statement, declarationNode) {
|
|
3437
|
-
if (specifier.local.type !==
|
|
3557
|
+
if (specifier.local.type !== AST_NODE_TYPES47.Identifier) {
|
|
3438
3558
|
return;
|
|
3439
3559
|
}
|
|
3440
3560
|
const { name } = specifier.local;
|
|
@@ -3467,16 +3587,16 @@ var preferInlineTypeExport = createRule45({
|
|
|
3467
3587
|
return {
|
|
3468
3588
|
Program(node) {
|
|
3469
3589
|
node.body.forEach((statement) => {
|
|
3470
|
-
if (statement.type ===
|
|
3590
|
+
if (statement.type === AST_NODE_TYPES47.TSInterfaceDeclaration || statement.type === AST_NODE_TYPES47.TSTypeAliasDeclaration) {
|
|
3471
3591
|
collectDeclaration(statement);
|
|
3472
3592
|
}
|
|
3473
3593
|
});
|
|
3474
3594
|
node.body.forEach((statement) => {
|
|
3475
|
-
if (statement.type !==
|
|
3595
|
+
if (statement.type !== AST_NODE_TYPES47.ExportNamedDeclaration || statement.declaration !== null) {
|
|
3476
3596
|
return;
|
|
3477
3597
|
}
|
|
3478
3598
|
statement.specifiers.forEach((specifier) => {
|
|
3479
|
-
if (specifier.local.type !==
|
|
3599
|
+
if (specifier.local.type !== AST_NODE_TYPES47.Identifier) {
|
|
3480
3600
|
return;
|
|
3481
3601
|
}
|
|
3482
3602
|
const declarationNode = typeDeclarations.get(specifier.local.name);
|
|
@@ -3493,11 +3613,11 @@ var preferInlineTypeExport = createRule45({
|
|
|
3493
3613
|
var prefer_inline_type_export_default = preferInlineTypeExport;
|
|
3494
3614
|
|
|
3495
3615
|
// src/rules/prefer-interface-for-component-props.ts
|
|
3496
|
-
import { AST_NODE_TYPES as
|
|
3497
|
-
var
|
|
3616
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48, ESLintUtils as ESLintUtils48 } from "@typescript-eslint/utils";
|
|
3617
|
+
var createRule48 = ESLintUtils48.RuleCreator(
|
|
3498
3618
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3499
3619
|
);
|
|
3500
|
-
var preferInterfaceForComponentProps =
|
|
3620
|
+
var preferInterfaceForComponentProps = createRule48({
|
|
3501
3621
|
name: "prefer-interface-for-component-props",
|
|
3502
3622
|
meta: {
|
|
3503
3623
|
type: "suggestion",
|
|
@@ -3517,13 +3637,13 @@ var preferInterfaceForComponentProps = createRule46({
|
|
|
3517
3637
|
}
|
|
3518
3638
|
return {
|
|
3519
3639
|
TSTypeAliasDeclaration(node) {
|
|
3520
|
-
if (node.id.type !==
|
|
3640
|
+
if (node.id.type !== AST_NODE_TYPES48.Identifier) {
|
|
3521
3641
|
return;
|
|
3522
3642
|
}
|
|
3523
3643
|
if (!node.id.name.endsWith("Props")) {
|
|
3524
3644
|
return;
|
|
3525
3645
|
}
|
|
3526
|
-
if (node.typeAnnotation.type !==
|
|
3646
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES48.TSTypeLiteral) {
|
|
3527
3647
|
return;
|
|
3528
3648
|
}
|
|
3529
3649
|
const { name } = node.id;
|
|
@@ -3550,11 +3670,11 @@ var preferInterfaceForComponentProps = createRule46({
|
|
|
3550
3670
|
var prefer_interface_for_component_props_default = preferInterfaceForComponentProps;
|
|
3551
3671
|
|
|
3552
3672
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
3553
|
-
import { AST_NODE_TYPES as
|
|
3554
|
-
var
|
|
3673
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49, ESLintUtils as ESLintUtils49 } from "@typescript-eslint/utils";
|
|
3674
|
+
var createRule49 = ESLintUtils49.RuleCreator(
|
|
3555
3675
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3556
3676
|
);
|
|
3557
|
-
var preferInterfaceOverInlineTypes =
|
|
3677
|
+
var preferInterfaceOverInlineTypes = createRule49({
|
|
3558
3678
|
name: "prefer-interface-over-inline-types",
|
|
3559
3679
|
meta: {
|
|
3560
3680
|
type: "suggestion",
|
|
@@ -3570,54 +3690,54 @@ var preferInterfaceOverInlineTypes = createRule47({
|
|
|
3570
3690
|
defaultOptions: [],
|
|
3571
3691
|
create(context) {
|
|
3572
3692
|
function hasJSXInConditional(node) {
|
|
3573
|
-
return node.consequent.type ===
|
|
3693
|
+
return node.consequent.type === AST_NODE_TYPES49.JSXElement || node.consequent.type === AST_NODE_TYPES49.JSXFragment || node.alternate.type === AST_NODE_TYPES49.JSXElement || node.alternate.type === AST_NODE_TYPES49.JSXFragment;
|
|
3574
3694
|
}
|
|
3575
3695
|
function hasJSXInLogical(node) {
|
|
3576
|
-
return node.right.type ===
|
|
3696
|
+
return node.right.type === AST_NODE_TYPES49.JSXElement || node.right.type === AST_NODE_TYPES49.JSXFragment;
|
|
3577
3697
|
}
|
|
3578
3698
|
function hasJSXReturn(block) {
|
|
3579
3699
|
return block.body.some((stmt) => {
|
|
3580
|
-
if (stmt.type ===
|
|
3581
|
-
return stmt.argument.type ===
|
|
3700
|
+
if (stmt.type === AST_NODE_TYPES49.ReturnStatement && stmt.argument) {
|
|
3701
|
+
return stmt.argument.type === AST_NODE_TYPES49.JSXElement || stmt.argument.type === AST_NODE_TYPES49.JSXFragment || stmt.argument.type === AST_NODE_TYPES49.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES49.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
3582
3702
|
}
|
|
3583
3703
|
return false;
|
|
3584
3704
|
});
|
|
3585
3705
|
}
|
|
3586
3706
|
function isReactComponent2(node) {
|
|
3587
|
-
if (node.type ===
|
|
3588
|
-
if (node.body.type ===
|
|
3707
|
+
if (node.type === AST_NODE_TYPES49.ArrowFunctionExpression) {
|
|
3708
|
+
if (node.body.type === AST_NODE_TYPES49.JSXElement || node.body.type === AST_NODE_TYPES49.JSXFragment) {
|
|
3589
3709
|
return true;
|
|
3590
3710
|
}
|
|
3591
|
-
if (node.body.type ===
|
|
3711
|
+
if (node.body.type === AST_NODE_TYPES49.BlockStatement) {
|
|
3592
3712
|
return hasJSXReturn(node.body);
|
|
3593
3713
|
}
|
|
3594
|
-
} else if (node.type ===
|
|
3595
|
-
if (node.body && node.body.type ===
|
|
3714
|
+
} else if (node.type === AST_NODE_TYPES49.FunctionExpression || node.type === AST_NODE_TYPES49.FunctionDeclaration) {
|
|
3715
|
+
if (node.body && node.body.type === AST_NODE_TYPES49.BlockStatement) {
|
|
3596
3716
|
return hasJSXReturn(node.body);
|
|
3597
3717
|
}
|
|
3598
3718
|
}
|
|
3599
3719
|
return false;
|
|
3600
3720
|
}
|
|
3601
3721
|
function isInlineTypeAnnotation(node) {
|
|
3602
|
-
if (node.type ===
|
|
3722
|
+
if (node.type === AST_NODE_TYPES49.TSTypeLiteral) {
|
|
3603
3723
|
return true;
|
|
3604
3724
|
}
|
|
3605
|
-
if (node.type ===
|
|
3606
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3725
|
+
if (node.type === AST_NODE_TYPES49.TSTypeReference && node.typeArguments) {
|
|
3726
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES49.TSTypeLiteral);
|
|
3607
3727
|
}
|
|
3608
|
-
if (node.type ===
|
|
3728
|
+
if (node.type === AST_NODE_TYPES49.TSUnionType) {
|
|
3609
3729
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
3610
3730
|
}
|
|
3611
3731
|
return false;
|
|
3612
3732
|
}
|
|
3613
3733
|
function hasInlineObjectType(node) {
|
|
3614
|
-
if (node.type ===
|
|
3734
|
+
if (node.type === AST_NODE_TYPES49.TSTypeLiteral) {
|
|
3615
3735
|
return true;
|
|
3616
3736
|
}
|
|
3617
|
-
if (node.type ===
|
|
3618
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3737
|
+
if (node.type === AST_NODE_TYPES49.TSTypeReference && node.typeArguments) {
|
|
3738
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES49.TSTypeLiteral);
|
|
3619
3739
|
}
|
|
3620
|
-
if (node.type ===
|
|
3740
|
+
if (node.type === AST_NODE_TYPES49.TSUnionType) {
|
|
3621
3741
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
3622
3742
|
}
|
|
3623
3743
|
return false;
|
|
@@ -3630,7 +3750,7 @@ var preferInterfaceOverInlineTypes = createRule47({
|
|
|
3630
3750
|
return;
|
|
3631
3751
|
}
|
|
3632
3752
|
const param = node.params[0];
|
|
3633
|
-
if (param.type ===
|
|
3753
|
+
if (param.type === AST_NODE_TYPES49.Identifier && param.typeAnnotation) {
|
|
3634
3754
|
const { typeAnnotation } = param.typeAnnotation;
|
|
3635
3755
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
3636
3756
|
context.report({
|
|
@@ -3650,11 +3770,11 @@ var preferInterfaceOverInlineTypes = createRule47({
|
|
|
3650
3770
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
3651
3771
|
|
|
3652
3772
|
// src/rules/prefer-jsx-template-literals.ts
|
|
3653
|
-
import { AST_NODE_TYPES as
|
|
3654
|
-
var
|
|
3773
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50, ESLintUtils as ESLintUtils50 } from "@typescript-eslint/utils";
|
|
3774
|
+
var createRule50 = ESLintUtils50.RuleCreator(
|
|
3655
3775
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3656
3776
|
);
|
|
3657
|
-
var preferJSXTemplateLiterals =
|
|
3777
|
+
var preferJSXTemplateLiterals = createRule50({
|
|
3658
3778
|
name: "prefer-jsx-template-literals",
|
|
3659
3779
|
meta: {
|
|
3660
3780
|
type: "suggestion",
|
|
@@ -3723,9 +3843,9 @@ var preferJSXTemplateLiterals = createRule48({
|
|
|
3723
3843
|
if (!child || !nextChild) {
|
|
3724
3844
|
return;
|
|
3725
3845
|
}
|
|
3726
|
-
if (child.type ===
|
|
3846
|
+
if (child.type === AST_NODE_TYPES50.JSXText && nextChild.type === AST_NODE_TYPES50.JSXExpressionContainer) {
|
|
3727
3847
|
handleTextBeforeExpression(child, nextChild);
|
|
3728
|
-
} else if (child.type ===
|
|
3848
|
+
} else if (child.type === AST_NODE_TYPES50.JSXExpressionContainer && nextChild.type === AST_NODE_TYPES50.JSXText) {
|
|
3729
3849
|
handleExpressionBeforeText(child, nextChild);
|
|
3730
3850
|
}
|
|
3731
3851
|
}
|
|
@@ -3738,32 +3858,32 @@ var preferJSXTemplateLiterals = createRule48({
|
|
|
3738
3858
|
var prefer_jsx_template_literals_default = preferJSXTemplateLiterals;
|
|
3739
3859
|
|
|
3740
3860
|
// src/rules/prefer-named-param-types.ts
|
|
3741
|
-
import { AST_NODE_TYPES as
|
|
3742
|
-
var
|
|
3861
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ESLintUtils as ESLintUtils51 } from "@typescript-eslint/utils";
|
|
3862
|
+
var createRule51 = ESLintUtils51.RuleCreator(
|
|
3743
3863
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3744
3864
|
);
|
|
3745
3865
|
var returnsJsx2 = (node) => {
|
|
3746
|
-
if (node.type ===
|
|
3866
|
+
if (node.type === AST_NODE_TYPES51.JSXElement || node.type === AST_NODE_TYPES51.JSXFragment) {
|
|
3747
3867
|
return true;
|
|
3748
3868
|
}
|
|
3749
|
-
if (node.type ===
|
|
3869
|
+
if (node.type === AST_NODE_TYPES51.ConditionalExpression) {
|
|
3750
3870
|
return returnsJsx2(node.consequent) || returnsJsx2(node.alternate);
|
|
3751
3871
|
}
|
|
3752
|
-
if (node.type ===
|
|
3872
|
+
if (node.type === AST_NODE_TYPES51.LogicalExpression) {
|
|
3753
3873
|
return returnsJsx2(node.left) || returnsJsx2(node.right);
|
|
3754
3874
|
}
|
|
3755
3875
|
return false;
|
|
3756
3876
|
};
|
|
3757
3877
|
var bodyReturnsJsx2 = (body) => {
|
|
3758
|
-
if (body.type !==
|
|
3878
|
+
if (body.type !== AST_NODE_TYPES51.BlockStatement) {
|
|
3759
3879
|
return returnsJsx2(body);
|
|
3760
3880
|
}
|
|
3761
3881
|
return body.body.some(
|
|
3762
|
-
(stmt) => stmt.type ===
|
|
3882
|
+
(stmt) => stmt.type === AST_NODE_TYPES51.ReturnStatement && stmt.argument !== null && returnsJsx2(stmt.argument)
|
|
3763
3883
|
);
|
|
3764
3884
|
};
|
|
3765
3885
|
var isReactComponentFunction = (node) => bodyReturnsJsx2(node.body);
|
|
3766
|
-
var preferNamedParamTypes =
|
|
3886
|
+
var preferNamedParamTypes = createRule51({
|
|
3767
3887
|
name: "prefer-named-param-types",
|
|
3768
3888
|
meta: {
|
|
3769
3889
|
type: "suggestion",
|
|
@@ -3778,16 +3898,16 @@ var preferNamedParamTypes = createRule49({
|
|
|
3778
3898
|
defaultOptions: [],
|
|
3779
3899
|
create(context) {
|
|
3780
3900
|
function hasInlineObjectType(param) {
|
|
3781
|
-
if (param.type ===
|
|
3901
|
+
if (param.type === AST_NODE_TYPES51.AssignmentPattern) {
|
|
3782
3902
|
return hasInlineObjectType(param.left);
|
|
3783
3903
|
}
|
|
3784
|
-
if (param.type ===
|
|
3785
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3904
|
+
if (param.type === AST_NODE_TYPES51.ObjectPattern) {
|
|
3905
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES51.TSTypeLiteral) {
|
|
3786
3906
|
return true;
|
|
3787
3907
|
}
|
|
3788
3908
|
}
|
|
3789
|
-
if (param.type ===
|
|
3790
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3909
|
+
if (param.type === AST_NODE_TYPES51.Identifier) {
|
|
3910
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES51.TSTypeLiteral) {
|
|
3791
3911
|
return true;
|
|
3792
3912
|
}
|
|
3793
3913
|
}
|
|
@@ -3800,7 +3920,7 @@ var preferNamedParamTypes = createRule49({
|
|
|
3800
3920
|
} else if ("value" in node && node.value) {
|
|
3801
3921
|
params = node.value.params;
|
|
3802
3922
|
}
|
|
3803
|
-
if ((node.type ===
|
|
3923
|
+
if ((node.type === AST_NODE_TYPES51.FunctionDeclaration || node.type === AST_NODE_TYPES51.FunctionExpression || node.type === AST_NODE_TYPES51.ArrowFunctionExpression) && params.length === 1 && params[0].type === AST_NODE_TYPES51.Identifier && isReactComponentFunction(node)) {
|
|
3804
3924
|
return;
|
|
3805
3925
|
}
|
|
3806
3926
|
params.forEach((param) => {
|
|
@@ -3824,11 +3944,11 @@ var preferNamedParamTypes = createRule49({
|
|
|
3824
3944
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
3825
3945
|
|
|
3826
3946
|
// src/rules/prefer-props-with-children.ts
|
|
3827
|
-
import { AST_NODE_TYPES as
|
|
3828
|
-
var
|
|
3947
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES52, ESLintUtils as ESLintUtils52 } from "@typescript-eslint/utils";
|
|
3948
|
+
var createRule52 = ESLintUtils52.RuleCreator(
|
|
3829
3949
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3830
3950
|
);
|
|
3831
|
-
var preferPropsWithChildren =
|
|
3951
|
+
var preferPropsWithChildren = createRule52({
|
|
3832
3952
|
name: "prefer-props-with-children",
|
|
3833
3953
|
meta: {
|
|
3834
3954
|
type: "suggestion",
|
|
@@ -3846,24 +3966,24 @@ var preferPropsWithChildren = createRule50({
|
|
|
3846
3966
|
if (!typeNode) {
|
|
3847
3967
|
return false;
|
|
3848
3968
|
}
|
|
3849
|
-
if (typeNode.type !==
|
|
3969
|
+
if (typeNode.type !== AST_NODE_TYPES52.TSTypeReference) {
|
|
3850
3970
|
return false;
|
|
3851
3971
|
}
|
|
3852
3972
|
const { typeName } = typeNode;
|
|
3853
|
-
if (typeName.type ===
|
|
3973
|
+
if (typeName.type === AST_NODE_TYPES52.Identifier) {
|
|
3854
3974
|
return typeName.name === "ReactNode";
|
|
3855
3975
|
}
|
|
3856
|
-
if (typeName.type ===
|
|
3976
|
+
if (typeName.type === AST_NODE_TYPES52.TSQualifiedName && typeName.left.type === AST_NODE_TYPES52.Identifier && typeName.left.name === "React" && typeName.right.type === AST_NODE_TYPES52.Identifier && typeName.right.name === "ReactNode") {
|
|
3857
3977
|
return true;
|
|
3858
3978
|
}
|
|
3859
3979
|
return false;
|
|
3860
3980
|
}
|
|
3861
3981
|
function findChildrenReactNode(members) {
|
|
3862
3982
|
for (const member of members) {
|
|
3863
|
-
if (member.type !==
|
|
3983
|
+
if (member.type !== AST_NODE_TYPES52.TSPropertySignature) {
|
|
3864
3984
|
continue;
|
|
3865
3985
|
}
|
|
3866
|
-
if (member.key.type !==
|
|
3986
|
+
if (member.key.type !== AST_NODE_TYPES52.Identifier) {
|
|
3867
3987
|
continue;
|
|
3868
3988
|
}
|
|
3869
3989
|
if (member.key.name !== "children") {
|
|
@@ -3903,11 +4023,11 @@ var preferPropsWithChildren = createRule50({
|
|
|
3903
4023
|
var prefer_props_with_children_default = preferPropsWithChildren;
|
|
3904
4024
|
|
|
3905
4025
|
// src/rules/prefer-react-import-types.ts
|
|
3906
|
-
import { AST_NODE_TYPES as
|
|
3907
|
-
var
|
|
4026
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES53, ESLintUtils as ESLintUtils53 } from "@typescript-eslint/utils";
|
|
4027
|
+
var createRule53 = ESLintUtils53.RuleCreator(
|
|
3908
4028
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3909
4029
|
);
|
|
3910
|
-
var preferReactImportTypes =
|
|
4030
|
+
var preferReactImportTypes = createRule53({
|
|
3911
4031
|
name: "prefer-react-import-types",
|
|
3912
4032
|
meta: {
|
|
3913
4033
|
type: "suggestion",
|
|
@@ -3983,7 +4103,7 @@ var preferReactImportTypes = createRule51({
|
|
|
3983
4103
|
]);
|
|
3984
4104
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
3985
4105
|
function checkMemberExpression(node) {
|
|
3986
|
-
if (node.object.type ===
|
|
4106
|
+
if (node.object.type === AST_NODE_TYPES53.Identifier && node.object.name === "React" && node.property.type === AST_NODE_TYPES53.Identifier && allReactExports.has(node.property.name)) {
|
|
3987
4107
|
const typeName = node.property.name;
|
|
3988
4108
|
const isType = reactTypes.has(typeName);
|
|
3989
4109
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -4000,7 +4120,7 @@ var preferReactImportTypes = createRule51({
|
|
|
4000
4120
|
return {
|
|
4001
4121
|
MemberExpression: checkMemberExpression,
|
|
4002
4122
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
4003
|
-
if (node.left.type ===
|
|
4123
|
+
if (node.left.type === AST_NODE_TYPES53.Identifier && node.left.name === "React" && node.right.type === AST_NODE_TYPES53.Identifier && allReactExports.has(node.right.name)) {
|
|
4004
4124
|
const typeName = node.right.name;
|
|
4005
4125
|
const isType = reactTypes.has(typeName);
|
|
4006
4126
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -4020,11 +4140,11 @@ var preferReactImportTypes = createRule51({
|
|
|
4020
4140
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
4021
4141
|
|
|
4022
4142
|
// src/rules/react-props-destructure.ts
|
|
4023
|
-
import { AST_NODE_TYPES as
|
|
4024
|
-
var
|
|
4143
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES54, ESLintUtils as ESLintUtils54 } from "@typescript-eslint/utils";
|
|
4144
|
+
var createRule54 = ESLintUtils54.RuleCreator(
|
|
4025
4145
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4026
4146
|
);
|
|
4027
|
-
var reactPropsDestructure =
|
|
4147
|
+
var reactPropsDestructure = createRule54({
|
|
4028
4148
|
name: "react-props-destructure",
|
|
4029
4149
|
meta: {
|
|
4030
4150
|
type: "suggestion",
|
|
@@ -4040,29 +4160,29 @@ var reactPropsDestructure = createRule52({
|
|
|
4040
4160
|
defaultOptions: [],
|
|
4041
4161
|
create(context) {
|
|
4042
4162
|
function hasJSXInConditional(node) {
|
|
4043
|
-
return node.consequent.type ===
|
|
4163
|
+
return node.consequent.type === AST_NODE_TYPES54.JSXElement || node.consequent.type === AST_NODE_TYPES54.JSXFragment || node.alternate.type === AST_NODE_TYPES54.JSXElement || node.alternate.type === AST_NODE_TYPES54.JSXFragment;
|
|
4044
4164
|
}
|
|
4045
4165
|
function hasJSXInLogical(node) {
|
|
4046
|
-
return node.right.type ===
|
|
4166
|
+
return node.right.type === AST_NODE_TYPES54.JSXElement || node.right.type === AST_NODE_TYPES54.JSXFragment;
|
|
4047
4167
|
}
|
|
4048
4168
|
function hasJSXReturn(block) {
|
|
4049
4169
|
return block.body.some((stmt) => {
|
|
4050
|
-
if (stmt.type ===
|
|
4051
|
-
return stmt.argument.type ===
|
|
4170
|
+
if (stmt.type === AST_NODE_TYPES54.ReturnStatement && stmt.argument) {
|
|
4171
|
+
return stmt.argument.type === AST_NODE_TYPES54.JSXElement || stmt.argument.type === AST_NODE_TYPES54.JSXFragment || stmt.argument.type === AST_NODE_TYPES54.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES54.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
4052
4172
|
}
|
|
4053
4173
|
return false;
|
|
4054
4174
|
});
|
|
4055
4175
|
}
|
|
4056
4176
|
function isReactComponent2(node) {
|
|
4057
|
-
if (node.type ===
|
|
4058
|
-
if (node.body.type ===
|
|
4177
|
+
if (node.type === AST_NODE_TYPES54.ArrowFunctionExpression) {
|
|
4178
|
+
if (node.body.type === AST_NODE_TYPES54.JSXElement || node.body.type === AST_NODE_TYPES54.JSXFragment) {
|
|
4059
4179
|
return true;
|
|
4060
4180
|
}
|
|
4061
|
-
if (node.body.type ===
|
|
4181
|
+
if (node.body.type === AST_NODE_TYPES54.BlockStatement) {
|
|
4062
4182
|
return hasJSXReturn(node.body);
|
|
4063
4183
|
}
|
|
4064
|
-
} else if (node.type ===
|
|
4065
|
-
if (node.body && node.body.type ===
|
|
4184
|
+
} else if (node.type === AST_NODE_TYPES54.FunctionExpression || node.type === AST_NODE_TYPES54.FunctionDeclaration) {
|
|
4185
|
+
if (node.body && node.body.type === AST_NODE_TYPES54.BlockStatement) {
|
|
4066
4186
|
return hasJSXReturn(node.body);
|
|
4067
4187
|
}
|
|
4068
4188
|
}
|
|
@@ -4076,9 +4196,9 @@ var reactPropsDestructure = createRule52({
|
|
|
4076
4196
|
return;
|
|
4077
4197
|
}
|
|
4078
4198
|
const param = node.params[0];
|
|
4079
|
-
if (param.type ===
|
|
4080
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
4081
|
-
if (prop.key.type ===
|
|
4199
|
+
if (param.type === AST_NODE_TYPES54.ObjectPattern) {
|
|
4200
|
+
const properties = param.properties.filter((prop) => prop.type === AST_NODE_TYPES54.Property).map((prop) => {
|
|
4201
|
+
if (prop.key.type === AST_NODE_TYPES54.Identifier) {
|
|
4082
4202
|
return prop.key.name;
|
|
4083
4203
|
}
|
|
4084
4204
|
return null;
|
|
@@ -4105,57 +4225,57 @@ var reactPropsDestructure = createRule52({
|
|
|
4105
4225
|
var react_props_destructure_default = reactPropsDestructure;
|
|
4106
4226
|
|
|
4107
4227
|
// src/rules/require-explicit-return-type.ts
|
|
4108
|
-
import { AST_NODE_TYPES as
|
|
4109
|
-
var
|
|
4228
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55, ESLintUtils as ESLintUtils55 } from "@typescript-eslint/utils";
|
|
4229
|
+
var createRule55 = ESLintUtils55.RuleCreator(
|
|
4110
4230
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4111
4231
|
);
|
|
4112
4232
|
var isReactComponent = (node) => {
|
|
4113
|
-
if (node.type ===
|
|
4233
|
+
if (node.type === AST_NODE_TYPES55.ArrowFunctionExpression) {
|
|
4114
4234
|
const { parent } = node;
|
|
4115
|
-
if (parent?.type ===
|
|
4235
|
+
if (parent?.type === AST_NODE_TYPES55.VariableDeclarator) {
|
|
4116
4236
|
const { id } = parent;
|
|
4117
|
-
if (id.type ===
|
|
4237
|
+
if (id.type === AST_NODE_TYPES55.Identifier) {
|
|
4118
4238
|
return /^[A-Z]/.test(id.name);
|
|
4119
4239
|
}
|
|
4120
4240
|
}
|
|
4121
4241
|
}
|
|
4122
|
-
if (node.type ===
|
|
4242
|
+
if (node.type === AST_NODE_TYPES55.FunctionDeclaration && node.id) {
|
|
4123
4243
|
return /^[A-Z]/.test(node.id.name);
|
|
4124
4244
|
}
|
|
4125
4245
|
return false;
|
|
4126
4246
|
};
|
|
4127
4247
|
var isCallbackFunction = (node) => {
|
|
4128
|
-
if (node.type ===
|
|
4248
|
+
if (node.type === AST_NODE_TYPES55.FunctionDeclaration) {
|
|
4129
4249
|
return false;
|
|
4130
4250
|
}
|
|
4131
4251
|
const { parent } = node;
|
|
4132
4252
|
if (!parent) {
|
|
4133
4253
|
return false;
|
|
4134
4254
|
}
|
|
4135
|
-
if (parent.type ===
|
|
4255
|
+
if (parent.type === AST_NODE_TYPES55.CallExpression && parent.arguments.includes(node)) {
|
|
4136
4256
|
return true;
|
|
4137
4257
|
}
|
|
4138
|
-
if (parent.type ===
|
|
4258
|
+
if (parent.type === AST_NODE_TYPES55.Property) {
|
|
4139
4259
|
return true;
|
|
4140
4260
|
}
|
|
4141
|
-
if (parent.type ===
|
|
4261
|
+
if (parent.type === AST_NODE_TYPES55.ArrayExpression) {
|
|
4142
4262
|
return true;
|
|
4143
4263
|
}
|
|
4144
4264
|
return false;
|
|
4145
4265
|
};
|
|
4146
4266
|
var getFunctionName = (node) => {
|
|
4147
|
-
if (node.type ===
|
|
4267
|
+
if (node.type === AST_NODE_TYPES55.FunctionDeclaration && node.id) {
|
|
4148
4268
|
return node.id.name;
|
|
4149
4269
|
}
|
|
4150
|
-
if (node.type ===
|
|
4270
|
+
if (node.type === AST_NODE_TYPES55.FunctionExpression && node.id) {
|
|
4151
4271
|
return node.id.name;
|
|
4152
4272
|
}
|
|
4153
|
-
if ((node.type ===
|
|
4273
|
+
if ((node.type === AST_NODE_TYPES55.ArrowFunctionExpression || node.type === AST_NODE_TYPES55.FunctionExpression) && node.parent?.type === AST_NODE_TYPES55.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES55.Identifier) {
|
|
4154
4274
|
return node.parent.id.name;
|
|
4155
4275
|
}
|
|
4156
4276
|
return null;
|
|
4157
4277
|
};
|
|
4158
|
-
var requireExplicitReturnType =
|
|
4278
|
+
var requireExplicitReturnType = createRule55({
|
|
4159
4279
|
name: "require-explicit-return-type",
|
|
4160
4280
|
meta: {
|
|
4161
4281
|
type: "suggestion",
|
|
@@ -4204,8 +4324,8 @@ var requireExplicitReturnType = createRule53({
|
|
|
4204
4324
|
var require_explicit_return_type_default = requireExplicitReturnType;
|
|
4205
4325
|
|
|
4206
4326
|
// src/rules/sort-exports.ts
|
|
4207
|
-
import { AST_NODE_TYPES as
|
|
4208
|
-
var
|
|
4327
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES56, ESLintUtils as ESLintUtils56 } from "@typescript-eslint/utils";
|
|
4328
|
+
var createRule56 = ESLintUtils56.RuleCreator(
|
|
4209
4329
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4210
4330
|
);
|
|
4211
4331
|
var GROUP_NAMES = ["", "external/alias re-export", "relative re-export", "local export"];
|
|
@@ -4219,7 +4339,7 @@ function getExportGroup(node) {
|
|
|
4219
4339
|
}
|
|
4220
4340
|
return 1;
|
|
4221
4341
|
}
|
|
4222
|
-
var sortExports =
|
|
4342
|
+
var sortExports = createRule56({
|
|
4223
4343
|
name: "sort-exports",
|
|
4224
4344
|
meta: {
|
|
4225
4345
|
type: "suggestion",
|
|
@@ -4259,7 +4379,7 @@ var sortExports = createRule54({
|
|
|
4259
4379
|
Program(node) {
|
|
4260
4380
|
const exportGroups = [];
|
|
4261
4381
|
node.body.forEach((statement) => {
|
|
4262
|
-
if (statement.type !==
|
|
4382
|
+
if (statement.type !== AST_NODE_TYPES56.ExportNamedDeclaration || statement.declaration !== null) {
|
|
4263
4383
|
if (exportGroups.length > 0) {
|
|
4264
4384
|
checkOrder(exportGroups);
|
|
4265
4385
|
exportGroups.length = 0;
|
|
@@ -4278,8 +4398,8 @@ var sortExports = createRule54({
|
|
|
4278
4398
|
var sort_exports_default = sortExports;
|
|
4279
4399
|
|
|
4280
4400
|
// src/rules/sort-imports.ts
|
|
4281
|
-
import { AST_NODE_TYPES as
|
|
4282
|
-
var
|
|
4401
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES57, ESLintUtils as ESLintUtils57 } from "@typescript-eslint/utils";
|
|
4402
|
+
var createRule57 = ESLintUtils57.RuleCreator(
|
|
4283
4403
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4284
4404
|
);
|
|
4285
4405
|
var NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
@@ -4346,7 +4466,7 @@ function getImportGroup(node) {
|
|
|
4346
4466
|
function isTypeOnlyImport(node) {
|
|
4347
4467
|
return node.importKind === "type" && node.specifiers.length > 0;
|
|
4348
4468
|
}
|
|
4349
|
-
var sortImports =
|
|
4469
|
+
var sortImports = createRule57({
|
|
4350
4470
|
name: "sort-imports",
|
|
4351
4471
|
meta: {
|
|
4352
4472
|
type: "suggestion",
|
|
@@ -4390,7 +4510,7 @@ var sortImports = createRule55({
|
|
|
4390
4510
|
Program(node) {
|
|
4391
4511
|
const importGroups = [];
|
|
4392
4512
|
node.body.forEach((statement) => {
|
|
4393
|
-
if (statement.type !==
|
|
4513
|
+
if (statement.type !== AST_NODE_TYPES57.ImportDeclaration) {
|
|
4394
4514
|
if (importGroups.length > 0) {
|
|
4395
4515
|
checkOrder(importGroups);
|
|
4396
4516
|
importGroups.length = 0;
|
|
@@ -4412,13 +4532,13 @@ var sortImports = createRule55({
|
|
|
4412
4532
|
var sort_imports_default = sortImports;
|
|
4413
4533
|
|
|
4414
4534
|
// src/rules/sort-type-alphabetically.ts
|
|
4415
|
-
import { AST_NODE_TYPES as
|
|
4416
|
-
var
|
|
4535
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES58, ESLintUtils as ESLintUtils58 } from "@typescript-eslint/utils";
|
|
4536
|
+
var createRule58 = ESLintUtils58.RuleCreator(
|
|
4417
4537
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4418
4538
|
);
|
|
4419
4539
|
function isAlphabeticallySortedWithinGroups(members) {
|
|
4420
4540
|
const properties = members.filter(
|
|
4421
|
-
(member) => member.type ===
|
|
4541
|
+
(member) => member.type === AST_NODE_TYPES58.TSPropertySignature && member.key.type === AST_NODE_TYPES58.Identifier
|
|
4422
4542
|
);
|
|
4423
4543
|
if (properties.length < 2) {
|
|
4424
4544
|
return true;
|
|
@@ -4429,7 +4549,7 @@ function isAlphabeticallySortedWithinGroups(members) {
|
|
|
4429
4549
|
const isOptionalSorted = optional.every((name, index) => index === 0 || optional[index - 1].localeCompare(name) <= 0);
|
|
4430
4550
|
return isRequiredSorted && isOptionalSorted;
|
|
4431
4551
|
}
|
|
4432
|
-
var sortTypeAlphabetically =
|
|
4552
|
+
var sortTypeAlphabetically = createRule58({
|
|
4433
4553
|
name: "sort-type-alphabetically",
|
|
4434
4554
|
meta: {
|
|
4435
4555
|
type: "suggestion",
|
|
@@ -4447,7 +4567,7 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4447
4567
|
function fixMembers(fixer, members) {
|
|
4448
4568
|
const { sourceCode } = context;
|
|
4449
4569
|
const properties = members.filter(
|
|
4450
|
-
(member) => member.type ===
|
|
4570
|
+
(member) => member.type === AST_NODE_TYPES58.TSPropertySignature && member.key.type === AST_NODE_TYPES58.Identifier
|
|
4451
4571
|
);
|
|
4452
4572
|
const required = properties.filter((prop) => !prop.optional);
|
|
4453
4573
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4484,7 +4604,7 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4484
4604
|
}
|
|
4485
4605
|
},
|
|
4486
4606
|
TSTypeAliasDeclaration(node) {
|
|
4487
|
-
if (node.typeAnnotation.type !==
|
|
4607
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES58.TSTypeLiteral) {
|
|
4488
4608
|
return;
|
|
4489
4609
|
}
|
|
4490
4610
|
const { members } = node.typeAnnotation;
|
|
@@ -4504,13 +4624,13 @@ var sortTypeAlphabetically = createRule56({
|
|
|
4504
4624
|
var sort_type_alphabetically_default = sortTypeAlphabetically;
|
|
4505
4625
|
|
|
4506
4626
|
// src/rules/sort-type-required-first.ts
|
|
4507
|
-
import { AST_NODE_TYPES as
|
|
4508
|
-
var
|
|
4627
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES59, ESLintUtils as ESLintUtils59 } from "@typescript-eslint/utils";
|
|
4628
|
+
var createRule59 = ESLintUtils59.RuleCreator(
|
|
4509
4629
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4510
4630
|
);
|
|
4511
4631
|
function isRequiredBeforeOptional(members) {
|
|
4512
4632
|
const properties = members.filter(
|
|
4513
|
-
(member) => member.type ===
|
|
4633
|
+
(member) => member.type === AST_NODE_TYPES59.TSPropertySignature && member.key.type === AST_NODE_TYPES59.Identifier
|
|
4514
4634
|
);
|
|
4515
4635
|
if (properties.length < 2) {
|
|
4516
4636
|
return true;
|
|
@@ -4521,7 +4641,7 @@ function isRequiredBeforeOptional(members) {
|
|
|
4521
4641
|
}
|
|
4522
4642
|
return properties.slice(firstOptionalIndex).every((prop) => prop.optional);
|
|
4523
4643
|
}
|
|
4524
|
-
var sortTypeRequiredFirst =
|
|
4644
|
+
var sortTypeRequiredFirst = createRule59({
|
|
4525
4645
|
name: "sort-type-required-first",
|
|
4526
4646
|
meta: {
|
|
4527
4647
|
type: "suggestion",
|
|
@@ -4539,7 +4659,7 @@ var sortTypeRequiredFirst = createRule57({
|
|
|
4539
4659
|
function fixMembers(fixer, members) {
|
|
4540
4660
|
const { sourceCode } = context;
|
|
4541
4661
|
const properties = members.filter(
|
|
4542
|
-
(member) => member.type ===
|
|
4662
|
+
(member) => member.type === AST_NODE_TYPES59.TSPropertySignature && member.key.type === AST_NODE_TYPES59.Identifier
|
|
4543
4663
|
);
|
|
4544
4664
|
const required = properties.filter((prop) => !prop.optional);
|
|
4545
4665
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4560,7 +4680,7 @@ var sortTypeRequiredFirst = createRule57({
|
|
|
4560
4680
|
}
|
|
4561
4681
|
},
|
|
4562
4682
|
TSTypeAliasDeclaration(node) {
|
|
4563
|
-
if (node.typeAnnotation.type !==
|
|
4683
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES59.TSTypeLiteral) {
|
|
4564
4684
|
return;
|
|
4565
4685
|
}
|
|
4566
4686
|
const { members } = node.typeAnnotation;
|
|
@@ -4612,6 +4732,7 @@ var rules = {
|
|
|
4612
4732
|
"no-direct-date": no_direct_date_default,
|
|
4613
4733
|
"no-emoji": no_emoji_default,
|
|
4614
4734
|
"no-env-fallback": no_env_fallback_default,
|
|
4735
|
+
"no-ghost-wrapper": no_ghost_wrapper_default,
|
|
4615
4736
|
"no-inline-default-export": no_inline_default_export_default,
|
|
4616
4737
|
"no-inline-nested-object": no_inline_nested_object_default,
|
|
4617
4738
|
"no-inline-return-properties": no_inline_return_properties_default,
|
|
@@ -4621,6 +4742,7 @@ var rules = {
|
|
|
4621
4742
|
"no-misleading-constant-case": no_misleading_constant_case_default,
|
|
4622
4743
|
"no-nested-interface-declaration": no_nested_interface_declaration_default,
|
|
4623
4744
|
"no-nested-ternary": no_nested_ternary_default,
|
|
4745
|
+
"no-redundant-fragment": no_redundant_fragment_default,
|
|
4624
4746
|
"no-relative-imports": no_relative_imports_default,
|
|
4625
4747
|
"no-single-char-variables": no_single_char_variables_default,
|
|
4626
4748
|
"prefer-async-await": prefer_async_await_default,
|
|
@@ -4744,6 +4866,8 @@ var jsxRules = {
|
|
|
4744
4866
|
"nextfriday/jsx-simple-props": "warn",
|
|
4745
4867
|
"nextfriday/jsx-sort-props": "warn",
|
|
4746
4868
|
"nextfriday/jsx-spread-props-last": "warn",
|
|
4869
|
+
"nextfriday/no-ghost-wrapper": "warn",
|
|
4870
|
+
"nextfriday/no-redundant-fragment": "warn",
|
|
4747
4871
|
"nextfriday/prefer-interface-for-component-props": "warn",
|
|
4748
4872
|
"nextfriday/prefer-interface-over-inline-types": "warn",
|
|
4749
4873
|
"nextfriday/prefer-jsx-template-literals": "warn",
|
|
@@ -4763,6 +4887,8 @@ var jsxRecommendedRules = {
|
|
|
4763
4887
|
"nextfriday/jsx-simple-props": "error",
|
|
4764
4888
|
"nextfriday/jsx-sort-props": "error",
|
|
4765
4889
|
"nextfriday/jsx-spread-props-last": "error",
|
|
4890
|
+
"nextfriday/no-ghost-wrapper": "error",
|
|
4891
|
+
"nextfriday/no-redundant-fragment": "error",
|
|
4766
4892
|
"nextfriday/prefer-interface-for-component-props": "error",
|
|
4767
4893
|
"nextfriday/prefer-interface-over-inline-types": "error",
|
|
4768
4894
|
"nextfriday/prefer-jsx-template-literals": "error",
|