ShtukbaseStandard
файл пакета→ .shtukbase/packages/code-refactoring/checks/long_functions.ts

checks/long_functions.ts

24 строки, 1005 Б.

Файл как есть в пакете: код и комментарии в нём не переводятся.

  1. // RF-R01 (Fowler, Long Function). A function longer than `functionLines` lines of code (comments and blank
  2. // lines do not count). Rust and Python included; anonymous callbacks count inside the function around them.
  3. import { type CheckDef, num, runCheck } from '../../code-lib/checks/lib/run.ts';
  4. import { codeLines } from '../../code-lib/checks/lib/scan.ts';
  5. import { functions } from '../../code-lib/checks/lib/units.ts';
  6. export const CHECK: CheckDef = {
  7. pkg: 'code-refactoring',
  8. rule: 'RF-R01',
  9. name: 'long-functions',
  10. defaults: { functionLines: 60 },
  11. scan(srcs, set) {
  12. const max = num(set.functionLines, 60);
  13. const out = [];
  14. for (const s of srcs)
  15. for (const f of functions(s)) {
  16. const n = codeLines(s, f.line, f.endLine);
  17. 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` });
  18. }
  19. return out;
  20. },
  21. };
  22. if (import.meta.main) runCheck(CHECK);