mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Use square brackets for %w
and %i
array literals
This commit is contained in:
parent
06dc201344
commit
10b577d23a
27 changed files with 101 additions and 99 deletions
|
@ -6,41 +6,41 @@ module Ameba::Rule::Lint
|
|||
|
||||
it "passes if percent arrays are written correctly" do
|
||||
s = Source.new %q(
|
||||
%i(one two three)
|
||||
%w(one two three)
|
||||
%i[one two three]
|
||||
%w[one two three]
|
||||
|
||||
%i(1 2 3)
|
||||
%w(1 2 3)
|
||||
%i[1 2 3]
|
||||
%w[1 2 3]
|
||||
|
||||
%i()
|
||||
%w()
|
||||
%i[]
|
||||
%w[]
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
|
||||
it "fails if string percent array has commas" do
|
||||
s = Source.new %( %w(one, two) )
|
||||
s = Source.new %( %w[one, two] )
|
||||
subject.catch(s).should_not be_valid
|
||||
end
|
||||
|
||||
it "fails if string percent array has quotes" do
|
||||
s = Source.new %( %w("one" "two") )
|
||||
s = Source.new %( %w["one" "two"] )
|
||||
subject.catch(s).should_not be_valid
|
||||
end
|
||||
|
||||
it "fails if symbols percent array has commas" do
|
||||
s = Source.new %( %i(one, two) )
|
||||
s = Source.new %( %i[one, two] )
|
||||
subject.catch(s).should_not be_valid
|
||||
end
|
||||
|
||||
it "fails if symbols percent array has a colon" do
|
||||
s = Source.new %( %i(:one :two) )
|
||||
s = Source.new %( %i[:one :two] )
|
||||
subject.catch(s).should_not be_valid
|
||||
end
|
||||
|
||||
it "reports rule, location and message for %i" do
|
||||
s = Source.new %(
|
||||
%i(:one)
|
||||
%i[:one]
|
||||
), "source.cr"
|
||||
|
||||
subject.catch(s).should_not be_valid
|
||||
|
@ -54,7 +54,7 @@ module Ameba::Rule::Lint
|
|||
|
||||
it "reports rule, location and message for %w" do
|
||||
s = Source.new %(
|
||||
%w("one")
|
||||
%w["one"]
|
||||
), "source.cr"
|
||||
|
||||
subject.catch(s).should_not be_valid
|
||||
|
@ -71,14 +71,14 @@ module Ameba::Rule::Lint
|
|||
it "#string_array_unwanted_symbols" do
|
||||
rule = PercentArrays.new
|
||||
rule.string_array_unwanted_symbols = ","
|
||||
s = Source.new %( %w("one") )
|
||||
s = Source.new %( %w["one"] )
|
||||
rule.catch(s).should be_valid
|
||||
end
|
||||
|
||||
it "#symbol_array_unwanted_symbols" do
|
||||
rule = PercentArrays.new
|
||||
rule.symbol_array_unwanted_symbols = ","
|
||||
s = Source.new %( %i(:one) )
|
||||
s = Source.new %( %i[:one] )
|
||||
rule.catch(s).should be_valid
|
||||
end
|
||||
end
|
||||
|
|
|
@ -977,7 +977,7 @@ module Ameba::Rule::Lint
|
|||
s = Source.new %(
|
||||
foo = 22
|
||||
|
||||
{% for x in %w(foo) %}
|
||||
{% for x in %w[foo] %}
|
||||
add({{ x.id }})
|
||||
{% end %}
|
||||
)
|
||||
|
@ -988,7 +988,7 @@ module Ameba::Rule::Lint
|
|||
s = Source.new %(
|
||||
foo = 22
|
||||
|
||||
{% for x in %w(bar) %}
|
||||
{% for x in %w[bar] %}
|
||||
puts {{ "foo".id }}
|
||||
{% end %}
|
||||
)
|
||||
|
|
|
@ -48,7 +48,7 @@ module Ameba::Rule::Performance
|
|||
context "properties" do
|
||||
it "#filter_names" do
|
||||
rule = AnyAfterFilter.new
|
||||
rule.filter_names = %w(select)
|
||||
rule.filter_names = %w[select]
|
||||
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
[1, 2, 3].reject { |e| e > 2 }.any?
|
||||
|
|
|
@ -46,7 +46,7 @@ module Ameba::Rule::Performance
|
|||
context "properties" do
|
||||
it "#call_names" do
|
||||
rule = ChainedCallWithNoBang.new
|
||||
rule.call_names = %w(uniq)
|
||||
rule.call_names = %w[uniq]
|
||||
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
[1, 2, 3].select { |e| e > 2 }.reverse
|
||||
|
|
|
@ -64,7 +64,7 @@ module Ameba::Rule::Performance
|
|||
context "properties" do
|
||||
it "#filter_names" do
|
||||
rule = FirstLastAfterFilter.new
|
||||
rule.filter_names = %w(reject)
|
||||
rule.filter_names = %w[reject]
|
||||
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
[1, 2, 3].select { |e| e > 2 }.first
|
||||
|
|
|
@ -46,7 +46,7 @@ module Ameba::Rule::Performance
|
|||
context "properties" do
|
||||
it "#filter_names" do
|
||||
rule = SizeAfterFilter.new
|
||||
rule.filter_names = %w(select)
|
||||
rule.filter_names = %w[select]
|
||||
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
[1, 2, 3].reject(&.empty?).size
|
||||
|
|
|
@ -44,7 +44,7 @@ module Ameba::Rule::Style
|
|||
context "properties" do
|
||||
it "#filter_names" do
|
||||
rule = IsAFilter.new
|
||||
rule.filter_names = %w(select)
|
||||
rule.filter_names = %w[select]
|
||||
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
[1, 2, nil].reject(&.nil?)
|
||||
|
|
|
@ -4,7 +4,7 @@ module Ameba::Rule::Style
|
|||
subject = ParenthesesAroundCondition.new
|
||||
|
||||
describe ParenthesesAroundCondition do
|
||||
{% for keyword in %w(if unless while until) %}
|
||||
{% for keyword in %w[if unless while until] %}
|
||||
context "{{ keyword.id }}" do
|
||||
it "reports if redundant parentheses are found" do
|
||||
source = expect_issue subject, <<-CRYSTAL, keyword: {{ keyword }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue