eslint-plugin-nextfriday 4.1.0 → 4.3.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.
@@ -0,0 +1,69 @@
1
+ # no-helper-function-in-test
2
+
3
+ Disallow helper function definitions in test files.
4
+
5
+ ## Rule Details
6
+
7
+ Test files should contain only pure test code — `describe`, `it`, `test`, `beforeEach`, and similar test runner constructs. Helper functions defined at the top level of a test file are utility code that belongs in a separate file and should be imported.
8
+
9
+ ### Why?
10
+
11
+ When helper functions are defined inside test files, they become invisible to other tests and are harder to maintain, test independently, and reuse. Keeping test files free of utility logic makes them easier to read and reason about.
12
+
13
+ ## Examples
14
+
15
+ ### Incorrect
16
+
17
+ ```ts
18
+ function findTemplateFiles(directory: string): string[] {
19
+ // ...
20
+ }
21
+
22
+ const extractImports = (source: string): string[] => {
23
+ // ...
24
+ };
25
+
26
+ describe("template imports", () => {
27
+ it("must only import from allowed paths", () => {
28
+ // ...
29
+ });
30
+ });
31
+ ```
32
+
33
+ ### Correct
34
+
35
+ ```ts
36
+ import { findTemplateFiles, extractImports } from "./test-utils";
37
+
38
+ describe("template imports", () => {
39
+ it("must only import from allowed paths", () => {
40
+ // ...
41
+ });
42
+ });
43
+ ```
44
+
45
+ ## What This Rule Checks
46
+
47
+ - Top-level `function` declarations
48
+ - Top-level `const`/`let`/`var` declarations assigned an arrow function or function expression
49
+
50
+ Constants that are not functions (regex patterns, arrays, objects) are allowed.
51
+
52
+ ## Exceptions
53
+
54
+ Functions declared inside `describe`, `it`, `test`, `beforeEach`, or other callback bodies are not flagged.
55
+
56
+ ## When Not To Use It
57
+
58
+ Disable this rule for files that are intentionally test utility modules (e.g., `test-utils.ts`, `helpers.ts`) rather than test suite files.
59
+
60
+ This rule should be scoped to test files using the ESLint `files` glob:
61
+
62
+ ```js
63
+ {
64
+ files: ["**/*.test.ts", "**/*.spec.ts", "**/*.test.tsx", "**/*.spec.tsx"],
65
+ rules: {
66
+ "nextfriday/no-helper-function-in-test": "error",
67
+ },
68
+ }
69
+ ```