Repository navigation
Description
A lot of new users seem to stumble upon the quirkiness of the dcf format we use for .lintr.
I see three major pitfalls:
- Indentation of multiline code is not intuitive
# Wrong
linters: with_defaults(
line_length_linter = line_length_linter(120)
)
# Right
linters: with_defaults(
line_length_linter = line_length_linter(120)
)
- Trailing newline is mandatory, but not reported as an error
# Wrong
linters: with_defaults(
line_length_linter = line_length_linter(120)
)
(EOF)
# Right
linters: with_defaults(
line_length_linter = line_length_linter(120)
)
(EOF)
- The proper location of the
.lintrconfig files sometimes causes confusion.
It would be nice of us to catch these and report a warning (or maybe even an error?) if the config file is malformed.
Regarding the location issue, maybe reporting the config file used (if any) would help diagnosing the problem more quickly.
I see a few options here as to when to report it:
- Only if some option (
linter.verbose, orlintr.debug?) is set. - Only if some argument (
verbose, ordebug?) is TRUE. - Always if running interactively.
- Always at the start of a top-level call (lint_dir, lint_package or lint if the latter isn't called from within lint_*).
WDYT?
I think the most user-friendly version would be to use getOption("lintr.???", default = interactive()) to decide whether to print this diagnostic info at the start of a top-level call.
If no config file is found, the info could be
Using the default linter configuration. See vignette("using_lintr", package = "lintr") for customization options.
or something like that.
Activity
stufield commentedon Nov 13, 2021
@AshesITR I think this is a great idea!
MichaelChirico commentedon Nov 15, 2021
Even better than just detecting issues, if we can
warn(), fix, and continue, that's even better. (2) in particular strikes me as something that we should be flexible on.Is there any ambiguity that we avoid by keeping the current strict rules on the .lintr? Or is it just maintenance overhead for the .lintr parser?
(3) is a bit tougher... could we expose a
show_lintr_config()helper that would give a detailed warning if no .lintr is found in the right places?AshesITR commentedon Nov 15, 2021
(1) produces the following error in
read.dcf:(2) appears to not cause issues in
read.dcffor R 4.1.2, but I think it used to cause the same warning asreadLines()in some earlier versions:https://github.com/jimhester/lintr/blob/8cd6adde3c6f08b88fcd1a280ad276784bd4f1f4/R/settings.R#L28
Can someone verify this?
(3) maybe call it
lintr_sitrep(), akin to other tidyverse packages?Sounds cleaner than changing the (default) output of long-existing functions.
The only downside is users may need to be pointed to it.
MichaelChirico commentedon Jun 25, 2023
One easy win here would be to signal that the config is malformed, e.g. I had this file:
and
lint_package()complains:Not the most informative error.
more informative error message if a lintr config setting is broken
more informative error message if a lintr config setting is broken (#…