Remove most of the obsolete specs

This commit is contained in:
Sijawusz Pur Rahnama 2022-12-21 21:13:01 +01:00
parent 1ba6fcb55c
commit 9926f0295a
36 changed files with 0 additions and 513 deletions

View file

@ -15,16 +15,5 @@ module Ameba::Rule::Layout
expect_correction source, "whitespace at the end" expect_correction source, "whitespace at the end"
end end
it "reports rule, pos and message" do
source = Source.new "a = 1\n b = 2 ", "source.cr"
subject.catch(source).should_not be_valid
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:2:7"
issue.end_location.to_s.should eq "source.cr:2:7"
issue.message.should eq "Trailing whitespace detected"
end
end end
end end

View file

@ -94,16 +94,6 @@ module Ameba::Rule::Lint
a a
CRYSTAL CRYSTAL
end end
it "reports rule, pos and message" do
source = Source.new "a != true", "source.cr"
subject.catch(source)
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
context "boolean on the left" do context "boolean on the left" do
@ -165,17 +155,6 @@ module Ameba::Rule::Lint
a a
CRYSTAL CRYSTAL
end end
it "reports rule, pos and message" do
source = Source.new "true != a", "source.cr"
subject.catch(source).should_not be_valid
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq "source.cr:1:9"
issue.message.should eq "Comparison to a boolean is pointless"
end
end end
end end
end end

View file

@ -28,16 +28,5 @@ module Ameba::Rule::Lint
CRYSTAL CRYSTAL
end end
end end
it "reports rule, pos and message" do
s = Source.new "pp! :foo", "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq "source.cr:1:8"
issue.message.should eq "Possibly forgotten debug-related `pp!` call detected"
end
end end
end end

View file

@ -31,16 +31,5 @@ module Ameba::Rule::Lint
expect_no_corrections source expect_no_corrections source
end end
it "reports rule, pos and message" do
s = Source.new "debugger", "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq "source.cr:1:8"
issue.message.should eq "Possible forgotten debugger statement detected"
end
end end
end end

View file

@ -22,28 +22,5 @@ module Ameba::Rule::Lint
expect_no_corrections source expect_no_corrections source
end end
it "reports rule, pos and message" do
source = Source.new <<-CRYSTAL, "source.cr"
require "./thing"
require "./thing"
require "./another_thing"
require "./another_thing"
CRYSTAL
subject.catch(source).should_not be_valid
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:2:1"
issue.end_location.to_s.should eq ""
issue.message.should eq "Duplicated require of `./thing`"
issue = source.issues.last
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:4:1"
issue.end_location.to_s.should eq ""
issue.message.should eq "Duplicated require of `./another_thing`"
end
end end
end end

View file

