Skip to content

Bad error handling for invalid Lint()s #763

Closed

Description

@AshesITR

When a linter returns a Lint with an invalid (NA) column_number, as has recently happened in some regex-based linters, the error message is extremely confusing:

Error in rep.int(character, length) : invalid 'times' value
Calls: <Anonymous> ... print.lint -> cat -> highlight_string -> fill_with -> paste0
Execution halted

IMO Lint() should do some mild verification during construction so that invalid Lint()s can't be created successfully.

Here are a bunch of checks we could add:

  1. No NAs are allowed anywhere.
  2. 1L <= column_number <= nchar(line) + 1L.
  3. line_number >= 1L.
  4. ranges is a list of length 2 integer(ish) vectors, or NULL.
  5. 1L <= ranges[[i]][1L] <= ranges[[i]][2L] <= nchar(line) + 1L for all i.

WDYT?

Activity

  1. added
    feature
    on Feb 17, 2021
  2. MichaelChirico commented on Feb 18, 2021

    @MichaelChirico
    Collaborator

    Would NULL be allowed for all of these? I'm thinking of lints that aren't as specific as the line/column level (e.g. file-level lints or line-level lints), which might make sense to leave one/both of line_number / column_number blank.

    For ranges, don't we have cases where ranges[2L] might apply to a different line?

  3. AshesITR commented on Feb 18, 2021

    @AshesITR
    CollaboratorAuthor

    IINM NULLs are allowed in some places, but ranges are constrained to a single line only (or NULL), as we can currently only flag one line.

    Line and column numbers could default to 1 as that would always be valid.

  4. added this to the 3.0.1 milestone on Jul 27, 2022
  5. added a commit that references this issue on Dec 3, 2022
    1c23a25
  6. added a commit that references this issue on Dec 8, 2022
    a936cf6
  7. modified the milestones: 3.0.3, on Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions