-
-
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
NodePattern: Add <> for matching children in any order. #6965
Conversation
…rder. These can be used multiple times in the same sequence as well as nested. Limitations: A sequence can only contain a single ellipsis (contained or not within a <> sequence). Other implementation changes: - Captures are now an array (e.g. `capture0` is now `captures[0]`) - Temporary variables like `temp1` were renamed to `node1`. - Reading tokens until a delimiter was factorized into `tokens_until`
Fixed a few small things and even found a strange JRuby bug, all green now. |
Fantastic work, @marcandre! |
Follow up rubocop/rubocop#6965. This PR fixes a false negartive for `Performance/RegexpMatch` when using RuboCop 0.68 or higher. ```ruby # example.rb def foo if /re/.match(foo, 1) do_something end end ``` ## RuboCop 0.67 RuboCop 0.67 warns. ```console % rubocop _0.67.2_ --only Performance/RegexpMatch Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` ## RuboCop 0.68 (Before) RuboCop 0.68 does not warn. This is a false negative. ```console % rubocop _0.68.1_ --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file . 1 file inspected, no offenses detected ``` ## RuboCop 0.68 (After) This PR fixes a false negative. ```console % rubocop --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` This fix uses the following `<>` node pattern notation introduced in RuboCop 0.68, so it supports Ruby version 0.68 or higher. rubocop/rubocop#6965
Follow up rubocop/rubocop#6965. This PR fixes a false negartive for `Performance/RegexpMatch` when using RuboCop 0.68 or higher. ```ruby # example.rb def foo if /re/.match(foo, 1) do_something end end ``` ## RuboCop 0.67 RuboCop 0.67 warns. ```console % rubocop _0.67.2_ --only Performance/RegexpMatch Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` ## RuboCop 0.68 (Before) RuboCop 0.68 does not warn. This is a false negative. ```console % rubocop _0.68.1_ --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file . 1 file inspected, no offenses detected ``` ## RuboCop 0.68 (After) This PR fixes a false negative. ```console % rubocop --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` This fix uses the following `<>` node pattern notation introduced in RuboCop 0.68, so it supports Ruby version 0.68 or higher. rubocop/rubocop#6965
Follow up rubocop/rubocop#6965. This PR fixes a false negartive for `Performance/RegexpMatch` when using RuboCop 0.68 or higher. ```ruby # example.rb def foo if /re/.match(foo, 1) do_something end end ``` ## RuboCop 0.67 RuboCop 0.67 warns. ```console % rubocop _0.67.2_ --only Performance/RegexpMatch Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` ## RuboCop 0.68 (Before) RuboCop 0.68 does not warn. This is a false negative. ```console % rubocop _0.68.1_ --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file . 1 file inspected, no offenses detected ``` ## RuboCop 0.68 (After) This PR fixes a false negative. ```console % rubocop --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` This fix uses the following `<>` node pattern notation introduced in RuboCop 0.68, so it supports Ruby version 0.68 or higher. rubocop/rubocop#6965
Please correct me if I'm mistaken, but it seems there's a minor mistake in the description:
should probably be:
|
@pirj Both are valid and should give you similar results. Using |
PS: I believe you are right though that |
0.68.0 ships with hash children matching (rubocop/rubocop#6965) that might come handy for some of RSpec cops.
0.68.0 ships with the new children matching syntax (rubocop/rubocop#6965) that might come handy for some of RSpec cops.
What makes this change double as awesome is that it also works for matching arguments, not only in a hash. 💯 |
0.68.0 ships with the new children matching syntax (rubocop/rubocop#6965) that might come handy for some of RSpec cops.
0.68.0 ships with the new children matching syntax (rubocop/rubocop#6965) that might come handy for some of RSpec cops.
0.68.0 ships with the new children matching syntax (rubocop/rubocop#6965) that might come handy for some of RSpec cops.
Follow up rubocop/rubocop#6965. This PR fixes a false negartive for `Performance/RegexpMatch` when using RuboCop 0.68 or higher. ```ruby # example.rb def foo if /re/.match(foo, 1) do_something end end ``` ## RuboCop 0.67 RuboCop 0.67 warns. ```console % rubocop _0.67.2_ --only Performance/RegexpMatch Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` ## RuboCop 0.68 (Before) RuboCop 0.68 does not warn. This is a false negative. ```console % rubocop _0.68.1_ --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file . 1 file inspected, no offenses detected ``` ## RuboCop 0.68 (After) This PR fixes a false negative. ```console % rubocop --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` This fix uses the following `<>` node pattern notation introduced in RuboCop 0.68, so it supports Ruby version 0.68 or higher. rubocop/rubocop#6965
Follow up rubocop/rubocop#6965. This PR fixes a false negartive for `Performance/RegexpMatch` when using RuboCop 0.68 or higher. ```ruby # example.rb def foo if /re/.match(foo, 1) do_something end end ``` ## RuboCop 0.67 RuboCop 0.67 warns. ```console % rubocop _0.67.2_ --only Performance/RegexpMatch Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` ## RuboCop 0.68 (Before) RuboCop 0.68 does not warn. This is a false negative. ```console % rubocop _0.68.1_ --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file . 1 file inspected, no offenses detected ``` ## RuboCop 0.68 (After) This PR fixes a false negative. ```console % rubocop --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` This fix uses the following `<>` node pattern notation introduced in RuboCop 0.68, so it supports Ruby version 0.68 or higher. rubocop/rubocop#6965
0.68.0 ships with the new children matching syntax (rubocop/rubocop#6965) that might come handy for some of RSpec cops.
0.68.0 ships with the new children matching syntax (rubocop/rubocop#6965) that might come handy for some of RSpec cops.
Follow up rubocop/rubocop#6965. This PR fixes a false negartive for `Performance/RegexpMatch` when using RuboCop 0.68 or higher. ```ruby # example.rb def foo if /re/.match(foo, 1) do_something end end ``` ## RuboCop 0.67 RuboCop 0.67 warns. ```console % rubocop _0.67.2_ --only Performance/RegexpMatch Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` ## RuboCop 0.68 (Before) RuboCop 0.68 does not warn. This is a false negative. ```console % rubocop _0.68.1_ --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file . 1 file inspected, no offenses detected ``` ## RuboCop 0.68 (After) This PR fixes a false negative. ```console % rubocop --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` This fix uses the following `<>` node pattern notation introduced in RuboCop 0.68, so it supports Ruby version 0.68 or higher. rubocop/rubocop#6965
Follow up rubocop/rubocop#6965. This PR fixes a false negartive for `Performance/RegexpMatch` when using RuboCop 0.68 or higher. ```ruby # example.rb def foo if /re/.match(foo, 1) do_something end end ``` ## RuboCop 0.67 RuboCop 0.67 warns. ```console % rubocop _0.67.2_ --only Performance/RegexpMatch Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` ## RuboCop 0.68 (Before) RuboCop 0.68 does not warn. This is a false negative. ```console % rubocop _0.68.1_ --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file . 1 file inspected, no offenses detected ``` ## RuboCop 0.68 (After) This PR fixes a false negative. ```console % rubocop --only Performance/RegexpMatch --require rubocop-performance Inspecting 1 file C Offenses: example.rb:2:6: C: Performance/RegexpMatch: Use match? instead of match when MatchData is not used. if /re/.match(foo, 1) ^^^^^^^^^^^^^^^^^^ 1 file inspected, 1 offense detected ``` This fix uses the following `<>` node pattern notation introduced in RuboCop 0.68, so it supports Ruby version 0.68 or higher. rubocop/rubocop#6965
0.68.0 ships with the new children matching syntax (rubocop/rubocop#6965) that might come handy for some of RSpec cops.
0.68.0 ships with the new children matching syntax (rubocop/rubocop#6965) that might come handy for some of RSpec cops.
These can be used multiple times in the same sequence as well as
nested.
Limitations: A sequence can only contain a single ellipsis (contained
or not within a <> sequence).
Other implementation changes:
capture0
is nowcaptures[0]
)temp1
were renamed tonode1
.tokens_until
Example of produced code:
Fixes #6841