-
Notifications
You must be signed in to change notification settings - Fork 26
feat(#566): check name match kebab-case #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4742bda
37a5d50
4621f49
df45486
6bba476
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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> | ||
| <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 | ||
| ``` |
| 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 ? | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This input uses |
||
| 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_ |
There was a problem hiding this comment.
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-6inpacks/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 extendeo:specialto recognise theauto-named-attr-at-*prefix or add a sibling predicate here that excludes that prefix before the regex check.