mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Allow constants to be in PascalCase (i.e. Log, SuperConstant)
closes #148
This commit is contained in:
parent
1a25583036
commit
478da94c20
2 changed files with 11 additions and 7 deletions
|
@ -24,6 +24,8 @@ module Ameba
|
||||||
def works(n : Int32)
|
def works(n : Int32)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Log = ::Log.for("db")
|
||||||
|
|
||||||
a = 1
|
a = 1
|
||||||
myVar = 2
|
myVar = 2
|
||||||
m_var = 3
|
m_var = 3
|
||||||
|
@ -31,21 +33,21 @@ module Ameba
|
||||||
subject.catch(s).should be_valid
|
subject.catch(s).should be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
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
|
it "reports rule, pos and message" do
|
||||||
s = Source.new %(
|
s = Source.new %(
|
||||||
Const = 1
|
Const_Name = 1
|
||||||
), "source.cr"
|
), "source.cr"
|
||||||
subject.catch(s).should_not be_valid
|
subject.catch(s).should_not be_valid
|
||||||
issue = s.issues.first
|
issue = s.issues.first
|
||||||
issue.rule.should_not be_nil
|
issue.rule.should_not be_nil
|
||||||
issue.location.to_s.should eq "source.cr:1:1"
|
issue.location.to_s.should eq "source.cr:1:1"
|
||||||
issue.end_location.to_s.should eq "source.cr:1:5"
|
issue.end_location.to_s.should eq "source.cr:1:10"
|
||||||
issue.message.should eq(
|
issue.message.should eq(
|
||||||
"Constant name should be screaming-cased: CONST, not Const"
|
"Constant name should be screaming-cased: CONST_NAME, not Const_Name"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,8 +11,8 @@ module Ameba::Rule::Style
|
||||||
# And these are invalid names:
|
# And these are invalid names:
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# MyBadConstant = 1
|
# myBadConstant = 1
|
||||||
# Wrong_NAME = 2
|
# Wrong_NAME = 2
|
||||||
# ```
|
# ```
|
||||||
#
|
#
|
||||||
# YAML configuration example:
|
# YAML configuration example:
|
||||||
|
@ -32,7 +32,9 @@ module Ameba::Rule::Style
|
||||||
def test(source, node : Crystal::Assign)
|
def test(source, node : Crystal::Assign)
|
||||||
if (target = node.target).is_a? Crystal::Path
|
if (target = node.target).is_a? Crystal::Path
|
||||||
name = target.names.first
|
name = target.names.first
|
||||||
return if (expected = name.upcase) == name
|
expected = name.upcase
|
||||||
|
|
||||||
|
return if expected == name || name.camelcase == name
|
||||||
|
|
||||||
issue_for target, MSG % {expected, name}
|
issue_for target, MSG % {expected, name}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue