rubocop 0.59.2 → 0.60.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +3 -2
  3. data/config/default.yml +2960 -552
  4. data/lib/rubocop.rb +1 -0
  5. data/lib/rubocop/ast/builder.rb +29 -29
  6. data/lib/rubocop/ast/node.rb +29 -25
  7. data/lib/rubocop/ast/node/args_node.rb +1 -1
  8. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +1 -1
  9. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +26 -0
  10. data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +5 -1
  11. data/lib/rubocop/ast/node/pair_node.rb +8 -1
  12. data/lib/rubocop/ast/node/str_node.rb +1 -1
  13. data/lib/rubocop/cached_data.rb +2 -2
  14. data/lib/rubocop/config.rb +1 -1
  15. data/lib/rubocop/config_loader.rb +8 -0
  16. data/lib/rubocop/cop/autocorrect_logic.rb +7 -1
  17. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
  18. data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -1
  19. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +1 -1
  20. data/lib/rubocop/cop/generator.rb +10 -3
  21. data/lib/rubocop/cop/generator/require_file_injector.rb +1 -1
  22. data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +1 -1
  23. data/lib/rubocop/cop/layout/align_hash.rb +9 -1
  24. data/lib/rubocop/cop/layout/block_end_newline.rb +2 -4
  25. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +7 -7
  26. data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
  27. data/lib/rubocop/cop/layout/dot_position.rb +2 -2
  28. data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
  29. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +1 -2
  30. data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
  31. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +25 -25
  32. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +1 -1
  33. data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +1 -1
  34. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -1
  35. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
  36. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -1
  37. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +1 -1
  38. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +1 -1
  39. data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
  40. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
  41. data/lib/rubocop/cop/layout/indent_hash.rb +1 -1
  42. data/lib/rubocop/cop/layout/indent_heredoc.rb +2 -2
  43. data/lib/rubocop/cop/layout/indentation_consistency.rb +1 -1
  44. data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
  45. data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
  46. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +1 -1
  47. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
  48. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +84 -43
  49. data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -1
  50. data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
  51. data/lib/rubocop/cop/layout/space_around_operators.rb +3 -2
  52. data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +1 -1
  53. data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +2 -2
  54. data/lib/rubocop/cop/lint/ambiguous_operator.rb +5 -5
  55. data/lib/rubocop/cop/lint/assignment_in_condition.rb +10 -20
  56. data/lib/rubocop/cop/lint/ensure_return.rb +3 -0
  57. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +3 -3
  58. data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -1
  59. data/lib/rubocop/cop/lint/percent_string_array.rb +2 -2
  60. data/lib/rubocop/cop/lint/percent_symbol_array.rb +10 -7
  61. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +3 -4
  62. data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -2
  63. data/lib/rubocop/cop/lint/syntax.rb +3 -2
  64. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +3 -3
  65. data/lib/rubocop/cop/lint/useless_setter_call.rb +4 -7
  66. data/lib/rubocop/cop/metrics/abc_size.rb +1 -17
  67. data/lib/rubocop/cop/metrics/line_length.rb +14 -10
  68. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +45 -0
  69. data/lib/rubocop/cop/mixin/check_assignment.rb +12 -6
  70. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -1
  71. data/lib/rubocop/cop/mixin/configurable_formatting.rb +0 -2
  72. data/lib/rubocop/cop/mixin/configurable_max.rb +4 -2
  73. data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
  74. data/lib/rubocop/cop/mixin/configurable_numbering.rb +2 -2
  75. data/lib/rubocop/cop/mixin/hash_alignment.rb +32 -5
  76. data/lib/rubocop/cop/mixin/heredoc.rb +1 -1
  77. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -4
  78. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -1
  79. data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -0
  80. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  81. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
  82. data/lib/rubocop/cop/naming/constant_name.rb +1 -1
  83. data/lib/rubocop/cop/naming/file_name.rb +1 -1
  84. data/lib/rubocop/cop/naming/method_name.rb +2 -0
  85. data/lib/rubocop/cop/naming/variable_number.rb +1 -1
  86. data/lib/rubocop/cop/offense.rb +1 -1
  87. data/lib/rubocop/cop/performance/regexp_match.rb +1 -1
  88. data/lib/rubocop/cop/performance/sample.rb +3 -2
  89. data/lib/rubocop/cop/performance/start_with.rb +1 -1
  90. data/lib/rubocop/cop/performance/string_replacement.rb +1 -1
  91. data/lib/rubocop/cop/rails/date.rb +8 -8
  92. data/lib/rubocop/cop/rails/dynamic_find_by.rb +1 -1
  93. data/lib/rubocop/cop/rails/exit.rb +8 -9
  94. data/lib/rubocop/cop/rails/output_safety.rb +3 -3
  95. data/lib/rubocop/cop/rails/read_write_attribute.rb +5 -4
  96. data/lib/rubocop/cop/rails/refute_methods.rb +13 -13
  97. data/lib/rubocop/cop/rails/reversible_migration.rb +2 -1
  98. data/lib/rubocop/cop/rails/skips_model_validations.rb +17 -0
  99. data/lib/rubocop/cop/registry.rb +11 -2
  100. data/lib/rubocop/cop/style/and_or.rb +3 -3
  101. data/lib/rubocop/cop/style/collection_methods.rb +26 -0
  102. data/lib/rubocop/cop/style/empty_literal.rb +1 -1
  103. data/lib/rubocop/cop/style/encoding.rb +1 -1
  104. data/lib/rubocop/cop/style/even_odd.rb +2 -2
  105. data/lib/rubocop/cop/style/for.rb +3 -3
  106. data/lib/rubocop/cop/style/global_vars.rb +1 -1
  107. data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
  108. data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -13
  109. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  110. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  111. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +4 -7
  112. data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
  113. data/lib/rubocop/cop/style/module_function.rb +1 -1
  114. data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
  115. data/lib/rubocop/cop/style/mutable_constant.rb +15 -1
  116. data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
  117. data/lib/rubocop/cop/style/not.rb +2 -1
  118. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +6 -6
  119. data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
  120. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
  121. data/lib/rubocop/cop/style/one_line_conditional.rb +2 -2
  122. data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
  123. data/lib/rubocop/cop/style/proc.rb +1 -1
  124. data/lib/rubocop/cop/style/redundant_freeze.rb +10 -0
  125. data/lib/rubocop/cop/style/redundant_parentheses.rb +6 -2
  126. data/lib/rubocop/cop/style/redundant_self.rb +1 -1
  127. data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
  128. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  129. data/lib/rubocop/cop/style/ternary_parentheses.rb +4 -3
  130. data/lib/rubocop/cop/style/unneeded_condition.rb +2 -2
  131. data/lib/rubocop/cop/style/unneeded_percent_q.rb +2 -2
  132. data/lib/rubocop/cop/style/unpack_first.rb +1 -1
  133. data/lib/rubocop/cop/team.rb +3 -2
  134. data/lib/rubocop/cop/util.rb +2 -22
  135. data/lib/rubocop/cop/variable_force/scope.rb +3 -3
  136. data/lib/rubocop/cop/variable_force/variable.rb +3 -4
  137. data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
  138. data/lib/rubocop/formatter/base_formatter.rb +3 -3
  139. data/lib/rubocop/formatter/disabled_config_formatter.rb +16 -1
  140. data/lib/rubocop/formatter/formatter_set.rb +14 -14
  141. data/lib/rubocop/formatter/html_formatter.rb +4 -4
  142. data/lib/rubocop/formatter/json_formatter.rb +13 -13
  143. data/lib/rubocop/formatter/simple_text_formatter.rb +4 -4
  144. data/lib/rubocop/magic_comment.rb +4 -4
  145. data/lib/rubocop/node_pattern.rb +17 -17
  146. data/lib/rubocop/options.rb +93 -82
  147. data/lib/rubocop/result_cache.rb +9 -1
  148. data/lib/rubocop/rspec/expect_offense.rb +2 -2
  149. data/lib/rubocop/rspec/shared_contexts.rb +11 -11
  150. data/lib/rubocop/rspec/shared_examples.rb +4 -4
  151. data/lib/rubocop/string_interpreter.rb +1 -1
  152. data/lib/rubocop/version.rb +1 -1
  153. metadata +6 -13
  154. data/config/disabled.yml +0 -161
  155. data/config/enabled.yml +0 -2092
@@ -330,6 +330,7 @@ require_relative 'rubocop/cop/lint/void'
330
330
 
331
331
  require_relative 'rubocop/cop/metrics/cyclomatic_complexity'
332
332
  # relies on cyclomatic_complexity
333
+ require_relative 'rubocop/cop/metrics/utils/abc_size_calculator'
333
334
  require_relative 'rubocop/cop/metrics/abc_size'
334
335
  require_relative 'rubocop/cop/metrics/block_length'
335
336
  require_relative 'rubocop/cop/metrics/block_nesting'
@@ -15,37 +15,37 @@ module RuboCop
15
15
  # root_node = parser.parse(buffer)
16
16
  class Builder < Parser::Builders::Default
17
17
  NODE_MAP = {
18
- and: AndNode,
19
- args: ArgsNode,
20
- array: ArrayNode,
21
- block: BlockNode,
22
- case: CaseNode,
23
- def: DefNode,
24
- defined?: DefinedNode,
25
- defs: DefNode,
26
- ensure: EnsureNode,
27
- for: ForNode,
28
- hash: HashNode,
29
- if: IfNode,
30
- kwsplat: KeywordSplatNode,
31
- or: OrNode,
32
- pair: PairNode,
33
- regexp: RegexpNode,
34
- resbody: ResbodyNode,
35
- csend: SendNode,
36
- send: SendNode,
37
- str: StrNode,
38
- dstr: StrNode,
39
- xstr: StrNode,
40
- super: SuperNode,
41
- zsuper: SuperNode,
42
- sym: SymbolNode,
43
- until: UntilNode,
18
+ and: AndNode,
19
+ args: ArgsNode,
20
+ array: ArrayNode,
21
+ block: BlockNode,
22
+ case: CaseNode,
23
+ def: DefNode,
24
+ defined?: DefinedNode,
25
+ defs: DefNode,
26
+ ensure: EnsureNode,
27
+ for: ForNode,
28
+ hash: HashNode,
29
+ if: IfNode,
30
+ kwsplat: KeywordSplatNode,
31
+ or: OrNode,
32
+ pair: PairNode,
33
+ regexp: RegexpNode,
34
+ resbody: ResbodyNode,
35
+ csend: SendNode,
36
+ send: SendNode,
37
+ str: StrNode,
38
+ dstr: StrNode,
39
+ xstr: StrNode,
40
+ super: SuperNode,
41
+ zsuper: SuperNode,
42
+ sym: SymbolNode,
43
+ until: UntilNode,
44
44
  until_post: UntilNode,
45
- when: WhenNode,
46
- while: WhileNode,
45
+ when: WhenNode,
46
+ while: WhileNode,
47
47
  while_post: WhileNode,
48
- yield: YieldNode
48
+ yield: YieldNode
49
49
  }.freeze
