@kristijorgji/eslint-plugin 0.1.2 → 0.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/README.md +80 -7
- package/dist/configs/component-extraction.d.ts +1 -0
- package/dist/configs/component-extraction.d.ts.map +1 -1
- package/dist/configs/component-extraction.js +1 -1
- package/dist/configs/component-extraction.js.map +1 -1
- package/dist/configs/recommended.d.ts +3 -1
- package/dist/configs/recommended.d.ts.map +1 -1
- package/dist/configs/recommended.js +3 -2
- package/dist/configs/recommended.js.map +1 -1
- package/dist/configs/size-limits.d.ts +39 -0
- package/dist/configs/size-limits.d.ts.map +1 -0
- package/dist/configs/size-limits.js +111 -0
- package/dist/configs/size-limits.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +0 -2
- package/dist/plugin.js.map +1 -1
- package/package.json +4 -3
- package/skills/component-extraction/SKILL.md +73 -0
- package/skills/size-limits/SKILL.md +85 -0
- package/dist/rules/jsx-leading-prop-order.d.ts +0 -16
- package/dist/rules/jsx-leading-prop-order.d.ts.map +0 -1
- package/dist/rules/jsx-leading-prop-order.js +0 -143
- package/dist/rules/jsx-leading-prop-order.js.map +0 -1
package/README.md
CHANGED
|
@@ -35,10 +35,13 @@ export default [
|
|
|
35
35
|
|
|
36
36
|
- `kj/no-pure-type-alias`
|
|
37
37
|
- `kj/no-single-export-barrel`
|
|
38
|
-
- `kj/jsx-leading-prop-order`
|
|
39
38
|
|
|
40
39
|
Pass `{ severity: 'warn' }` to downgrade all of them to warnings.
|
|
41
40
|
|
|
41
|
+
JSX prop order is **not** in this package — use
|
|
42
|
+
`@kristijorgji/eslint-config-react-typescript`, which enables
|
|
43
|
+
`perfectionist/sort-jsx-props`.
|
|
44
|
+
|
|
42
45
|
`kj/no-weak-typeof-satisfies` is **not** in `recommended()` — it needs type information. Use `typed()` for that.
|
|
43
46
|
|
|
44
47
|
### Type-aware rules
|
|
@@ -75,6 +78,80 @@ This enables `kj/no-multi-comp` for `**/*.tsx` files, plus `max-lines-per-functi
|
|
|
75
78
|
and `max-lines` for components, and `max-lines-per-function` for hook files
|
|
76
79
|
(`**/use*.ts`, `**/hooks/**/*.ts`).
|
|
77
80
|
|
|
81
|
+
#### Bundled agent skill
|
|
82
|
+
|
|
83
|
+
This package ships `skills/component-extraction/` (an [Agent Skills](https://agentskills.io)
|
|
84
|
+
`SKILL.md`). Coding agents do **not** read `node_modules` automatically — sync the
|
|
85
|
+
folder into your project's `.agents/skills/` (for example under
|
|
86
|
+
`.agents/skills/vendor/component-extraction/`) after install.
|
|
87
|
+
|
|
88
|
+
Optional Cursor rule wrapper (lives in the **consumer** repo, not this package):
|
|
89
|
+
|
|
90
|
+
```md
|
|
91
|
+
---
|
|
92
|
+
description: Split oversized React components and hooks flagged by ESLint
|
|
93
|
+
globs: "**/*.{tsx,ts}"
|
|
94
|
+
alwaysApply: false
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
# Component extraction
|
|
98
|
+
|
|
99
|
+
When ESLint reports `kj/no-multi-comp`, `max-lines-per-function`, or `max-lines`
|
|
100
|
+
warnings, or when splitting components/hooks, read and follow:
|
|
101
|
+
|
|
102
|
+
- [.agents/skills/vendor/component-extraction/SKILL.md](../../.agents/skills/vendor/component-extraction/SKILL.md)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Size limits
|
|
106
|
+
|
|
107
|
+
Line-count and cognitive-complexity limits for non-component TypeScript modules
|
|
108
|
+
(`.ts`, `.mts`, `.cts`). Use this alongside `componentExtraction()` so `.tsx`
|
|
109
|
+
components stay under the component rules and `.ts` modules stay under these:
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
import { DEFAULT_HOOK_FILES, DEFAULT_SIZE_LIMITS_IGNORES, sizeLimits } from '@kristijorgji/eslint-plugin';
|
|
113
|
+
import path from 'node:path';
|
|
114
|
+
|
|
115
|
+
export default [
|
|
116
|
+
...sizeLimits({
|
|
117
|
+
severity: 'error',
|
|
118
|
+
fileMaxLines: 300,
|
|
119
|
+
functionMaxLines: 80,
|
|
120
|
+
cognitiveComplexity: 20,
|
|
121
|
+
baselineFile: path.join(import.meta.dirname, 'size-limits.baseline.json'),
|
|
122
|
+
ignores: DEFAULT_SIZE_LIMITS_IGNORES,
|
|
123
|
+
functionIgnores: DEFAULT_HOOK_FILES,
|
|
124
|
+
}),
|
|
125
|
+
];
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
| Option | Default | Purpose |
|
|
129
|
+
| --- | --- | --- |
|
|
130
|
+
| `severity` | `'error'` | `'warn'` or `'error'` |
|
|
131
|
+
| `files` | `**/*.{ts,mts,cts}` | Which files to check |
|
|
132
|
+
| `ignores` | tests, stories, `*.d.ts`, fixture folders | Replaces the default ignore list when set |
|
|
133
|
+
| `fileMaxLines` | `300` | `max-lines` (blank lines and comments skipped) |
|
|
134
|
+
| `functionMaxLines` | `80` | `max-lines-per-function` |
|
|
135
|
+
| `cognitiveComplexity` | `20` | `sonarjs/cognitive-complexity`; `false` disables it |
|
|
136
|
+
| `functionIgnores` | `[]` | Extra globs excluded from the function rule only (for example hook files) |
|
|
137
|
+
| `sonarjsPlugin` | unset | Register `sonarjs` on the complexity block; otherwise another config must register it |
|
|
138
|
+
| `baseline` / `baselineFile` | none | Frozen per-file exemption list |
|
|
139
|
+
|
|
140
|
+
The exemption list is a JSON object keyed by paths relative to the ESLint config
|
|
141
|
+
directory. Each value is a map of rule id to the current (integer) measurement.
|
|
142
|
+
A file in the list may not grow: ESLint uses `max(limit, baselineValue)` for
|
|
143
|
+
that file. Values may only shrink. New oversized files must be refactored, not
|
|
144
|
+
added to the list.
|
|
145
|
+
|
|
146
|
+
Set `KJ_SIZE_LIMITS_IGNORE_BASELINE=1` while generating the list so the
|
|
147
|
+
exemption-list blocks do not hide the real measurements.
|
|
148
|
+
|
|
149
|
+
#### Bundled agent skill
|
|
150
|
+
|
|
151
|
+
This package ships `skills/size-limits/`. Sync it into the consuming project's
|
|
152
|
+
`.agents/skills/` after install (for example
|
|
153
|
+
`.agents/skills/vendor/size-limits/`).
|
|
154
|
+
|
|
78
155
|
### `no-barrel`
|
|
79
156
|
|
|
80
157
|
`kj/no-barrel` is opt-in and requires two options, since it targets a specific
|
|
@@ -135,7 +212,6 @@ use `restrictedSyntax()` directly if you want just the entry array.
|
|
|
135
212
|
| `kj/no-pure-type-alias` | Discourage pure re-alias type declarations (`type A = B;`). | No |
|
|
136
213
|
| `kj/no-single-export-barrel` | Disallow `index.ts` barrels that only re-export a single symbol. | No |
|
|
137
214
|
| `kj/no-weak-typeof-satisfies` | Disallow `typeof expr` in `satisfies` when `expr` is `any`/`unknown` (enable via `typed()`). | No |
|
|
138
|
-
| `kj/jsx-leading-prop-order` | Require configured leading JSX attributes to appear in order. | Yes |
|
|
139
215
|
| `kj/no-barrel` | Disallow importing/exporting a configured package's barrel entry point. | No |
|
|
140
216
|
|
|
141
217
|
### Options
|
|
@@ -149,9 +225,6 @@ use `restrictedSyntax()` directly if you want just the entry array.
|
|
|
149
225
|
- **`kj/no-weak-typeof-satisfies`**: `{ allowUnknown?: boolean (default false) }`.
|
|
150
226
|
When `true`, only `any` is flagged (not `unknown`). Requires type information —
|
|
151
227
|
use with `typed()` or a type-aware parser configuration.
|
|
152
|
-
- **`kj/jsx-leading-prop-order`**: `{ order?: string[] }`, defaults to
|
|
153
|
-
`['data-testid', 'testID', 'key', 'ref', 'id', 'name']`. Never reorders attributes
|
|
154
|
-
across a `{...spread}`.
|
|
155
228
|
- **`kj/no-barrel`**: `{ packageName: string, exampleSubpath: string }` (both
|
|
156
229
|
**required**).
|
|
157
230
|
|
|
@@ -165,7 +238,7 @@ If you previously vendored these rules locally, update rule IDs as follows:
|
|
|
165
238
|
| `type-alias/no-pure-alias` | `kj/no-pure-type-alias` |
|
|
166
239
|
| `no-single-export-barrel/no-single-export-barrel` | `kj/no-single-export-barrel` |
|
|
167
240
|
| `repo-typing/no-weak-typeof-satisfies` | `kj/no-weak-typeof-satisfies` |
|
|
168
|
-
| `jsx-leading-prop-order/jsx-leading-prop-order` | `
|
|
241
|
+
| `jsx-leading-prop-order/jsx-leading-prop-order` | `perfectionist/sort-jsx-props` (via `@kristijorgji/eslint-config-react-typescript`) |
|
|
169
242
|
| `<pkg>/no-barrel` (e.g. `utils/no-barrel`) | `kj/no-barrel` (pass `packageName`/`exampleSubpath` in options) |
|
|
170
243
|
|
|
171
244
|
## Overriding caveat
|
|
@@ -182,7 +255,7 @@ export default [
|
|
|
182
255
|
files: ['**/*.tsx'],
|
|
183
256
|
rules: {
|
|
184
257
|
// This wins over recommended()'s severity for the same rule/files.
|
|
185
|
-
'kj/
|
|
258
|
+
'kj/no-pure-type-alias': 'warn',
|
|
186
259
|
},
|
|
187
260
|
},
|
|
188
261
|
];
|
|
@@ -14,6 +14,7 @@ export interface ComponentExtractionOptions {
|
|
|
14
14
|
/** Glob patterns excluded from all component-extraction checks. */
|
|
15
15
|
ignores?: string[];
|
|
16
16
|
}
|
|
17
|
+
export declare const DEFAULT_HOOK_FILES: string[];
|
|
17
18
|
/**
|
|
18
19
|
* Encourages splitting large components/hooks into smaller modules: flags files with
|
|
19
20
|
* more than one component (`kj/no-multi-comp`), components/files/hooks that exceed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-extraction.d.ts","sourceRoot":"","sources":["../../src/configs/component-extraction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIrC,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,8DAA8D;IAC9D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,8FAA8F;IAC9F,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;
|
|
1
|
+
{"version":3,"file":"component-extraction.d.ts","sourceRoot":"","sources":["../../src/configs/component-extraction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIrC,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,8DAA8D;IAC9D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,8FAA8F;IAC9F,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAMD,eAAO,MAAM,kBAAkB,UAAqC,CAAC;AAGrE;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,MAAM,CAAC,MAAM,EAAE,CAqCzF"}
|
|
@@ -3,7 +3,7 @@ const DEFAULT_COMPONENT_MAX_LINES = 70;
|
|
|
3
3
|
const DEFAULT_FILE_MAX_LINES = 300;
|
|
4
4
|
const DEFAULT_HOOK_MAX_LINES = 120;
|
|
5
5
|
const DEFAULT_COMPONENT_FILES = ['**/*.tsx'];
|
|
6
|
-
const DEFAULT_HOOK_FILES = ['**/use*.ts', '**/hooks/**/*.ts'];
|
|
6
|
+
export const DEFAULT_HOOK_FILES = ['**/use*.ts', '**/hooks/**/*.ts'];
|
|
7
7
|
const DEFAULT_IGNORES = ['**/*.test.tsx', '**/*.stories.tsx', '**/*.test.ts', '**/*.stories.ts'];
|
|
8
8
|
/**
|
|
9
9
|
* Encourages splitting large components/hooks into smaller modules: flags files with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-extraction.js","sourceRoot":"","sources":["../../src/configs/component-extraction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAkBtC,MAAM,2BAA2B,GAAG,EAAE,CAAC;AACvC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,uBAAuB,GAAG,CAAC,UAAU,CAAC,CAAC;AAC7C,MAAM,kBAAkB,GAAG,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"component-extraction.js","sourceRoot":"","sources":["../../src/configs/component-extraction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAkBtC,MAAM,2BAA2B,GAAG,EAAE,CAAC;AACvC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,uBAAuB,GAAG,CAAC,UAAU,CAAC,CAAC;AAC7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;AACrE,MAAM,eAAe,GAAG,CAAC,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAE,iBAAiB,CAAC,CAAC;AAEjG;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAoC;IACtE,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,MAAM,CAAC;IAC7C,MAAM,iBAAiB,GAAG,OAAO,EAAE,iBAAiB,IAAI,2BAA2B,CAAC;IACpF,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,sBAAsB,CAAC;IACrE,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,sBAAsB,CAAC;IACrE,MAAM,cAAc,GAAG,OAAO,EAAE,cAAc,IAAI,uBAAuB,CAAC;IAC1E,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,kBAAkB,CAAC;IAC3D,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,eAAe,CAAC;IAEpD,OAAO;QACL;YACE,KAAK,EAAE,cAAc;YACrB,OAAO;YACP,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE;YACvB,KAAK,EAAE;gBACL,kBAAkB,EAAE,QAAQ;aAC7B;SACF;QACD;YACE,KAAK,EAAE,cAAc;YACrB,OAAO;YACP,KAAK,EAAE;gBACL,wBAAwB,EAAE;oBACxB,QAAQ;oBACR,EAAE,GAAG,EAAE,iBAAiB,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE;iBACrE;gBACD,WAAW,EAAE,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;aACzF;SACF;QACD;YACE,KAAK,EAAE,SAAS;YAChB,OAAO;YACP,KAAK,EAAE;gBACL,wBAAwB,EAAE,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;aACtG;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -6,7 +6,9 @@ export interface RecommendedOptions {
|
|
|
6
6
|
* Baseline recommended rules for TypeScript/TSX files.
|
|
7
7
|
* `kj/no-weak-typeof-satisfies` is type-aware — enable it via `typed()` instead.
|
|
8
8
|
* `no-multi-comp` and `no-barrel` are intentionally left out (see `componentExtraction()`
|
|
9
|
-
* and manual opt-in respectively).
|
|
9
|
+
* and manual opt-in respectively). JSX prop order lives on
|
|
10
|
+
* `@kristijorgji/eslint-config-react-typescript` (`perfectionist/sort-jsx-props`).
|
|
11
|
+
* Returns a fresh array on every call.
|
|
10
12
|
*/
|
|
11
13
|
export declare function recommended(options?: RecommendedOptions): Linter.Config[];
|
|
12
14
|
//# sourceMappingURL=recommended.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recommended.d.ts","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIrC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAC7B;AAED
|
|
1
|
+
{"version":3,"file":"recommended.d.ts","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIrC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,CAazE"}
|
|
@@ -3,7 +3,9 @@ import { plugin } from '../plugin.js';
|
|
|
3
3
|
* Baseline recommended rules for TypeScript/TSX files.
|
|
4
4
|
* `kj/no-weak-typeof-satisfies` is type-aware — enable it via `typed()` instead.
|
|
5
5
|
* `no-multi-comp` and `no-barrel` are intentionally left out (see `componentExtraction()`
|
|
6
|
-
* and manual opt-in respectively).
|
|
6
|
+
* and manual opt-in respectively). JSX prop order lives on
|
|
7
|
+
* `@kristijorgji/eslint-config-react-typescript` (`perfectionist/sort-jsx-props`).
|
|
8
|
+
* Returns a fresh array on every call.
|
|
7
9
|
*/
|
|
8
10
|
export function recommended(options) {
|
|
9
11
|
const severity = options?.severity ?? 'error';
|
|
@@ -14,7 +16,6 @@ export function recommended(options) {
|
|
|
14
16
|
rules: {
|
|
15
17
|
'kj/no-pure-type-alias': severity,
|
|
16
18
|
'kj/no-single-export-barrel': severity,
|
|
17
|
-
'kj/jsx-leading-prop-order': severity,
|
|
18
19
|
},
|
|
19
20
|
},
|
|
20
21
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recommended.js","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAMtC
|
|
1
|
+
{"version":3,"file":"recommended.js","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAMtC;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,OAA4B;IACtD,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,OAAO,CAAC;IAE9C,OAAO;QACL;YACE,KAAK,EAAE,CAAC,eAAe,CAAC;YACxB,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE;YACvB,KAAK,EAAE;gBACL,uBAAuB,EAAE,QAAQ;gBACjC,4BAA4B,EAAE,QAAQ;aACvC;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ESLint, Linter } from 'eslint';
|
|
2
|
+
export declare const SIZE_LIMIT_RULES: readonly ["max-lines", "max-lines-per-function", "sonarjs/cognitive-complexity"];
|
|
3
|
+
export type SizeLimitRule = (typeof SIZE_LIMIT_RULES)[number];
|
|
4
|
+
/** Keys are paths relative to the ESLint config directory (posix separators). */
|
|
5
|
+
export type SizeLimitsBaseline = Record<string, Partial<Record<SizeLimitRule, number>>>;
|
|
6
|
+
export declare const SIZE_LIMITS_IGNORE_BASELINE_ENV = "KJ_SIZE_LIMITS_IGNORE_BASELINE";
|
|
7
|
+
export declare const DEFAULT_SIZE_LIMITS_FILES: string[];
|
|
8
|
+
export declare const DEFAULT_SIZE_LIMITS_IGNORES: string[];
|
|
9
|
+
export declare const SIZE_LIMITS_DEFAULTS: {
|
|
10
|
+
readonly fileMaxLines: 300;
|
|
11
|
+
readonly functionMaxLines: 80;
|
|
12
|
+
readonly cognitiveComplexity: 20;
|
|
13
|
+
};
|
|
14
|
+
export interface SizeLimitsOptions {
|
|
15
|
+
severity?: 'warn' | 'error';
|
|
16
|
+
/** Defaults to `DEFAULT_SIZE_LIMITS_FILES`. */
|
|
17
|
+
files?: string[];
|
|
18
|
+
/** Replaces `DEFAULT_SIZE_LIMITS_IGNORES` when set. */
|
|
19
|
+
ignores?: string[];
|
|
20
|
+
fileMaxLines?: number;
|
|
21
|
+
functionMaxLines?: number;
|
|
22
|
+
/** `false` disables the sonarjs rule. */
|
|
23
|
+
cognitiveComplexity?: number | false;
|
|
24
|
+
/** Extra globs excluded from `max-lines-per-function` only (for example hook files governed elsewhere). */
|
|
25
|
+
functionIgnores?: string[];
|
|
26
|
+
/** Registered on the complexity block when given; otherwise `sonarjs` must be registered by another config. */
|
|
27
|
+
sonarjsPlugin?: ESLint.Plugin;
|
|
28
|
+
baseline?: SizeLimitsBaseline;
|
|
29
|
+
/** Absolute path to a JSON exemption list; a missing file means no entries. */
|
|
30
|
+
baselineFile?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function escapeGlobPath(filePath: string): string;
|
|
33
|
+
export declare function readSizeLimitsBaseline(filePath: string): SizeLimitsBaseline;
|
|
34
|
+
/**
|
|
35
|
+
* Line-count and cognitive-complexity limits for non-component modules, with a frozen
|
|
36
|
+
* per-file exemption list (values may only shrink). Returns a fresh array on every call.
|
|
37
|
+
*/
|
|
38
|
+
export declare function sizeLimits(options?: SizeLimitsOptions): Linter.Config[];
|
|
39
|
+
//# sourceMappingURL=size-limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size-limits.d.ts","sourceRoot":"","sources":["../../src/configs/size-limits.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAA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CAAC,MAAM,EAAE,CA0DvE"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
export const SIZE_LIMIT_RULES = ['max-lines', 'max-lines-per-function', 'sonarjs/cognitive-complexity'];
|
|
3
|
+
export const SIZE_LIMITS_IGNORE_BASELINE_ENV = 'KJ_SIZE_LIMITS_IGNORE_BASELINE';
|
|
4
|
+
export const DEFAULT_SIZE_LIMITS_FILES = ['**/*.ts', '**/*.mts', '**/*.cts'];
|
|
5
|
+
export const DEFAULT_SIZE_LIMITS_IGNORES = [
|
|
6
|
+
'**/*.test.*',
|
|
7
|
+
'**/*.spec.*',
|
|
8
|
+
'**/*.stories.*',
|
|
9
|
+
'**/*.d.ts',
|
|
10
|
+
'**/test/**',
|
|
11
|
+
'**/tests/**',
|
|
12
|
+
'**/__tests__/**',
|
|
13
|
+
'**/__fixtures__/**',
|
|
14
|
+
'**/__mocks__/**',
|
|
15
|
+
];
|
|
16
|
+
export const SIZE_LIMITS_DEFAULTS = { fileMaxLines: 300, functionMaxLines: 80, cognitiveComplexity: 20 };
|
|
17
|
+
const LINE_OPTIONS = { skipBlankLines: true, skipComments: true };
|
|
18
|
+
function isPlainObject(value) {
|
|
19
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
export function escapeGlobPath(filePath) {
|
|
22
|
+
return filePath.replace(/[[\]{}()*?!+@]/g, '\\$&');
|
|
23
|
+
}
|
|
24
|
+
export function readSizeLimitsBaseline(filePath) {
|
|
25
|
+
if (!fs.existsSync(filePath))
|
|
26
|
+
return {};
|
|
27
|
+
const parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
28
|
+
if (!isPlainObject(parsed))
|
|
29
|
+
throw new Error(`${filePath}: size-limits baseline must be a JSON object`);
|
|
30
|
+
for (const [file, entry] of Object.entries(parsed)) {
|
|
31
|
+
if (!isPlainObject(entry))
|
|
32
|
+
throw new Error(`${filePath}: entry for ${file} must be an object`);
|
|
33
|
+
for (const [rule, value] of Object.entries(entry)) {
|
|
34
|
+
if (!SIZE_LIMIT_RULES.includes(rule)) {
|
|
35
|
+
throw new Error(`${filePath}: unknown rule "${rule}" for ${file}`);
|
|
36
|
+
}
|
|
37
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {
|
|
38
|
+
throw new Error(`${filePath}: value for ${file} ${rule} must be a positive integer`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return parsed;
|
|
43
|
+
}
|
|
44
|
+
function ruleEntry(rule, severity, max) {
|
|
45
|
+
if (rule === 'sonarjs/cognitive-complexity')
|
|
46
|
+
return [severity, max];
|
|
47
|
+
if (rule === 'max-lines-per-function')
|
|
48
|
+
return [severity, { max, ...LINE_OPTIONS, IIFEs: true }];
|
|
49
|
+
return [severity, { max, ...LINE_OPTIONS }];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Line-count and cognitive-complexity limits for non-component modules, with a frozen
|
|
53
|
+
* per-file exemption list (values may only shrink). Returns a fresh array on every call.
|
|
54
|
+
*/
|
|
55
|
+
export function sizeLimits(options) {
|
|
56
|
+
const severity = options?.severity ?? 'error';
|
|
57
|
+
const files = options?.files ?? DEFAULT_SIZE_LIMITS_FILES;
|
|
58
|
+
const ignores = options?.ignores ?? DEFAULT_SIZE_LIMITS_IGNORES;
|
|
59
|
+
const limits = {
|
|
60
|
+
'max-lines': options?.fileMaxLines ?? SIZE_LIMITS_DEFAULTS.fileMaxLines,
|
|
61
|
+
'max-lines-per-function': options?.functionMaxLines ?? SIZE_LIMITS_DEFAULTS.functionMaxLines,
|
|
62
|
+
'sonarjs/cognitive-complexity': options?.cognitiveComplexity ?? SIZE_LIMITS_DEFAULTS.cognitiveComplexity,
|
|
63
|
+
};
|
|
64
|
+
const configs = [
|
|
65
|
+
{
|
|
66
|
+
name: 'kj/size-limits/file',
|
|
67
|
+
files,
|
|
68
|
+
ignores,
|
|
69
|
+
rules: { 'max-lines': ruleEntry('max-lines', severity, limits['max-lines']) },
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'kj/size-limits/function',
|
|
73
|
+
files,
|
|
74
|
+
ignores: [...ignores, ...(options?.functionIgnores ?? [])],
|
|
75
|
+
rules: {
|
|
76
|
+
'max-lines-per-function': ruleEntry('max-lines-per-function', severity, limits['max-lines-per-function']),
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
const complexity = limits['sonarjs/cognitive-complexity'];
|
|
81
|
+
if (complexity !== false) {
|
|
82
|
+
configs.push({
|
|
83
|
+
name: 'kj/size-limits/complexity',
|
|
84
|
+
files,
|
|
85
|
+
ignores,
|
|
86
|
+
...(options?.sonarjsPlugin ? { plugins: { sonarjs: options.sonarjsPlugin } } : {}),
|
|
87
|
+
rules: { 'sonarjs/cognitive-complexity': ruleEntry('sonarjs/cognitive-complexity', severity, complexity) },
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (process.env[SIZE_LIMITS_IGNORE_BASELINE_ENV] === '1')
|
|
91
|
+
return configs;
|
|
92
|
+
const baseline = {
|
|
93
|
+
...(options?.baselineFile ? readSizeLimitsBaseline(options.baselineFile) : {}),
|
|
94
|
+
...options?.baseline,
|
|
95
|
+
};
|
|
96
|
+
for (const file of Object.keys(baseline).sort()) {
|
|
97
|
+
const rules = {};
|
|
98
|
+
for (const rule of SIZE_LIMIT_RULES) {
|
|
99
|
+
const value = baseline[file]?.[rule];
|
|
100
|
+
const limit = limits[rule];
|
|
101
|
+
if (value === undefined || limit === false)
|
|
102
|
+
continue;
|
|
103
|
+
rules[rule] = ruleEntry(rule, severity, Math.max(value, limit));
|
|
104
|
+
}
|
|
105
|
+
if (Object.keys(rules).length > 0) {
|
|
106
|
+
configs.push({ name: `kj/size-limits/baseline:${file}`, files: [escapeGlobPath(file)], rules });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return configs;
|
|
110
|
+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AC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAClG,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { plugin };
|
|
|
4
4
|
export * from './configs/recommended.js';
|
|
5
5
|
export * from './configs/typed.js';
|
|
6
6
|
export * from './configs/component-extraction.js';
|
|
7
|
+
export * from './configs/size-limits.js';
|
|
7
8
|
export * from './selectors/object-literal-typing.js';
|
|
8
9
|
export * from './selectors/mock-body-satisfies.js';
|
|
9
10
|
export * from './selectors/restricted-syntax.js';
|
|
@@ -12,6 +13,5 @@ export type { NoMultiCompOptions } from './rules/no-multi-comp.js';
|
|
|
12
13
|
export type { NoPureTypeAliasOptions } from './rules/no-pure-type-alias.js';
|
|
13
14
|
export type { NoSingleExportBarrelOptions } from './rules/no-single-export-barrel.js';
|
|
14
15
|
export type { NoWeakTypeofSatisfiesOptions } from './rules/no-weak-typeof-satisfies.js';
|
|
15
|
-
export type { JsxLeadingPropOrderOptions } from './rules/jsx-leading-prop-order.js';
|
|
16
16
|
export type { NoBarrelOptions } from './rules/no-barrel.js';
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AAEzC,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,sBAAsB,CAAC;AAErC,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,YAAY,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,YAAY,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACtF,YAAY,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AACxF,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { plugin };
|
|
|
4
4
|
export * from './configs/recommended.js';
|
|
5
5
|
export * from './configs/typed.js';
|
|
6
6
|
export * from './configs/component-extraction.js';
|
|
7
|
+
export * from './configs/size-limits.js';
|
|
7
8
|
export * from './selectors/object-literal-typing.js';
|
|
8
9
|
export * from './selectors/mock-body-satisfies.js';
|
|
9
10
|
export * from './selectors/restricted-syntax.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AAEzC,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,sBAAsB,CAAC"}
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAqBrC,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAS3B,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { jsxLeadingPropOrder } from './rules/jsx-leading-prop-order.js';
|
|
2
1
|
import { noBarrel } from './rules/no-barrel.js';
|
|
3
2
|
import { noMultiComp } from './rules/no-multi-comp.js';
|
|
4
3
|
import { noPureTypeAlias } from './rules/no-pure-type-alias.js';
|
|
@@ -14,7 +13,6 @@ const rules = {
|
|
|
14
13
|
'no-pure-type-alias': noPureTypeAlias,
|
|
15
14
|
'no-single-export-barrel': noSingleExportBarrel,
|
|
16
15
|
'no-weak-typeof-satisfies': noWeakTypeofSatisfies,
|
|
17
|
-
'jsx-leading-prop-order': jsxLeadingPropOrder,
|
|
18
16
|
'no-barrel': noBarrel,
|
|
19
17
|
};
|
|
20
18
|
export const plugin = {
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,KAAK,GAAG;IACZ,eAAe,EAAE,WAAW;IAC5B,oBAAoB,EAAE,eAAe;IACrC,yBAAyB,EAAE,oBAAoB;IAC/C,0BAA0B,EAAE,qBAAqB;IACjD,WAAW,EAAE,QAAQ;CACtB,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAkB;IACnC,IAAI,EAAE;QACJ,IAAI,EAAE,6BAA6B;QACnC,OAAO,EAAE,OAAO;KACjB;IACD,kFAAkF;IAClF,+EAA+E;IAC/E,6EAA6E;IAC7E,KAAK,EAAE,KAA0C;CAClD,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kristijorgji/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Custom ESLint rules for TypeScript and React projects (kj namespace)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"dist",
|
|
22
|
+
"skills",
|
|
22
23
|
"README.md",
|
|
23
24
|
"LICENSE"
|
|
24
25
|
],
|
|
@@ -39,10 +40,10 @@
|
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@typescript-eslint/rule-tester": "^8",
|
|
41
42
|
"@types/estree": "^1",
|
|
42
|
-
"eslint": "^
|
|
43
|
+
"eslint": "^10",
|
|
43
44
|
"typescript": "^5",
|
|
44
45
|
"typescript-eslint": "^8",
|
|
45
|
-
"vitest": "^
|
|
46
|
+
"vitest": "^5"
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"build": "tsc -p tsconfig.json",
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: component-extraction
|
|
3
|
+
description: >
|
|
4
|
+
Split oversized React components and hooks flagged by the kj extraction rules.
|
|
5
|
+
Use when kj/no-multi-comp, max-lines-per-function, or max-lines warnings appear,
|
|
6
|
+
when splitting a screen, or when extracting logic into a hook.
|
|
7
|
+
paths:
|
|
8
|
+
- '**/*.tsx'
|
|
9
|
+
- '**/*.ts'
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Component Extraction
|
|
13
|
+
|
|
14
|
+
Workflow for acting on ESLint extraction warnings from
|
|
15
|
+
`@kristijorgji/eslint-plugin`'s `componentExtraction()` config.
|
|
16
|
+
|
|
17
|
+
## Detection thresholds
|
|
18
|
+
|
|
19
|
+
| Target | Rules | Defaults |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| `**/*.tsx` | `kj/no-multi-comp`, `max-lines-per-function`, `max-lines` | 70 lines/fn, 300 lines/file |
|
|
22
|
+
| `**/use*.ts`, `**/hooks/**/*.ts` | `max-lines-per-function` | 120 lines/fn |
|
|
23
|
+
|
|
24
|
+
Default ignores: `**/*.test.tsx`, `**/*.stories.tsx`, `**/*.test.ts`, `**/*.stories.ts`.
|
|
25
|
+
|
|
26
|
+
All rules are **warn-only** by default — they signal extraction candidates, not blockers.
|
|
27
|
+
|
|
28
|
+
## Override the defaults
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import { componentExtraction } from '@kristijorgji/eslint-plugin';
|
|
32
|
+
|
|
33
|
+
export default [
|
|
34
|
+
...componentExtraction({
|
|
35
|
+
severity: 'warn',
|
|
36
|
+
componentMaxLines: 70,
|
|
37
|
+
fileMaxLines: 300,
|
|
38
|
+
hookMaxLines: 120,
|
|
39
|
+
componentFiles: ['**/*.tsx'],
|
|
40
|
+
hookFiles: ['**/use*.ts', '**/hooks/**/*.ts'],
|
|
41
|
+
ignores: ['**/*.test.tsx', '**/*.stories.tsx'],
|
|
42
|
+
}),
|
|
43
|
+
];
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Workflow
|
|
47
|
+
|
|
48
|
+
### 1. Confirm the signal
|
|
49
|
+
|
|
50
|
+
Run the consuming project's lint script. Map warnings to the thresholds above.
|
|
51
|
+
If only one rule fires, address that rule's intent:
|
|
52
|
+
|
|
53
|
+
- `kj/no-multi-comp` → move each component into its own file
|
|
54
|
+
- `max-lines` / `max-lines-per-function` → extract subcomponents or a `use*` hook
|
|
55
|
+
|
|
56
|
+
### 2. Decide extraction boundaries
|
|
57
|
+
|
|
58
|
+
- **Presentational vs logic** — move state/effects into a `use*.ts` hook; keep JSX thin.
|
|
59
|
+
- **Reuse** — search the project's shared components and hooks before creating anything new.
|
|
60
|
+
- Do **not** extract one-off wrappers with no clarity gain.
|
|
61
|
+
|
|
62
|
+
### 3. Apply the consuming project's conventions
|
|
63
|
+
|
|
64
|
+
File layout, Storybook/test coverage policy, and verification commands come from
|
|
65
|
+
the consuming project's own component-guidelines, testing, and verification skills.
|
|
66
|
+
Do not invent a new folder structure when the project already has one.
|
|
67
|
+
|
|
68
|
+
## Anti-patterns
|
|
69
|
+
|
|
70
|
+
- Extracting without searching existing shared components/hooks first.
|
|
71
|
+
- Extracting a hook with logic without a matching unit test.
|
|
72
|
+
- Splitting purely to silence ESLint when the result is harder to follow.
|
|
73
|
+
- Raising thresholds instead of extracting when the code is genuinely oversized.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: size-limits
|
|
3
|
+
description: >
|
|
4
|
+
Split oversized TypeScript modules flagged by max-lines, max-lines-per-function,
|
|
5
|
+
or sonarjs/cognitive-complexity. Use when sizeLimits() reports errors, when a
|
|
6
|
+
.ts file grows past the file or function cap, or when extracting helpers from
|
|
7
|
+
a public entry module.
|
|
8
|
+
paths:
|
|
9
|
+
- '**/*.ts'
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Size limits
|
|
13
|
+
|
|
14
|
+
Workflow for acting on ESLint size-limit errors from
|
|
15
|
+
`@kristijorgji/eslint-plugin`'s `sizeLimits()` config.
|
|
16
|
+
|
|
17
|
+
## Detection thresholds
|
|
18
|
+
|
|
19
|
+
| Target | Rules | Defaults |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| `**/*.ts`, `**/*.mts`, `**/*.cts` | `max-lines`, `max-lines-per-function`, `sonarjs/cognitive-complexity` | 300 lines/file, 80 lines/fn, complexity 20 |
|
|
22
|
+
|
|
23
|
+
Default ignores: `**/*.test.*`, `**/*.spec.*`, `**/*.stories.*`, `**/*.d.ts`,
|
|
24
|
+
`**/test/**`, `**/tests/**`, `**/__tests__/**`, `**/__fixtures__/**`, `**/__mocks__/**`.
|
|
25
|
+
|
|
26
|
+
Hook files (`**/use*.ts`, `**/hooks/**/*.ts`) are often excluded from
|
|
27
|
+
`max-lines-per-function` because `componentExtraction()` already caps them at 120.
|
|
28
|
+
|
|
29
|
+
All rules are **error** by default. A frozen per-file exemption list may raise
|
|
30
|
+
the cap for existing files; values may only shrink.
|
|
31
|
+
|
|
32
|
+
## Workflow
|
|
33
|
+
|
|
34
|
+
### 1. Keep the public entry
|
|
35
|
+
|
|
36
|
+
Keep the original file as the public entry. Do not rename exported functions or
|
|
37
|
+
change their signatures. Callers and existing tests keep importing the same
|
|
38
|
+
module.
|
|
39
|
+
|
|
40
|
+
### 2. Move into sibling modules
|
|
41
|
+
|
|
42
|
+
Copy function bodies character for character into sibling files next to the
|
|
43
|
+
entry (or a feature folder when the split has several related files). Allowed
|
|
44
|
+
edits:
|
|
45
|
+
|
|
46
|
+
- adding `export`
|
|
47
|
+
- adding or adjusting `import` lines
|
|
48
|
+
- replacing one contiguous block of statements with a call to a new function
|
|
49
|
+
whose body is exactly that block (variables the block reads become
|
|
50
|
+
parameters; variables it assigns that are used afterwards become return
|
|
51
|
+
values)
|
|
52
|
+
|
|
53
|
+
Do not change log messages, conditions, operator choice (`??` vs `||`),
|
|
54
|
+
default values, `await` order, or the order of side effects.
|
|
55
|
+
|
|
56
|
+
### 3. Move module state with its functions
|
|
57
|
+
|
|
58
|
+
A module-level `let` or constant moves with the functions that read or write
|
|
59
|
+
it. Do not wrap or re-export a module that existing tests mock.
|
|
60
|
+
|
|
61
|
+
### 4. No barrels
|
|
62
|
+
|
|
63
|
+
Do not add `index.ts` re-export files. Callers import the entry file by its
|
|
64
|
+
full path.
|
|
65
|
+
|
|
66
|
+
### 5. Leave existing tests unchanged
|
|
67
|
+
|
|
68
|
+
Existing tests are the behavior oracle. Do not edit them except to update an
|
|
69
|
+
import path when a symbol actually moved (and the plan or lint error names
|
|
70
|
+
that path). Add colocated unit tests only for newly extracted pure helpers.
|
|
71
|
+
|
|
72
|
+
### 6. Fallback when a new file still exceeds a limit
|
|
73
|
+
|
|
74
|
+
Extract its largest contiguous block into a named function in the same file.
|
|
75
|
+
Repeat until the file passes. Do not raise thresholds and do not add the new
|
|
76
|
+
file to the exemption list.
|
|
77
|
+
|
|
78
|
+
## Anti-patterns
|
|
79
|
+
|
|
80
|
+
- Rewriting control flow while splitting (shared loop helpers, lookup tables
|
|
81
|
+
for status codes) unless the consuming project explicitly asked for that.
|
|
82
|
+
- Fixing odd-looking but working code (`a.trim() ?? fallback`) as part of the
|
|
83
|
+
split.
|
|
84
|
+
- Adding a file to the exemption list instead of extracting.
|
|
85
|
+
- Creating `index.ts` barrels to hide the new files.
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
-
export interface JsxLeadingPropOrderOptions {
|
|
3
|
-
order?: string[];
|
|
4
|
-
}
|
|
5
|
-
type Options = [JsxLeadingPropOrderOptions];
|
|
6
|
-
export declare const DEFAULT_ORDER: string[];
|
|
7
|
-
/**
|
|
8
|
-
* Enforce a configurable leading order for specific JSX attributes.
|
|
9
|
-
* Other props stay unordered relative to each other (stable sort by rank).
|
|
10
|
-
* Never moves attributes across JSXSpreadAttribute boundaries.
|
|
11
|
-
*/
|
|
12
|
-
export declare const jsxLeadingPropOrder: TSESLint.RuleModule<"outOfOrder", Options, unknown, TSESLint.RuleListener> & {
|
|
13
|
-
name: string;
|
|
14
|
-
};
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=jsx-leading-prop-order.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-leading-prop-order.d.ts","sourceRoot":"","sources":["../../src/rules/jsx-leading-prop-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,QAAQ,EAAY,MAAM,0BAA0B,CAAC;AAI9E,MAAM,WAAW,0BAA0B;IACzC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,KAAK,OAAO,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAG5C,eAAO,MAAM,aAAa,UAAwD,CAAC;AAgDnF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;CAsG9B,CAAC"}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
-
import { createRule } from '../utils/create-rule.js';
|
|
3
|
-
export const DEFAULT_ORDER = ['data-testid', 'testID', 'key', 'ref', 'id', 'name'];
|
|
4
|
-
function attrName(node) {
|
|
5
|
-
if (node.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
const name = node.name;
|
|
9
|
-
if (name.type === AST_NODE_TYPES.JSXIdentifier) {
|
|
10
|
-
return name.name;
|
|
11
|
-
}
|
|
12
|
-
if (name.type === AST_NODE_TYPES.JSXNamespacedName) {
|
|
13
|
-
return `${name.namespace.name}:${name.name.name}`;
|
|
14
|
-
}
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
function stableSortByRank(segment, getRank) {
|
|
18
|
-
return segment
|
|
19
|
-
.map((attr, index) => ({ attr, index, rank: getRank(attr) }))
|
|
20
|
-
.sort((a, b) => a.rank - b.rank || a.index - b.index)
|
|
21
|
-
.map(({ attr }) => attr);
|
|
22
|
-
}
|
|
23
|
-
/** Split JSX attributes into segments separated by spreads. */
|
|
24
|
-
function attributeSegments(attrs) {
|
|
25
|
-
const segments = [];
|
|
26
|
-
let current = [];
|
|
27
|
-
for (const attr of attrs) {
|
|
28
|
-
if (attr.type === AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
29
|
-
if (current.length > 0) {
|
|
30
|
-
segments.push(current);
|
|
31
|
-
current = [];
|
|
32
|
-
}
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
current.push(attr);
|
|
36
|
-
}
|
|
37
|
-
if (current.length > 0) {
|
|
38
|
-
segments.push(current);
|
|
39
|
-
}
|
|
40
|
-
return segments;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Enforce a configurable leading order for specific JSX attributes.
|
|
44
|
-
* Other props stay unordered relative to each other (stable sort by rank).
|
|
45
|
-
* Never moves attributes across JSXSpreadAttribute boundaries.
|
|
46
|
-
*/
|
|
47
|
-
export const jsxLeadingPropOrder = createRule({
|
|
48
|
-
name: 'jsx-leading-prop-order',
|
|
49
|
-
meta: {
|
|
50
|
-
type: 'layout',
|
|
51
|
-
docs: {
|
|
52
|
-
description: 'Require configured leading JSX attributes to appear in order; never reorder across spreads',
|
|
53
|
-
},
|
|
54
|
-
fixable: 'code',
|
|
55
|
-
schema: [
|
|
56
|
-
{
|
|
57
|
-
type: 'object',
|
|
58
|
-
properties: {
|
|
59
|
-
order: {
|
|
60
|
-
type: 'array',
|
|
61
|
-
items: { type: 'string' },
|
|
62
|
-
minItems: 1,
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
additionalProperties: false,
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
messages: {
|
|
69
|
-
outOfOrder: 'JSX attributes must follow leading prop order ({{order}}).',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
defaultOptions: [{ order: DEFAULT_ORDER }],
|
|
73
|
-
create(context, [options]) {
|
|
74
|
-
const order = options.order ?? DEFAULT_ORDER;
|
|
75
|
-
const rankByName = new Map(order.map((name, index) => [name, index]));
|
|
76
|
-
const sourceCode = context.sourceCode;
|
|
77
|
-
function getRank(attr) {
|
|
78
|
-
const name = attrName(attr);
|
|
79
|
-
if (name === null || !rankByName.has(name)) {
|
|
80
|
-
return Number.POSITIVE_INFINITY;
|
|
81
|
-
}
|
|
82
|
-
return rankByName.get(name);
|
|
83
|
-
}
|
|
84
|
-
function fixSegment(segment, sorted) {
|
|
85
|
-
return (fixer) => {
|
|
86
|
-
const separators = [];
|
|
87
|
-
for (let i = 0; i < segment.length - 1; i++) {
|
|
88
|
-
const left = segment[i];
|
|
89
|
-
const right = segment[i + 1];
|
|
90
|
-
if (!left || !right)
|
|
91
|
-
continue;
|
|
92
|
-
separators.push(sourceCode.text.slice(left.range[1], right.range[0]));
|
|
93
|
-
}
|
|
94
|
-
const firstSorted = sorted[0];
|
|
95
|
-
if (!firstSorted) {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
const parts = [sourceCode.getText(firstSorted)];
|
|
99
|
-
for (let i = 0; i < separators.length; i++) {
|
|
100
|
-
const next = sorted[i + 1];
|
|
101
|
-
if (!next)
|
|
102
|
-
continue;
|
|
103
|
-
parts.push(separators[i] ?? '', sourceCode.getText(next));
|
|
104
|
-
}
|
|
105
|
-
const first = segment[0];
|
|
106
|
-
const last = segment[segment.length - 1];
|
|
107
|
-
if (!first || !last) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
return fixer.replaceTextRange([first.range[0], last.range[1]], parts.join(''));
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
return {
|
|
114
|
-
JSXOpeningElement(node) {
|
|
115
|
-
const attrs = node.attributes;
|
|
116
|
-
if (attrs.length < 2) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
for (const segment of attributeSegments(attrs)) {
|
|
120
|
-
if (segment.length < 2) {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
const sorted = stableSortByRank(segment, getRank);
|
|
124
|
-
const firstMismatch = segment.findIndex((attr, i) => attr !== sorted[i]);
|
|
125
|
-
if (firstMismatch === -1) {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
const reportNode = segment[firstMismatch];
|
|
129
|
-
if (!reportNode) {
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
context.report({
|
|
133
|
-
node: reportNode,
|
|
134
|
-
messageId: 'outOfOrder',
|
|
135
|
-
data: { order: order.join(', ') },
|
|
136
|
-
fix: fixSegment(segment, sorted),
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
//# sourceMappingURL=jsx-leading-prop-order.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-leading-prop-order.js","sourceRoot":"","sources":["../../src/rules/jsx-leading-prop-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AASrD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAInF,SAAS,QAAQ,CAAC,IAAa;IAC7B,IAAI,IAAI,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