mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add AsciiIdentifiers#ignore_symbols
property
This commit is contained in:
parent
be76b3682a
commit
018adb54be
2 changed files with 27 additions and 3 deletions
|
@ -126,5 +126,26 @@ module Ameba::Rule::Naming
|
||||||
space = :invader # 👾
|
space = :invader # 👾
|
||||||
CRYSTAL
|
CRYSTAL
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "properties" do
|
||||||
|
context "#ignore_symbols" do
|
||||||
|
it "returns `false` by default" do
|
||||||
|
rule = AsciiIdentifiers.new
|
||||||
|
rule.ignore_symbols?.should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "stops reporting symbol literals if set to `true`" do
|
||||||
|
rule = AsciiIdentifiers.new
|
||||||
|
rule.ignore_symbols = true
|
||||||
|
|
||||||
|
expect_no_issues rule, <<-CRYSTAL
|
||||||
|
def forest_adventure(animal_type = :🐺); end
|
||||||
|
%i[🐺 🐿].index!(:🐺)
|
||||||
|
foo, bar = :신장, true
|
||||||
|
foo = :신장
|
||||||
|
CRYSTAL
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,10 +20,12 @@ module Ameba::Rule::Naming
|
||||||
# ```
|
# ```
|
||||||
# Naming/AsciiIdentifiers:
|
# Naming/AsciiIdentifiers:
|
||||||
# Enabled: true
|
# Enabled: true
|
||||||
|
# IgnoreSymbols: false
|
||||||
# ```
|
# ```
|
||||||
class AsciiIdentifiers < Base
|
class AsciiIdentifiers < Base
|
||||||
properties do
|
properties do
|
||||||
description "Disallows non-ascii characters in identifiers"
|
description "Disallows non-ascii characters in identifiers"
|
||||||
|
ignore_symbols false
|
||||||
end
|
end
|
||||||
|
|
||||||
MSG = "Identifier contains non-ascii characters"
|
MSG = "Identifier contains non-ascii characters"
|
||||||
|
@ -68,9 +70,10 @@ module Ameba::Rule::Naming
|
||||||
end
|
end
|
||||||
|
|
||||||
private def check_symbol_literal(source, node)
|
private def check_symbol_literal(source, node)
|
||||||
if node.is_a?(Crystal::SymbolLiteral)
|
return if ignore_symbols?
|
||||||
check_issue(source, node, node.value)
|
return unless node.is_a?(Crystal::SymbolLiteral)
|
||||||
end
|
|
||||||
|
check_issue(source, node, node.value)
|
||||||
end
|
end
|
||||||
|
|
||||||
private def check_issue(source, location, end_location, name)
|
private def check_issue(source, location, end_location, name)
|
||||||
|
|
Loading…
Reference in a new issue