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.
- package/CHANGELOG.md +18 -0
- package/README.md +22 -8
- package/docs/rules/ENFORCE_HOOK_FILENAME.md +77 -0
- package/docs/rules/ENFORCE_RENDER_NAMING.md +96 -0
- package/docs/rules/ENFORCE_TEST_FILENAME.md +61 -0
- package/docs/rules/JSX_NO_DATA_ARRAY.md +63 -0
- package/docs/rules/JSX_NO_DATA_OBJECT.md +71 -0
- package/docs/rules/JSX_NO_SUB_INTERFACE.md +86 -0
- package/docs/rules/NO_HELPER_FUNCTION_IN_HOOK.md +86 -0
- package/docs/rules/NO_HELPER_FUNCTION_IN_TEST.md +69 -0
- package/lib/index.cjs +1143 -495
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +336 -0
- package/lib/index.d.ts +336 -0
- package/lib/index.js +1185 -537
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -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
|
+
```
|