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

Support Ruby 2.7's pattern matching for Layout/SpaceAroundKeyword #9841

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
* [#9841](https://github.com/rubocop/rubocop/pull/9841): Support guard `if` and `unless` syntax keywords of Ruby 2.7's pattern matching for `Layout/SpaceAroundKeyword`. ([@koic][])
8 changes: 8 additions & 0 deletions lib/rubocop/cop/layout/space_around_keyword.rb
Expand Up @@ -69,6 +69,10 @@ def on_if(node)
check(node, %i[keyword else begin end].freeze, 'then')
end

def on_if_guard(node)
check(node, [:keyword].freeze)
end

def on_in_pattern(node)
check(node, [:keyword].freeze)
end
Expand Down Expand Up @@ -117,6 +121,10 @@ def on_zsuper(node)
check(node, [:keyword].freeze)
end

def on_unless_guard(node)
check(node, [:keyword].freeze)
end

def on_until(node)
check(node, %i[begin end keyword].freeze)
end
Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/cop/layout/space_around_keyword_spec.rb
Expand Up @@ -84,6 +84,15 @@
it_behaves_like 'missing before', 'else', 'case a; in b; ""else end',
'case a; in b; "" else end'
it_behaves_like 'missing after', 'else', 'case a; in b; else"" end', 'case a; in b; else "" end'

it_behaves_like 'missing before', 'if', 'case a; in "pattern"if "condition"; else "" end',
'case a; in "pattern" if "condition"; else "" end'
it_behaves_like 'missing after', 'if', 'case a; in "pattern" if"condition"; else "" end',
'case a; in "pattern" if "condition"; else "" end'
it_behaves_like 'missing before', 'unless', 'case a; in "pattern"unless "condition"; else "" end',
'case a; in "pattern" unless "condition"; else "" end'
it_behaves_like 'missing after', 'unless', 'case a; in "pattern" unless"condition"; else "" end',
'case a; in "pattern" unless "condition"; else "" end'
end

it_behaves_like 'missing before', 'elsif', 'if a; ""elsif b; end', 'if a; "" elsif b; end'
Expand Down