Sha256: a27f95dad6faed5c24136adb4022826200d53e67b78b56333f0caf05c1a60cf1

Contents?: true

Size: 1.87 KB

Versions: 11

Compression:

Stored size: 1.87 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 require 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 < Base
        include TrailingComma
        extend AutoCorrector

        def on_array(node)
          return unless node.square_brackets?

          check_literal(node, 'item of %<article>s array')
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-1.29.1 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-1.29.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-1.28.2 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-1.28.1 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-1.28.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-1.27.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-1.26.1 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb
rubocop-1.26.0 lib/rubocop/cop/style/trailing_comma_in_array_literal.rb