Sha256: c7e966a2c6c38c28a7b5feaee5a79158572c0b46547634b125e7fce55f86797f

Contents?: true

Size: 1.1 KB

Versions: 11

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for trailing comma in array literals.
      #
      # @example EnforcedStyleForMultiline: consistent_comma
      #   # bad
      #   a = [1, 2,]
      #
      #   # good
      #   a = [
      #     1, 2,
      #     3,
      #   ]
      #
      #   # good
      #   a = [
      #     1,
      #     2,
      #   ]
      #
      # @example EnforcedStyleForMultiline: comma
      #   # bad
      #   a = [1, 2,]
      #
      #   # good
      #   a = [
      #     1,
      #     2,
      #   ]
      #
      # @example EnforcedStyleForMultiline: no_comma (default)
      #   # bad
      #   a = [1, 2,]
      #
      #   # good
      #   a = [
      #     1,
      #     2
      #   ]
      class TrailingCommaInArrayLiteral < Cop
        include TrailingComma

        def on_array(node)
          return unless node.square_brackets?
          check_literal(node, 'item of %<article>s array')
        end

        def autocorrect(range)
          PunctuationCorrector.swap_comma(range)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
rubocop-0.58.2 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.58.1 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.58.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.57.2 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.57.1 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.57.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.56.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.55.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.54.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.53.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb