mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Merge pull request #413 from crystal-ameba/group-naming-rules
Move naming-related rules into its own group
This commit is contained in:
commit
bcb72fb3c3
14 changed files with 28 additions and 27 deletions
|
@ -15,6 +15,7 @@ module Ameba::Rule
|
|||
Layout
|
||||
Lint
|
||||
Metrics
|
||||
Naming
|
||||
Performance
|
||||
Style
|
||||
)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
require "../../../spec_helper"
|
||||
|
||||
module Ameba
|
||||
subject = Rule::Style::ConstantNames.new
|
||||
subject = Rule::Naming::ConstantNames.new
|
||||
|
||||
private def it_reports_constant(name, value, expected, *, file = __FILE__, line = __LINE__)
|
||||
it "reports constant name #{expected}", file, line do
|
||||
rule = Rule::Style::ConstantNames.new
|
||||
rule = Rule::Naming::ConstantNames.new
|
||||
expect_issue rule, <<-CRYSTAL, name: name, file: file, line: line
|
||||
%{name} = #{value}
|
||||
# ^{name} error: Constant name should be screaming-cased: #{expected}, not #{name}
|
||||
|
@ -13,7 +13,7 @@ module Ameba
|
|||
end
|
||||
end
|
||||
|
||||
describe Rule::Style::ConstantNames do
|
||||
describe Rule::Naming::ConstantNames do
|
||||
it "passes if type names are screaming-cased" do
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
LUCKY_NUMBERS = [3, 7, 11]
|
|
@ -1,11 +1,11 @@
|
|||
require "../../../spec_helper"
|
||||
|
||||
module Ameba
|
||||
subject = Rule::Style::MethodNames.new
|
||||
subject = Rule::Naming::MethodNames.new
|
||||
|
||||
private def it_reports_method_name(name, expected, *, file = __FILE__, line = __LINE__)
|
||||
it "reports method name #{expected}", file, line do
|
||||
rule = Rule::Style::MethodNames.new
|
||||
rule = Rule::Naming::MethodNames.new
|
||||
expect_issue rule, <<-CRYSTAL, name: name, file: file, line: line
|
||||
def %{name}; end
|
||||
# ^{name} error: Method name should be underscore-cased: #{expected}, not %{name}
|
||||
|
@ -13,7 +13,7 @@ module Ameba
|
|||
end
|
||||
end
|
||||
|
||||
describe Rule::Style::MethodNames do
|
||||
describe Rule::Naming::MethodNames do
|
||||
it "passes if method names are underscore-cased" do
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
class Person
|
|
@ -1,6 +1,6 @@
|
|||
require "../../../spec_helper"
|
||||
|
||||
module Ameba::Rule::Style
|
||||
module Ameba::Rule::Naming
|
||||
subject = PredicateName.new
|
||||
|
||||
describe PredicateName do
|
|
@ -1,6 +1,6 @@
|
|||
require "../../../spec_helper"
|
||||
|
||||
module Ameba::Rule::Style
|
||||
module Ameba::Rule::Naming
|
||||
subject = QueryBoolMethods.new
|
||||
|
||||
describe QueryBoolMethods do
|
|
@ -1,11 +1,11 @@
|
|||
require "../../../spec_helper"
|
||||
|
||||
module Ameba
|
||||
subject = Rule::Style::TypeNames.new
|
||||
subject = Rule::Naming::TypeNames.new
|
||||
|
||||
private def it_reports_name(type, name, expected, *, file = __FILE__, line = __LINE__)
|
||||
it "reports type name #{expected}", file, line do
|
||||
rule = Rule::Style::TypeNames.new
|
||||
rule = Rule::Naming::TypeNames.new
|
||||
expect_issue rule, <<-CRYSTAL, type: type, name: name, file: file, line: line
|
||||
%{type} %{name}; end
|
||||
# ^{type}^{name}^^^^ error: Type name should be camelcased: #{expected}, but it was %{name}
|
||||
|
@ -13,7 +13,7 @@ module Ameba
|
|||
end
|
||||
end
|
||||
|
||||
describe Rule::Style::TypeNames do
|
||||
describe Rule::Naming::TypeNames do
|
||||
it "passes if type names are camelcased" do
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
class ParseError < Exception
|
|
@ -1,11 +1,11 @@
|
|||
require "../../../spec_helper"
|
||||
|
||||
module Ameba
|
||||
subject = Rule::Style::VariableNames.new
|
||||
subject = Rule::Naming::VariableNames.new
|
||||
|
||||
private def it_reports_var_name(name, value, expected, *, file = __FILE__, line = __LINE__)
|
||||
it "reports variable name #{expected}", file, line do
|
||||
rule = Rule::Style::VariableNames.new
|
||||
rule = Rule::Naming::VariableNames.new
|
||||
expect_issue rule, <<-CRYSTAL, name: name, file: file, line: line
|
||||
%{name} = #{value}
|
||||
# ^{name} error: Var name should be underscore-cased: #{expected}, not %{name}
|
||||
|
@ -13,7 +13,7 @@ module Ameba
|
|||
end
|
||||
end
|
||||
|
||||
describe Rule::Style::VariableNames do
|
||||
describe Rule::Naming::VariableNames do
|
||||
it "passes if var names are underscore-cased" do
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
class Greeting
|
|
@ -95,7 +95,7 @@ module Ameba
|
|||
end
|
||||
|
||||
it "does not run other rules" do
|
||||
rules = [Rule::Lint::Syntax.new, Rule::Style::ConstantNames.new] of Rule::Base
|
||||
rules = [Rule::Lint::Syntax.new, Rule::Naming::ConstantNames.new] of Rule::Base
|
||||
source = Source.new <<-CRYSTAL
|
||||
MyBadConstant = 1
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module Ameba::Rule::Style
|
||||
module Ameba::Rule::Naming
|
||||
# A rule that enforces constant names to be in screaming case.
|
||||
#
|
||||
# For example, these constant names are considered valid:
|
||||
|
@ -18,7 +18,7 @@ module Ameba::Rule::Style
|
|||
# YAML configuration example:
|
||||
#
|
||||
# ```
|
||||
# Style/ConstantNames:
|
||||
# Naming/ConstantNames:
|
||||
# Enabled: true
|
||||
# ```
|
||||
class ConstantNames < Base
|
|
@ -1,4 +1,4 @@
|
|||
module Ameba::Rule::Style
|
||||
module Ameba::Rule::Naming
|
||||
# A rule that enforces method names to be in underscored case.
|
||||
#
|
||||
# For example, these are considered valid:
|
||||
|
@ -34,7 +34,7 @@ module Ameba::Rule::Style
|
|||
# YAML configuration example:
|
||||
#
|
||||
# ```
|
||||
# Style/MethodNames:
|
||||
# Naming/MethodNames:
|
||||
# Enabled: true
|
||||
# ```
|
||||
class MethodNames < Base
|
|
@ -1,4 +1,4 @@
|
|||
module Ameba::Rule::Style
|
||||
module Ameba::Rule::Naming
|
||||
# A rule that disallows tautological predicate names -
|
||||
# meaning those that start with the prefix `is_`, except for
|
||||
# the ones that are not valid Crystal code (e.g. `is_404?`).
|
||||
|
@ -20,7 +20,7 @@ module Ameba::Rule::Style
|
|||
# YAML configuration example:
|
||||
#
|
||||
# ```
|
||||
# Style/PredicateName:
|
||||
# Naming/PredicateName:
|
||||
# Enabled: true
|
||||
# ```
|
||||
class PredicateName < Base
|
|
@ -1,4 +1,4 @@
|
|||
module Ameba::Rule::Style
|
||||
module Ameba::Rule::Naming
|
||||
# A rule that disallows boolean properties without the `?` suffix - defined
|
||||
# using `Object#(class_)property` or `Object#(class_)getter` macros.
|
||||
#
|
||||
|
@ -23,7 +23,7 @@ module Ameba::Rule::Style
|
|||
# YAML configuration example:
|
||||
#
|
||||
# ```
|
||||
# Style/QueryBoolMethods:
|
||||
# Naming/QueryBoolMethods:
|
||||
# Enabled: true
|
||||
# ```
|
||||
class QueryBoolMethods < Base
|
|
@ -1,4 +1,4 @@
|
|||
module Ameba::Rule::Style
|
||||
module Ameba::Rule::Naming
|
||||
# A rule that enforces type names in camelcase manner.
|
||||
#
|
||||
# For example, these are considered valid:
|
||||
|
@ -48,7 +48,7 @@ module Ameba::Rule::Style
|
|||
# YAML configuration example:
|
||||
#
|
||||
# ```
|
||||
# Style/TypeNames:
|
||||
# Naming/TypeNames:
|
||||
# Enabled: true
|
||||
# ```
|
||||
class TypeNames < Base
|
|
@ -1,4 +1,4 @@
|
|||
module Ameba::Rule::Style
|
||||
module Ameba::Rule::Naming
|
||||
# A rule that enforces variable names to be in underscored case.
|
||||
#
|
||||
# For example, these variable names are considered valid:
|
||||
|
@ -19,7 +19,7 @@ module Ameba::Rule::Style
|
|||
# YAML configuration example:
|
||||
#
|
||||
# ```
|
||||
# Style/VariableNames:
|
||||
# Naming/VariableNames:
|
||||
# Enabled: true
|
||||
# ```
|
||||
class VariableNames < Base
|
Loading…
Reference in a new issue