50
50
 
51
51
  # Generates {Node} from the given information.
@@ -33,9 +33,17 @@ module RuboCop
33
33
  COMPOSITE_LITERALS = %i[dstr xstr dsym array hash irange
34
34
  erange regexp].freeze
35
35
  BASIC_LITERALS = (LITERALS - COMPOSITE_LITERALS).freeze
36
- MUTABLE_LITERALS = %i[str dstr xstr array hash].freeze
36
+ MUTABLE_LITERALS = %i[str dstr xstr array hash
37
+ regexp irange erange].freeze
37
38
  IMMUTABLE_LITERALS = (LITERALS - MUTABLE_LITERALS).freeze
38
39
 
40
+ EQUALS_ASSIGNMENTS = %i[lvasgn ivasgn cvasgn gvasgn
41
+ casgn masgn].freeze
42
+ SHORTHAND_ASSIGNMENTS = %i[op_asgn or_asgn and_asgn].freeze
43
+ ASSIGNMENTS = (EQUALS_ASSIGNMENTS + SHORTHAND_ASSIGNMENTS).freeze
44
+
45
+ BASIC_CONDITIONALS = %i[if while until].freeze
46
+ CONDITIONALS = [*BASIC_CONDITIONALS, :case].freeze
39
47
  VARIABLES = %i[ivar gvar cvar lvar].freeze
