You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running lint_package(linters = object_name_linter()) on current master of lintr:
R/utils.R:224:1: style: Variable and function name style should be snake_case or symbols.
Linter <- function(fun) { # nolint: object_name_linter.
^~~~~~
and a couple of similar issues.
Note that if the nolint comment for Linter in R/utils.R is changed, removing the terminal dot:
Note further, if the call to lint_package is made with a named list (and with the lint-exclusion comments as they initially were, with the closing dot), no object-name lints are thrown:
lint_package(linters = object_name_linter()) # Some_class is green; Another_class is red (or possibly a warning for misspecified linter-exclusion syntax)
lint_package(linters = list(object_name_linter = object_name_linter())) # Same results as the previous command
At first glance this looks like a regression introduced by the Linter class PR.
Could you check names(linters) in the MWE?
Re expected behaviour: I'd expect Another_class to be green as well since failure to parse exclusions should cause a blanket # nolint behaviour, suppressing all lints.
@russHyde WDYT about the defaults being the match of "^[A-Za-z._]+" against deparse(...) and then passing defaults to make.unique() to ensure uniqueness?
This would auto name list(line_length_linter(120), line_length_linter(80)) as c("line_length_linter", "line_length_linter_1") if we make.unique(..., sep = "_")
The changed separator is necessary if we stick with the current specification for linter exclusions as it does not allow dots in the names.
What I don't like about make.unique is that it only renames the second duplicate.
I think we have an even bigger problem. With the custom linters going in, deparse returns basically the source code of the Linter.
This could be fixed by adding a name attribute to the Linter class and making Linter() smart about auto-naming. WDYT?
Do you think anyone would be using multiple copies of the same Linter in their set of linters?
I'm afraid I didn't follow the bit about deparse'ing a custom linter.
Making the Linter class smarter about naming would clarify the code a bit. For example, there's duplication of the linter-name in a few places in the code-base and it can be a bit confusing
# the user might call
lint(".", linters = list(some_linter = some_linter()))
# the "linter" in the output is the same as the function-name
some_linter <- function(...) {
...
Lint(..., linter = "some_linter")
}
I've started a draft to make this smarter.
Re multiple linters of the same type: line_length_linter is a bad example, but a more complete example for shiny apps to force all library() statements to occur at a specific location:
linters = with_defaults(undesirable_function_linter(default_undesirable_functions[-4]), library_linter = undesirable_function_linter(list(library = "place all library calls at the top of 'global.R'"))
Could work nicely with
global.R
# nolint start: library_linter.
# place all library calls here
library(shiny)
# ...
# nolint end
Activity
russHyde commentedon Feb 11, 2021
Note further, if the call to lint_package is made with a named list (and with the lint-exclusion comments as they initially were, with the closing dot), no object-name lints are thrown:
(but now, if I remove the terminal dot in the exclusion comment, the object-name lints are thrown)
russHyde commentedon Feb 11, 2021
The expected behaviour here is:
AshesITR commentedon Feb 11, 2021
At first glance this looks like a regression introduced by the
Linterclass PR.Could you check
names(linters)in the MWE?Re expected behaviour: I'd expect
Another_classto be green as well since failure to parse exclusions should cause a blanket# nolintbehaviour, suppressing all lints.AshesITR commentedon Feb 13, 2021
Here's the problem:
We need to change the implementation of
auto_names().AshesITR commentedon Feb 13, 2021
@russHyde WDYT about the defaults being the match of
"^[A-Za-z._]+"againstdeparse(...)and then passing defaults tomake.unique()to ensure uniqueness?This would auto name
list(line_length_linter(120), line_length_linter(80))asc("line_length_linter", "line_length_linter_1")if wemake.unique(..., sep = "_")The changed separator is necessary if we stick with the current specification for linter exclusions as it does not allow dots in the names.
What I don't like about
make.uniqueis that it only renames the second duplicate.AshesITR commentedon Feb 13, 2021
I think we have an even bigger problem. With the custom linters going in,
deparsereturns basically the source code of theLinter.This could be fixed by adding a
nameattribute to theLinterclass and makingLinter()smart about auto-naming. WDYT?russHyde commentedon Feb 13, 2021
Do you think anyone would be using multiple copies of the same
Linterin their set of linters?I'm afraid I didn't follow the bit about deparse'ing a custom linter.
Making the Linter class smarter about naming would clarify the code a bit. For example, there's duplication of the linter-name in a few places in the code-base and it can be a bit confusing
AshesITR commentedon Feb 13, 2021
I've started a draft to make this smarter.
Re multiple linters of the same type:
line_length_linteris a bad example, but a more complete example for shiny apps to force alllibrary()statements to occur at a specific location:linters = with_defaults(undesirable_function_linter(default_undesirable_functions[-4]), library_linter = undesirable_function_linter(list(library = "place all library calls at the top of 'global.R'"))Could work nicely with
global.R
add name attribute to Linter class
add name attribute to Linter class (#753)
add name attribute to Linter class (#753)
add name attribute to Linter class (#753)
Add a script for comparing lint output on branches/PRs (#760)