diff --git a/spec/ameba/rule/naming/ascii_identifiers_spec.cr b/spec/ameba/rule/naming/ascii_identifiers_spec.cr index d3bb3267..87bed331 100644 --- a/spec/ameba/rule/naming/ascii_identifiers_spec.cr +++ b/spec/ameba/rule/naming/ascii_identifiers_spec.cr @@ -126,5 +126,26 @@ module Ameba::Rule::Naming space = :invader # 👾 CRYSTAL 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 diff --git a/src/ameba/rule/naming/ascii_identifiers.cr b/src/ameba/rule/naming/ascii_identifiers.cr index dfc2987e..f2739b47 100644 --- a/src/ameba/rule/naming/ascii_identifiers.cr +++ b/src/ameba/rule/naming/ascii_identifiers.cr @@ -20,10 +20,12 @@ module Ameba::Rule::Naming # ``` # Naming/AsciiIdentifiers: # Enabled: true + # IgnoreSymbols: false # ``` class AsciiIdentifiers < Base properties do description "Disallows non-ascii characters in identifiers" + ignore_symbols false end MSG = "Identifier contains non-ascii characters" @@ -68,9 +70,10 @@ module Ameba::Rule::Naming end private def check_symbol_literal(source, node) - if node.is_a?(Crystal::SymbolLiteral) - check_issue(source, node, node.value) - end + return if ignore_symbols? + return unless node.is_a?(Crystal::SymbolLiteral) + + check_issue(source, node, node.value) end private def check_issue(source, location, end_location, name)