包文件→ .shtukbase/packages/code-refactoring/checks/long_functions.ts
checks/long_functions.ts
24 行, 1005 B.
文件按包中的原样显示:代码及其注释不做翻译。
- // RF-R01 (Fowler, Long Function). A function longer than `functionLines` lines of code (comments and blank
- // lines do not count). Rust and Python included; anonymous callbacks count inside the function around them.
- import { type CheckDef, num, runCheck } from '../../code-lib/checks/lib/run.ts';
- import { codeLines } from '../../code-lib/checks/lib/scan.ts';
- import { functions } from '../../code-lib/checks/lib/units.ts';
- export const CHECK: CheckDef = {
- pkg: 'code-refactoring',
- rule: 'RF-R01',
- name: 'long-functions',
- defaults: { functionLines: 60 },
- scan(srcs, set) {
- const max = num(set.functionLines, 60);
- const out = [];
- for (const s of srcs)
- for (const f of functions(s)) {
- const n = codeLines(s, f.line, f.endLine);
- if (n > max) out.push({ rel: s.rel, line: f.line, msg: `the function ${f.name} is ${n} lines of code (threshold ${max}): extract parts into named functions` });
- }
- return out;
- },
- };
- if (import.meta.main) runCheck(CHECK);