Sha256: fe79ee7c47219261a18a4d8d8ed697d03b5412e1bd0045962abedcfa32746b6a

Contents?: true

Size: 1.93 KB

Versions: 13

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for trailing comma in array literals.
      # The configuration options are:
      #
      # * `consistent_comma`: Requires a comma after the
      # last item of all non-empty, multiline array literals.
      # * `comma`: Requires a comma after last item in an array,
      # but only when each item is on its own line.
      # * `no_comma`: Does not requires a comma after the
      # last item in an array
      #
      # @example EnforcedStyleForMultiline: consistent_comma
      #   # bad
      #   a = [1, 2,]
      #
      #   # good
      #   a = [1, 2]
      #
      #   # good
      #   a = [
      #     1, 2,
      #     3,
      #   ]
      #
      #   # good
      #   a = [
      #     1, 2, 3,
      #   ]
      #
      #   # good
      #   a = [
      #     1,
      #     2,
      #   ]
      #
      # @example EnforcedStyleForMultiline: comma
      #   # bad
      #   a = [1, 2,]
      #
      #   # good
      #   a = [1, 2]
      #
      #   # bad
      #   a = [
      #     1, 2,
      #     3,
      #   ]
      #
      #   # good
      #   a = [
      #     1, 2,
      #     3
      #   ]
      #
      #   # bad
      #   a = [
      #     1, 2, 3,
      #   ]
      #
      #   # good
      #   a = [
      #     1, 2, 3
      #   ]
      #
      #   # 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

13 entries across 13 versions & 3 rubygems

Version Path
rubocop-0.89.1 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.89.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.88.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.87.1 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.87.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.86.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.85.1 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-0.85.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb