Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request rubocop#12782 from Earlopain/fix-error-for-style-a…
Browse files Browse the repository at this point in the history
…lias-spec

Fix an error for `Style/Alias` when calling `alias_method` with fewer than 2 arguments.
  • Loading branch information
koic authored Mar 12, 2024
2 parents e93a1f0 + 00c0a84 commit afddf65
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_style_alias.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12782](https://github.com/rubocop/rubocop/pull/12782): Fix an error for `Style/Alias` with `EnforcedStyle: prefer_alias` when calling `alias_method` with fewer than 2 arguments. ([@earlopain][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Alias < Base
def on_send(node)
return unless node.command?(:alias_method)
return unless style == :prefer_alias && alias_keyword_possible?(node)
return unless node.arguments.count == 2

msg = format(MSG_ALIAS_METHOD, current: lexical_scope_type(node))
add_offense(node.loc.selector, message: msg) do |corrector|
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cop/style/alias_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def foo
end
RUBY
end

it 'register an offense for alias_method when calling with no arguments' do
expect_no_offenses('alias_method')
end

it 'registers no offense for alias_method when calling with one argument' do
expect_no_offenses('alias_method :foo')
end
end

context 'when EnforcedStyle is prefer_alias' do
Expand Down Expand Up @@ -208,5 +216,13 @@ def foo
end
RUBY
end

it 'registers no offense for alias_method when calling with no arguments' do
expect_no_offenses('alias_method')
end

it 'registers no offense for alias_method when calling with one argument' do
expect_no_offenses('alias_method :foo')
end
end
end

0 comments on commit afddf65

Please sign in to comment.