mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add Style/QueryBoolMethods
rule
This commit is contained in:
parent
be65ba2a92
commit
1524aad299
3 changed files with 139 additions and 0 deletions
60
spec/ameba/rule/style/query_bool_methods_spec.cr
Normal file
60
spec/ameba/rule/style/query_bool_methods_spec.cr
Normal file
|
@ -0,0 +1,60 @@
|
|||
require "../../../spec_helper"
|
||||
|
||||
module Ameba::Rule::Style
|
||||
subject = QueryBoolMethods.new
|
||||
|
||||
describe QueryBoolMethods do
|
||||
it "passes for valid cases" do
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
class Foo
|
||||
class_property? foo = true
|
||||
property? foo = true
|
||||
property foo2 : Bool? = true
|
||||
setter panda = true
|
||||
end
|
||||
|
||||
module Bar
|
||||
class_getter? bar : Bool = true
|
||||
getter? bar : Bool
|
||||
getter bar2 : Bool? = true
|
||||
setter panda : Bool = true
|
||||
|
||||
def initialize(@bar = true)
|
||||
end
|
||||
end
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
{% for call in %w[getter class_getter property class_property] %}
|
||||
it "reports `{{ call.id }}` assign with Bool" do
|
||||
expect_issue subject, <<-CRYSTAL, call: {{ call }}
|
||||
class Foo
|
||||
%{call} foo = true
|
||||
_{call} # ^^^ error: Consider using '%{call}?' for 'foo'
|
||||
end
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports `{{ call.id }}` type declaration assign with Bool" do
|
||||
expect_issue subject, <<-CRYSTAL, call: {{ call }}
|
||||
class Foo
|
||||
%{call} foo : Bool = true
|
||||
_{call} # ^ error: Consider using '%{call}?' for 'foo'
|
||||
end
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports `{{ call.id }}` type declaration with Bool" do
|
||||
expect_issue subject, <<-CRYSTAL, call: {{ call }}
|
||||
class Foo
|
||||
%{call} foo : Bool
|
||||
_{call} # ^ error: Consider using '%{call}?' for 'foo'
|
||||
|
||||
def initialize(@foo = true)
|
||||
end
|
||||
end
|
||||
CRYSTAL
|
||||
end
|
||||
{% end %}
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue