rubocop 0.55.0 → 0.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +45 -0
  4. data/config/disabled.yml +4 -4
  5. data/config/enabled.yml +32 -16
  6. data/lib/rubocop.rb +8 -2
  7. data/lib/rubocop/cli.rb +4 -0
  8. data/lib/rubocop/comment_config.rb +36 -9
  9. data/lib/rubocop/config.rb +8 -1
  10. data/lib/rubocop/cop/generator.rb +4 -3
  11. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +101 -29
  12. data/lib/rubocop/cop/{style → layout}/empty_line_after_guard_clause.rb +1 -1
  13. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +5 -5
  14. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +112 -2
  15. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +8 -4
  16. data/lib/rubocop/cop/lint/erb_new_arguments.rb +107 -0
  17. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +4 -0
  18. data/lib/rubocop/cop/lint/nested_percent_literal.rb +0 -8
  19. data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
  20. data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
  21. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +3 -0
  22. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +16 -3
  23. data/lib/rubocop/cop/lint/splat_keyword_arguments.rb +36 -0
  24. data/lib/rubocop/cop/lint/unneeded_cop_enable_directive.rb +20 -2
  25. data/lib/rubocop/cop/performance/inefficient_hash_search.rb +95 -0
  26. data/lib/rubocop/cop/performance/unneeded_sort.rb +41 -6
  27. data/lib/rubocop/cop/rails/assert_not.rb +44 -0
  28. data/lib/rubocop/cop/rails/blank.rb +34 -28
  29. data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +1 -1
  30. data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +12 -2
  31. data/lib/rubocop/cop/rails/http_positional_arguments.rb +7 -7
  32. data/lib/rubocop/cop/rails/present.rb +31 -25
  33. data/lib/rubocop/cop/rails/refute_methods.rb +76 -0
  34. data/lib/rubocop/cop/rails/reversible_migration.rb +6 -4
  35. data/lib/rubocop/cop/rails/save_bang.rb +4 -1
  36. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +1 -10
  37. data/lib/rubocop/cop/style/command_literal.rb +15 -3
  38. data/lib/rubocop/cop/style/comment_annotation.rb +6 -1
  39. data/lib/rubocop/cop/style/empty_method.rb +6 -3
  40. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +12 -2
  41. data/lib/rubocop/cop/style/method_missing_super.rb +34 -0
  42. data/lib/rubocop/cop/style/{method_missing.rb → missing_respond_to_missing.rb} +7 -29
  43. data/lib/rubocop/cop/style/parentheses_around_condition.rb +28 -2
  44. data/lib/rubocop/node_pattern.rb +1 -1
  45. data/lib/rubocop/processed_source.rb +12 -6
  46. data/lib/rubocop/result_cache.rb +9 -4
  47. data/lib/rubocop/rspec/shared_contexts.rb +4 -0
  48. data/lib/rubocop/runner.rb +8 -2
  49. data/lib/rubocop/target_finder.rb +40 -60
  50. data/lib/rubocop/version.rb +1 -1
  51. metadata +10 -4
@@ -7,7 +7,7 @@ require 'etc'
7
7
  module RuboCop
8
8
  # Provides functionality for caching rubocop runs.
9
9
  class ResultCache
10
- NON_CHANGING = %i[color format formatters out debug fail_level
10
+ NON_CHANGING = %i[color format formatters out debug fail_level auto_correct
11
11
  cache fail_fast stdin parallel].freeze
12
12
 
13
13
  # Remove old files so that the cache doesn't grow too big. When the
@@ -84,6 +84,7 @@ module RuboCop
84
84
  relevant_options_digest(options),
85
85
  file_checksum(file, config_store))
86
86
  @cached_data = CachedData.new(file)
87
+ @pwd = Dir.pwd
87
88
  end
88
89
 
89
90
  def valid?
@@ -132,9 +133,13 @@ module RuboCop
132
133
  end
133
134
 
134
135
  def file_checksum(file, config_store)
135
- Digest::MD5.hexdigest(Dir.pwd + file + IO.binread(file) +
136
- File.stat(file).mode.to_s +
137
- config_store.for(file).to_s)
136
+ digester = Digest::MD5.new
137
+ mode = File.stat(file).mode
138
+ digester.update(
139
+ "#{@pwd}#{file}#{mode}#{config_store.for(file).signature}"
140
+ )
141
+ digester.file(file)
142
+ digester.hexdigest
138
143
  rescue Errno::ENOENT
139
144
  # Spurious files that come and go should not cause a crash, at least not
140
145
  # here.
@@ -79,6 +79,10 @@ shared_context 'ruby 2.5', :ruby25 do
79
79
  let(:ruby_version) { 2.5 }
80
80
  end
81
81
 
82
+ shared_context 'ruby 2.6', :ruby26 do
83
+ let(:ruby_version) { 2.6 }
84
+ end
85
+
82
86
  shared_context 'with Rails', :enabled_rails do
83
87
  let(:enabled_rails) { true }
84
88
  end
@@ -117,7 +117,15 @@ module RuboCop
117
117
  cache = ResultCache.new(file, @options, @config_store) if cached_run?
118
118
  if cache && cache.valid?
119
119
  offenses = cache.load
120
+ # If we're running --auto-correct and the cache says there are
121
+ # offenses, we need to actually inspect the file. If the cache shows no
122
+ # offenses, we're good.
123
+ real_run_needed = @options[:auto_correct] && offenses.any?
120
124
  else
125
+ real_run_needed = true
126
+ end
127
+
128
+ if real_run_needed
121
129
  offenses = yield
122
130
  save_in_cache(cache, offenses)
123
131
  end
@@ -176,8 +184,6 @@ module RuboCop
176
184
  # cops related to calculating the Max parameters for Metrics cops. We
177
185
  # need to do that processing and can not use caching.
178
186
  !@options[:auto_gen_config] &&
179
- # Auto-correction needs a full run. It can not use cached results.
180
- !@options[:auto_correct] &&
181
187
  # We can't cache results from code which is piped in to stdin
182
188
  !@options[:stdin]
183
189
  end
@@ -3,61 +3,6 @@
3
3
  require 'set'
4
4
 
5
5
  module RuboCop
6
- RUBY_EXTENSIONS = %w[.rb
7
- .arb
8
- .axlsx
9
- .builder
10
- .fcgi
11
- .gemfile
12
- .gemspec
13
- .god
14
- .jb
15
- .jbuilder
16
- .mspec
17
- .opal
18
- .pluginspec
19
- .podspec
20
- .rabl
21
- .rake
22
- .rbuild
23
- .rbw
24
- .rbx
25
- .ru
26
- .ruby
27
- .spec
28
- .thor
29
- .watchr].freeze
30
-
31
- RUBY_INTERPRETERS = %w[ruby
32
- macruby
33
- rake
34
- jruby
35
- rbx].freeze
36
-
37
- RUBY_FILENAMES = %w[.irbrc
38
- .pryrc
39
- Appraisals
40
- Berksfile
41
- Brewfile
42
- Buildfile
43
- Capfile
44
- Cheffile
45
- Dangerfile
46
- Deliverfile
47
- Fastfile
48
- Gemfile
49
- Guardfile
50
- Jarfile
51
- Mavenfile
52
- Podfile
53
- Puppetfile
54
- Rakefile
55
- Snapfile
56
- Thorfile
57
- Vagabondfile
58
- Vagrantfile
59
- buildfile].freeze
60
-
61
6
  # This class finds target files to inspect by scanning the directory tree
62
7
  # and picking ruby files.
63
8
  class TargetFinder
@@ -169,30 +114,65 @@ module RuboCop
169
114
  end
170
115
 
171
116
  def ruby_extension?(file)
172
- RUBY_EXTENSIONS.include?(File.extname(file))
117
+ ruby_extensions.include?(File.extname(file))
118
+ end
119
+
120
+ def ruby_extensions
121
+ ext_patterns = all_cops_include.select do |pattern|
122
+ pattern.start_with?('**/*.')
123
+ end
124
+ ext_patterns.map { |pattern| pattern.sub('**/*', '') }
173
125
  end
174
126
 
175
127
  def ruby_filename?(file)
176
- RUBY_FILENAMES.include?(File.basename(file))
128
+ ruby_filenames.include?(File.basename(file))
129
+ end
130
+
131
+ def ruby_filenames
132
+ file_patterns = all_cops_include.reject do |pattern|
133
+ pattern.start_with?('**/*.')
134
+ end
135
+ file_patterns.map { |pattern| pattern.sub('**/', '') }
136
+ end
137
+
138
+ def all_cops_include
139
+ @config_store.for('.').for_all_cops['Include'].map(&:to_s)
177
140
  end
178
141
 
179
142
  def ruby_executable?(file)
180
143
  return false unless File.extname(file).empty? && File.exist?(file)
181
144
  first_line = File.open(file, &:readline)
182
- !(first_line =~ /#!.*(#{RUBY_INTERPRETERS.join('|')})/).nil?
145
+ !(first_line =~ /#!.*(#{ruby_interpreters(file).join('|')})/).nil?
183
146
  rescue EOFError, ArgumentError => e
184
147
  warn "Unprocessable file #{file}: #{e.class}, #{e.message}" if debug?
185
148
  false
186
149
  end
187
150
 
151
+ def ruby_interpreters(file)
152
+ @config_store.for(file).for_all_cops['RubyInterpreters']
153
+ end
154
+
155
+ def stdin?
156
+ @options.key?(:stdin)
157
+ end
158
+
188
159
  def ruby_file?(file)
189
- ruby_extension?(file) || ruby_filename?(file) || ruby_executable?(file)
160
+ stdin? || ruby_extension?(file) || ruby_filename?(file) ||
161
+ ruby_executable?(file)
162
+ end
163
+
164
+ def configured_include?(file)
165
+ @config_store.for('.').file_to_include?(file)
166
+ end
167
+
168
+ def included_file?(file)
169
+ ruby_file?(file) || configured_include?(file)
190
170
  end
191
171
 
192
172
  def process_explicit_path(path)
193
173
  files = path.include?('*') ? Dir[path] : [path]
194
174
 
195
- files.select! { |file| ruby_file?(file) }
175
+ files.select! { |file| included_file?(file) }
196
176
 
197
177
  return files unless force_exclusion?
198
178
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.55.0'.freeze
6
+ STRING = '0.56.0'.freeze
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, running on ' \
9
9
  '%<ruby_engine>s %<ruby_version>s %<ruby_platform>s)'.freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.55.0
4
+ version: 0.56.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-04-16 00:00:00.000000000 Z
13
+ date: 2018-05-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel
@@ -254,6 +254,7 @@ files:
254
254
  - lib/rubocop/cop/layout/dot_position.rb
255
255
  - lib/rubocop/cop/layout/else_alignment.rb
256
256
  - lib/rubocop/cop/layout/empty_comment.rb
257
+ - lib/rubocop/cop/layout/empty_line_after_guard_clause.rb
257
258
  - lib/rubocop/cop/layout/empty_line_after_magic_comment.rb
258
259
  - lib/rubocop/cop/layout/empty_line_between_defs.rb
259
260
  - lib/rubocop/cop/layout/empty_lines.rb
@@ -337,6 +338,7 @@ files:
337
338
  - lib/rubocop/cop/lint/empty_when.rb
338
339
  - lib/rubocop/cop/lint/end_in_method.rb
339
340
  - lib/rubocop/cop/lint/ensure_return.rb
341
+ - lib/rubocop/cop/lint/erb_new_arguments.rb
340
342
  - lib/rubocop/cop/lint/float_out_of_range.rb
341
343
  - lib/rubocop/cop/lint/format_parameter_mismatch.rb
342
344
  - lib/rubocop/cop/lint/handle_exceptions.rb
@@ -372,6 +374,7 @@ files:
372
374
  - lib/rubocop/cop/lint/shadowed_argument.rb
373
375
  - lib/rubocop/cop/lint/shadowed_exception.rb
374
376
  - lib/rubocop/cop/lint/shadowing_outer_local_variable.rb
377
+ - lib/rubocop/cop/lint/splat_keyword_arguments.rb
375
378
  - lib/rubocop/cop/lint/string_conversion_in_interpolation.rb
376
379
  - lib/rubocop/cop/lint/syntax.rb
377
380
  - lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb
@@ -486,6 +489,7 @@ files:
486
489
  - lib/rubocop/cop/performance/end_with.rb
487
490
  - lib/rubocop/cop/performance/fixed_size.rb
488
491
  - lib/rubocop/cop/performance/flat_map.rb
492
+ - lib/rubocop/cop/performance/inefficient_hash_search.rb
489
493
  - lib/rubocop/cop/performance/lstrip_rstrip.rb
490
494
  - lib/rubocop/cop/performance/range_include.rb
491
495
  - lib/rubocop/cop/performance/redundant_block_call.rb
@@ -507,6 +511,7 @@ files:
507
511
  - lib/rubocop/cop/rails/active_support_aliases.rb
508
512
  - lib/rubocop/cop/rails/application_job.rb
509
513
  - lib/rubocop/cop/rails/application_record.rb
514
+ - lib/rubocop/cop/rails/assert_not.rb
510
515
  - lib/rubocop/cop/rails/blank.rb
511
516
  - lib/rubocop/cop/rails/create_table_with_timestamps.rb
512
517
  - lib/rubocop/cop/rails/date.rb
@@ -533,6 +538,7 @@ files:
533
538
  - lib/rubocop/cop/rails/present.rb
534
539
  - lib/rubocop/cop/rails/read_write_attribute.rb
535
540
  - lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb
541
+ - lib/rubocop/cop/rails/refute_methods.rb
536
542
  - lib/rubocop/cop/rails/relative_date_constant.rb
537
543
  - lib/rubocop/cop/rails/request_referer.rb
538
544
  - lib/rubocop/cop/rails/reversible_migration.rb
@@ -588,7 +594,6 @@ files:
588
594
  - lib/rubocop/cop/style/empty_case_condition.rb
589
595
  - lib/rubocop/cop/style/empty_else.rb
590
596
  - lib/rubocop/cop/style/empty_lambda_parameter.rb
591
- - lib/rubocop/cop/style/empty_line_after_guard_clause.rb
592
597
  - lib/rubocop/cop/style/empty_literal.rb
593
598
  - lib/rubocop/cop/style/empty_method.rb
594
599
  - lib/rubocop/cop/style/encoding.rb
@@ -620,9 +625,10 @@ files:
620
625
  - lib/rubocop/cop/style/method_call_without_args_parentheses.rb
621
626
  - lib/rubocop/cop/style/method_called_on_do_end_block.rb
622
627
  - lib/rubocop/cop/style/method_def_parentheses.rb
623
- - lib/rubocop/cop/style/method_missing.rb
628
+ - lib/rubocop/cop/style/method_missing_super.rb
624
629
  - lib/rubocop/cop/style/min_max.rb
625
630
  - lib/rubocop/cop/style/missing_else.rb
631
+ - lib/rubocop/cop/style/missing_respond_to_missing.rb
626
632
  - lib/rubocop/cop/style/mixin_grouping.rb
627
633
  - lib/rubocop/cop/style/mixin_usage.rb
628
634
  - lib/rubocop/cop/style/module_function.rb