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