mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Rename Error to Issue
This commit is contained in:
parent
e1b51f62a5
commit
f8d14d4222
81 changed files with 475 additions and 384 deletions
|
@ -66,10 +66,10 @@ module Ameba::Rule
|
|||
source = Source.new "a != true", "source.cr"
|
||||
subject.catch(source)
|
||||
|
||||
error = source.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:1:1"
|
||||
error.message.should eq "Comparison to a boolean is pointless"
|
||||
issue = source.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:1:1"
|
||||
issue.message.should eq "Comparison to a boolean is pointless"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -103,10 +103,10 @@ module Ameba::Rule
|
|||
source = Source.new "true != a", "source.cr"
|
||||
subject.catch(source).should_not be_valid
|
||||
|
||||
error = source.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:1:1"
|
||||
error.message.should eq "Comparison to a boolean is pointless"
|
||||
issue = source.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:1:1"
|
||||
issue.message.should eq "Comparison to a boolean is pointless"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module Ameba
|
|||
it "reports constant name #{expected}" do
|
||||
s = Source.new code
|
||||
Rule::ConstantNames.new.catch(s).should_not be_valid
|
||||
s.errors.first.message.should contain expected
|
||||
s.issues.first.message.should contain expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -40,10 +40,10 @@ module Ameba
|
|||
Const = 1
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:9"
|
||||
error.message.should eq(
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:9"
|
||||
issue.message.should eq(
|
||||
"Constant name should be screaming-cased: CONST, not Const"
|
||||
)
|
||||
end
|
||||
|
|
|
@ -35,10 +35,10 @@ module Ameba::Rule
|
|||
s = Source.new "debugger", "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:1:1"
|
||||
error.message.should eq "Possible forgotten debugger statement detected"
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:1:1"
|
||||
issue.message.should eq "Possible forgotten debugger statement detected"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -58,11 +58,11 @@ module Ameba::Rule
|
|||
end
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
issue = s.issues.first
|
||||
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:3:11"
|
||||
error.message.should eq "Empty `ensure` block detected"
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:3:11"
|
||||
issue.message.should eq "Empty `ensure` block detected"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -101,10 +101,10 @@ module Ameba
|
|||
end
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:12"
|
||||
error.message.should eq "Avoid empty expressions"
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:12"
|
||||
issue.message.should eq "Avoid empty expressions"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,10 +32,10 @@ module Ameba::Rule
|
|||
h = {"a" => 1, "a" => 2}
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:13"
|
||||
error.message.should eq %(Duplicated keys in hash literal: "a")
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:13"
|
||||
issue.message.should eq %(Duplicated keys in hash literal: "a")
|
||||
end
|
||||
|
||||
it "reports multiple duplicated keys" do
|
||||
|
@ -43,8 +43,8 @@ module Ameba::Rule
|
|||
h = {"key1" => 1, "key1" => 2, "key2" => 3, "key2" => 4}
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.message.should eq %(Duplicated keys in hash literal: "key1", "key2")
|
||||
issue = s.issues.first
|
||||
issue.message.should eq %(Duplicated keys in hash literal: "key1", "key2")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module Ameba
|
|||
it "transforms large number #{number}" do
|
||||
s = Source.new number
|
||||
Rule::LargeNumbers.new.catch(s).should_not be_valid
|
||||
s.errors.first.message.should contain expected
|
||||
s.issues.first.message.should contain expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -115,10 +115,10 @@ module Ameba
|
|||
1200000
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:10"
|
||||
error.message.should match /1_200_000/
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:10"
|
||||
issue.message.should match /1_200_000/
|
||||
end
|
||||
|
||||
context "properties" do
|
||||
|
|
|
@ -24,10 +24,10 @@ module Ameba::Rule
|
|||
source = Source.new long_line, "source.cr"
|
||||
subject.catch(source).should_not be_valid
|
||||
|
||||
error = source.errors.first
|
||||
error.rule.should eq subject
|
||||
error.location.to_s.should eq "source.cr:1:81"
|
||||
error.message.should eq "Line too long"
|
||||
issue = source.issues.first
|
||||
issue.rule.should eq subject
|
||||
issue.location.to_s.should eq "source.cr:1:81"
|
||||
issue.message.should eq "Line too long"
|
||||
end
|
||||
|
||||
context "properties" do
|
||||
|
|
|
@ -62,11 +62,11 @@ module Ameba::Rule
|
|||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
s.errors.size.should eq 1
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:9"
|
||||
error.message.should eq "Literal value found in conditional"
|
||||
s.issues.size.should eq 1
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:9"
|
||||
issue.message.should eq "Literal value found in conditional"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,10 +32,10 @@ module Ameba::Rule
|
|||
s = Source.new %q("#{4}"), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:1:1"
|
||||
error.message.should eq "Literal value found in interpolation"
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:1:1"
|
||||
issue.message.should eq "Literal value found in interpolation"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module Ameba
|
|||
it "reports method name #{expected}" do
|
||||
s = Source.new code
|
||||
Rule::MethodNames.new.catch(s).should_not be_valid
|
||||
s.errors.first.message.should contain expected
|
||||
s.issues.first.message.should contain expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -44,10 +44,10 @@ module Ameba
|
|||
end
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:9"
|
||||
error.message.should eq(
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:9"
|
||||
issue.message.should eq(
|
||||
"Method name should be underscore-cased: bad_name, not bad_Name"
|
||||
)
|
||||
end
|
||||
|
|
|
@ -59,10 +59,10 @@ module Ameba::Rule
|
|||
s = Source.new ":nok unless !s.empty?", "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:1:1"
|
||||
error.message.should eq "Avoid negated conditions in unless blocks"
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:1:1"
|
||||
issue.message.should eq "Avoid negated conditions in unless blocks"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,10 +44,10 @@ module Ameba::Rule
|
|||
), "source.cr"
|
||||
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:9"
|
||||
error.message.should eq(
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:9"
|
||||
issue.message.should eq(
|
||||
"Symbols `,:` may be unwanted in %i array literals"
|
||||
)
|
||||
end
|
||||
|
@ -58,10 +58,10 @@ module Ameba::Rule
|
|||
), "source.cr"
|
||||
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:9"
|
||||
error.message.should eq(
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:9"
|
||||
issue.message.should eq(
|
||||
"Symbols `,\"` may be unwanted in %w array literals"
|
||||
)
|
||||
end
|
||||
|
|
|
@ -38,10 +38,10 @@ module Ameba::Rule
|
|||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:3:11"
|
||||
error.message.should eq(
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:3:11"
|
||||
issue.message.should eq(
|
||||
"Favour method name 'picture?' over 'has_picture?'")
|
||||
end
|
||||
|
||||
|
|
|
@ -26,11 +26,11 @@ module Ameba::Rule
|
|||
it "reports rule, location and a message" do
|
||||
s = Source.new "rand(1)", "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
issue = s.issues.first
|
||||
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:1:1"
|
||||
error.message.should eq "rand(1) always returns 0"
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:1:1"
|
||||
issue.message.should eq "rand(1) always returns 0"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -204,10 +204,10 @@ module Ameba::Rule
|
|||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:9"
|
||||
error.message.should eq "Redundant `begin` block detected"
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:9"
|
||||
issue.message.should eq "Redundant `begin` block detected"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -156,10 +156,10 @@ module Ameba::Rule
|
|||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:3:11"
|
||||
error.message.should eq "Argument `bar` is assigned before it is used"
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:3:11"
|
||||
issue.message.should eq "Argument `bar` is assigned before it is used"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require "../../spec_helper"
|
|||
private def check_shadowed(source, exceptions)
|
||||
s = Ameba::Source.new source
|
||||
Ameba::Rule::ShadowedException.new.catch(s).should_not be_valid
|
||||
s.errors.first.message.should contain exceptions.join(", ")
|
||||
s.issues.first.message.should contain exceptions.join(", ")
|
||||
end
|
||||
|
||||
module Ameba::Rule
|
||||
|
@ -163,11 +163,11 @@ module Ameba::Rule
|
|||
end
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
issue = s.issues.first
|
||||
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:3:11"
|
||||
error.message.should eq(
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:3:11"
|
||||
issue.message.should eq(
|
||||
"Exception handler has shadowed exceptions: IndexError"
|
||||
)
|
||||
end
|
||||
|
|
|
@ -68,7 +68,7 @@ module Ameba::Rule
|
|||
)
|
||||
subject.catch(source).should_not be_valid
|
||||
|
||||
source.errors.size.should eq 2
|
||||
source.issues.size.should eq 2
|
||||
end
|
||||
|
||||
it "reports if a splat block argument shadows local var" do
|
||||
|
@ -89,7 +89,7 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(source).should_not be_valid
|
||||
source.errors.first.message.should eq "Shadowing outer local variable `block`"
|
||||
source.issues.first.message.should eq "Shadowing outer local variable `block`"
|
||||
end
|
||||
|
||||
it "reports if there are multiple args and one shadows local var" do
|
||||
|
@ -100,7 +100,7 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(source).should_not be_valid
|
||||
source.errors.first.message.should eq "Shadowing outer local variable `foo`"
|
||||
source.issues.first.message.should eq "Shadowing outer local variable `foo`"
|
||||
end
|
||||
|
||||
it "doesn't report if an outer var is reassigned in a block" do
|
||||
|
@ -131,10 +131,10 @@ module Ameba::Rule
|
|||
), "source.cr"
|
||||
subject.catch(source).should_not be_valid
|
||||
|
||||
error = source.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:3:20"
|
||||
error.message.should eq "Shadowing outer local variable `foo`"
|
||||
issue = source.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:3:20"
|
||||
issue.message.should eq "Shadowing outer local variable `foo`"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,11 +27,11 @@ module Ameba::Rule
|
|||
it "reports rule, location and message" do
|
||||
s = Source.new "def hello end", "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
issue = s.issues.first
|
||||
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:1:11"
|
||||
error.message.should eq "unexpected token: end (expected ';' or newline)"
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:1:11"
|
||||
issue.message.should eq "unexpected token: end (expected ';' or newline)"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,10 +28,10 @@ module Ameba::Rule
|
|||
source = Source.new "a = 1\n\n ", "source.cr"
|
||||
subject.catch(source).should_not be_valid
|
||||
|
||||
error = source.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:3:1"
|
||||
error.message.should eq "Blank lines detected at the end of the file"
|
||||
issue = source.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:3:1"
|
||||
issue.message.should eq "Blank lines detected at the end of the file"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,10 +18,10 @@ module Ameba::Rule
|
|||
source = Source.new "a = 1\n b = 2 ", "source.cr"
|
||||
subject.catch(source).should_not be_valid
|
||||
|
||||
error = source.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:7"
|
||||
error.message.should eq "Trailing whitespace detected"
|
||||
issue = source.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:7"
|
||||
issue.message.should eq "Trailing whitespace detected"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module Ameba
|
|||
it "reports type name #{expected}" do
|
||||
s = Source.new code
|
||||
Rule::TypeNames.new.catch(s).should_not be_valid
|
||||
s.errors.first.message.should contain expected
|
||||
s.issues.first.message.should contain expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,10 +49,10 @@ module Ameba
|
|||
end
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:9"
|
||||
error.message.should eq(
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:9"
|
||||
issue.message.should eq(
|
||||
"Type name should be camelcased: MyClass, but it was My_class"
|
||||
)
|
||||
end
|
||||
|
|
|
@ -34,11 +34,11 @@ module Ameba::Rule
|
|||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
error = s.errors.first
|
||||
error.should_not be_nil
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:9"
|
||||
error.message.should eq "Favour if over unless with else"
|
||||
issue = s.issues.first
|
||||
issue.should_not be_nil
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:9"
|
||||
issue.message.should eq "Favour if over unless with else"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,8 @@ module Ameba::Rule
|
|||
# ameba:disable #{NamedRule.name}
|
||||
a = 1
|
||||
)
|
||||
s.error NamedRule.new, 3, 9, "Useless assignment", :disabled
|
||||
s.add_issue NamedRule.new, location: {3, 9},
|
||||
message: "Useless assignment", status: :disabled
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
|
||||
|
@ -31,7 +32,8 @@ module Ameba::Rule
|
|||
s = Source.new %Q(
|
||||
a = 1 # ameba:disable #{NamedRule.name}
|
||||
)
|
||||
s.error NamedRule.new, 2, 1, "Alarm!", :disabled
|
||||
s.add_issue NamedRule.new, location: {2, 1},
|
||||
message: "Alarm!", status: :disabled
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
|
||||
|
@ -40,7 +42,8 @@ module Ameba::Rule
|
|||
# # ameba:disable #{NamedRule.name}
|
||||
a = 1
|
||||
)
|
||||
s.error NamedRule.new, 3, 1, "Alarm!", :disabled
|
||||
s.add_issue NamedRule.new, location: {3, 1},
|
||||
message: "Alarm!", status: :disabled
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
|
||||
|
@ -50,7 +53,7 @@ module Ameba::Rule
|
|||
a = 1
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.first.message.should eq(
|
||||
s.issues.first.message.should eq(
|
||||
"Unnecessary disabling of #{NamedRule.name}"
|
||||
)
|
||||
end
|
||||
|
@ -58,7 +61,7 @@ module Ameba::Rule
|
|||
it "fails if there is inline unneeded directive" do
|
||||
s = Source.new %Q(a = 1 # ameba:disable #{NamedRule.name})
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.first.message.should eq(
|
||||
s.issues.first.message.should eq(
|
||||
"Unnecessary disabling of #{NamedRule.name}"
|
||||
)
|
||||
end
|
||||
|
@ -69,9 +72,9 @@ module Ameba::Rule
|
|||
a = 1 # ameba:disable Rule3
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.size.should eq 2
|
||||
s.errors.first.message.should contain "Rule1, Rule2"
|
||||
s.errors.last.message.should contain "Rule3"
|
||||
s.issues.size.should eq 2
|
||||
s.issues.first.message.should contain "Rule1, Rule2"
|
||||
s.issues.last.message.should contain "Rule3"
|
||||
end
|
||||
|
||||
it "fails if there is disabled UnneededDisableDirective" do
|
||||
|
@ -79,20 +82,21 @@ module Ameba::Rule
|
|||
# ameba:disable #{UnneededDisableDirective.rule_name}
|
||||
a = 1
|
||||
), "source.cr"
|
||||
s.error UnneededDisableDirective.new, 3, 1, "Alarm!", :disabled
|
||||
s.add_issue UnneededDisableDirective.new, location: {3, 1},
|
||||
message: "Alarm!", status: :disabled
|
||||
subject.catch(s).should_not be_valid
|
||||
end
|
||||
|
||||
it "reports error, location and message" do
|
||||
it "reports issue, location and message" do
|
||||
s = Source.new %Q(
|
||||
# ameba:disable Rule1, Rule2
|
||||
a = 1
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:9"
|
||||
error.message.should eq "Unnecessary disabling of Rule1, Rule2"
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:9"
|
||||
issue.message.should eq "Unnecessary disabling of Rule1, Rule2"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.first.message.should eq "Unused argument `c`. If it's necessary, use `_c` " \
|
||||
s.issues.first.message.should eq "Unused argument `c`. If it's necessary, use `_c` " \
|
||||
"as an argument name to indicate that it won't be used."
|
||||
end
|
||||
|
||||
|
@ -38,7 +38,7 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.first.message.should eq "Unused argument `i`. If it's necessary, use `_` " \
|
||||
s.issues.first.message.should eq "Unused argument `i`. If it's necessary, use `_` " \
|
||||
"as an argument name to indicate that it won't be used."
|
||||
end
|
||||
|
||||
|
@ -49,7 +49,7 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.first.message.should eq "Unused argument `b`. If it's necessary, use `_b` " \
|
||||
s.issues.first.message.should eq "Unused argument `b`. If it's necessary, use `_b` " \
|
||||
"as an argument name to indicate that it won't be used."
|
||||
end
|
||||
|
||||
|
@ -60,11 +60,11 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors[0].message.should eq "Unused argument `a`. If it's necessary, use `_a` " \
|
||||
s.issues[0].message.should eq "Unused argument `a`. If it's necessary, use `_a` " \
|
||||
"as an argument name to indicate that it won't be used."
|
||||
s.errors[1].message.should eq "Unused argument `b`. If it's necessary, use `_b` " \
|
||||
s.issues[1].message.should eq "Unused argument `b`. If it's necessary, use `_b` " \
|
||||
"as an argument name to indicate that it won't be used."
|
||||
s.errors[2].message.should eq "Unused argument `c`. If it's necessary, use `_c` " \
|
||||
s.issues[2].message.should eq "Unused argument `c`. If it's necessary, use `_c` " \
|
||||
"as an argument name to indicate that it won't be used."
|
||||
end
|
||||
|
||||
|
@ -164,7 +164,7 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.first.message.should eq "Unused argument `b`. If it's necessary, use `_b` " \
|
||||
s.issues.first.message.should eq "Unused argument `b`. If it's necessary, use `_b` " \
|
||||
"as an argument name to indicate that it won't be used."
|
||||
end
|
||||
|
||||
|
@ -174,11 +174,11 @@ module Ameba::Rule
|
|||
end
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.message.should eq "Unused argument `a`. If it's necessary, use `_a` " \
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.message.should eq "Unused argument `a`. If it's necessary, use `_a` " \
|
||||
"as an argument name to indicate that it won't be used."
|
||||
error.location.to_s.should eq "source.cr:2:22"
|
||||
issue.location.to_s.should eq "source.cr:2:22"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -75,10 +75,10 @@ module Ameba::Rule
|
|||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:3:11"
|
||||
error.message.should eq "Useless assignment to variable `a`"
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:3:11"
|
||||
issue.message.should eq "Useless assignment to variable `a`"
|
||||
end
|
||||
|
||||
it "does not report useless assignment of instance var" do
|
||||
|
@ -137,7 +137,7 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.first.location.to_s.should eq ":3:11"
|
||||
s.issues.first.location.to_s.should eq ":3:11"
|
||||
end
|
||||
|
||||
it "reports if variable reassigned and not used" do
|
||||
|
@ -314,10 +314,10 @@ module Ameba::Rule
|
|||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
error = s.errors.last
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:5:13"
|
||||
error.message.should eq "Useless assignment to variable `a`"
|
||||
issue = s.issues.last
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:5:13"
|
||||
issue.message.should eq "Useless assignment to variable `a`"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -340,9 +340,9 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.location.to_s.should eq ":3:16"
|
||||
error.message.should eq "Useless assignment to variable `b`"
|
||||
issue = s.issues.first
|
||||
issue.location.to_s.should eq ":3:16"
|
||||
issue.message.should eq "Useless assignment to variable `b`"
|
||||
end
|
||||
|
||||
it "reports if both assigns are reassigned and useless" do
|
||||
|
@ -363,13 +363,13 @@ module Ameba::Rule
|
|||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
error = s.errors.first
|
||||
error.location.to_s.should eq ":3:13"
|
||||
error.message.should eq "Useless assignment to variable `a`"
|
||||
issue = s.issues.first
|
||||
issue.location.to_s.should eq ":3:13"
|
||||
issue.message.should eq "Useless assignment to variable `a`"
|
||||
|
||||
error = s.errors.last
|
||||
error.location.to_s.should eq ":3:16"
|
||||
error.message.should eq "Useless assignment to variable `b`"
|
||||
issue = s.issues.last
|
||||
issue.location.to_s.should eq ":3:16"
|
||||
issue.message.should eq "Useless assignment to variable `b`"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -380,9 +380,9 @@ module Ameba::Rule
|
|||
a = 2
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.size.should eq 2
|
||||
s.errors.first.location.to_s.should eq ":2:11"
|
||||
s.errors.last.location.to_s.should eq ":3:11"
|
||||
s.issues.size.should eq 2
|
||||
s.issues.first.location.to_s.should eq ":2:11"
|
||||
s.issues.last.location.to_s.should eq ":3:11"
|
||||
end
|
||||
|
||||
it "doesn't report if assignments are referenced" do
|
||||
|
@ -476,8 +476,8 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.size.should eq 1
|
||||
s.errors.first.location.to_s.should eq ":5:17"
|
||||
s.issues.size.should eq 1
|
||||
s.issues.first.location.to_s.should eq ":5:17"
|
||||
end
|
||||
|
||||
it "does not report of assignments are referenced in all branches" do
|
||||
|
@ -545,8 +545,8 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.size.should eq 1
|
||||
s.errors.first.location.to_s.should eq ":5:17"
|
||||
s.issues.size.should eq 1
|
||||
s.issues.first.location.to_s.should eq ":5:17"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -578,9 +578,9 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.size.should eq 2
|
||||
s.errors.first.location.to_s.should eq ":5:17"
|
||||
s.errors.last.location.to_s.should eq ":7:17"
|
||||
s.issues.size.should eq 2
|
||||
s.issues.first.location.to_s.should eq ":5:17"
|
||||
s.issues.last.location.to_s.should eq ":7:17"
|
||||
end
|
||||
|
||||
it "doesn't report if assignment is referenced in cond" do
|
||||
|
@ -615,8 +615,8 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.size.should eq 1
|
||||
s.errors.first.location.to_s.should eq ":3:27"
|
||||
s.issues.size.should eq 1
|
||||
s.issues.first.location.to_s.should eq ":3:27"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -642,8 +642,8 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.size.should eq 1
|
||||
s.errors.first.location.to_s.should eq ":4:17"
|
||||
s.issues.size.should eq 1
|
||||
s.issues.first.location.to_s.should eq ":4:17"
|
||||
end
|
||||
|
||||
it "does not report if assignment is referenced in a loop" do
|
||||
|
@ -737,8 +737,8 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.size.should eq 1
|
||||
s.errors.first.location.to_s.should eq ":4:17"
|
||||
s.issues.size.should eq 1
|
||||
s.issues.first.location.to_s.should eq ":4:17"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -785,8 +785,8 @@ module Ameba::Rule
|
|||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
s.errors.size.should eq 1
|
||||
s.errors.first.location.to_s.should eq ":4:15"
|
||||
s.issues.size.should eq 1
|
||||
s.issues.first.location.to_s.should eq ":4:15"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,10 +36,10 @@ module Ameba::Rule
|
|||
end
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:6:23"
|
||||
error.message.should eq "Useless condition in when detected"
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:6:23"
|
||||
issue.message.should eq "Useless condition in when detected"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module Ameba
|
|||
it "reports method name #{expected}" do
|
||||
s = Source.new code
|
||||
Rule::VariableNames.new.catch(s).should_not be_valid
|
||||
s.errors.first.message.should contain expected
|
||||
s.issues.first.message.should contain expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -50,10 +50,10 @@ module Ameba
|
|||
badName = "Yeah"
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
error = s.errors.first
|
||||
error.rule.should_not be_nil
|
||||
error.location.to_s.should eq "source.cr:2:9"
|
||||
error.message.should eq(
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:2:9"
|
||||
issue.message.should eq(
|
||||
"Var name should be underscore-cased: bad_name, not badName"
|
||||
)
|
||||
end
|
||||
|
|
|
@ -34,9 +34,9 @@ module Ameba::Rule
|
|||
source = Source.new invalid_source, "source.cr"
|
||||
subject.catch(source).should_not be_valid
|
||||
|
||||
error = source.errors.first
|
||||
error.location.to_s.should eq "source.cr:2:1"
|
||||
error.message.should eq "While statement using true literal as condition"
|
||||
issue = source.issues.first
|
||||
issue.location.to_s.should eq "source.cr:2:1"
|
||||
issue.message.should eq "While statement using true literal as condition"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue