Skip to content

Commit

Permalink
[Fix #4039] Change Style/PercentLiteralDelimiters default configura…
Browse files Browse the repository at this point in the history
…tion to match Style Guide update

The Style Guide was changed to [prefer square brackets for word- and
symbol array literals](rubocop/ruby-style-guide#526).

This change brings RuboCop's config back in line.
  • Loading branch information
Drenmi authored and bbatsov committed Apr 2, 2017
1 parent ef729df commit 022e732
Show file tree
Hide file tree
Showing 193 changed files with 557 additions and 551 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* [#4219](https://github.com/bbatsov/rubocop/issues/4219): Add a link to style guide for `Style/IndentationConsistency` cop. ([@pocke][])
* [#4168](https://github.com/bbatsov/rubocop/issues/4168): Removed `-n` option. ([@sadovnik][])
* [#4039](https://github.com/bbatsov/rubocop/pull/4039): Change `Style/PercentLiteralDelimiters` default configuration to match Style Guide update. ([@drenmi][])

### Bug fixes

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end
desc 'Run RuboCop over itself'
RuboCop::RakeTask.new(:internal_investigation)

task default: %i(spec ascii_spec internal_investigation)
task default: %i[spec ascii_spec internal_investigation]

require 'yard'
YARD::Rake::YardocTask.new
Expand All @@ -43,7 +43,7 @@ task :repl do
end

desc 'Benchmark a cop on given source file/dir'
task :bench_cop, %i(cop srcpath times) do |_task, args|
task :bench_cop, %i[cop srcpath times] do |_task, args|
require 'benchmark'
require 'rubocop'
include RuboCop
Expand Down
4 changes: 4 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,11 @@ Style/PercentLiteralDelimiters:
# an individual key
PreferredDelimiters:
default: ()
'%i': '[]'
'%I': '[]'
'%r': '{}'
'%w': '[]'
'%W': '[]'

Style/PercentQLiterals:
EnforcedStyle: lower_case_q
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/ast/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class Builder < Parser::Builders::Default
PairNode => [:pair],
ResbodyNode => [:resbody],
SendNode => [:send],
UntilNode => %i(until until_post),
UntilNode => %i[until until_post],
WhenNode => [:when],
WhileNode => %i(while while_post)
WhileNode => %i[while while_post]
}.freeze

# Generates {Node} from the given information.
Expand Down
28 changes: 14 additions & 14 deletions lib/rubocop/ast/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ module AST
class Node < Parser::AST::Node # rubocop:disable Metrics/ClassLength
include RuboCop::AST::Sexp

COMPARISON_OPERATORS = %i(! == === != <= >= > < <=>).freeze
COMPARISON_OPERATORS = %i[! == === != <= >= > < <=>].freeze

TRUTHY_LITERALS = %i(str dstr xstr int float sym dsym array
TRUTHY_LITERALS = %i[str dstr xstr int float sym dsym array
hash regexp true irange erange complex
rational regopt).freeze
FALSEY_LITERALS = %i(false nil).freeze
rational regopt].freeze
FALSEY_LITERALS = %i[false nil].freeze
LITERALS = (TRUTHY_LITERALS + FALSEY_LITERALS).freeze
COMPOSITE_LITERALS = %i(dstr xstr dsym array hash irange
erange regexp).freeze
COMPOSITE_LITERALS = %i[dstr xstr dsym array hash irange
erange regexp].freeze
BASIC_LITERALS = (LITERALS - COMPOSITE_LITERALS).freeze
MUTABLE_LITERALS = %i(str dstr xstr array hash).freeze
MUTABLE_LITERALS = %i[str dstr xstr array hash].freeze
IMMUTABLE_LITERALS = (LITERALS - MUTABLE_LITERALS).freeze

VARIABLES = %i(ivar gvar cvar lvar).freeze
REFERENCES = %i(nth_ref back_ref).freeze
KEYWORDS = %i(alias and break case class def defs defined?
VARIABLES = %i[ivar gvar cvar lvar].freeze
REFERENCES = %i[nth_ref back_ref].freeze
KEYWORDS = %i[alias and break case class def defs defined?
kwbegin do else ensure for if module next
not or postexe redo rescue retry return self
super zsuper then undef until when while
yield).freeze
OPERATOR_KEYWORDS = %i(and or).freeze
SPECIAL_KEYWORDS = %w(__FILE__ __LINE__ __ENCODING__).freeze
yield].freeze
OPERATOR_KEYWORDS = %i[and or].freeze
SPECIAL_KEYWORDS = %w[__FILE__ __LINE__ __ENCODING__].freeze

# def_matcher can be used to define a pattern-matching method on Node
class << self
Expand Down Expand Up @@ -361,7 +361,7 @@ def immutable_literal?
IMMUTABLE_LITERALS.include?(type)
end

%i(literal basic_literal).each do |kind|
%i[literal basic_literal].each do |kind|
recursive_kind = :"recursive_#{kind}?"
kind_filter = :"#{kind}?"
define_method(recursive_kind) do
Expand Down
16 changes: 8 additions & 8 deletions lib/rubocop/ast/traversal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ def walk(node)
nil
end

NO_CHILD_NODES = %i(true false nil int float complex
NO_CHILD_NODES = %i[true false nil int float complex
rational str sym regopt self lvar
ivar cvar gvar nth_ref back_ref cbase
arg restarg blockarg shadowarg
kwrestarg zsuper lambda redo retry).freeze
ONE_CHILD_NODE = %i(splat kwsplat block_pass not break next
kwrestarg zsuper lambda redo retry].freeze
ONE_CHILD_NODE = %i[splat kwsplat block_pass not break next
preexe postexe match_current_line defined?
arg_expr).freeze
MANY_CHILD_NODES = %i(dstr dsym xstr regexp array hash pair
arg_expr].freeze
MANY_CHILD_NODES = %i[dstr dsym xstr regexp array hash pair
irange erange mlhs masgn or_asgn and_asgn
undef alias args super yield or and
while_post until_post iflipflop eflipflop
match_with_lvasgn begin kwbegin return).freeze
SECOND_CHILD_ONLY = %i(lvasgn ivasgn cvasgn gvasgn optarg kwarg
kwoptarg).freeze
match_with_lvasgn begin kwbegin return].freeze
SECOND_CHILD_ONLY = %i[lvasgn ivasgn cvasgn gvasgn optarg kwarg
kwoptarg].freeze

NO_CHILD_NODES.each do |type|
module_eval("def on_#{type}(node); end")
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module RuboCop
class Config
include PathUtil

COMMON_PARAMS = %w(Exclude Include Severity
AutoCorrect StyleGuide Details).freeze
COMMON_PARAMS = %w[Exclude Include Severity
AutoCorrect StyleGuide Details].freeze
# 2.1 is the oldest officially supported Ruby version.
DEFAULT_RUBY_VERSION = 2.1
KNOWN_RUBIES = [1.9, 2.0, 2.1, 2.2, 2.3, 2.4].freeze
Expand Down Expand Up @@ -178,7 +178,7 @@ def add_excludes_from_higher_level(highest_config)
end

def deprecation_check
%w(Exclude Include).each do |key|
%w[Exclude Include].each do |key|
plural = "#{key}s"
next unless for_all_cops[plural]

Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/config_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def merge(base_hash, derived_hash)

def base_configs(path, inherit_from)
configs = Array(inherit_from).compact.map do |f|
if f =~ /\A#{URI::Parser.new.make_regexp(%w(http https))}\z/
if f =~ /\A#{URI::Parser.new.make_regexp(%w[http https])}\z/
f = RemoteConfig.new(f, File.dirname(path)).file
else
f = File.expand_path(f, File.dirname(path))
Expand Down Expand Up @@ -187,7 +187,7 @@ def yaml_safe_load(yaml_code, filename)
if YAML.respond_to?(:safe_load) # Ruby 2.1+
if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
SafeYAML.load(yaml_code, filename,
whitelisted_tags: %w(!ruby/regexp))
whitelisted_tags: %w[!ruby/regexp])
else
YAML.safe_load(yaml_code, [Regexp, Symbol], [], false, filename)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/format_parameter_mismatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FormatParameterMismatch < Cop
SHOVEL = '<<'.freeze
PERCENT = '%'.freeze
PERCENT_PERCENT = '%%'.freeze
STRING_TYPES = %i(str dstr).freeze
STRING_TYPES = %i[str dstr].freeze
NAMED_INTERPOLATION = /%(?:<\w+>|\{\w+\})/

def on_send(node)
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/lint/inherit_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class InheritException < Cop
runtime_error: 'RuntimeError',
standard_error: 'StandardError'
}.freeze
ILLEGAL_CLASSES = %w(
ILLEGAL_CLASSES = %w[
Exception
SystemStackError
NoMemoryError
Expand All @@ -49,7 +49,7 @@ class InheritException < Cop
Interrupt
SignalException
SystemExit
).freeze
].freeze

def on_class(node)
_class, base_class, _body = *node
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/literal_in_condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def check_node(node)
def handle_node(node)
if node.literal?
add_offense(node, :expression)
elsif %i(send and or begin).include?(node.type)
elsif %i[send and or begin].include?(node.type)
check_node(node)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/literal_in_interpolation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Lint
# "result is 10"
class LiteralInInterpolation < Cop
MSG = 'Literal interpolation detected.'.freeze
COMPOSITE = %i(array hash pair irange erange).freeze
COMPOSITE = %i[array hash pair irange erange].freeze

def on_dstr(node)
node.each_child_node(:begin) do |begin_node|
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/unneeded_splat_expansion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class UnneededSplatExpansion < Cop
PERCENT_I = '%i'.freeze
PERCENT_CAPITAL_I = '%I'.freeze
ARRAY_NEW_PATTERN = '$(send (const nil :Array) :new ...)'.freeze
ASSIGNMENT_TYPES = %i(lvasgn ivasgn cvasgn gvasgn).freeze
ASSIGNMENT_TYPES = %i[lvasgn ivasgn cvasgn gvasgn].freeze

def_node_matcher :literal_expansion?, <<-PATTERN
(splat {$({str dstr int float array} ...) (block #{ARRAY_NEW_PATTERN} ...) #{ARRAY_NEW_PATTERN}} ...)
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/lint/unreachable_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module Lint
class UnreachableCode < Cop
MSG = 'Unreachable code detected.'.freeze

NODE_TYPES = %i(return next break retry redo).freeze
FLOW_COMMANDS = %i(throw raise fail).freeze
NODE_TYPES = %i[return next break retry redo].freeze
FLOW_COMMANDS = %i[throw raise fail].freeze

def on_begin(node)
expressions = *node
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/useless_comparison.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Lint
# x.top >= x.top
class UselessComparison < Cop
MSG = 'Comparison of something with itself detected.'.freeze
OPS = %w(== === != < > <= >= <=>).freeze
OPS = %w[== === != < > <= >= <=>].freeze

def_node_matcher :useless_comparison?,
"(send $_match {:#{OPS.join(' :')}} $_match)"
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/useless_setter_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UselessSetterCall < Cop
include OnMethodDef

MSG = 'Useless setter call to local variable `%s`.'.freeze
ASSIGNMENT_TYPES = %i(lvasgn ivasgn cvasgn gvasgn).freeze
ASSIGNMENT_TYPES = %i[lvasgn ivasgn cvasgn gvasgn].freeze

private

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/void.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Void < Cop
SELF_MSG = '`self` used in void context.'.freeze
DEFINED_MSG = '`%s` used in void context.'.freeze

OPS = %w(* / % + - == === != < > <= >= <=>).freeze
OPS = %w[* / % + - == === != < > <= >= <=>].freeze

def on_begin(node)
check_begin(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/metrics/abc_size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AbcSize < Cop

MSG = 'Assignment Branch Condition size for %s is too high. ' \
'[%.4g/%.4g]'.freeze
BRANCH_NODES = %i(send csend).freeze
BRANCH_NODES = %i[send csend].freeze
CONDITION_NODES = CyclomaticComplexity::COUNTED_NODES.freeze

private
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/metrics/block_nesting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module Metrics
class BlockNesting < Cop
include ConfigurableMax

NESTING_BLOCKS = %i(
NESTING_BLOCKS = %i[
case if while while_post
until until_post for resbody
).freeze
].freeze

def investigate(processed_source)
return unless processed_source.ast
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/metrics/cyclomatic_complexity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class CyclomaticComplexity < Cop
include MethodComplexity

MSG = 'Cyclomatic complexity for %s is too high. [%d/%d]'.freeze
COUNTED_NODES = %i(if while until for
rescue when and or).freeze
COUNTED_NODES = %i[if while until for
rescue when and or].freeze

private

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/metrics/parameter_lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def args_count(node)
if count_keyword_args?
node.children.size
else
node.children.count { |a| !%i(kwoptarg kwarg).include?(a.type) }
node.children.count { |a| !%i[kwoptarg kwarg].include?(a.type) }
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/metrics/perceived_complexity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class PerceivedComplexity < Cop
include MethodComplexity

MSG = 'Perceived complexity for %s is too high. [%d/%d]'.freeze
COUNTED_NODES = %i(if case while until
for rescue and or).freeze
COUNTED_NODES = %i[if case while until
for rescue and or].freeze

private

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/access_modifier_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def class_or_module_parent?(node)
if ancestor.block_type?
return true if ancestor.class_constructor?
elsif !ancestor.begin_type?
return %i(casgn sclass class module).include?(ancestor.type)
return %i[casgn sclass class module].include?(ancestor.type)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/def_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Cop
module DefNode
extend NodePattern::Macros

NON_PUBLIC_MODIFIERS = %w(private protected).freeze
NON_PUBLIC_MODIFIERS = %w[private protected].freeze

def non_public?(node)
non_public_modifier?(node.parent) ||
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/frozen_string_literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module FrozenStringLiteral

FROZEN_STRING_LITERAL = '# frozen_string_literal:'.freeze
FROZEN_STRING_LITERAL_ENABLED = '# frozen_string_literal: true'.freeze
FROZEN_STRING_LITERAL_TYPES = %i(str dstr).freeze
FROZEN_STRING_LITERAL_TYPES = %i[str dstr].freeze

def frozen_string_literal_comment_exists?
leading_comment_lines.any? do |line|
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/on_method_def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def modifier_and_def_on_same_line?(send_node)
!send_node.receiver &&
send_node.method_name != :def &&
send_node.arguments.one? &&
%i(def defs).include?(send_node.first_argument.type)
%i[def defs].include?(send_node.first_argument.type)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/mixin/percent_literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module RuboCop
module Cop
# Common functionality for handling percent literals.
module PercentLiteral
PERCENT_LITERAL_TYPES = %w(% %i %I %q %Q %r %s %w %W %x).freeze
PERCENT_LITERAL_TYPES = %w[% %i %I %q %Q %r %s %w %W %x].freeze

private

Expand Down Expand Up @@ -65,7 +65,7 @@ def autocorrect_words(word_nodes, escape, base_line_number, delimiters)

def ensure_valid_preferred_delimiters
invalid = preferred_delimiters_config.keys -
(PERCENT_LITERAL_TYPES + %w(default))
(PERCENT_LITERAL_TYPES + %w[default])
return if invalid.empty?

raise ArgumentError,
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/space_after_punctuation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def space_required_before?(token)
end

def allowed_type?(token)
%i(tRPAREN tRBRACK tPIPE).include?(token.type)
%i[tRPAREN tRBRACK tPIPE].include?(token.type)
end

def space_forbidden_before_rcurly?
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/unused_argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def check_argument(variable)
end

def autocorrect(node)
return if %i(kwarg kwoptarg).include?(node.type)
return if %i[kwarg kwoptarg].include?(node.type)

if node.blockarg_type?
lambda do |corrector|
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/offense.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Offense
include Comparable

# @api private
COMPARISON_ATTRIBUTES = %i(line column cop_name
message severity).freeze
COMPARISON_ATTRIBUTES = %i[line column cop_name
message severity].freeze

# @api public
#
Expand Down
Loading

0 comments on commit 022e732

Please sign in to comment.