Skip to content

linter exclusions bug #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
russHyde opened this issue Feb 11, 2021 · 8 comments · Fixed by #753
Closed

linter exclusions bug #746

russHyde opened this issue Feb 11, 2021 · 8 comments · Fixed by #753
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@russHyde
Copy link
Collaborator

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:

# R/utils.R
Linter <- function(fun) { # nolint: object_name_linter
  # blah
}

... no lint is thrown for the name Linter

@russHyde
Copy link
Collaborator Author

russHyde commented 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:

lint_package(linters = list(object_name_linter = object_name_linter()))

(but now, if I remove the terminal dot in the exclusion comment, the object-name lints are thrown)

@russHyde
Copy link
Collaborator Author

The expected behaviour here is:

# R/file.R
Some_class <- function(x) { # nolint object_name_linter.
}
Another_class <- function(x) { # nolint object_name_linter
}
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

@AshesITR
Copy link
Collaborator

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.

@AshesITR AshesITR added the bug an unexpected problem or unintended behavior label Feb 11, 2021
@AshesITR AshesITR added this to the 3.0.0 milestone Feb 11, 2021
@AshesITR
Copy link
Collaborator

Here's the problem:

>names(linters)
[1] "object_name_linter()"

We need to change the implementation of auto_names().

@AshesITR
Copy link
Collaborator

@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.

@AshesITR
Copy link
Collaborator

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?

@russHyde
Copy link
Collaborator Author

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")
}

@AshesITR
Copy link
Collaborator

AshesITR commented Feb 13, 2021

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

AshesITR added a commit that referenced this issue Feb 13, 2021
AshesITR added a commit that referenced this issue Feb 16, 2021
* add name attribute to Linter class

fixes #746

* fix test failures

* document()

* restore 100% coverage for utils.R

* deprecate Lint(linter = ...) and remove all calling instances

make expect_lint() resilient to complete removal of the argument

* add NEWS bullet

* document()

* fix lint, collapse with space

fix test expectation

Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
MichaelChirico added a commit that referenced this issue Feb 17, 2021
* add name attribute to Linter class

fixes #746

* fix test failures

* document()

* restore 100% coverage for utils.R

* deprecate Lint(linter = ...) and remove all calling instances

make expect_lint() resilient to complete removal of the argument

* add NEWS bullet

* document()

* fix lint, collapse with space

fix test expectation

Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
MichaelChirico added a commit that referenced this issue Feb 17, 2021
* add name attribute to Linter class

fixes #746

* fix test failures

* document()

* restore 100% coverage for utils.R

* deprecate Lint(linter = ...) and remove all calling instances

make expect_lint() resilient to complete removal of the argument

* add NEWS bullet

* document()

* fix lint, collapse with space

fix test expectation

Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
AshesITR added a commit that referenced this issue Feb 18, 2021
* initial formalization of Russ's branch comparison script

* tweaks

* tweak again

* debugging

* workaround for Depends

* more tweak

* skip empty depends

* add to buildignore

* use optparse

* consolidate TODO

* add name attribute to Linter class (#753)

* add name attribute to Linter class

fixes #746

* fix test failures

* document()

* restore 100% coverage for utils.R

* deprecate Lint(linter = ...) and remove all calling instances

make expect_lint() resilient to complete removal of the argument

* add NEWS bullet

* document()

* fix lint, collapse with space

fix test expectation

Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>

* typo in optparse funciton

skip Depends except on object_usage_linter

typo

need check higher up

forgot to supply arg

just exit early if Depends unavailable

provide an interactive() experience for debugging

tweak

* add name attribute to Linter class (#753)

* add name attribute to Linter class

fixes #746

* fix test failures

* document()

* restore 100% coverage for utils.R

* deprecate Lint(linter = ...) and remove all calling instances

make expect_lint() resilient to complete removal of the argument

* add NEWS bullet

* document()

* fix lint, collapse with space

fix test expectation

Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>

* typo

* vestigial variable name

not working from command line

testing more

debugging Rscript sucks

progress -- we need to skip missing Imports too

more progress -- skip on platforms without tcl/tk

need testing again

need to exit early

* skip directories with encoding issues

* switch conditions

* remove tracing

Co-authored-by: AshesITR <alexander.rosenstock@web.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants