rubocop 0.59.2 → 0.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -23,7 +23,7 @@ module RuboCop
23
23
  def style_detected(detected)
24
24
  return if no_acceptable_style?
25
25
 
26
- # `detected` can be a single style, or an Array of possible styles
26
+ # `detected` can be a single style or an Array of possible styles
27
27
  # (if there is more than one which matches the observed code)
28
28
  detected_as_strings = Array(detected).map(&:to_s)
29
29
 
@@ -7,8 +7,6 @@ module RuboCop
7
7
  include ConfigurableEnforcedStyle
8
8
 
9
9
  def check_name(node, name, name_range)
10
- return if operator?(name)
11
-
12
10
  if valid_name?(node, name)
13
11
  correct_style_detected
14
12
  else
@@ -9,8 +9,10 @@ module RuboCop
9
9
 
10
10
  def max=(value)
11
11
  cfg = config_to_allow_offenses
12
- value = [cfg[max_parameter_name], value].max if cfg[max_parameter_name]
13
- cfg[max_parameter_name] = value
12
+ cfg[:exclude_limit] ||= {}
13
+ current_max = cfg[:exclude_limit][max_parameter_name]
14
+ value = [current_max, value].max if current_max
15
+ cfg[:exclude_limit][max_parameter_name] = value
14
16
  end
15
17
 
16
18
  def max_parameter_name
@@ -9,7 +9,7 @@ module RuboCop
9
9
 
10
10
  FORMATS = {
11
11
  snake_case: /^@{0,2}[\da-z_]+[!?=]?$/,
12
- camelCase: /^@{0,2}_?[a-z][\da-zA-Z]+[!?=]?$/
12
+ camelCase: /^@{0,2}_?[a-z][\da-zA-Z]+[!?=]?$/
13
13
  }.freeze
14
14
  end
15
15
  end
@@ -8,8 +8,8 @@ module RuboCop
8
8
  include ConfigurableFormatting
9
9
 
10
10
  FORMATS = {
11
- snake_case: /(?:[a-z_]|_\d+)$/,
12
- normalcase: /(?:_\D*|[A-Za-z]\d*)$/,
11
+ snake_case: /(?:[a-z_]|_\d+)$/,
12
+ normalcase: /(?:_\D*|[A-Za-z]\d*)$/,
13
13
  non_integer: /[A-Za-z_]$/
14
14
  }.freeze
15
15
  end
@@ -10,17 +10,46 @@ module RuboCop
10
10
  true
11
11
  end
12
12
 
13
- def deltas_for_first_pair(*_nodes)
14
- {}
13
+ def deltas_for_first_pair(first_pair, _node)
14
+ {
15
+ separator: separator_delta(first_pair),
16
+ value: value_delta(first_pair)
17
+ }
15
18
  end
16
19
 
17
20
  def deltas(first_pair, current_pair)
18
21
  if Util.begins_its_line?(current_pair.source_range)
19
- { key: first_pair.key_delta(current_pair) }
22
+ key_delta = first_pair.key_delta(current_pair)
23
+ separator_delta = separator_delta(current_pair)
24
+ value_delta = value_delta(current_pair)
25
+
26
+ { key: key_delta, separator: separator_delta, value: value_delta }
20
27
  else
21
28
  {}
22
29
  end
23
30
  end
31
+
32
+ private
33
+
34
+ def separator_delta(pair)
35
+ if pair.hash_rocket?
36
+ correct_separator_column = pair.key.loc.expression.end.column + 1
37
+ actual_separator_column = pair.loc.operator.column
38
+
39
+ correct_separator_column - actual_separator_column
40
+ else
41
+ 0
42
+ end
43
+ end
44
+
45
+ def value_delta(pair)
46
+ return 0 if pair.kwsplat_type? || pair.value_on_new_line?
47
+
48
+ correct_value_column = pair.loc.operator.end.column + 1
49
+ actual_value_column = pair.value.loc.column
50
+
51
+ correct_value_column - actual_value_column
52
+ end
24
53
  end
