Skip to content

feat(#467): add cyclomatic-complexity lint - #1490

Open
yegor256 wants to merge 2 commits into
masterfrom
claude/eager-planck-ppdmru
Open

yegor256 wants to merge 2 commits into
masterfrom
claude/eager-planck-ppdmru

Conversation

@yegor256

Copy link
Copy Markdown
Member

fix #467

What

Adds a new design lint, cyclomatic-complexity:

  • src/main/resources/org/eolang/lints/design/cyclomatic-complexity.xsl
  • src/main/resources/org/eolang/motives/design/cyclomatic-complexity.md
  • src/test/resources/org/eolang/lints/packs/single/cyclomatic-complexity/*.yaml

It also adds "cyclomatic" to the spell-checker's ignore list in
src/test/java/matchers/GrammarMatcher.java, since the word is flagged
as a misspelling by the English dictionary the tests use.

Why

#467 asks for a cyclomatic-complexity-style lint. The thread on the issue
worked through why a full CFG/McCabe metric is not decidable in EO
(if/and/or are ordinary method dispatches, so telling a boolean
dispatch apart from a same-named method of an unrelated object needs
type inference we don't have), and landed on a heuristic: count a
standalone while and any if/and/or dispatch as a decision point,
the way broad-scope.xsl and sparse-decoration.xsl already accept
heuristic false positives for other design smells. Because of that, the
defect is marked experimental, consistent with how this codebase
already flags other heuristic-based design lints
(excessive-visibility, unoptimizable-recursion).

How it works

For every formation (o[eo:abstract(.) and @name and o[@name='φ']],
skipping auto-named cactus formations the way unoptimizable-recursion
does), the lint counts decision points in its own body — a dispatch
whose @base's last .-separated segment is if, and, or or, or a
standalone Φ.while — excluding decision points that belong to a nested
formation (which are counted against that nested formation instead, the
same way a Java method's cyclomatic complexity excludes the branches of
methods it calls). The complexity is 1 + decisions; when it exceeds
10, a warning is raised.

Tests

  • catches-too-complex-formation.yaml — 11 decision points (complexity
    12) trigger the defect
  • allows-simple-formation.yaml — 2 decision points (complexity 3) do
    not
  • allows-outer-formation-when-only-nested-is-complex.yaml — a nested
    formation's 11 decisions are attributed to it, not to the enclosing
    formation, which stays under the threshold

mvn test (full suite) and mvn clean install -Pqulice both pass
locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UYLcdVGK73NpHUbiyaTx3r


Generated by Claude Code

Adds a new design lint that counts EO's only expressible decision
points - a standalone "while" and any "if"/"and"/"or" dispatch - per
formation, and warns when the resulting cyclomatic complexity exceeds
ten. Since EO gives no way to tell a boolean dispatch from a same-named
method of an unrelated object without type inference, the defect is
marked experimental, the same way other heuristic design lints
(broad-scope, sparse-decoration, unoptimizable-recursion) are.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UYLcdVGK73NpHUbiyaTx3r
vale's Vale.Spelling rule doesn't know "cyclomatic" or "boolean", and
the motive's prose tripped Microsoft.Adverbs, Microsoft.SentenceLength,
Google.Semicolons and Microsoft.Wordiness. Add the two words to the
custom vocabulary and rewrite the paragraph into shorter sentences.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UYLcdVGK73NpHUbiyaTx3r
@github-actions github-actions Bot added the core Changes are made to core parts of the code base label Sep 19, 2026
@yegor256
yegor256 marked this pull request as ready for review September 19, 2026 06:39
Copilot AI lite review requested due to automatic review settings September 19, 2026 06:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes are made to core parts of the code base

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cyclomatic Complexity Unchecked in EO Programs

3 participants