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

checks/long_params.ts

22 строки, 879 Б.

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

  1. // RF-R04 (Fowler, Long Parameter List). A function with more than `maxParams` parameters. `self`, `this` and
  2. // `cls` do not count; a destructured object counts as one.
  3. import { type CheckDef, num, runCheck } from '../../code-lib/checks/lib/run.ts';
  4. import { functions } from '../../code-lib/checks/lib/units.ts';
  5. export const CHECK: CheckDef = {
  6. pkg: 'code-refactoring',
  7. rule: 'RF-R04',
  8. name: 'long-params',
  9. defaults: { maxParams: 5 },
  10. scan(srcs, set) {
  11. const max = num(set.maxParams, 5);
  12. const out = [];
  13. for (const s of srcs)
  14. for (const f of functions(s))
  15. if (f.params.length > max)
  16. out.push({ rel: s.rel, line: f.line, msg: `the function ${f.name} has ${f.params.length} parameters (threshold ${max}): gather related ones into an object or split the function` });
  17. return out;
  18. },
  19. };
  20. if (import.meta.main) runCheck(CHECK);