Skip to content

Commit d59cc9e

Browse files
authored
Improve compound name linting and idiomatic checks (#809)
* #806: Improve compound name linting and idiomatic checks. * #806: Refactor compound-name.md for clarity and consistency * #806: Refactor idiomatic prefixes and suffixes in EO standard library. * #806: Refactor idiomatic prefixes and suffixes in compound-name.md.
1 parent b0fdc35 commit d59cc9e

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/main/resources/org/eolang/lints/names/compound-name.xsl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,24 @@
99
<xsl:import href="/org/eolang/funcs/special-name.xsl"/>
1010
<xsl:import href="/org/eolang/funcs/escape.xsl"/>
1111
<xsl:output encoding="UTF-8" method="xml"/>
12-
<!--Since developers might decide not to use kebab-case, its better to catch all such cases.-->
12+
<!--Since developers might decide not to use kebab-case, it's better to catch all such cases.-->
1313
<xsl:function name="eo:compound" as="xs:boolean">
1414
<xsl:param name="name"/>
1515
<xsl:sequence select="contains($name, '-') or contains($name, '_') or matches($name, '[A-Z]')"/>
1616
</xsl:function>
17+
<!--
18+
These prefixes/suffixes are idiomatic in EO standard library:
19+
- 'as-' for type conversions (as-bytes, as-i64, as-number, etc.)
20+
- 'is-' for boolean predicates (is-empty, is-nan, is-finite, etc.)
21+
- '-of' for extracting parts (slice-of, value-of, length-of, etc.)
22+
-->
23+
<xsl:function name="eo:idiomatic" as="xs:boolean">
24+
<xsl:param name="name"/>
25+
<xsl:sequence select="starts-with($name, 'as-') or starts-with($name, 'is-') or ends-with($name, '-of')"/>
26+
</xsl:function>
1727
<xsl:template match="/">
1828
<defects>
19-
<xsl:for-each select="//o[@base and @name and not(eo:special(@name)) and eo:compound(@name)]">
29+
<xsl:for-each select="//o[@base and @name and not(eo:special(@name)) and eo:compound(@name) and not(eo:idiomatic(@name))]">
2030
<defect>
2131
<xsl:variable name="line" select="eo:lineno(@line)"/>
2232
<xsl:attribute name="line">

src/main/resources/org/eolang/motives/names/compound-name.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ Correct:
2121
parse > records
2222
read file
2323
```
24+
25+
There are exceptions for idiomatic prefixes and suffixes.
26+
The `as-` prefix is for type conversions: `as-bytes`, `as-i64`, `as-number`.
27+
The `is-` prefix is for predicates: `is-empty`, `is-nan`, `is-finite`.
28+
The `-of` suffix is for extracting parts: `slice-of`, `value-of`, `length-of`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
sheets:
5+
- /org/eolang/lints/names/compound-name.xsl
6+
asserts:
7+
- /defects[count(defect[@severity='warning'])=0]
8+
input: |
9+
# No comments.
10+
[] > main
11+
x.as-bytes > as-bytes
12+
y.as-i64 > as-i64
13+
z.is-empty > is-empty
14+
w.is-nan > is-nan
15+
a.slice-of > slice-of
16+
b.value-of > value-of

0 commit comments

Comments
 (0)