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
|
Layout
|
||||||
Lint
|
Lint
|
||||||
Metrics
|
Metrics
|
||||||
|
Naming
|
||||||
Performance
|
Performance
|
||||||
Style
|
Style
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
require "../../../spec_helper"
|
require "../../../spec_helper"
|
||||||
|
|
||||||
module Ameba
|
module Ameba
|
||||||
subject = Rule::Style::ConstantNames.new
|
subject = Rule::Naming::ConstantNames.new
|
||||||
|
|
||||||
private def it_reports_constant(name, value, expected, *, file = __FILE__, line = __LINE__)
|
private def it_reports_constant(name, value, expected, *, file = __FILE__, line = __LINE__)
|
||||||
it "reports constant name #{expected}", file, line do
|
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
|
expect_issue rule, <<-CRYSTAL, name: name, file: file, line: line
|
||||||
%{name} = #{value}
|
%{name} = #{value}
|
||||||
# ^{name} error: Constant name should be screaming-cased: #{expected}, not #{name}
|
# ^{name} error: Constant name should be screaming-cased: #{expected}, not #{name}
|
||||||
|
@ -13,7 +13,7 @@ module Ameba
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Rule::Style::ConstantNames do
|
describe Rule::Naming::ConstantNames do
|
||||||
it "passes if type names are screaming-cased" do
|
it "passes if type names are screaming-cased" do
|
||||||
expect_no_issues subject, <<-CRYSTAL
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
LUCKY_NUMBERS = [3, 7, 11]
|
LUCKY_NUMBERS = [3, 7, 11]
|
|
@ -1,11 +1,11 @@
|
||||||
require "../../../spec_helper"
|
require "../../../spec_helper"
|
||||||
|
|
||||||
module Ameba
|
module Ameba
|
||||||
subject = Rule::Style::MethodNames.new
|
subject = Rule::Naming::MethodNames.new
|
||||||
|
|
||||||
private def it_reports_method_name(name, expected, *, file = __FILE__, line = __LINE__)
|
private def it_reports_method_name(name, expected, *, file = __FILE__, line = __LINE__)
|
||||||
it "reports method name #{expected}", file, line do
|
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
|
expect_issue rule, <<-CRYSTAL, name: name, file: file, line: line
|
||||||
def %{name}; end
|
def %{name}; end
|
||||||
# ^{name} error: Method name should be underscore-cased: #{expected}, not %{name}
|
# ^{name} error: Method name should be underscore-cased: #{expected}, not %{name}
|
||||||
|
@ -13,7 +13,7 @@ module Ameba
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Rule::Style::MethodNames do
|
describe Rule::Naming::MethodNames do
|
||||||
it "passes if method names are underscore-cased" do
|
it "passes if method names are underscore-cased" do
|
||||||
expect_no_issues subject, <<-CRYSTAL
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
class Person
|
class Person
|
|
@ -1,6 +1,6 @@
|
||||||
require "../../../spec_helper"
|
require "../../../spec_helper"
|
||||||
|
|
||||||
module Ameba::Rule::Style
|
module Ameba::Rule::Naming
|
||||||
subject = PredicateName.new
|
subject = PredicateName.new
|
||||||
|
|
||||||
describe PredicateName do
|
describe PredicateName do
|
|
@ -1,6 +1,6 @@
|
||||||
require "../../../spec_helper"
|
require "../../../spec_helper"
|
||||||
|
|
||||||
module Ameba::Rule::Style
|
module Ameba::Rule::Naming
|
||||||
subject = QueryBoolMethods.new
|
subject = QueryBoolMethods.new
|
||||||
|
|
||||||
describe QueryBoolMethods do
|
describe QueryBoolMethods do
|
|
@ -1,11 +1,11 @@
|
||||||
require "../../../spec_helper"
|
require "../../../spec_helper"
|
||||||
|
|
||||||
module Ameba
|
module Ameba
|
||||||
subject = Rule::Style::TypeNames.new
|
subject = Rule::Naming::TypeNames.new
|
||||||
|
|
||||||
private def it_reports_name(type, name, expected, *, file = __FILE__, line = __LINE__)
|
private def it_reports_name(type, name, expected, *, file = __FILE__, line = __LINE__)
|
||||||
it "reports type name #{expected}", file, line do
|
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
|
expect_issue rule, <<-CRYSTAL, type: type, name: name, file: file, line: line
|
||||||
%{type} %{name}; end
|
%{type} %{name}; end
|
||||||
# ^{type}^{name}^^^^ error: Type name should be camelcased: #{expected}, but it was %{name}
|
# ^{type}^{name}^^^^ error: Type name should be camelcased: #{expected}, but it was %{name}
|
||||||
|
@ -13,7 +13,7 @@ module Ameba
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Rule::Style::TypeNames do
|
describe Rule::Naming::TypeNames do
|
||||||
it "passes if type names are camelcased" do
|
it "passes if type names are camelcased" do
|
||||||
expect_no_issues subject, <<-CRYSTAL
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
class ParseError < Exception
|
class ParseError < Exception
|
|
@ -1,11 +1,11 @@
|
||||||
require "../../../spec_helper"
|
require "../../../spec_helper"
|
||||||
|
|
||||||
module Ameba
|
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__)
|
private def it_reports_var_name(name, value, expected, *, file = __FILE__, line = __LINE__)
|
||||||
it "reports variable name #{expected}", file, line do
|
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
|
expect_issue rule, <<-CRYSTAL, name: name, file: file, line: line
|
||||||
%{name} = #{value}
|
%{name} = #{value}
|
||||||
# ^{name} error: Var name should be underscore-cased: #{expected}, not %{name}
|
# ^{name} error: Var name should be underscore-cased: #{expected}, not %{name}
|
||||||
|
@ -13,7 +13,7 @@ module Ameba
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Rule::Style::VariableNames do
|
describe Rule::Naming::VariableNames do
|
||||||
it "passes if var names are underscore-cased" do
|
it "passes if var names are underscore-cased" do
|
||||||
expect_no_issues subject, <<-CRYSTAL
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
class Greeting
|
class Greeting
|
|
@ -95,7 +95,7 @@ module Ameba
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not run other rules" do
|
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
|
source = Source.new <<-CRYSTAL
|
||||||
MyBadConstant = 1
|
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.
|
# A rule that enforces constant names to be in screaming case.
|
||||||
#
|
#
|
||||||
# For example, these constant names are considered valid:
|
# For example, these constant names are considered valid:
|
||||||
|
@ -18,7 +18,7 @@ module Ameba::Rule::Style
|
||||||
# YAML configuration example:
|
# YAML configuration example:
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# Style/ConstantNames:
|
# Naming/ConstantNames:
|
||||||
# Enabled: true
|
# Enabled: true
|
||||||
# ```
|
# ```
|
||||||
class ConstantNames < Base
|
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.
|
# A rule that enforces method names to be in underscored case.
|
||||||
#
|
#
|
||||||
# For example, these are considered valid:
|
# For example, these are considered valid:
|
||||||
|
@ -34,7 +34,7 @@ module Ameba::Rule::Style
|
||||||
# YAML configuration example:
|
# YAML configuration example:
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# Style/MethodNames:
|
# Naming/MethodNames:
|
||||||
# Enabled: true
|
# Enabled: true
|
||||||
# ```
|
# ```
|
||||||
class MethodNames < Base
|
class MethodNames < Base
|
|
@ -1,4 +1,4 @@
|
||||||
module Ameba::Rule::Style
|
module Ameba::Rule::Naming
|
||||||
# A rule that disallows tautological predicate names -
|
# A rule that disallows tautological predicate names -
|
||||||
# meaning those that start with the prefix `is_`, except for
|
# meaning those that start with the prefix `is_`, except for
|
||||||
# the ones that are not valid Crystal code (e.g. `is_404?`).
|
# the ones that are not valid Crystal code (e.g. `is_404?`).
|
||||||
|
@ -20,7 +20,7 @@ module Ameba::Rule::Style
|
||||||
# YAML configuration example:
|
# YAML configuration example:
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# Style/PredicateName:
|
# Naming/PredicateName:
|
||||||
# Enabled: true
|
# Enabled: true
|
||||||
# ```
|
# ```
|
||||||
class PredicateName < Base
|
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
|
# A rule that disallows boolean properties without the `?` suffix - defined
|
||||||
# using `Object#(class_)property` or `Object#(class_)getter` macros.
|
# using `Object#(class_)property` or `Object#(class_)getter` macros.
|
||||||
#
|
#
|
||||||
|
@ -23,7 +23,7 @@ module Ameba::Rule::Style
|
||||||
# YAML configuration example:
|
# YAML configuration example:
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# Style/QueryBoolMethods:
|
# Naming/QueryBoolMethods:
|
||||||
# Enabled: true
|
# Enabled: true
|
||||||
# ```
|
# ```
|
||||||
class QueryBoolMethods < Base
|
class QueryBoolMethods < Base
|
|
@ -1,4 +1,4 @@
|
||||||
module Ameba::Rule::Style
|
module Ameba::Rule::Naming
|
||||||
# A rule that enforces type names in camelcase manner.
|
# A rule that enforces type names in camelcase manner.
|
||||||
#
|
#
|
||||||
# For example, these are considered valid:
|
# For example, these are considered valid:
|
||||||
|
@ -48,7 +48,7 @@ module Ameba::Rule::Style
|
||||||
# YAML configuration example:
|
# YAML configuration example:
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# Style/TypeNames:
|
# Naming/TypeNames:
|
||||||
# Enabled: true
|
# Enabled: true
|
||||||
# ```
|
# ```
|
||||||
class TypeNames < Base
|
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.
|
# A rule that enforces variable names to be in underscored case.
|
||||||
#
|
#
|
||||||
# For example, these variable names are considered valid:
|
# For example, these variable names are considered valid:
|
||||||
|
@ -19,7 +19,7 @@ module Ameba::Rule::Style
|
||||||
# YAML configuration example:
|
# YAML configuration example:
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# Style/VariableNames:
|
# Naming/VariableNames:
|
||||||
# Enabled: true
|
# Enabled: true
|
||||||
# ```
|
# ```
|
||||||
class VariableNames < Base
|
class VariableNames < Base
|
Loading…
Reference in a new issue