Skip to content

Commit

Permalink
#11 comments checked
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 19, 2024
1 parent a25068e commit f15c131
Show file tree
Hide file tree
Showing 44 changed files with 413 additions and 115 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/lints/Defect.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ final class Default implements Defect {
* @param text Description of the defect
* @checkstyle ParameterNumberCheck (5 lines)
*/
Default(final String rule, final Severity severity,
public Default(final String rule, final Severity severity,
final int line, final String text) {
this.rle = rule;
this.sev = severity;
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/org/eolang/lints/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import org.cactoos.iterable.Joined;
import org.cactoos.iterable.Sticky;
import org.eolang.lints.comments.AsciiOnly;

/**
* A single XMIR program to analyze.
Expand All @@ -43,7 +46,14 @@ public final class Program {
/**
* Lints to use.
*/
private static final Iterable<Lint> LINTS = new Sticky<>(new XslLints());
private static final Iterable<Lint> LINTS = new Sticky<>(
new Joined<Lint>(
new XslLints(),
Arrays.asList(
new AsciiOnly()
)
)
);

/**
* The XMIR program to analyze.
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/org/eolang/lints/comments/AsciiOnly.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.
*/
package org.eolang.lints.comments;

import com.jcabi.xml.XML;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import org.eolang.lints.Defect;
import org.eolang.lints.Lint;
import org.eolang.lints.Severity;

/**
* A comment must include only ASCII characters.
*
* @since 0.1.0
*/
public final class AsciiOnly implements Lint {

@Override
public Collection<Defect> defects(final XML xmir) throws IOException {
final Collection<Defect> defects = new LinkedList<>();
for (final XML comment : xmir.nodes("/program/comments/comment")) {
if (comment.xpath("text()").get(0).chars().anyMatch(chr -> chr < 32 || chr > 127)) {
defects.add(
new Defect.Default(
"ascii-only",
Severity.ERROR,
Integer.parseInt(comment.xpath("@line").get(0)),
"Comment must contain only ASCII printable characters: 0x20-0x7f"
)
);
}
}
return defects;
}
}
30 changes: 30 additions & 0 deletions src/main/java/org/eolang/lints/comments/package-info.java
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.
*/

/**
* Lints for comments.
*
* @since 0.0.1
*/
package org.eolang.lints.comments;
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/lints/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

/**
* Linters.
* Lints (style checkers).
*
* @since 0.0.1
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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-capital" version="2.0">
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<xsl:variable name="min" select="32"/>
<defects>
<xsl:for-each select="/program/comments/comment[matches(., '^[A-Z]')]">
<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 doesn't start with a capital English letter</xsl:text>
</xsl:element>
</xsl:for-each>
</defects>
</xsl:template>
</xsl:stylesheet>
45 changes: 45 additions & 0 deletions src/main/resources/org/eolang/lints/comments/comment-too-short.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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-too-short" version="2.0">
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<xsl:variable name="min" select="32"/>
<defects>
<xsl:for-each select="/program/comments/comment[string-length(.) &lt; $min]">
<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 for the object is too short (shorter than </xsl:text>
<xsl:value-of select="$min"/>
<xsl:text> characters)</xsl:text>
</xsl:element>
</xsl:for-each>
</defects>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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-too-short" version="2.0">
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="/">
<xsl:variable name="min" select="32"/>
<defects>
<xsl:for-each select="/program/comments/comment[ends-with(., '.')]">
<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 for the object doesn't end with a dot</xsl:text>
</xsl:element>
</xsl:for-each>
</defects>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ SOFTWARE.
<xsl:variable name="x" select="."/>
<xsl:if test="preceding-sibling::o/@name = $x/@name">
<xsl:element name="defect">
<xsl:attribute name="check">
<xsl:text>duplicate-names</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ SOFTWARE.
<defects>
<xsl:for-each select="//o[@atom and o[@base]]">
<xsl:element name="defect">
<xsl:attribute name="check">
<xsl:text>not-empty-atoms</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
Expand All @@ -52,9 +49,6 @@ SOFTWARE.
</xsl:for-each>
<xsl:for-each select="//o[@atom and o[@atom]]">
<xsl:element name="defect">
<xsl:attribute name="check">
<xsl:text>not-empty-atoms</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ SOFTWARE.
<xsl:variable name="x" select="."/>
<xsl:for-each select="(following::o | descendant::o)[@name=$x/@name and @line=$x/@line]">
<xsl:element name="defect">
<xsl:attribute name="check">
<xsl:text>same-line-names</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/org/eolang/lints/critical/self-naming.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ SOFTWARE.
<defects>
<xsl:for-each select="//o[@name and @base and (eo:base-eq-name(.) or eo:with-this(.) or eo:with-method(.) or eo:with-method-and-this(.))]">
<xsl:element name="defect">
<xsl:attribute name="check">
<xsl:text>self-naming</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ SOFTWARE.
<defects>
<xsl:for-each select="//o[eo:abstract(.) and @name and @name='@']">
<xsl:element name="defect">
<xsl:attribute name="check">
<xsl:text>abstract-decoratee</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/org/eolang/lints/errors/empty-object.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ SOFTWARE.
<defects>
<xsl:for-each select="//o[@abstract and not(o)]">
<xsl:element name="defect">
<xsl:attribute name="check">
<xsl:text>empty-object</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ SOFTWARE.
<xsl:if test="not($package='org.eolang')">
<xsl:for-each select="//o[@atom and @atom='?']">
<xsl:element name="defect">
<xsl:attribute name="check">
<xsl:text>external-weak-typed-atoms</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/org/eolang/lints/errors/global-nonames.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ SOFTWARE.
<defects>
<xsl:for-each select="/program/objects/o[not(@name) and not(@method) and not(following-sibling::o[1][@method])]">
<xsl:element name="defect">
<xsl:attribute name="check">
<xsl:text>global-nonames</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ SOFTWARE.
<defects>
<xsl:for-each select="//o[count(o[@name and not(@base) and not(@atom) and count(o)=0]) &gt; 5]">
<xsl:element name="defect">
<xsl:attribute name="check">
<xsl:text>too-many-attributes</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ SOFTWARE.
<xsl:template match="o" mode="abstract">
<xsl:for-each select="o[not(@name)]">
<xsl:element name="defect">
<xsl:attribute name="check">
<xsl:text>noname-attributes</xsl:text>
</xsl:attribute>
<xsl:attribute name="line">
<xsl:value-of select="@line"/>
</xsl:attribute>
Expand Down
Loading

0 comments on commit f15c131

Please sign in to comment.