eslint-plugin-nextfriday 1.5.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js ADDED
@@ -0,0 +1,1647 @@
1
+ // package.json
2
+ var package_default = {
3
+ name: "eslint-plugin-nextfriday",
4
+ version: "1.6.0",
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.replaceAll("-", "_").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/enforce-sorted-destructuring.ts
211
+ import { AST_NODE_TYPES as AST_NODE_TYPES2, ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
212
+ var createRule2 = ESLintUtils2.RuleCreator(
213
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
214
+ );
215
+ var enforceSortedDestructuring = createRule2({
216
+ name: "enforce-sorted-destructuring",
217
+ meta: {
218
+ type: "suggestion",
219
+ docs: {
220
+ description: "Enforce alphabetical sorting of destructured properties with defaults first"
221
+ },
222
+ schema: [],
223
+ messages: {
224
+ unsortedDestructuring: "Destructured properties should be sorted alphabetically. Properties with defaults should come first, sorted by type (string, number, boolean, object) then alphabetically."
225
+ }
226
+ },
227
+ defaultOptions: [],
228
+ create(context) {
229
+ function getPropertyName(property) {
230
+ if (property.type === AST_NODE_TYPES2.RestElement) {
231
+ return null;
232
+ }
233
+ if (property.key.type === AST_NODE_TYPES2.Identifier) {
234
+ return property.key.name;
235
+ }
236
+ return null;
237
+ }
238
+ function hasDefaultValue(property) {
239
+ return property.value.type === AST_NODE_TYPES2.AssignmentPattern && Boolean(property.value.right);
240
+ }
241
+ function getDefaultValueType(property) {
242
+ if (!hasDefaultValue(property)) {
243
+ return "none";
244
+ }
245
+ const assignmentPattern = property.value;
246
+ const { right } = assignmentPattern;
247
+ if (!right) {
248
+ return "none";
249
+ }
250
+ switch (right.type) {
251
+ case AST_NODE_TYPES2.Literal:
252
+ if (typeof right.value === "string") {
253
+ return "string";
254
+ }
255
+ if (typeof right.value === "number") {
256
+ return "number";
257
+ }
258
+ if (typeof right.value === "boolean") {
259
+ return "boolean";
260
+ }
261
+ return "other";
262
+ case AST_NODE_TYPES2.TemplateLiteral:
263
+ return "string";
264
+ case AST_NODE_TYPES2.ObjectExpression:
265
+ case AST_NODE_TYPES2.ArrayExpression:
266
+ return "object";
267
+ default:
268
+ return "other";
269
+ }
270
+ }
271
+ function getTypeSortOrder(type) {
272
+ const order = {
273
+ string: 0,
274
+ number: 1,
275
+ boolean: 2,
276
+ object: 3,
277
+ other: 4,
278
+ none: 5
279
+ };
280
+ return order[type] ?? 5;
281
+ }
282
+ function checkVariableDeclarator(node) {
283
+ if (node.id.type !== AST_NODE_TYPES2.ObjectPattern) {
284
+ return;
285
+ }
286
+ const { properties } = node.id;
287
+ if (properties.length < 2) {
288
+ return;
289
+ }
290
+ const propertyInfo = properties.map((prop) => {
291
+ if (prop.type === AST_NODE_TYPES2.RestElement) {
292
+ return null;
293
+ }
294
+ return {
295
+ property: prop,
296
+ name: getPropertyName(prop),
297
+ hasDefault: hasDefaultValue(prop),
298
+ defaultType: getDefaultValueType(prop)
299
+ };
300
+ }).filter((info) => info !== null && info.name !== null);
301
+ const sorted = [...propertyInfo].sort((a, b) => {
302
+ if (a.hasDefault && !b.hasDefault) {
303
+ return -1;
304
+ }
305
+ if (!a.hasDefault && b.hasDefault) {
306
+ return 1;
307
+ }
308
+ if (a.hasDefault && b.hasDefault) {
309
+ const typeComparison = getTypeSortOrder(a.defaultType) - getTypeSortOrder(b.defaultType);
310
+ if (typeComparison !== 0) {
311
+ return typeComparison;
312
+ }
313
+ }
314
+ return a.name.localeCompare(b.name);
315
+ });
316
+ const isSorted = propertyInfo.every((info, index) => info.name === sorted[index].name);
317
+ if (!isSorted) {
318
+ context.report({
319
+ node: node.id,
320
+ messageId: "unsortedDestructuring"
321
+ });
322
+ }
323
+ }
324
+ return {
325
+ VariableDeclarator: checkVariableDeclarator
326
+ };
327
+ }
328
+ });
329
+ var enforce_sorted_destructuring_default = enforceSortedDestructuring;
330
+
331
+ // src/rules/file-kebab-case.ts
332
+ import path from "path";
333
+ import { ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
334
+ var createRule3 = ESLintUtils3.RuleCreator(
335
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
336
+ );
337
+ var isKebabCase = (str) => {
338
+ if (/\.(config|rc|setup|spec|test)$/.test(str) || /^[a-z0-9]+(?:-[a-z0-9]+)*\.[a-z0-9]+(?:-[a-z0-9]+)*$/.test(str)) {
339
+ return /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\.[a-z0-9]+(?:-[a-z0-9]+)*)*$/.test(str);
340
+ }
341
+ return /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(str);
342
+ };
343
+ var fileKebabCase = createRule3({
344
+ name: "file-kebab-case",
345
+ meta: {
346
+ type: "problem",
347
+ docs: {
348
+ description: "Enforce kebab-case filenames for .ts and .js files"
349
+ },
350
+ messages: {
351
+ fileKebabCase: "File names must be kebab-case"
352
+ },
353
+ schema: []
354
+ },
355
+ defaultOptions: [],
356
+ create(context) {
357
+ return {
358
+ Program() {
359
+ const { filename } = context;
360
+ const ext = path.extname(filename);
361
+ if (ext !== ".ts" && ext !== ".js") {
362
+ return;
363
+ }
364
+ const basename2 = path.basename(filename, ext);
365
+ if (!isKebabCase(basename2)) {
366
+ context.report({
367
+ loc: { line: 1, column: 0 },
368
+ messageId: "fileKebabCase"
369
+ });
370
+ }
371
+ }
372
+ };
373
+ }
374
+ });
375
+ var file_kebab_case_default = fileKebabCase;
376
+
377
+ // src/rules/jsx-pascal-case.ts
378
+ import path2 from "path";
379
+ import { ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
380
+ var createRule4 = ESLintUtils4.RuleCreator(
381
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
382
+ );
383
+ var isPascalCase = (str) => /^[A-Z][a-zA-Z0-9]*$/.test(str) && !/^[A-Z]+$/.test(str);
384
+ var jsxPascalCase = createRule4({
385
+ name: "jsx-pascal-case",
386
+ meta: {
387
+ type: "problem",
388
+ docs: {
389
+ description: "Enforce PascalCase filenames for .jsx and .tsx files"
390
+ },
391
+ messages: {
392
+ jsxPascalCase: "JSX/TSX file names must be PascalCase"
393
+ },
394
+ schema: []
395
+ },
396
+ defaultOptions: [],
397
+ create(context) {
398
+ return {
399
+ Program() {
400
+ const { filename } = context;
401
+ const ext = path2.extname(filename);
402
+ if (ext !== ".jsx" && ext !== ".tsx") {
403
+ return;
404
+ }
405
+ const basename2 = path2.basename(filename, ext);
406
+ if (!isPascalCase(basename2)) {
407
+ context.report({
408
+ loc: { line: 1, column: 0 },
409
+ messageId: "jsxPascalCase"
410
+ });
411
+ }
412
+ }
413
+ };
414
+ }
415
+ });
416
+ var jsx_pascal_case_default = jsxPascalCase;
417
+
418
+ // src/rules/jsx-no-variable-in-callback.ts
419
+ import { AST_NODE_TYPES as AST_NODE_TYPES3, ESLintUtils as ESLintUtils5 } from "@typescript-eslint/utils";
420
+ var createRule5 = ESLintUtils5.RuleCreator(
421
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
422
+ );
423
+ var jsxNoVariableInCallback = createRule5({
424
+ name: "jsx-no-variable-in-callback",
425
+ meta: {
426
+ type: "suggestion",
427
+ docs: {
428
+ description: "Disallow variable declarations inside callback functions within JSX"
429
+ },
430
+ schema: [],
431
+ messages: {
432
+ noVariableInCallback: "Variable declarations should not be inside callback functions within JSX. Extract the logic to a separate function outside the JSX."
433
+ }
434
+ },
435
+ defaultOptions: [],
436
+ create(context) {
437
+ function isInsideJSX(node) {
438
+ let current = node.parent;
439
+ while (current) {
440
+ if (current.type === AST_NODE_TYPES3.JSXElement || current.type === AST_NODE_TYPES3.JSXFragment) {
441
+ return true;
442
+ }
443
+ current = current.parent;
444
+ }
445
+ return false;
446
+ }
447
+ function isCallbackInJSX(node) {
448
+ if (!node.parent) {
449
+ return false;
450
+ }
451
+ if (!isInsideJSX(node)) {
452
+ return false;
453
+ }
454
+ if (node.parent.type === AST_NODE_TYPES3.CallExpression || node.parent.type === AST_NODE_TYPES3.JSXExpressionContainer) {
455
+ return true;
456
+ }
457
+ if (node.parent.type === AST_NODE_TYPES3.ArrayExpression && node.parent.parent) {
458
+ if (node.parent.parent.type === AST_NODE_TYPES3.CallExpression || node.parent.parent.type === AST_NODE_TYPES3.JSXExpressionContainer) {
459
+ return true;
460
+ }
461
+ }
462
+ return false;
463
+ }
464
+ function checkFunctionBody(node) {
465
+ if (!isCallbackInJSX(node)) {
466
+ return;
467
+ }
468
+ const { body } = node;
469
+ if (body.type !== AST_NODE_TYPES3.BlockStatement) {
470
+ return;
471
+ }
472
+ body.body.forEach((statement) => {
473
+ if (statement.type === AST_NODE_TYPES3.VariableDeclaration) {
474
+ context.report({
475
+ node: statement,
476
+ messageId: "noVariableInCallback"
477
+ });
478
+ }
479
+ });
480
+ }
481
+ return {
482
+ ArrowFunctionExpression: checkFunctionBody,
483
+ FunctionExpression: checkFunctionBody
484
+ };
485
+ }
486
+ });
487
+ var jsx_no_variable_in_callback_default = jsxNoVariableInCallback;
488
+
489
+ // src/rules/md-filename-case-restriction.ts
490
+ import path3 from "path";
491
+ import { ESLintUtils as ESLintUtils6 } from "@typescript-eslint/utils";
492
+ var createRule6 = ESLintUtils6.RuleCreator(
493
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
494
+ );
495
+ var mdFilenameCaseRestriction = createRule6({
496
+ name: "md-filename-case-restriction",
497
+ meta: {
498
+ type: "problem",
499
+ docs: {
500
+ description: "Enforce .md filenames to be SNAKE_CASE only"
501
+ },
502
+ messages: {
503
+ invalidFilenameCase: "Markdown filename must be SNAKE_CASE (UPPERCASE with underscores). Found: '{{ filename }}'"
504
+ },
505
+ schema: []
506
+ },
507
+ defaultOptions: [],
508
+ create(context) {
509
+ return {
510
+ Program() {
511
+ const { filename } = context;
512
+ if (!filename.endsWith(".md")) {
513
+ return;
514
+ }
515
+ const basename2 = path3.basename(filename, ".md");
516
+ function isSnakeCase(text) {
517
+ return /^[A-Z][A-Z0-9_]*$/.test(text);
518
+ }
519
+ function isValidCase(text) {
520
+ return isSnakeCase(text);
521
+ }
522
+ if (!isValidCase(basename2)) {
523
+ context.report({
524
+ node: context.sourceCode.ast,
525
+ messageId: "invalidFilenameCase",
526
+ data: { filename: basename2 }
527
+ });
528
+ }
529
+ }
530
+ };
531
+ }
532
+ });
533
+ var md_filename_case_restriction_default = mdFilenameCaseRestriction;
534
+
535
+ // src/rules/no-complex-inline-return.ts
536
+ import { ESLintUtils as ESLintUtils7, AST_NODE_TYPES as AST_NODE_TYPES4 } from "@typescript-eslint/utils";
537
+ var createRule7 = ESLintUtils7.RuleCreator(
538
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
539
+ );
540
+ var noComplexInlineReturn = createRule7({
541
+ name: "no-complex-inline-return",
542
+ meta: {
543
+ type: "suggestion",
544
+ docs: {
545
+ description: "Disallow complex inline expressions in return statements - prefer extracting to a const first"
546
+ },
547
+ messages: {
548
+ noComplexInlineReturn: "Avoid returning complex expressions directly. Extract to a const variable first for better readability."
549
+ },
550
+ schema: []
551
+ },
552
+ defaultOptions: [],
553
+ create(context) {
554
+ const isComplexExpression = (node) => {
555
+ if (!node) return false;
556
+ if (node.type === AST_NODE_TYPES4.ConditionalExpression) {
557
+ return true;
558
+ }
559
+ if (node.type === AST_NODE_TYPES4.LogicalExpression) {
560
+ return true;
561
+ }
562
+ if (node.type === AST_NODE_TYPES4.NewExpression) {
563
+ return true;
564
+ }
565
+ return false;
566
+ };
567
+ return {
568
+ ReturnStatement(node) {
569
+ if (node.argument && isComplexExpression(node.argument)) {
570
+ context.report({
571
+ node: node.argument,
572
+ messageId: "noComplexInlineReturn"
573
+ });
574
+ }
575
+ }
576
+ };
577
+ }
578
+ });
579
+ var no_complex_inline_return_default = noComplexInlineReturn;
580
+
581
+ // src/rules/no-emoji.ts
582
+ import emojiRegex from "emoji-regex";
583
+ import { ESLintUtils as ESLintUtils8 } from "@typescript-eslint/utils";
584
+ var createRule8 = ESLintUtils8.RuleCreator(
585
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
586
+ );
587
+ var noEmoji = createRule8({
588
+ name: "no-emoji",
589
+ meta: {
590
+ type: "problem",
591
+ docs: {
592
+ description: "Disallow emoji characters in source code"
593
+ },
594
+ messages: {
595
+ noEmoji: "Emoji are not allowed in source code"
596
+ },
597
+ schema: []
598
+ },
599
+ defaultOptions: [],
600
+ create(context) {
601
+ const { sourceCode } = context;
602
+ return {
603
+ Program() {
604
+ const text = sourceCode.getText();
605
+ const regex = emojiRegex();
606
+ const matches = Array.from(text.matchAll(regex));
607
+ matches.forEach((match) => {
608
+ const loc = sourceCode.getLocFromIndex(match.index);
609
+ context.report({
610
+ loc,
611
+ messageId: "noEmoji"
612
+ });
613
+ });
614
+ }
615
+ };
616
+ }
617
+ });
618
+ var no_emoji_default = noEmoji;
619
+
620
+ // src/rules/no-env-fallback.ts
621
+ import { ESLintUtils as ESLintUtils9, AST_NODE_TYPES as AST_NODE_TYPES5 } from "@typescript-eslint/utils";
622
+ var createRule9 = ESLintUtils9.RuleCreator(
623
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
624
+ );
625
+ var noEnvFallback = createRule9({
626
+ name: "no-env-fallback",
627
+ meta: {
628
+ type: "problem",
629
+ docs: {
630
+ description: "Disallow fallback values for environment variables as they can be dangerous in production"
631
+ },
632
+ messages: {
633
+ noEnvFallback: "Avoid using fallback values with process.env. Environment variables should fail explicitly when missing rather than silently using a default value."
634
+ },
635
+ schema: []
636
+ },
637
+ defaultOptions: [],
638
+ create(context) {
639
+ const isProcessEnvAccess = (node) => {
640
+ if (node.type !== AST_NODE_TYPES5.MemberExpression) {
641
+ return false;
642
+ }
643
+ const { object } = node;
644
+ if (object.type !== AST_NODE_TYPES5.MemberExpression) {
645
+ return false;
646
+ }
647
+ const processNode = object.object;
648
+ const envNode = object.property;
649
+ return processNode.type === AST_NODE_TYPES5.Identifier && processNode.name === "process" && envNode.type === AST_NODE_TYPES5.Identifier && envNode.name === "env";
650
+ };
651
+ return {
652
+ LogicalExpression(node) {
653
+ if ((node.operator === "||" || node.operator === "??") && isProcessEnvAccess(node.left)) {
654
+ context.report({
655
+ node,
656
+ messageId: "noEnvFallback"
657
+ });
658
+ }
659
+ },
660
+ ConditionalExpression(node) {
661
+ if (isProcessEnvAccess(node.test)) {
662
+ context.report({
663
+ node,
664
+ messageId: "noEnvFallback"
665
+ });
666
+ }
667
+ }
668
+ };
669
+ }
670
+ });
671
+ var no_env_fallback_default = noEnvFallback;
672
+
673
+ // src/rules/no-explicit-return-type.ts
674
+ import { ESLintUtils as ESLintUtils10 } from "@typescript-eslint/utils";
675
+ var createRule10 = ESLintUtils10.RuleCreator(
676
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
677
+ );
678
+ var noExplicitReturnType = createRule10({
679
+ name: "no-explicit-return-type",
680
+ meta: {
681
+ type: "suggestion",
682
+ docs: {
683
+ description: "Disallow explicit return types on functions"
684
+ },
685
+ fixable: "code",
686
+ schema: [],
687
+ messages: {
688
+ noExplicitReturnType: "Remove explicit return type '{{returnType}}' - TypeScript can infer it automatically"
689
+ }
690
+ },
691
+ defaultOptions: [],
692
+ create(context) {
693
+ const checkFunction = (node) => {
694
+ if (node.returnType) {
695
+ const returnTypeText = context.sourceCode.getText(node.returnType);
696
+ context.report({
697
+ node: node.returnType,
698
+ messageId: "noExplicitReturnType",
699
+ data: {
700
+ returnType: returnTypeText
701
+ },
702
+ fix(fixer) {
703
+ return fixer.remove(node.returnType);
704
+ }
705
+ });
706
+ }
707
+ };
708
+ return {
709
+ FunctionDeclaration: checkFunction,
710
+ FunctionExpression: checkFunction,
711
+ ArrowFunctionExpression: checkFunction
712
+ };
713
+ }
714
+ });
715
+ var no_explicit_return_type_default = noExplicitReturnType;
716
+
717
+ // src/rules/jsx-no-non-component-function.ts
718
+ import { AST_NODE_TYPES as AST_NODE_TYPES7, ESLintUtils as ESLintUtils11 } from "@typescript-eslint/utils";
719
+
720
+ // src/utils.ts
721
+ import { basename, extname } from "path";
722
+ import { AST_NODE_TYPES as AST_NODE_TYPES6 } from "@typescript-eslint/utils";
723
+ var getFileExtension = (filename) => extname(filename).slice(1);
724
+
725
+ // src/rules/jsx-no-non-component-function.ts
726
+ var createRule11 = ESLintUtils11.RuleCreator(
727
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
728
+ );
729
+ var jsxNoNonComponentFunction = createRule11({
730
+ name: "jsx-no-non-component-function",
731
+ meta: {
732
+ type: "problem",
733
+ docs: {
734
+ description: "Disallow non-component functions defined at top level in .tsx and .jsx files"
735
+ },
736
+ schema: [],
737
+ messages: {
738
+ noTopLevelFunction: "Non-component functions should not be defined at top level in .tsx/.jsx files. Either move it inside the component or extract it to a separate file."
739
+ }
740
+ },
741
+ defaultOptions: [],
742
+ create(context) {
743
+ const { filename } = context;
744
+ const extension = getFileExtension(filename);
745
+ if (extension !== "tsx" && extension !== "jsx") {
746
+ return {};
747
+ }
748
+ function isReactComponent(node) {
749
+ const functionName = node.type === AST_NODE_TYPES7.FunctionDeclaration && node.id ? node.id.name : null;
750
+ if (functionName && /^[A-Z]/.test(functionName)) {
751
+ return true;
752
+ }
753
+ if (node.returnType?.typeAnnotation) {
754
+ const returnTypeNode = node.returnType.typeAnnotation;
755
+ if (returnTypeNode.type === AST_NODE_TYPES7.TSTypeReference && returnTypeNode.typeName.type === AST_NODE_TYPES7.Identifier) {
756
+ const typeName = returnTypeNode.typeName.name;
757
+ if (typeName === "JSX" || typeName === "ReactElement" || typeName === "ReactNode") {
758
+ return true;
759
+ }
760
+ }
761
+ }
762
+ return false;
763
+ }
764
+ function checkTopLevelFunction(node, declaratorNode) {
765
+ if (isReactComponent(node)) {
766
+ return;
767
+ }
768
+ const { parent } = node;
769
+ if (!parent) {
770
+ return;
771
+ }
772
+ if (parent.type === AST_NODE_TYPES7.ExportDefaultDeclaration || parent.type === AST_NODE_TYPES7.ExportNamedDeclaration) {
773
+ return;
774
+ }
775
+ if (declaratorNode?.parent?.parent?.type === AST_NODE_TYPES7.ExportNamedDeclaration) {
776
+ return;
777
+ }
778
+ if (declaratorNode?.id.type === AST_NODE_TYPES7.Identifier) {
779
+ const varName = declaratorNode.id.name;
780
+ if (/^[A-Z]/.test(varName)) {
781
+ return;
782
+ }
783
+ }
784
+ context.report({
785
+ node: declaratorNode || node,
786
+ messageId: "noTopLevelFunction"
787
+ });
788
+ }
789
+ return {
790
+ "Program > VariableDeclaration > VariableDeclarator > ArrowFunctionExpression": function checkArrowFunction(node) {
791
+ const declarator = node.parent;
792
+ checkTopLevelFunction(node, declarator);
793
+ },
794
+ "Program > FunctionDeclaration": function checkFunctionDeclaration(node) {
795
+ checkTopLevelFunction(node);
796
+ }
797
+ };
798
+ }
799
+ });
800
+ var jsx_no_non_component_function_default = jsxNoNonComponentFunction;
801
+
802
+ // src/rules/no-logic-in-params.ts
803
+ import { ESLintUtils as ESLintUtils12, AST_NODE_TYPES as AST_NODE_TYPES8 } from "@typescript-eslint/utils";
804
+ var createRule12 = ESLintUtils12.RuleCreator(
805
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
806
+ );
807
+ var noLogicInParams = createRule12({
808
+ name: "no-logic-in-params",
809
+ meta: {
810
+ type: "suggestion",
811
+ docs: {
812
+ description: "Disallow logic or conditions in function parameters - extract to a const variable first"
813
+ },
814
+ messages: {
815
+ noLogicInParams: "Avoid logic or conditions in function parameters. Extract to a const variable first for better readability."
816
+ },
817
+ schema: []
818
+ },
819
+ defaultOptions: [],
820
+ create(context) {
821
+ const isComplexExpression = (node) => {
822
+ if (node.type === AST_NODE_TYPES8.SpreadElement) {
823
+ return false;
824
+ }
825
+ if (node.type === AST_NODE_TYPES8.ConditionalExpression) {
826
+ return true;
827
+ }
828
+ if (node.type === AST_NODE_TYPES8.LogicalExpression) {
829
+ return true;
830
+ }
831
+ if (node.type === AST_NODE_TYPES8.BinaryExpression) {
832
+ const logicalOperators = ["==", "===", "!=", "!==", "<", ">", "<=", ">=", "in", "instanceof"];
833
+ return logicalOperators.includes(node.operator);
834
+ }
835
+ if (node.type === AST_NODE_TYPES8.UnaryExpression) {
836
+ return node.operator === "!";
837
+ }
838
+ return false;
839
+ };
840
+ return {
841
+ CallExpression(node) {
842
+ node.arguments.forEach((arg) => {
843
+ if (isComplexExpression(arg)) {
844
+ context.report({
845
+ node: arg,
846
+ messageId: "noLogicInParams"
847
+ });
848
+ }
849
+ });
850
+ },
851
+ NewExpression(node) {
852
+ node.arguments.forEach((arg) => {
853
+ if (isComplexExpression(arg)) {
854
+ context.report({
855
+ node: arg,
856
+ messageId: "noLogicInParams"
857
+ });
858
+ }
859
+ });
860
+ }
861
+ };
862
+ }
863
+ });
864
+ var no_logic_in_params_default = noLogicInParams;
865
+
866
+ // src/rules/prefer-destructuring-params.ts
867
+ import { AST_NODE_TYPES as AST_NODE_TYPES9, ESLintUtils as ESLintUtils13 } from "@typescript-eslint/utils";
868
+ var createRule13 = ESLintUtils13.RuleCreator(
869
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
870
+ );
871
+ var preferDestructuringParams = createRule13({
872
+ name: "prefer-destructuring-params",
873
+ meta: {
874
+ type: "suggestion",
875
+ docs: {
876
+ description: "Enforce destructuring for functions with multiple parameters"
877
+ },
878
+ messages: {
879
+ preferDestructuring: "Functions with multiple parameters should use destructuring"
880
+ },
881
+ schema: []
882
+ },
883
+ defaultOptions: [],
884
+ create(context) {
885
+ const isCallbackFunction = (node) => {
886
+ const { parent } = node;
887
+ return parent?.type === AST_NODE_TYPES9.CallExpression;
888
+ };
889
+ const isDeveloperFunction = (node) => {
890
+ if (node.type === AST_NODE_TYPES9.FunctionDeclaration) {
891
+ return true;
892
+ }
893
+ if (node.type === AST_NODE_TYPES9.FunctionExpression || node.type === AST_NODE_TYPES9.ArrowFunctionExpression) {
894
+ if (isCallbackFunction(node)) {
895
+ return false;
896
+ }
897
+ const { parent } = node;
898
+ return parent?.type === AST_NODE_TYPES9.VariableDeclarator || parent?.type === AST_NODE_TYPES9.AssignmentExpression || parent?.type === AST_NODE_TYPES9.Property || parent?.type === AST_NODE_TYPES9.MethodDefinition;
899
+ }
900
+ return false;
901
+ };
902
+ const checkFunction = (node) => {
903
+ const { filename } = context;
904
+ if (filename.includes("node_modules") || filename.includes(".d.ts")) {
905
+ return;
906
+ }
907
+ if (!isDeveloperFunction(node)) {
908
+ return;
909
+ }
910
+ if (node.type === AST_NODE_TYPES9.FunctionDeclaration && node.id) {
911
+ const functionName = node.id.name;
912
+ if (functionName.startsWith("_") || functionName.includes("$") || /^[A-Z][a-zA-Z]*$/.test(functionName)) {
913
+ return;
914
+ }
915
+ }
916
+ if (node.params.length <= 1) {
917
+ return;
918
+ }
919
+ const hasNonDestructuredParams = node.params.some(
920
+ (param) => param.type !== AST_NODE_TYPES9.ObjectPattern && param.type !== AST_NODE_TYPES9.RestElement
921
+ );
922
+ if (hasNonDestructuredParams) {
923
+ context.report({
924
+ node,
925
+ messageId: "preferDestructuring"
926
+ });
927
+ }
928
+ };
929
+ return {
930
+ FunctionDeclaration: checkFunction,
931
+ FunctionExpression: checkFunction,
932
+ ArrowFunctionExpression: checkFunction
933
+ };
934
+ }
935
+ });
936
+ var prefer_destructuring_params_default = preferDestructuringParams;
937
+
938
+ // src/rules/prefer-import-type.ts
939
+ import { AST_NODE_TYPES as AST_NODE_TYPES10, ESLintUtils as ESLintUtils14 } from "@typescript-eslint/utils";
940
+ var createRule14 = ESLintUtils14.RuleCreator(
941
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
942
+ );
943
+ var preferImportType = createRule14({
944
+ name: "prefer-import-type",
945
+ meta: {
946
+ type: "suggestion",
947
+ docs: {
948
+ description: "Enforce using 'import type' for type-only imports"
949
+ },
950
+ fixable: "code",
951
+ schema: [],
952
+ messages: {
953
+ preferImportType: "Use 'import type' for type-only imports"
954
+ }
955
+ },
956
+ defaultOptions: [],
957
+ create(context) {
958
+ function isInTypeContext(node) {
959
+ let current = node;
960
+ while (current) {
961
+ switch (current.type) {
962
+ case AST_NODE_TYPES10.TSTypeReference:
963
+ case AST_NODE_TYPES10.TSTypeAnnotation:
964
+ case AST_NODE_TYPES10.TSTypeParameterInstantiation:
965
+ case AST_NODE_TYPES10.TSInterfaceHeritage:
966
+ case AST_NODE_TYPES10.TSClassImplements:
967
+ case AST_NODE_TYPES10.TSTypeQuery:
968
+ case AST_NODE_TYPES10.TSTypeAssertion:
969
+ case AST_NODE_TYPES10.TSAsExpression:
970
+ case AST_NODE_TYPES10.TSSatisfiesExpression:
971
+ case AST_NODE_TYPES10.TSTypeAliasDeclaration:
972
+ case AST_NODE_TYPES10.TSInterfaceDeclaration:
973
+ case AST_NODE_TYPES10.TSTypeParameter:
974
+ case AST_NODE_TYPES10.TSQualifiedName:
975
+ return true;
976
+ case AST_NODE_TYPES10.MemberExpression:
977
+ case AST_NODE_TYPES10.Identifier:
978
+ current = current.parent;
979
+ break;
980
+ default:
981
+ return false;
982
+ }
983
+ }
984
+ return false;
985
+ }
986
+ function isUsedAsValue(localName, scope) {
987
+ const variable = scope.set.get(localName);
988
+ if (!variable) {
989
+ return false;
990
+ }
991
+ if (variable.references.length === 0) {
992
+ return false;
993
+ }
994
+ return variable.references.some((ref) => {
995
+ if (ref.isWrite()) {
996
+ return false;
997
+ }
998
+ const { identifier } = ref;
999
+ const { parent } = identifier;
1000
+ if (!parent) {
1001
+ return false;
1002
+ }
1003
+ if (isInTypeContext(parent)) {
1004
+ return false;
1005
+ }
1006
+ switch (parent.type) {
1007
+ case AST_NODE_TYPES10.CallExpression:
1008
+ case AST_NODE_TYPES10.NewExpression:
1009
+ case AST_NODE_TYPES10.JSXOpeningElement:
1010
+ case AST_NODE_TYPES10.JSXClosingElement:
1011
+ case AST_NODE_TYPES10.MemberExpression:
1012
+ case AST_NODE_TYPES10.VariableDeclarator:
1013
+ case AST_NODE_TYPES10.TaggedTemplateExpression:
1014
+ case AST_NODE_TYPES10.SpreadElement:
1015
+ case AST_NODE_TYPES10.ExportSpecifier:
1016
+ case AST_NODE_TYPES10.ArrayExpression:
1017
+ case AST_NODE_TYPES10.ObjectExpression:
1018
+ case AST_NODE_TYPES10.BinaryExpression:
1019
+ case AST_NODE_TYPES10.LogicalExpression:
1020
+ case AST_NODE_TYPES10.UnaryExpression:
1021
+ case AST_NODE_TYPES10.ReturnStatement:
1022
+ case AST_NODE_TYPES10.ArrowFunctionExpression:
1023
+ case AST_NODE_TYPES10.ConditionalExpression:
1024
+ case AST_NODE_TYPES10.AwaitExpression:
1025
+ case AST_NODE_TYPES10.YieldExpression:
1026
+ case AST_NODE_TYPES10.Property:
1027
+ return true;
1028
+ default:
1029
+ return false;
1030
+ }
1031
+ });
1032
+ }
1033
+ function checkImportDeclaration(node) {
1034
+ if (node.importKind === "type") {
1035
+ return;
1036
+ }
1037
+ if (context.filename.includes(".test.") || context.filename.includes(".spec.") || context.filename.includes("__tests__")) {
1038
+ return;
1039
+ }
1040
+ if (node.specifiers.length === 0) {
1041
+ return;
1042
+ }
1043
+ const source = node.source.value;
1044
+ 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/");
1045
+ if (isRuntimeImport) {
1046
+ return;
1047
+ }
1048
+ const scope = context.sourceCode.getScope(node);
1049
+ const isTypeOnlyImport = node.specifiers.every((specifier) => {
1050
+ if (specifier.type === AST_NODE_TYPES10.ImportDefaultSpecifier) {
1051
+ return false;
1052
+ }
1053
+ if (specifier.type === AST_NODE_TYPES10.ImportNamespaceSpecifier) {
1054
+ return false;
1055
+ }
1056
+ if (specifier.type === AST_NODE_TYPES10.ImportSpecifier) {
1057
+ const localName = specifier.local.name;
1058
+ return !isUsedAsValue(localName, scope);
1059
+ }
1060
+ return false;
1061
+ });
1062
+ if (isTypeOnlyImport) {
1063
+ context.report({
1064
+ node,
1065
+ messageId: "preferImportType",
1066
+ fix(fixer) {
1067
+ const sourceText = context.sourceCode.getText(node);
1068
+ const fixedSource = sourceText.replace(/^import\s+/, "import type ");
1069
+ return fixer.replaceText(node, fixedSource);
1070
+ }
1071
+ });
1072
+ }
1073
+ }
1074
+ return {
1075
+ ImportDeclaration: checkImportDeclaration
1076
+ };
1077
+ }
1078
+ });
1079
+ var prefer_import_type_default = preferImportType;
1080
+
1081
+ // src/rules/prefer-interface-over-inline-types.ts
1082
+ import { AST_NODE_TYPES as AST_NODE_TYPES11, ESLintUtils as ESLintUtils15 } from "@typescript-eslint/utils";
1083
+ var createRule15 = ESLintUtils15.RuleCreator(
1084
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
1085
+ );
1086
+ var preferInterfaceOverInlineTypes = createRule15({
1087
+ name: "prefer-interface-over-inline-types",
1088
+ meta: {
1089
+ type: "suggestion",
1090
+ docs: {
1091
+ description: "Enforce interface declarations over inline type annotations for React component props"
1092
+ },
1093
+ fixable: void 0,
1094
+ schema: [],
1095
+ messages: {
1096
+ useInterface: "Use interface declaration for component props instead of inline type annotation"
1097
+ }
1098
+ },
1099
+ defaultOptions: [],
1100
+ create(context) {
1101
+ function hasJSXInConditional(node) {
1102
+ return node.consequent.type === AST_NODE_TYPES11.JSXElement || node.consequent.type === AST_NODE_TYPES11.JSXFragment || node.alternate.type === AST_NODE_TYPES11.JSXElement || node.alternate.type === AST_NODE_TYPES11.JSXFragment;
1103
+ }
1104
+ function hasJSXInLogical(node) {
1105
+ return node.right.type === AST_NODE_TYPES11.JSXElement || node.right.type === AST_NODE_TYPES11.JSXFragment;
1106
+ }
1107
+ function hasJSXReturn(block) {
1108
+ return block.body.some((stmt) => {
1109
+ if (stmt.type === AST_NODE_TYPES11.ReturnStatement && stmt.argument) {
1110
+ return stmt.argument.type === AST_NODE_TYPES11.JSXElement || stmt.argument.type === AST_NODE_TYPES11.JSXFragment || stmt.argument.type === AST_NODE_TYPES11.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES11.LogicalExpression && hasJSXInLogical(stmt.argument);
1111
+ }
1112
+ return false;
1113
+ });
1114
+ }
1115
+ function isReactComponent(node) {
1116
+ if (node.type === AST_NODE_TYPES11.ArrowFunctionExpression) {
1117
+ if (node.body.type === AST_NODE_TYPES11.JSXElement || node.body.type === AST_NODE_TYPES11.JSXFragment) {
1118
+ return true;
1119
+ }
1120
+ if (node.body.type === AST_NODE_TYPES11.BlockStatement) {
1121
+ return hasJSXReturn(node.body);
1122
+ }
1123
+ } else if (node.type === AST_NODE_TYPES11.FunctionExpression || node.type === AST_NODE_TYPES11.FunctionDeclaration) {
1124
+ if (node.body && node.body.type === AST_NODE_TYPES11.BlockStatement) {
1125
+ return hasJSXReturn(node.body);
1126
+ }
1127
+ }
1128
+ return false;
1129
+ }
1130
+ function isInlineTypeAnnotation(node) {
1131
+ if (node.type === AST_NODE_TYPES11.TSTypeLiteral) {
1132
+ return true;
1133
+ }
1134
+ if (node.type === AST_NODE_TYPES11.TSTypeReference && node.typeArguments) {
1135
+ return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES11.TSTypeLiteral);
1136
+ }
1137
+ if (node.type === AST_NODE_TYPES11.TSUnionType) {
1138
+ return node.types.some((type) => isInlineTypeAnnotation(type));
1139
+ }
1140
+ return false;
1141
+ }
1142
+ function hasInlineObjectType(node) {
1143
+ if (node.type === AST_NODE_TYPES11.TSTypeLiteral) {
1144
+ return true;
1145
+ }
1146
+ if (node.type === AST_NODE_TYPES11.TSTypeReference && node.typeArguments) {
1147
+ return node.typeArguments.params.some((param) => param.type === AST_NODE_TYPES11.TSTypeLiteral);
1148
+ }
1149
+ if (node.type === AST_NODE_TYPES11.TSUnionType) {
1150
+ return node.types.some((type) => hasInlineObjectType(type));
1151
+ }
1152
+ return false;
1153
+ }
1154
+ function checkFunction(node) {
1155
+ if (!isReactComponent(node)) {
1156
+ return;
1157
+ }
1158
+ if (node.params.length !== 1) {
1159
+ return;
1160
+ }
1161
+ const param = node.params[0];
1162
+ if (param.type === AST_NODE_TYPES11.Identifier && param.typeAnnotation) {
1163
+ const { typeAnnotation } = param.typeAnnotation;
1164
+ if (isInlineTypeAnnotation(typeAnnotation) && hasInlineObjectType(typeAnnotation)) {
1165
+ context.report({
1166
+ node: param.typeAnnotation,
1167
+ messageId: "useInterface"
1168
+ });
1169
+ }
1170
+ }
1171
+ }
1172
+ return {
1173
+ ArrowFunctionExpression: checkFunction,
1174
+ FunctionExpression: checkFunction,
1175
+ FunctionDeclaration: checkFunction
1176
+ };
1177
+ }
1178
+ });
1179
+ var prefer_interface_over_inline_types_default = preferInterfaceOverInlineTypes;
1180
+
1181
+ // src/rules/prefer-jsx-template-literals.ts
1182
+ import { AST_NODE_TYPES as AST_NODE_TYPES12, ESLintUtils as ESLintUtils16 } from "@typescript-eslint/utils";
1183
+ var createRule16 = ESLintUtils16.RuleCreator(
1184
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
1185
+ );
1186
+ var preferJSXTemplateLiterals = createRule16({
1187
+ name: "prefer-jsx-template-literals",
1188
+ meta: {
1189
+ type: "suggestion",
1190
+ docs: {
1191
+ description: "Enforce using template literals instead of mixing text and JSX expressions"
1192
+ },
1193
+ fixable: "code",
1194
+ schema: [],
1195
+ messages: {
1196
+ preferTemplate: "Use template literal instead of mixing text with JSX expressions"
1197
+ }
1198
+ },
1199
+ defaultOptions: [],
1200
+ create(context) {
1201
+ function handleTextBeforeExpression(textNode, exprNode) {
1202
+ const textValue = textNode.value;
1203
+ const trimmedText = textValue.trim();
1204
+ if (!trimmedText) {
1205
+ return;
1206
+ }
1207
+ const hasTextContent = trimmedText.length > 0 && textValue !== trimmedText;
1208
+ const hasNoTrailingSpace = trimmedText.length > 0 && /\S$/.test(textValue);
1209
+ if (!hasTextContent && !hasNoTrailingSpace) {
1210
+ return;
1211
+ }
1212
+ context.report({
1213
+ node: textNode,
1214
+ messageId: "preferTemplate",
1215
+ fix(fixer) {
1216
+ const textPart = textValue.trimEnd();
1217
+ const exprText = context.sourceCode.getText(exprNode.expression);
1218
+ const templateLiteral = `{\`${textPart}\${${exprText}}\`}`;
1219
+ return [fixer.replaceText(textNode, templateLiteral), fixer.remove(exprNode)];
1220
+ }
1221
+ });
1222
+ }
1223
+ function handleExpressionBeforeText(exprNode, textNode) {
1224
+ const textValue = textNode.value;
1225
+ const trimmedText = textValue.trim();
1226
+ if (!trimmedText) {
1227
+ return;
1228
+ }
1229
+ const startsWithNonWhitespace = /^\S/.test(trimmedText);
1230
+ if (!startsWithNonWhitespace) {
1231
+ return;
1232
+ }
1233
+ context.report({
1234
+ node: textNode,
1235
+ messageId: "preferTemplate",
1236
+ fix(fixer) {
1237
+ const exprText = context.sourceCode.getText(exprNode.expression);
1238
+ const textPart = textValue.trim();
1239
+ const templateLiteral = `{\`\${${exprText}}${textPart}\`}`;
1240
+ return [fixer.replaceText(exprNode, templateLiteral), fixer.remove(textNode)];
1241
+ }
1242
+ });
1243
+ }
1244
+ function checkJSXElement(node) {
1245
+ const { children } = node;
1246
+ if (children.length < 2) {
1247
+ return;
1248
+ }
1249
+ for (let i = 0; i < children.length - 1; i += 1) {
1250
+ const child = children[i];
1251
+ const nextChild = children[i + 1];
1252
+ if (!child || !nextChild) {
1253
+ return;
1254
+ }
1255
+ if (child.type === AST_NODE_TYPES12.JSXText && nextChild.type === AST_NODE_TYPES12.JSXExpressionContainer) {
1256
+ handleTextBeforeExpression(child, nextChild);
1257
+ } else if (child.type === AST_NODE_TYPES12.JSXExpressionContainer && nextChild.type === AST_NODE_TYPES12.JSXText) {
1258
+ handleExpressionBeforeText(child, nextChild);
1259
+ }
1260
+ }
1261
+ }
1262
+ return {
1263
+ JSXElement: checkJSXElement
1264
+ };
1265
+ }
1266
+ });
1267
+ var prefer_jsx_template_literals_default = preferJSXTemplateLiterals;
1268
+
1269
+ // src/rules/prefer-named-param-types.ts
1270
+ import { AST_NODE_TYPES as AST_NODE_TYPES13, ESLintUtils as ESLintUtils17 } from "@typescript-eslint/utils";
1271
+ var createRule17 = ESLintUtils17.RuleCreator(
1272
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
1273
+ );
1274
+ var preferNamedParamTypes = createRule17({
1275
+ name: "prefer-named-param-types",
1276
+ meta: {
1277
+ type: "suggestion",
1278
+ docs: {
1279
+ description: "Enforce named interfaces/types instead of inline object types for function parameters"
1280
+ },
1281
+ messages: {
1282
+ preferNamedParamTypes: "Use a named interface or type for object parameter types instead of inline type annotations"
1283
+ },
1284
+ schema: []
1285
+ },
1286
+ defaultOptions: [],
1287
+ create(context) {
1288
+ function hasInlineObjectType(param) {
1289
+ if (param.type === AST_NODE_TYPES13.AssignmentPattern) {
1290
+ return hasInlineObjectType(param.left);
1291
+ }
1292
+ if (param.type === AST_NODE_TYPES13.ObjectPattern) {
1293
+ if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES13.TSTypeLiteral) {
1294
+ return true;
1295
+ }
1296
+ }
1297
+ if (param.type === AST_NODE_TYPES13.Identifier) {
1298
+ if (param.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES13.TSTypeLiteral) {
1299
+ return true;
1300
+ }
1301
+ }
1302
+ return false;
1303
+ }
1304
+ function checkFunction(node) {
1305
+ let params = [];
1306
+ if ("params" in node) {
1307
+ params = node.params;
1308
+ } else if ("value" in node && node.value) {
1309
+ params = node.value.params;
1310
+ }
1311
+ params.forEach((param) => {
1312
+ if (hasInlineObjectType(param)) {
1313
+ context.report({
1314
+ node: param,
1315
+ messageId: "preferNamedParamTypes"
1316
+ });
1317
+ }
1318
+ });
1319
+ }
1320
+ return {
1321
+ FunctionDeclaration: checkFunction,
1322
+ FunctionExpression: checkFunction,
1323
+ ArrowFunctionExpression: checkFunction,
1324
+ TSMethodSignature: checkFunction,
1325
+ MethodDefinition: checkFunction
1326
+ };
1327
+ }
1328
+ });
1329
+ var prefer_named_param_types_default = preferNamedParamTypes;
1330
+
1331
+ // src/rules/prefer-react-import-types.ts
1332
+ import { AST_NODE_TYPES as AST_NODE_TYPES14, ESLintUtils as ESLintUtils18 } from "@typescript-eslint/utils";
1333
+ var createRule18 = ESLintUtils18.RuleCreator(
1334
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
1335
+ );
1336
+ var preferReactImportTypes = createRule18({
1337
+ name: "prefer-react-import-types",
1338
+ meta: {
1339
+ type: "suggestion",
1340
+ docs: {
1341
+ description: "Enforce importing React types and utilities from 'react' instead of using React.X"
1342
+ },
1343
+ fixable: "code",
1344
+ schema: [],
1345
+ messages: {
1346
+ preferDirectImport: "Use direct import '{{importStatement}}' instead of 'React.{{typeName}}'"
1347
+ }
1348
+ },
1349
+ defaultOptions: [],
1350
+ create(context) {
1351
+ const reactTypes = /* @__PURE__ */ new Set([
1352
+ "ReactNode",
1353
+ "ReactElement",
1354
+ "ReactChildren",
1355
+ "ReactChild",
1356
+ "ComponentType",
1357
+ "FC",
1358
+ "FunctionComponent",
1359
+ "Component",
1360
+ "PureComponent",
1361
+ "ReactEventHandler",
1362
+ "MouseEventHandler",
1363
+ "ChangeEventHandler",
1364
+ "FormEventHandler",
1365
+ "KeyboardEventHandler",
1366
+ "TouchEventHandler",
1367
+ "PointerEventHandler",
1368
+ "FocusEventHandler",
1369
+ "UIEventHandler",
1370
+ "WheelEventHandler",
1371
+ "AnimationEventHandler",
1372
+ "TransitionEventHandler",
1373
+ "RefObject",
1374
+ "MutableRefObject",
1375
+ "Ref",
1376
+ "ForwardedRef",
1377
+ "HTMLProps",
1378
+ "ComponentProps",
1379
+ "JSXElementConstructor"
1380
+ ]);
1381
+ const reactRuntimeExports = /* @__PURE__ */ new Set([
1382
+ "useState",
1383
+ "useEffect",
1384
+ "useContext",
1385
+ "useReducer",
1386
+ "useCallback",
1387
+ "useMemo",
1388
+ "useRef",
1389
+ "useImperativeHandle",
1390
+ "useLayoutEffect",
1391
+ "useDebugValue",
1392
+ "useDeferredValue",
1393
+ "useTransition",
1394
+ "useId",
1395
+ "useSyncExternalStore",
1396
+ "useInsertionEffect",
1397
+ "createElement",
1398
+ "createContext",
1399
+ "forwardRef",
1400
+ "memo",
1401
+ "lazy",
1402
+ "Suspense",
1403
+ "Fragment",
1404
+ "StrictMode",
1405
+ "createRef",
1406
+ "isValidElement",
1407
+ "cloneElement",
1408
+ "Children"
1409
+ ]);
1410
+ const allReactExports = /* @__PURE__ */ new Set([...reactTypes, ...reactRuntimeExports]);
1411
+ function checkMemberExpression(node) {
1412
+ if (node.object.type === AST_NODE_TYPES14.Identifier && node.object.name === "React" && node.property.type === AST_NODE_TYPES14.Identifier && allReactExports.has(node.property.name)) {
1413
+ const typeName = node.property.name;
1414
+ const isType = reactTypes.has(typeName);
1415
+ const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
1416
+ context.report({
1417
+ node,
1418
+ messageId: "preferDirectImport",
1419
+ data: { typeName, importStatement },
1420
+ fix(fixer) {
1421
+ return fixer.replaceText(node, typeName);
1422
+ }
1423
+ });
1424
+ }
1425
+ }
1426
+ return {
1427
+ MemberExpression: checkMemberExpression,
1428
+ "TSTypeReference > TSQualifiedName": (node) => {
1429
+ if (node.left.type === AST_NODE_TYPES14.Identifier && node.left.name === "React" && node.right.type === AST_NODE_TYPES14.Identifier && allReactExports.has(node.right.name)) {
1430
+ const typeName = node.right.name;
1431
+ const isType = reactTypes.has(typeName);
1432
+ const importStatement = isType ? `import type { ${typeName} } from "react"` : `import { ${typeName} } from "react"`;
1433
+ context.report({
1434
+ node,
1435
+ messageId: "preferDirectImport",
1436
+ data: { typeName, importStatement },
1437
+ fix(fixer) {
1438
+ return fixer.replaceText(node, typeName);
1439
+ }
1440
+ });
1441
+ }
1442
+ }
1443
+ };
1444
+ }
1445
+ });
1446
+ var prefer_react_import_types_default = preferReactImportTypes;
1447
+
1448
+ // src/rules/react-props-destructure.ts
1449
+ import { AST_NODE_TYPES as AST_NODE_TYPES15, ESLintUtils as ESLintUtils19 } from "@typescript-eslint/utils";
1450
+ var createRule19 = ESLintUtils19.RuleCreator(
1451
+ (name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`
1452
+ );
1453
+ var reactPropsDestructure = createRule19({
1454
+ name: "react-props-destructure",
1455
+ meta: {
1456
+ type: "suggestion",
1457
+ docs: {
1458
+ description: "Enforce destructuring props inside React component body instead of parameters"
1459
+ },
1460
+ fixable: void 0,
1461
+ schema: [],
1462
+ messages: {
1463
+ noParameterDestructuring: "Destructure props inside component body instead of parameters. Use 'const { {{properties}} } = props;'"
1464
+ }
1465
+ },
1466
+ defaultOptions: [],
1467
+ create(context) {
1468
+ function hasJSXInConditional(node) {
1469
+ return node.consequent.type === AST_NODE_TYPES15.JSXElement || node.consequent.type === AST_NODE_TYPES15.JSXFragment || node.alternate.type === AST_NODE_TYPES15.JSXElement || node.alternate.type === AST_NODE_TYPES15.JSXFragment;
1470
+ }
1471
+ function hasJSXInLogical(node) {
1472
+ return node.right.type === AST_NODE_TYPES15.JSXElement || node.right.type === AST_NODE_TYPES15.JSXFragment;
1473
+ }
1474
+ function hasJSXReturn(block) {
1475
+ return block.body.some((stmt) => {
1476
+ if (stmt.type === AST_NODE_TYPES15.ReturnStatement && stmt.argument) {
1477
+ return stmt.argument.type === AST_NODE_TYPES15.JSXElement || stmt.argument.type === AST_NODE_TYPES15.JSXFragment || stmt.argument.type === AST_NODE_TYPES15.ConditionalExpression && hasJSXInConditional(stmt.argument) || stmt.argument.type === AST_NODE_TYPES15.LogicalExpression && hasJSXInLogical(stmt.argument);
1478
+ }
1479
+ return false;
1480
+ });
1481
+ }
1482
+ function isReactComponent(node) {
1483
+ if (node.type === AST_NODE_TYPES15.ArrowFunctionExpression) {
1484
+ if (node.body.type === AST_NODE_TYPES15.JSXElement || node.body.type === AST_NODE_TYPES15.JSXFragment) {
1485
+ return true;
1486
+ }
1487
+ if (node.body.type === AST_NODE_TYPES15.BlockStatement) {
1488
+ return hasJSXReturn(node.body);
1489
+ }
1490
+ } else if (node.type === AST_NODE_TYPES15.FunctionExpression || node.type === AST_NODE_TYPES15.FunctionDeclaration) {
1491
+ if (node.body && node.body.type === AST_NODE_TYPES15.BlockStatement) {
1492
+ return hasJSXReturn(node.body);
1493
+ }
1494
+ }
1495
+ return false;
1496
+ }
1497
+ function checkFunction(node) {
1498
+ if (!isReactComponent(node)) {
1499
+ return;
1500
+ }
1501
+ if (node.params.length !== 1) {
1502
+ return;
1503
+ }
1504
+ const param = node.params[0];
1505
+ if (param.type === AST_NODE_TYPES15.ObjectPattern) {
1506
+ const properties = param.properties.filter((prop) => prop.type === AST_NODE_TYPES15.Property).map((prop) => {
1507
+ if (prop.key.type === AST_NODE_TYPES15.Identifier) {
1508
+ return prop.key.name;
1509
+ }
1510
+ return null;
1511
+ }).filter((name) => name !== null);
1512
+ if (properties.length === 0) {
1513
+ return;
1514
+ }
1515
+ context.report({
1516
+ node: param,
1517
+ messageId: "noParameterDestructuring",
1518
+ data: {
1519
+ properties: properties.join(", ")
1520
+ }
1521
+ });
1522
+ }
1523
+ }
1524
+ return {
1525
+ ArrowFunctionExpression: checkFunction,
1526
+ FunctionExpression: checkFunction,
1527
+ FunctionDeclaration: checkFunction
1528
+ };
1529
+ }
1530
+ });
1531
+ var react_props_destructure_default = reactPropsDestructure;
1532
+
1533
+ // src/index.ts
1534
+ var meta = {
1535
+ name: package_default.name,
1536
+ version: package_default.version
1537
+ };
1538
+ var rules = {
1539
+ "enforce-readonly-component-props": enforce_readonly_component_props_default,
1540
+ "enforce-sorted-destructuring": enforce_sorted_destructuring_default,
1541
+ "file-kebab-case": file_kebab_case_default,
1542
+ "jsx-pascal-case": jsx_pascal_case_default,
1543
+ "jsx-no-non-component-function": jsx_no_non_component_function_default,
1544
+ "jsx-no-variable-in-callback": jsx_no_variable_in_callback_default,
1545
+ "md-filename-case-restriction": md_filename_case_restriction_default,
1546
+ "no-complex-inline-return": no_complex_inline_return_default,
1547
+ "no-emoji": no_emoji_default,
1548
+ "no-env-fallback": no_env_fallback_default,
1549
+ "no-explicit-return-type": no_explicit_return_type_default,
1550
+ "no-logic-in-params": no_logic_in_params_default,
1551
+ "prefer-destructuring-params": prefer_destructuring_params_default,
1552
+ "prefer-import-type": prefer_import_type_default,
1553
+ "prefer-interface-over-inline-types": prefer_interface_over_inline_types_default,
1554
+ "prefer-jsx-template-literals": prefer_jsx_template_literals_default,
1555
+ "prefer-named-param-types": prefer_named_param_types_default,
1556
+ "prefer-react-import-types": prefer_react_import_types_default,
1557
+ "react-props-destructure": react_props_destructure_default
1558
+ };
1559
+ var plugin = {
1560
+ meta,
1561
+ rules
1562
+ };
1563
+ var baseRules = {
1564
+ "nextfriday/no-emoji": "warn",
1565
+ "nextfriday/enforce-sorted-destructuring": "warn",
1566
+ "nextfriday/file-kebab-case": "warn",
1567
+ "nextfriday/md-filename-case-restriction": "warn",
1568
+ "nextfriday/prefer-destructuring-params": "warn",
1569
+ "nextfriday/no-explicit-return-type": "warn",
1570
+ "nextfriday/prefer-import-type": "warn",
1571
+ "nextfriday/prefer-named-param-types": "warn",
1572
+ "nextfriday/prefer-react-import-types": "warn",
1573
+ "nextfriday/no-complex-inline-return": "warn",
1574
+ "nextfriday/no-logic-in-params": "warn",
1575
+ "nextfriday/no-env-fallback": "warn"
1576
+ };
1577
+ var baseRecommendedRules = {
1578
+ "nextfriday/no-emoji": "error",
1579
+ "nextfriday/enforce-sorted-destructuring": "error",
1580
+ "nextfriday/file-kebab-case": "error",
1581
+ "nextfriday/md-filename-case-restriction": "error",
1582
+ "nextfriday/prefer-destructuring-params": "error",
1583
+ "nextfriday/no-explicit-return-type": "error",
1584
+ "nextfriday/prefer-import-type": "error",
1585
+ "nextfriday/prefer-named-param-types": "error",
1586
+ "nextfriday/prefer-react-import-types": "error",
1587
+ "nextfriday/no-complex-inline-return": "error",
1588
+ "nextfriday/no-logic-in-params": "error",
1589
+ "nextfriday/no-env-fallback": "error"
1590
+ };
1591
+ var jsxRules = {
1592
+ "nextfriday/jsx-pascal-case": "warn",
1593
+ "nextfriday/jsx-no-non-component-function": "warn",
1594
+ "nextfriday/jsx-no-variable-in-callback": "warn",
1595
+ "nextfriday/prefer-interface-over-inline-types": "warn",
1596
+ "nextfriday/prefer-jsx-template-literals": "warn",
1597
+ "nextfriday/react-props-destructure": "warn",
1598
+ "nextfriday/enforce-readonly-component-props": "warn"
1599
+ };
1600
+ var jsxRecommendedRules = {
1601
+ "nextfriday/jsx-pascal-case": "error",
1602
+ "nextfriday/jsx-no-non-component-function": "error",
1603
+ "nextfriday/jsx-no-variable-in-callback": "error",
1604
+ "nextfriday/prefer-interface-over-inline-types": "error",
1605
+ "nextfriday/prefer-jsx-template-literals": "error",
1606
+ "nextfriday/react-props-destructure": "error",
1607
+ "nextfriday/enforce-readonly-component-props": "error"
1608
+ };
1609
+ var createConfig = (configRules) => ({
1610
+ plugins: {
1611
+ nextfriday: plugin
1612
+ },
1613
+ rules: configRules
1614
+ });
1615
+ var configs = {
1616
+ base: createConfig(baseRules),
1617
+ "base/recommended": createConfig(baseRecommendedRules),
1618
+ react: createConfig({
1619
+ ...baseRules,
1620
+ ...jsxRules
1621
+ }),
1622
+ "react/recommended": createConfig({
1623
+ ...baseRecommendedRules,
1624
+ ...jsxRecommendedRules
1625
+ }),
1626
+ nextjs: createConfig({
1627
+ ...baseRules,
1628
+ ...jsxRules
1629
+ }),
1630
+ "nextjs/recommended": createConfig({
1631
+ ...baseRecommendedRules,
1632
+ ...jsxRecommendedRules
1633
+ })
1634
+ };
1635
+ var nextfridayPlugin = {
1636
+ meta,
1637
+ configs,
1638
+ rules
1639
+ };
1640
+ var index_default = nextfridayPlugin;
1641
+ export {
1642
+ configs,
1643
+ index_default as default,
1644
+ meta,
1645
+ rules
1646
+ };
1647
+ //# sourceMappingURL=index.js.map