Skip to content

feat(#155): add too-deep-object lint - #1247

Open
VasilevNStas wants to merge 1 commit into
objectionary:masterfrom
VasilevNStas:fix/issue-155-too-deep-object
Open

feat(#155): add too-deep-object lint#1247
VasilevNStas wants to merge 1 commit into
objectionary:masterfrom
VasilevNStas:fix/issue-155-too-deep-object

Conversation

@VasilevNStas

Copy link
Copy Markdown
Contributor

fix #155

What

A new design/too-deep-object lint that warns when an object is nested
deeper than twelve levels.

How it works

The lint counts the ancestors of every object in XMIR:

depth = count(ancestor::o)

If the depth exceeds 12, the object is reported as a warning.

Synthetic nodes introduced by the parser are excluded from the count:
Φ.tuple (tuples written as *), Φ.bytes, Φ.number and Φ.string
(literals). Without this, even the canonical example
(src/test/resources/org/eolang/lints/canonical.eo, which is only about
12 source levels deep) would be flagged, because the parser wraps every
literal and tuple in extra levels of nesting.

Only the deepest offending objects are reported (not every descendant),
so a single deep chain yields a single defect.

Why

Deeply nested objects are hard to read and debug. The issue proposes a
threshold of 12, which this lint follows.

Tests

  • catches-too-deep-object — a 14-level chain is flagged
  • allows-normal-nesting — a 7-level chain (from the issue) is clean

Both mvn test (592 tests) and mvn clean install -Pqulice pass.

@VasilevNStas

Copy link
Copy Markdown
Contributor Author

@volodya-lombrozo plz review this pull request

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new lint too-deep-object to catch very nested objects

1 participant