@ -110,18 +110,5 @@ module Ameba
) )
subject.catch(s).should be_valid subject.catch(s).should be_valid
end end
it "reports rule, location and message" do
s = Source.new %(
if ()
end
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:4"
issue.end_location.to_s.should eq "source.cr:1:5"
issue.message.should eq "Avoid empty expressions"
end
end end
end end

View file

@ -64,21 +64,5 @@ module Ameba::Rule::Lint
end end
CRYSTAL CRYSTAL
end end
it "reports rule, message and location" do
s = Source.new %(
a = 1
loop do
# comment goes here
end
), "source.cr"
subject.catch(s).should_not be_valid
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:1"
issue.end_location.to_s.should eq "source.cr:4:3"
issue.message.should eq EmptyLoop::MSG
end
end end
end end

View file

@ -32,17 +32,5 @@ module Ameba::Rule::Lint
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Duplicated keys in hash literal: "key1", "key2" # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Duplicated keys in hash literal: "key1", "key2"
CRYSTAL CRYSTAL
end end
it "reports rule, location and message" do
s = Source.new %q(
h = {"a" => 1, "a" => 2}
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:5"
issue.end_location.to_s.should eq "source.cr:1:24"
issue.message.should eq %(Duplicated keys in hash literal: "a")
end
end end
end end

View file

@ -58,18 +58,5 @@ module Ameba::Rule::Lint
CRYSTAL CRYSTAL
end end
end end
it "reports rule, pos and message" do
s = Source.new %(
"foo" == "foo"
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq "source.cr:1:14"
issue.message.should eq "Comparison always evaluates to true"
end
end end
end end

View file

@ -58,18 +58,5 @@ module Ameba::Rule::Lint
CRYSTAL CRYSTAL
end end
end end
it "reports rule, pos and message" do
s = Source.new %(
(1..3).index(1).not_nil!
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:8"
issue.end_location.to_s.should eq "source.cr:1:24"
issue.message.should eq "Use `index! {...}` instead of `index {...}.not_nil!`"
end
end end
end end

View file

@ -32,18 +32,5 @@ module Ameba::Rule::Lint
CRYSTAL CRYSTAL
end end
end end
it "reports rule, pos and message" do
s = Source.new %(
(1..3).first?.not_nil!
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:15"
issue.end_location.to_s.should eq "source.cr:1:22"
issue.message.should eq "Avoid using `not_nil!`"
end
end end
end end

View file

@ -25,16 +25,5 @@ module Ameba::Rule::Lint
# ^^^^^ error: rand(1) always returns 0 # ^^^^^ error: rand(1) always returns 0
CRYSTAL CRYSTAL
end end
it "reports rule, location and a message" do
s = Source.new "rand(1)", "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq "source.cr:1:7"
issue.message.should eq "rand(1) always returns 0"
end
end end
end end

View file

@ -157,20 +157,6 @@ module Ameba::Rule::Lint
CRYSTAL CRYSTAL
end end
it "reports rule, location and message" do
source = Source.new %(
foo = 1
3.times { |foo| foo + 1 }
), "source.cr"
subject.catch(source).should_not be_valid
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:2:12"
issue.end_location.should be_nil
issue.message.should eq "Shadowing outer local variable `foo`"
end
context "macro" do context "macro" do
it "does not report shadowed vars in outer scope" do it "does not report shadowed vars in outer scope" do
expect_no_issues subject, <<-CRYSTAL expect_no_issues subject, <<-CRYSTAL

View file

@ -194,24 +194,5 @@ module Ameba::Rule::Lint
end end
CRYSTAL CRYSTAL
end end
it "reports rule, location and message" do
s = Source.new %(
i = 0
while true
i += 1
spawn { i }
end
), "source.cr"
subject.catch(s).should_not be_valid
s.issues.size.should eq 1
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:4:11"
issue.end_location.to_s.should eq "source.cr:4:11"
issue.message.should eq "Shared variable `i` is used in fiber"
end
end end
end end

View file

@ -23,16 +23,6 @@ module Ameba::Rule::Lint
CRYSTAL CRYSTAL
end end
it "reports rule, location and message" do
s = Source.new "def hello end", "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:11"
issue.message.should match /unexpected token: "?end"? \(expected ["'];["'] or newline\)/
end
it "has highest severity" do it "has highest severity" do
subject.severity.should eq Severity::Error subject.severity.should eq Severity::Error
end end

View file

@ -24,22 +24,5 @@ module Ameba::Rule::Lint
end end
CRYSTAL CRYSTAL
end end
it "reports rule, location and message" do
s = Source.new %(
case
when String
puts "hello"
when can_generate?
generate if can_generate?
end
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:5:15"
issue.end_location.to_s.should eq "source.cr:5:27"
issue.message.should eq "Useless condition in when detected"
end
end end
end end

View file

@ -66,14 +66,5 @@ module Ameba::Rule::Performance
expect_no_corrections source expect_no_corrections source
end end
end end
it "reports rule, pos and message" do
source = expect_issue subject, <<-CRYSTAL
[1, 2, 3].reject { |e| e > 2 }.any?
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `any? {...}` instead of `reject {...}.any?`
CRYSTAL
expect_no_corrections source
end
end end
end end

View file

@ -42,18 +42,5 @@ module Ameba::Rule::Performance
CRYSTAL CRYSTAL
end end
end end
it "reports rule, pos and message" do
source = Source.new path: "source.cr", code: %(
[1, 2, 3].any?
)
subject.catch(source).should_not be_valid
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:11"
issue.end_location.to_s.should eq "source.cr:1:14"
issue.message.should eq "Use `!{...}.empty?` instead of `{...}.any?`"
end
end end
end end

View file

@ -54,22 +54,6 @@ module Ameba::Rule::Performance
end end
end end
it "reports rule, pos and message" do
source = Source.new path: "source.cr", code: <<-CODE
[1, 2, 3].select { |e| e > 1 }.reverse
CODE
subject.catch(source).should_not be_valid
source.issues.size.should eq 1
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:32"
issue.end_location.to_s.should eq "source.cr:1:38"
issue.message.should eq "Use bang method variant `reverse!` after chained `select` call"
end
context "macro" do context "macro" do
it "doesn't report in macro scope" do it "doesn't report in macro scope" do
expect_no_issues subject, <<-CRYSTAL expect_no_issues subject, <<-CRYSTAL

View file

@ -36,18 +36,5 @@ module Ameba::Rule::Performance
CRYSTAL CRYSTAL
end end
end end
it "reports rule, pos and message" do
s = Source.new %(
(1..3).map(&.itself).compact
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:8"
issue.end_location.to_s.should eq "source.cr:1:29"
issue.message.should eq "Use `compact_map {...}` instead of `map {...}.compact`"
end
end end
end end

View file

@ -72,21 +72,6 @@ module Ameba::Rule::Performance
end end
end end
it "reports rule, pos and message" do
s = Source.new %(
[1, 2, 3].select { |e| e > 2 }.first
), "source.cr"
subject.catch(s).should_not be_valid
s.issues.size.should eq 1
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:11"
issue.end_location.to_s.should eq "source.cr:1:37"
issue.message.should eq "Use `find {...}` instead of `select {...}.first`"
end
context "macro" do context "macro" do
it "doesn't report in macro scope" do it "doesn't report in macro scope" do
expect_no_issues subject, <<-CRYSTAL expect_no_issues subject, <<-CRYSTAL

View file

@ -30,18 +30,5 @@ module Ameba::Rule::Performance
CRYSTAL CRYSTAL
end end
end end
it "reports rule, pos and message" do
s = Source.new %(
%w[Alice Bob].map(&.chars).flatten
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:15"
issue.end_location.to_s.should eq "source.cr:1:35"
issue.message.should eq "Use `flat_map {...}` instead of `map {...}.flatten`"
end
end end
end end

View file

@ -45,18 +45,5 @@ module Ameba::Rule::Performance
CRYSTAL CRYSTAL
end end
end end
it "reports rule, pos and message" do
s = Source.new %(
(1..3).map(&.to_u64).sum
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:8"
issue.end_location.to_s.should eq "source.cr:1:25"
issue.message.should eq "Use `sum {...}` instead of `map {...}.sum`"
end
end end
end end

View file

@ -61,18 +61,5 @@ module Ameba::Rule::Performance
CRYSTAL CRYSTAL
end end
end end
it "reports rule, pos and message" do
s = Source.new %(
lines.split("\n").reject(&.empty?).size
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:2:4"
issue.end_location.to_s.should eq "source.cr:2:25"
issue.message.should eq "Use `count {...}` instead of `reject {...}.size`."
end
end end
end end

View file

@ -37,19 +37,5 @@ module Ameba
# it_reports_constant "MyBadConstant", "1", "MYBADCONSTANT" # it_reports_constant "MyBadConstant", "1", "MYBADCONSTANT"
it_reports_constant "Wrong_NAME", "2", "WRONG_NAME" it_reports_constant "Wrong_NAME", "2", "WRONG_NAME"
it_reports_constant "Wrong_Name", "3", "WRONG_NAME" it_reports_constant "Wrong_Name", "3", "WRONG_NAME"
it "reports rule, pos and message" do
s = Source.new %(
Const_Name = 1
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq "source.cr:1:10"
issue.message.should eq(
"Constant name should be screaming-cased: CONST_NAME, not Const_Name"
)
end
end end
end end

View file

@ -59,20 +59,5 @@ module Ameba::Rule::Style
CRYSTAL CRYSTAL
end end
end end
it "reports rule, pos and message" do
source = Source.new path: "source.cr", code: %(
[1, 2, nil].reject(&.nil?)
)
subject.catch(source).should_not be_valid
source.issues.size.should eq 1
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:13"
issue.end_location.to_s.should eq "source.cr:1:26"
issue.message.should eq "Use `reject(Nil)` instead of `reject {...}`"
end
end end
end end

View file

@ -34,19 +34,5 @@ module Ameba::Rule::Style
a.nil? a.nil?
CRYSTAL CRYSTAL
end end
it "reports rule, location and message" do
s = Source.new %(
nil.is_a? Nil
), "source.cr"
subject.catch(s).should_not be_valid
s.issues.size.should eq 1
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:11"
issue.end_location.to_s.should eq "source.cr:1:13"
issue.message.should eq IsANil::MSG
end
end end
end end

View file

@ -117,18 +117,6 @@ module Ameba
it_transforms "3.001234", "3.001_234" it_transforms "3.001234", "3.001_234"
it_transforms "3.0012345", "3.001_234_5" it_transforms "3.0012345", "3.001_234_5"
it "reports rule, pos and message" do
s = Source.new %q(
1200000
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq "source.cr:1:7"
issue.message.should match /1_200_000/
end
context "properties" do context "properties" do
it "#int_min_digits" do it "#int_min_digits" do
rule = Rule::Style::LargeNumbers.new rule = Rule::Style::LargeNumbers.new

View file

@ -38,20 +38,5 @@ module Ameba
it_reports_method_name "firstName", "first_name" it_reports_method_name "firstName", "first_name"
it_reports_method_name "date_of_Birth", "date_of_birth" it_reports_method_name "date_of_Birth", "date_of_birth"
it_reports_method_name "homepageURL", "homepage_url" it_reports_method_name "homepageURL", "homepage_url"
it "reports rule, pos and message" do
s = Source.new %(
def bad_Name(a)
end
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:5"
issue.end_location.to_s.should eq "source.cr:1:12"
issue.message.should eq(
"Method name should be underscore-cased: bad_name, not bad_Name"
)
end
end end
end end

View file

@ -53,16 +53,5 @@ module Ameba::Rule::Style
end end
CRYSTAL CRYSTAL
end end
it "reports rule, pos and message" do
s = Source.new ":nok unless !s.empty?", "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq "source.cr:1:21"
issue.message.should eq "Avoid negated conditions in unless blocks"
end
end end
end end

View file

@ -27,24 +27,6 @@ module Ameba::Rule::Style
CRYSTAL CRYSTAL
end end
it "reports rule, pos and message" do
s = Source.new %q(
class Image
def is_valid?(x)
true
end
end
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:2:3"
issue.end_location.to_s.should eq "source.cr:4:5"
issue.message.should eq(
"Favour method name 'valid?' over 'is_valid?'")
end
it "ignores if alternative name isn't valid syntax" do it "ignores if alternative name isn't valid syntax" do
expect_no_issues subject, <<-CRYSTAL expect_no_issues subject, <<-CRYSTAL
class Image class Image

View file

@ -294,24 +294,5 @@ module Ameba::Rule::Style
} }
CRYSTAL CRYSTAL
end end
it "reports rule, pos and message" do
s = Source.new %q(
def method
begin
open_connection
ensure
close_connection
end
end
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:2:3"
issue.end_location.to_s.should eq "source.cr:2:7"
issue.message.should eq "Redundant `begin` block detected"
end
end end
end end

View file

@ -49,20 +49,5 @@ module Ameba
# ^{} error: Type name should be camelcased: NumericValue, but it was Numeric_value # ^{} error: Type name should be camelcased: NumericValue, but it was Numeric_value
CRYSTAL CRYSTAL
end end
it "reports rule, pos and message" do
s = Source.new %(
class My_class
end
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq "source.cr:2:3"
issue.message.should eq(
"Type name should be camelcased: MyClass, but it was My_class"
)
end
end end
end end

View file

@ -22,23 +22,5 @@ module Ameba::Rule::Style
end end
CRYSTAL CRYSTAL
end end
it "reports rule, pos and message" do
s = Source.new %(
unless something
:one
else
:two
end
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.should_not be_nil
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq "source.cr:5:3"
issue.message.should eq "Favour if over unless with else"
end
end end
end end

View file

@ -62,19 +62,5 @@ module Ameba
end end
CRYSTAL CRYSTAL
end end
it "reports rule, pos and message" do
s = Source.new %(
badName = "Yeah"
), "source.cr"
subject.catch(s).should_not be_valid
issue = s.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq "source.cr:1:7"
issue.message.should eq(
"Var name should be underscore-cased: bad_name, not badName"
)
end
end end
end end

View file

@ -273,20 +273,5 @@ module Ameba::Rule::Style
(1..3).join(separator: '.', &.to_s) (1..3).join(separator: '.', &.to_s)
CRYSTAL CRYSTAL
end end
it "reports rule, pos and message" do
source = Source.new path: "source.cr", code: <<-CRYSTAL
(1..3).any? { |i| i.odd? }
CRYSTAL
subject.catch(source).should_not be_valid
source.issues.size.should eq 1
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:8"
issue.end_location.to_s.should eq "source.cr:1:26"
issue.message.should eq "Use short block notation instead: `any?(&.odd?)`"
end
end end
end end