Skip to content

Commit 4d6b816

Browse files
authored
Merge pull request #305 from h1alexbel/296
bug(#296): compare `/program/@name` with packaged object path
2 parents 573b608 + 8e7224c commit 4d6b816

File tree

3 files changed

+109
-22
lines changed

3 files changed

+109
-22
lines changed

src/main/resources/org/eolang/lints/names/object-does-not-match-filename.xsl

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,36 @@ SOFTWARE.
2828
<xsl:output encoding="UTF-8" method="xml"/>
2929
<xsl:variable name="package" select="/program/metas/meta[head='package'][1]"/>
3030
<xsl:variable name="program" select="/program/@name"/>
31-
<xsl:variable name="filename" as="xs:string">
32-
<xsl:choose>
33-
<xsl:when test="$package">
34-
<xsl:value-of select="substring-after($program, concat($package/tail/text(), '.'))"/>
35-
</xsl:when>
36-
<xsl:otherwise>
37-
<xsl:value-of select="$program"/>
38-
</xsl:otherwise>
39-
</xsl:choose>
40-
</xsl:variable>
4131
<xsl:variable name="tested" select="/program/metas/meta[head='tests']"/>
4232
<xsl:template match="/">
4333
<defects>
4434
<xsl:if test="not($tested)">
45-
<xsl:apply-templates select="/program/objects/o[@name != $filename]" mode="confused-name"/>
35+
<xsl:apply-templates select="/program/objects/o" mode="live"/>
4636
</xsl:if>
4737
</defects>
4838
</xsl:template>
49-
<xsl:template match="o" mode="confused-name">
50-
<defect>
51-
<xsl:attribute name="line">
52-
<xsl:value-of select="eo:lineno(@line)"/>
53-
</xsl:attribute>
54-
<xsl:attribute name="severity">warning</xsl:attribute>
55-
<xsl:text>Object </xsl:text>
56-
<xsl:value-of select="eo:escape(@name)"/>
57-
<xsl:text> does not match with filename </xsl:text>
58-
<xsl:value-of select="eo:escape($filename)"/>
59-
</defect>
39+
<xsl:template match="o" mode="live">
40+
<xsl:variable name="opath" as="xs:string">
41+
<xsl:choose>
42+
<xsl:when test="$package">
43+
<xsl:value-of select="concat($package/tail/text(), '.', @name)"/>
44+
</xsl:when>
45+
<xsl:otherwise>
46+
<xsl:value-of select="@name"/>
47+
</xsl:otherwise>
48+
</xsl:choose>
49+
</xsl:variable>
50+
<xsl:if test="$program != $opath">
51+
<defect>
52+
<xsl:attribute name="line">
53+
<xsl:value-of select="eo:lineno(@line)"/>
54+
</xsl:attribute>
55+
<xsl:attribute name="severity">warning</xsl:attribute>
56+
<xsl:text>Object </xsl:text>
57+
<xsl:value-of select="eo:escape($opath)"/>
58+
<xsl:text> does not match with filename </xsl:text>
59+
<xsl:value-of select="eo:escape($program)"/>
60+
</defect>
61+
</xsl:if>
6062
</xsl:template>
6163
</xsl:stylesheet>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2016-2025 Objectionary.com
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included
13+
# in all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
---
23+
sheets:
24+
- /org/eolang/lints/names/object-does-not-match-filename.xsl
25+
asserts:
26+
- /defects[count(defect[@severity='warning'])=1]
27+
- /defects/defect[@line='4']
28+
- /defects/defect[1][normalize-space()='Object "f.main" does not match with filename "foo.x.main"']
29+
document: |
30+
<program name="foo.x.main">
31+
<metas>
32+
<meta line="1">
33+
<head>package</head>
34+
<tail>f</tail>
35+
<part>f</part>
36+
</meta>
37+
</metas>
38+
<objects>
39+
<o line="4" name="main" pos="0"/>
40+
</objects>
41+
</program>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2016-2025 Objectionary.com
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included
13+
# in all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
---
23+
sheets:
24+
- /org/eolang/lints/names/object-does-not-match-filename.xsl
25+
asserts:
26+
- /defects[count(defect[@severity='warning'])=2]
27+
- /defects/defect[@line='4']
28+
- /defects/defect[@line='5']
29+
- /defects/defect[1][normalize-space()='Object "f.main" does not match with filename "foo.x.main"']
30+
- /defects/defect[2][normalize-space()='Object "f.foo" does not match with filename "foo.x.main"']
31+
document: |
32+
<program name="foo.x.main">
33+
<metas>
34+
<meta line="1">
35+
<head>package</head>
36+
<tail>f</tail>
37+
<part>f</part>
38+
</meta>
39+
</metas>
40+
<objects>
41+
<o line="4" name="main" pos="0"/>
42+
<o line="5" name="foo" pos="0"/>
43+
</objects>
44+
</program>

0 commit comments

Comments
 (0)