Skip to content

Feature: allow turning off specific linters per-line #605

@AshesITR

Description

@AshesITR

It might be useful to disable only a specific linter on a per-line basis, e.g.

`%||%` = function(x, y) {
  if (is.null(x)) y else x
}

produces two default lints: object_name_linter and assignment_linter.
One may actively decide that %||% is an acceptable name here and not want to generally disable object_name_linter.

Currently, this can only be achieved by # nolint'ing the entire line

`%||%` = function(x, y) { # nolint
  if (is.null(x)) y else x
}

but unfortunately this also kills the assignment_linter

It would be very useful to have a way to only exclude some linters on a line (or in a block).
A syntax might be a space-separated list of linters to be disabled, e.g.

`%||%` = function(x, y) { # nolint object_name_linter
  if (is.null(x)) y else x
}

I realize this would require work in the way exclusions are specified. Especially the line-based specification in .lintr files or the exclusions argument requires thought.

One solution would be one more level of (optional) nesting

exclude: list(
    "my_file.R" = list(
      1,
      "2" = "object_name_linter",
      "4" = c("line_length_linter", "commented_code_linter")
    )
  )

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions