Skip to content

Commit 085c8ff

Browse files
authored
bug(#708): formation-without-comment lint (#729)
* bug(#708): formation-without-comment * bug(#708): typos, clean for yamllint * bug(#708): no errors * bug(#708): start-with
1 parent b910ce8 commit 085c8ff

File tree

8 files changed

+139
-0
lines changed

8 files changed

+139
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
4+
* SPDX-License-Identifier: MIT
5+
-->
6+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="formation-without-comment" version="2.0">
7+
<xsl:import href="/org/eolang/parser/_funcs.xsl"/>
8+
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
9+
<xsl:import href="/org/eolang/funcs/escape.xsl"/>
10+
<xsl:import href="/org/eolang/funcs/defect-context.xsl"/>
11+
<xsl:output encoding="UTF-8" method="xml"/>
12+
<xsl:template match="/">
13+
<xsl:variable name="min" select="32"/>
14+
<defects>
15+
<xsl:for-each select="//o[eo:abstract(.) and @name and not(starts-with(@name, 'a🌵')) and not(eo:test-attr(.)) and @line]">
16+
<xsl:variable name="line" select="eo:lineno(@line)"/>
17+
<xsl:if test="not(/object/comments/comment[@line = $line])">
18+
<xsl:element name="defect">
19+
<xsl:attribute name="line">
20+
<xsl:value-of select="$line"/>
21+
</xsl:attribute>
22+
<xsl:if test="$line = '0'">
23+
<xsl:attribute name="context">
24+
<xsl:value-of select="eo:defect-context(.)"/>
25+
</xsl:attribute>
26+
</xsl:if>
27+
<xsl:attribute name="severity">
28+
<xsl:text>warning</xsl:text>
29+
</xsl:attribute>
30+
<xsl:text>The formation </xsl:text>
31+
<xsl:value-of select="eo:escape(@name)"/>
32+
<xsl:text> does not have a comment</xsl:text>
33+
</xsl:element>
34+
</xsl:if>
35+
</xsl:for-each>
36+
</defects>
37+
</xsl:template>
38+
</xsl:stylesheet>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Formation Without Comments
2+
3+
Each named formation should have comment on top of it.
4+
5+
Incorrect:
6+
7+
```eo
8+
[] > main
9+
42 > @
10+
```
11+
12+
Correct:
13+
14+
```eo
15+
# This is main.
16+
[] > main
17+
42 > @
18+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
sheets:
5+
- /org/eolang/lints/comments/formation-without-comment.xsl
6+
asserts:
7+
- /defects[count(defect)=0]
8+
input: |
9+
# Top object.
10+
[args] > main
11+
start > @
12+
[]
13+
42 > i
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
sheets:
5+
- /org/eolang/lints/comments/formation-without-comment.xsl
6+
asserts:
7+
- /defects[count(defect)=0]
8+
input: |
9+
# Top object.
10+
[args] > main
11+
start > @
12+
[i] >>
13+
i.plus 2 > x
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
sheets:
5+
- /org/eolang/lints/comments/formation-without-comment.xsl
6+
asserts:
7+
- /defects[count(defect)=0]
8+
input: |
9+
# Top object.
10+
[args] > main
11+
# Nested object.
12+
[] > f
13+
42 > @
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
sheets:
5+
- /org/eolang/lints/comments/formation-without-comment.xsl
6+
asserts:
7+
- /defects[count(defect)=0]
8+
input: |
9+
# Top object.
10+
[] > f
11+
[] +> checks-data
12+
eq. > @
13+
42
14+
42
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
sheets:
5+
- /org/eolang/lints/comments/formation-without-comment.xsl
6+
asserts:
7+
- /defects[count(defect[@severity='warning'])=1]
8+
- /defects/defect[@line='1']
9+
input: |
10+
[args] > main
11+
42 > @
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
# yamllint disable rule:line-length
5+
sheets:
6+
- /org/eolang/lints/comments/formation-without-comment.xsl
7+
asserts:
8+
- /defects[count(defect[@severity='warning'])=1]
9+
- /defects/defect[@line='7']
10+
- /defects/defect[normalize-space()='The formation "s" does not have a comment']
11+
input: |
12+
# Top object.
13+
[args] > main
14+
# Nested object.
15+
[] > f
16+
# One more nested object.
17+
[] > a
18+
[] > s
19+
42 > @

0 commit comments

Comments
 (0)