-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Rails/LexicallyScopedActionFilter
outputs error for %I literal
#5524
Comments
8 tasks
wata727
added a commit
to wata727/rubocop
that referenced
this issue
Jan 31, 2018
Fixes rubocop#5524 When parsing the following, we get `StrNode` instead of `SymbolNode`. ```ruby %I[index] ``` ``` $ pry -rparser -rparser/ruby24 -rrubocop [1] pry(main)> buffer = Parser::Source::Buffer.new('(string)') [2] pry(main)> buffer.source = "%I[index]" [3] pry(main)> builder = RuboCop::AST::Builder.new [4] pry(main)> parser = Parser::Ruby24.new(builder) [5] pry(main)> node = parser.parse(buffer) => s(:array, s(;sym, :index)) [6] pry(main)> node.children.first.type => :sym [7] pry(main)> node.children.first.class => RuboCop::AST::StrNode # Why? ``` This is because the parser gem updates the node itself in `Parser::AST::Node#symbols_compose` when processing `tSYMBOLS_BEG`. See also: https://github.com/whitequark/parser/blob/v2.4.0.2/lib/parser/ruby24.y#L1738 https://github.com/whitequark/parser/blob/v2.4.0.2/lib/parser/builders/default.rb#L298 However, since RuboCop overrides `Parser::AST::Node#updated`, even if the type is updated, it will use the current class as it is. In order to prevent this, it creates an instance based on type instead of `self` class.
bbatsov
pushed a commit
that referenced
this issue
Feb 2, 2018
Fixes #5524 When parsing the following, we get `StrNode` instead of `SymbolNode`. ```ruby %I[index] ``` ``` $ pry -rparser -rparser/ruby24 -rrubocop [1] pry(main)> buffer = Parser::Source::Buffer.new('(string)') [2] pry(main)> buffer.source = "%I[index]" [3] pry(main)> builder = RuboCop::AST::Builder.new [4] pry(main)> parser = Parser::Ruby24.new(builder) [5] pry(main)> node = parser.parse(buffer) => s(:array, s(;sym, :index)) [6] pry(main)> node.children.first.type => :sym [7] pry(main)> node.children.first.class => RuboCop::AST::StrNode # Why? ``` This is because the parser gem updates the node itself in `Parser::AST::Node#symbols_compose` when processing `tSYMBOLS_BEG`. See also: https://github.com/whitequark/parser/blob/v2.4.0.2/lib/parser/ruby24.y#L1738 https://github.com/whitequark/parser/blob/v2.4.0.2/lib/parser/builders/default.rb#L298 However, since RuboCop overrides `Parser::AST::Node#updated`, even if the type is updated, it will use the current class as it is. In order to prevent this, it creates an instance based on type instead of `self` class.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected behavior
No offences are detected.
Actual behavior
Steps to reproduce the problem
rubocop -d --only Rails/LexicallyScopedActionFilter app/controllers/hoge_controller.rb
RuboCop version
Note
If a line in the controller was
before_action :foo, except: %I[index show]
(not%I
, but%i
), behavior is expected.The text was updated successfully, but these errors were encountered: