rubocop / rubocop

A Ruby static code analyzer and formatter, based on the community Ruby style guide.

Home Page:https://docs.rubocop.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False positive for `Layout/SpaceAroundKeyword` when using `ParserEngine: parser_prism`

andyw8 opened this issue · comments

Steps to reproduce the problem

Create a file containing:

while true
  # random
end

RuboCop fails with Layout/SpaceAroundKeyword: Space before keyword do is missing.

This might relate to some underlying issue in prism, I haven't investigated yet.

RuboCop version

% bin/rubocop -V                                                                                                                  
1.62.1 (using Prism 0.24.0, rubocop-ast 1.31.2, running on ruby 3.3.0) [x86_64-linux]
  - rubocop-graphql 1.5.1
  - rubocop-minitest 0.35.0
  - rubocop-performance 1.21.0
  - rubocop-rails 2.24.1
  - rubocop-sorbet 0.8.0

(I also get Style/WhileUntilDo: Do not use do with multi-line while.).

Another one, which is probably the same underlying cause:

if true
  # ;
end

Fails with Style/IfWithSemicolon: Do not use if true; - use a ternary operator instead.

(this is is Prism 0.24.0, I'll check if it still happens on 0.25.0).

Yes, still happens with 0.25.0.

Both of these are problems with srange_find in the translation layer. They should not be searching comments.

Thanks @kddnewton, I'll look into fixing that in Prism.

@koic I'm not sure if you want to keep this open for tracking, feel free to close it.

Working on a fix in ruby/prism#2694

@andyw8 this may have been fixed in the latest version of prism, can you check?

Indeed it is, I updated the core branch earlier.