Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/main/resources/org/eolang/lints/design/too-deep-object.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
* SPDX-License-Identifier: MIT
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" version="2.0" id="too-deep-object">
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
<xsl:import href="/org/eolang/funcs/escape.xsl"/>
<xsl:import href="/org/eolang/funcs/defect-context.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="//o[count(ancestor::o[not(@base='Φ.tuple') and not(@base='Φ.bytes') and not(@base='Φ.number') and not(@base='Φ.string')]) &gt; 12 and not(o[count(ancestor::o[not(@base='Φ.tuple') and not(@base='Φ.bytes') and not(@base='Φ.number') and not(@base='Φ.string')]) &gt; 12])]">
<defect>
<xsl:variable name="line" select="eo:lineno(@line)"/>
<xsl:attribute name="line">
<xsl:value-of select="$line"/>
</xsl:attribute>
<xsl:if test="$line = '0'">
<xsl:attribute name="context">
<xsl:value-of select="eo:defect-context(.)"/>
</xsl:attribute>
</xsl:if>
<xsl:attribute name="severity">warning</xsl:attribute>
<xsl:text>The object </xsl:text>
<xsl:value-of select="eo:escape(@base)"/>
<xsl:text> is nested too deep: </xsl:text>
<xsl:value-of select="count(ancestor::o)"/>
<xsl:text> levels of nesting, while the maximum is 12</xsl:text>
</defect>
</xsl:for-each>
</defects>
</xsl:template>
</xsl:stylesheet>
29 changes: 29 additions & 0 deletions src/main/resources/org/eolang/motives/design/too-deep-object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Too deep object

Objects nested deeper than twelve levels are hard to read and to debug.
The nesting level of an object is the number of its ancestor objects.
If it exceeds twelve, a warning is raised.

Incorrect:

```eo
# Foo.
[] > foo
a > x
b
c
d
e
f
g
h
i
j
k
l
m
```

Here, `m` is nested thirteen levels deep, which is hard to follow.
It should be refactored by extracting some of the nested objects into
their own top-level objects.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/design/too-deep-object.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
input: |
# Foo.

[] > foo
a > x
b
c
d
e
f
g
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/design/too-deep-object.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='16']
input: |
# Foo.

[] > foo
a > x
b
c
d
e
f
g
h
i
j
k
l
m
Loading