Skip to content

file-length-limit: count each skipped line once - #1928

Open
TastyHeadphones wants to merge 1 commit into
revive-lint:masterfrom
TastyHeadphones:fix/file-length-limit-double-count
Open

TastyHeadphones wants to merge 1 commit into
revive-lint:masterfrom
TastyHeadphones:fix/file-length-limit-double-count

Conversation

@TastyHeadphones

Copy link
Copy Markdown

Closes #1863

With skipComments and skipBlankLines both enabled, file-length-limit subtracted comment lines and blank lines separately, so an empty line inside a block comment was removed twice. Two comments on the same line (/* a */ // b) were also counted as two comment lines.

The rule now collects the skipped physical line numbers in a set and subtracts its size, so each line is skipped at most once. Comment lines come from the comments' token positions instead of counting \n in the comment text. Which lines count as comment lines is unchanged.

Tests: added testdata/file_length_limit_4_skip_comments_skip_blank_overlap.go, which has a block comment with an empty line and a line with two comments. It reports 3 lines (no failure) before this change and 5 lines after. go test -race ./..., revive --config revive.toml ./... and golangci-lint run (v2.14.0) pass.

This change was drafted with AI assistance (Grok). I reviewed the diff and ran the tests above.

With skipComments and skipBlankLines both set, an empty line inside a
block comment was subtracted twice, and two comments on one line were
counted as two comment lines. Collect the skipped line numbers in a set
and take comment lines from token positions instead.

Closes revive-lint#1863
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant