Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move naming-related rules into its own group #413

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/ameba/base_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Ameba::Rule
Layout
Lint
Metrics
Naming
Performance
Style
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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}
CRYSTAL
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]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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}
CRYSTAL
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../../spec_helper"

module Ameba::Rule::Style
module Ameba::Rule::Naming
subject = PredicateName.new

describe PredicateName do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../../spec_helper"

module Ameba::Rule::Style
module Ameba::Rule::Naming
subject = QueryBoolMethods.new

describe QueryBoolMethods do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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}
CRYSTAL
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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}
CRYSTAL
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
Expand Down
2 changes: 1 addition & 1 deletion spec/ameba/runner_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -18,7 +18,7 @@ module Ameba::Rule::Style
# YAML configuration example:
#
# ```
# Style/ConstantNames:
# Naming/ConstantNames:
# Enabled: true
# ```
class ConstantNames < Base
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -34,7 +34,7 @@ module Ameba::Rule::Style
# YAML configuration example:
#
# ```
# Style/MethodNames:
# Naming/MethodNames:
# Enabled: true
# ```
class MethodNames < Base
Expand Down
Original file line number Diff line number Diff line change
@@ -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?`).
Expand All @@ -20,7 +20,7 @@ module Ameba::Rule::Style
# YAML configuration example:
#
# ```
# Style/PredicateName:
# Naming/PredicateName:
# Enabled: true
# ```
class PredicateName < Base
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
#
Expand All @@ -23,7 +23,7 @@ module Ameba::Rule::Style
# YAML configuration example:
#
# ```
# Style/QueryBoolMethods:
# Naming/QueryBoolMethods:
# Enabled: true
# ```
class QueryBoolMethods < Base
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -48,7 +48,7 @@ module Ameba::Rule::Style
# YAML configuration example:
#
# ```
# Style/TypeNames:
# Naming/TypeNames:
# Enabled: true
# ```
class TypeNames < Base
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -19,7 +19,7 @@ module Ameba::Rule::Style
# YAML configuration example:
#
# ```
# Style/VariableNames:
# Naming/VariableNames:
# Enabled: true
# ```
class VariableNames < Base
Expand Down
Loading