Sha256: 61432374196b85fd3cf933c3213c2e0cff488c5a092cb3c5106dbb34e9205e58

Contents?: true

Size: 871 Bytes

Versions: 2

Compression:

Stored size: 871 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for usage of the %W() syntax when %w() would do.
      class UnneededCapitalW < Cop
        include PercentLiteral

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

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

        private

        def on_percent_literal(node)
          node.children.each do |string|
            if string.type == :dstr ||
               string.loc.expression.source =~ StringHelp::ESCAPED_CHAR_REGEXP
              return
            end
          end
          add_offense(node, :expression)
        end

        def autocorrect(node)
          @corrections << lambda do |corrector|
            corrector.replace(node.loc.begin, '%w(')
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.27.1 lib/rubocop/cop/style/unneeded_capital_w.rb
rubocop-0.27.0 lib/rubocop/cop/style/unneeded_capital_w.rb