forked from objectionary/lints
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request objectionary#170 from h1alexbel/16
feat(objectionary#16): comment-is-too-wide lint
- Loading branch information
Showing
6 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/main/resources/org/eolang/lints/comments/comment-is-too-wide.xsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
The MIT License (MIT) | ||
Copyright (c) 2016-2024 Objectionary.com | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
--> | ||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="comment-is-too-wide" version="2.0"> | ||
<xsl:output encoding="UTF-8" method="xml"/> | ||
<xsl:template match="/"> | ||
<xsl:variable name="max" select="80"/> | ||
<defects> | ||
<xsl:for-each select="/program/comments/comment"> | ||
<xsl:variable name="line" select="if (@line) then @line else '0'"/> | ||
<xsl:variable name="lines" select="tokenize(replace(., '\\n', ' '), ' ')"/> | ||
<xsl:choose> | ||
<xsl:when test="count($lines) > 1"> | ||
<xsl:for-each select="$lines[string-length(.) > $max]"> | ||
<xsl:element name="defect"> | ||
<xsl:attribute name="line"> | ||
<xsl:value-of select="$line"/> | ||
</xsl:attribute> | ||
<xsl:attribute name="severity"> | ||
<xsl:text>warning</xsl:text> | ||
</xsl:attribute> | ||
<xsl:text>The comment line width is "</xsl:text> | ||
<xsl:value-of select="string-length(.)"/> | ||
<xsl:text>", while "</xsl:text> | ||
<xsl:value-of select="$max"/> | ||
<xsl:text>" is max allowed</xsl:text> | ||
</xsl:element> | ||
</xsl:for-each> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:if test="string-length(.) > $max"> | ||
<xsl:element name="defect"> | ||
<xsl:attribute name="line"> | ||
<xsl:value-of select="$line"/> | ||
</xsl:attribute> | ||
<xsl:attribute name="severity"> | ||
<xsl:text>warning</xsl:text> | ||
</xsl:attribute> | ||
<xsl:text>The comment width is "</xsl:text> | ||
<xsl:value-of select="string-length(.)"/> | ||
<xsl:text>", while "</xsl:text> | ||
<xsl:value-of select="$max"/> | ||
<xsl:text>" is max allowed</xsl:text> | ||
</xsl:element> | ||
</xsl:if> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:for-each> | ||
</defects> | ||
</xsl:template> | ||
</xsl:stylesheet> |
17 changes: 17 additions & 0 deletions
17
src/main/resources/org/eolang/motives/comments/comment-is-too-wide.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Comment is too wide | ||
|
||
Each comment should be not wider than 80 characters. | ||
|
||
Incorrect: | ||
|
||
```eo | ||
# This is a very long comment that contains more than eighty characters and should be flagged by the lint as too wide. | ||
[] > foo | ||
``` | ||
|
||
Correct: | ||
|
||
```eo | ||
# This is a good comment. | ||
[] > foo | ||
``` |
30 changes: 30 additions & 0 deletions
30
src/test/resources/org/eolang/lints/packs/comment-is-too-wide/allows-good-comment-width.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2016-2024 Objectionary.com | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
--- | ||
sheets: | ||
- /org/eolang/lints/comments/comment-is-too-wide.xsl | ||
asserts: | ||
- /defects[count(defect[@severity='warning'])=0] | ||
input: | | ||
# This comment is good. | ||
[] > foo | ||
42 > @ |
33 changes: 33 additions & 0 deletions
33
...t/resources/org/eolang/lints/packs/comment-is-too-wide/allows-multiline-good-comment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2016-2024 Objectionary.com | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
--- | ||
sheets: | ||
- /org/eolang/lints/comments/comment-is-too-wide.xsl | ||
asserts: | ||
- /defects[count(defect[@severity='warning'])=0] | ||
input: | | ||
# This is good line. | ||
# This is good line too. | ||
# This is good line as well. | ||
# We are here! | ||
[] > foo | ||
52 > @ |
32 changes: 32 additions & 0 deletions
32
.../resources/org/eolang/lints/packs/comment-is-too-wide/catches-multiline-wide-comment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2016-2024 Objectionary.com | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
--- | ||
sheets: | ||
- /org/eolang/lints/comments/comment-is-too-wide.xsl | ||
asserts: | ||
- /defects[count(defect[@severity='warning'])=1] | ||
- /defects/defect[@line='3'] | ||
input: | | ||
# This is good line. | ||
# This is a very long line that contains more than eighty characters and should be flagged by the lint as too wide. | ||
[] > foo | ||
42 > @ |
31 changes: 31 additions & 0 deletions
31
src/test/resources/org/eolang/lints/packs/comment-is-too-wide/catches-too-wide-comment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2016-2024 Objectionary.com | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
--- | ||
sheets: | ||
- /org/eolang/lints/comments/comment-is-too-wide.xsl | ||
asserts: | ||
- /defects[count(defect[@severity='warning'])=1] | ||
- /defects/defect[@line='2'] | ||
input: | | ||
# This is a very long comment that contains more than eighty characters and should be flagged by the lint as too wide. | ||
[] > foo | ||
42 > @ |