Sha256: 7da22fc8a69a3459d82ee5bf0ae3dba3cc55f99492627cb88ac6ed6a0779d65f
Contents?: true
Size: 1.38 KB
Versions: 97
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Layout # Checks for unnecessary additional spaces inside the delimiters of # %i/%w/%x literals. # # @example # # # good # %i(foo bar baz) # # # bad # %w( foo bar baz ) # # # bad # %x( ls -l ) class SpaceInsidePercentLiteralDelimiters < Base include MatchRange include PercentLiteral extend AutoCorrector MSG = 'Do not use spaces inside percent literal delimiters.' BEGIN_REGEX = /\A( +)/.freeze END_REGEX = /(?<!\\)( +)\z/.freeze def on_array(node) process(node, '%i', '%I', '%w', '%W') end def on_xstr(node) process(node, '%x') end def on_percent_literal(node) add_offenses_for_unnecessary_spaces(node) end private def add_offenses_for_unnecessary_spaces(node) return unless node.single_line? regex_matches(node) do |match_range| add_offense(match_range) do |corrector| corrector.remove(match_range) end end end def regex_matches(node, &blk) [BEGIN_REGEX, END_REGEX].each do |regex| each_match_range(contents_range(node), regex, &blk) end end end end end end
Version data entries
97 entries across 91 versions & 9 rubygems