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
33 changes: 33 additions & 0 deletions src/main/resources/org/eolang/lints/tests/test-with-comment.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* SPDX-FileCopyrightText: Copyright (c) 2016-2026 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="test-with-comment">
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
<xsl:import href="/org/eolang/funcs/escape.xsl"/>
<xsl:import href="/org/eolang/funcs/test-name.xsl"/>
<xsl:import href="/org/eolang/funcs/defect-context.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<defects>
<xsl:for-each select="/object/o[eo:test-name(@name) and /object/comments/comment]">
<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>The test object </xsl:text>
<xsl:value-of select="eo:escape(@name)"/>
<xsl:text> has a comment, which duplicates its name. Make the name self-explanatory and remove the comment</xsl:text>
</defect>
</xsl:for-each>
</defects>
</xsl:template>
</xsl:stylesheet>
24 changes: 24 additions & 0 deletions src/main/resources/org/eolang/motives/tests/test-with-comment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Test with comment

A test object must not have a comment before it. A comment usually just
duplicates the test name: if the test is named `checks-the-app`, a comment
like "This test checks the app" adds nothing. Instead of documenting a
test, make its name short and self-explanatory.

Incorrect:

```eo
# This test checks the app.

[] +> checks-the-app
42 > @
```

Correct:

```eo
[] +> checks-the-app
42 > @
```

The name says it all; the comment is redundant.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/tests/test-with-comment.xsl
asserts:
- /defects[count(defect[@severity='warning'])=0]
input: |
[] > foo

[] +> checks-the-app
42 > @
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: Copyright (c) 2016-2026 Objectionary.com
# SPDX-License-Identifier: MIT
---
sheets:
- /org/eolang/lints/tests/test-with-comment.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
input: |
# This test checks the app.

[] +> checks-the-app
42 > @
Loading