Skip to content

Commit

Permalink
fix assignment case in Angellist/NoUnless, update prefer date current…
Browse files Browse the repository at this point in the history
… spec
  • Loading branch information
stathis-alexander committed Oct 23, 2024
1 parent 41082b5 commit 9e8c789
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rubocop-angellist (1.0.1)
rubocop-angellist (1.0.2)
rubocop (~> 1)
rubocop-graphql
rubocop-performance
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop-angellist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# frozen_string_literal: true

require 'rubocop'
require 'sorbet-runtime'

require_relative 'rubocop/angellist'
require_relative 'rubocop/angellist/version'
Expand Down
4 changes: 3 additions & 1 deletion lib/rubocop/cop/angellist/no_unless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def on_if(node)

private

sig { params(corrector: RuboCop::Cop::Corrector, node: RuboCop::AST::IfNode).void }
sig { params(corrector: RuboCop::Cop::Corrector, node: RuboCop::AST::Node).void }
def autocorrect(corrector, node)
case node.type
when :begin
Expand All @@ -54,6 +54,8 @@ def autocorrect(corrector, node)
corrector.replace(node.loc.expression, 'false')
when :false
corrector.replace(node.loc.expression, 'true')
when :lvasgn
corrector.replace(node.loc.expression, "!(#{node.source})")
else
corrector.replace(node.loc.expression, "!#{node.source}")
end
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/angellist/no_unless_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Angellist::NoUnless, :config do
Expand Down Expand Up @@ -148,5 +149,16 @@
return if x == y
RUBY
end

it 'corrects assignments' do
expect_offense(<<~RUBY)
return unless x = y
^^^^^^^^^^^^^^^^^^^ Angellist/NoUnless: Use `if !condition` instead of `unless condition`.
RUBY

expect_correction(<<~RUBY)
return if !(x = y)
RUBY
end
end
end
11 changes: 6 additions & 5 deletions spec/rubocop/cop/angellist/prefer_date_current_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Angellist::PreferDateCurrent, :config do
Expand All @@ -6,16 +7,16 @@
# TODO: Write test code
#
# For example
it 'registers an offense when using `#bad_method`' do
it 'registers an offense when using `Time.zone.today`' do
expect_offense(<<~RUBY)
bad_method
^^^^^^^^^^ Use `#good_method` instead of `#bad_method`.
Time.zone.today
^^^^^^^^^^^^^^^ Angellist/PreferDateCurrent: Use `Date.current` instead of `Time.zone.today`.
RUBY
end

it 'does not register an offense when using `#good_method`' do
it 'does not register an offense when using `Date.current`' do
expect_no_offenses(<<~RUBY)
good_method
Date.current
RUBY
end
end

0 comments on commit 9e8c789

Please sign in to comment.