Description
I have noticed what I expect is unintended behaviour.
Consider the example below
Starting with an empty folder, we include create file "test.R") with the following content:
N <- 2
If we run lintr::lint_dir()
, we get the following lints:
Line 1 [object_name_linter] Variable and function name style should match snake_case or symbols
If we then alter the file to read:
N <- 2 # nolint: some_linter
And then we then run lintr::lint_dir()
, we now get no lints at all despite not supressing the object_name_linter
.
Looking into the issue, it seems to stem form the default setting for "exclude_linter"
which takes the value "^[[:space:]]*:[[:space:]]*(?<linters>(?:(?:[^,.])+[[:space:]]*,[[:space:]]*)*(?:[^,.])+)\."
If I now add a .lintr.R
file to my project with the following content:
exclude_linter <- r"{"^[[:space:]]*:[[:space:]]*((?:(?:[^,.])+[[:space:]]*,[[:space:]]*)*(?:[^,.])+)\.?"}"
And run the linter again, we correctly get lints for our altered file
Line 1 [object_name_linter] Variable and function name style should match snake_case or symbols
This regex expression is different in two ways from the default:
- It ends with
\.?
instead of\.
- The naming of the capture group was dropped.
The latter change is only because it will not validate with the naming present.
This second change is related to a separate, minor issue with lintr:::is_valid_regex
:
lintr:::is_valid_regex(lintr::default_settings$exclude_linter) # FALSE