@kristijorgji/eslint-plugin 0.2.0 → 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 +50 -0
- 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/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 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/skills/size-limits/SKILL.md +85 -0
package/README.md
CHANGED
|
@@ -102,6 +102,56 @@ warnings, or when splitting components/hooks, read and follow:
|
|
|
102
102
|
- [.agents/skills/vendor/component-extraction/SKILL.md](../../.agents/skills/vendor/component-extraction/SKILL.md)
|
|
103
103
|
```
|
|
104
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
|
+
|
|
105
155
|
### `no-barrel`
|
|
106
156
|
|
|
107
157
|
`kj/no-barrel` is opt-in and requires two options, since it targets a specific
|
|
@@ -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":[],"m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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"}
|
|
@@ -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,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE7C,eAAO,MAAM,gBAAgB,kFAAmF,CAAC;AACjH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC9D,iFAAiF;AACjF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AAExF,eAAO,MAAM,+BAA+B,mCAAmC,CAAC;AAChF,eAAO,MAAM,yBAAyB,UAAsC,CAAC;AAC7E,eAAO,MAAM,2BAA2B,UAUvC,CAAC;AACF,eAAO,MAAM,oBAAoB;;;;CAAgF,CAAC;AAElH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yCAAyC;IACzC,mBAAmB,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACrC,2GAA2G;IAC3G,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,+GAA+G;IAC/G,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAQD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,kBAAkB,CAgB3E;AAQD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,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
|
+
}
|
|
111
|
+
//# sourceMappingURL=size-limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size-limits.js","sourceRoot":"","sources":["../../src/configs/size-limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAIzB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,wBAAwB,EAAE,8BAA8B,CAAU,CAAC;AAKjH,MAAM,CAAC,MAAM,+BAA+B,GAAG,gCAAgC,CAAC;AAChF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,CAAC,CA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AAC,sBAAsB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9E,GAAG,OAAO,EAAE,QAAQ;KACrB,CAAC;IACF,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QAChD,MAAM,KAAK,GAAuB,EAAE,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,gBAAgB,EAAE,CAAC;YACpC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YACrC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YAC3B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK;gBAAE,SAAS;YACrD,KAAK,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QAClE,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,2BAA2B,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,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';
|
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/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",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"eslint": "^10",
|
|
44
44
|
"typescript": "^5",
|
|
45
45
|
"typescript-eslint": "^8",
|
|
46
|
-
"vitest": "^
|
|
46
|
+
"vitest": "^5"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsc -p tsconfig.json",
|
|
@@ -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.
|