-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ef1ce49
commit dbc8a91
Showing
7 changed files
with
91 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module SalsifyRubocop | ||
VERSION = '1.59.1' | ||
VERSION = '1.68.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
describe RuboCop::Cop::Salsify::RailsUnscoped, :config do | ||
let(:msgs) { [described_class::MSG] } | ||
|
||
subject(:cop) { described_class.new(config) } | ||
|
||
it "accepts scopes without `unscoped`" do | ||
source = 'User.where(foo: bar)' | ||
inspect_source(source) | ||
expect(cop.offenses).to be_empty | ||
expect_no_offenses('User.where(foo: bar)') | ||
end | ||
|
||
it "detects `unscoped` in scope with explicit model" do | ||
source = 'User.where(foo: bar).unscoped' | ||
inspect_source(source) | ||
expect(cop.highlights).to eq([source]) | ||
expect(cop.messages).to match_array(msgs) | ||
expect_offense(<<~RUBY) | ||
User.where(foo: bar).unscoped | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Explicitly remove scopes instead of using `unscoped`. | ||
RUBY | ||
end | ||
|
||
it "detects `unscoped` in scope with implicit model" do | ||
source = 'where(foo: bar).unscoped' | ||
inspect_source(source) | ||
expect(cop.highlights).to eq([source]) | ||
expect(cop.messages).to match_array(msgs) | ||
expect_offense(<<~RUBY) | ||
where(foo: bar).unscoped | ||
^^^^^^^^^^^^^^^^^^^^^^^^ Explicitly remove scopes instead of using `unscoped`. | ||
RUBY | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,121 @@ | ||
# frozen_string_literal: true | ||
|
||
describe RuboCop::Cop::Salsify::StyleDig, :config do | ||
let(:ruby_version) { 2.4 } | ||
let(:msgs) { [described_class::MSG] } | ||
include RuboCop::RSpec::ExpectOffense | ||
|
||
subject(:cop) { described_class.new(config) } | ||
|
||
it "accepts non-nested access" do | ||
source = 'ary[0]' | ||
inspect_source(source) | ||
expect(cop.offenses).to be_empty | ||
expect_no_offenses('ary[0]') | ||
end | ||
|
||
it "corrects nested access" do | ||
source = 'hash[one][two]' | ||
inspect_source(source) | ||
expect(cop.highlights).to eq([source]) | ||
expect(cop.messages).to match_array(msgs) | ||
expect(autocorrect_source(source)).to eq('hash.dig(one, two)') | ||
expect_offense(<<~RUBY) | ||
hash[one][two] | ||
^^^^^^^^^^^^^^ Use `dig` for nested access. | ||
RUBY | ||
expect_correction(<<~RUBY) | ||
hash.dig(one, two) | ||
RUBY | ||
end | ||
|
||
it "corrects triple-nested access" do | ||
source = 'hash[one][two][three]' | ||
inspect_source(source) | ||
expect(cop.highlights).to eq([source]) | ||
expect(cop.messages).to match_array(msgs) | ||
expect(autocorrect_source(source)).to eq('hash.dig(one, two, three)') | ||
expect_offense(<<~RUBY) | ||
hash[one][two][three] | ||
^^^^^^^^^^^^^^^^^^^^^ Use `dig` for nested access. | ||
RUBY | ||
expect_correction(<<~RUBY) | ||
hash.dig(one, two, three) | ||
RUBY | ||
end | ||
|
||
it "corrects nested access after a method call" do | ||
source = 'obj.hash[:one][:two]' | ||
inspect_source(source) | ||
expect(cop.highlights).to eq([source]) | ||
expect(cop.messages).to match_array(msgs) | ||
expect(autocorrect_source(source)).to eq('obj.hash.dig(:one, :two)') | ||
expect_offense(<<~RUBY) | ||
obj.hash[:one][:two] | ||
^^^^^^^^^^^^^^^^^^^^ Use `dig` for nested access. | ||
RUBY | ||
expect_correction(<<~RUBY) | ||
obj.hash.dig(:one, :two) | ||
RUBY | ||
end | ||
|
||
it "corrects nested access for a method arg" do | ||
source = 'call(array[0][1])' | ||
inspect_source(source) | ||
expect(cop.highlights).to eq(['array[0][1]']) | ||
expect(cop.messages).to match_array(msgs) | ||
expect(autocorrect_source(source)).to eq('call(array.dig(0, 1))') | ||
expect_offense(<<~RUBY) | ||
call(array[0][1]) | ||
^^^^^^^^^^^ Use `dig` for nested access. | ||
RUBY | ||
expect_correction(<<~RUBY) | ||
call(array.dig(0, 1)) | ||
RUBY | ||
end | ||
|
||
it "corrects when a method is called after nested access" do | ||
source = 'hash[one][two].foo' | ||
inspect_source(source) | ||
expect(cop.highlights).to eq(['hash[one][two]']) | ||
expect(cop.messages).to match_array(msgs) | ||
expect(autocorrect_source(source)).to eq('hash.dig(one, two).foo') | ||
expect_offense(<<~RUBY) | ||
hash[one][two].foo | ||
^^^^^^^^^^^^^^ Use `dig` for nested access. | ||
RUBY | ||
expect_correction(<<~RUBY) | ||
hash.dig(one, two).foo | ||
RUBY | ||
end | ||
|
||
it "accepts nested access on conditional assignment" do | ||
source = 'foo[bar][baz] ||= 1' | ||
inspect_source(source) | ||
expect(cop.offenses).to be_empty | ||
expect_no_offenses('foo[bar][baz] ||= 1') | ||
end | ||
|
||
it "corrects nested access in the value for conditional assignment" do | ||
source = 'blah ||= foo[bar][baz]' | ||
inspect_source(source) | ||
expect(cop.highlights).to eq(['foo[bar][baz]']) | ||
expect(cop.messages).to match_array(msgs) | ||
expect(autocorrect_source(source)).to eq('blah ||= foo.dig(bar, baz)') | ||
expect_offense(<<~RUBY) | ||
blah ||= hash[one][two] | ||
^^^^^^^^^^^^^^ Use `dig` for nested access. | ||
RUBY | ||
expect_correction(<<~RUBY) | ||
blah ||= hash.dig(one, two) | ||
RUBY | ||
end | ||
|
||
it "accepts nested access for increment" do | ||
source = 'foo[bar][baz] += 1' | ||
inspect_source(source) | ||
expect(cop.offenses).to be_empty | ||
expect_no_offenses('foo[bar][baz] += 1') | ||
end | ||
|
||
it "accepts nested access for assignment" do | ||
source = 'foo[bar][baz] = 0' | ||
inspect_source(source) | ||
expect(cop.offenses).to be_empty | ||
expect_no_offenses('foo[bar][baz] = 0') | ||
end | ||
|
||
it "corrects nested access with append" do | ||
source = 'foo[bar][baz] << 1' | ||
inspect_source(source) | ||
expect(cop.highlights).to match_array(['foo[bar][baz]']) | ||
expect(cop.messages).to match_array(msgs) | ||
expect(autocorrect_source(source)).to eq('foo.dig(bar, baz) << 1') | ||
expect_offense(<<~RUBY) | ||
foo[bar][baz] << 1 | ||
^^^^^^^^^^^^^ Use `dig` for nested access. | ||
RUBY | ||
expect_correction(<<~RUBY) | ||
foo.dig(bar, baz) << 1 | ||
RUBY | ||
end | ||
|
||
it "accepts nested access that uses an inclusive range" do | ||
source = 'foo[bar][0..2]' | ||
inspect_source(source) | ||
expect(cop.offenses).to be_empty | ||
expect_no_offenses('foo[bar][0..2]') | ||
end | ||
|
||
it "accepts nested access that uses an exclusive range" do | ||
source = 'foo[bar][0...2]' | ||
inspect_source(source) | ||
expect(cop.offenses).to be_empty | ||
expect_no_offenses('foo[bar][0...2]') | ||
end | ||
|
||
it "corrects nested access before the use of an inclusive range" do | ||
source = 'foo[bar][baz][0..2]' | ||
inspect_source(source) | ||
expect(cop.messages).to match_array(msgs) | ||
expect(autocorrect_source(source)).to eq('foo.dig(bar, baz)[0..2]') | ||
expect_offense(<<~RUBY) | ||
foo[bar][baz][0..2] | ||
^^^^^^^^^^^^^ Use `dig` for nested access. | ||
RUBY | ||
expect_correction(<<~RUBY) | ||
foo.dig(bar, baz)[0..2] | ||
RUBY | ||
end | ||
|
||
it "corrects nested access before the use of an exclusive range" do | ||
source = 'foo[bar][baz][0...2]' | ||
inspect_source(source) | ||
expect(cop.messages).to match_array(msgs) | ||
expect(autocorrect_source(source)).to eq('foo.dig(bar, baz)[0...2]') | ||
expect_offense(<<~RUBY) | ||
foo[bar][baz][0...2] | ||
^^^^^^^^^^^^^ Use `dig` for nested access. | ||
RUBY | ||
expect_correction(<<~RUBY) | ||
foo.dig(bar, baz)[0...2] | ||
RUBY | ||
end | ||
end |