eslint-plugin-nextfriday 1.23.1 → 2.0.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 +16 -0
- package/README.md +4 -1
- package/docs/rules/JSX_SPREAD_PROPS_LAST.md +42 -0
- package/lib/index.cjs +355 -311
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +42 -0
- package/lib/index.d.ts +42 -0
- package/lib/index.js +355 -311
- package/lib/index.js.map +1 -1
- package/package.json +4 -5
package/lib/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import rawUnicorn from "eslint-plugin-unicorn";
|
|
|
5
5
|
// package.json
|
|
6
6
|
var package_default = {
|
|
7
7
|
name: "eslint-plugin-nextfriday",
|
|
8
|
-
version: "
|
|
8
|
+
version: "2.0.0",
|
|
9
9
|
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
10
10
|
keywords: [
|
|
11
11
|
"eslint",
|
|
@@ -80,7 +80,7 @@ var package_default = {
|
|
|
80
80
|
"@changesets/cli": "^2.31.0",
|
|
81
81
|
"@commitlint/cli": "^20.5.2",
|
|
82
82
|
"@commitlint/config-conventional": "^20.5.0",
|
|
83
|
-
"@eslint/js": "^
|
|
83
|
+
"@eslint/js": "^10.0.1",
|
|
84
84
|
"@jest/globals": "^30.3.0",
|
|
85
85
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
86
86
|
"@swc/core": "^1.15.32",
|
|
@@ -91,8 +91,7 @@ var package_default = {
|
|
|
91
91
|
"@types/ramda": "^0.31.1",
|
|
92
92
|
"@typescript-eslint/parser": "^8.59.1",
|
|
93
93
|
"@typescript-eslint/rule-tester": "^8.59.1",
|
|
94
|
-
eslint: "^
|
|
95
|
-
"eslint-config-airbnb-extended": "^3.0.1",
|
|
94
|
+
eslint: "^10.2.1",
|
|
96
95
|
"eslint-config-prettier": "^10.1.8",
|
|
97
96
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
98
97
|
"eslint-plugin-import-x": "^4.16.2",
|
|
@@ -109,7 +108,7 @@ var package_default = {
|
|
|
109
108
|
"typescript-eslint": "^8.59.1"
|
|
110
109
|
},
|
|
111
110
|
peerDependencies: {
|
|
112
|
-
eslint: "^
|
|
111
|
+
eslint: "^10.0.0"
|
|
113
112
|
},
|
|
114
113
|
packageManager: "pnpm@9.12.0",
|
|
115
114
|
engines: {
|
|
@@ -1834,13 +1833,55 @@ var jsxSortProps = createRule22({
|
|
|
1834
1833
|
});
|
|
1835
1834
|
var jsx_sort_props_default = jsxSortProps;
|
|
1836
1835
|
|
|
1837
|
-
// src/rules/
|
|
1836
|
+
// src/rules/jsx-spread-props-last.ts
|
|
1838
1837
|
import { AST_NODE_TYPES as AST_NODE_TYPES22, ESLintUtils as ESLintUtils23 } from "@typescript-eslint/utils";
|
|
1839
1838
|
var createRule23 = ESLintUtils23.RuleCreator(
|
|
1840
1839
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1841
1840
|
);
|
|
1841
|
+
var jsxSpreadPropsLast = createRule23({
|
|
1842
|
+
name: "jsx-spread-props-last",
|
|
1843
|
+
meta: {
|
|
1844
|
+
type: "suggestion",
|
|
1845
|
+
docs: {
|
|
1846
|
+
description: "Enforce JSX spread attributes appear after all other props"
|
|
1847
|
+
},
|
|
1848
|
+
messages: {
|
|
1849
|
+
spreadNotLast: "JSX spread attributes must come after all other props."
|
|
1850
|
+
},
|
|
1851
|
+
schema: []
|
|
1852
|
+
},
|
|
1853
|
+
defaultOptions: [],
|
|
1854
|
+
create(context) {
|
|
1855
|
+
return {
|
|
1856
|
+
JSXOpeningElement(node) {
|
|
1857
|
+
const { attributes } = node;
|
|
1858
|
+
let lastNonSpreadIndex = -1;
|
|
1859
|
+
attributes.forEach((attribute, index) => {
|
|
1860
|
+
if (attribute.type !== AST_NODE_TYPES22.JSXSpreadAttribute) {
|
|
1861
|
+
lastNonSpreadIndex = index;
|
|
1862
|
+
}
|
|
1863
|
+
});
|
|
1864
|
+
attributes.forEach((attribute, index) => {
|
|
1865
|
+
if (attribute.type === AST_NODE_TYPES22.JSXSpreadAttribute && index < lastNonSpreadIndex) {
|
|
1866
|
+
context.report({
|
|
1867
|
+
node: attribute,
|
|
1868
|
+
messageId: "spreadNotLast"
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
}
|
|
1875
|
+
});
|
|
1876
|
+
var jsx_spread_props_last_default = jsxSpreadPropsLast;
|
|
1877
|
+
|
|
1878
|
+
// src/rules/newline-after-multiline-block.ts
|
|
1879
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23, ESLintUtils as ESLintUtils24 } from "@typescript-eslint/utils";
|
|
1880
|
+
var createRule24 = ESLintUtils24.RuleCreator(
|
|
1881
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1882
|
+
);
|
|
1842
1883
|
function isImportDeclaration(node) {
|
|
1843
|
-
return node.type ===
|
|
1884
|
+
return node.type === AST_NODE_TYPES23.ImportDeclaration;
|
|
1844
1885
|
}
|
|
1845
1886
|
function checkStatements(statements, context) {
|
|
1846
1887
|
const { sourceCode } = context;
|
|
@@ -1875,7 +1916,7 @@ function checkStatements(statements, context) {
|
|
|
1875
1916
|
}
|
|
1876
1917
|
});
|
|
1877
1918
|
}
|
|
1878
|
-
var newlineAfterMultilineBlock =
|
|
1919
|
+
var newlineAfterMultilineBlock = createRule24({
|
|
1879
1920
|
name: "newline-after-multiline-block",
|
|
1880
1921
|
meta: {
|
|
1881
1922
|
type: "layout",
|
|
@@ -1903,11 +1944,11 @@ var newlineAfterMultilineBlock = createRule23({
|
|
|
1903
1944
|
var newline_after_multiline_block_default = newlineAfterMultilineBlock;
|
|
1904
1945
|
|
|
1905
1946
|
// src/rules/newline-before-return.ts
|
|
1906
|
-
import { AST_NODE_TYPES as
|
|
1907
|
-
var
|
|
1947
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24, ESLintUtils as ESLintUtils25 } from "@typescript-eslint/utils";
|
|
1948
|
+
var createRule25 = ESLintUtils25.RuleCreator(
|
|
1908
1949
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1909
1950
|
);
|
|
1910
|
-
var newlineBeforeReturn =
|
|
1951
|
+
var newlineBeforeReturn = createRule25({
|
|
1911
1952
|
name: "newline-before-return",
|
|
1912
1953
|
meta: {
|
|
1913
1954
|
type: "layout",
|
|
@@ -1925,7 +1966,7 @@ var newlineBeforeReturn = createRule24({
|
|
|
1925
1966
|
const { sourceCode } = context;
|
|
1926
1967
|
function checkReturnStatement(node) {
|
|
1927
1968
|
const { parent } = node;
|
|
1928
|
-
if (!parent || parent.type !==
|
|
1969
|
+
if (!parent || parent.type !== AST_NODE_TYPES24.BlockStatement) {
|
|
1929
1970
|
return;
|
|
1930
1971
|
}
|
|
1931
1972
|
const { body: statements } = parent;
|
|
@@ -1962,11 +2003,11 @@ var newlineBeforeReturn = createRule24({
|
|
|
1962
2003
|
var newline_before_return_default = newlineBeforeReturn;
|
|
1963
2004
|
|
|
1964
2005
|
// src/rules/nextjs-require-public-env.ts
|
|
1965
|
-
import { AST_NODE_TYPES as
|
|
1966
|
-
var
|
|
2006
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25, ESLintUtils as ESLintUtils26 } from "@typescript-eslint/utils";
|
|
2007
|
+
var createRule26 = ESLintUtils26.RuleCreator(
|
|
1967
2008
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
1968
2009
|
);
|
|
1969
|
-
var nextjsRequirePublicEnv =
|
|
2010
|
+
var nextjsRequirePublicEnv = createRule26({
|
|
1970
2011
|
name: "nextjs-require-public-env",
|
|
1971
2012
|
meta: {
|
|
1972
2013
|
type: "problem",
|
|
@@ -1984,7 +2025,7 @@ var nextjsRequirePublicEnv = createRule25({
|
|
|
1984
2025
|
return {
|
|
1985
2026
|
Program(node) {
|
|
1986
2027
|
const firstStatement = node.body[0];
|
|
1987
|
-
if (firstStatement?.type ===
|
|
2028
|
+
if (firstStatement?.type === AST_NODE_TYPES25.ExpressionStatement && firstStatement.expression.type === AST_NODE_TYPES25.Literal && firstStatement.expression.value === "use client") {
|
|
1988
2029
|
isClientComponent = true;
|
|
1989
2030
|
}
|
|
1990
2031
|
},
|
|
@@ -1992,7 +2033,7 @@ var nextjsRequirePublicEnv = createRule25({
|
|
|
1992
2033
|
if (!isClientComponent) {
|
|
1993
2034
|
return;
|
|
1994
2035
|
}
|
|
1995
|
-
if (node.object.type ===
|
|
2036
|
+
if (node.object.type === AST_NODE_TYPES25.MemberExpression && node.object.object.type === AST_NODE_TYPES25.Identifier && node.object.object.name === "process" && node.object.property.type === AST_NODE_TYPES25.Identifier && node.object.property.name === "env" && node.property.type === AST_NODE_TYPES25.Identifier) {
|
|
1996
2037
|
const envVarName = node.property.name;
|
|
1997
2038
|
if (!envVarName.startsWith("NEXT_PUBLIC_") && envVarName !== "NODE_ENV") {
|
|
1998
2039
|
context.report({
|
|
@@ -2011,11 +2052,11 @@ var nextjsRequirePublicEnv = createRule25({
|
|
|
2011
2052
|
var nextjs_require_public_env_default = nextjsRequirePublicEnv;
|
|
2012
2053
|
|
|
2013
2054
|
// src/rules/no-complex-inline-return.ts
|
|
2014
|
-
import { AST_NODE_TYPES as
|
|
2015
|
-
var
|
|
2055
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26, ESLintUtils as ESLintUtils27 } from "@typescript-eslint/utils";
|
|
2056
|
+
var createRule27 = ESLintUtils27.RuleCreator(
|
|
2016
2057
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2017
2058
|
);
|
|
2018
|
-
var noComplexInlineReturn =
|
|
2059
|
+
var noComplexInlineReturn = createRule27({
|
|
2019
2060
|
name: "no-complex-inline-return",
|
|
2020
2061
|
meta: {
|
|
2021
2062
|
type: "suggestion",
|
|
@@ -2031,13 +2072,13 @@ var noComplexInlineReturn = createRule26({
|
|
|
2031
2072
|
create(context) {
|
|
2032
2073
|
const isComplexExpression = (node) => {
|
|
2033
2074
|
if (!node) return false;
|
|
2034
|
-
if (node.type ===
|
|
2075
|
+
if (node.type === AST_NODE_TYPES26.ConditionalExpression) {
|
|
2035
2076
|
return true;
|
|
2036
2077
|
}
|
|
2037
|
-
if (node.type ===
|
|
2078
|
+
if (node.type === AST_NODE_TYPES26.LogicalExpression) {
|
|
2038
2079
|
return true;
|
|
2039
2080
|
}
|
|
2040
|
-
if (node.type ===
|
|
2081
|
+
if (node.type === AST_NODE_TYPES26.NewExpression) {
|
|
2041
2082
|
return true;
|
|
2042
2083
|
}
|
|
2043
2084
|
return false;
|
|
@@ -2057,11 +2098,11 @@ var noComplexInlineReturn = createRule26({
|
|
|
2057
2098
|
var no_complex_inline_return_default = noComplexInlineReturn;
|
|
2058
2099
|
|
|
2059
2100
|
// src/rules/no-direct-date.ts
|
|
2060
|
-
import { AST_NODE_TYPES as
|
|
2061
|
-
var
|
|
2101
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27, ESLintUtils as ESLintUtils28 } from "@typescript-eslint/utils";
|
|
2102
|
+
var createRule28 = ESLintUtils28.RuleCreator(
|
|
2062
2103
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2063
2104
|
);
|
|
2064
|
-
var noDirectDate =
|
|
2105
|
+
var noDirectDate = createRule28({
|
|
2065
2106
|
name: "no-direct-date",
|
|
2066
2107
|
meta: {
|
|
2067
2108
|
type: "problem",
|
|
@@ -2079,7 +2120,7 @@ var noDirectDate = createRule27({
|
|
|
2079
2120
|
create(context) {
|
|
2080
2121
|
return {
|
|
2081
2122
|
NewExpression(node) {
|
|
2082
|
-
if (node.callee.type ===
|
|
2123
|
+
if (node.callee.type === AST_NODE_TYPES27.Identifier && node.callee.name === "Date") {
|
|
2083
2124
|
context.report({
|
|
2084
2125
|
node,
|
|
2085
2126
|
messageId: "noNewDate"
|
|
@@ -2087,7 +2128,7 @@ var noDirectDate = createRule27({
|
|
|
2087
2128
|
}
|
|
2088
2129
|
},
|
|
2089
2130
|
CallExpression(node) {
|
|
2090
|
-
if (node.callee.type ===
|
|
2131
|
+
if (node.callee.type === AST_NODE_TYPES27.MemberExpression && node.callee.object.type === AST_NODE_TYPES27.Identifier && node.callee.object.name === "Date" && node.callee.property.type === AST_NODE_TYPES27.Identifier) {
|
|
2091
2132
|
const methodName = node.callee.property.name;
|
|
2092
2133
|
if (methodName === "now") {
|
|
2093
2134
|
context.report({
|
|
@@ -2110,11 +2151,11 @@ var no_direct_date_default = noDirectDate;
|
|
|
2110
2151
|
|
|
2111
2152
|
// src/rules/no-emoji.ts
|
|
2112
2153
|
import emojiRegex from "emoji-regex";
|
|
2113
|
-
import { ESLintUtils as
|
|
2114
|
-
var
|
|
2154
|
+
import { ESLintUtils as ESLintUtils29 } from "@typescript-eslint/utils";
|
|
2155
|
+
var createRule29 = ESLintUtils29.RuleCreator(
|
|
2115
2156
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2116
2157
|
);
|
|
2117
|
-
var noEmoji =
|
|
2158
|
+
var noEmoji = createRule29({
|
|
2118
2159
|
name: "no-emoji",
|
|
2119
2160
|
meta: {
|
|
2120
2161
|
type: "problem",
|
|
@@ -2148,11 +2189,11 @@ var noEmoji = createRule28({
|
|
|
2148
2189
|
var no_emoji_default = noEmoji;
|
|
2149
2190
|
|
|
2150
2191
|
// src/rules/no-env-fallback.ts
|
|
2151
|
-
import { AST_NODE_TYPES as
|
|
2152
|
-
var
|
|
2192
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28, ESLintUtils as ESLintUtils30 } from "@typescript-eslint/utils";
|
|
2193
|
+
var createRule30 = ESLintUtils30.RuleCreator(
|
|
2153
2194
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2154
2195
|
);
|
|
2155
|
-
var noEnvFallback =
|
|
2196
|
+
var noEnvFallback = createRule30({
|
|
2156
2197
|
name: "no-env-fallback",
|
|
2157
2198
|
meta: {
|
|
2158
2199
|
type: "problem",
|
|
@@ -2167,16 +2208,16 @@ var noEnvFallback = createRule29({
|
|
|
2167
2208
|
defaultOptions: [],
|
|
2168
2209
|
create(context) {
|
|
2169
2210
|
const isProcessEnvAccess = (node) => {
|
|
2170
|
-
if (node.type !==
|
|
2211
|
+
if (node.type !== AST_NODE_TYPES28.MemberExpression) {
|
|
2171
2212
|
return false;
|
|
2172
2213
|
}
|
|
2173
2214
|
const { object } = node;
|
|
2174
|
-
if (object.type !==
|
|
2215
|
+
if (object.type !== AST_NODE_TYPES28.MemberExpression) {
|
|
2175
2216
|
return false;
|
|
2176
2217
|
}
|
|
2177
2218
|
const processNode = object.object;
|
|
2178
2219
|
const envNode = object.property;
|
|
2179
|
-
return processNode.type ===
|
|
2220
|
+
return processNode.type === AST_NODE_TYPES28.Identifier && processNode.name === "process" && envNode.type === AST_NODE_TYPES28.Identifier && envNode.name === "env";
|
|
2180
2221
|
};
|
|
2181
2222
|
return {
|
|
2182
2223
|
LogicalExpression(node) {
|
|
@@ -2201,11 +2242,11 @@ var noEnvFallback = createRule29({
|
|
|
2201
2242
|
var no_env_fallback_default = noEnvFallback;
|
|
2202
2243
|
|
|
2203
2244
|
// src/rules/no-inline-default-export.ts
|
|
2204
|
-
import { AST_NODE_TYPES as
|
|
2205
|
-
var
|
|
2245
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29, ESLintUtils as ESLintUtils31 } from "@typescript-eslint/utils";
|
|
2246
|
+
var createRule31 = ESLintUtils31.RuleCreator(
|
|
2206
2247
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2207
2248
|
);
|
|
2208
|
-
var noInlineDefaultExport =
|
|
2249
|
+
var noInlineDefaultExport = createRule31({
|
|
2209
2250
|
name: "no-inline-default-export",
|
|
2210
2251
|
meta: {
|
|
2211
2252
|
type: "suggestion",
|
|
@@ -2224,7 +2265,7 @@ var noInlineDefaultExport = createRule30({
|
|
|
2224
2265
|
return {
|
|
2225
2266
|
ExportDefaultDeclaration(node) {
|
|
2226
2267
|
const { declaration } = node;
|
|
2227
|
-
if (declaration.type ===
|
|
2268
|
+
if (declaration.type === AST_NODE_TYPES29.FunctionDeclaration) {
|
|
2228
2269
|
if (declaration.id) {
|
|
2229
2270
|
context.report({
|
|
2230
2271
|
node,
|
|
@@ -2239,7 +2280,7 @@ var noInlineDefaultExport = createRule30({
|
|
|
2239
2280
|
});
|
|
2240
2281
|
}
|
|
2241
2282
|
}
|
|
2242
|
-
if (declaration.type ===
|
|
2283
|
+
if (declaration.type === AST_NODE_TYPES29.ClassDeclaration) {
|
|
2243
2284
|
if (declaration.id) {
|
|
2244
2285
|
context.report({
|
|
2245
2286
|
node,
|
|
@@ -2254,7 +2295,7 @@ var noInlineDefaultExport = createRule30({
|
|
|
2254
2295
|
});
|
|
2255
2296
|
}
|
|
2256
2297
|
}
|
|
2257
|
-
if (declaration.type ===
|
|
2298
|
+
if (declaration.type === AST_NODE_TYPES29.ArrowFunctionExpression || declaration.type === AST_NODE_TYPES29.FunctionExpression) {
|
|
2258
2299
|
context.report({
|
|
2259
2300
|
node,
|
|
2260
2301
|
messageId: "noAnonymousDefaultExport",
|
|
@@ -2267,14 +2308,14 @@ var noInlineDefaultExport = createRule30({
|
|
|
2267
2308
|
if (!declaration) {
|
|
2268
2309
|
return;
|
|
2269
2310
|
}
|
|
2270
|
-
if (declaration.type ===
|
|
2311
|
+
if (declaration.type === AST_NODE_TYPES29.FunctionDeclaration && declaration.id) {
|
|
2271
2312
|
context.report({
|
|
2272
2313
|
node,
|
|
2273
2314
|
messageId: "noInlineNamedExport",
|
|
2274
2315
|
data: { type: "function", name: declaration.id.name }
|
|
2275
2316
|
});
|
|
2276
2317
|
}
|
|
2277
|
-
if (declaration.type ===
|
|
2318
|
+
if (declaration.type === AST_NODE_TYPES29.ClassDeclaration && declaration.id) {
|
|
2278
2319
|
context.report({
|
|
2279
2320
|
node,
|
|
2280
2321
|
messageId: "noInlineNamedExport",
|
|
@@ -2288,15 +2329,15 @@ var noInlineDefaultExport = createRule30({
|
|
|
2288
2329
|
var no_inline_default_export_default = noInlineDefaultExport;
|
|
2289
2330
|
|
|
2290
2331
|
// src/rules/no-inline-nested-object.ts
|
|
2291
|
-
import { AST_NODE_TYPES as
|
|
2292
|
-
var
|
|
2332
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30, ESLintUtils as ESLintUtils32 } from "@typescript-eslint/utils";
|
|
2333
|
+
var createRule32 = ESLintUtils32.RuleCreator(
|
|
2293
2334
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2294
2335
|
);
|
|
2295
2336
|
function isObjectOrArray(node) {
|
|
2296
|
-
return node.type ===
|
|
2337
|
+
return node.type === AST_NODE_TYPES30.ObjectExpression || node.type === AST_NODE_TYPES30.ArrayExpression || node.type === AST_NODE_TYPES30.TSAsExpression;
|
|
2297
2338
|
}
|
|
2298
2339
|
function getInnerExpression(node) {
|
|
2299
|
-
if (node.type ===
|
|
2340
|
+
if (node.type === AST_NODE_TYPES30.TSAsExpression) {
|
|
2300
2341
|
return getInnerExpression(node.expression);
|
|
2301
2342
|
}
|
|
2302
2343
|
return node;
|
|
@@ -2305,10 +2346,10 @@ function arrayContainsOnlyPrimitives(node) {
|
|
|
2305
2346
|
return node.elements.every((el) => {
|
|
2306
2347
|
if (el === null) return true;
|
|
2307
2348
|
const inner = getInnerExpression(el);
|
|
2308
|
-
return inner.type ===
|
|
2349
|
+
return inner.type === AST_NODE_TYPES30.Literal || inner.type === AST_NODE_TYPES30.Identifier || inner.type === AST_NODE_TYPES30.TemplateLiteral || inner.type === AST_NODE_TYPES30.UnaryExpression;
|
|
2309
2350
|
});
|
|
2310
2351
|
}
|
|
2311
|
-
var noInlineNestedObject =
|
|
2352
|
+
var noInlineNestedObject = createRule32({
|
|
2312
2353
|
name: "no-inline-nested-object",
|
|
2313
2354
|
meta: {
|
|
2314
2355
|
type: "layout",
|
|
@@ -2330,17 +2371,17 @@ var noInlineNestedObject = createRule31({
|
|
|
2330
2371
|
return;
|
|
2331
2372
|
}
|
|
2332
2373
|
const valueNode = getInnerExpression(node.value);
|
|
2333
|
-
if (valueNode.type !==
|
|
2374
|
+
if (valueNode.type !== AST_NODE_TYPES30.ObjectExpression && valueNode.type !== AST_NODE_TYPES30.ArrayExpression) {
|
|
2334
2375
|
return;
|
|
2335
2376
|
}
|
|
2336
2377
|
if (!valueNode.loc) {
|
|
2337
2378
|
return;
|
|
2338
2379
|
}
|
|
2339
|
-
const elements = valueNode.type ===
|
|
2380
|
+
const elements = valueNode.type === AST_NODE_TYPES30.ObjectExpression ? valueNode.properties : valueNode.elements;
|
|
2340
2381
|
if (elements.length <= 1) {
|
|
2341
2382
|
return;
|
|
2342
2383
|
}
|
|
2343
|
-
if (valueNode.type ===
|
|
2384
|
+
if (valueNode.type === AST_NODE_TYPES30.ArrayExpression && arrayContainsOnlyPrimitives(valueNode)) {
|
|
2344
2385
|
return;
|
|
2345
2386
|
}
|
|
2346
2387
|
const isMultiline = valueNode.loc.start.line !== valueNode.loc.end.line;
|
|
@@ -2359,7 +2400,7 @@ var noInlineNestedObject = createRule31({
|
|
|
2359
2400
|
const indent = " ".repeat(node.loc?.start.column ?? 0);
|
|
2360
2401
|
const innerIndent = `${indent} `;
|
|
2361
2402
|
const elementTexts = elements.filter((el) => el !== null).map((el) => sourceCode.getText(el));
|
|
2362
|
-
const isObject = valueNode.type ===
|
|
2403
|
+
const isObject = valueNode.type === AST_NODE_TYPES30.ObjectExpression;
|
|
2363
2404
|
const openChar = isObject ? "{" : "[";
|
|
2364
2405
|
const closeChar = isObject ? "}" : "]";
|
|
2365
2406
|
const formattedElements = elementTexts.map((text) => `${innerIndent}${text},`).join("\n");
|
|
@@ -2376,20 +2417,20 @@ ${indent}${closeChar}`;
|
|
|
2376
2417
|
var no_inline_nested_object_default = noInlineNestedObject;
|
|
2377
2418
|
|
|
2378
2419
|
// src/rules/no-inline-return-properties.ts
|
|
2379
|
-
import { AST_NODE_TYPES as
|
|
2380
|
-
var
|
|
2420
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31, ESLintUtils as ESLintUtils33 } from "@typescript-eslint/utils";
|
|
2421
|
+
var createRule33 = ESLintUtils33.RuleCreator(
|
|
2381
2422
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2382
2423
|
);
|
|
2383
2424
|
var isShorthandProperty = (property) => {
|
|
2384
|
-
if (property.type ===
|
|
2425
|
+
if (property.type === AST_NODE_TYPES31.SpreadElement) {
|
|
2385
2426
|
return true;
|
|
2386
2427
|
}
|
|
2387
|
-
if (property.type !==
|
|
2428
|
+
if (property.type !== AST_NODE_TYPES31.Property) {
|
|
2388
2429
|
return false;
|
|
2389
2430
|
}
|
|
2390
2431
|
return property.shorthand;
|
|
2391
2432
|
};
|
|
2392
|
-
var noInlineReturnProperties =
|
|
2433
|
+
var noInlineReturnProperties = createRule33({
|
|
2393
2434
|
name: "no-inline-return-properties",
|
|
2394
2435
|
meta: {
|
|
2395
2436
|
type: "suggestion",
|
|
@@ -2405,20 +2446,20 @@ var noInlineReturnProperties = createRule32({
|
|
|
2405
2446
|
create(context) {
|
|
2406
2447
|
return {
|
|
2407
2448
|
ReturnStatement(node) {
|
|
2408
|
-
if (!node.argument || node.argument.type !==
|
|
2449
|
+
if (!node.argument || node.argument.type !== AST_NODE_TYPES31.ObjectExpression) {
|
|
2409
2450
|
return;
|
|
2410
2451
|
}
|
|
2411
2452
|
node.argument.properties.forEach((property) => {
|
|
2412
2453
|
if (isShorthandProperty(property)) {
|
|
2413
2454
|
return;
|
|
2414
2455
|
}
|
|
2415
|
-
if (property.type !==
|
|
2456
|
+
if (property.type !== AST_NODE_TYPES31.Property) {
|
|
2416
2457
|
return;
|
|
2417
2458
|
}
|
|
2418
2459
|
let keyName = null;
|
|
2419
|
-
if (property.key.type ===
|
|
2460
|
+
if (property.key.type === AST_NODE_TYPES31.Identifier) {
|
|
2420
2461
|
keyName = property.key.name;
|
|
2421
|
-
} else if (property.key.type ===
|
|
2462
|
+
} else if (property.key.type === AST_NODE_TYPES31.Literal) {
|
|
2422
2463
|
keyName = String(property.key.value);
|
|
2423
2464
|
}
|
|
2424
2465
|
context.report({
|
|
@@ -2434,8 +2475,8 @@ var noInlineReturnProperties = createRule32({
|
|
|
2434
2475
|
var no_inline_return_properties_default = noInlineReturnProperties;
|
|
2435
2476
|
|
|
2436
2477
|
// src/rules/no-lazy-identifiers.ts
|
|
2437
|
-
import { AST_NODE_TYPES as
|
|
2438
|
-
var
|
|
2478
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32, ESLintUtils as ESLintUtils34 } from "@typescript-eslint/utils";
|
|
2479
|
+
var createRule34 = ESLintUtils34.RuleCreator(
|
|
2439
2480
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2440
2481
|
);
|
|
2441
2482
|
var KEYBOARD_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm", "1234567890"];
|
|
@@ -2476,7 +2517,7 @@ var isLazyIdentifier = (name) => {
|
|
|
2476
2517
|
}
|
|
2477
2518
|
return false;
|
|
2478
2519
|
};
|
|
2479
|
-
var noLazyIdentifiers =
|
|
2520
|
+
var noLazyIdentifiers = createRule34({
|
|
2480
2521
|
name: "no-lazy-identifiers",
|
|
2481
2522
|
meta: {
|
|
2482
2523
|
type: "problem",
|
|
@@ -2502,27 +2543,27 @@ var noLazyIdentifiers = createRule33({
|
|
|
2502
2543
|
});
|
|
2503
2544
|
};
|
|
2504
2545
|
const checkPattern = (pattern) => {
|
|
2505
|
-
if (pattern.type ===
|
|
2546
|
+
if (pattern.type === AST_NODE_TYPES32.Identifier) {
|
|
2506
2547
|
checkIdentifier(pattern);
|
|
2507
|
-
} else if (pattern.type ===
|
|
2548
|
+
} else if (pattern.type === AST_NODE_TYPES32.ObjectPattern) {
|
|
2508
2549
|
pattern.properties.forEach((prop) => {
|
|
2509
|
-
if (prop.type ===
|
|
2550
|
+
if (prop.type === AST_NODE_TYPES32.Property && prop.value.type === AST_NODE_TYPES32.Identifier) {
|
|
2510
2551
|
checkIdentifier(prop.value);
|
|
2511
|
-
} else if (prop.type ===
|
|
2552
|
+
} else if (prop.type === AST_NODE_TYPES32.RestElement && prop.argument.type === AST_NODE_TYPES32.Identifier) {
|
|
2512
2553
|
checkIdentifier(prop.argument);
|
|
2513
2554
|
}
|
|
2514
2555
|
});
|
|
2515
|
-
} else if (pattern.type ===
|
|
2556
|
+
} else if (pattern.type === AST_NODE_TYPES32.ArrayPattern) {
|
|
2516
2557
|
pattern.elements.forEach((element) => {
|
|
2517
|
-
if (element?.type ===
|
|
2558
|
+
if (element?.type === AST_NODE_TYPES32.Identifier) {
|
|
2518
2559
|
checkIdentifier(element);
|
|
2519
|
-
} else if (element?.type ===
|
|
2560
|
+
} else if (element?.type === AST_NODE_TYPES32.RestElement && element.argument.type === AST_NODE_TYPES32.Identifier) {
|
|
2520
2561
|
checkIdentifier(element.argument);
|
|
2521
2562
|
}
|
|
2522
2563
|
});
|
|
2523
|
-
} else if (pattern.type ===
|
|
2564
|
+
} else if (pattern.type === AST_NODE_TYPES32.AssignmentPattern && pattern.left.type === AST_NODE_TYPES32.Identifier) {
|
|
2524
2565
|
checkIdentifier(pattern.left);
|
|
2525
|
-
} else if (pattern.type ===
|
|
2566
|
+
} else if (pattern.type === AST_NODE_TYPES32.RestElement && pattern.argument.type === AST_NODE_TYPES32.Identifier) {
|
|
2526
2567
|
checkIdentifier(pattern.argument);
|
|
2527
2568
|
}
|
|
2528
2569
|
};
|
|
@@ -2567,11 +2608,11 @@ var noLazyIdentifiers = createRule33({
|
|
|
2567
2608
|
var no_lazy_identifiers_default = noLazyIdentifiers;
|
|
2568
2609
|
|
|
2569
2610
|
// src/rules/no-logic-in-params.ts
|
|
2570
|
-
import { AST_NODE_TYPES as
|
|
2571
|
-
var
|
|
2611
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33, ESLintUtils as ESLintUtils35 } from "@typescript-eslint/utils";
|
|
2612
|
+
var createRule35 = ESLintUtils35.RuleCreator(
|
|
2572
2613
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2573
2614
|
);
|
|
2574
|
-
var noLogicInParams =
|
|
2615
|
+
var noLogicInParams = createRule35({
|
|
2575
2616
|
name: "no-logic-in-params",
|
|
2576
2617
|
meta: {
|
|
2577
2618
|
type: "suggestion",
|
|
@@ -2586,20 +2627,20 @@ var noLogicInParams = createRule34({
|
|
|
2586
2627
|
defaultOptions: [],
|
|
2587
2628
|
create(context) {
|
|
2588
2629
|
const isComplexExpression = (node) => {
|
|
2589
|
-
if (node.type ===
|
|
2630
|
+
if (node.type === AST_NODE_TYPES33.SpreadElement) {
|
|
2590
2631
|
return false;
|
|
2591
2632
|
}
|
|
2592
|
-
if (node.type ===
|
|
2633
|
+
if (node.type === AST_NODE_TYPES33.ConditionalExpression) {
|
|
2593
2634
|
return true;
|
|
2594
2635
|
}
|
|
2595
|
-
if (node.type ===
|
|
2636
|
+
if (node.type === AST_NODE_TYPES33.LogicalExpression) {
|
|
2596
2637
|
return true;
|
|
2597
2638
|
}
|
|
2598
|
-
if (node.type ===
|
|
2639
|
+
if (node.type === AST_NODE_TYPES33.BinaryExpression) {
|
|
2599
2640
|
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
2600
2641
|
return logicalOperators.includes(node.operator);
|
|
2601
2642
|
}
|
|
2602
|
-
if (node.type ===
|
|
2643
|
+
if (node.type === AST_NODE_TYPES33.UnaryExpression) {
|
|
2603
2644
|
return node.operator === "!";
|
|
2604
2645
|
}
|
|
2605
2646
|
return false;
|
|
@@ -2612,7 +2653,7 @@ var noLogicInParams = createRule34({
|
|
|
2612
2653
|
messageId: "noLogicInParams"
|
|
2613
2654
|
});
|
|
2614
2655
|
}
|
|
2615
|
-
if (arg.type ===
|
|
2656
|
+
if (arg.type === AST_NODE_TYPES33.ArrayExpression) {
|
|
2616
2657
|
arg.elements.forEach((element) => {
|
|
2617
2658
|
if (element && isComplexExpression(element)) {
|
|
2618
2659
|
context.report({
|
|
@@ -2637,46 +2678,46 @@ var noLogicInParams = createRule34({
|
|
|
2637
2678
|
var no_logic_in_params_default = noLogicInParams;
|
|
2638
2679
|
|
|
2639
2680
|
// src/rules/no-misleading-constant-case.ts
|
|
2640
|
-
import { AST_NODE_TYPES as
|
|
2641
|
-
var
|
|
2681
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34, ESLintUtils as ESLintUtils36 } from "@typescript-eslint/utils";
|
|
2682
|
+
var createRule36 = ESLintUtils36.RuleCreator(
|
|
2642
2683
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2643
2684
|
);
|
|
2644
2685
|
var SCREAMING_SNAKE_CASE_REGEX3 = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
2645
|
-
var isAsConstAssertion2 = (node) => node.type ===
|
|
2686
|
+
var isAsConstAssertion2 = (node) => node.type === AST_NODE_TYPES34.TSAsExpression && node.typeAnnotation.type === AST_NODE_TYPES34.TSTypeReference && node.typeAnnotation.typeName.type === AST_NODE_TYPES34.Identifier && node.typeAnnotation.typeName.name === "const";
|
|
2646
2687
|
var isStaticValue3 = (init) => {
|
|
2647
2688
|
if (isAsConstAssertion2(init)) {
|
|
2648
2689
|
return true;
|
|
2649
2690
|
}
|
|
2650
|
-
if (init.type ===
|
|
2691
|
+
if (init.type === AST_NODE_TYPES34.Literal) {
|
|
2651
2692
|
return true;
|
|
2652
2693
|
}
|
|
2653
|
-
if (init.type ===
|
|
2694
|
+
if (init.type === AST_NODE_TYPES34.UnaryExpression && init.argument.type === AST_NODE_TYPES34.Literal) {
|
|
2654
2695
|
return true;
|
|
2655
2696
|
}
|
|
2656
|
-
if (init.type ===
|
|
2697
|
+
if (init.type === AST_NODE_TYPES34.TemplateLiteral && init.expressions.length === 0) {
|
|
2657
2698
|
return true;
|
|
2658
2699
|
}
|
|
2659
|
-
if (init.type ===
|
|
2660
|
-
return init.elements.every((el) => el !== null && el.type !==
|
|
2700
|
+
if (init.type === AST_NODE_TYPES34.ArrayExpression) {
|
|
2701
|
+
return init.elements.every((el) => el !== null && el.type !== AST_NODE_TYPES34.SpreadElement && isStaticValue3(el));
|
|
2661
2702
|
}
|
|
2662
|
-
if (init.type ===
|
|
2703
|
+
if (init.type === AST_NODE_TYPES34.ObjectExpression) {
|
|
2663
2704
|
return init.properties.every(
|
|
2664
|
-
(prop) => prop.type ===
|
|
2705
|
+
(prop) => prop.type === AST_NODE_TYPES34.Property && isStaticValue3(prop.value)
|
|
2665
2706
|
);
|
|
2666
2707
|
}
|
|
2667
2708
|
return false;
|
|
2668
2709
|
};
|
|
2669
2710
|
var isGlobalScope3 = (node) => {
|
|
2670
2711
|
const { parent } = node;
|
|
2671
|
-
if (parent.type ===
|
|
2712
|
+
if (parent.type === AST_NODE_TYPES34.Program) {
|
|
2672
2713
|
return true;
|
|
2673
2714
|
}
|
|
2674
|
-
if (parent.type ===
|
|
2715
|
+
if (parent.type === AST_NODE_TYPES34.ExportNamedDeclaration && parent.parent?.type === AST_NODE_TYPES34.Program) {
|
|
2675
2716
|
return true;
|
|
2676
2717
|
}
|
|
2677
2718
|
return false;
|
|
2678
2719
|
};
|
|
2679
|
-
var noMisleadingConstantCase =
|
|
2720
|
+
var noMisleadingConstantCase = createRule36({
|
|
2680
2721
|
name: "no-misleading-constant-case",
|
|
2681
2722
|
meta: {
|
|
2682
2723
|
type: "suggestion",
|
|
@@ -2695,7 +2736,7 @@ var noMisleadingConstantCase = createRule35({
|
|
|
2695
2736
|
return {
|
|
2696
2737
|
VariableDeclaration(node) {
|
|
2697
2738
|
node.declarations.forEach((declarator) => {
|
|
2698
|
-
if (declarator.id.type !==
|
|
2739
|
+
if (declarator.id.type !== AST_NODE_TYPES34.Identifier) {
|
|
2699
2740
|
return;
|
|
2700
2741
|
}
|
|
2701
2742
|
const { name } = declarator.id;
|
|
@@ -2736,11 +2777,11 @@ var noMisleadingConstantCase = createRule35({
|
|
|
2736
2777
|
var no_misleading_constant_case_default = noMisleadingConstantCase;
|
|
2737
2778
|
|
|
2738
2779
|
// src/rules/no-nested-interface-declaration.ts
|
|
2739
|
-
import { AST_NODE_TYPES as
|
|
2740
|
-
var
|
|
2780
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35, ESLintUtils as ESLintUtils37 } from "@typescript-eslint/utils";
|
|
2781
|
+
var createRule37 = ESLintUtils37.RuleCreator(
|
|
2741
2782
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2742
2783
|
);
|
|
2743
|
-
var noNestedInterfaceDeclaration =
|
|
2784
|
+
var noNestedInterfaceDeclaration = createRule37({
|
|
2744
2785
|
name: "no-nested-interface-declaration",
|
|
2745
2786
|
meta: {
|
|
2746
2787
|
type: "suggestion",
|
|
@@ -2761,15 +2802,15 @@ var noNestedInterfaceDeclaration = createRule36({
|
|
|
2761
2802
|
return;
|
|
2762
2803
|
}
|
|
2763
2804
|
const { typeAnnotation } = node.typeAnnotation;
|
|
2764
|
-
if (typeAnnotation.type ===
|
|
2805
|
+
if (typeAnnotation.type === AST_NODE_TYPES35.TSTypeLiteral) {
|
|
2765
2806
|
context.report({
|
|
2766
2807
|
node: typeAnnotation,
|
|
2767
2808
|
messageId: "noNestedInterface"
|
|
2768
2809
|
});
|
|
2769
2810
|
return;
|
|
2770
2811
|
}
|
|
2771
|
-
if (typeAnnotation.type ===
|
|
2772
|
-
if (typeAnnotation.elementType.type ===
|
|
2812
|
+
if (typeAnnotation.type === AST_NODE_TYPES35.TSArrayType) {
|
|
2813
|
+
if (typeAnnotation.elementType.type === AST_NODE_TYPES35.TSTypeLiteral) {
|
|
2773
2814
|
context.report({
|
|
2774
2815
|
node: typeAnnotation.elementType,
|
|
2775
2816
|
messageId: "noNestedInterface"
|
|
@@ -2777,9 +2818,9 @@ var noNestedInterfaceDeclaration = createRule36({
|
|
|
2777
2818
|
}
|
|
2778
2819
|
return;
|
|
2779
2820
|
}
|
|
2780
|
-
if (typeAnnotation.type ===
|
|
2821
|
+
if (typeAnnotation.type === AST_NODE_TYPES35.TSTypeReference && typeAnnotation.typeArguments) {
|
|
2781
2822
|
typeAnnotation.typeArguments.params.forEach((param) => {
|
|
2782
|
-
if (param.type ===
|
|
2823
|
+
if (param.type === AST_NODE_TYPES35.TSTypeLiteral) {
|
|
2783
2824
|
context.report({
|
|
2784
2825
|
node: param,
|
|
2785
2826
|
messageId: "noNestedInterface"
|
|
@@ -2794,11 +2835,11 @@ var noNestedInterfaceDeclaration = createRule36({
|
|
|
2794
2835
|
var no_nested_interface_declaration_default = noNestedInterfaceDeclaration;
|
|
2795
2836
|
|
|
2796
2837
|
// src/rules/no-nested-ternary.ts
|
|
2797
|
-
import { AST_NODE_TYPES as
|
|
2798
|
-
var
|
|
2838
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36, ESLintUtils as ESLintUtils38 } from "@typescript-eslint/utils";
|
|
2839
|
+
var createRule38 = ESLintUtils38.RuleCreator(
|
|
2799
2840
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2800
2841
|
);
|
|
2801
|
-
var noNestedTernary =
|
|
2842
|
+
var noNestedTernary = createRule38({
|
|
2802
2843
|
name: "no-nested-ternary",
|
|
2803
2844
|
meta: {
|
|
2804
2845
|
type: "suggestion",
|
|
@@ -2815,13 +2856,13 @@ var noNestedTernary = createRule37({
|
|
|
2815
2856
|
return {
|
|
2816
2857
|
ConditionalExpression(node) {
|
|
2817
2858
|
const { consequent, alternate } = node;
|
|
2818
|
-
if (consequent.type ===
|
|
2859
|
+
if (consequent.type === AST_NODE_TYPES36.ConditionalExpression) {
|
|
2819
2860
|
context.report({
|
|
2820
2861
|
node: consequent,
|
|
2821
2862
|
messageId: "noNestedTernary"
|
|
2822
2863
|
});
|
|
2823
2864
|
}
|
|
2824
|
-
if (alternate.type ===
|
|
2865
|
+
if (alternate.type === AST_NODE_TYPES36.ConditionalExpression) {
|
|
2825
2866
|
context.report({
|
|
2826
2867
|
node: alternate,
|
|
2827
2868
|
messageId: "noNestedTernary"
|
|
@@ -2834,11 +2875,11 @@ var noNestedTernary = createRule37({
|
|
|
2834
2875
|
var no_nested_ternary_default = noNestedTernary;
|
|
2835
2876
|
|
|
2836
2877
|
// src/rules/no-relative-imports.ts
|
|
2837
|
-
import { AST_NODE_TYPES as
|
|
2838
|
-
var
|
|
2878
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37, ESLintUtils as ESLintUtils39 } from "@typescript-eslint/utils";
|
|
2879
|
+
var createRule39 = ESLintUtils39.RuleCreator(
|
|
2839
2880
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2840
2881
|
);
|
|
2841
|
-
var noRelativeImports =
|
|
2882
|
+
var noRelativeImports = createRule39({
|
|
2842
2883
|
name: "no-relative-imports",
|
|
2843
2884
|
meta: {
|
|
2844
2885
|
type: "suggestion",
|
|
@@ -2862,22 +2903,22 @@ var noRelativeImports = createRule38({
|
|
|
2862
2903
|
};
|
|
2863
2904
|
return {
|
|
2864
2905
|
ImportDeclaration(node) {
|
|
2865
|
-
if (node.source.type ===
|
|
2906
|
+
if (node.source.type === AST_NODE_TYPES37.Literal && typeof node.source.value === "string") {
|
|
2866
2907
|
checkImportPath(node.source.value, node);
|
|
2867
2908
|
}
|
|
2868
2909
|
},
|
|
2869
2910
|
ImportExpression(node) {
|
|
2870
|
-
if (node.source.type ===
|
|
2911
|
+
if (node.source.type === AST_NODE_TYPES37.Literal && typeof node.source.value === "string") {
|
|
2871
2912
|
checkImportPath(node.source.value, node);
|
|
2872
2913
|
}
|
|
2873
2914
|
},
|
|
2874
2915
|
ExportNamedDeclaration(node) {
|
|
2875
|
-
if (node.source?.type ===
|
|
2916
|
+
if (node.source?.type === AST_NODE_TYPES37.Literal && typeof node.source.value === "string") {
|
|
2876
2917
|
checkImportPath(node.source.value, node);
|
|
2877
2918
|
}
|
|
2878
2919
|
},
|
|
2879
2920
|
ExportAllDeclaration(node) {
|
|
2880
|
-
if (node.source.type ===
|
|
2921
|
+
if (node.source.type === AST_NODE_TYPES37.Literal && typeof node.source.value === "string") {
|
|
2881
2922
|
checkImportPath(node.source.value, node);
|
|
2882
2923
|
}
|
|
2883
2924
|
}
|
|
@@ -2887,8 +2928,8 @@ var noRelativeImports = createRule38({
|
|
|
2887
2928
|
var no_relative_imports_default = noRelativeImports;
|
|
2888
2929
|
|
|
2889
2930
|
// src/rules/no-single-char-variables.ts
|
|
2890
|
-
import { AST_NODE_TYPES as
|
|
2891
|
-
var
|
|
2931
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38, ESLintUtils as ESLintUtils40 } from "@typescript-eslint/utils";
|
|
2932
|
+
var createRule40 = ESLintUtils40.RuleCreator(
|
|
2892
2933
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
2893
2934
|
);
|
|
2894
2935
|
var ALLOWED_IN_FOR_LOOPS = /* @__PURE__ */ new Set(["i", "j", "k", "n"]);
|
|
@@ -2900,7 +2941,7 @@ var isForLoopInit = (node) => {
|
|
|
2900
2941
|
if (!parentNode) {
|
|
2901
2942
|
return false;
|
|
2902
2943
|
}
|
|
2903
|
-
if (parentNode.type ===
|
|
2944
|
+
if (parentNode.type === AST_NODE_TYPES38.ForStatement) {
|
|
2904
2945
|
const { init } = parentNode;
|
|
2905
2946
|
if (init && init === current) {
|
|
2906
2947
|
return true;
|
|
@@ -2919,7 +2960,7 @@ var isAllowedInContext = (name, node) => {
|
|
|
2919
2960
|
}
|
|
2920
2961
|
return false;
|
|
2921
2962
|
};
|
|
2922
|
-
var noSingleCharVariables =
|
|
2963
|
+
var noSingleCharVariables = createRule40({
|
|
2923
2964
|
name: "no-single-char-variables",
|
|
2924
2965
|
meta: {
|
|
2925
2966
|
type: "suggestion",
|
|
@@ -2948,27 +2989,27 @@ var noSingleCharVariables = createRule39({
|
|
|
2948
2989
|
});
|
|
2949
2990
|
};
|
|
2950
2991
|
const checkPattern = (pattern, declarationNode) => {
|
|
2951
|
-
if (pattern.type ===
|
|
2992
|
+
if (pattern.type === AST_NODE_TYPES38.Identifier) {
|
|
2952
2993
|
checkIdentifier(pattern, declarationNode);
|
|
2953
|
-
} else if (pattern.type ===
|
|
2994
|
+
} else if (pattern.type === AST_NODE_TYPES38.ObjectPattern) {
|
|
2954
2995
|
pattern.properties.forEach((prop) => {
|
|
2955
|
-
if (prop.type ===
|
|
2996
|
+
if (prop.type === AST_NODE_TYPES38.Property && prop.value.type === AST_NODE_TYPES38.Identifier) {
|
|
2956
2997
|
checkIdentifier(prop.value, declarationNode);
|
|
2957
|
-
} else if (prop.type ===
|
|
2998
|
+
} else if (prop.type === AST_NODE_TYPES38.RestElement && prop.argument.type === AST_NODE_TYPES38.Identifier) {
|
|
2958
2999
|
checkIdentifier(prop.argument, declarationNode);
|
|
2959
3000
|
}
|
|
2960
3001
|
});
|
|
2961
|
-
} else if (pattern.type ===
|
|
3002
|
+
} else if (pattern.type === AST_NODE_TYPES38.ArrayPattern) {
|
|
2962
3003
|
pattern.elements.forEach((element) => {
|
|
2963
|
-
if (element?.type ===
|
|
3004
|
+
if (element?.type === AST_NODE_TYPES38.Identifier) {
|
|
2964
3005
|
checkIdentifier(element, declarationNode);
|
|
2965
|
-
} else if (element?.type ===
|
|
3006
|
+
} else if (element?.type === AST_NODE_TYPES38.RestElement && element.argument.type === AST_NODE_TYPES38.Identifier) {
|
|
2966
3007
|
checkIdentifier(element.argument, declarationNode);
|
|
2967
3008
|
}
|
|
2968
3009
|
});
|
|
2969
|
-
} else if (pattern.type ===
|
|
3010
|
+
} else if (pattern.type === AST_NODE_TYPES38.AssignmentPattern && pattern.left.type === AST_NODE_TYPES38.Identifier) {
|
|
2970
3011
|
checkIdentifier(pattern.left, declarationNode);
|
|
2971
|
-
} else if (pattern.type ===
|
|
3012
|
+
} else if (pattern.type === AST_NODE_TYPES38.RestElement && pattern.argument.type === AST_NODE_TYPES38.Identifier) {
|
|
2972
3013
|
checkIdentifier(pattern.argument, declarationNode);
|
|
2973
3014
|
}
|
|
2974
3015
|
};
|
|
@@ -3002,11 +3043,11 @@ var noSingleCharVariables = createRule39({
|
|
|
3002
3043
|
var no_single_char_variables_default = noSingleCharVariables;
|
|
3003
3044
|
|
|
3004
3045
|
// src/rules/prefer-async-await.ts
|
|
3005
|
-
import { AST_NODE_TYPES as
|
|
3006
|
-
var
|
|
3046
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39, ESLintUtils as ESLintUtils41 } from "@typescript-eslint/utils";
|
|
3047
|
+
var createRule41 = ESLintUtils41.RuleCreator(
|
|
3007
3048
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3008
3049
|
);
|
|
3009
|
-
var preferAsyncAwait =
|
|
3050
|
+
var preferAsyncAwait = createRule41({
|
|
3010
3051
|
name: "prefer-async-await",
|
|
3011
3052
|
meta: {
|
|
3012
3053
|
type: "suggestion",
|
|
@@ -3022,7 +3063,7 @@ var preferAsyncAwait = createRule40({
|
|
|
3022
3063
|
create(context) {
|
|
3023
3064
|
return {
|
|
3024
3065
|
CallExpression(node) {
|
|
3025
|
-
if (node.callee.type ===
|
|
3066
|
+
if (node.callee.type === AST_NODE_TYPES39.MemberExpression && node.callee.property.type === AST_NODE_TYPES39.Identifier && node.callee.property.name === "then") {
|
|
3026
3067
|
context.report({
|
|
3027
3068
|
node: node.callee.property,
|
|
3028
3069
|
messageId: "preferAsyncAwait"
|
|
@@ -3035,11 +3076,11 @@ var preferAsyncAwait = createRule40({
|
|
|
3035
3076
|
var prefer_async_await_default = preferAsyncAwait;
|
|
3036
3077
|
|
|
3037
3078
|
// src/rules/prefer-destructuring-params.ts
|
|
3038
|
-
import { AST_NODE_TYPES as
|
|
3039
|
-
var
|
|
3079
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40, ESLintUtils as ESLintUtils42 } from "@typescript-eslint/utils";
|
|
3080
|
+
var createRule42 = ESLintUtils42.RuleCreator(
|
|
3040
3081
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3041
3082
|
);
|
|
3042
|
-
var preferDestructuringParams =
|
|
3083
|
+
var preferDestructuringParams = createRule42({
|
|
3043
3084
|
name: "prefer-destructuring-params",
|
|
3044
3085
|
meta: {
|
|
3045
3086
|
type: "suggestion",
|
|
@@ -3055,18 +3096,18 @@ var preferDestructuringParams = createRule41({
|
|
|
3055
3096
|
create(context) {
|
|
3056
3097
|
const isCallbackFunction2 = (node) => {
|
|
3057
3098
|
const { parent } = node;
|
|
3058
|
-
return parent?.type ===
|
|
3099
|
+
return parent?.type === AST_NODE_TYPES40.CallExpression;
|
|
3059
3100
|
};
|
|
3060
3101
|
const isDeveloperFunction = (node) => {
|
|
3061
|
-
if (node.type ===
|
|
3102
|
+
if (node.type === AST_NODE_TYPES40.FunctionDeclaration) {
|
|
3062
3103
|
return true;
|
|
3063
3104
|
}
|
|
3064
|
-
if (node.type ===
|
|
3105
|
+
if (node.type === AST_NODE_TYPES40.FunctionExpression || node.type === AST_NODE_TYPES40.ArrowFunctionExpression) {
|
|
3065
3106
|
if (isCallbackFunction2(node)) {
|
|
3066
3107
|
return false;
|
|
3067
3108
|
}
|
|
3068
3109
|
const { parent } = node;
|
|
3069
|
-
return parent?.type ===
|
|
3110
|
+
return parent?.type === AST_NODE_TYPES40.VariableDeclarator || parent?.type === AST_NODE_TYPES40.AssignmentExpression || parent?.type === AST_NODE_TYPES40.Property || parent?.type === AST_NODE_TYPES40.MethodDefinition;
|
|
3070
3111
|
}
|
|
3071
3112
|
return false;
|
|
3072
3113
|
};
|
|
@@ -3078,7 +3119,7 @@ var preferDestructuringParams = createRule41({
|
|
|
3078
3119
|
if (!isDeveloperFunction(node)) {
|
|
3079
3120
|
return;
|
|
3080
3121
|
}
|
|
3081
|
-
if (node.type ===
|
|
3122
|
+
if (node.type === AST_NODE_TYPES40.FunctionDeclaration && node.id) {
|
|
3082
3123
|
const functionName = node.id.name;
|
|
3083
3124
|
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
3084
3125
|
return;
|
|
@@ -3088,7 +3129,7 @@ var preferDestructuringParams = createRule41({
|
|
|
3088
3129
|
return;
|
|
3089
3130
|
}
|
|
3090
3131
|
const hasNonDestructuredParams = node.params.some(
|
|
3091
|
-
(param) => param.type !==
|
|
3132
|
+
(param) => param.type !== AST_NODE_TYPES40.ObjectPattern && param.type !== AST_NODE_TYPES40.RestElement
|
|
3092
3133
|
);
|
|
3093
3134
|
if (hasNonDestructuredParams) {
|
|
3094
3135
|
context.report({
|
|
@@ -3107,8 +3148,8 @@ var preferDestructuringParams = createRule41({
|
|
|
3107
3148
|
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
3108
3149
|
|
|
3109
3150
|
// src/rules/prefer-function-declaration.ts
|
|
3110
|
-
import { AST_NODE_TYPES as
|
|
3111
|
-
var
|
|
3151
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41, ESLintUtils as ESLintUtils43 } from "@typescript-eslint/utils";
|
|
3152
|
+
var createRule43 = ESLintUtils43.RuleCreator(
|
|
3112
3153
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3113
3154
|
);
|
|
3114
3155
|
var isTsFile = (filename) => filename.endsWith(".ts") && !filename.endsWith(".d.ts");
|
|
@@ -3117,33 +3158,33 @@ var isCallbackContext = (node) => {
|
|
|
3117
3158
|
if (!parent) {
|
|
3118
3159
|
return false;
|
|
3119
3160
|
}
|
|
3120
|
-
if (parent.type ===
|
|
3161
|
+
if (parent.type === AST_NODE_TYPES41.CallExpression && parent.arguments.includes(node)) {
|
|
3121
3162
|
return true;
|
|
3122
3163
|
}
|
|
3123
|
-
if (parent.type ===
|
|
3164
|
+
if (parent.type === AST_NODE_TYPES41.NewExpression && parent.arguments.includes(node)) {
|
|
3124
3165
|
return true;
|
|
3125
3166
|
}
|
|
3126
|
-
if (parent.type ===
|
|
3167
|
+
if (parent.type === AST_NODE_TYPES41.ReturnStatement) {
|
|
3127
3168
|
return true;
|
|
3128
3169
|
}
|
|
3129
|
-
if (parent.type ===
|
|
3170
|
+
if (parent.type === AST_NODE_TYPES41.Property) {
|
|
3130
3171
|
return true;
|
|
3131
3172
|
}
|
|
3132
|
-
if (parent.type ===
|
|
3173
|
+
if (parent.type === AST_NODE_TYPES41.ArrayExpression) {
|
|
3133
3174
|
return true;
|
|
3134
3175
|
}
|
|
3135
|
-
if (parent.type ===
|
|
3176
|
+
if (parent.type === AST_NODE_TYPES41.ConditionalExpression) {
|
|
3136
3177
|
return true;
|
|
3137
3178
|
}
|
|
3138
|
-
if (parent.type ===
|
|
3179
|
+
if (parent.type === AST_NODE_TYPES41.LogicalExpression) {
|
|
3139
3180
|
return true;
|
|
3140
3181
|
}
|
|
3141
|
-
if (parent.type ===
|
|
3182
|
+
if (parent.type === AST_NODE_TYPES41.AssignmentExpression && parent.left !== node) {
|
|
3142
3183
|
return true;
|
|
3143
3184
|
}
|
|
3144
3185
|
return false;
|
|
3145
3186
|
};
|
|
3146
|
-
var preferFunctionDeclaration =
|
|
3187
|
+
var preferFunctionDeclaration = createRule43({
|
|
3147
3188
|
name: "prefer-function-declaration",
|
|
3148
3189
|
meta: {
|
|
3149
3190
|
type: "suggestion",
|
|
@@ -3164,14 +3205,14 @@ var preferFunctionDeclaration = createRule42({
|
|
|
3164
3205
|
}
|
|
3165
3206
|
return {
|
|
3166
3207
|
VariableDeclarator(node) {
|
|
3167
|
-
if (node.id.type !==
|
|
3208
|
+
if (node.id.type !== AST_NODE_TYPES41.Identifier) {
|
|
3168
3209
|
return;
|
|
3169
3210
|
}
|
|
3170
3211
|
const { init } = node;
|
|
3171
3212
|
if (!init) {
|
|
3172
3213
|
return;
|
|
3173
3214
|
}
|
|
3174
|
-
if (init.type ===
|
|
3215
|
+
if (init.type === AST_NODE_TYPES41.ArrowFunctionExpression) {
|
|
3175
3216
|
if (isCallbackContext(init)) {
|
|
3176
3217
|
return;
|
|
3177
3218
|
}
|
|
@@ -3181,7 +3222,7 @@ var preferFunctionDeclaration = createRule42({
|
|
|
3181
3222
|
data: { name: node.id.name }
|
|
3182
3223
|
});
|
|
3183
3224
|
}
|
|
3184
|
-
if (init.type ===
|
|
3225
|
+
if (init.type === AST_NODE_TYPES41.FunctionExpression) {
|
|
3185
3226
|
if (isCallbackContext(init)) {
|
|
3186
3227
|
return;
|
|
3187
3228
|
}
|
|
@@ -3198,11 +3239,11 @@ var preferFunctionDeclaration = createRule42({
|
|
|
3198
3239
|
var prefer_function_declaration_default = preferFunctionDeclaration;
|
|
3199
3240
|
|
|
3200
3241
|
// src/rules/prefer-guard-clause.ts
|
|
3201
|
-
import { AST_NODE_TYPES as
|
|
3202
|
-
var
|
|
3242
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42, ESLintUtils as ESLintUtils44 } from "@typescript-eslint/utils";
|
|
3243
|
+
var createRule44 = ESLintUtils44.RuleCreator(
|
|
3203
3244
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3204
3245
|
);
|
|
3205
|
-
var preferGuardClause =
|
|
3246
|
+
var preferGuardClause = createRule44({
|
|
3206
3247
|
name: "prefer-guard-clause",
|
|
3207
3248
|
meta: {
|
|
3208
3249
|
type: "suggestion",
|
|
@@ -3219,8 +3260,8 @@ var preferGuardClause = createRule43({
|
|
|
3219
3260
|
return {
|
|
3220
3261
|
IfStatement(node) {
|
|
3221
3262
|
const { consequent } = node;
|
|
3222
|
-
if (consequent.type ===
|
|
3223
|
-
const hasNestedIf = consequent.body.some((statement) => statement.type ===
|
|
3263
|
+
if (consequent.type === AST_NODE_TYPES42.BlockStatement) {
|
|
3264
|
+
const hasNestedIf = consequent.body.some((statement) => statement.type === AST_NODE_TYPES42.IfStatement);
|
|
3224
3265
|
if (hasNestedIf && consequent.body.length === 1) {
|
|
3225
3266
|
context.report({
|
|
3226
3267
|
node,
|
|
@@ -3228,7 +3269,7 @@ var preferGuardClause = createRule43({
|
|
|
3228
3269
|
});
|
|
3229
3270
|
}
|
|
3230
3271
|
}
|
|
3231
|
-
if (consequent.type ===
|
|
3272
|
+
if (consequent.type === AST_NODE_TYPES42.IfStatement) {
|
|
3232
3273
|
context.report({
|
|
3233
3274
|
node,
|
|
3234
3275
|
messageId: "preferGuardClause"
|
|
@@ -3241,11 +3282,11 @@ var preferGuardClause = createRule43({
|
|
|
3241
3282
|
var prefer_guard_clause_default = preferGuardClause;
|
|
3242
3283
|
|
|
3243
3284
|
// src/rules/prefer-import-type.ts
|
|
3244
|
-
import { AST_NODE_TYPES as
|
|
3245
|
-
var
|
|
3285
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43, ESLintUtils as ESLintUtils45 } from "@typescript-eslint/utils";
|
|
3286
|
+
var createRule45 = ESLintUtils45.RuleCreator(
|
|
3246
3287
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3247
3288
|
);
|
|
3248
|
-
var preferImportType =
|
|
3289
|
+
var preferImportType = createRule45({
|
|
3249
3290
|
name: "prefer-import-type",
|
|
3250
3291
|
meta: {
|
|
3251
3292
|
type: "suggestion",
|
|
@@ -3264,22 +3305,22 @@ var preferImportType = createRule44({
|
|
|
3264
3305
|
let current = node;
|
|
3265
3306
|
while (current) {
|
|
3266
3307
|
switch (current.type) {
|
|
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
|
|
3308
|
+
case AST_NODE_TYPES43.TSTypeReference:
|
|
3309
|
+
case AST_NODE_TYPES43.TSTypeAnnotation:
|
|
3310
|
+
case AST_NODE_TYPES43.TSTypeParameterInstantiation:
|
|
3311
|
+
case AST_NODE_TYPES43.TSInterfaceHeritage:
|
|
3312
|
+
case AST_NODE_TYPES43.TSClassImplements:
|
|
3313
|
+
case AST_NODE_TYPES43.TSTypeQuery:
|
|
3314
|
+
case AST_NODE_TYPES43.TSTypeAssertion:
|
|
3315
|
+
case AST_NODE_TYPES43.TSAsExpression:
|
|
3316
|
+
case AST_NODE_TYPES43.TSSatisfiesExpression:
|
|
3317
|
+
case AST_NODE_TYPES43.TSTypeAliasDeclaration:
|
|
3318
|
+
case AST_NODE_TYPES43.TSInterfaceDeclaration:
|
|
3319
|
+
case AST_NODE_TYPES43.TSTypeParameter:
|
|
3320
|
+
case AST_NODE_TYPES43.TSQualifiedName:
|
|
3280
3321
|
return true;
|
|
3281
|
-
case
|
|
3282
|
-
case
|
|
3322
|
+
case AST_NODE_TYPES43.MemberExpression:
|
|
3323
|
+
case AST_NODE_TYPES43.Identifier:
|
|
3283
3324
|
current = current.parent;
|
|
3284
3325
|
break;
|
|
3285
3326
|
default:
|
|
@@ -3309,27 +3350,27 @@ var preferImportType = createRule44({
|
|
|
3309
3350
|
return false;
|
|
3310
3351
|
}
|
|
3311
3352
|
switch (parent.type) {
|
|
3312
|
-
case
|
|
3313
|
-
case
|
|
3314
|
-
case
|
|
3315
|
-
case
|
|
3316
|
-
case
|
|
3317
|
-
case
|
|
3318
|
-
case
|
|
3319
|
-
case
|
|
3320
|
-
case
|
|
3321
|
-
case
|
|
3322
|
-
case
|
|
3323
|
-
case
|
|
3324
|
-
case
|
|
3325
|
-
case
|
|
3326
|
-
case
|
|
3327
|
-
case
|
|
3328
|
-
case
|
|
3329
|
-
case
|
|
3330
|
-
case
|
|
3331
|
-
case
|
|
3332
|
-
case
|
|
3353
|
+
case AST_NODE_TYPES43.CallExpression:
|
|
3354
|
+
case AST_NODE_TYPES43.NewExpression:
|
|
3355
|
+
case AST_NODE_TYPES43.JSXOpeningElement:
|
|
3356
|
+
case AST_NODE_TYPES43.JSXClosingElement:
|
|
3357
|
+
case AST_NODE_TYPES43.MemberExpression:
|
|
3358
|
+
case AST_NODE_TYPES43.VariableDeclarator:
|
|
3359
|
+
case AST_NODE_TYPES43.TaggedTemplateExpression:
|
|
3360
|
+
case AST_NODE_TYPES43.SpreadElement:
|
|
3361
|
+
case AST_NODE_TYPES43.ExportSpecifier:
|
|
3362
|
+
case AST_NODE_TYPES43.ArrayExpression:
|
|
3363
|
+
case AST_NODE_TYPES43.ObjectExpression:
|
|
3364
|
+
case AST_NODE_TYPES43.BinaryExpression:
|
|
3365
|
+
case AST_NODE_TYPES43.LogicalExpression:
|
|
3366
|
+
case AST_NODE_TYPES43.UnaryExpression:
|
|
3367
|
+
case AST_NODE_TYPES43.ReturnStatement:
|
|
3368
|
+
case AST_NODE_TYPES43.ArrowFunctionExpression:
|
|
3369
|
+
case AST_NODE_TYPES43.ConditionalExpression:
|
|
3370
|
+
case AST_NODE_TYPES43.AwaitExpression:
|
|
3371
|
+
case AST_NODE_TYPES43.YieldExpression:
|
|
3372
|
+
case AST_NODE_TYPES43.Property:
|
|
3373
|
+
case AST_NODE_TYPES43.JSXExpressionContainer:
|
|
3333
3374
|
return true;
|
|
3334
3375
|
default:
|
|
3335
3376
|
return false;
|
|
@@ -3353,13 +3394,13 @@ var preferImportType = createRule44({
|
|
|
3353
3394
|
}
|
|
3354
3395
|
const scope = context.sourceCode.getScope(node);
|
|
3355
3396
|
const isTypeOnlyImport2 = node.specifiers.every((specifier) => {
|
|
3356
|
-
if (specifier.type ===
|
|
3397
|
+
if (specifier.type === AST_NODE_TYPES43.ImportDefaultSpecifier) {
|
|
3357
3398
|
return false;
|
|
3358
3399
|
}
|
|
3359
|
-
if (specifier.type ===
|
|
3400
|
+
if (specifier.type === AST_NODE_TYPES43.ImportNamespaceSpecifier) {
|
|
3360
3401
|
return false;
|
|
3361
3402
|
}
|
|
3362
|
-
if (specifier.type ===
|
|
3403
|
+
if (specifier.type === AST_NODE_TYPES43.ImportSpecifier) {
|
|
3363
3404
|
const localName = specifier.local.name;
|
|
3364
3405
|
return !isUsedAsValue(localName, scope);
|
|
3365
3406
|
}
|
|
@@ -3385,19 +3426,19 @@ var preferImportType = createRule44({
|
|
|
3385
3426
|
var prefer_import_type_default = preferImportType;
|
|
3386
3427
|
|
|
3387
3428
|
// src/rules/prefer-inline-literal-union.ts
|
|
3388
|
-
import { AST_NODE_TYPES as
|
|
3389
|
-
var
|
|
3429
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44, ESLintUtils as ESLintUtils46 } from "@typescript-eslint/utils";
|
|
3430
|
+
var createRule46 = ESLintUtils46.RuleCreator(
|
|
3390
3431
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3391
3432
|
);
|
|
3392
3433
|
function isLiteralUnionType(node) {
|
|
3393
|
-
if (node.type !==
|
|
3434
|
+
if (node.type !== AST_NODE_TYPES44.TSUnionType) {
|
|
3394
3435
|
return false;
|
|
3395
3436
|
}
|
|
3396
3437
|
return node.types.every(
|
|
3397
|
-
(member) => member.type ===
|
|
3438
|
+
(member) => member.type === AST_NODE_TYPES44.TSLiteralType || member.type === AST_NODE_TYPES44.TSNullKeyword || member.type === AST_NODE_TYPES44.TSUndefinedKeyword
|
|
3398
3439
|
);
|
|
3399
3440
|
}
|
|
3400
|
-
var preferInlineLiteralUnion =
|
|
3441
|
+
var preferInlineLiteralUnion = createRule46({
|
|
3401
3442
|
name: "prefer-inline-literal-union",
|
|
3402
3443
|
meta: {
|
|
3403
3444
|
type: "suggestion",
|
|
@@ -3424,10 +3465,10 @@ var preferInlineLiteralUnion = createRule45({
|
|
|
3424
3465
|
return;
|
|
3425
3466
|
}
|
|
3426
3467
|
const { typeAnnotation } = node.typeAnnotation;
|
|
3427
|
-
if (typeAnnotation.type !==
|
|
3468
|
+
if (typeAnnotation.type !== AST_NODE_TYPES44.TSTypeReference) {
|
|
3428
3469
|
return;
|
|
3429
3470
|
}
|
|
3430
|
-
if (typeAnnotation.typeName.type !==
|
|
3471
|
+
if (typeAnnotation.typeName.type !== AST_NODE_TYPES44.Identifier) {
|
|
3431
3472
|
return;
|
|
3432
3473
|
}
|
|
3433
3474
|
const aliasName = typeAnnotation.typeName.name;
|
|
@@ -3451,12 +3492,12 @@ var preferInlineLiteralUnion = createRule45({
|
|
|
3451
3492
|
var prefer_inline_literal_union_default = preferInlineLiteralUnion;
|
|
3452
3493
|
|
|
3453
3494
|
// src/rules/prefer-inline-type-export.ts
|
|
3454
|
-
import { AST_NODE_TYPES as
|
|
3455
|
-
var
|
|
3495
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45, ESLintUtils as ESLintUtils47 } from "@typescript-eslint/utils";
|
|
3496
|
+
var createRule47 = ESLintUtils47.RuleCreator(
|
|
3456
3497
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3457
3498
|
);
|
|
3458
|
-
var isTypeDeclaration = (node) => node.type ===
|
|
3459
|
-
var preferInlineTypeExport =
|
|
3499
|
+
var isTypeDeclaration = (node) => node.type === AST_NODE_TYPES45.TSInterfaceDeclaration || node.type === AST_NODE_TYPES45.TSTypeAliasDeclaration;
|
|
3500
|
+
var preferInlineTypeExport = createRule47({
|
|
3460
3501
|
name: "prefer-inline-type-export",
|
|
3461
3502
|
meta: {
|
|
3462
3503
|
type: "suggestion",
|
|
@@ -3473,12 +3514,12 @@ var preferInlineTypeExport = createRule46({
|
|
|
3473
3514
|
create(context) {
|
|
3474
3515
|
const typeDeclarations = /* @__PURE__ */ new Map();
|
|
3475
3516
|
function collectDeclaration(node) {
|
|
3476
|
-
if (node.parent.type !==
|
|
3517
|
+
if (node.parent.type !== AST_NODE_TYPES45.ExportNamedDeclaration) {
|
|
3477
3518
|
typeDeclarations.set(node.id.name, node);
|
|
3478
3519
|
}
|
|
3479
3520
|
}
|
|
3480
3521
|
function reportSpecifier(specifier, statement, declarationNode) {
|
|
3481
|
-
if (specifier.local.type !==
|
|
3522
|
+
if (specifier.local.type !== AST_NODE_TYPES45.Identifier) {
|
|
3482
3523
|
return;
|
|
3483
3524
|
}
|
|
3484
3525
|
const { name } = specifier.local;
|
|
@@ -3511,16 +3552,16 @@ var preferInlineTypeExport = createRule46({
|
|
|
3511
3552
|
return {
|
|
3512
3553
|
Program(node) {
|
|
3513
3554
|
node.body.forEach((statement) => {
|
|
3514
|
-
if (statement.type ===
|
|
3555
|
+
if (statement.type === AST_NODE_TYPES45.TSInterfaceDeclaration || statement.type === AST_NODE_TYPES45.TSTypeAliasDeclaration) {
|
|
3515
3556
|
collectDeclaration(statement);
|
|
3516
3557
|
}
|
|
3517
3558
|
});
|
|
3518
3559
|
node.body.forEach((statement) => {
|
|
3519
|
-
if (statement.type !==
|
|
3560
|
+
if (statement.type !== AST_NODE_TYPES45.ExportNamedDeclaration || statement.declaration !== null) {
|
|
3520
3561
|
return;
|
|
3521
3562
|
}
|
|
3522
3563
|
statement.specifiers.forEach((specifier) => {
|
|
3523
|
-
if (specifier.local.type !==
|
|
3564
|
+
if (specifier.local.type !== AST_NODE_TYPES45.Identifier) {
|
|
3524
3565
|
return;
|
|
3525
3566
|
}
|
|
3526
3567
|
const declarationNode = typeDeclarations.get(specifier.local.name);
|
|
@@ -3537,11 +3578,11 @@ var preferInlineTypeExport = createRule46({
|
|
|
3537
3578
|
var prefer_inline_type_export_default = preferInlineTypeExport;
|
|
3538
3579
|
|
|
3539
3580
|
// src/rules/prefer-interface-over-inline-types.ts
|
|
3540
|
-
import { AST_NODE_TYPES as
|
|
3541
|
-
var
|
|
3581
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46, ESLintUtils as ESLintUtils48 } from "@typescript-eslint/utils";
|
|
3582
|
+
var createRule48 = ESLintUtils48.RuleCreator(
|
|
3542
3583
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3543
3584
|
);
|
|
3544
|
-
var preferInterfaceOverInlineTypes =
|
|
3585
|
+
var preferInterfaceOverInlineTypes = createRule48({
|
|
3545
3586
|
name: "prefer-interface-over-inline-types",
|
|
3546
3587
|
meta: {
|
|
3547
3588
|
type: "suggestion",
|
|
@@ -3557,54 +3598,54 @@ var preferInterfaceOverInlineTypes = createRule47({
|
|
|
3557
3598
|
defaultOptions: [],
|
|
3558
3599
|
create(context) {
|
|
3559
3600
|
function hasJSXInConditional(node) {
|
|
3560
|
-
return node.consequent.type ===
|
|
3601
|
+
return node.consequent.type === AST_NODE_TYPES46.JSXElement || node.consequent.type === AST_NODE_TYPES46.JSXFragment || node.alternate.type === AST_NODE_TYPES46.JSXElement || node.alternate.type === AST_NODE_TYPES46.JSXFragment;
|
|
3561
3602
|
}
|
|
3562
3603
|
function hasJSXInLogical(node) {
|
|
3563
|
-
return node.right.type ===
|
|
3604
|
+
return node.right.type === AST_NODE_TYPES46.JSXElement || node.right.type === AST_NODE_TYPES46.JSXFragment;
|
|
3564
3605
|
}
|
|
3565
3606
|
function hasJSXReturn(block) {
|
|
3566
3607
|
return block.body.some((stmt) => {
|
|
3567
|
-
if (stmt.type ===
|
|
3568
|
-
return stmt.argument.type ===
|
|
3608
|
+
if (stmt.type === AST_NODE_TYPES46.ReturnStatement && stmt.argument) {
|
|
3609
|
+
return stmt.argument.type === AST_NODE_TYPES46.JSXElement || stmt.argument.type === AST_NODE_TYPES46.JSXFragment || stmt.argument.type === AST_NODE_TYPES46.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES46.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
3569
3610
|
}
|
|
3570
3611
|
return false;
|
|
3571
3612
|
});
|
|
3572
3613
|
}
|
|
3573
3614
|
function isReactComponent2(node) {
|
|
3574
|
-
if (node.type ===
|
|
3575
|
-
if (node.body.type ===
|
|
3615
|
+
if (node.type === AST_NODE_TYPES46.ArrowFunctionExpression) {
|
|
3616
|
+
if (node.body.type === AST_NODE_TYPES46.JSXElement || node.body.type === AST_NODE_TYPES46.JSXFragment) {
|
|
3576
3617
|
return true;
|
|
3577
3618
|
}
|
|
3578
|
-
if (node.body.type ===
|
|
3619
|
+
if (node.body.type === AST_NODE_TYPES46.BlockStatement) {
|
|
3579
3620
|
return hasJSXReturn(node.body);
|
|
3580
3621
|
}
|
|
3581
|
-
} else if (node.type ===
|
|
3582
|
-
if (node.body && node.body.type ===
|
|
3622
|
+
} else if (node.type === AST_NODE_TYPES46.FunctionExpression || node.type === AST_NODE_TYPES46.FunctionDeclaration) {
|
|
3623
|
+
if (node.body && node.body.type === AST_NODE_TYPES46.BlockStatement) {
|
|
3583
3624
|
return hasJSXReturn(node.body);
|
|
3584
3625
|
}
|
|
3585
3626
|
}
|
|
3586
3627
|
return false;
|
|
3587
3628
|
}
|
|
3588
3629
|
function isInlineTypeAnnotation(node) {
|
|
3589
|
-
if (node.type ===
|
|
3630
|
+
if (node.type === AST_NODE_TYPES46.TSTypeLiteral) {
|
|
3590
3631
|
return true;
|
|
3591
3632
|
}
|
|
3592
|
-
if (node.type ===
|
|
3593
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3633
|
+
if (node.type === AST_NODE_TYPES46.TSTypeReference && node.typeArguments) {
|
|
3634
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES46.TSTypeLiteral);
|
|
3594
3635
|
}
|
|
3595
|
-
if (node.type ===
|
|
3636
|
+
if (node.type === AST_NODE_TYPES46.TSUnionType) {
|
|
3596
3637
|
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
3597
3638
|
}
|
|
3598
3639
|
return false;
|
|
3599
3640
|
}
|
|
3600
3641
|
function hasInlineObjectType(node) {
|
|
3601
|
-
if (node.type ===
|
|
3642
|
+
if (node.type === AST_NODE_TYPES46.TSTypeLiteral) {
|
|
3602
3643
|
return true;
|
|
3603
3644
|
}
|
|
3604
|
-
if (node.type ===
|
|
3605
|
-
return node.typeArguments.params.some((param) => param.type ===
|
|
3645
|
+
if (node.type === AST_NODE_TYPES46.TSTypeReference && node.typeArguments) {
|
|
3646
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES46.TSTypeLiteral);
|
|
3606
3647
|
}
|
|
3607
|
-
if (node.type ===
|
|
3648
|
+
if (node.type === AST_NODE_TYPES46.TSUnionType) {
|
|
3608
3649
|
return node.types.some((type) => hasInlineObjectType(type));
|
|
3609
3650
|
}
|
|
3610
3651
|
return false;
|
|
@@ -3617,7 +3658,7 @@ var preferInterfaceOverInlineTypes = createRule47({
|
|
|
3617
3658
|
return;
|
|
3618
3659
|
}
|
|
3619
3660
|
const param = node.params[0];
|
|
3620
|
-
if (param.type ===
|
|
3661
|
+
if (param.type === AST_NODE_TYPES46.Identifier && param.typeAnnotation) {
|
|
3621
3662
|
const { typeAnnotation } = param.typeAnnotation;
|
|
3622
3663
|
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
3623
3664
|
context.report({
|
|
@@ -3637,11 +3678,11 @@ var preferInterfaceOverInlineTypes = createRule47({
|
|
|
3637
3678
|
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
3638
3679
|
|
|
3639
3680
|
// src/rules/prefer-jsx-template-literals.ts
|
|
3640
|
-
import { AST_NODE_TYPES as
|
|
3641
|
-
var
|
|
3681
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47, ESLintUtils as ESLintUtils49 } from "@typescript-eslint/utils";
|
|
3682
|
+
var createRule49 = ESLintUtils49.RuleCreator(
|
|
3642
3683
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3643
3684
|
);
|
|
3644
|
-
var preferJSXTemplateLiterals =
|
|
3685
|
+
var preferJSXTemplateLiterals = createRule49({
|
|
3645
3686
|
name: "prefer-jsx-template-literals",
|
|
3646
3687
|
meta: {
|
|
3647
3688
|
type: "suggestion",
|
|
@@ -3710,9 +3751,9 @@ var preferJSXTemplateLiterals = createRule48({
|
|
|
3710
3751
|
if (!child || !nextChild) {
|
|
3711
3752
|
return;
|
|
3712
3753
|
}
|
|
3713
|
-
if (child.type ===
|
|
3754
|
+
if (child.type === AST_NODE_TYPES47.JSXText && nextChild.type === AST_NODE_TYPES47.JSXExpressionContainer) {
|
|
3714
3755
|
handleTextBeforeExpression(child, nextChild);
|
|
3715
|
-
} else if (child.type ===
|
|
3756
|
+
} else if (child.type === AST_NODE_TYPES47.JSXExpressionContainer && nextChild.type === AST_NODE_TYPES47.JSXText) {
|
|
3716
3757
|
handleExpressionBeforeText(child, nextChild);
|
|
3717
3758
|
}
|
|
3718
3759
|
}
|
|
@@ -3725,11 +3766,11 @@ var preferJSXTemplateLiterals = createRule48({
|
|
|
3725
3766
|
var prefer_jsx_template_literals_default = preferJSXTemplateLiterals;
|
|
3726
3767
|
|
|
3727
3768
|
// src/rules/prefer-named-param-types.ts
|
|
3728
|
-
import { AST_NODE_TYPES as
|
|
3729
|
-
var
|
|
3769
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48, ESLintUtils as ESLintUtils50 } from "@typescript-eslint/utils";
|
|
3770
|
+
var createRule50 = ESLintUtils50.RuleCreator(
|
|
3730
3771
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3731
3772
|
);
|
|
3732
|
-
var preferNamedParamTypes =
|
|
3773
|
+
var preferNamedParamTypes = createRule50({
|
|
3733
3774
|
name: "prefer-named-param-types",
|
|
3734
3775
|
meta: {
|
|
3735
3776
|
type: "suggestion",
|
|
@@ -3744,16 +3785,16 @@ var preferNamedParamTypes = createRule49({
|
|
|
3744
3785
|
defaultOptions: [],
|
|
3745
3786
|
create(context) {
|
|
3746
3787
|
function hasInlineObjectType(param) {
|
|
3747
|
-
if (param.type ===
|
|
3788
|
+
if (param.type === AST_NODE_TYPES48.AssignmentPattern) {
|
|
3748
3789
|
return hasInlineObjectType(param.left);
|
|
3749
3790
|
}
|
|
3750
|
-
if (param.type ===
|
|
3751
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3791
|
+
if (param.type === AST_NODE_TYPES48.ObjectPattern) {
|
|
3792
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES48.TSTypeLiteral) {
|
|
3752
3793
|
return true;
|
|
3753
3794
|
}
|
|
3754
3795
|
}
|
|
3755
|
-
if (param.type ===
|
|
3756
|
-
if (param.typeAnnotation?.typeAnnotation.type ===
|
|
3796
|
+
if (param.type === AST_NODE_TYPES48.Identifier) {
|
|
3797
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES48.TSTypeLiteral) {
|
|
3757
3798
|
return true;
|
|
3758
3799
|
}
|
|
3759
3800
|
}
|
|
@@ -3787,11 +3828,11 @@ var preferNamedParamTypes = createRule49({
|
|
|
3787
3828
|
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
3788
3829
|
|
|
3789
3830
|
// src/rules/prefer-react-import-types.ts
|
|
3790
|
-
import { AST_NODE_TYPES as
|
|
3791
|
-
var
|
|
3831
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49, ESLintUtils as ESLintUtils51 } from "@typescript-eslint/utils";
|
|
3832
|
+
var createRule51 = ESLintUtils51.RuleCreator(
|
|
3792
3833
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3793
3834
|
);
|
|
3794
|
-
var preferReactImportTypes =
|
|
3835
|
+
var preferReactImportTypes = createRule51({
|
|
3795
3836
|
name: "prefer-react-import-types",
|
|
3796
3837
|
meta: {
|
|
3797
3838
|
type: "suggestion",
|
|
@@ -3867,7 +3908,7 @@ var preferReactImportTypes = createRule50({
|
|
|
3867
3908
|
]);
|
|
3868
3909
|
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
3869
3910
|
function checkMemberExpression(node) {
|
|
3870
|
-
if (node.object.type ===
|
|
3911
|
+
if (node.object.type === AST_NODE_TYPES49.Identifier && node.object.name === "React" && node.property.type === AST_NODE_TYPES49.Identifier && allReactExports.has(node.property.name)) {
|
|
3871
3912
|
const typeName = node.property.name;
|
|
3872
3913
|
const isType = reactTypes.has(typeName);
|
|
3873
3914
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -3884,7 +3925,7 @@ var preferReactImportTypes = createRule50({
|
|
|
3884
3925
|
return {
|
|
3885
3926
|
MemberExpression: checkMemberExpression,
|
|
3886
3927
|
"TSTypeReference > TSQualifiedName": (node) => {
|
|
3887
|
-
if (node.left.type ===
|
|
3928
|
+
if (node.left.type === AST_NODE_TYPES49.Identifier && node.left.name === "React" && node.right.type === AST_NODE_TYPES49.Identifier && allReactExports.has(node.right.name)) {
|
|
3888
3929
|
const typeName = node.right.name;
|
|
3889
3930
|
const isType = reactTypes.has(typeName);
|
|
3890
3931
|
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
@@ -3904,11 +3945,11 @@ var preferReactImportTypes = createRule50({
|
|
|
3904
3945
|
var prefer_react_import_types_default = preferReactImportTypes;
|
|
3905
3946
|
|
|
3906
3947
|
// src/rules/react-props-destructure.ts
|
|
3907
|
-
import { AST_NODE_TYPES as
|
|
3908
|
-
var
|
|
3948
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50, ESLintUtils as ESLintUtils52 } from "@typescript-eslint/utils";
|
|
3949
|
+
var createRule52 = ESLintUtils52.RuleCreator(
|
|
3909
3950
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3910
3951
|
);
|
|
3911
|
-
var reactPropsDestructure =
|
|
3952
|
+
var reactPropsDestructure = createRule52({
|
|
3912
3953
|
name: "react-props-destructure",
|
|
3913
3954
|
meta: {
|
|
3914
3955
|
type: "suggestion",
|
|
@@ -3924,29 +3965,29 @@ var reactPropsDestructure = createRule51({
|
|
|
3924
3965
|
defaultOptions: [],
|
|
3925
3966
|
create(context) {
|
|
3926
3967
|
function hasJSXInConditional(node) {
|
|
3927
|
-
return node.consequent.type ===
|
|
3968
|
+
return node.consequent.type === AST_NODE_TYPES50.JSXElement || node.consequent.type === AST_NODE_TYPES50.JSXFragment || node.alternate.type === AST_NODE_TYPES50.JSXElement || node.alternate.type === AST_NODE_TYPES50.JSXFragment;
|
|
3928
3969
|
}
|
|
3929
3970
|
function hasJSXInLogical(node) {
|
|
3930
|
-
return node.right.type ===
|
|
3971
|
+
return node.right.type === AST_NODE_TYPES50.JSXElement || node.right.type === AST_NODE_TYPES50.JSXFragment;
|
|
3931
3972
|
}
|
|
3932
3973
|
function hasJSXReturn(block) {
|
|
3933
3974
|
return block.body.some((stmt) => {
|
|
3934
|
-
if (stmt.type ===
|
|
3935
|
-
return stmt.argument.type ===
|
|
3975
|
+
if (stmt.type === AST_NODE_TYPES50.ReturnStatement && stmt.argument) {
|
|
3976
|
+
return stmt.argument.type === AST_NODE_TYPES50.JSXElement || stmt.argument.type === AST_NODE_TYPES50.JSXFragment || stmt.argument.type === AST_NODE_TYPES50.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES50.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
3936
3977
|
}
|
|
3937
3978
|
return false;
|
|
3938
3979
|
});
|
|
3939
3980
|
}
|
|
3940
3981
|
function isReactComponent2(node) {
|
|
3941
|
-
if (node.type ===
|
|
3942
|
-
if (node.body.type ===
|
|
3982
|
+
if (node.type === AST_NODE_TYPES50.ArrowFunctionExpression) {
|
|
3983
|
+
if (node.body.type === AST_NODE_TYPES50.JSXElement || node.body.type === AST_NODE_TYPES50.JSXFragment) {
|
|
3943
3984
|
return true;
|
|
3944
3985
|
}
|
|
3945
|
-
if (node.body.type ===
|
|
3986
|
+
if (node.body.type === AST_NODE_TYPES50.BlockStatement) {
|
|
3946
3987
|
return hasJSXReturn(node.body);
|
|
3947
3988
|
}
|
|
3948
|
-
} else if (node.type ===
|
|
3949
|
-
if (node.body && node.body.type ===
|
|
3989
|
+
} else if (node.type === AST_NODE_TYPES50.FunctionExpression || node.type === AST_NODE_TYPES50.FunctionDeclaration) {
|
|
3990
|
+
if (node.body && node.body.type === AST_NODE_TYPES50.BlockStatement) {
|
|
3950
3991
|
return hasJSXReturn(node.body);
|
|
3951
3992
|
}
|
|
3952
3993
|
}
|
|
@@ -3960,9 +4001,9 @@ var reactPropsDestructure = createRule51({
|
|
|
3960
4001
|
return;
|
|
3961
4002
|
}
|
|
3962
4003
|
const param = node.params[0];
|
|
3963
|
-
if (param.type ===
|
|
3964
|
-
const properties = param.properties.filter((prop) => prop.type ===
|
|
3965
|
-
if (prop.key.type ===
|
|
4004
|
+
if (param.type === AST_NODE_TYPES50.ObjectPattern) {
|
|
4005
|
+
const properties = param.properties.filter((prop) => prop.type === AST_NODE_TYPES50.Property).map((prop) => {
|
|
4006
|
+
if (prop.key.type === AST_NODE_TYPES50.Identifier) {
|
|
3966
4007
|
return prop.key.name;
|
|
3967
4008
|
}
|
|
3968
4009
|
return null;
|
|
@@ -3989,57 +4030,57 @@ var reactPropsDestructure = createRule51({
|
|
|
3989
4030
|
var react_props_destructure_default = reactPropsDestructure;
|
|
3990
4031
|
|
|
3991
4032
|
// src/rules/require-explicit-return-type.ts
|
|
3992
|
-
import { AST_NODE_TYPES as
|
|
3993
|
-
var
|
|
4033
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51, ESLintUtils as ESLintUtils53 } from "@typescript-eslint/utils";
|
|
4034
|
+
var createRule53 = ESLintUtils53.RuleCreator(
|
|
3994
4035
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
3995
4036
|
);
|
|
3996
4037
|
var isReactComponent = (node) => {
|
|
3997
|
-
if (node.type ===
|
|
4038
|
+
if (node.type === AST_NODE_TYPES51.ArrowFunctionExpression) {
|
|
3998
4039
|
const { parent } = node;
|
|
3999
|
-
if (parent?.type ===
|
|
4040
|
+
if (parent?.type === AST_NODE_TYPES51.VariableDeclarator) {
|
|
4000
4041
|
const { id } = parent;
|
|
4001
|
-
if (id.type ===
|
|
4042
|
+
if (id.type === AST_NODE_TYPES51.Identifier) {
|
|
4002
4043
|
return /^[A-Z]/.test(id.name);
|
|
4003
4044
|
}
|
|
4004
4045
|
}
|
|
4005
4046
|
}
|
|
4006
|
-
if (node.type ===
|
|
4047
|
+
if (node.type === AST_NODE_TYPES51.FunctionDeclaration && node.id) {
|
|
4007
4048
|
return /^[A-Z]/.test(node.id.name);
|
|
4008
4049
|
}
|
|
4009
4050
|
return false;
|
|
4010
4051
|
};
|
|
4011
4052
|
var isCallbackFunction = (node) => {
|
|
4012
|
-
if (node.type ===
|
|
4053
|
+
if (node.type === AST_NODE_TYPES51.FunctionDeclaration) {
|
|
4013
4054
|
return false;
|
|
4014
4055
|
}
|
|
4015
4056
|
const { parent } = node;
|
|
4016
4057
|
if (!parent) {
|
|
4017
4058
|
return false;
|
|
4018
4059
|
}
|
|
4019
|
-
if (parent.type ===
|
|
4060
|
+
if (parent.type === AST_NODE_TYPES51.CallExpression && parent.arguments.includes(node)) {
|
|
4020
4061
|
return true;
|
|
4021
4062
|
}
|
|
4022
|
-
if (parent.type ===
|
|
4063
|
+
if (parent.type === AST_NODE_TYPES51.Property) {
|
|
4023
4064
|
return true;
|
|
4024
4065
|
}
|
|
4025
|
-
if (parent.type ===
|
|
4066
|
+
if (parent.type === AST_NODE_TYPES51.ArrayExpression) {
|
|
4026
4067
|
return true;
|
|
4027
4068
|
}
|
|
4028
4069
|
return false;
|
|
4029
4070
|
};
|
|
4030
4071
|
var getFunctionName = (node) => {
|
|
4031
|
-
if (node.type ===
|
|
4072
|
+
if (node.type === AST_NODE_TYPES51.FunctionDeclaration && node.id) {
|
|
4032
4073
|
return node.id.name;
|
|
4033
4074
|
}
|
|
4034
|
-
if (node.type ===
|
|
4075
|
+
if (node.type === AST_NODE_TYPES51.FunctionExpression && node.id) {
|
|
4035
4076
|
return node.id.name;
|
|
4036
4077
|
}
|
|
4037
|
-
if ((node.type ===
|
|
4078
|
+
if ((node.type === AST_NODE_TYPES51.ArrowFunctionExpression || node.type === AST_NODE_TYPES51.FunctionExpression) && node.parent?.type === AST_NODE_TYPES51.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES51.Identifier) {
|
|
4038
4079
|
return node.parent.id.name;
|
|
4039
4080
|
}
|
|
4040
4081
|
return null;
|
|
4041
4082
|
};
|
|
4042
|
-
var requireExplicitReturnType =
|
|
4083
|
+
var requireExplicitReturnType = createRule53({
|
|
4043
4084
|
name: "require-explicit-return-type",
|
|
4044
4085
|
meta: {
|
|
4045
4086
|
type: "suggestion",
|
|
@@ -4088,8 +4129,8 @@ var requireExplicitReturnType = createRule52({
|
|
|
4088
4129
|
var require_explicit_return_type_default = requireExplicitReturnType;
|
|
4089
4130
|
|
|
4090
4131
|
// src/rules/sort-exports.ts
|
|
4091
|
-
import { AST_NODE_TYPES as
|
|
4092
|
-
var
|
|
4132
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES52, ESLintUtils as ESLintUtils54 } from "@typescript-eslint/utils";
|
|
4133
|
+
var createRule54 = ESLintUtils54.RuleCreator(
|
|
4093
4134
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4094
4135
|
);
|
|
4095
4136
|
var GROUP_NAMES = ["", "external/alias re-export", "relative re-export", "local export"];
|
|
@@ -4103,7 +4144,7 @@ function getExportGroup(node) {
|
|
|
4103
4144
|
}
|
|
4104
4145
|
return 1;
|
|
4105
4146
|
}
|
|
4106
|
-
var sortExports =
|
|
4147
|
+
var sortExports = createRule54({
|
|
4107
4148
|
name: "sort-exports",
|
|
4108
4149
|
meta: {
|
|
4109
4150
|
type: "suggestion",
|
|
@@ -4143,7 +4184,7 @@ var sortExports = createRule53({
|
|
|
4143
4184
|
Program(node) {
|
|
4144
4185
|
const exportGroups = [];
|
|
4145
4186
|
node.body.forEach((statement) => {
|
|
4146
|
-
if (statement.type !==
|
|
4187
|
+
if (statement.type !== AST_NODE_TYPES52.ExportNamedDeclaration || statement.declaration !== null) {
|
|
4147
4188
|
if (exportGroups.length > 0) {
|
|
4148
4189
|
checkOrder(exportGroups);
|
|
4149
4190
|
exportGroups.length = 0;
|
|
@@ -4162,8 +4203,8 @@ var sortExports = createRule53({
|
|
|
4162
4203
|
var sort_exports_default = sortExports;
|
|
4163
4204
|
|
|
4164
4205
|
// src/rules/sort-imports.ts
|
|
4165
|
-
import { AST_NODE_TYPES as
|
|
4166
|
-
var
|
|
4206
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES53, ESLintUtils as ESLintUtils55 } from "@typescript-eslint/utils";
|
|
4207
|
+
var createRule55 = ESLintUtils55.RuleCreator(
|
|
4167
4208
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4168
4209
|
);
|
|
4169
4210
|
var NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
@@ -4230,7 +4271,7 @@ function getImportGroup(node) {
|
|
|
4230
4271
|
function isTypeOnlyImport(node) {
|
|
4231
4272
|
return node.importKind === "type" && node.specifiers.length > 0;
|
|
4232
4273
|
}
|
|
4233
|
-
var sortImports =
|
|
4274
|
+
var sortImports = createRule55({
|
|
4234
4275
|
name: "sort-imports",
|
|
4235
4276
|
meta: {
|
|
4236
4277
|
type: "suggestion",
|
|
@@ -4274,7 +4315,7 @@ var sortImports = createRule54({
|
|
|
4274
4315
|
Program(node) {
|
|
4275
4316
|
const importGroups = [];
|
|
4276
4317
|
node.body.forEach((statement) => {
|
|
4277
|
-
if (statement.type !==
|
|
4318
|
+
if (statement.type !== AST_NODE_TYPES53.ImportDeclaration) {
|
|
4278
4319
|
if (importGroups.length > 0) {
|
|
4279
4320
|
checkOrder(importGroups);
|
|
4280
4321
|
importGroups.length = 0;
|
|
@@ -4296,13 +4337,13 @@ var sortImports = createRule54({
|
|
|
4296
4337
|
var sort_imports_default = sortImports;
|
|
4297
4338
|
|
|
4298
4339
|
// src/rules/sort-type-alphabetically.ts
|
|
4299
|
-
import { AST_NODE_TYPES as
|
|
4300
|
-
var
|
|
4340
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES54, ESLintUtils as ESLintUtils56 } from "@typescript-eslint/utils";
|
|
4341
|
+
var createRule56 = ESLintUtils56.RuleCreator(
|
|
4301
4342
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4302
4343
|
);
|
|
4303
4344
|
function isAlphabeticallySortedWithinGroups(members) {
|
|
4304
4345
|
const properties = members.filter(
|
|
4305
|
-
(member) => member.type ===
|
|
4346
|
+
(member) => member.type === AST_NODE_TYPES54.TSPropertySignature && member.key.type === AST_NODE_TYPES54.Identifier
|
|
4306
4347
|
);
|
|
4307
4348
|
if (properties.length < 2) {
|
|
4308
4349
|
return true;
|
|
@@ -4313,7 +4354,7 @@ function isAlphabeticallySortedWithinGroups(members) {
|
|
|
4313
4354
|
const isOptionalSorted = optional.every((name, index) => index === 0 || optional[index - 1].localeCompare(name) <= 0);
|
|
4314
4355
|
return isRequiredSorted && isOptionalSorted;
|
|
4315
4356
|
}
|
|
4316
|
-
var sortTypeAlphabetically =
|
|
4357
|
+
var sortTypeAlphabetically = createRule56({
|
|
4317
4358
|
name: "sort-type-alphabetically",
|
|
4318
4359
|
meta: {
|
|
4319
4360
|
type: "suggestion",
|
|
@@ -4331,7 +4372,7 @@ var sortTypeAlphabetically = createRule55({
|
|
|
4331
4372
|
function fixMembers(fixer, members) {
|
|
4332
4373
|
const { sourceCode } = context;
|
|
4333
4374
|
const properties = members.filter(
|
|
4334
|
-
(member) => member.type ===
|
|
4375
|
+
(member) => member.type === AST_NODE_TYPES54.TSPropertySignature && member.key.type === AST_NODE_TYPES54.Identifier
|
|
4335
4376
|
);
|
|
4336
4377
|
const required = properties.filter((prop) => !prop.optional);
|
|
4337
4378
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4368,7 +4409,7 @@ var sortTypeAlphabetically = createRule55({
|
|
|
4368
4409
|
}
|
|
4369
4410
|
},
|
|
4370
4411
|
TSTypeAliasDeclaration(node) {
|
|
4371
|
-
if (node.typeAnnotation.type !==
|
|
4412
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES54.TSTypeLiteral) {
|
|
4372
4413
|
return;
|
|
4373
4414
|
}
|
|
4374
4415
|
const { members } = node.typeAnnotation;
|
|
@@ -4388,13 +4429,13 @@ var sortTypeAlphabetically = createRule55({
|
|
|
4388
4429
|
var sort_type_alphabetically_default = sortTypeAlphabetically;
|
|
4389
4430
|
|
|
4390
4431
|
// src/rules/sort-type-required-first.ts
|
|
4391
|
-
import { AST_NODE_TYPES as
|
|
4392
|
-
var
|
|
4432
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES55, ESLintUtils as ESLintUtils57 } from "@typescript-eslint/utils";
|
|
4433
|
+
var createRule57 = ESLintUtils57.RuleCreator(
|
|
4393
4434
|
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
|
|
4394
4435
|
);
|
|
4395
4436
|
function isRequiredBeforeOptional(members) {
|
|
4396
4437
|
const properties = members.filter(
|
|
4397
|
-
(member) => member.type ===
|
|
4438
|
+
(member) => member.type === AST_NODE_TYPES55.TSPropertySignature && member.key.type === AST_NODE_TYPES55.Identifier
|
|
4398
4439
|
);
|
|
4399
4440
|
if (properties.length < 2) {
|
|
4400
4441
|
return true;
|
|
@@ -4405,7 +4446,7 @@ function isRequiredBeforeOptional(members) {
|
|
|
4405
4446
|
}
|
|
4406
4447
|
return properties.slice(firstOptionalIndex).every((prop) => prop.optional);
|
|
4407
4448
|
}
|
|
4408
|
-
var sortTypeRequiredFirst =
|
|
4449
|
+
var sortTypeRequiredFirst = createRule57({
|
|
4409
4450
|
name: "sort-type-required-first",
|
|
4410
4451
|
meta: {
|
|
4411
4452
|
type: "suggestion",
|
|
@@ -4423,7 +4464,7 @@ var sortTypeRequiredFirst = createRule56({
|
|
|
4423
4464
|
function fixMembers(fixer, members) {
|
|
4424
4465
|
const { sourceCode } = context;
|
|
4425
4466
|
const properties = members.filter(
|
|
4426
|
-
(member) => member.type ===
|
|
4467
|
+
(member) => member.type === AST_NODE_TYPES55.TSPropertySignature && member.key.type === AST_NODE_TYPES55.Identifier
|
|
4427
4468
|
);
|
|
4428
4469
|
const required = properties.filter((prop) => !prop.optional);
|
|
4429
4470
|
const optional = properties.filter((prop) => prop.optional);
|
|
@@ -4444,7 +4485,7 @@ var sortTypeRequiredFirst = createRule56({
|
|
|
4444
4485
|
}
|
|
4445
4486
|
},
|
|
4446
4487
|
TSTypeAliasDeclaration(node) {
|
|
4447
|
-
if (node.typeAnnotation.type !==
|
|
4488
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES55.TSTypeLiteral) {
|
|
4448
4489
|
return;
|
|
4449
4490
|
}
|
|
4450
4491
|
const { members } = node.typeAnnotation;
|
|
@@ -4491,6 +4532,7 @@ var rules = {
|
|
|
4491
4532
|
"jsx-require-suspense": jsx_require_suspense_default,
|
|
4492
4533
|
"jsx-simple-props": jsx_simple_props_default,
|
|
4493
4534
|
"jsx-sort-props": jsx_sort_props_default,
|
|
4535
|
+
"jsx-spread-props-last": jsx_spread_props_last_default,
|
|
4494
4536
|
"newline-after-multiline-block": newline_after_multiline_block_default,
|
|
4495
4537
|
"newline-before-return": newline_before_return_default,
|
|
4496
4538
|
"nextjs-require-public-env": nextjs_require_public_env_default,
|
|
@@ -4627,6 +4669,7 @@ var jsxRules = {
|
|
|
4627
4669
|
"nextfriday/jsx-require-suspense": "warn",
|
|
4628
4670
|
"nextfriday/jsx-simple-props": "warn",
|
|
4629
4671
|
"nextfriday/jsx-sort-props": "warn",
|
|
4672
|
+
"nextfriday/jsx-spread-props-last": "warn",
|
|
4630
4673
|
"nextfriday/prefer-interface-over-inline-types": "warn",
|
|
4631
4674
|
"nextfriday/prefer-jsx-template-literals": "warn",
|
|
4632
4675
|
"nextfriday/react-props-destructure": "warn"
|
|
@@ -4644,6 +4687,7 @@ var jsxRecommendedRules = {
|
|
|
4644
4687
|
"nextfriday/jsx-require-suspense": "error",
|
|
4645
4688
|
"nextfriday/jsx-simple-props": "error",
|
|
4646
4689
|
"nextfriday/jsx-sort-props": "error",
|
|
4690
|
+
"nextfriday/jsx-spread-props-last": "error",
|
|
4647
4691
|
"nextfriday/prefer-interface-over-inline-types": "error",
|
|
4648
4692
|
"nextfriday/prefer-jsx-template-literals": "error",
|
|
4649
4693
|
"nextfriday/react-props-destructure": "error"
|