Remove one-line methods

Unnecessary level of abstraction
This commit is contained in:
Vitalii Elenhaupt 2019-03-23 19:25:03 +02:00
parent 3a71b86193
commit a059ade305
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
4 changed files with 2 additions and 22 deletions

View file

@ -36,16 +36,6 @@ module Ameba::AST
end
end
describe "#string_literal?" do
it "returns true if node is a string literal" do
subject.string_literal?(Crystal::StringLiteral.new "").should be_true
end
it "returns false if node is not a string literal" do
subject.string_literal?(Crystal::Nop.new).should be_false
end
end
describe "#node_source" do
it "returns original source of the node" do
s = %(

View file

@ -27,16 +27,6 @@ module Ameba::AST::Util
end
end
# Returns true if current `node` is a string literal, false otherwise.
def string_literal?(node)
node.is_a? Crystal::StringLiteral
end
# Returns true if current `node` is an exception handler, false otherwise.
def exception_handler?(node)
node.is_a? Crystal::ExceptionHandler
end
# Returns a source code for the current node.
# This method uses `node.location` and `node.end_location`
# to determine and cut a piece of source of the node.

View file

@ -30,7 +30,7 @@ module Ameba::Rule::Lint
end
def test(source, node : Crystal::StringInterpolation)
found = node.expressions.any? { |e| !string_literal?(e) && literal?(e) }
found = node.expressions.any? { |e| !e.is_a?(Crystal::StringLiteral) && literal?(e) }
return unless found
issue_for node, MSG
end

View file

@ -102,7 +102,7 @@ module Ameba::Rule::Style
private def begin_exprs_in_handler?(handler)
if (body = handler.body).is_a?(Crystal::Expressions)
exception_handler?(body.expressions.first)
body.expressions.first.is_a?(Crystal::ExceptionHandler)
end
end