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
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-2025 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="invalid-name-notation">
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
<xsl:import href="/org/eolang/funcs/defect-context.xsl"/>
<xsl:import href="/org/eolang/funcs/special-name.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:variable name="pattern" select="'^[a-z]+(-[a-z]+)*$'"/>
<xsl:template match="/">
<defects>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The selector only filters via eo:special(@name), which knows about @, λ, and cactoos-prefixed names. Parser-injected names from [] >> (the test pack already has one literal example: auto-named-attr-at-4-6 in packs/single/duplicate-names/catches-conflict-with-auto-name.yaml) contain digits and a non-kebab segment, so this for-each will report them as defects. Either extend eo:special to recognise the auto-named-attr-at-* prefix or add a sibling predicate here that excludes that prefix before the regex check.

<xsl:for-each select="//o[@name and not(eo:special(@name)) and not(matches(@name, $pattern))]">
<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>Object name "</xsl:text>
<xsl:value-of select="@name"/>
<xsl:text>" doesn’t match the regular expression </xsl:text>
<xsl:value-of select="$pattern"/>
</defect>
</xsl:for-each>
</defects>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Invalid name notation

The object name must match the regular expression `[a-z]+(-[a-z]+)*`.
Basically, it should follow kebab-case style,
but using only Latin letters - no digits or other characters.

Incorrect:

```eo
# App.
[] > mainApp
foo > x1
bar > y_
```

Correct:

```eo
# App.
[] > main-app
foo > x
bar > y
```
4 changes: 2 additions & 2 deletions src/test/resources/org/eolang/lints/canonical.eo
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*
x.put 2
while
x.as-number.lt 6 > [i1] >>
[i] >>
x.as-number.lt 6 > [i] >>
[j] >>
seq > @
*
QQ.io.stdout
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/names/invalid-name-notation.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
input: |
# App.
[] > main-app
foo > x
bar > y
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/names/invalid-name-notation.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
input: |
# App.
[] > app
x > f
[] >>
foo > @
[] > baz ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This input uses [] >> and [] > baz ? but the asserts only check the total defect count. Add an input case whose XMIR contains a name like auto-named-attr-at-4-6 (the same shape the parser produces for >>) and assert it is not reported. Without that case the lint silently regresses on the auto-named path, which is what is taking down acceptsCanonicalCode.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/names/invalid-name-notation.xsl
asserts:
- /defects[count(defect[@severity='warning'])=3]
- /defects/defect[@line='2']
- /defects/defect[@line='3']
- /defects/defect[@line='4']
input: |
# App.
[] > mainApp
foo > x1
bar > y_
Loading