Sha256: e82445728862e1d2e9bd74869011f4ecce77268d79f03aa6c0cbe5ce2fcfa563

Contents?: true

Size: 1.13 KB

Versions: 6834

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for trailing comma in hash literals.
      #
      # @example EnforcedStyleForMultiline: consistent_comma
      #   # bad
      #   a = { foo: 1, bar: 2, }
      #
      #   # good
      #   a = {
      #     foo: 1, bar: 2,
      #     qux: 3,
      #   }
      #
      #   # good
      #   a = {
      #     foo: 1,
      #     bar: 2,
      #   }
      #
      # @example EnforcedStyleForMultiline: comma
      #   # bad
      #   a = { foo: 1, bar: 2, }
      #
      #   # good
      #   a = {
      #     foo: 1,
      #     bar: 2,
      #   }
      #
      # @example EnforcedStyleForMultiline: no_comma (default)
      #   # bad
      #   a = { foo: 1, bar: 2, }
      #
      #   # good
      #   a = {
      #     foo: 1,
      #     bar: 2
      #   }
      class TrailingCommaInHashLiteral < Cop
        include TrailingComma

        def on_hash(node)
          check_literal(node, 'item of %<article>s hash')
        end

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

Version data entries

6,834 entries across 6,809 versions & 27 rubygems

Version Path
rubocop-0.59.2 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
rubocop-0.59.1 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
rubocop-0.59.0 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
rubocop-0.58.2 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
rubocop-0.58.1 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
rubocop-0.58.0 lib/rubocop/cop/style/trailing_comma_in_hash_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_hash_literal.rb
rubocop-0.57.2 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
rubocop-0.57.1 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
rubocop-0.57.0 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
rubocop-0.56.0 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
rubocop-0.55.0 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
rubocop-0.54.0 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb
rubocop-0.53.0 lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb