Sha256: 943a397231b8b1cafc8943e9e5a130343fdc68941e6ecaa4ade04a2045acb9d2

Contents?: true

Size: 1.15 KB

Versions: 6835

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for usage of the %W() syntax when %w() would do.
      #
      # @example
      #   # bad
      #   %W(cat dog pig)
      #   %W[door wall floor]
      #
      #   # good
      #   %w/swim run bike/
      #   %w[shirt pants shoes]
      #   %W(apple #{fruit} grape)
      class UnneededCapitalW < Cop
        include PercentLiteral

        MSG = 'Do not use `%W` unless interpolation is needed. ' \
              'If not, use `%w`.'.freeze

        def on_array(node)
          process(node, '%W')
        end

        def autocorrect(node)
          lambda do |corrector|
            src = node.loc.begin.source
            corrector.replace(node.loc.begin, src.tr('W', 'w'))
          end
        end

        private

        def on_percent_literal(node)
          return if requires_interpolation?(node)

          add_offense(node)
        end

        def requires_interpolation?(node)
          node.child_nodes.any? do |string|
            string.dstr_type? ||
              double_quotes_required?(string.source)
          end
        end
      end
    end
  end
end

Version data entries

6,835 entries across 6,829 versions & 26 rubygems

Version Path
ory-client-0.0.1.alpha78 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha77 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha76 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha75 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha74 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha73 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha72 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha71 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha70 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha69 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha68 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha67 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha66 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-oathkeeper-client-0.38.19.beta1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-oathkeeper-client-0.38.18.beta1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-oathkeeper-client-0.38.17.beta1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
avalara_sdk-2.4.7 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha58 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha57 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb
ory-client-0.0.1.alpha56 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/unneeded_capital_w.rb