Skip to content

Ignore multi-line string contents optionally in line_length_linter - #2799

Merged
MichaelChirico merged 24 commits into
mainfrom
line-length-str-body
Nov 11, 2025
Merged

MichaelChirico merged 24 commits into
mainfrom
line-length-str-body

Conversation

@MichaelChirico

Copy link
Copy Markdown
Collaborator

Closes #856. Progress on #2737

@codecov

codecov Bot commented Feb 27, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.24%. Comparing base (57ced9c) to head (13205f9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2799   +/-   ##
=======================================
  Coverage   99.24%   99.24%           
=======================================
  Files         129      129           
  Lines        7282     7317   +35     
=======================================
+ Hits         7227     7262   +35     
  Misses         55       55           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AshesITR AshesITR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the tests I'm wondering whether all you need is supress lints if the lint line satisfies line1 < line < line2 for some //STR_CONST?

Comment thread R/line_length_linter.R Resolved
Comment thread R/line_length_linter.R Resolved
Comment thread R/line_length_linter.R Resolved
Comment thread R/line_length_linter.R Resolved
@MichaelChirico

Copy link
Copy Markdown
Collaborator Author

Looking at the tests I'm wondering whether all you need is supress lints if the lint line satisfies line1 < line < line2 for some //STR_CONST?

there's also the issue of how to deal with lines like this:

x <- 'long string starting on a short
line which also has long strings in
the other parts of the body'

Before this rule, there's 3 lints, but under ignore_string_bodies=TRUE here, there are 0

@MichaelChirico

Copy link
Copy Markdown
Collaborator Author

Bumping for review :)

@MichaelChirico
MichaelChirico requested review from Bisaloo, IndrajeetPatil and olivroy and removed request for olivroy June 27, 2025 18:55
@MichaelChirico MichaelChirico added this to the 3.3.0 milestone Jul 29, 2025
@MichaelChirico MichaelChirico changed the title Ignore multi-string contents optionally in line_length_linter Ignore multi-line string contents optionally in line_length_linter Jul 29, 2025
Comment thread NEWS.md Resolved

@Bisaloo Bisaloo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to come back to this several time because the current version of is_in_string_body() is quite complex. I think part of it is the switch between vectorized and vapply logic and the easily missed changes between str_idx/long_idx as well as str_data/parse_data.

Comment thread R/line_length_linter.R
#' @param length Maximum line length allowed. Default is `80L` (Hollerith limit).
#' @param ignore_string_bodies Logical, default `FALSE`. If `TRUE`, the contents
#' of string literals are ignored. The quotes themselves are included, so this
#' mainly affects wide multiline strings, e.g. SQL queries.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' mainly affects wide multiline strings, e.g. SQL queries.
#' only affects wide multiline strings, e.g. SQL queries.

?

Looking at the code, this seems clearer & more precise.

@MichaelChirico MichaelChirico Oct 29, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new example related to this -- what I'm trying to convey is mainly that the closing quote counts towards the line length where it's found.

1234567890
----------
string <- "
 too long!
"

The less common case is that the opening " here will also trigger a lint (with max width 10)

lint("string <- '\n  too long\n'", line_length_linter(10, ignore_string_bodies=TRUE))
# <text>:1:11: style: [line_length_linter] Lines should not be more than 10 characters. This line is 11 characters.
# string <- '
# ~~~~~~~~~~^

Comment thread R/line_length_linter.R Resolved
Comment thread R/line_length_linter.R Resolved
Co-authored-by: Hugo Gruson <[email protected]>
@MichaelChirico
MichaelChirico merged commit 252b4f4 into main Nov 11, 2025
@MichaelChirico
MichaelChirico deleted the line-length-str-body branch November 11, 2025 15:27
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.

Turn off line length linter within string literals (optionally?)

3 participants