Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
43 changes: 23 additions & 20 deletions src/main/resources/org/eolang/lints/errors/empty-object.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,30 @@ SOFTWARE.
<xsl:import href="/org/eolang/funcs/escape.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<xsl:variable name="void" select="//o[@base='∅']/@name"/>
<defects>
<xsl:for-each select="/program/objects//o[not(o)]">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>warning</xsl:text>
</xsl:attribute>
<xsl:text>The </xsl:text>
<xsl:choose>
<xsl:when test="@name">
<xsl:text>object </xsl:text>
<xsl:value-of select="eo:escape(@name)"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>anonymous object</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text> is empty. It doesn't have any attributes, neither void nor attached</xsl:text>
</xsl:element>
<xsl:for-each select="/program/objects//o[not(@base) and not(o) and not(@atom)]">
<xsl:if test="not($void = @base)">
Copy link
Member

Choose a reason for hiding this comment

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

@h1alexbel I don't really understand what is this comparison for? You've already checked that object does not have @base='∅' in the line above

Copy link
Member Author

@h1alexbel h1alexbel Jan 14, 2025

Choose a reason for hiding this comment

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

@maxonfjvipon here, I check that $void, which is a set of atom names don't contain @base attribute of current object in the iteration.

Consider following XMIR:

<objects>
  <o line="2" name="main" pos="0">
    <o base="" line="2" name="x" pos="1"/>
    <o base="" line="2" name="y" pos="1"/>
    <o base=".print" line="3" name="@" pos="2">
      <o base="stdout" line="4" pos="4">
        <o base="string" line="4" pos="11">48-65-6C-6C-6F-21</o>
        <o base="x" line="4" pos="20"/>
      </o>
    </o>
  </o>
</objects>

In this XMIR, x object referenced to the void attribute x, declared at line 2. This check ensures that atom names ('x', 'y') contain x. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

@h1alexbel the original idea of such check was not to have abstract objects that does not have any inner objects, for example:

[] > app
  [] > a1 # empty and useless - should be caught
  if. > @
    true
    [] # kind of useles, but not empty - should not be caught
      2 > @
    1
  [x] > a2 # not empty - should not be caught

So the idea is simple - catch abstract object (which does not have @base attribute) that does not have inner <o> elements

Copy link
Member

Choose a reason for hiding this comment

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

@h1alexbel this condition is not necessary anymore, this condition in for-each /program/objects//o[not(@base) and not(o) and not(@atom)] is enough to find empty objects, also variable $void may be deleted

<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="eo:lineno(@line)"/>
</xsl:attribute>
<xsl:attribute name="severity">
<xsl:text>warning</xsl:text>
</xsl:attribute>
<xsl:text>The </xsl:text>
<xsl:choose>
<xsl:when test="@name">
<xsl:text>object </xsl:text>
<xsl:value-of select="eo:escape(@name)"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>anonymous object</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text> is empty. It doesn't have any attributes, neither void nor attached</xsl:text>
</xsl:element>
</xsl:if>
</xsl:for-each>
</defects>
</xsl:template>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
sheets:
- /org/eolang/lints/errors/empty-object.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
document: |
<program>
<objects>
<o line="2" name="main" pos="0">
<o base="∅" line="2" name="x" pos="1"/>
<o base="∅" line="2" name="y" pos="1"/>
<o base=".print" line="3" name="@" pos="2">
<o base="stdout" line="4" pos="4">
<o base="string" line="4" pos="11">48-65-6C-6C-6F-21</o>
<o base="x" line="4" pos="20"/>
</o>
</o>
</o>
</objects>
</program>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
sheets:
- /org/eolang/lints/errors/empty-object.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
document: |
<program>
<objects>
<o line="2" name="main" pos="0">
<o base="∅" line="2" name="x" pos="1"/>
<o base=".print" line="3" name="@" pos="2">
<o base="stdout" line="4" pos="4">
<o base="string" line="4" pos="11">48-65-6C-6C-6F-21</o>
<o base="x" line="4" pos="20"/>
</o>
</o>
</o>
</objects>
</program>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
sheets:
- /org/eolang/lints/errors/empty-object.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
document: |
<program>
<objects>
<o line="2" name="main" pos="0">
<o base="∅" line="2" name="x" pos="1"/>
</o>
</objects>
</program>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
sheets:
- /org/eolang/lints/errors/empty-object.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='4']
document: |
<program>
<objects>
<o line="2" name="main" pos="0">
<o base="∅" line="2" name="x" pos="1"/>
<o base=".print" line="3" name="@" pos="2">
<o base="stdout" line="4" pos="4">
<o base="string" line="4" pos="11">48-65-6C-6C-6F-21</o>
<o name="y" line="4" pos="20"/>
</o>
</o>
</o>
</objects>
</program>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
sheets:
- /org/eolang/lints/errors/empty-object.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='3']
input: |
# Snippet with some empty objects.
[] > app
[] > a1
if. > @
true
[]
2 > @
1
[x] > a2
Loading