Skip to content
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

Off-by-one diagnostic #595

Closed
mattmassicotte opened this issue Sep 8, 2022 · 4 comments
Closed

Off-by-one diagnostic #595

mattmassicotte opened this issue Sep 8, 2022 · 4 comments

Comments

@mattmassicotte
Copy link
Contributor

After a little digging, I've discovered that the following document will produce a diagnostic with a position that is 1 character past the end of the last line. Something with the line being empty matters here. If it is a single space, things are ok.

require 'a thing'

class Example
  # @return [String]
  def stringify
    "example".
  end
end

Example.new.stringify(1, 2)
Example.new.stringify(1, 2)

The diagnostic is:

unexpected token $end
(Using Ruby 2.5 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)

rubocop.yml

Style/StringLiterals:
  EnforcedStyle: double_quotes
@castwide
Copy link
Owner

That diagnostic gets reported because of the trailing period in "example".. Solargraph can ignore those kinds of syntax errors under certain circumstances, but RuboCop still detects it.

@mattmassicotte
Copy link
Contributor Author

mattmassicotte commented Sep 28, 2022

Just to be really clear, the diagnostic itself is expected. The range it returns is out of bounds.

@castwide
Copy link
Owner

Ah, gotcha. RuboCop uses 1-based lines and columns, and there's a branch in the reporter that doesn't account for it. I'll fix it in a patch.

castwide added a commit that referenced this issue Sep 30, 2022
@castwide
Copy link
Owner

Released in v0.47.2.

@castwide castwide closed this as completed Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants