Skip to content

Commit

Permalink
Remove one-line methods
Browse files Browse the repository at this point in the history
Unnecessary level of abstraction
  • Loading branch information
veelenga committed Mar 23, 2019
1 parent 3a71b86 commit a059ade
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 22 deletions.
10 changes: 0 additions & 10 deletions spec/ameba/ast/util_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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 = %(
Expand Down
10 changes: 0 additions & 10 deletions src/ameba/ast/util.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/ameba/rule/lint/literal_in_interpolation.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ameba/rule/style/redundant_begin.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a059ade

Please sign in to comment.