40
48
  REFERENCES = %i[nth_ref back_ref].freeze
41
49
  KEYWORDS = %i[alias and break case class def defs defined?
@@ -358,16 +366,6 @@ module RuboCop
358
366
  source_length.zero?
359
367
  end
360
368
 
361
- def_node_matcher :equals_asgn?, <<-PATTERN
362
- {lvasgn ivasgn cvasgn gvasgn casgn masgn}
363
- PATTERN
364
-
365
- def_node_matcher :shorthand_asgn?, '{op_asgn or_asgn and_asgn}'
366
-
367
- def_node_matcher :assignment?, <<-PATTERN
368
- {equals_asgn? shorthand_asgn?}
369
- PATTERN
370
-
371
369
  # Some cops treat the shovel operator as a kind of assignment.
372
370
  def_node_matcher :assignment_or_similar?, <<-PATTERN
373
371
  {assignment? (send _recv :<< ...)}
@@ -422,6 +420,26 @@ module RuboCop
422
420
  REFERENCES.include?(type)
423
421
  end
424
422
 
423
+ def equals_asgn?
424
+ EQUALS_ASSIGNMENTS.include?(type)
425
+ end
426
+
427
+ def shorthand_asgn?
428
+ SHORTHAND_ASSIGNMENTS.include?(type)
429
+ end
430
+
431
+ def assignment?
432
+ ASSIGNMENTS.include?(type)
433
+ end
434
+
435
+ def basic_conditional?
436
+ BASIC_CONDITIONALS.include?(type)
437
+ end
438
+
439
+ def conditional?
440
+ CONDITIONALS.include?(type)
441
+ end
442
+
425
443
  def keyword?
426
444
  return true if special_keyword? || send_type? && prefix_not?
427
445
  return false unless KEYWORDS.include?(type)
@@ -437,20 +455,6 @@ module RuboCop
437
455
  OPERATOR_KEYWORDS.include?(type)
438
456
  end
439
457
 
440
- def unary_operation?
441
- return false unless loc.respond_to?(:selector) && loc.selector
442
-
443
- Cop::Util.operator?(loc.selector.source.to_sym) &&
444
- source_range.begin_pos == loc.selector.begin_pos
445
- end
446
-
447
- def binary_operation?
448
- return false unless loc.respond_to?(:selector) && loc.selector
449
-
450
- Cop::Util.operator?(method_name) &&
451
- source_range.begin_pos != loc.selector.begin_pos
452
- end
453
-
454
458
  def parenthesized_call?
455
459
  loc.respond_to?(:begin) && loc.begin && loc.begin.is?('(')
456
460
  end
@@ -8,7 +8,7 @@ module RuboCop
8
8
  class ArgsNode < Node
9
9
  include CollectionNode
10
10
 
11
- # It returns true if arguments are empty, and delimiters do not exist.
11
+ # It returns true if arguments are empty and delimiters do not exist.
12
12
  # @example:
13
13
  # # true
14
14
  # def x; end
@@ -31,7 +31,7 @@ module RuboCop
31
31
  rhs = rhs.children.first if rhs.begin_type?
32
32
 
33
33
  [lhs, rhs].each_with_object([]) do |side, collection|
34
- if AST::Node::OPERATOR_KEYWORDS.include?(side.type)
34
+ if side.operator_keyword?
35
35
  collection.concat(side.conditions)
36
36
  else
37
37
  collection << side
@@ -182,6 +182,32 @@ module RuboCop
182
182
  block_literal? && loc.expression && loc.expression.source == '->'
183
183
  end
184
184
 
185
+ # Checks whether this is a unary operation.
186
+ #
187
+ # @example
188
+ #
189
+ # -foo
190
+ #
191
+ # @return [Boolean] whether this method is a unary operation
192
+ def unary_operation?
193
+ return false unless loc.selector
194
+
195
+ operator_method? && loc.expression.begin_pos == loc.selector.begin_pos
196
+ end
197
+
198
+ # Checks whether this is a binary operation.
199
+ #
200
+ # @example
201
+ #
202
+ # foo + bar
203
+ #
204
+ # @return [Bookean] whether this method is a binary operation
205
+ def binary_operation?
206
+ return false unless loc.selector
207
+
208
+ operator_method? && loc.expression.begin_pos != loc.selector.begin_pos
209
+ end
210
+
185
211
  private
186
212
 
187
213
  def_node_matcher :macro_scope?, <<-PATTERN
@@ -12,6 +12,10 @@ module RuboCop
12
12
  map reduce reject reject! reverse_each select
13
13
  select! times upto].freeze
