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
 | 
			
		||||
      s = Source.new %(
 | 
			
		||||
        def method
 | 
			
		||||
          $? = 3
 | 
			
		||||
          $1 = 3
 | 
			
		||||
        end
 | 
			
		||||
      )
 | 
			
		||||
      subject.catch(s).should be_valid
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue