Style improvements

This commit is contained in:
Vitalii Elenhaupt 2017-11-01 19:30:08 +02:00
parent 628077066e
commit 996dc962db
No known key found for this signature in database
GPG Key ID: 7558EF3A4056C706
8 changed files with 10 additions and 7 deletions

View File

@ -11,6 +11,7 @@ module Ameba::Rules
# This is because these expressions evaluate to `true` or `false`, so you
# could get the same result by using either the variable directly,
# or negating the variable.
#
struct ComparisonToBoolean < Rule
def test(source)
AST::CallVisitor.new self, source

View File

@ -3,6 +3,7 @@ module Ameba::Rules
#
# This is because we don't want debugger breakpoints accidentally being
# committed into our codebase.
#
struct DebuggerStatement < Rule
def test(source)
AST::CallVisitor.new self, source

View File

@ -1,5 +1,6 @@
module Ameba::Rules
# A rule that disallows lines longer than 79 symbols.
#
struct LineLength < Rule
def test(source)
source.lines.each_with_index do |line, index|

View File

@ -12,6 +12,7 @@ module Ameba::Rules
# :ok
# end
# ```
#
struct LiteralInCondition < Rule
include AST::Util

View File

@ -6,7 +6,7 @@ module Ameba::Rules
#
# ```
# "Hello, #{:Ary}"
# "The are #{4} cats"
# "There are #{4} cats"
# ```
#
struct LiteralInInterpolation < Rule
@ -17,12 +17,8 @@ module Ameba::Rules
end
def test(source, node : Crystal::StringInterpolation)
has_literal = node.expressions.any? do |e|
!string_literal?(e) && literal?(e)
end
return unless has_literal
found = node.expressions.any? { |e| !string_literal?(e) && literal?(e) }
return unless found
source.error self, node.location.try &.line_number,
"Literal value found in interpolation"
end

View File

@ -1,5 +1,6 @@
module Ameba::Rules
# A rule that disallows trailing blank lines at the end of the source file.
#
struct TrailingBlankLines < Rule
def test(source)
if source.lines.size > 1 && source.lines[-2, 2].join.strip.empty?

View File

@ -1,5 +1,6 @@
module Ameba::Rules
# A rule that disallows trailing whitespaces.
#
struct TrailingWhitespace < Rule
def test(source)
source.lines.each_with_index do |line, index|

View File

@ -35,6 +35,7 @@ module Ameba::Rules
# :one
# end
# ```
#
struct UnlessElse < Rule
def test(source)
AST::UnlessVisitor.new self, source