Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔧 chore(rules): raise the source file size limit from 800 to 1200 lines (#21115)

Arvin Xuebb13e676da2
diff --git a/.agents/scripts/check/check.test.ts b/.agents/scripts/check/check.test.ts
index 778ada865a8..39e82714ab9 100644
--- a/.agents/scripts/check/check.test.ts
+++ b/.agents/scripts/check/check.test.ts
@@ -201,16 +201,16 @@ describe('countLines', () => {
describe('checkFileSizes', () => {
const current: Record<string, number> = {
- 'src/Big.ts': 801,
- 'src/Crossed.ts': 900,
- 'src/Grown.tsx': 1200,
- 'src/Shrunk.ts': 1000,
- 'src/Small.ts': 800,
+ 'src/Big.ts': 1201,
+ 'src/Crossed.ts': 1300,
+ 'src/Grown.tsx': 1600,
+ 'src/Shrunk.ts': 1400,
+ 'src/Small.ts': 1200,
'packages/locales/src/default/setting.ts': 5000,
- 'packages/locales/src/create.ts': 900,
+ 'packages/locales/src/create.ts': 1300,
'src/types.d.ts': 2000,
'packages/sdk/src/generated/types.gen.ts': 12000,
- 'packages/sdk/src/generated/core/client.ts': 900,
+ 'packages/sdk/src/generated/core/client.ts': 1300,
'README.md': 5000,
};
const base: Record<string, number | null> = {
@@ -220,9 +220,9 @@ describe('checkFileSizes', () => {
'src/types.d.ts': 1000,
'packages/sdk/src/generated/types.gen.ts': null,
'packages/sdk/src/generated/core/client.ts': null,
- 'src/Crossed.ts': 790,
- 'src/Grown.tsx': 1100,
- 'src/Shrunk.ts': 1100,
+ 'src/Crossed.ts': 1190,
+ 'src/Grown.tsx': 1500,
+ 'src/Shrunk.ts': 1500,
};
const run = (files: string[]) =>
checkFileSizes(
@@ -235,12 +235,12 @@ describe('checkFileSizes', () => {
const findings = await run(Object.keys(current));
expect(findings.errors).toEqual([
- expect.stringContaining('src/Big.ts: new file has 801 lines'),
- expect.stringContaining('src/Crossed.ts: grew from 790 to 900 lines'),
- expect.stringContaining('packages/locales/src/create.ts: new file has 900 lines'),
+ expect.stringContaining('src/Big.ts: new file has 1201 lines'),
+ expect.stringContaining('src/Crossed.ts: grew from 1190 to 1300 lines'),
+ expect.stringContaining('packages/locales/src/create.ts: new file has 1300 lines'),
]);
expect(findings.advisories).toEqual([
- expect.stringContaining('src/Grown.tsx: already over 800 lines and grew from 1100 to 1200'),
+ expect.stringContaining('src/Grown.tsx: already over 1200 lines and grew from 1500 to 1600'),
]);
});
@@ -248,7 +248,7 @@ describe('checkFileSizes', () => {
await expect(
checkFileSizes(
['src/Big.ts'],
- async () => 801,
+ async () => 1201,
async () => undefined,
),
).resolves.toEqual({ advisories: [], errors: [] });
diff --git a/.agents/scripts/check/fileSize.ts b/.agents/scripts/check/fileSize.ts
index 2c91772f0a1..ee0fba4068c 100644
--- a/.agents/scripts/check/fileSize.ts
+++ b/.agents/scripts/check/fileSize.ts
@@ -5,7 +5,7 @@ import { createBaseLocator } from './base';
import { run } from './exec';
import { mountDir, rootDir } from './paths';
-export const MAX_FILE_LINES = 800;
+export const MAX_FILE_LINES = 1200;
const SOURCE_PATTERN = /\.[cm]?[jt]sx?$/;
/**
@@ -63,7 +63,7 @@ const createBaseLinesReader = (): ReadBaseLines => {
};
/**
- * Enforce the 800-line limit on changed source and test files. Hundreds of
+ * Enforce the 1200-line limit on changed source and test files. Hundreds of
* legacy files already exceed it, so blocking every touch would stall
* unrelated fixes: only violations this change creates fail the run, and a
* legacy file that keeps growing is reported as an advisory.
diff --git a/.agents/skills/deep-review/references/dimensions/code-style.md b/.agents/skills/deep-review/references/dimensions/code-style.md
index 27bbba2da17..596ae9202ab 100644
--- a/.agents/skills/deep-review/references/dimensions/code-style.md
+++ b/.agents/skills/deep-review/references/dimensions/code-style.md
@@ -20,7 +20,7 @@ Fragment-level readability and convention adherence. Look at each changed hunk i
- Nesting ≥ 3 levels that early returns / lookup tables would flatten
- Redundant or derivable state: a variable/state field that mirrors a prop or is computable from existing state — derive it (selector, `useMemo`, plain expression) instead of storing a second copy that can drift
- Type looseness: `any`, runtime narrowing that the type signature hides, implicit contracts
-- File ballooning past \~800 lines without splitting
+- File ballooning past \~1200 lines without splitting
## Rule sources (deep mode: read before reviewing)
diff --git a/.agents/skills/react/SKILL.md b/.agents/skills/react/SKILL.md
index 040b2c3c39a..174ae9656e1 100644
--- a/.agents/skills/react/SKILL.md
+++ b/.agents/skills/react/SKILL.md
@@ -58,7 +58,7 @@ For Modal specifically, see the dedicated **modal** skill — use the imperative
Keep transient state in its smallest useful owner. Extract a custom hook when state transitions and handlers obscure rendering or form a reusable unit; do not extract solely because a component has a particular number of hooks.
-Split a component only to establish a real state, reuse, render-update, or mountable-capability boundary. Do not split solely to make files smaller; when a file reaches the 800-line limit in **`source-layout`**, find one of these boundaries rather than cutting at a line count. Decomposing a heavy domain feature into host-assembled atoms is owned by **`compose-atoms`**.
+Split a component only to establish a real state, reuse, render-update, or mountable-capability boundary. Do not split solely to make files smaller; when a file reaches the 1200-line limit in **`source-layout`**, find one of these boundaries rather than cutting at a line count. Decomposing a heavy domain feature into host-assembled atoms is owned by **`compose-atoms`**.
## Render Performance and Memoization
diff --git a/.agents/skills/source-layout/SKILL.md b/.agents/skills/source-layout/SKILL.md
index f12e022515c..8fb0b91399f 100644
--- a/.agents/skills/source-layout/SKILL.md
+++ b/.agents/skills/source-layout/SKILL.md
@@ -1,6 +1,6 @@
---
name: source-layout
-description: 'Use for where a file lives, how it is named, where its tests go, and how to split a source or test file over 800 lines (拆分大文件, 目录结构, 文件命名).'
+description: 'Use for where a file lives, how it is named, where its tests go, and how to split a source or test file over 1200 lines (拆分大文件, 目录结构, 文件命名).'
user-invocable: false
---
@@ -36,10 +36,10 @@ One rule for every app and package:
## 3. File size
-Source and test files stay at or below 800 lines. Generated code (`*.gen.ts`, `generated/` directories) and the `locales/default/` tables are exempt:
+Source and test files stay at or below 1200 lines. Generated code (`*.gen.ts`, `generated/` directories) and the `locales/default/` tables are exempt:
-- A new file over 800 lines, or an existing file that crosses 800 lines in this change, is split in the same change. `bun run check`, the pre-commit hook, and the PR's File Size Gate job fail on both.
-- A file already over 800 lines must not grow, including for a bug fix: the change may only keep or reduce its line count. Before adding code, extract the cohesive part the change touches. Put a new test in a scenario test file under the limit (§2), splitting the old test file first when the test belongs to one of its scenarios. Because hundreds of legacy files are over the limit, these checks report their growth as an advisory (a warning annotation in CI) instead of failing; it is still a required fix.
+- A new file over 1200 lines, or an existing file that crosses 1200 lines in this change, is split in the same change. `bun run check`, the pre-commit hook, and the PR's File Size Gate job fail on both.
+- A file already over 1200 lines must not grow, including for a bug fix: the change may only keep or reduce its line count. Before adding code, extract the cohesive part the change touches. Put a new test in a scenario test file under the limit (§2), splitting the old test file first when the test belongs to one of its scenarios. Because hundreds of legacy files are over the limit, these checks report their growth as an advisory (a warning annotation in CI) instead of failing; it is still a required fix.
The limit says when to split, not where. Split on a real boundary (state, reuse, render update, sub-domain, pipeline stage), as `react` requires; never cut a file at an arbitrary line count. When a heavy feature is mounted by several hosts, use `compose-atoms` instead.
diff --git a/.agents/skills/split-large-file/SKILL.md b/.agents/skills/split-large-file/SKILL.md
index bbe8de0ad6d..48addcd4f67 100644
--- a/.agents/skills/split-large-file/SKILL.md
+++ b/.agents/skills/split-large-file/SKILL.md
@@ -1,6 +1,6 @@
---
name: split-large-file
-description: 'Refactor a source file over 800 lines into a directory of cohesive modules without changing behavior, test-first. Use when asked to split, decompose, or shrink a large file (拆分大文件, 拆文件, 重构大文件); with no file given, pick one.'
+description: 'Refactor a source file over 1200 lines into a directory of cohesive modules without changing behavior, test-first. Use when asked to split, decompose, or shrink a large file (拆分大文件, 拆文件, 重构大文件); with no file given, pick one.'
---
# Split a Large File
@@ -16,7 +16,7 @@ Given a file, use it. Otherwise build a shortlist:
```bash
git ls-files -z -- 'src/*.ts' 'src/*.tsx' 'apps/*.ts' 'apps/*.tsx' 'packages/*.ts' 'packages/*.tsx' \
| rg --null-data -v '(^|/)(__tests__|__mocks__|fixtures|locales)/|\.(test|spec)\.|\.d\.ts$' \
- | xargs -0 wc -l | awk '$1 > 800 && $NF != "total"' | sort -rn | head -30
+ | xargs -0 wc -l | awk '$1 > 1200 && $NF != "total"' | sort -rn | head -30
```
The shortlist still contains data tables and generated code; filter it by reading. Prefer a file with:
@@ -64,7 +64,7 @@ Extract one boundary at a time and rerun the guard tests by explicit path after
- Child components to PascalCase siblings with named exports.
- A constant stays in the module that uses it; one shared by several extracted modules goes to the nearest common directory's `constants.ts`.
-Keep the public import path and exported names unchanged so callers do not change. Every resulting file must be at most 800 lines, and the entry should read as composition, not logic.
+Keep the public import path and exported names unchanged so callers do not change. Every resulting file must be at most 1200 lines, and the entry should read as composition, not logic.
## 6. Split and trim the tests
diff --git a/AGENTS.md b/AGENTS.md
index 58347ec0b76..f337e7546b8 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -105,7 +105,7 @@ When acceptance is required, put its published `https://app.lobehub.com/acceptan
### Code Style
-- Source and test files stay at or below 800 lines; a file already over the limit must not grow. Before adding, moving, or splitting files, read the `source-layout` skill for placement, naming, test location, and how a large file becomes a directory.
+- Source and test files stay at or below 1200 lines; a file already over the limit must not grow. Before adding, moving, or splitting files, read the `source-layout` skill for placement, naming, test location, and how a large file becomes a directory.
### Code Review