eslint-plugin-nextfriday 1.5.2 → 1.5.3
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 +6 -0
- package/lib/index.cjs +1236 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +388 -0
- package/lib/index.d.ts +388 -0
- package/lib/index.js +1197 -0
- package/lib/index.js.map +1 -0
- package/package.json +2 -1
package/lib/index.js
ADDED
|
@@ -0,0 +1,1197 @@
|
|
|
1
|
+
// package.json
|
|
2
|
+
var package_default = {
|
|
3
|
+
name: "eslint-plugin-nextfriday",
|
|
4
|
+
version: "1.5.3",
|
|
5
|
+
description: "A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.",
|
|
6
|
+
keywords: [
|
|
7
|
+
"eslint",
|
|
8
|
+
"eslintplugin",
|
|
9
|
+
"eslint-plugin",
|
|
10
|
+
"nextfriday",
|
|
11
|
+
"next-friday",
|
|
12
|
+
"linting",
|
|
13
|
+
"code-quality",
|
|
14
|
+
"javascript",
|
|
15
|
+
"typescript",
|
|
16
|
+
"development-tools"
|
|
17
|
+
],
|
|
18
|
+
homepage: "https://github.com/next-friday/eslint-plugin-nextfriday",
|
|
19
|
+
bugs: {
|
|
20
|
+
url: "https://github.com/next-friday/eslint-plugin-nextfriday/issues"
|
|
21
|
+
},
|
|
22
|
+
repository: {
|
|
23
|
+
type: "git",
|
|
24
|
+
url: "https://github.com/next-friday/eslint-plugin-nextfriday.git"
|
|
25
|
+
},
|
|
26
|
+
license: "MIT",
|
|
27
|
+
author: "Next Friday <nextfriday.developer@gmail.com>",
|
|
28
|
+
contributors: [
|
|
29
|
+
"@joetakara"
|
|
30
|
+
],
|
|
31
|
+
type: "module",
|
|
32
|
+
exports: {
|
|
33
|
+
".": {
|
|
34
|
+
types: "./lib/index.d.ts",
|
|
35
|
+
import: "./lib/index.js",
|
|
36
|
+
require: "./lib/index.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
main: "lib/index.js",
|
|
40
|
+
types: "lib/index.d.ts",
|
|
41
|
+
files: [
|
|
42
|
+
"LICENSE",
|
|
43
|
+
"README.md",
|
|
44
|
+
"CHANGELOG.md",
|
|
45
|
+
"docs",
|
|
46
|
+
"lib"
|
|
47
|
+
],
|
|
48
|
+
scripts: {
|
|
49
|
+
build: "tsup",
|
|
50
|
+
changeset: "changeset",
|
|
51
|
+
"changeset:publish": "npm publish --provenance --access public",
|
|
52
|
+
"changeset:version": "changeset version",
|
|
53
|
+
clear: "rm -rf lib node_modules/.cache .eslintcache",
|
|
54
|
+
eslint: "eslint src --ext .js,.ts --fix",
|
|
55
|
+
"eslint:check": "eslint src --ext .js,.ts",
|
|
56
|
+
prepare: "husky",
|
|
57
|
+
prepublishOnly: "pnpm build",
|
|
58
|
+
prettier: "prettier --write .",
|
|
59
|
+
"prettier:check": "prettier --check .",
|
|
60
|
+
"sort-package-json": "pnpm exec sort-package-json",
|
|
61
|
+
"sort-package-json:check": "pnpm exec sort-package-json --check",
|
|
62
|
+
test: "jest",
|
|
63
|
+
"test:coverage": "jest --coverage",
|
|
64
|
+
"test:watch": "jest --watch",
|
|
65
|
+
typecheck: "tsc --noEmit"
|
|
66
|
+
},
|
|
67
|
+
dependencies: {
|
|
68
|
+
"@typescript-eslint/utils": "^8.42.0",
|
|
69
|
+
"emoji-regex": "^10.5.0",
|
|
70
|
+
tsup: "^8.5.0"
|
|
71
|
+
},
|
|
72
|
+
devDependencies: {
|
|
73
|
+
"@changesets/changelog-github": "^0.5.1",
|
|
74
|
+
"@changesets/cli": "^2.29.6",
|
|
75
|
+
"@commitlint/cli": "^19.8.1",
|
|
76
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
77
|
+
"@eslint/js": "^9.35.0",
|
|
78
|
+
"@jest/globals": "^30.1.2",
|
|
79
|
+
"@stylistic/eslint-plugin": "^3.1.0",
|
|
80
|
+
"@swc/core": "^1.13.5",
|
|
81
|
+
"@types/eslint": "^9.6.1",
|
|
82
|
+
"@types/jest": "^30.0.0",
|
|
83
|
+
"@types/node": "^22.5.4",
|
|
84
|
+
"@types/ramda": "^0.31.0",
|
|
85
|
+
"@typescript-eslint/parser": "^8.42.0",
|
|
86
|
+
"@typescript-eslint/rule-tester": "^8.42.0",
|
|
87
|
+
eslint: "^9.35.0",
|
|
88
|
+
"eslint-config-airbnb-extended": "^2.2.0",
|
|
89
|
+
"eslint-config-prettier": "^10.1.8",
|
|
90
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
91
|
+
"eslint-plugin-import-x": "^4.16.1",
|
|
92
|
+
"eslint-plugin-jest": "^29.0.1",
|
|
93
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
94
|
+
"eslint-plugin-sonarjs": "^3.0.5",
|
|
95
|
+
husky: "^9.1.7",
|
|
96
|
+
jest: "^29.7.0",
|
|
97
|
+
"lint-staged": "^16.1.6",
|
|
98
|
+
prettier: "^3.6.2",
|
|
99
|
+
"sort-package-json": "^3.4.0",
|
|
100
|
+
"ts-jest": "^29.4.1",
|
|
101
|
+
"ts-node": "^10.9.2",
|
|
102
|
+
typescript: "^5.6.2",
|
|
103
|
+
"typescript-eslint": "^8.42.0"
|
|
104
|
+
},
|
|
105
|
+
peerDependencies: {
|
|
106
|
+
eslint: "^9.0.0"
|
|
107
|
+
},
|
|
108
|
+
packageManager: "pnpm@9.12.0",
|
|
109
|
+
engines: {
|
|
110
|
+
node: ">=22.0.0",
|
|
111
|
+
pnpm: ">=9.0.0"
|
|
112
|
+
},
|
|
113
|
+
publishConfig: {
|
|
114
|
+
access: "public"
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// src/rules/enforce-readonly-component-props.ts
|
|
119
|
+
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
120
|
+
var createRule = ESLintUtils.RuleCreator(
|
|
121
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
122
|
+
);
|
|
123
|
+
var enforceReadonlyComponentProps = createRule({
|
|
124
|
+
name: "enforce-readonly-component-props",
|
|
125
|
+
meta: {
|
|
126
|
+
type: "suggestion",
|
|
127
|
+
docs: {
|
|
128
|
+
description: "Enforce Readonly wrapper for React component props when using named types or interfaces"
|
|
129
|
+
},
|
|
130
|
+
fixable: "code",
|
|
131
|
+
schema: [],
|
|
132
|
+
messages: {
|
|
133
|
+
useReadonly: "Component props should be wrapped with Readonly<> for immutability"
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
defaultOptions: [],
|
|
137
|
+
create(context) {
|
|
138
|
+
function hasJSXInConditional(node) {
|
|
139
|
+
return node.consequent.type === AST_NODE_TYPES.JSXElement || node.consequent.type === AST_NODE_TYPES.JSXFragment || node.alternate.type === AST_NODE_TYPES.JSXElement || node.alternate.type === AST_NODE_TYPES.JSXFragment;
|
|
140
|
+
}
|
|
141
|
+
function hasJSXInLogical(node) {
|
|
142
|
+
return node.right.type === AST_NODE_TYPES.JSXElement || node.right.type === AST_NODE_TYPES.JSXFragment;
|
|
143
|
+
}
|
|
144
|
+
function hasJSXReturn(block) {
|
|
145
|
+
return block.body.some((stmt) => {
|
|
146
|
+
if (stmt.type === AST_NODE_TYPES.ReturnStatement && stmt.argument) {
|
|
147
|
+
return stmt.argument.type === AST_NODE_TYPES.JSXElement || stmt.argument.type === AST_NODE_TYPES.JSXFragment || stmt.argument.type === AST_NODE_TYPES.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function isReactComponent(node) {
|
|
153
|
+
if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
154
|
+
if (node.body.type === AST_NODE_TYPES.JSXElement || node.body.type === AST_NODE_TYPES.JSXFragment) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
if (node.body.type === AST_NODE_TYPES.BlockStatement) {
|
|
158
|
+
return hasJSXReturn(node.body);
|
|
159
|
+
}
|
|
160
|
+
} else if (node.type === AST_NODE_TYPES.FunctionExpression || node.type === AST_NODE_TYPES.FunctionDeclaration) {
|
|
161
|
+
if (node.body && node.body.type === AST_NODE_TYPES.BlockStatement) {
|
|
162
|
+
return hasJSXReturn(node.body);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
function isNamedType(node) {
|
|
168
|
+
return node.type === AST_NODE_TYPES.TSTypeReference;
|
|
169
|
+
}
|
|
170
|
+
function isAlreadyReadonly(node) {
|
|
171
|
+
if (node.type === AST_NODE_TYPES.TSTypeReference && node.typeName) {
|
|
172
|
+
if (node.typeName.type === AST_NODE_TYPES.Identifier && node.typeName.name === "Readonly") {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
function checkFunction(node) {
|
|
179
|
+
if (!isReactComponent(node)) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (node.params.length !== 1) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const param = node.params[0];
|
|
186
|
+
if (param.type === AST_NODE_TYPES.Identifier && param.typeAnnotation) {
|
|
187
|
+
const { typeAnnotation } = param.typeAnnotation;
|
|
188
|
+
if (isNamedType(typeAnnotation) && !isAlreadyReadonly(typeAnnotation)) {
|
|
189
|
+
const { sourceCode } = context;
|
|
190
|
+
const typeText = sourceCode.getText(typeAnnotation);
|
|
191
|
+
context.report({
|
|
192
|
+
node: param.typeAnnotation,
|
|
193
|
+
messageId: "useReadonly",
|
|
194
|
+
fix(fixer) {
|
|
195
|
+
return fixer.replaceText(typeAnnotation, `Readonly<${typeText}>`);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
ArrowFunctionExpression: checkFunction,
|
|
203
|
+
FunctionExpression: checkFunction,
|
|
204
|
+
FunctionDeclaration: checkFunction
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
var enforce_readonly_component_props_default = enforceReadonlyComponentProps;
|
|
209
|
+
|
|
210
|
+
// src/rules/file-kebab-case.ts
|
|
211
|
+
import path from "path";
|
|
212
|
+
import { ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
|
|
213
|
+
var createRule2 = ESLintUtils2.RuleCreator(
|
|
214
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
215
|
+
);
|
|
216
|
+
var isKebabCase = (str) => {
|
|
217
|
+
if (/\.(config|rc|setup|spec|test)$/.test(str) || /^[a-z0-9]+(?:-[a-z0-9]+)*\.[a-z0-9]+(?:-[a-z0-9]+)*$/.test(str)) {
|
|
218
|
+
return /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\.[a-z0-9]+(?:-[a-z0-9]+)*)*$/.test(str);
|
|
219
|
+
}
|
|
220
|
+
return /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(str);
|
|
221
|
+
};
|
|
222
|
+
var fileKebabCase = createRule2({
|
|
223
|
+
name: "file-kebab-case",
|
|
224
|
+
meta: {
|
|
225
|
+
type: "problem",
|
|
226
|
+
docs: {
|
|
227
|
+
description: "Enforce kebab-case filenames for .ts and .js files"
|
|
228
|
+
},
|
|
229
|
+
messages: {
|
|
230
|
+
fileKebabCase: "File names must be kebab-case"
|
|
231
|
+
},
|
|
232
|
+
schema: []
|
|
233
|
+
},
|
|
234
|
+
defaultOptions: [],
|
|
235
|
+
create(context) {
|
|
236
|
+
return {
|
|
237
|
+
Program() {
|
|
238
|
+
const { filename } = context;
|
|
239
|
+
const ext = path.extname(filename);
|
|
240
|
+
if (ext !== ".ts" && ext !== ".js") {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const basename = path.basename(filename, ext);
|
|
244
|
+
if (!isKebabCase(basename)) {
|
|
245
|
+
context.report({
|
|
246
|
+
loc: { line: 1, column: 0 },
|
|
247
|
+
messageId: "fileKebabCase"
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
var file_kebab_case_default = fileKebabCase;
|
|
255
|
+
|
|
256
|
+
// src/rules/jsx-pascal-case.ts
|
|
257
|
+
import path2 from "path";
|
|
258
|
+
import { ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
|
|
259
|
+
var createRule3 = ESLintUtils3.RuleCreator(
|
|
260
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
261
|
+
);
|
|
262
|
+
var isPascalCase = (str) => /^[A-Z][a-zA-Z0-9]*$/.test(str) && !/^[A-Z]+$/.test(str);
|
|
263
|
+
var jsxPascalCase = createRule3({
|
|
264
|
+
name: "jsx-pascal-case",
|
|
265
|
+
meta: {
|
|
266
|
+
type: "problem",
|
|
267
|
+
docs: {
|
|
268
|
+
description: "Enforce PascalCase filenames for .jsx and .tsx files"
|
|
269
|
+
},
|
|
270
|
+
messages: {
|
|
271
|
+
jsxPascalCase: "JSX/TSX file names must be PascalCase"
|
|
272
|
+
},
|
|
273
|
+
schema: []
|
|
274
|
+
},
|
|
275
|
+
defaultOptions: [],
|
|
276
|
+
create(context) {
|
|
277
|
+
return {
|
|
278
|
+
Program() {
|
|
279
|
+
const { filename } = context;
|
|
280
|
+
const ext = path2.extname(filename);
|
|
281
|
+
if (ext !== ".jsx" && ext !== ".tsx") {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const basename = path2.basename(filename, ext);
|
|
285
|
+
if (!isPascalCase(basename)) {
|
|
286
|
+
context.report({
|
|
287
|
+
loc: { line: 1, column: 0 },
|
|
288
|
+
messageId: "jsxPascalCase"
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
var jsx_pascal_case_default = jsxPascalCase;
|
|
296
|
+
|
|
297
|
+
// src/rules/md-filename-case-restriction.ts
|
|
298
|
+
import path3 from "path";
|
|
299
|
+
import { ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
|
|
300
|
+
var createRule4 = ESLintUtils4.RuleCreator(
|
|
301
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
302
|
+
);
|
|
303
|
+
var mdFilenameCaseRestriction = createRule4({
|
|
304
|
+
name: "md-filename-case-restriction",
|
|
305
|
+
meta: {
|
|
306
|
+
type: "problem",
|
|
307
|
+
docs: {
|
|
308
|
+
description: "Enforce .md filenames to be SNAKE_CASE only"
|
|
309
|
+
},
|
|
310
|
+
messages: {
|
|
311
|
+
invalidFilenameCase: "Markdown filename must be SNAKE_CASE (UPPERCASE with underscores). Found: '{{ filename }}'"
|
|
312
|
+
},
|
|
313
|
+
schema: []
|
|
314
|
+
},
|
|
315
|
+
defaultOptions: [],
|
|
316
|
+
create(context) {
|
|
317
|
+
return {
|
|
318
|
+
Program() {
|
|
319
|
+
const { filename } = context;
|
|
320
|
+
if (!filename.endsWith(".md")) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const basename = path3.basename(filename, ".md");
|
|
324
|
+
function isSnakeCase(text) {
|
|
325
|
+
return /^[A-Z][A-Z0-9_]*$/.test(text);
|
|
326
|
+
}
|
|
327
|
+
function isValidCase(text) {
|
|
328
|
+
return isSnakeCase(text);
|
|
329
|
+
}
|
|
330
|
+
if (!isValidCase(basename)) {
|
|
331
|
+
context.report({
|
|
332
|
+
node: context.sourceCode.ast,
|
|
333
|
+
messageId: "invalidFilenameCase",
|
|
334
|
+
data: { filename: basename }
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
var md_filename_case_restriction_default = mdFilenameCaseRestriction;
|
|
342
|
+
|
|
343
|
+
// src/rules/no-complex-inline-return.ts
|
|
344
|
+
import { ESLintUtils as ESLintUtils5, AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/utils";
|
|
345
|
+
var createRule5 = ESLintUtils5.RuleCreator(
|
|
346
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
347
|
+
);
|
|
348
|
+
var noComplexInlineReturn = createRule5({
|
|
349
|
+
name: "no-complex-inline-return",
|
|
350
|
+
meta: {
|
|
351
|
+
type: "suggestion",
|
|
352
|
+
docs: {
|
|
353
|
+
description: "Disallow complex inline expressions in return statements - prefer extracting to a const first"
|
|
354
|
+
},
|
|
355
|
+
messages: {
|
|
356
|
+
noComplexInlineReturn: "Avoid returning complex expressions directly. Extract to a const variable first for better readability."
|
|
357
|
+
},
|
|
358
|
+
schema: []
|
|
359
|
+
},
|
|
360
|
+
defaultOptions: [],
|
|
361
|
+
create(context) {
|
|
362
|
+
const isComplexExpression = (node) => {
|
|
363
|
+
if (!node) return false;
|
|
364
|
+
if (node.type === AST_NODE_TYPES2.ConditionalExpression) {
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
if (node.type === AST_NODE_TYPES2.LogicalExpression) {
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
if (node.type === AST_NODE_TYPES2.NewExpression) {
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
return false;
|
|
374
|
+
};
|
|
375
|
+
return {
|
|
376
|
+
ReturnStatement(node) {
|
|
377
|
+
if (node.argument && isComplexExpression(node.argument)) {
|
|
378
|
+
context.report({
|
|
379
|
+
node: node.argument,
|
|
380
|
+
messageId: "noComplexInlineReturn"
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
var no_complex_inline_return_default = noComplexInlineReturn;
|
|
388
|
+
|
|
389
|
+
// src/rules/no-emoji.ts
|
|
390
|
+
import emojiRegex from "emoji-regex";
|
|
391
|
+
import { ESLintUtils as ESLintUtils6 } from "@typescript-eslint/utils";
|
|
392
|
+
var createRule6 = ESLintUtils6.RuleCreator(
|
|
393
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
394
|
+
);
|
|
395
|
+
var noEmoji = createRule6({
|
|
396
|
+
name: "no-emoji",
|
|
397
|
+
meta: {
|
|
398
|
+
type: "problem",
|
|
399
|
+
docs: {
|
|
400
|
+
description: "Disallow emoji characters in source code"
|
|
401
|
+
},
|
|
402
|
+
messages: {
|
|
403
|
+
noEmoji: "Emoji are not allowed in source code"
|
|
404
|
+
},
|
|
405
|
+
schema: []
|
|
406
|
+
},
|
|
407
|
+
defaultOptions: [],
|
|
408
|
+
create(context) {
|
|
409
|
+
const { sourceCode } = context;
|
|
410
|
+
return {
|
|
411
|
+
Program() {
|
|
412
|
+
const text = sourceCode.getText();
|
|
413
|
+
const regex = emojiRegex();
|
|
414
|
+
const matches = Array.from(text.matchAll(regex));
|
|
415
|
+
matches.forEach((match) => {
|
|
416
|
+
const loc = sourceCode.getLocFromIndex(match.index);
|
|
417
|
+
context.report({
|
|
418
|
+
loc,
|
|
419
|
+
messageId: "noEmoji"
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
var no_emoji_default = noEmoji;
|
|
427
|
+
|
|
428
|
+
// src/rules/no-env-fallback.ts
|
|
429
|
+
import { ESLintUtils as ESLintUtils7, AST_NODE_TYPES as AST_NODE_TYPES3 } from "@typescript-eslint/utils";
|
|
430
|
+
var createRule7 = ESLintUtils7.RuleCreator(
|
|
431
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
432
|
+
);
|
|
433
|
+
var noEnvFallback = createRule7({
|
|
434
|
+
name: "no-env-fallback",
|
|
435
|
+
meta: {
|
|
436
|
+
type: "problem",
|
|
437
|
+
docs: {
|
|
438
|
+
description: "Disallow fallback values for environment variables as they can be dangerous in production"
|
|
439
|
+
},
|
|
440
|
+
messages: {
|
|
441
|
+
noEnvFallback: "Avoid using fallback values with process.env. Environment variables should fail explicitly when missing rather than silently using a default value."
|
|
442
|
+
},
|
|
443
|
+
schema: []
|
|
444
|
+
},
|
|
445
|
+
defaultOptions: [],
|
|
446
|
+
create(context) {
|
|
447
|
+
const isProcessEnvAccess = (node) => {
|
|
448
|
+
if (node.type !== AST_NODE_TYPES3.MemberExpression) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
const { object } = node;
|
|
452
|
+
if (object.type !== AST_NODE_TYPES3.MemberExpression) {
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
const processNode = object.object;
|
|
456
|
+
const envNode = object.property;
|
|
457
|
+
return processNode.type === AST_NODE_TYPES3.Identifier && processNode.name === "process" && envNode.type === AST_NODE_TYPES3.Identifier && envNode.name === "env";
|
|
458
|
+
};
|
|
459
|
+
return {
|
|
460
|
+
LogicalExpression(node) {
|
|
461
|
+
if ((node.operator === "||" || node.operator === "??") && isProcessEnvAccess(node.left)) {
|
|
462
|
+
context.report({
|
|
463
|
+
node,
|
|
464
|
+
messageId: "noEnvFallback"
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
ConditionalExpression(node) {
|
|
469
|
+
if (isProcessEnvAccess(node.test)) {
|
|
470
|
+
context.report({
|
|
471
|
+
node,
|
|
472
|
+
messageId: "noEnvFallback"
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
var no_env_fallback_default = noEnvFallback;
|
|
480
|
+
|
|
481
|
+
// src/rules/no-explicit-return-type.ts
|
|
482
|
+
import { ESLintUtils as ESLintUtils8 } from "@typescript-eslint/utils";
|
|
483
|
+
var createRule8 = ESLintUtils8.RuleCreator(
|
|
484
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
485
|
+
);
|
|
486
|
+
var noExplicitReturnType = createRule8({
|
|
487
|
+
name: "no-explicit-return-type",
|
|
488
|
+
meta: {
|
|
489
|
+
type: "suggestion",
|
|
490
|
+
docs: {
|
|
491
|
+
description: "Disallow explicit return types on functions"
|
|
492
|
+
},
|
|
493
|
+
fixable: "code",
|
|
494
|
+
schema: [],
|
|
495
|
+
messages: {
|
|
496
|
+
noExplicitReturnType: "Remove explicit return type '{{returnType}}' - TypeScript can infer it automatically"
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
defaultOptions: [],
|
|
500
|
+
create(context) {
|
|
501
|
+
const checkFunction = (node) => {
|
|
502
|
+
if (node.returnType) {
|
|
503
|
+
const returnTypeText = context.sourceCode.getText(node.returnType);
|
|
504
|
+
context.report({
|
|
505
|
+
node: node.returnType,
|
|
506
|
+
messageId: "noExplicitReturnType",
|
|
507
|
+
data: {
|
|
508
|
+
returnType: returnTypeText
|
|
509
|
+
},
|
|
510
|
+
fix(fixer) {
|
|
511
|
+
return fixer.remove(node.returnType);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
return {
|
|
517
|
+
FunctionDeclaration: checkFunction,
|
|
518
|
+
FunctionExpression: checkFunction,
|
|
519
|
+
ArrowFunctionExpression: checkFunction
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
var no_explicit_return_type_default = noExplicitReturnType;
|
|
524
|
+
|
|
525
|
+
// src/rules/no-logic-in-params.ts
|
|
526
|
+
import { ESLintUtils as ESLintUtils9, AST_NODE_TYPES as AST_NODE_TYPES4 } from "@typescript-eslint/utils";
|
|
527
|
+
var createRule9 = ESLintUtils9.RuleCreator(
|
|
528
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
529
|
+
);
|
|
530
|
+
var noLogicInParams = createRule9({
|
|
531
|
+
name: "no-logic-in-params",
|
|
532
|
+
meta: {
|
|
533
|
+
type: "suggestion",
|
|
534
|
+
docs: {
|
|
535
|
+
description: "Disallow logic or conditions in function parameters - extract to a const variable first"
|
|
536
|
+
},
|
|
537
|
+
messages: {
|
|
538
|
+
noLogicInParams: "Avoid logic or conditions in function parameters. Extract to a const variable first for better readability."
|
|
539
|
+
},
|
|
540
|
+
schema: []
|
|
541
|
+
},
|
|
542
|
+
defaultOptions: [],
|
|
543
|
+
create(context) {
|
|
544
|
+
const isComplexExpression = (node) => {
|
|
545
|
+
if (node.type === AST_NODE_TYPES4.SpreadElement) {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
if (node.type === AST_NODE_TYPES4.ConditionalExpression) {
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
if (node.type === AST_NODE_TYPES4.LogicalExpression) {
|
|
552
|
+
return true;
|
|
553
|
+
}
|
|
554
|
+
if (node.type === AST_NODE_TYPES4.BinaryExpression) {
|
|
555
|
+
const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
|
|
556
|
+
return logicalOperators.includes(node.operator);
|
|
557
|
+
}
|
|
558
|
+
if (node.type === AST_NODE_TYPES4.UnaryExpression) {
|
|
559
|
+
return node.operator === "!";
|
|
560
|
+
}
|
|
561
|
+
return false;
|
|
562
|
+
};
|
|
563
|
+
return {
|
|
564
|
+
CallExpression(node) {
|
|
565
|
+
node.arguments.forEach((arg) => {
|
|
566
|
+
if (isComplexExpression(arg)) {
|
|
567
|
+
context.report({
|
|
568
|
+
node: arg,
|
|
569
|
+
messageId: "noLogicInParams"
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
},
|
|
574
|
+
NewExpression(node) {
|
|
575
|
+
node.arguments.forEach((arg) => {
|
|
576
|
+
if (isComplexExpression(arg)) {
|
|
577
|
+
context.report({
|
|
578
|
+
node: arg,
|
|
579
|
+
messageId: "noLogicInParams"
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
var no_logic_in_params_default = noLogicInParams;
|
|
588
|
+
|
|
589
|
+
// src/rules/prefer-destructuring-params.ts
|
|
590
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES5, ESLintUtils as ESLintUtils10 } from "@typescript-eslint/utils";
|
|
591
|
+
var createRule10 = ESLintUtils10.RuleCreator(
|
|
592
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
593
|
+
);
|
|
594
|
+
var preferDestructuringParams = createRule10({
|
|
595
|
+
name: "prefer-destructuring-params",
|
|
596
|
+
meta: {
|
|
597
|
+
type: "suggestion",
|
|
598
|
+
docs: {
|
|
599
|
+
description: "Enforce destructuring for functions with multiple parameters"
|
|
600
|
+
},
|
|
601
|
+
messages: {
|
|
602
|
+
preferDestructuring: "Functions with multiple parameters should use destructuring"
|
|
603
|
+
},
|
|
604
|
+
schema: []
|
|
605
|
+
},
|
|
606
|
+
defaultOptions: [],
|
|
607
|
+
create(context) {
|
|
608
|
+
const isCallbackFunction = (node) => {
|
|
609
|
+
const { parent } = node;
|
|
610
|
+
return parent?.type === AST_NODE_TYPES5.CallExpression;
|
|
611
|
+
};
|
|
612
|
+
const isDeveloperFunction = (node) => {
|
|
613
|
+
if (node.type === AST_NODE_TYPES5.FunctionDeclaration) {
|
|
614
|
+
return true;
|
|
615
|
+
}
|
|
616
|
+
if (node.type === AST_NODE_TYPES5.FunctionExpression || node.type === AST_NODE_TYPES5.ArrowFunctionExpression) {
|
|
617
|
+
if (isCallbackFunction(node)) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
const { parent } = node;
|
|
621
|
+
return parent?.type === AST_NODE_TYPES5.VariableDeclarator || parent?.type === AST_NODE_TYPES5.AssignmentExpression || parent?.type === AST_NODE_TYPES5.Property || parent?.type === AST_NODE_TYPES5.MethodDefinition;
|
|
622
|
+
}
|
|
623
|
+
return false;
|
|
624
|
+
};
|
|
625
|
+
const checkFunction = (node) => {
|
|
626
|
+
const { filename } = context;
|
|
627
|
+
if (filename.includes("node_modules") || filename.includes(".d.ts")) {
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
if (!isDeveloperFunction(node)) {
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if (node.type === AST_NODE_TYPES5.FunctionDeclaration && node.id) {
|
|
634
|
+
const functionName = node.id.name;
|
|
635
|
+
if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
if (node.params.length <= 1) {
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
const hasNonDestructuredParams = node.params.some(
|
|
643
|
+
(param) => param.type !== AST_NODE_TYPES5.ObjectPattern && param.type !== AST_NODE_TYPES5.RestElement
|
|
644
|
+
);
|
|
645
|
+
if (hasNonDestructuredParams) {
|
|
646
|
+
context.report({
|
|
647
|
+
node,
|
|
648
|
+
messageId: "preferDestructuring"
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
return {
|
|
653
|
+
FunctionDeclaration: checkFunction,
|
|
654
|
+
FunctionExpression: checkFunction,
|
|
655
|
+
ArrowFunctionExpression: checkFunction
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
var prefer_destructuring_params_default = preferDestructuringParams;
|
|
660
|
+
|
|
661
|
+
// src/rules/prefer-import-type.ts
|
|
662
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES6, ESLintUtils as ESLintUtils11 } from "@typescript-eslint/utils";
|
|
663
|
+
var createRule11 = ESLintUtils11.RuleCreator(
|
|
664
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
665
|
+
);
|
|
666
|
+
var preferImportType = createRule11({
|
|
667
|
+
name: "prefer-import-type",
|
|
668
|
+
meta: {
|
|
669
|
+
type: "suggestion",
|
|
670
|
+
docs: {
|
|
671
|
+
description: "Enforce using 'import type' for type-only imports"
|
|
672
|
+
},
|
|
673
|
+
fixable: "code",
|
|
674
|
+
schema: [],
|
|
675
|
+
messages: {
|
|
676
|
+
preferImportType: "Use 'import type' for type-only imports"
|
|
677
|
+
}
|
|
678
|
+
},
|
|
679
|
+
defaultOptions: [],
|
|
680
|
+
create(context) {
|
|
681
|
+
function checkImportDeclaration(node) {
|
|
682
|
+
if (node.importKind === "type") {
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
if (context.filename.includes(".test.") || context.filename.includes(".spec.") || context.filename.includes("__tests__")) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (node.specifiers.length === 0) {
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
const source = node.source.value;
|
|
692
|
+
const isRuntimeImport = /\.(css|scss|sass|less|styl)(\?.*)?$/.test(source) || /\.(png|jpg|jpeg|gif|svg|webp|ico|bmp)(\?.*)?$/.test(source) || /\.(woff|woff2|ttf|eot|otf)(\?.*)?$/.test(source) || /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/.test(source) || /\.(json|txt|md|xml|yml|yaml)(\?.*)?$/.test(source) || /^next\/(font|image|link|head|script|dynamic|router)/.test(source) || source.includes("/font/") || source === "react-dom" || source === "react-dom/client" || source === "react-dom/server" || source.startsWith("@emotion/") || source.startsWith("styled-components") || source.includes("polyfill") || source.includes("shim") || source === "styled-jsx/css" || source.startsWith("webpack/");
|
|
693
|
+
if (isRuntimeImport) {
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
const isTypeOnlyImport = node.specifiers.every((specifier) => {
|
|
697
|
+
if (specifier.type === AST_NODE_TYPES6.ImportDefaultSpecifier) {
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
if (specifier.type === AST_NODE_TYPES6.ImportNamespaceSpecifier) {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
if (specifier.type === AST_NODE_TYPES6.ImportSpecifier) {
|
|
704
|
+
const importedName = specifier.imported.type === AST_NODE_TYPES6.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
705
|
+
const isKnownTypeOnly = node.source.value === "@typescript-eslint/utils" && ["TSESTree", "RuleContext"].includes(importedName) || node.source.value === "react" && ["Component", "ComponentProps", "ReactNode", "FC", "JSX", "ReactElement", "PropsWithChildren"].includes(
|
|
706
|
+
importedName
|
|
707
|
+
) || importedName.endsWith("Type") || importedName.endsWith("Interface") || importedName.endsWith("Props");
|
|
708
|
+
return isKnownTypeOnly;
|
|
709
|
+
}
|
|
710
|
+
return false;
|
|
711
|
+
});
|
|
712
|
+
if (isTypeOnlyImport) {
|
|
713
|
+
context.report({
|
|
714
|
+
node,
|
|
715
|
+
messageId: "preferImportType",
|
|
716
|
+
fix(fixer) {
|
|
717
|
+
const sourceText = context.sourceCode.getText(node);
|
|
718
|
+
const fixedSource = sourceText.replace(/^import\s+/, "import type ");
|
|
719
|
+
return fixer.replaceText(node, fixedSource);
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return {
|
|
725
|
+
ImportDeclaration: checkImportDeclaration
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
var prefer_import_type_default = preferImportType;
|
|
730
|
+
|
|
731
|
+
// src/rules/prefer-interface-over-inline-types.ts
|
|
732
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES7, ESLintUtils as ESLintUtils12 } from "@typescript-eslint/utils";
|
|
733
|
+
var createRule12 = ESLintUtils12.RuleCreator(
|
|
734
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
735
|
+
);
|
|
736
|
+
var preferInterfaceOverInlineTypes = createRule12({
|
|
737
|
+
name: "prefer-interface-over-inline-types",
|
|
738
|
+
meta: {
|
|
739
|
+
type: "suggestion",
|
|
740
|
+
docs: {
|
|
741
|
+
description: "Enforce interface declarations over inline type annotations for React component props"
|
|
742
|
+
},
|
|
743
|
+
fixable: void 0,
|
|
744
|
+
schema: [],
|
|
745
|
+
messages: {
|
|
746
|
+
useInterface: "Use interface declaration for component props instead of inline type annotation"
|
|
747
|
+
}
|
|
748
|
+
},
|
|
749
|
+
defaultOptions: [],
|
|
750
|
+
create(context) {
|
|
751
|
+
function hasJSXInConditional(node) {
|
|
752
|
+
return node.consequent.type === AST_NODE_TYPES7.JSXElement || node.consequent.type === AST_NODE_TYPES7.JSXFragment || node.alternate.type === AST_NODE_TYPES7.JSXElement || node.alternate.type === AST_NODE_TYPES7.JSXFragment;
|
|
753
|
+
}
|
|
754
|
+
function hasJSXInLogical(node) {
|
|
755
|
+
return node.right.type === AST_NODE_TYPES7.JSXElement || node.right.type === AST_NODE_TYPES7.JSXFragment;
|
|
756
|
+
}
|
|
757
|
+
function hasJSXReturn(block) {
|
|
758
|
+
return block.body.some((stmt) => {
|
|
759
|
+
if (stmt.type === AST_NODE_TYPES7.ReturnStatement && stmt.argument) {
|
|
760
|
+
return stmt.argument.type === AST_NODE_TYPES7.JSXElement || stmt.argument.type === AST_NODE_TYPES7.JSXFragment || stmt.argument.type === AST_NODE_TYPES7.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES7.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
761
|
+
}
|
|
762
|
+
return false;
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
function isReactComponent(node) {
|
|
766
|
+
if (node.type === AST_NODE_TYPES7.ArrowFunctionExpression) {
|
|
767
|
+
if (node.body.type === AST_NODE_TYPES7.JSXElement || node.body.type === AST_NODE_TYPES7.JSXFragment) {
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
770
|
+
if (node.body.type === AST_NODE_TYPES7.BlockStatement) {
|
|
771
|
+
return hasJSXReturn(node.body);
|
|
772
|
+
}
|
|
773
|
+
} else if (node.type === AST_NODE_TYPES7.FunctionExpression || node.type === AST_NODE_TYPES7.FunctionDeclaration) {
|
|
774
|
+
if (node.body && node.body.type === AST_NODE_TYPES7.BlockStatement) {
|
|
775
|
+
return hasJSXReturn(node.body);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
return false;
|
|
779
|
+
}
|
|
780
|
+
function isInlineTypeAnnotation(node) {
|
|
781
|
+
if (node.type === AST_NODE_TYPES7.TSTypeLiteral) {
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
if (node.type === AST_NODE_TYPES7.TSTypeReference && node.typeArguments) {
|
|
785
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES7.TSTypeLiteral);
|
|
786
|
+
}
|
|
787
|
+
if (node.type === AST_NODE_TYPES7.TSUnionType) {
|
|
788
|
+
return node.types.some((type) => isInlineTypeAnnotation(type));
|
|
789
|
+
}
|
|
790
|
+
return false;
|
|
791
|
+
}
|
|
792
|
+
function hasInlineObjectType(node) {
|
|
793
|
+
if (node.type === AST_NODE_TYPES7.TSTypeLiteral) {
|
|
794
|
+
return true;
|
|
795
|
+
}
|
|
796
|
+
if (node.type === AST_NODE_TYPES7.TSTypeReference && node.typeArguments) {
|
|
797
|
+
return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES7.TSTypeLiteral);
|
|
798
|
+
}
|
|
799
|
+
if (node.type === AST_NODE_TYPES7.TSUnionType) {
|
|
800
|
+
return node.types.some((type) => hasInlineObjectType(type));
|
|
801
|
+
}
|
|
802
|
+
return false;
|
|
803
|
+
}
|
|
804
|
+
function checkFunction(node) {
|
|
805
|
+
if (!isReactComponent(node)) {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
if (node.params.length !== 1) {
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
const param = node.params[0];
|
|
812
|
+
if (param.type === AST_NODE_TYPES7.Identifier && param.typeAnnotation) {
|
|
813
|
+
const { typeAnnotation } = param.typeAnnotation;
|
|
814
|
+
if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
|
|
815
|
+
context.report({
|
|
816
|
+
node: param.typeAnnotation,
|
|
817
|
+
messageId: "useInterface"
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
return {
|
|
823
|
+
ArrowFunctionExpression: checkFunction,
|
|
824
|
+
FunctionExpression: checkFunction,
|
|
825
|
+
FunctionDeclaration: checkFunction
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
|
|
830
|
+
|
|
831
|
+
// src/rules/prefer-named-param-types.ts
|
|
832
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES8, ESLintUtils as ESLintUtils13 } from "@typescript-eslint/utils";
|
|
833
|
+
var createRule13 = ESLintUtils13.RuleCreator(
|
|
834
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
835
|
+
);
|
|
836
|
+
var preferNamedParamTypes = createRule13({
|
|
837
|
+
name: "prefer-named-param-types",
|
|
838
|
+
meta: {
|
|
839
|
+
type: "suggestion",
|
|
840
|
+
docs: {
|
|
841
|
+
description: "Enforce named interfaces/types instead of inline object types for function parameters"
|
|
842
|
+
},
|
|
843
|
+
messages: {
|
|
844
|
+
preferNamedParamTypes: "Use a named interface or type for object parameter types instead of inline type annotations"
|
|
845
|
+
},
|
|
846
|
+
schema: []
|
|
847
|
+
},
|
|
848
|
+
defaultOptions: [],
|
|
849
|
+
create(context) {
|
|
850
|
+
function hasInlineObjectType(param) {
|
|
851
|
+
if (param.type === AST_NODE_TYPES8.AssignmentPattern) {
|
|
852
|
+
return hasInlineObjectType(param.left);
|
|
853
|
+
}
|
|
854
|
+
if (param.type === AST_NODE_TYPES8.ObjectPattern) {
|
|
855
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES8.TSTypeLiteral) {
|
|
856
|
+
return true;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
if (param.type === AST_NODE_TYPES8.Identifier) {
|
|
860
|
+
if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES8.TSTypeLiteral) {
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return false;
|
|
865
|
+
}
|
|
866
|
+
function checkFunction(node) {
|
|
867
|
+
let params = [];
|
|
868
|
+
if ("params" in node) {
|
|
869
|
+
params = node.params;
|
|
870
|
+
} else if ("value" in node && node.value) {
|
|
871
|
+
params = node.value.params;
|
|
872
|
+
}
|
|
873
|
+
params.forEach((param) => {
|
|
874
|
+
if (hasInlineObjectType(param)) {
|
|
875
|
+
context.report({
|
|
876
|
+
node: param,
|
|
877
|
+
messageId: "preferNamedParamTypes"
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
return {
|
|
883
|
+
FunctionDeclaration: checkFunction,
|
|
884
|
+
FunctionExpression: checkFunction,
|
|
885
|
+
ArrowFunctionExpression: checkFunction,
|
|
886
|
+
TSMethodSignature: checkFunction,
|
|
887
|
+
MethodDefinition: checkFunction
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
var prefer_named_param_types_default = preferNamedParamTypes;
|
|
892
|
+
|
|
893
|
+
// src/rules/prefer-react-import-types.ts
|
|
894
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES9, ESLintUtils as ESLintUtils14 } from "@typescript-eslint/utils";
|
|
895
|
+
var createRule14 = ESLintUtils14.RuleCreator(
|
|
896
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
897
|
+
);
|
|
898
|
+
var preferReactImportTypes = createRule14({
|
|
899
|
+
name: "prefer-react-import-types",
|
|
900
|
+
meta: {
|
|
901
|
+
type: "suggestion",
|
|
902
|
+
docs: {
|
|
903
|
+
description: "Enforce importing React types and utilities from 'react' instead of using React.X"
|
|
904
|
+
},
|
|
905
|
+
fixable: "code",
|
|
906
|
+
schema: [],
|
|
907
|
+
messages: {
|
|
908
|
+
preferDirectImport: "Use direct import '{{importStatement}}' instead of 'React.{{typeName}}'"
|
|
909
|
+
}
|
|
910
|
+
},
|
|
911
|
+
defaultOptions: [],
|
|
912
|
+
create(context) {
|
|
913
|
+
const reactTypes = /* @__PURE__ */ new Set([
|
|
914
|
+
"ReactNode",
|
|
915
|
+
"ReactElement",
|
|
916
|
+
"ReactChildren",
|
|
917
|
+
"ReactChild",
|
|
918
|
+
"ComponentType",
|
|
919
|
+
"FC",
|
|
920
|
+
"FunctionComponent",
|
|
921
|
+
"Component",
|
|
922
|
+
"PureComponent",
|
|
923
|
+
"ReactEventHandler",
|
|
924
|
+
"MouseEventHandler",
|
|
925
|
+
"ChangeEventHandler",
|
|
926
|
+
"FormEventHandler",
|
|
927
|
+
"KeyboardEventHandler",
|
|
928
|
+
"TouchEventHandler",
|
|
929
|
+
"PointerEventHandler",
|
|
930
|
+
"FocusEventHandler",
|
|
931
|
+
"UIEventHandler",
|
|
932
|
+
"WheelEventHandler",
|
|
933
|
+
"AnimationEventHandler",
|
|
934
|
+
"TransitionEventHandler",
|
|
935
|
+
"RefObject",
|
|
936
|
+
"MutableRefObject",
|
|
937
|
+
"Ref",
|
|
938
|
+
"ForwardedRef",
|
|
939
|
+
"HTMLProps",
|
|
940
|
+
"ComponentProps",
|
|
941
|
+
"JSXElementConstructor"
|
|
942
|
+
]);
|
|
943
|
+
const reactRuntimeExports = /* @__PURE__ */ new Set([
|
|
944
|
+
"useState",
|
|
945
|
+
"useEffect",
|
|
946
|
+
"useContext",
|
|
947
|
+
"useReducer",
|
|
948
|
+
"useCallback",
|
|
949
|
+
"useMemo",
|
|
950
|
+
"useRef",
|
|
951
|
+
"useImperativeHandle",
|
|
952
|
+
"useLayoutEffect",
|
|
953
|
+
"useDebugValue",
|
|
954
|
+
"useDeferredValue",
|
|
955
|
+
"useTransition",
|
|
956
|
+
"useId",
|
|
957
|
+
"useSyncExternalStore",
|
|
958
|
+
"useInsertionEffect",
|
|
959
|
+
"createElement",
|
|
960
|
+
"createContext",
|
|
961
|
+
"forwardRef",
|
|
962
|
+
"memo",
|
|
963
|
+
"lazy",
|
|
964
|
+
"Suspense",
|
|
965
|
+
"Fragment",
|
|
966
|
+
"StrictMode",
|
|
967
|
+
"createRef",
|
|
968
|
+
"isValidElement",
|
|
969
|
+
"cloneElement",
|
|
970
|
+
"Children"
|
|
971
|
+
]);
|
|
972
|
+
const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
|
|
973
|
+
function checkMemberExpression(node) {
|
|
974
|
+
if (node.object.type === AST_NODE_TYPES9.Identifier && node.object.name === "React" && node.property.type === AST_NODE_TYPES9.Identifier && allReactExports.has(node.property.name)) {
|
|
975
|
+
const typeName = node.property.name;
|
|
976
|
+
const isType = reactTypes.has(typeName);
|
|
977
|
+
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
978
|
+
context.report({
|
|
979
|
+
node,
|
|
980
|
+
messageId: "preferDirectImport",
|
|
981
|
+
data: { typeName, importStatement },
|
|
982
|
+
fix(fixer) {
|
|
983
|
+
return fixer.replaceText(node, typeName);
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
return {
|
|
989
|
+
MemberExpression: checkMemberExpression,
|
|
990
|
+
"TSTypeReference > TSQualifiedName": (node) => {
|
|
991
|
+
if (node.left.type === AST_NODE_TYPES9.Identifier && node.left.name === "React" && node.right.type === AST_NODE_TYPES9.Identifier && allReactExports.has(node.right.name)) {
|
|
992
|
+
const typeName = node.right.name;
|
|
993
|
+
const isType = reactTypes.has(typeName);
|
|
994
|
+
const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
|
|
995
|
+
context.report({
|
|
996
|
+
node,
|
|
997
|
+
messageId: "preferDirectImport",
|
|
998
|
+
data: { typeName, importStatement },
|
|
999
|
+
fix(fixer) {
|
|
1000
|
+
return fixer.replaceText(node, typeName);
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
var prefer_react_import_types_default = preferReactImportTypes;
|
|
1009
|
+
|
|
1010
|
+
// src/rules/react-props-destructure.ts
|
|
1011
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES10, ESLintUtils as ESLintUtils15 } from "@typescript-eslint/utils";
|
|
1012
|
+
var createRule15 = ESLintUtils15.RuleCreator(
|
|
1013
|
+
(name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replace(/-/g, "_").toUpperCase()}.md`
|
|
1014
|
+
);
|
|
1015
|
+
var reactPropsDestructure = createRule15({
|
|
1016
|
+
name: "react-props-destructure",
|
|
1017
|
+
meta: {
|
|
1018
|
+
type: "suggestion",
|
|
1019
|
+
docs: {
|
|
1020
|
+
description: "Enforce destructuring props inside React component body instead of parameters"
|
|
1021
|
+
},
|
|
1022
|
+
fixable: void 0,
|
|
1023
|
+
schema: [],
|
|
1024
|
+
messages: {
|
|
1025
|
+
noParameterDestructuring: "Destructure props inside component body instead of parameters. Use 'const { {{properties}} } = props;'"
|
|
1026
|
+
}
|
|
1027
|
+
},
|
|
1028
|
+
defaultOptions: [],
|
|
1029
|
+
create(context) {
|
|
1030
|
+
function hasJSXInConditional(node) {
|
|
1031
|
+
return node.consequent.type === AST_NODE_TYPES10.JSXElement || node.consequent.type === AST_NODE_TYPES10.JSXFragment || node.alternate.type === AST_NODE_TYPES10.JSXElement || node.alternate.type === AST_NODE_TYPES10.JSXFragment;
|
|
1032
|
+
}
|
|
1033
|
+
function hasJSXInLogical(node) {
|
|
1034
|
+
return node.right.type === AST_NODE_TYPES10.JSXElement || node.right.type === AST_NODE_TYPES10.JSXFragment;
|
|
1035
|
+
}
|
|
1036
|
+
function hasJSXReturn(block) {
|
|
1037
|
+
return block.body.some((stmt) => {
|
|
1038
|
+
if (stmt.type === AST_NODE_TYPES10.ReturnStatement && stmt.argument) {
|
|
1039
|
+
return stmt.argument.type === AST_NODE_TYPES10.JSXElement || stmt.argument.type === AST_NODE_TYPES10.JSXFragment || stmt.argument.type === AST_NODE_TYPES10.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES10.LogicalExpression && hasJSXInLogical(stmt.argument);
|
|
1040
|
+
}
|
|
1041
|
+
return false;
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
function isReactComponent(node) {
|
|
1045
|
+
if (node.type === AST_NODE_TYPES10.ArrowFunctionExpression) {
|
|
1046
|
+
if (node.body.type === AST_NODE_TYPES10.JSXElement || node.body.type === AST_NODE_TYPES10.JSXFragment) {
|
|
1047
|
+
return true;
|
|
1048
|
+
}
|
|
1049
|
+
if (node.body.type === AST_NODE_TYPES10.BlockStatement) {
|
|
1050
|
+
return hasJSXReturn(node.body);
|
|
1051
|
+
}
|
|
1052
|
+
} else if (node.type === AST_NODE_TYPES10.FunctionExpression || node.type === AST_NODE_TYPES10.FunctionDeclaration) {
|
|
1053
|
+
if (node.body && node.body.type === AST_NODE_TYPES10.BlockStatement) {
|
|
1054
|
+
return hasJSXReturn(node.body);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
return false;
|
|
1058
|
+
}
|
|
1059
|
+
function checkFunction(node) {
|
|
1060
|
+
if (!isReactComponent(node)) {
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
if (node.params.length !== 1) {
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
const param = node.params[0];
|
|
1067
|
+
if (param.type === AST_NODE_TYPES10.ObjectPattern) {
|
|
1068
|
+
const properties = param.properties.filter((prop) => prop.type === AST_NODE_TYPES10.Property).map((prop) => {
|
|
1069
|
+
if (prop.key.type === AST_NODE_TYPES10.Identifier) {
|
|
1070
|
+
return prop.key.name;
|
|
1071
|
+
}
|
|
1072
|
+
return null;
|
|
1073
|
+
}).filter((name) => name !== null);
|
|
1074
|
+
if (properties.length === 0) {
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
context.report({
|
|
1078
|
+
node: param,
|
|
1079
|
+
messageId: "noParameterDestructuring",
|
|
1080
|
+
data: {
|
|
1081
|
+
properties: properties.join(", ")
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
return {
|
|
1087
|
+
ArrowFunctionExpression: checkFunction,
|
|
1088
|
+
FunctionExpression: checkFunction,
|
|
1089
|
+
FunctionDeclaration: checkFunction
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
var react_props_destructure_default = reactPropsDestructure;
|
|
1094
|
+
|
|
1095
|
+
// src/index.ts
|
|
1096
|
+
var meta = {
|
|
1097
|
+
name: package_default.name,
|
|
1098
|
+
version: package_default.version
|
|
1099
|
+
};
|
|
1100
|
+
var rules = {
|
|
1101
|
+
"enforce-readonly-component-props": enforce_readonly_component_props_default,
|
|
1102
|
+
"file-kebab-case": file_kebab_case_default,
|
|
1103
|
+
"jsx-pascal-case": jsx_pascal_case_default,
|
|
1104
|
+
"md-filename-case-restriction": md_filename_case_restriction_default,
|
|
1105
|
+
"no-complex-inline-return": no_complex_inline_return_default,
|
|
1106
|
+
"no-emoji": no_emoji_default,
|
|
1107
|
+
"no-env-fallback": no_env_fallback_default,
|
|
1108
|
+
"no-explicit-return-type": no_explicit_return_type_default,
|
|
1109
|
+
"no-logic-in-params": no_logic_in_params_default,
|
|
1110
|
+
"prefer-destructuring-params": prefer_destructuring_params_default,
|
|
1111
|
+
"prefer-import-type": prefer_import_type_default,
|
|
1112
|
+
"prefer-interface-over-inline-types": prefer_interface_over_inline_types_default,
|
|
1113
|
+
"prefer-named-param-types": prefer_named_param_types_default,
|
|
1114
|
+
"prefer-react-import-types": prefer_react_import_types_default,
|
|
1115
|
+
"react-props-destructure": react_props_destructure_default
|
|
1116
|
+
};
|
|
1117
|
+
var plugin = {
|
|
1118
|
+
meta,
|
|
1119
|
+
rules
|
|
1120
|
+
};
|
|
1121
|
+
var baseRules = {
|
|
1122
|
+
"nextfriday/no-emoji": "warn",
|
|
1123
|
+
"nextfriday/file-kebab-case": "warn",
|
|
1124
|
+
"nextfriday/md-filename-case-restriction": "warn",
|
|
1125
|
+
"nextfriday/prefer-destructuring-params": "warn",
|
|
1126
|
+
"nextfriday/no-explicit-return-type": "warn",
|
|
1127
|
+
"nextfriday/prefer-import-type": "warn",
|
|
1128
|
+
"nextfriday/prefer-named-param-types": "warn",
|
|
1129
|
+
"nextfriday/prefer-react-import-types": "warn",
|
|
1130
|
+
"nextfriday/no-complex-inline-return": "warn",
|
|
1131
|
+
"nextfriday/no-logic-in-params": "warn",
|
|
1132
|
+
"nextfriday/no-env-fallback": "warn"
|
|
1133
|
+
};
|
|
1134
|
+
var baseRecommendedRules = {
|
|
1135
|
+
"nextfriday/no-emoji": "error",
|
|
1136
|
+
"nextfriday/file-kebab-case": "error",
|
|
1137
|
+
"nextfriday/md-filename-case-restriction": "error",
|
|
1138
|
+
"nextfriday/prefer-destructuring-params": "error",
|
|
1139
|
+
"nextfriday/no-explicit-return-type": "error",
|
|
1140
|
+
"nextfriday/prefer-import-type": "error",
|
|
1141
|
+
"nextfriday/prefer-named-param-types": "error",
|
|
1142
|
+
"nextfriday/prefer-react-import-types": "error",
|
|
1143
|
+
"nextfriday/no-complex-inline-return": "error",
|
|
1144
|
+
"nextfriday/no-logic-in-params": "error",
|
|
1145
|
+
"nextfriday/no-env-fallback": "error"
|
|
1146
|
+
};
|
|
1147
|
+
var jsxRules = {
|
|
1148
|
+
"nextfriday/jsx-pascal-case": "warn",
|
|
1149
|
+
"nextfriday/prefer-interface-over-inline-types": "warn",
|
|
1150
|
+
"nextfriday/react-props-destructure": "warn",
|
|
1151
|
+
"nextfriday/enforce-readonly-component-props": "warn"
|
|
1152
|
+
};
|
|
1153
|
+
var jsxRecommendedRules = {
|
|
1154
|
+
"nextfriday/jsx-pascal-case": "error",
|
|
1155
|
+
"nextfriday/prefer-interface-over-inline-types": "error",
|
|
1156
|
+
"nextfriday/react-props-destructure": "error",
|
|
1157
|
+
"nextfriday/enforce-readonly-component-props": "error"
|
|
1158
|
+
};
|
|
1159
|
+
var createConfig = (configRules) => ({
|
|
1160
|
+
plugins: {
|
|
1161
|
+
nextfriday: plugin
|
|
1162
|
+
},
|
|
1163
|
+
rules: configRules
|
|
1164
|
+
});
|
|
1165
|
+
var configs = {
|
|
1166
|
+
base: createConfig(baseRules),
|
|
1167
|
+
"base/recommended": createConfig(baseRecommendedRules),
|
|
1168
|
+
react: createConfig({
|
|
1169
|
+
...baseRules,
|
|
1170
|
+
...jsxRules
|
|
1171
|
+
}),
|
|
1172
|
+
"react/recommended": createConfig({
|
|
1173
|
+
...baseRecommendedRules,
|
|
1174
|
+
...jsxRecommendedRules
|
|
1175
|
+
}),
|
|
1176
|
+
nextjs: createConfig({
|
|
1177
|
+
...baseRules,
|
|
1178
|
+
...jsxRules
|
|
1179
|
+
}),
|
|
1180
|
+
"nextjs/recommended": createConfig({
|
|
1181
|
+
...baseRecommendedRules,
|
|
1182
|
+
...jsxRecommendedRules
|
|
1183
|
+
})
|
|
1184
|
+
};
|
|
1185
|
+
var nextfridayPlugin = {
|
|
1186
|
+
meta,
|
|
1187
|
+
configs,
|
|
1188
|
+
rules
|
|
1189
|
+
};
|
|
1190
|
+
var index_default = nextfridayPlugin;
|
|
1191
|
+
export {
|
|
1192
|
+
configs,
|
|
1193
|
+
index_default as default,
|
|
1194
|
+
meta,
|
|
1195
|
+
rules
|
|
1196
|
+
};
|
|
1197
|
+
//# sourceMappingURL=index.js.map
|