mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Ignores PredicateName if alternative isn't valid (e.g. is_404?)
This commit is contained in:
parent
9e2ab9c002
commit
d6c6af883d
2 changed files with 16 additions and 2 deletions
|
@ -44,5 +44,16 @@ module Ameba::Rule
|
||||||
error.message.should eq(
|
error.message.should eq(
|
||||||
"Favour method name 'picture?' over 'has_picture?'")
|
"Favour method name 'picture?' over 'has_picture?'")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "ignores if alternative name isn't valid syntax" do
|
||||||
|
s = Source.new %q(
|
||||||
|
class Image
|
||||||
|
def is_404?(x)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
subject.catch(s).should be_valid
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module Ameba::Rule
|
module Ameba::Rule
|
||||||
# A rule that disallows tautological predicate names, meaning those that
|
# A rule that disallows tautological predicate names, meaning those that
|
||||||
# start with the prefix `has_` or the prefix `is_`.
|
# start with the prefix `has_` or the prefix `is_`. Ignores if the alternative isn't valid Crystal code (e.g. `is_404?`).
|
||||||
#
|
#
|
||||||
# Favour these:
|
# Favour these:
|
||||||
#
|
#
|
||||||
|
@ -40,8 +40,11 @@ module Ameba::Rule
|
||||||
|
|
||||||
def test(source, node : Crystal::Def)
|
def test(source, node : Crystal::Def)
|
||||||
if node.name =~ /^(is|has)_(\w+)\?/
|
if node.name =~ /^(is|has)_(\w+)\?/
|
||||||
|
alternative = $2
|
||||||
|
return unless alternative =~ /^[a-z_][a-zA-Z_0-9]*$/
|
||||||
|
|
||||||
source.error self, node.location,
|
source.error self, node.location,
|
||||||
"Favour method name '#{$2}?' over '#{node.name}'"
|
"Favour method name '#{alternative}?' over '#{node.name}'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue