Skip to content

Metrics rules

Reports per-file size and complexity numbers and explains how to read them; the numbers are guidance for other agents, not defects.

  • Agent id: metrics
  • Rules: 9 (source: metrics.yaml)
  • Deterministic checks: file_metrics

MET-001: Read metrics as heuristics

  • Severity: info
  • Languages: all

Treat every metric from the metrics check as an estimate counted from text patterns, not from a full parser. Keywords inside strings, comments or generated code can inflate the counts, so open the file before quoting a number as a defect, and never raise the severity of a metrics finding above info.

MET-002: Lines of code

  • Severity: info
  • Languages: all

Read lines of code as non-blank, non-comment lines. Use it as a guide only, and treat a hand-written source file above roughly 500 lines as a candidate for splitting that the architecture and code quality agents should look at. Generated files, fixtures, migrations and data tables are large by nature and need no action.

MET-003: Cyclomatic complexity per file

  • Severity: info
  • Languages: all
  • References: CWE-1121

Read the file-level cyclomatic complexity as the number of decision points plus one. As guidance, below 10 per function is simple, 10 to 15 is worth a second look, and above 15 is where code_quality rule CQ-004 applies. Prefer the per-function numbers from the complexity findings; a file total divided by the function count is only a rough average.

MET-004: Maximum nesting depth

  • Severity: info
  • Languages: all
  • References: CWE-1124

Read maximum nesting depth as the deepest block level found in the file. Depth up to 3 is ordinary, and depth above 4 is where code_quality rule CQ-005 applies. In languages where classes and functions add a level (Python methods, Java classes), subtract those levels before judging the logic inside.

MET-005: Function count and average length

  • Severity: info
  • Languages: all

Read the function count together with lines of code. An average above about 40 lines per function suggests a few long functions worth checking with CQ-006; a file with many functions under 5 lines each may be a thin wrapper layer worth checking with ARC-013.

MET-006: Duplicated blocks

  • Severity: info
  • Languages: all
  • References: CWE-1041

Read a duplicated block count, when one is reported, as repeated runs of five or more identical lines. Repetition inside test files, data literals or license headers is usually harmless; repetition in business logic is where code_quality rule CQ-007 applies.

MET-008: Rank files for review

  • Severity: info
  • Languages: all

Use the metrics to choose which files to read first when the review cannot cover all of them. Rank by complexity per function, then nesting depth, then size, and favor files the current change touches over files it does not.

MET-009: Compare against the project, not an absolute

  • Severity: info
  • Languages: all

Judge a file against the other files of the same project and language before calling it an outlier. A number that is high everywhere in a project describes its style and belongs in the summary once, not as a finding on every file.

MET-010: Report metrics without a verdict

  • Severity: info
  • Languages: all

Write metrics findings as plain numbers with the file path, such as "412 lines, 9 functions, complexity 58, max nesting 5". Leave the judgment to the code quality and architecture rules, and do not count metrics findings toward the quality score.