14
14
 
15
+ # http://phrogz.net/programmingruby/language.html#table_18.4
16
+ OPERATOR_METHODS = %i[| ^ & <=> == === =~ > >= < <= << >> + - * /
17
+ % ** ~ +@ -@ !@ ~@ [] []= ! != !~ `].freeze
18
+
15
19
  # Checks whether the method name matches the argument.
16
20
  #
17
21
  # @param [Symbol, String] name the method name to check for
@@ -24,7 +28,7 @@ module RuboCop
24
28
  #
25
29
  # @return [Boolean] whether the method is an operator
26
30
  def operator_method?
27
- RuboCop::Cop::Util::OPERATOR_METHODS.include?(method_name)
31
+ OPERATOR_METHODS.include?(method_name)
28
32
  end
29
33
 
30
34
  # Checks whether the method is a comparison method.
@@ -28,7 +28,7 @@ module RuboCop
28
28
  end
29
29
 
30
30
  # Returns the delimiter of the `pair` as a string. Returns `=>` for a
31
- # colon delimited `pair`, and `:` for a hash rocket delimited `pair`.
31
+ # colon delimited `pair` and `:` for a hash rocket delimited `pair`.
32
32
  #
33
33
  # @param [Boolean] with_spacing whether to include spacing
34
34
  # @return [String] the delimiter of the `pair`
@@ -51,6 +51,13 @@ module RuboCop
51
51
  hash_rocket? ? COLON : HASH_ROCKET
52
52
  end
53
53
  end
54
+
55
+ # Checks whether the value starts on its own line.
56
+ #
57
+ # @return [Boolean] whether the value in the `pair` starts its own line
58
+ def value_on_new_line?
59
+ key.loc.line != value.loc.line
60
+ end
54
61
  end
55
62
  end
56
63
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module AST
5
- # A node extension for `str`, `dstr` and `xstr` nodes. This will be used
5
+ # A node extension for `str`, `dstr`, and `xstr` nodes. This will be used
6
6
  # in place of a plain node when the builder constructs the AST, making
7
7
  # its methods available to all `str` nodes within RuboCop.
8
8
  class StrNode < Node
@@ -29,9 +29,9 @@ module RuboCop
29
29
  begin_pos: offense.location.begin_pos,
30
30
  end_pos: offense.location.end_pos
31
31
  },
32
- message: message(offense),
32
+ message: message(offense),
33
33
  cop_name: offense.cop_name,
34
- status: offense.status
34
+ status: :uncorrected
35
35
  }
36
36
  end
37
37
 
@@ -18,7 +18,7 @@ module RuboCop
18
18
  AutoCorrect StyleGuide Details].freeze
19
19
  # 2.2 is the oldest officially supported Ruby version.
20
20
  DEFAULT_RUBY_VERSION = 2.2
21
- KNOWN_RUBIES = [2.2, 2.3, 2.4, 2.5].freeze
21
+ KNOWN_RUBIES = [2.2, 2.3, 2.4, 2.5, 2.6].freeze
22
22
  OBSOLETE_RUBIES = { 1.9 => '0.50', 2.0 => '0.50', 2.1 => '0.58' }.freeze
23
23
  RUBY_VERSION_FILENAME = '.ruby-version'.freeze
24
24
  DEFAULT_RAILS_VERSION = 5.0
@@ -181,6 +181,14 @@ module RuboCop
181
181
  if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
182
182
  SafeYAML.load(yaml_code, filename,
183
183
  whitelisted_tags: %w[!ruby/regexp])
184
+ elsif RUBY_VERSION >= '2.6'
185
+ YAML.safe_load(
186
+ yaml_code,
187
+ whitelist_classes: [Regexp, Symbol],
188
+ whitelist_symbols: [],
189
+ aliases: false,
190
+ filename: filename
191
+ )
184
192
  else
185
193
  YAML.safe_load(yaml_code, [Regexp, Symbol], [], false, filename)
186
194
  end
@@ -20,7 +20,13 @@ module RuboCop
20
20
  # allow turning off autocorrect on a cop by cop basis
21
21
  return true unless cop_config
22
22
 
23
- cop_config['AutoCorrect'] != false
23
+ return false if cop_config['AutoCorrect'] == false
24
+
25
+ if @options.fetch(:safe_auto_correct, false)
26
+ return cop_config.fetch('SafeAutoCorrect', true)
27
+ end
28
+
29
+ true
24
30
  end
25
31
  end
26
32
  end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Bundler
6
- # The symbol argument `:gemcutter`, `:rubygems` and `:rubyforge`
6
+ # The symbol argument `:gemcutter`, `:rubygems`, and `:rubyforge`
7
7
  # are deprecated. So please change your source to URL string that
8
8
  # 'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
9
9
  #
@@ -69,7 +69,8 @@ module RuboCop
69
69
  end
70
70
 
71
71
  def calculate_range(expr, line_begin_pos, column_delta)
72
- starts_with_space = expr.source_buffer.source[line_begin_pos] =~ / /
72
+ starts_with_space =
73
+ expr.source_buffer.source[line_begin_pos].start_with?(' ')
73
74
  pos_to_remove = if column_delta > 0 || starts_with_space
74
75
  line_begin_pos
75
76
  else
@@ -8,7 +8,7 @@ module RuboCop
8
8
  #
9
9
  # Assigning to an attribute with the same name using `spec.foo =` will be
10
10
  # an unintended usage. On the other hand, duplication of methods such
11
- # as `spec.requirements`, `spec.add_runtime_dependency` and others are
11
+ # as `spec.requirements`, `spec.add_runtime_dependency`, and others are
12
12
  # permitted because it is the intended use of appending values.
13
13
  #
14
14
  # @example
@@ -122,12 +122,13 @@ module RuboCop
122
122
  ).inject
123
123
  end
124
124
 
125
- def inject_config(config_file_path: 'config/enabled.yml')
125
+ def inject_config(config_file_path: 'config/default.yml')
126
126
  config = File.readlines(config_file_path)
127
127
  content = <<-YAML.strip_indent
128
128
  #{badge}:
129
129
  Description: 'TODO: Write a description of the cop.'
130
130
  Enabled: true
131
+ VersionAdded: #{bump_minor_version}
131
132
 
132
133
  YAML
133
134
  target_line = config.find.with_index(1) do |line, index|
@@ -138,7 +139,7 @@ module RuboCop
138
139
  File.write(config_file_path, config.join)
139
140
  output.puts <<-MESSAGE.strip_indent
140
141
  [modify] A configuration for the cop is added into #{config_file_path}.
141
- If you want to disable the cop by default, move the added config to config/disabled.yml
142
+ If you want to disable the cop by default, set `Enabled` option to false.
142
143
  MESSAGE
143
144
  end
144
145
 
@@ -147,7 +148,7 @@ module RuboCop
147
148
  Do 3 steps:
148
149
  1. Add an entry to the "New features" section in CHANGELOG.md,
149
150
  e.g. "Add new `#{badge}` cop. ([@#{github_user}][])"
150
- 2. Modify the description of #{badge} in config/enabled.yml
151
+ 2. Modify the description of #{badge} in config/default.yml
151
152
  3. Implement your new cop in the generated file!
152
153
  TODO
153
154
  end
@@ -209,6 +210,12 @@ module RuboCop
209
210
  .gsub(/([A-Z])([A-Z][^A-Z\d]+)/, '\1_\2')
210
211
  .downcase
211
212
  end
213
+
214
+ def bump_minor_version
215
+ versions = RuboCop::Version::STRING.split('.')
216
+
217
+ "#{versions[0]}.#{versions[1].succ}"
218
+ end
212
219
  end
213
220
  end
214
221
  end
@@ -7,7 +7,7 @@ module RuboCop
7
7
  # It looks for other directives that require files in the same (cop)
8
8
  # namespace and injects the provided one in alpha
9
9
  class RequireFileInjector
10
- REQUIRE_PATH = /require_relative ['"](.+)['"]/
10
+ REQUIRE_PATH = /require_relative ['"](.+)['"]/.freeze
11
11
 
12
12
  def initialize(source_path:, root_file_path:, output: $stdout)
13
13
  @source_path = Pathname(source_path)
@@ -22,7 +22,7 @@ module RuboCop
22
22
  # # good
23
23
  # method_name = send_node.method_name
24
24
  class NodeDestructuring < Cop
25
- MSG = 'Use the methods provided with the node extensions, or ' \
25
+ MSG = 'Use the methods provided with the node extensions or ' \
26
26
  'destructure the node using `*`.'.freeze
27
27
 
28
28
  def_node_matcher :node_children_destructuring?, <<-PATTERN
@@ -7,7 +7,7 @@ module RuboCop
7
7
  # literal are aligned according to configuration. The configuration
8
8
  # options are:
9
9
  #
10
- # - key (left align keys)
10
+ # - key (left align keys, one space before hash rockets and values)
11
11
  # - separator (align hash rockets and colons, right align keys)
12
12
  # - table (left align keys, hash rockets, and values)
13
13
  #
@@ -25,6 +25,10 @@ module RuboCop
25
25
  # :foo => bar,
26
26
  # :ba => baz
27
27
  # }
28
+ # {
29
+ # :foo => bar,
30
+ # :ba => baz
31
+ # }
28
32
  #
29
33
  # # good
30
34
  # {
@@ -68,6 +72,10 @@ module RuboCop
68
72
  # foo: bar,
69
73
  # ba: baz
70
74
  # }
75
+ # {
76
+ # foo: bar,
77
+ # ba: baz
78
+ # }
71
79
  #
72
80
  # # good
73
81
  # {
@@ -33,12 +33,10 @@ module RuboCop
33
33
  def on_block(node)
34
34
  return if node.single_line?
35
35
 
36
- end_loc = node.loc.end
37
-
38
36
  # If the end is on its own line, there is no offense
39
- return if end_loc.source_line =~ /^\s*#{end_loc.source}/
37
+ return if begins_its_line?(node.loc.end)
40
38
 
41
- add_offense(node, location: end_loc)
39
+ add_offense(node, location: :end)
42
40
  end
43
41
 
44
42
  def autocorrect(node)