Sha256: e0c61cf69917fb1d485316d30cfc9decb3fdf5e3d4746ce777addf8223f8240d

Contents?: true

Size: 870 Bytes

Versions: 4

Compression:

Stored size: 870 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

4 entries across 4 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/unneeded_capital_w.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/unneeded_capital_w.rb
rubocop-0.26.1 lib/rubocop/cop/style/unneeded_capital_w.rb
rubocop-0.26.0 lib/rubocop/cop/style/unneeded_capital_w.rb