objectionary / objectionary/lints
`comment-is-too-wide` incorrectly reports over-wide lines at the start of multi-line comments
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 14
- Forks
- 39
- Avg merge
- 22h 54m
- Merged PRs (30d)
- 90
Description
comment-is-too-wide splits a multi-line comment into its lines and reports each over-wide line at the comment's first line, so the number in the defect points at a line that is very likely fine.
src/main/resources/org/eolang/lints/comments/comment-is-too-wide.xsl:
<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>
$line is read once, before the loop, from the comment element. Every defect the loop emits carries that same value. A comment whose fourth line is 120 characters wide is reported on the line the comment starts on, and a comment with three over-wide lines produces three defects that all name that one line.
The rule is the only one in this directory that walks inside a comment, so it is the only one where the comment's own line and the offending line differ. Its single-line branch, further down, is correct by construction — there the two are the same line.
The offset is available where the defect is built, but not from position(): the predicate [string-length(.) > $max] filters first, so inside that for-each the position is the index among the offending lines, not among all of them. Walking every line and testing inside the loop keeps the index meaningful:
<xsl:for-each select="$lines">
<xsl:if test="string-length(.) > $max">
<xsl:element name="defect">
<xsl:attribute name="line">
<xsl:value-of select="number($line) + position() - 1"/>
</xsl:attribute>
with number($line) guarding against the '0' fallback being concatenated rather than added.
Worth checking the '0' path in the same change. When the comment carries no @line, every defect gets line 0 and a context attribute, which is the intended fallback; with the offset added, 0 + position() - 1 would produce line numbers counting from zero for a comment whose real position is unknown. Keeping the fallback at 0 when @line is absent, and offsetting only when it is present, avoids inventing a location.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/main/resources/org/eolang/lints/comments/comment-is-too-wide.xsl, especially the multi-line and single-line branches. Check how the reported line is calculated for each over-wide line, then verify both comments with @line and the fallback path without it. Done means defects point to the offending lines without changing the existing single-line behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- xml
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 85/100