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
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,50 @@
<xsl:import href="/org/eolang/funcs/lineno.xsl"/>
<xsl:import href="/org/eolang/funcs/defect-context.xsl"/>
<xsl:output encoding="UTF-8" method="xml"/>
<!--
@todo #1046:30min Report the exact physical line of the too-wide line
inside a multi-line comment. Right now every offending line is reported
with the comment block's own start @line, since the XSL has no way to
compute the offset of a line within the tokenized comment text. Add a
$pos-based offset (comment @line + position() - 1) so
catches-multiline-wide-comment.yaml can assert on line 2 (the actual
offending line) instead of line 1.
-->
<xsl:template match="/">
<xsl:variable name="max" select="100"/>
<defects>
<xsl:for-each select="/object/comments/comment">
<xsl:variable name="line" select="if (@line) then @line else '0'"/>
<xsl:variable name="comment" select="."/>
<xsl:variable name="line" select="eo:lineno(@line)"/>
<xsl:variable name="lines" select="tokenize(replace(., '\\n', '&#10;'), '&#10;')"/>
<xsl:choose>
<xsl:when test="count($lines) &gt; 1">
<xsl:for-each select="$lines[string-length(.) &gt; $max]">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="$line"/>
<xsl:for-each select="$lines">
<xsl:variable name="offset" select="position() - 1"/>
Comment thread
yegor256 marked this conversation as resolved.
<xsl:if test="string-length(.) &gt; $max">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:choose>
<xsl:when test="$line = '0'">
<xsl:value-of select="$line"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number(number($line) + $offset, '0')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="$line = '0'">
<xsl:attribute name="context">
<xsl:value-of select="eo:defect-context($comment)"/>
</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">
<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(.) &gt; $max">
<xsl:element name="defect">
<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">
<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:if>
<xsl:attribute name="severity">
<xsl:text>warning</xsl:text>
</xsl:attribute>
<xsl:choose>
<xsl:when test="count($lines) &gt; 1">
<xsl:text>The comment line width is </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>The comment width is </xsl:text>
</xsl:otherwise>
</xsl:choose>
<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:for-each>
</xsl:for-each>
</defects>
</xsl:template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sheets:
- /org/eolang/lints/comments/comment-is-too-wide.xsl
asserts:
- /defects[count(defect[@severity='warning'])=1]
- /defects/defect[@line='1']
- /defects/defect[@line='2']
input: |
# This is good line.
# This is a very long line that contains more than 100 characters and should be flagged by the lint as too wide.
Expand Down
Loading