@kristijorgji/eslint-plugin 0.1.1 → 0.2.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 +32 -7
- 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/index.d.ts +0 -1
- package/dist/index.d.ts.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 +12 -11
- package/skills/component-extraction/SKILL.md +73 -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
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Custom ESLint rules for TypeScript and React projects, namespaced under `kj`.
|
|
4
4
|
|
|
5
|
+
Published from the [js-devkit](https://github.com/kristijorgji/js-devkit) monorepo via npm Trusted Publishing (OIDC).
|
|
6
|
+
|
|
5
7
|
Ships flat-config ready rule implementations, ready-made config factories, and a
|
|
6
8
|
small "selector" toolkit for composing your own `no-restricted-syntax` rules.
|
|
7
9
|
|
|
@@ -33,10 +35,13 @@ export default [
|
|
|
33
35
|
|
|
34
36
|
- `kj/no-pure-type-alias`
|
|
35
37
|
- `kj/no-single-export-barrel`
|
|
36
|
-
- `kj/jsx-leading-prop-order`
|
|
37
38
|
|
|
38
39
|
Pass `{ severity: 'warn' }` to downgrade all of them to warnings.
|
|
39
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
|
+
|
|
40
45
|
`kj/no-weak-typeof-satisfies` is **not** in `recommended()` — it needs type information. Use `typed()` for that.
|
|
41
46
|
|
|
42
47
|
### Type-aware rules
|
|
@@ -73,6 +78,30 @@ This enables `kj/no-multi-comp` for `**/*.tsx` files, plus `max-lines-per-functi
|
|
|
73
78
|
and `max-lines` for components, and `max-lines-per-function` for hook files
|
|
74
79
|
(`**/use*.ts`, `**/hooks/**/*.ts`).
|
|
75
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
|
+
|
|
76
105
|
### `no-barrel`
|
|
77
106
|
|
|
78
107
|
`kj/no-barrel` is opt-in and requires two options, since it targets a specific
|
|
@@ -133,7 +162,6 @@ use `restrictedSyntax()` directly if you want just the entry array.
|
|
|
133
162
|
| `kj/no-pure-type-alias` | Discourage pure re-alias type declarations (`type A = B;`). | No |
|
|
134
163
|
| `kj/no-single-export-barrel` | Disallow `index.ts` barrels that only re-export a single symbol. | No |
|
|
135
164
|
| `kj/no-weak-typeof-satisfies` | Disallow `typeof expr` in `satisfies` when `expr` is `any`/`unknown` (enable via `typed()`). | No |
|
|
136
|
-
| `kj/jsx-leading-prop-order` | Require configured leading JSX attributes to appear in order. | Yes |
|
|
137
165
|
| `kj/no-barrel` | Disallow importing/exporting a configured package's barrel entry point. | No |
|
|
138
166
|
|
|
139
167
|
### Options
|
|
@@ -147,9 +175,6 @@ use `restrictedSyntax()` directly if you want just the entry array.
|
|
|
147
175
|
- **`kj/no-weak-typeof-satisfies`**: `{ allowUnknown?: boolean (default false) }`.
|
|
148
176
|
When `true`, only `any` is flagged (not `unknown`). Requires type information —
|
|
149
177
|
use with `typed()` or a type-aware parser configuration.
|
|
150
|
-
- **`kj/jsx-leading-prop-order`**: `{ order?: string[] }`, defaults to
|
|
151
|
-
`['data-testid', 'testID', 'key', 'ref', 'id', 'name']`. Never reorders attributes
|
|
152
|
-
across a `{...spread}`.
|
|
153
178
|
- **`kj/no-barrel`**: `{ packageName: string, exampleSubpath: string }` (both
|
|
154
179
|
**required**).
|
|
155
180
|
|
|
@@ -163,7 +188,7 @@ If you previously vendored these rules locally, update rule IDs as follows:
|
|
|
163
188
|
| `type-alias/no-pure-alias` | `kj/no-pure-type-alias` |
|
|
164
189
|
| `no-single-export-barrel/no-single-export-barrel` | `kj/no-single-export-barrel` |
|
|
165
190
|
| `repo-typing/no-weak-typeof-satisfies` | `kj/no-weak-typeof-satisfies` |
|
|
166
|
-
| `jsx-leading-prop-order/jsx-leading-prop-order` | `
|
|
191
|
+
| `jsx-leading-prop-order/jsx-leading-prop-order` | `perfectionist/sort-jsx-props` (via `@kristijorgji/eslint-config-react-typescript`) |
|
|
167
192
|
| `<pkg>/no-barrel` (e.g. `utils/no-barrel`) | `kj/no-barrel` (pass `packageName`/`exampleSubpath` in options) |
|
|
168
193
|
|
|
169
194
|
## Overriding caveat
|
|
@@ -180,7 +205,7 @@ export default [
|
|
|
180
205
|
files: ['**/*.tsx'],
|
|
181
206
|
rules: {
|
|
182
207
|
// This wins over recommended()'s severity for the same rule/files.
|
|
183
|
-
'kj/
|
|
208
|
+
'kj/no-pure-type-alias': 'warn',
|
|
184
209
|
},
|
|
185
210
|
},
|
|
186
211
|
];
|
|
@@ -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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,5 @@ export type { NoMultiCompOptions } from './rules/no-multi-comp.js';
|
|
|
12
12
|
export type { NoPureTypeAliasOptions } from './rules/no-pure-type-alias.js';
|
|
13
13
|
export type { NoSingleExportBarrelOptions } from './rules/no-single-export-barrel.js';
|
|
14
14
|
export type { NoWeakTypeofSatisfiesOptions } from './rules/no-weak-typeof-satisfies.js';
|
|
15
|
-
export type { JsxLeadingPropOrderOptions } from './rules/jsx-leading-prop-order.js';
|
|
16
15
|
export type { NoBarrelOptions } from './rules/no-barrel.js';
|
|
17
16
|
//# 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;AAElD,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,
|
|
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;AAElD,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/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.2.0",
|
|
4
4
|
"description": "Custom ESLint rules for TypeScript and React projects (kj namespace)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public",
|
|
13
|
-
"provenance":
|
|
13
|
+
"provenance": true
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"dist",
|
|
22
|
+
"skills",
|
|
22
23
|
"README.md",
|
|
23
24
|
"LICENSE"
|
|
24
25
|
],
|
|
@@ -29,12 +30,6 @@
|
|
|
29
30
|
}
|
|
30
31
|
},
|
|
31
32
|
"types": "./dist/index.d.ts",
|
|
32
|
-
"scripts": {
|
|
33
|
-
"build": "tsc -p tsconfig.json",
|
|
34
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
35
|
-
"test": "vitest run",
|
|
36
|
-
"test:watch": "vitest"
|
|
37
|
-
},
|
|
38
33
|
"peerDependencies": {
|
|
39
34
|
"eslint": "^9 || ^10",
|
|
40
35
|
"typescript": "^5 || ^6"
|
|
@@ -45,9 +40,15 @@
|
|
|
45
40
|
"devDependencies": {
|
|
46
41
|
"@typescript-eslint/rule-tester": "^8",
|
|
47
42
|
"@types/estree": "^1",
|
|
48
|
-
"eslint": "^
|
|
43
|
+
"eslint": "^10",
|
|
49
44
|
"typescript": "^5",
|
|
50
45
|
"typescript-eslint": "^8",
|
|
51
|
-
"vitest": "^
|
|
46
|
+
"vitest": "^4"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -p tsconfig.json",
|
|
50
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"test:watch": "vitest"
|
|
52
53
|
}
|
|
53
|
-
}
|
|
54
|
+
}
|
|
@@ -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.
|
|
@@ -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,CAAC,IAAI,KAAK,cAAc,CAAC,YAAY,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACvB,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,aAAa,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,iBAAiB,EAAE,CAAC;QACnD,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACpD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,gBAA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