diff --git a/spec/ameba/rule/lint/useless_assign_spec.cr b/spec/ameba/rule/lint/useless_assign_spec.cr index 79d6619f..5ee62329 100644 --- a/spec/ameba/rule/lint/useless_assign_spec.cr +++ b/spec/ameba/rule/lint/useless_assign_spec.cr @@ -228,7 +228,7 @@ module Ameba::Rule::Lint it "does not report if global var" do s = Source.new %( def method - $? = 3 + $1 = 3 end ) subject.catch(s).should be_valid diff --git a/spec/ameba/rule/performance/size_after_filter_spec.cr b/spec/ameba/rule/performance/size_after_filter_spec.cr index bfd67336..ccf958d8 100644 --- a/spec/ameba/rule/performance/size_after_filter_spec.cr +++ b/spec/ameba/rule/performance/size_after_filter_spec.cr @@ -66,8 +66,8 @@ module Ameba::Rule::Performance issue = s.issues.first issue.rule.should_not be_nil - issue.location.to_s.should eq "source.cr:1:4" - issue.end_location.to_s.should eq "source.cr:1:25" + issue.location.to_s.should eq "source.cr:2:4" + issue.end_location.to_s.should eq "source.cr:2:25" issue.message.should eq "Use `count {...}` instead of `reject {...}.size`." end end diff --git a/src/ameba/ast/util.cr b/src/ameba/ast/util.cr index 32a83b2a..091ba00f 100644 --- a/src/ameba/ast/util.cr +++ b/src/ameba/ast/util.cr @@ -56,12 +56,12 @@ module Ameba::AST::Util # Returns true if node is a flow command, false - otherwise. # Node represents a flow command if it is a control expression, # 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 when Crystal::Return true when Crystal::Break, Crystal::Next - in_loop? + in_loop when Crystal::Call raise?(node) || exit?(node) || abort?(node) else @@ -95,31 +95,31 @@ module Ameba::AST::Util # # That's because not all branches return(i.e. `else` is missing). # - def flow_expression?(node, in_loop? = false) - return true if flow_command? node, in_loop? + def flow_expression?(node, in_loop = false) + return true if flow_command? node, in_loop case node when Crystal::If, Crystal::Unless - flow_expressions? [node.then, node.else], in_loop? + flow_expressions? [node.then, node.else], in_loop when Crystal::BinaryOp - flow_expression? node.left, in_loop? + flow_expression? node.left, in_loop when Crystal::Case - flow_expressions? [node.whens, node.else].flatten, in_loop? + flow_expressions? [node.whens, node.else].flatten, in_loop 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 - flow_expression? node.body, in_loop? + flow_expression? node.body, in_loop when Crystal::Rescue, Crystal::When - flow_expression? node.body, in_loop? + flow_expression? node.body, in_loop when Crystal::Expressions - node.expressions.any? { |exp| flow_expression? exp, in_loop? } + node.expressions.any? { |exp| flow_expression? exp, in_loop } else false end end - private def flow_expressions?(nodes, in_loop?) - nodes.all? { |exp| flow_expression? exp, in_loop? } + private def flow_expressions?(nodes, in_loop) + nodes.all? { |exp| flow_expression? exp, in_loop } end # Returns true if node represents `raise` method call. diff --git a/src/ameba/config.cr b/src/ameba/config.cr index d3c72040..d82c26af 100644 --- a/src/ameba/config.cr +++ b/src/ameba/config.cr @@ -50,8 +50,8 @@ class Ameba::Config # config = Ameba::Config.load # ``` # - def self.load(path = PATH, colors? = true) - Colorize.enabled = colors? + def self.load(path = PATH, colors = true) + Colorize.enabled = colors content = File.exists?(path) ? File.read path : "" Config.new YAML.parse(content) rescue e diff --git a/src/ameba/formatter/dot_formatter.cr b/src/ameba/formatter/dot_formatter.cr index b8b57ca1..6cf51631 100644 --- a/src/ameba/formatter/dot_formatter.cr +++ b/src/ameba/formatter/dot_formatter.cr @@ -10,7 +10,7 @@ module Ameba::Formatter # Reports a message when inspection is started. def started(sources) - @started_at = Time.now # Time.monotonic + @started_at = Time.utc # Time.monotonic output << started_message(sources.size) end @@ -45,7 +45,7 @@ module Ameba::Formatter 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) end diff --git a/src/ameba/formatter/todo_formatter.cr b/src/ameba/formatter/todo_formatter.cr index 857b42b6..e127d657 100644 --- a/src/ameba/formatter/todo_formatter.cr +++ b/src/ameba/formatter/todo_formatter.cr @@ -41,7 +41,7 @@ module Ameba::Formatter private def header <<-HEADER # 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 # one by one as the reported problems are removed from the code base. diff --git a/src/ameba/inline_comments.cr b/src/ameba/inline_comments.cr index 5aea7cfc..3dcaf97d 100644 --- a/src/ameba/inline_comments.cr +++ b/src/ameba/inline_comments.cr @@ -94,11 +94,11 @@ module Ameba end private def commented_out?(line) - commented? = false + commented = false lexer = Crystal::Lexer.new(line).tap { |l| l.comments_enabled = true } - Tokenizer.new(lexer).run { |t| commented? = true if t.type == :COMMENT } - commented? + Tokenizer.new(lexer).run { |t| commented = true if t.type == :COMMENT } + commented end end end diff --git a/src/ameba/rule/lint/comparison_to_boolean.cr b/src/ameba/rule/lint/comparison_to_boolean.cr index 3e595b51..f9a314c6 100644 --- a/src/ameba/rule/lint/comparison_to_boolean.cr +++ b/src/ameba/rule/lint/comparison_to_boolean.cr @@ -33,11 +33,11 @@ module Ameba::Rule::Lint end def test(source, node : Crystal::Call) - comparison? = %w(== != ===).includes?(node.name) - to_boolean? = node.args.first?.try &.is_a?(Crystal::BoolLiteral) || - node.obj.is_a?(Crystal::BoolLiteral) + comparison = %w(== != ===).includes?(node.name) + to_boolean = node.args.first?.try &.is_a?(Crystal::BoolLiteral) || + node.obj.is_a?(Crystal::BoolLiteral) - return unless comparison? && to_boolean? + return unless comparison && to_boolean issue_for node, MSG end diff --git a/src/ameba/rule/style/method_names.cr b/src/ameba/rule/style/method_names.cr index 5d424c4b..7ffd37f5 100644 --- a/src/ameba/rule/style/method_names.cr +++ b/src/ameba/rule/style/method_names.cr @@ -53,9 +53,9 @@ module Ameba::Rule::Style return if (expected = node.name.underscore) == node.name 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( {line_number, column_number}, diff --git a/src/ameba/rule/style/redundant_begin.cr b/src/ameba/rule/style/redundant_begin.cr index e21d1927..891da8e2 100644 --- a/src/ameba/rule/style/redundant_begin.cr +++ b/src/ameba/rule/style/redundant_begin.cr @@ -108,7 +108,7 @@ module Ameba::Rule::Style private def def_redundant_begin?(code) lexer = Crystal::Lexer.new code - in_body? = in_argument_list? = false + in_body = in_argument_list = false loop do token = lexer.next_token @@ -116,16 +116,16 @@ module Ameba::Rule::Style when :EOF, :"->" break when :IDENT - return token.value == :begin if in_body? + return token.value == :begin if in_body when :"(" - in_argument_list? = true + in_argument_list = true when :")" - in_argument_list? = false + in_argument_list = false when :NEWLINE - in_body? = true unless in_argument_list? + in_body = true unless in_argument_list when :SPACE else - return false if in_body? + return false if in_body end end end