Sha256: a56566a982c0fa48f7649ed8d181a26c621011c18a7556bffbc8bef779adb627

Contents?: true

Size: 922 Bytes

Versions: 3

Compression:

Stored size: 922 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|
            src = node.loc.begin.source
            corrector.replace(node.loc.begin, src.tr('W', 'w'))
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.29.1 lib/rubocop/cop/style/unneeded_capital_w.rb
rubocop-0.29.0 lib/rubocop/cop/style/unneeded_capital_w.rb
rubocop-0.28.0 lib/rubocop/cop/style/unneeded_capital_w.rb