mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Crystal 0.29 fixes (#109)
* Fixes vs crystal head * Use crystal nightly * Remove trailing ? from local variable * Do not use ? in the lhs ref https://github.com/crystal-lang/crystal/issues/6685#issuecomment-419758587 * Upgrade to crystal 0.29.0 (warnings free) (#108) * Remove trailing ? from local variable (take 2) * Fix Time.now deprecation warnings * Remove Crystal nightly
This commit is contained in:
parent
633a08f9c7
commit
ffa5dc9b4c
10 changed files with 36 additions and 36 deletions
|
@ -228,7 +228,7 @@ module Ameba::Rule::Lint
|
||||||
it "does not report if global var" do
|
it "does not report if global var" do
|
||||||
s = Source.new %(
|
s = Source.new %(
|
||||||
def method
|
def method
|
||||||
$? = 3
|
$1 = 3
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
subject.catch(s).should be_valid
|
subject.catch(s).should be_valid
|
||||||
|
|
|
@ -66,8 +66,8 @@ module Ameba::Rule::Performance
|
||||||
issue = s.issues.first
|
issue = s.issues.first
|
||||||
|
|
||||||
issue.rule.should_not be_nil
|
issue.rule.should_not be_nil
|
||||||
issue.location.to_s.should eq "source.cr:1:4"
|
issue.location.to_s.should eq "source.cr:2:4"
|
||||||
issue.end_location.to_s.should eq "source.cr:1:25"
|
issue.end_location.to_s.should eq "source.cr:2:25"
|
||||||
issue.message.should eq "Use `count {...}` instead of `reject {...}.size`."
|
issue.message.should eq "Use `count {...}` instead of `reject {...}.size`."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,12 +56,12 @@ module Ameba::AST::Util
|
||||||
# Returns true if node is a flow command, false - otherwise.
|
# Returns true if node is a flow command, false - otherwise.
|
||||||
# Node represents a flow command if it is a control expression,
|
# Node represents a flow command if it is a control expression,
|
||||||
# or special call node that interrupts execution (i.e. raise, exit, abort).
|
# or special call node that interrupts execution (i.e. raise, exit, abort).
|
||||||
def flow_command?(node, in_loop?)
|
def flow_command?(node, in_loop)
|
||||||
case node
|
case node
|
||||||
when Crystal::Return
|
when Crystal::Return
|
||||||
true
|
true
|
||||||
when Crystal::Break, Crystal::Next
|
when Crystal::Break, Crystal::Next
|
||||||
in_loop?
|
in_loop
|
||||||
when Crystal::Call
|
when Crystal::Call
|
||||||
raise?(node) || exit?(node) || abort?(node)
|
raise?(node) || exit?(node) || abort?(node)
|
||||||
else
|
else
|
||||||
|
@ -95,31 +95,31 @@ module Ameba::AST::Util
|
||||||
#
|
#
|
||||||
# That's because not all branches return(i.e. `else` is missing).
|
# That's because not all branches return(i.e. `else` is missing).
|
||||||
#
|
#
|
||||||
def flow_expression?(node, in_loop? = false)
|
def flow_expression?(node, in_loop = false)
|
||||||
return true if flow_command? node, in_loop?
|
return true if flow_command? node, in_loop
|
||||||
|
|
||||||
case node
|
case node
|
||||||
when Crystal::If, Crystal::Unless
|
when Crystal::If, Crystal::Unless
|
||||||
flow_expressions? [node.then, node.else], in_loop?
|
flow_expressions? [node.then, node.else], in_loop
|
||||||
when Crystal::BinaryOp
|
when Crystal::BinaryOp
|
||||||
flow_expression? node.left, in_loop?
|
flow_expression? node.left, in_loop
|
||||||
when Crystal::Case
|
when Crystal::Case
|
||||||
flow_expressions? [node.whens, node.else].flatten, in_loop?
|
flow_expressions? [node.whens, node.else].flatten, in_loop
|
||||||
when Crystal::ExceptionHandler
|
when Crystal::ExceptionHandler
|
||||||
flow_expressions? [node.else || node.body, node.rescues].flatten, in_loop?
|
flow_expressions? [node.else || node.body, node.rescues].flatten, in_loop
|
||||||
when Crystal::While, Crystal::Until
|
when Crystal::While, Crystal::Until
|
||||||
flow_expression? node.body, in_loop?
|
flow_expression? node.body, in_loop
|
||||||
when Crystal::Rescue, Crystal::When
|
when Crystal::Rescue, Crystal::When
|
||||||
flow_expression? node.body, in_loop?
|
flow_expression? node.body, in_loop
|
||||||
when Crystal::Expressions
|
when Crystal::Expressions
|
||||||
node.expressions.any? { |exp| flow_expression? exp, in_loop? }
|
node.expressions.any? { |exp| flow_expression? exp, in_loop }
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private def flow_expressions?(nodes, in_loop?)
|
private def flow_expressions?(nodes, in_loop)
|
||||||
nodes.all? { |exp| flow_expression? exp, in_loop? }
|
nodes.all? { |exp| flow_expression? exp, in_loop }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if node represents `raise` method call.
|
# Returns true if node represents `raise` method call.
|
||||||
|
|
|
@ -50,8 +50,8 @@ class Ameba::Config
|
||||||
# config = Ameba::Config.load
|
# config = Ameba::Config.load
|
||||||
# ```
|
# ```
|
||||||
#
|
#
|
||||||
def self.load(path = PATH, colors? = true)
|
def self.load(path = PATH, colors = true)
|
||||||
Colorize.enabled = colors?
|
Colorize.enabled = colors
|
||||||
content = File.exists?(path) ? File.read path : ""
|
content = File.exists?(path) ? File.read path : ""
|
||||||
Config.new YAML.parse(content)
|
Config.new YAML.parse(content)
|
||||||
rescue e
|
rescue e
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Ameba::Formatter
|
||||||
|
|
||||||
# Reports a message when inspection is started.
|
# Reports a message when inspection is started.
|
||||||
def started(sources)
|
def started(sources)
|
||||||
@started_at = Time.now # Time.monotonic
|
@started_at = Time.utc # Time.monotonic
|
||||||
|
|
||||||
output << started_message(sources.size)
|
output << started_message(sources.size)
|
||||||
end
|
end
|
||||||
|
@ -45,7 +45,7 @@ module Ameba::Formatter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
output << finished_in_message(@started_at, Time.now) # Time.monotonic
|
output << finished_in_message(@started_at, Time.utc) # Time.monotonic
|
||||||
output << final_message(sources, failed_sources)
|
output << final_message(sources, failed_sources)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ module Ameba::Formatter
|
||||||
private def header
|
private def header
|
||||||
<<-HEADER
|
<<-HEADER
|
||||||
# This configuration file was generated by `ameba --gen-config`
|
# This configuration file was generated by `ameba --gen-config`
|
||||||
# on #{Time.utc_now} using Ameba version #{VERSION}.
|
# on #{Time.utc} using Ameba version #{VERSION}.
|
||||||
# The point is for the user to remove these configuration records
|
# The point is for the user to remove these configuration records
|
||||||
# one by one as the reported problems are removed from the code base.
|
# one by one as the reported problems are removed from the code base.
|
||||||
|
|
||||||
|
|
|
@ -94,11 +94,11 @@ module Ameba
|
||||||
end
|
end
|
||||||
|
|
||||||
private def commented_out?(line)
|
private def commented_out?(line)
|
||||||
commented? = false
|
commented = false
|
||||||
|
|
||||||
lexer = Crystal::Lexer.new(line).tap { |l| l.comments_enabled = true }
|
lexer = Crystal::Lexer.new(line).tap { |l| l.comments_enabled = true }
|
||||||
Tokenizer.new(lexer).run { |t| commented? = true if t.type == :COMMENT }
|
Tokenizer.new(lexer).run { |t| commented = true if t.type == :COMMENT }
|
||||||
commented?
|
commented
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,11 +33,11 @@ module Ameba::Rule::Lint
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(source, node : Crystal::Call)
|
def test(source, node : Crystal::Call)
|
||||||
comparison? = %w(== != ===).includes?(node.name)
|
comparison = %w(== != ===).includes?(node.name)
|
||||||
to_boolean? = node.args.first?.try &.is_a?(Crystal::BoolLiteral) ||
|
to_boolean = node.args.first?.try &.is_a?(Crystal::BoolLiteral) ||
|
||||||
node.obj.is_a?(Crystal::BoolLiteral)
|
node.obj.is_a?(Crystal::BoolLiteral)
|
||||||
|
|
||||||
return unless comparison? && to_boolean?
|
return unless comparison && to_boolean
|
||||||
|
|
||||||
issue_for node, MSG
|
issue_for node, MSG
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,9 +53,9 @@ module Ameba::Rule::Style
|
||||||
return if (expected = node.name.underscore) == node.name
|
return if (expected = node.name.underscore) == node.name
|
||||||
|
|
||||||
line_number = node.location.try &.line_number
|
line_number = node.location.try &.line_number
|
||||||
column_number = node.name_column_number
|
column_number = node.name_location.try &.column_number
|
||||||
|
|
||||||
return unless line_number
|
return if line_number.nil? || column_number.nil?
|
||||||
|
|
||||||
issue_for(
|
issue_for(
|
||||||
{line_number, column_number},
|
{line_number, column_number},
|
||||||
|
|
|
@ -108,7 +108,7 @@ module Ameba::Rule::Style
|
||||||
|
|
||||||
private def def_redundant_begin?(code)
|
private def def_redundant_begin?(code)
|
||||||
lexer = Crystal::Lexer.new code
|
lexer = Crystal::Lexer.new code
|
||||||
in_body? = in_argument_list? = false
|
in_body = in_argument_list = false
|
||||||
loop do
|
loop do
|
||||||
token = lexer.next_token
|
token = lexer.next_token
|
||||||
|
|
||||||
|
@ -116,16 +116,16 @@ module Ameba::Rule::Style
|
||||||
when :EOF, :"->"
|
when :EOF, :"->"
|
||||||
break
|
break
|
||||||
when :IDENT
|
when :IDENT
|
||||||
return token.value == :begin if in_body?
|
return token.value == :begin if in_body
|
||||||
when :"("
|
when :"("
|
||||||
in_argument_list? = true
|
in_argument_list = true
|
||||||
when :")"
|
when :")"
|
||||||
in_argument_list? = false
|
in_argument_list = false
|
||||||
when :NEWLINE
|
when :NEWLINE
|
||||||
in_body? = true unless in_argument_list?
|
in_body = true unless in_argument_list
|
||||||
when :SPACE
|
when :SPACE
|
||||||
else
|
else
|
||||||
return false if in_body?
|
return false if in_body
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue