mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Remove one-line methods
Unnecessary level of abstraction
This commit is contained in:
parent
3a71b86193
commit
a059ade305
4 changed files with 2 additions and 22 deletions
|
@ -36,16 +36,6 @@ module Ameba::AST
|
||||||
end
|
end
|
||||||
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
|
describe "#node_source" do
|
||||||
it "returns original source of the node" do
|
it "returns original source of the node" do
|
||||||
s = %(
|
s = %(
|
||||||
|
|
|
@ -27,16 +27,6 @@ module Ameba::AST::Util
|
||||||
end
|
end
|
||||||
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.
|
# Returns a source code for the current node.
|
||||||
# This method uses `node.location` and `node.end_location`
|
# This method uses `node.location` and `node.end_location`
|
||||||
# to determine and cut a piece of source of the node.
|
# to determine and cut a piece of source of the node.
|
||||||
|
|
|
@ -30,7 +30,7 @@ module Ameba::Rule::Lint
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(source, node : Crystal::StringInterpolation)
|
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
|
return unless found
|
||||||
issue_for node, MSG
|
issue_for node, MSG
|
||||||
end
|
end
|
||||||
|
|
|
@ -102,7 +102,7 @@ module Ameba::Rule::Style
|
||||||
|
|
||||||
private def begin_exprs_in_handler?(handler)
|
private def begin_exprs_in_handler?(handler)
|
||||||
if (body = handler.body).is_a?(Crystal::Expressions)
|
if (body = handler.body).is_a?(Crystal::Expressions)
|
||||||
exception_handler?(body.expressions.first)
|
body.expressions.first.is_a?(Crystal::ExceptionHandler)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue