rubocop 0.31.0 → 0.35.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 (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +315 -0
  3. data/README.md +199 -38
  4. data/config/default.yml +91 -12
  5. data/config/disabled.yml +45 -4
  6. data/config/enabled.yml +107 -9
  7. data/lib/rubocop/ast_node.rb +48 -0
  8. data/lib/rubocop/cli.rb +11 -1
  9. data/lib/rubocop/comment_config.rb +4 -1
  10. data/lib/rubocop/config.rb +26 -17
  11. data/lib/rubocop/config_loader.rb +61 -14
  12. data/lib/rubocop/cop/commissioner.rb +7 -12
  13. data/lib/rubocop/cop/cop.rb +43 -20
  14. data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
  15. data/lib/rubocop/cop/lint/circular_argument_reference.rb +69 -0
  16. data/lib/rubocop/cop/lint/debugger.rb +9 -48
  17. data/lib/rubocop/cop/lint/def_end_alignment.rb +8 -4
  18. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +42 -23
  19. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
  20. data/lib/rubocop/cop/lint/duplicated_key.rb +37 -0
  21. data/lib/rubocop/cop/lint/end_alignment.rb +33 -13
  22. data/lib/rubocop/cop/lint/eval.rb +6 -2
  23. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +175 -0
  24. data/lib/rubocop/cop/lint/literal_in_condition.rb +0 -5
  25. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +10 -0
  26. data/lib/rubocop/cop/lint/nested_method_definition.rb +31 -0
  27. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +19 -1
  28. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
  29. data/lib/rubocop/cop/lint/space_before_first_arg.rb +1 -1
  30. data/lib/rubocop/cop/lint/unneeded_disable.rb +72 -0
  31. data/lib/rubocop/cop/lint/unused_block_argument.rb +6 -0
  32. data/lib/rubocop/cop/lint/unused_method_argument.rb +8 -0
  33. data/lib/rubocop/cop/metrics/abc_size.rb +17 -6
  34. data/lib/rubocop/cop/metrics/class_length.rb +1 -1
  35. data/lib/rubocop/cop/metrics/method_length.rb +1 -3
  36. data/lib/rubocop/cop/metrics/module_length.rb +1 -1
  37. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
  38. data/lib/rubocop/cop/mixin/access_modifier_node.rb +1 -1
  39. data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -2
  40. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +28 -4
  41. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +26 -3
  42. data/lib/rubocop/cop/mixin/check_assignment.rb +2 -3
  43. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +59 -12
  44. data/lib/rubocop/cop/mixin/configurable_max.rb +1 -1
  45. data/lib/rubocop/cop/mixin/configurable_naming.rb +14 -3
  46. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -3
  47. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +10 -1
  48. data/lib/rubocop/cop/mixin/first_element_line_break.rb +41 -0
  49. data/lib/rubocop/cop/mixin/if_node.rb +10 -0
  50. data/lib/rubocop/cop/mixin/method_preference.rb +28 -0
  51. data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -1
  52. data/lib/rubocop/cop/mixin/on_method_def.rb +4 -5
  53. data/lib/rubocop/cop/mixin/safe_assignment.rb +3 -14
  54. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +8 -1
  55. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +8 -1
  56. data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -7
  57. data/lib/rubocop/cop/mixin/string_help.rb +1 -1
  58. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  59. data/lib/rubocop/cop/mixin/surrounding_space.rb +5 -4
  60. data/lib/rubocop/cop/offense.rb +16 -3
  61. data/lib/rubocop/cop/performance/case_when_splat.rb +160 -0
  62. data/lib/rubocop/cop/performance/count.rb +35 -30
  63. data/lib/rubocop/cop/performance/detect.rb +16 -3
  64. data/lib/rubocop/cop/performance/fixed_size.rb +50 -0
  65. data/lib/rubocop/cop/performance/flat_map.rb +3 -3
  66. data/lib/rubocop/cop/performance/sample.rb +103 -59
  67. data/lib/rubocop/cop/performance/size.rb +2 -1
  68. data/lib/rubocop/cop/performance/string_replacement.rb +187 -0
  69. data/lib/rubocop/cop/rails/action_filter.rb +31 -5
  70. data/lib/rubocop/cop/rails/date.rb +15 -14
  71. data/lib/rubocop/cop/rails/pluralization_grammar.rb +97 -0
  72. data/lib/rubocop/cop/rails/read_write_attribute.rb +1 -1
  73. data/lib/rubocop/cop/rails/time_zone.rb +46 -18
  74. data/lib/rubocop/cop/style/alias.rb +1 -0
  75. data/lib/rubocop/cop/style/align_hash.rb +8 -15
  76. data/lib/rubocop/cop/style/align_parameters.rb +19 -7
  77. data/lib/rubocop/cop/style/and_or.rb +42 -13
  78. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +2 -1
  79. data/lib/rubocop/cop/style/block_comments.rb +4 -2
  80. data/lib/rubocop/cop/style/block_delimiters.rb +69 -24
  81. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +40 -12
  82. data/lib/rubocop/cop/style/case_indentation.rb +18 -4
  83. data/lib/rubocop/cop/style/collection_methods.rb +2 -20
  84. data/lib/rubocop/cop/style/command_literal.rb +2 -10
  85. data/lib/rubocop/cop/style/comment_annotation.rb +29 -8
  86. data/lib/rubocop/cop/style/copyright.rb +5 -3
  87. data/lib/rubocop/cop/style/documentation.rb +21 -12
  88. data/lib/rubocop/cop/style/dot_position.rb +6 -0
  89. data/lib/rubocop/cop/style/double_negation.rb +4 -15
  90. data/lib/rubocop/cop/style/each_with_object.rb +17 -4
  91. data/lib/rubocop/cop/style/else_alignment.rb +2 -1
  92. data/lib/rubocop/cop/style/empty_else.rb +25 -0
  93. data/lib/rubocop/cop/style/empty_line_between_defs.rb +39 -14
  94. data/lib/rubocop/cop/style/encoding.rb +10 -4
  95. data/lib/rubocop/cop/style/extra_spacing.rb +126 -5
  96. data/lib/rubocop/cop/style/first_array_element_line_break.rb +41 -0
  97. data/lib/rubocop/cop/style/first_hash_element_line_break.rb +35 -0
  98. data/lib/rubocop/cop/style/first_method_argument_line_break.rb +37 -0
  99. data/lib/rubocop/cop/style/first_method_parameter_line_break.rb +42 -0
  100. data/lib/rubocop/cop/style/first_parameter_indentation.rb +5 -3
  101. data/lib/rubocop/cop/style/for.rb +2 -1
  102. data/lib/rubocop/cop/style/hash_syntax.rb +5 -0
  103. data/lib/rubocop/cop/style/if_unless_modifier.rb +32 -5
  104. data/lib/rubocop/cop/style/indent_hash.rb +67 -37
  105. data/lib/rubocop/cop/style/indentation_width.rb +36 -10
  106. data/lib/rubocop/cop/style/initial_indentation.rb +37 -0
  107. data/lib/rubocop/cop/style/leading_comment_space.rb +3 -2
  108. data/lib/rubocop/cop/style/method_call_parentheses.rb +28 -1
  109. data/lib/rubocop/cop/style/method_def_parentheses.rb +10 -7
  110. data/lib/rubocop/cop/style/multiline_operation_indentation.rb +21 -24
  111. data/lib/rubocop/cop/style/mutable_constant.rb +35 -0
  112. data/lib/rubocop/cop/style/nested_modifier.rb +97 -0
  113. data/lib/rubocop/cop/style/next.rb +50 -15
  114. data/lib/rubocop/cop/style/non_nil_check.rb +12 -8
  115. data/lib/rubocop/cop/style/one_line_conditional.rb +8 -4
  116. data/lib/rubocop/cop/style/option_hash.rb +64 -0
  117. data/lib/rubocop/cop/style/optional_arguments.rb +49 -0
  118. data/lib/rubocop/cop/style/parallel_assignment.rb +218 -0
  119. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -66
  120. data/lib/rubocop/cop/style/predicate_name.rb +7 -2
  121. data/lib/rubocop/cop/style/redundant_begin.rb +2 -13
  122. data/lib/rubocop/cop/style/redundant_freeze.rb +37 -0
  123. data/lib/rubocop/cop/style/redundant_return.rb +32 -3
  124. data/lib/rubocop/cop/style/regexp_literal.rb +2 -10
  125. data/lib/rubocop/cop/style/rescue_ensure_alignment.rb +81 -0
  126. data/lib/rubocop/cop/style/rescue_modifier.rb +30 -22
  127. data/lib/rubocop/cop/style/send.rb +18 -0
  128. data/lib/rubocop/cop/style/signal_exception.rb +24 -11
  129. data/lib/rubocop/cop/style/single_line_methods.rb +8 -9
  130. data/lib/rubocop/cop/style/single_space_before_first_arg.rb +1 -1
  131. data/lib/rubocop/cop/style/space_around_operators.rb +2 -0
  132. data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +61 -0
  133. data/lib/rubocop/cop/style/special_global_vars.rb +4 -2
  134. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +108 -0
  135. data/lib/rubocop/cop/style/string_methods.rb +32 -0
  136. data/lib/rubocop/cop/style/struct_inheritance.rb +11 -10
  137. data/lib/rubocop/cop/style/symbol_literal.rb +1 -1
  138. data/lib/rubocop/cop/style/symbol_proc.rb +62 -13
  139. data/lib/rubocop/cop/style/trailing_blank_lines.rb +9 -1
  140. data/lib/rubocop/cop/style/trailing_comma.rb +17 -7
  141. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +23 -2
  142. data/lib/rubocop/cop/style/trivial_accessors.rb +10 -1
  143. data/lib/rubocop/cop/style/unneeded_percent_q.rb +31 -20
  144. data/lib/rubocop/cop/style/variable_name.rb +5 -0
  145. data/lib/rubocop/cop/style/while_until_do.rb +1 -1
  146. data/lib/rubocop/cop/style/word_array.rb +15 -2
  147. data/lib/rubocop/cop/team.rb +25 -5
  148. data/lib/rubocop/cop/util.rb +7 -2
  149. data/lib/rubocop/cop/variable_force/locatable.rb +6 -6
  150. data/lib/rubocop/cop/variable_force.rb +10 -10
  151. data/lib/rubocop/formatter/base_formatter.rb +1 -1
  152. data/lib/rubocop/formatter/disabled_config_formatter.rb +70 -8
  153. data/lib/rubocop/formatter/formatter_set.rb +27 -1
  154. data/lib/rubocop/formatter/progress_formatter.rb +10 -2
  155. data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
  156. data/lib/rubocop/node_pattern.rb +390 -0
  157. data/lib/rubocop/options.rb +148 -81
  158. data/lib/rubocop/processed_source.rb +7 -2
  159. data/lib/rubocop/rake_task.rb +1 -1
  160. data/lib/rubocop/remote_config.rb +60 -0
  161. data/lib/rubocop/result_cache.rb +123 -0
  162. data/lib/rubocop/runner.rb +85 -22
  163. data/lib/rubocop/target_finder.rb +4 -4
  164. data/lib/rubocop/token.rb +2 -1
  165. data/lib/rubocop/version.rb +1 -1
  166. data/lib/rubocop/warning.rb +11 -0
  167. data/lib/rubocop.rb +32 -3
  168. data/relnotes/v0.32.0.md +139 -0
  169. data/relnotes/v0.32.1.md +122 -0
  170. data/relnotes/v0.33.0.md +157 -0
  171. data/relnotes/v0.34.0.md +182 -0
  172. data/relnotes/v0.34.1.md +129 -0
  173. data/relnotes/v0.34.2.md +139 -0
  174. data/relnotes/v0.35.0.md +210 -0
  175. data/rubocop.gemspec +4 -4
  176. metadata +50 -12
  177. data/lib/rubocop/cop/performance/parallel_assignment.rb +0 -79
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This class handles the processing of files, which includes dealing with
5
5
  # formatters and letting cops inspect the files.
6
- class Runner
6
+ class Runner # rubocop:disable Metrics/ClassLength
7
7
  # An exception indicating that the inspection loop got stuck correcting
8
8
  # offenses back and forth.
9
9
  class InfiniteCorrectionLoop < Exception
@@ -15,19 +15,24 @@ module RuboCop
15
15
  end
16
16
  end
17
17
 
18
- attr_reader :errors, :aborting
18
+ attr_reader :errors, :warnings, :aborting
19
19
  alias_method :aborting?, :aborting
20
20
 
21
21
  def initialize(options, config_store)
22
22
  @options = options
23
23
  @config_store = config_store
24
24
  @errors = []
25
+ @warnings = []
25
26
  @aborting = false
26
27
  end
27
28
 
28
29
  def run(paths)
29
30
  target_files = find_target_files(paths)
30
- inspect_files(target_files)
31
+ if @options[:list_target_files]
32
+ list_files(target_files)
33
+ else
34
+ inspect_files(target_files)
35
+ end
31
36
  end
32
37
 
33
38
  def abort
@@ -58,20 +63,39 @@ module RuboCop
58
63
 
59
64
  all_passed
60
65
  ensure
66
+ ResultCache.cleanup(@config_store, @options[:debug]) if cached_run?
61
67
  formatter_set.finished(inspected_files.freeze)
62
68
  formatter_set.close_output_files
63
69
  end
64
70
 
71
+ def list_files(paths)
72
+ paths.each do |path|
73
+ puts PathUtil.relative_path(path)
74
+ end
75
+ end
76
+
65
77
  def process_file(file)
66
78
  puts "Scanning #{file}" if @options[:debug]
67
79
 
68
- processed_source = ProcessedSource.from_file(file)
69
-
70
- formatter_set.file_started(file, file_info(processed_source))
71
-
72
- offenses = do_inspection_loop(file, processed_source)
80
+ cache = ResultCache.new(file, @options, @config_store) if cached_run?
81
+ if cache && cache.valid?
82
+ offenses, disabled_line_ranges, comments = cache.load
83
+ file_started(file, disabled_line_ranges, comments)
84
+ else
85
+ processed_source = get_processed_source(file)
86
+ # Use delegators for objects sent to the formatters. These can be
87
+ # updated when the file is re-inspected.
88
+ disabled_line_ranges =
89
+ SimpleDelegator.new(processed_source.disabled_line_ranges)
90
+ comments = SimpleDelegator.new(processed_source.comments)
91
+
92
+ file_started(file, disabled_line_ranges, comments)
93
+ offenses = do_inspection_loop(file, processed_source,
94
+ disabled_line_ranges, comments)
95
+ save_in_cache(cache, offenses, processed_source)
96
+ end
73
97
 
74
- formatter_set.file_finished(file, offenses.compact.sort.freeze)
98
+ offenses = formatter_set.file_finished(file, offenses.compact.sort.freeze)
75
99
 
76
100
  offenses
77
101
  rescue InfiniteCorrectionLoop => e
@@ -79,7 +103,40 @@ module RuboCop
79
103
  raise
80
104
  end
81
105
 
82
- def do_inspection_loop(file, processed_source)
106
+ def file_started(file, disabled_line_ranges, comments)
107
+ formatter_set.file_started(file,
108
+ cop_disabled_line_ranges: disabled_line_ranges,
109
+ comments: comments,
110
+ cli_options: @options,
111
+ config_store: @config_store)
112
+ end
113
+
114
+ def cached_run?
115
+ @cached_run ||=
116
+ (@options[:cache] == 'true' ||
117
+ @options[:cache] != 'false' &&
118
+ @config_store.for(Dir.pwd)['AllCops']['UseCache']) &&
119
+ # When running --auto-gen-config, there's some processing done in the
120
+ # cops related to calculating the Max parameters for Metrics cops. We
121
+ # need to do that processing and can not use caching.
122
+ !@options[:auto_gen_config] &&
123
+ # Auto-correction needs a full run. It can not use cached results.
124
+ !@options[:auto_correct]
125
+ end
126
+
127
+ def save_in_cache(cache, offenses, processed_source)
128
+ return unless cache
129
+ # Caching results when a cop has crashed would prevent the crash in the
130
+ # next run, since the cop would not be called then. We want crashes to
131
+ # show up the same in each run.
132
+ return if errors.any? || warnings.any?
133
+
134
+ cache.save(offenses, processed_source.disabled_line_ranges,
135
+ processed_source.comments)
136
+ end
137
+
138
+ def do_inspection_loop(file, processed_source, disabled_line_ranges,
139
+ comments)
83
140
  offenses = []
84
141
 
85
142
  # Keep track of the state of the source. If a cop modifies the source
@@ -105,7 +162,11 @@ module RuboCop
105
162
  # loop if we find any.
106
163
  break unless updated_source_file
107
164
 
108
- processed_source = ProcessedSource.from_file(file)
165
+ processed_source = get_processed_source(file)
166
+
167
+ # Update delegators with new objects.
168
+ disabled_line_ranges.__setobj__(processed_source.disabled_line_ranges)
169
+ comments.__setobj__(processed_source.comments)
109
170
  end
110
171
 
111
172
  offenses
@@ -128,6 +189,7 @@ module RuboCop
128
189
  team = Cop::Team.new(mobilized_cop_classes(config), config, @options)
129
190
  offenses = team.inspect_file(processed_source)
130
191
  @errors.concat(team.errors)
192
+ @warnings.concat(team.warnings)
131
193
  [offenses, team.updated_source_file?]
132
194
  end
133
195
 
@@ -136,12 +198,12 @@ module RuboCop
136
198
  @mobilized_cop_classes[config.object_id] ||= begin
137
199
  cop_classes = Cop::Cop.all
138
200
 
139
- [:only, :except].each { |opt| Options.validate_cop_list(@options[opt]) }
201
+ [:only, :except].each do |opt|
202
+ OptionsValidator.validate_cop_list(@options[opt])
203
+ end
140
204
 
141
205
  if @options[:only]
142
- cop_classes.select! do |c|
143
- c.match?(@options[:only]) || @options[:lint] && c.lint?
144
- end
206
+ cop_classes.select! { |c| c.match?(@options[:only]) }
145
207
  else
146
208
  filter_cop_classes(cop_classes, config)
147
209
  end
@@ -160,9 +222,6 @@ module RuboCop
160
222
 
161
223
  # filter out Rails cops unless requested
162
224
  cop_classes.reject!(&:rails?) unless run_rails_cops?(config)
163
-
164
- # select only lint cops when --lint is passed
165
- cop_classes.select!(&:lint?) if @options[:lint]
166
225
  end
167
226
 
168
227
  def run_rails_cops?(config)
@@ -190,8 +249,11 @@ module RuboCop
190
249
 
191
250
  def considered_failure?(offense)
192
251
  # For :autocorrect level, any offense - corrected or not - is a failure.
193
- @options[:fail_level] == :autocorrect ||
194
- !offense.corrected? && offense.severity >= minimum_severity_to_fail
252
+ return false if offense.disabled?
253
+
254
+ return true if @options[:fail_level] == :autocorrect
255
+
256
+ !offense.corrected? && offense.severity >= minimum_severity_to_fail
195
257
  end
196
258
 
197
259
  def minimum_severity_to_fail
@@ -201,8 +263,9 @@ module RuboCop
201
263
  end
202
264
  end
203
265
 
204
- def file_info(processed_source)
205
- { cop_disabled_line_ranges: processed_source.disabled_line_ranges }
266
+ def get_processed_source(file)
267
+ return ProcessedSource.new(@options[:stdin], file) if @options[:stdin]
268
+ ProcessedSource.from_file(file)
206
269
  end
207
270
  end
208
271
  end
@@ -88,16 +88,16 @@ module RuboCop
88
88
  def find_files(base_dir, flags)
89
89
  wanted_toplevel_dirs = toplevel_dirs(base_dir, flags) -
90
90
  excluded_dirs(base_dir)
91
- wanted_toplevel_dirs.map! { |dir| dir.gsub(',', '\,') }
91
+ wanted_toplevel_dirs.map! { |dir| dir << '/**/*' }
92
92
 
93
93
  pattern = if wanted_toplevel_dirs.empty?
94
94
  # We need this special case to avoid creating the pattern
95
95
  # /**/* which searches the entire file system.
96
- "#{base_dir}/**/*"
96
+ ["#{base_dir}/**/*"]
97
97
  else
98
98
  # Search the non-excluded top directories, but also add files
99
99
  # on the top level, which would otherwise not be found.
100
- "{#{base_dir}/*,{#{wanted_toplevel_dirs.join(',')}}/**/*}"
100
+ wanted_toplevel_dirs.unshift("#{base_dir}/*")
101
101
  end
102
102
  Dir.glob(pattern, flags).select { |path| FileTest.file?(path) }
103
103
  end
@@ -118,7 +118,7 @@ module RuboCop
118
118
 
119
119
  def ruby_executable?(file)
120
120
  return false unless File.extname(file).empty?
121
- first_line = File.open(file) { |f| f.readline }
121
+ first_line = File.open(file, &:readline)
122
122
  first_line =~ /#!.*ruby/
123
123
  rescue EOFError, ArgumentError => e
124
124
  warn "Unprocessable file #{file}: #{e.class}, #{e.message}" if debug?
data/lib/rubocop/token.rb CHANGED
@@ -14,7 +14,8 @@ module RuboCop
14
14
  def initialize(pos, type, text)
15
15
  @pos = pos
16
16
  @type = type
17
- @text = text
17
+ # Parser token "text" may be a Fixnum
18
+ @text = text.to_s
18
19
  end
19
20
 
20
21
  def to_s
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.31.0'
6
+ STRING = '0.35.0'
7
7
 
8
8
  MSG = '%s (using Parser %s, running on %s %s %s)'
9
9
 
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ module RuboCop
4
+ # A Warning exception is different from an Offense with severity 'warning'
5
+ # When a Warning is raised, this means that RuboCop was unable to perform a
6
+ # requested operation (such as inspecting or correcting a source file) due to
7
+ # user error
8
+ # For example, a configuration value in .rubocop.yml might be malformed
9
+ class Warning < StandardError
10
+ end
11
+ end
data/lib/rubocop.rb CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'parser/current'
4
4
  require 'rainbow'
5
- # Rainbow 2.0 does not load the monkey-patch for String by default.
6
- require 'rainbow/ext/string' unless String.method_defined?(:color)
7
5
 
8
6
  require 'English'
9
7
  require 'set'
@@ -17,6 +15,8 @@ require 'rubocop/version'
17
15
 
18
16
  require 'rubocop/path_util'
19
17
  require 'rubocop/string_util'
18
+ require 'rubocop/node_pattern'
19
+ require 'rubocop/ast_node'
20
20
 
21
21
  require 'rubocop/cop/util'
22
22
  require 'rubocop/cop/offense'
@@ -50,10 +50,12 @@ require 'rubocop/cop/mixin/configurable_enforced_style'
50
50
  require 'rubocop/cop/mixin/configurable_naming'
51
51
  require 'rubocop/cop/mixin/empty_lines_around_body'
52
52
  require 'rubocop/cop/mixin/end_keyword_alignment'
53
+ require 'rubocop/cop/mixin/first_element_line_break'
53
54
  require 'rubocop/cop/mixin/if_node'
54
55
  require 'rubocop/cop/mixin/negative_conditional'
55
56
  require 'rubocop/cop/mixin/on_method_def'
56
57
  require 'rubocop/cop/mixin/method_complexity'
58
+ require 'rubocop/cop/mixin/method_preference'
57
59
  require 'rubocop/cop/mixin/min_body_length'
58
60
  require 'rubocop/cop/mixin/on_normal_if_unless'
59
61
  require 'rubocop/cop/mixin/parser_diagnostic'
@@ -72,11 +74,13 @@ require 'rubocop/cop/lint/ambiguous_operator'
72
74
  require 'rubocop/cop/lint/ambiguous_regexp_literal'
73
75
  require 'rubocop/cop/lint/assignment_in_condition'
74
76
  require 'rubocop/cop/lint/block_alignment'
77
+ require 'rubocop/cop/lint/circular_argument_reference'
75
78
  require 'rubocop/cop/lint/condition_position'
76
79
  require 'rubocop/cop/lint/debugger'
77
80
  require 'rubocop/cop/lint/def_end_alignment'
78
81
  require 'rubocop/cop/lint/deprecated_class_methods'
79
82
  require 'rubocop/cop/lint/duplicate_methods'
83
+ require 'rubocop/cop/lint/duplicated_key'
80
84
  require 'rubocop/cop/lint/each_with_object_argument'
81
85
  require 'rubocop/cop/lint/else_layout'
82
86
  require 'rubocop/cop/lint/empty_ensure'
@@ -85,11 +89,13 @@ require 'rubocop/cop/lint/end_alignment'
85
89
  require 'rubocop/cop/lint/end_in_method'
86
90
  require 'rubocop/cop/lint/ensure_return'
87
91
  require 'rubocop/cop/lint/eval'
92
+ require 'rubocop/cop/lint/format_parameter_mismatch'
88
93
  require 'rubocop/cop/lint/handle_exceptions'
89
94
  require 'rubocop/cop/lint/invalid_character_literal'
90
95
  require 'rubocop/cop/lint/literal_in_condition'
91
96
  require 'rubocop/cop/lint/literal_in_interpolation'
92
97
  require 'rubocop/cop/lint/loop'
98
+ require 'rubocop/cop/lint/nested_method_definition'
93
99
  require 'rubocop/cop/lint/non_local_exit_from_iterator'
94
100
  require 'rubocop/cop/lint/parentheses_as_grouped_expression'
95
101
  require 'rubocop/cop/lint/require_parentheses'
@@ -99,6 +105,7 @@ require 'rubocop/cop/lint/space_before_first_arg'
99
105
  require 'rubocop/cop/lint/string_conversion_in_interpolation'
100
106
  require 'rubocop/cop/lint/syntax'
101
107
  require 'rubocop/cop/lint/underscore_prefixed_variable_name'
108
+ require 'rubocop/cop/lint/unneeded_disable'
102
109
  require 'rubocop/cop/lint/unreachable_code'
103
110
  require 'rubocop/cop/lint/unused_block_argument'
104
111
  require 'rubocop/cop/lint/unused_method_argument'
@@ -119,13 +126,15 @@ require 'rubocop/cop/metrics/method_length'
119
126
  require 'rubocop/cop/metrics/parameter_lists'
120
127
  require 'rubocop/cop/metrics/perceived_complexity'
121
128
 
129
+ require 'rubocop/cop/performance/case_when_splat'
122
130
  require 'rubocop/cop/performance/count'
123
131
  require 'rubocop/cop/performance/detect'
132
+ require 'rubocop/cop/performance/fixed_size'
124
133
  require 'rubocop/cop/performance/flat_map'
125
- require 'rubocop/cop/performance/parallel_assignment'
126
134
  require 'rubocop/cop/performance/reverse_each'
127
135
  require 'rubocop/cop/performance/sample'
128
136
  require 'rubocop/cop/performance/size'
137
+ require 'rubocop/cop/performance/string_replacement'
129
138
 
130
139
  require 'rubocop/cop/style/access_modifier_indentation'
131
140
  require 'rubocop/cop/style/accessor_method_name'
@@ -184,6 +193,10 @@ require 'rubocop/cop/style/end_of_line'
184
193
  require 'rubocop/cop/style/even_odd'
185
194
  require 'rubocop/cop/style/extra_spacing'
186
195
  require 'rubocop/cop/style/file_name'
196
+ require 'rubocop/cop/style/first_array_element_line_break'
197
+ require 'rubocop/cop/style/first_hash_element_line_break'
198
+ require 'rubocop/cop/style/first_method_argument_line_break'
199
+ require 'rubocop/cop/style/first_method_parameter_line_break'
187
200
  require 'rubocop/cop/style/first_parameter_indentation'
188
201
  require 'rubocop/cop/style/flip_flop'
189
202
  require 'rubocop/cop/style/for'
@@ -198,6 +211,7 @@ require 'rubocop/cop/style/indent_hash'
198
211
  require 'rubocop/cop/style/indentation_consistency'
199
212
  require 'rubocop/cop/style/indentation_width'
200
213
  require 'rubocop/cop/style/infinite_loop'
214
+ require 'rubocop/cop/style/initial_indentation'
201
215
  require 'rubocop/cop/style/inline_comment'
202
216
  require 'rubocop/cop/style/lambda'
203
217
  require 'rubocop/cop/style/lambda_call'
@@ -213,8 +227,10 @@ require 'rubocop/cop/style/multiline_block_layout'
213
227
  require 'rubocop/cop/style/multiline_if_then'
214
228
  require 'rubocop/cop/style/multiline_operation_indentation'
215
229
  require 'rubocop/cop/style/multiline_ternary_operator'
230
+ require 'rubocop/cop/style/mutable_constant'
216
231
  require 'rubocop/cop/style/negated_if'
217
232
  require 'rubocop/cop/style/negated_while'
233
+ require 'rubocop/cop/style/nested_modifier'
218
234
  require 'rubocop/cop/style/nested_ternary_operator'
219
235
  require 'rubocop/cop/style/next'
220
236
  require 'rubocop/cop/style/nil_comparison'
@@ -223,6 +239,9 @@ require 'rubocop/cop/style/not'
223
239
  require 'rubocop/cop/style/numeric_literals'
224
240
  require 'rubocop/cop/style/one_line_conditional'
225
241
  require 'rubocop/cop/style/op_method'
242
+ require 'rubocop/cop/style/optional_arguments'
243
+ require 'rubocop/cop/style/option_hash'
244
+ require 'rubocop/cop/style/parallel_assignment'
226
245
  require 'rubocop/cop/style/parentheses_around_condition'
227
246
  require 'rubocop/cop/style/percent_literal_delimiters'
228
247
  require 'rubocop/cop/style/percent_q_literals'
@@ -232,12 +251,15 @@ require 'rubocop/cop/style/proc'
232
251
  require 'rubocop/cop/style/raise_args'
233
252
  require 'rubocop/cop/style/redundant_begin'
234
253
  require 'rubocop/cop/style/redundant_exception'
254
+ require 'rubocop/cop/style/redundant_freeze'
235
255
  require 'rubocop/cop/style/redundant_return'
236
256
  require 'rubocop/cop/style/redundant_self'
237
257
  require 'rubocop/cop/style/regexp_literal'
258
+ require 'rubocop/cop/style/rescue_ensure_alignment'
238
259
  require 'rubocop/cop/style/rescue_modifier'
239
260
  require 'rubocop/cop/style/self_assignment'
240
261
  require 'rubocop/cop/style/semicolon'
262
+ require 'rubocop/cop/style/send'
241
263
  require 'rubocop/cop/style/signal_exception'
242
264
  require 'rubocop/cop/style/single_line_block_params'
243
265
  require 'rubocop/cop/style/single_line_methods'
@@ -261,9 +283,12 @@ require 'rubocop/cop/style/space_inside_brackets'
261
283
  require 'rubocop/cop/style/space_inside_hash_literal_braces'
262
284
  require 'rubocop/cop/style/space_inside_parens'
263
285
  require 'rubocop/cop/style/space_inside_range_literal'
286
+ require 'rubocop/cop/style/space_inside_string_interpolation'
264
287
  require 'rubocop/cop/style/special_global_vars'
288
+ require 'rubocop/cop/style/stabby_lambda_parentheses'
265
289
  require 'rubocop/cop/style/string_literals'
266
290
  require 'rubocop/cop/style/string_literals_in_interpolation'
291
+ require 'rubocop/cop/style/string_methods'
267
292
  require 'rubocop/cop/style/struct_inheritance'
268
293
  require 'rubocop/cop/style/symbol_array'
269
294
  require 'rubocop/cop/style/symbol_literal'
@@ -292,6 +317,7 @@ require 'rubocop/cop/rails/find_by'
292
317
  require 'rubocop/cop/rails/find_each'
293
318
  require 'rubocop/cop/rails/has_and_belongs_to_many'
294
319
  require 'rubocop/cop/rails/output'
320
+ require 'rubocop/cop/rails/pluralization_grammar'
295
321
  require 'rubocop/cop/rails/read_write_attribute'
296
322
  require 'rubocop/cop/rails/scope_args'
297
323
  require 'rubocop/cop/rails/time_zone'
@@ -318,6 +344,9 @@ require 'rubocop/target_finder'
318
344
  require 'rubocop/token'
319
345
  require 'rubocop/comment_config'
320
346
  require 'rubocop/processed_source'
347
+ require 'rubocop/result_cache'
321
348
  require 'rubocop/runner'
322
349
  require 'rubocop/cli'
323
350
  require 'rubocop/options'
351
+ require 'rubocop/warning'
352
+ require 'rubocop/remote_config'
@@ -0,0 +1,139 @@
1
+ ### New features
2
+
3
+ * Adjust behavior of `TrailingComma` cop to account for multi-line hashes nested within method calls. ([@panthomakos][])
4
+ * [#1719](https://github.com/bbatsov/rubocop/pull/1719): Display an error and abort the program if input file can't be found. ([@matugm][])
5
+ * New cop `SpaceInsideStringInterpolation` checks for spaces within string interpolations. ([@glasnt][])
6
+ * New cop `NestedMethodDefinition` checks for method definitions inside other methods. ([@ojab][])
7
+ * `LiteralInInterpolation` cop does auto-correction. ([@tmr08c][])
8
+ * [#1865](https://github.com/bbatsov/rubocop/issues/1865): New cop `Lint/UnneededDisable` checks for `rubocop:disable` comments that can be removed. ([@jonas054][])
9
+ * `EmptyElse` cop does auto-correction. ([@lumeet][])
10
+ * Show reference links when displaying style guide links. ([@rrosenblum][])
11
+ * `Debugger` cop now checks for the Capybara debug method `save_screenshot`. ([@crazydog115][])
12
+ * [#1282](https://github.com/bbatsov/rubocop/issues/1282): `CaseIndentation` cop does auto-correction. ([@lumeet][])
13
+ * [#1928](https://github.com/bbatsov/rubocop/issues/1928): Do auto-correction one offense at a time (rather than one cop at a time) if there are tabs in the code. ([@jonas054][])
14
+
15
+ ### Changes
16
+
17
+ * Prefer `SpaceInsideBlockBraces` to `SpaceBeforeSemicolon` and `SpaceAfterSemicolon` to avoid an infinite loop when auto-correcting. ([@lumeet][])
18
+ * [#1873](https://github.com/bbatsov/rubocop/issues/1873): Move `ParallelAssignment` cop from Performance to Style. ([@rrosenblum][])
19
+ * Add `getlocal` to acceptable methods of `Rails/TimeZone`. ([@ojab][])
20
+ * [#1851](https://github.com/bbatsov/rubocop/issues/1851), [#1948](https://github.com/bbatsov/rubocop/issues/1948): Change offense message for `ClassLength` and `ModuleLength` to match that of `MethodLength`. ([@bquorning][])
21
+
22
+ ### Bugs fixed
23
+
24
+ * Don't count required keyword args when specifying `CountKeywordArgs: false` for `ParameterLists`. ([@sumeet][])
25
+ * [#1879](https://github.com/bbatsov/rubocop/issues/1879): Avoid auto-correcting hash with trailing comma into invalid code in `BracesAroundHashParameters`. ([@jonas054][])
26
+ * [#1868](https://github.com/bbatsov/rubocop/issues/1868): Do not register an offense in `Performance/Count` when `select` is called with symbols or strings as the parameters. ([@rrosenblum][])
27
+ * `Sample` rewritten to properly handle shuffle randomness source, first/last params and non-literal ranges. ([@chastell][])
28
+ * [#1873](https://github.com/bbatsov/rubocop/issues/1873): Modify `ParallelAssignment` to properly autocorrect when the assignment is protected by a modifier statement. ([@rrosenblum][])
29
+ * Configure `ParallelAssignment` to work with non-standard `IndentationWidths`. ([@rrosenblum][])
30
+ * [#1899](https://github.com/bbatsov/rubocop/issues/1899): Be careful about comments when auto-correcting in `BracesAroundHashParameters`. ([@jonas054][])
31
+ * [#1897](https://github.com/bbatsov/rubocop/issues/1897): Don't report that semicolon separated statements can be converted to modifier form in `IfUnlessModifier` (and don't auto-correct them). ([@jonas054][])
32
+ * [#1644](https://github.com/bbatsov/rubocop/issues/1644): Don't search the entire file system when a folder is named `,` (fix for jruby and rbx). ([@rrosenblum][])
33
+ * [#1803](https://github.com/bbatsov/rubocop/issues/1803): Don't warn for `return` from `lambda` block in `NonLocalExitFromIterator`. ([@ypresto][])
34
+ * [#1905](https://github.com/bbatsov/rubocop/issues/1905): Ignore sparse and trailing comments in `Style/Documentation`. ([@RGBD][])
35
+ * [#1923](https://github.com/bbatsov/rubocop/issues/1923): Handle properly `for` without body in `Style/Next`. ([@bbatsov][])
36
+ * [#1901](https://github.com/bbatsov/rubocop/issues/1901): Do not auto correct comments that are missing a note. ([@rrosenblum][])
37
+ * [#1926](https://github.com/bbatsov/rubocop/issues/1926): Fix crash in `Style/AlignHash` when correcting a hash with a splat in it. ([@rrosenblum][])
38
+ * [#1935](https://github.com/bbatsov/rubocop/issues/1935): Allow `Symbol#to_proc` blocks in Performance/Size. ([@m1foley][])
39
+
40
+ [@bbatsov]: https://github.com/bbatsov
41
+ [@jonas054]: https://github.com/jonas054
42
+ [@yujinakayama]: https://github.com/yujinakayama
43
+ [@dblock]: https://github.com/dblock
44
+ [@nevir]: https://github.com/nevir
45
+ [@daviddavis]: https://github.com/daviddavis
46
+ [@sds]: https://github.com/sds
47
+ [@fancyremarker]: https://github.com/fancyremarker
48
+ [@sinisterchipmunk]: https://github.com/sinisterchipmunk
49
+ [@vonTronje]: https://github.com/vonTronje
50
+ [@agrimm]: https://github.com/agrimm
51
+ [@pmenglund]: https://github.com/pmenglund
52
+ [@chulkilee]: https://github.com/chulkilee
53
+ [@codez]: https://github.com/codez
54
+ [@emou]: https://github.com/emou
55
+ [@skanev]: http://github.com/skanev
56
+ [@claco]: http://github.com/claco
57
+ [@rifraf]: http://github.com/rifraf
58
+ [@scottmatthewman]: https://github.com/scottmatthewman
59
+ [@ma2gedev]: http://github.com/ma2gedev
60
+ [@jeremyolliver]: https://github.com/jeremyolliver
61
+ [@hannestyden]: https://github.com/hannestyden
62
+ [@geniou]: https://github.com/geniou
63
+ [@jkogara]: https://github.com/jkogara
64
+ [@tmorris-fiksu]: https://github.com/tmorris-fiksu
65
+ [@mockdeep]: https://github.com/mockdeep
66
+ [@hiroponz]: https://github.com/hiroponz
67
+ [@tamird]: https://github.com/tamird
68
+ [@fshowalter]: https://github.com/fshowalter
69
+ [@cschramm]: https://github.com/cschramm
70
+ [@bquorning]: https://github.com/bquorning
71
+ [@bcobb]: https://github.com/bcobb
72
+ [@irrationalfab]: https://github.com/irrationalfab
73
+ [@tommeier]: https://github.com/tommeier
74
+ [@sfeldon]: https://github.com/sfeldon
75
+ [@biinari]: https://github.com/biinari
76
+ [@barunio]: https://github.com/barunio
77
+ [@molawson]: https://github.com/molawson
78
+ [@wndhydrnt]: https://github.com/wndhydrnt
79
+ [@ggilder]: https://github.com/ggilder
80
+ [@salbertson]: https://github.com/salbertson
81
+ [@camilleldn]: https://github.com/camilleldn
82
+ [@mcls]: https://github.com/mcls
83
+ [@yous]: https://github.com/yous
84
+ [@vrthra]: https://github.com/vrthra
85
+ [@SkuliOskarsson]: https://github.com/SkuliOskarsson
86
+ [@jspanjers]: https://github.com/jspanjers
87
+ [@sch1zo]: https://github.com/sch1zo
88
+ [@smangelsdorf]: https://github.com/smangelsdorf
89
+ [@mvz]: https://github.com/mvz
90
+ [@jfelchner]: https://github.com/jfelchner
91
+ [@janraasch]: https://github.com/janraasch
92
+ [@jcarbo]: https://github.com/jcarbo
93
+ [@oneamtu]: https://github.com/oneamtu
94
+ [@toy]: https://github.com/toy
95
+ [@Koronen]: https://github.com/Koronen
96
+ [@blainesch]: https://github.com/blainesch
97
+ [@marxarelli]: https://github.com/marxarelli
98
+ [@katieschilling]: https://github.com/katieschilling
99
+ [@kakutani]: https://github.com/kakutani
100
+ [@rrosenblum]: https://github.com/rrosenblum
101
+ [@mattjmcnaughton]: https://github.com/mattjmcnaughton
102
+ [@huerlisi]: https://github.com/huerlisi
103
+ [@volkert]: https://github.com/volkert
104
+ [@lumeet]: https://github.com/lumeet
105
+ [@mmozuras]: https://github.com/mmozuras
106
+ [@d4rk5eed]: https://github.com/d4rk5eed
107
+ [@cshaffer]: https://github.com/cshaffer
108
+ [@eitoball]: https://github.com/eitoball
109
+ [@iainbeeston]: https://github.com/iainbeeston
110
+ [@pimterry]: https://github.com/pimterry
111
+ [@palkan]: https://github.com/palkan
112
+ [@jdoconnor]: https://github.com/jdoconnor
113
+ [@meganemura]: https://github.com/meganemura
114
+ [@zvkemp]: https://github.com/zvkemp
115
+ [@vassilevsky]: https://github.com/vassilevsky
116
+ [@gerry3]: https://github.com/gerry3
117
+ [@ypresto]: https://github.com/ypresto
118
+ [@clowder]: https://github.com/clowder
119
+ [@mudge]: https://github.com/mudge
120
+ [@mzp]: https://github.com/mzp
121
+ [@bankair]: https://github.com/bankair
122
+ [@crimsonknave]: https://github.com/crimsonknave
123
+ [@renuo]: https://github.com/renuo
124
+ [@sdeframond]: https://github.com/sdeframond
125
+ [@til]: https://github.com/til
126
+ [@carhartl]: https://github.com/carhartl
127
+ [@dylandavidson]: https://github.com/dylandavidson
128
+ [@tmr08c]: https://github.com/tmr08c
129
+ [@hbd225]: https://github.com/hbd225
130
+ [@l8nite]: https://github.com/l8nite
131
+ [@sumeet]: https://github.com/sumeet
132
+ [@ojab]: https://github.com/ojab
133
+ [@chastell]: https://github.com/chastell
134
+ [@glasnt]: https://github.com/glasnt
135
+ [@crazydog115]: https://github.com/crazydog115
136
+ [@RGBD]: https://github.com/RGBD
137
+ [@panthomakos]: https://github.com/panthomakos
138
+ [@matugm]: https://github.com/matugm
139
+ [@m1foley]: https://github.com/m1foley