25
54
 
26
55
  # Common functionality for checking alignment of hash values.
@@ -54,8 +83,6 @@ module RuboCop
54
83
  class TableAlignment
55
84
  include ValueAlignment
56
85
 
57
- # The table style is the only one where the first key-value pair can
58
- # be considered to have bad alignment.
59
86
  def deltas_for_first_pair(first_pair, node)
60
87
  self.max_key_width = node.keys.map { |key| key.source.length }.max
61
88
 
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  # Common functionality for working with heredoc strings.
6
6
  module Heredoc
7
- OPENING_DELIMITER = /(<<[~-]?)['"`]?([^'"`]+)['"`]?/
7
+ OPENING_DELIMITER = /(<<[~-]?)['"`]?([^'"`]+)['"`]?/.freeze
8
8
 
9
9
  def on_str(node)
10
10
  return unless node.heredoc?
@@ -5,10 +5,9 @@ module RuboCop
5
5
  # Common functionality for checking multiline method calls and binary
6
6
  # operations.
7
7
  module MultilineExpressionIndentation # rubocop:disable Metrics/ModuleLength
8
- KEYWORD_ANCESTOR_TYPES = [:for, :return, *Util::MODIFIER_NODES].freeze
8
+ KEYWORD_ANCESTOR_TYPES = %i[for if while until return].freeze
9
9
  UNALIGNED_RHS_TYPES = %i[if while until for return
10
10
  array kwbegin].freeze
11
- ASSIGNMENT_RHS_TYPES = [:send, *Util::ASGN_NODES].freeze
12
11
  DEFAULT_MESSAGE_TAIL = 'an expression'.freeze
13
12
  ASSIGNMENT_MESSAGE_TAIL = 'an expression in an assignment'.freeze
14
13
  KEYWORD_MESSAGE_TAIL = 'a %<kind>s in %<article>s `%<keyword>s` ' \
@@ -121,7 +120,7 @@ module RuboCop
121
120
  def keyword_message_tail(node)
122
121
  keyword = node.loc.keyword.source
123
122
  kind = keyword == 'for' ? 'collection' : 'condition'
124
- article = keyword =~ /^[iu]/ ? 'an' : 'a'
123
+ article = keyword.start_with?('i', 'u') ? 'an' : 'a'
125
124
 
126
125
  format(KEYWORD_MESSAGE_TAIL, kind: kind,
127
126
  article: article,
@@ -191,7 +190,7 @@ module RuboCop
191
190
  def valid_rhs?(candidate, ancestor)
192
191
  if ancestor.send_type?
193
192
  valid_method_rhs_candidate?(candidate, ancestor)
194
- elsif Util::ASGN_NODES.include?(ancestor.type)
193
+ elsif ancestor.assignment?
195
194
  valid_rhs_candidate?(candidate, assignment_rhs(ancestor))
196
195
  else
197
196
  false
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  # Common functionality for checking the closing brace of a literal is
6
- # either on the same line as the last contained elements, or a new line.
6
+ # either on the same line as the last contained elements or a new line.
7
7
  module MultilineLiteralBraceLayout
8
8
  include ConfigurableEnforcedStyle
9
9
 
@@ -32,6 +32,8 @@ module RuboCop
32
32
  end
33
33
 
34
34
  def modifier_fits_on_single_line?(node)
35
+ return true unless max_line_length
36
+
35
37
  modifier_length = length_in_modifier_form(node, node.condition,
36
38
  node.body.source_length)
37
39
 
@@ -47,6 +49,8 @@ module RuboCop
47
49
  end
48
50
 
49
51
  def max_line_length
52
+ return unless config.for_cop('Metrics/LineLength')['Enabled']
53
+
50
54
  config.for_cop('Metrics/LineLength')['Max']
51
55
  end
52
56
 
@@ -86,7 +86,7 @@ module RuboCop
86
86
  end
87
87
 
88
88
  # Returns true if the round/square/curly brackets of the given node are
89
- # on different lines, and each item within is on its own line, and the
89
+ # on different lines, each item within is on its own line, and the
90
90
  # closing bracket is on its own line.
91
91
  def multiline?(node)
92
92
  # No need to process anything if the whole node is not multiline
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Naming
6
- # This cops checks for class and module names with
6
+ # This cop checks for class and module names with
7
7
  # an underscore in them.
8
8
  #
9
9
  # @example
@@ -21,7 +21,7 @@ module RuboCop
21
21
  MSG = 'Use SCREAMING_SNAKE_CASE for constants.'.freeze
22
22
  # Use POSIX character classes, so we allow accented characters rather
23
23
  # than just standard ASCII characters
24
- SNAKE_CASE = /^[[:digit:][:upper:]_]+$/
24
+ SNAKE_CASE = /^[[:digit:][:upper:]_]+$/.freeze
25
25
 
26
26
  def_node_matcher :class_or_struct_return_method?, <<-PATTERN
27
27
  (send
@@ -33,7 +33,7 @@ module RuboCop
33
33
  'called `%<namespace>s`.'.freeze
34
34
  MSG_REGEX = '`%<basename>s` should match `%<regex>s`.'.freeze
35
35
 
36
- SNAKE_CASE = /^[\da-z_.?!]+$/
36
+ SNAKE_CASE = /^[\da-z_.?!]+$/.freeze
37
37
 
38
38
  def investigate(processed_source)
39
39
  file_path = processed_source.file_path
@@ -25,6 +25,8 @@ module RuboCop
25
25
  MSG = 'Use %<style>s for method names.'.freeze
26
26
 
27
27
  def on_def(node)
28
+ return if node.operator_method?
29
+
28
30
  check_name(node, node.method_name, node.loc.name)
29
31
  end
30
32
  alias on_defs on_def
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Naming
6
6
  # This cop makes sure that all numbered variables use the
7
- # configured style, snake_case, normalcase or non_integer,
7
+ # configured style, snake_case, normalcase, or non_integer,
8
8
  # for their numbering.
9
9
  #
10
10
  # @example EnforcedStyle: snake_case
@@ -177,7 +177,7 @@ module RuboCop
177
177
 
178
178
  # @api public
179
179
  #
180
- # Returns `-1`, `0` or `+1`
180
+ # Returns `-1`, `0`, or `+1`
181
181
  # if this offense is less than, equal to, or greater than `other`.
182
182
  #
183
183
  # @return [Integer]
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # In Ruby 2.4, `String#match?`, `Regexp#match?` and `Symbol#match?`
6
+ # In Ruby 2.4, `String#match?`, `Regexp#match?`, and `Symbol#match?`
7
7
  # have been added. The methods are faster than `match`.
8
8
  # Because the methods avoid creating a `MatchData` object or saving
9
9
  # backref.
@@ -3,8 +3,9 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop is used to identify usages of `shuffle.first`, `shuffle.last`
7
- # and `shuffle[]` and change them to use `sample` instead.
6
+ # This cop is used to identify usages of `shuffle.first`,
7
+ # `shuffle.last`, and `shuffle[]` and change them to use
8
+ # `sample` instead.
8
9
  #
9
10
  # @example
10
11
  # # bad
@@ -26,7 +26,7 @@ module RuboCop
26
26
 
27
27
  def literal_at_start?(regex_str)
28
28
  # is this regexp 'literal' in the sense of only matching literal
29
- # chars, rather than using metachars like . and * and so on?
29
+ # chars, rather than using metachars like `.` and `*` and so on?
30
30
  # also, is it anchored at the start of the string?
31
31
  # (tricky: \s, \d, and so on are metacharacters, but other characters
32
32
  # escaped with a slash are just literals. LITERAL_REGEX takes all
@@ -22,7 +22,7 @@ module RuboCop
22
22
  include RangeHelp
23
23
 
24
24
  MSG = 'Use `%<prefer>s` instead of `%<current>s`.'.freeze
25
- DETERMINISTIC_REGEX = /\A(?:#{LITERAL_REGEX})+\Z/
25
+ DETERMINISTIC_REGEX = /\A(?:#{LITERAL_REGEX})+\Z/.freeze
26
26
  DELETE = 'delete'.freeze
27
27
  TR = 'tr'.freeze
28
28
  BANG = '!'.freeze
@@ -6,19 +6,19 @@ module RuboCop
6
6
  # This cop checks for the correct use of Date methods,
7
7
  # such as Date.today, Date.current etc.
8
8
  #
9
- # Using Date.today is dangerous, because it doesn't know anything about
10
- # Rails time zone. You must use Time.zone.today instead.
9
+ # Using `Date.today` is dangerous, because it doesn't know anything about
10
+ # Rails time zone. You must use `Time.zone.today` instead.
11
11
  #
12
- # The cop also reports warnings when you are using 'to_time' method,
12
+ # The cop also reports warnings when you are using `to_time` method,
13
13
  # because it doesn't know about Rails time zone either.
14
14
  #
15
15
  # Two styles are supported for this cop. When EnforcedStyle is 'strict'
16
- # then the Date methods (today, current, yesterday, tomorrow)
17
- # are prohibited and the usage of both 'to_time'
18
- # and 'to_time_in_current_zone' is reported as warning.
16
+ # then the Date methods `today`, `current`, `yesterday`, and `tomorrow`
17
+ # are prohibited and the usage of both `to_time`
18
+ # and 'to_time_in_current_zone' are reported as warning.
19
19
  #
20
- # When EnforcedStyle is 'flexible' then only 'Date.today' is prohibited
21
- # and only 'to_time' is reported as warning.
20
+ # When EnforcedStyle is 'flexible' then only `Date.today` is prohibited
21
+ # and only `to_time` is reported as warning.
22
22
  #
23
23
  # @example EnforcedStyle: strict
24
24
  # # bad
@@ -27,7 +27,7 @@ module RuboCop
27
27
  # User.find_by!(email: email)
28
28
  class DynamicFindBy < Cop
29
29
  MSG = 'Use `%<static_name>s` instead of dynamic `%<method>s`.'.freeze
30
- METHOD_PATTERN = /^find_by_(.+?)(!)?$/
30
+ METHOD_PATTERN = /^find_by_(.+?)(!)?$/.freeze
31
31
 
32
32
  def on_send(node)
33
33
  method_name = node.method_name.to_s
@@ -3,15 +3,15 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop enforces that 'exit' calls are not used within a rails app.
7
- # Valid options are instead to raise an error, break, return or some
6
+ # This cop enforces that `exit` calls are not used within a rails app.
7
+ # Valid options are instead to raise an error, break, return, or some
8
8
  # other form of stopping execution of current request.
9
9
  #
10
- # There are two obvious cases where 'exit' is particularly harmful:
10
+ # There are two obvious cases where `exit` is particularly harmful:
11
11
  #
12
- # - Usage in library code for your application. Even though rails will
13
- # rescue from a SystemExit and continue on, unit testing that library
14
- # code will result in specs exiting (potentially silently if exit(0)
12
+ # - Usage in library code for your application. Even though Rails will
13
+ # rescue from a `SystemExit` and continue on, unit testing that library
14
+ # code will result in specs exiting (potentially silently if `exit(0)`
15
15
  # is used.)
16
16
  # - Usage in application code outside of the web process could result in
17
17
  # the program exiting, which could result in the code failing to run and
@@ -52,9 +52,8 @@ module RuboCop
52
52
  arg_nodes.size <= 1
53
53
  end
54
54
 
55
- # Only register if exit is being called explicitly on
56
- # Kernel or Process or if receiver node is nil for plain
57
- # `exit` calls.
55
+ # Only register if exit is being called explicitly on `Kernel`,
56
+ # `Process`, or if receiver node is nil for plain `exit` calls.
58
57
  def right_receiver?(receiver_node)
59
58
  return true unless receiver_node
60
59
 
@@ -3,10 +3,10 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for the use of output safety calls like html_safe,
7
- # raw, and safe_concat. These methods do not escape content. They
6
+ # This cop checks for the use of output safety calls like `html_safe`,
7
+ # `raw`, and `safe_concat`. These methods do not escape content. They
8
8
  # simply return a SafeBuffer containing the content as is. Instead,
9
- # use safe_join to join content and escape it and concat to
9
+ # use `safe_join` to join content and escape it and concat to
10
10
  # concatenate content and escape it, ensuring its safety.
11
11
  #
12
12
  # @example
@@ -3,12 +3,13 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Rails
6
- # This cop checks for the use of the read_attribute or write_attribute
7
- # methods, and recommends square brackets instead.
6
+ # This cop checks for the use of the `read_attribute` or `write_attribute`
7
+ # methods and recommends square brackets instead.
8
8
  #
9
9
  # If an attribute is missing from the instance (for example, when
10
- # initialized by a partial `select`) then read_attribute will return nil,
11
- # but square brackets will raise an ActiveModel::MissingAttributeError.
10
+ # initialized by a partial `select`) then `read_attribute`
11
+ # will return nil, but square brackets will raise
12
+ # an `ActiveModel::MissingAttributeError`.
12
13
  #
13
14
  # Explicitly raising an error in this situation is preferable, and that
14
15
  # is why rubocop recommends using square brackets.
@@ -21,20 +21,20 @@ module RuboCop
21
21
  MSG = 'Prefer `%<assert_method>s` over `%<refute_method>s`.'.freeze
22
22
 
23
23
  CORRECTIONS = {
24
- refute: 'assert_not',
25
- refute_empty: 'assert_not_empty',
26
- refute_equal: 'assert_not_equal',
27
- refute_in_delta: 'assert_not_in_delta',
28
- refute_in_epsilon: 'assert_not_in_epsilon',
29
- refute_includes: 'assert_not_includes',
24
+ refute: 'assert_not',
25
+ refute_empty: 'assert_not_empty',
26
+ refute_equal: 'assert_not_equal',
27
+ refute_in_delta: 'assert_not_in_delta',
28
+ refute_in_epsilon: 'assert_not_in_epsilon',
29
+ refute_includes: 'assert_not_includes',
30
30
  refute_instance_of: 'assert_not_instance_of',
31
- refute_kind_of: 'assert_not_kind_of',
32
- refute_nil: 'assert_not_nil',
33
- refute_operator: 'assert_not_operator',
34
- refute_predicate: 'assert_not_predicate',
35
- refute_respond_to: 'assert_not_respond_to',
36
- refute_same: 'assert_not_same',
37
- refute_match: 'assert_no_match'
31
+ refute_kind_of: 'assert_not_kind_of',
32
+ refute_nil: 'assert_not_nil',
33
+ refute_operator: 'assert_not_operator',
34
+ refute_predicate: 'assert_not_predicate',
35
+ refute_respond_to: 'assert_not_respond_to',
36
+ refute_same: 'assert_not_same',
37
+ refute_match: 'assert_no_match'
38
38
  }.freeze
39
39
 
40
40
  OFFENSIVE_METHODS = CORRECTIONS.keys.freeze
@@ -169,6 +169,7 @@ module RuboCop
169
169
  def on_block(node)
170
170
  return unless within_change_method?(node)
171
171
  return if within_reversible_or_up_only_block?(node)
172
+ return if node.body.nil?
172
173
 
173
174
  check_change_table_node(node.send_node, node.body)
174
175
  end
@@ -238,7 +239,7 @@ module RuboCop
238
239
  elsif block.send_type?
239
240
  check_change_table_offense(arg, block)
240
241
  else
241
- block.each_child_node do |child_node|
242
+ block.each_child_node(:send) do |child_node|
242
243
  check_change_table_offense(arg, child_node)
243
244
  end
244
245
  end