Repository navigation
Ignore multi-line string contents optionally in line_length_linter - #2799
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
AshesITR
left a comment
There was a problem hiding this comment.
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 |
|
Bumping for review :) |
Bisaloo
left a comment
There was a problem hiding this comment.
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.
| #' @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. |
There was a problem hiding this comment.
| #' 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.
There was a problem hiding this comment.
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 <- '
# ~~~~~~~~~~^Co-authored-by: Hugo Gruson <[email protected]>
Closes #856. Progress on #2737