archivo del paquete→ .shtukbase/packages/code-refactoring/checks/long_params.ts
checks/long_params.ts
22 líneas, 879 B.
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- // RF-R04 (Fowler, Long Parameter List). A function with more than `maxParams` parameters. `self`, `this` and
- // `cls` do not count; a destructured object counts as one.
- import { type CheckDef, num, runCheck } from '../../code-lib/checks/lib/run.ts';
- import { functions } from '../../code-lib/checks/lib/units.ts';
- export const CHECK: CheckDef = {
- pkg: 'code-refactoring',
- rule: 'RF-R04',
- name: 'long-params',
- defaults: { maxParams: 5 },
- scan(srcs, set) {
- const max = num(set.maxParams, 5);
- const out = [];
- for (const s of srcs)
- for (const f of functions(s))
- if (f.params.length > max)
- 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` });
- return out;
- },
- };
- if (import.meta.main) runCheck(CHECK);