rubocop 0.66.0 → 0.67.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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +75 -26
  4. data/exe/rubocop +12 -0
  5. data/lib/rubocop.rb +12 -5
  6. data/lib/rubocop/cli.rb +11 -9
  7. data/lib/rubocop/config.rb +3 -0
  8. data/lib/rubocop/config_loader_resolver.rb +2 -2
  9. data/lib/rubocop/cop/commissioner.rb +3 -3
  10. data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +39 -0
  11. data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +50 -0
  12. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +52 -0
  13. data/lib/rubocop/cop/lint/to_json.rb +5 -2
  14. data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +33 -0
  15. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +6 -1
  16. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +76 -0
  17. data/lib/rubocop/cop/rails/active_record_override.rb +67 -0
  18. data/lib/rubocop/cop/rails/blank.rb +6 -0
  19. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +30 -4
  20. data/lib/rubocop/cop/rails/link_to_blank.rb +7 -6
  21. data/lib/rubocop/cop/rails/present.rb +5 -1
  22. data/lib/rubocop/cop/rails/redundant_allow_nil.rb +105 -0
  23. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -0
  24. data/lib/rubocop/cop/style/block_comments.rb +9 -1
  25. data/lib/rubocop/cop/{performance → style}/redundant_sort_by.rb +1 -1
  26. data/lib/rubocop/cop/{performance → style}/sample.rb +1 -1
  27. data/lib/rubocop/cop/style/stderr_puts.rb +9 -3
  28. data/lib/rubocop/cop/{performance/lstrip_rstrip.rb → style/strip.rb} +2 -2
  29. data/lib/rubocop/cop/style/struct_inheritance.rb +10 -2
  30. data/lib/rubocop/cop/{performance → style}/unneeded_sort.rb +1 -1
  31. data/lib/rubocop/node_pattern.rb +8 -6
  32. data/lib/rubocop/path_util.rb +3 -3
  33. data/lib/rubocop/processed_source.rb +2 -2
  34. data/lib/rubocop/remote_config.rb +6 -4
  35. data/lib/rubocop/result_cache.rb +2 -2
  36. data/lib/rubocop/runner.rb +2 -2
  37. data/lib/rubocop/target_finder.rb +7 -2
  38. data/lib/rubocop/version.rb +1 -1
  39. metadata +29 -7
@@ -81,6 +81,7 @@ module RuboCop
81
81
 
82
82
  def on_block(node)
83
83
  with_options?(node) do |arg, body|
84
+ return if body.nil?
84
85
  return unless all_block_nodes_in(body).count.zero?
85
86
 
86
87
  send_nodes = all_send_nodes_in(body)
@@ -52,10 +52,18 @@ module RuboCop
52
52
  def parts(comment)
53
53
  expr = comment.loc.expression
54
54
  eq_begin = expr.resize(BEGIN_LENGTH)
55
- eq_end = range_between(expr.end_pos - END_LENGTH, expr.end_pos)
55
+ eq_end = eq_end_part(comment, expr)
56
56
  contents = range_between(eq_begin.end_pos, eq_end.begin_pos)
57
57
  [eq_begin, eq_end, contents]
58
58
  end
59
+
60
+ def eq_end_part(comment, expr)
61
+ if comment.text.chomp == comment.text
62
+ range_between(expr.end_pos - END_LENGTH - 1, expr.end_pos - 2)
63
+ else
64
+ range_between(expr.end_pos - END_LENGTH, expr.end_pos)
65
+ end
66
+ end
59
67
  end
60
68
  end
61
69
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Performance
5
+ module Style
6
6
  # This cop identifies places where `sort_by { ... }` can be replaced by
7
7
  # `sort`.
8
8
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Performance
5
+ module Style
6
6
  # This cop is used to identify usages of `shuffle.first`,
7
7
  # `shuffle.last`, and `shuffle[]` and change them to use
8
8
  # `sample` instead.
@@ -17,12 +17,14 @@ module RuboCop
17
17
  class StderrPuts < Cop
18
18
  include RangeHelp
19
19
 
20
- MSG = 'Use `warn` instead of `$stderr.puts` to allow such output ' \
21
- 'to be disabled.'.freeze
20
+ MSG =
21
+ 'Use `warn` instead of `%<bad>s` to allow such output to be disabled.'
22
+ .freeze
22
23
 
23
24
  def_node_matcher :stderr_puts?, <<-PATTERN
24
25
  (send
25
- (gvar #stderr_gvar?) :puts $_
26
+ {(gvar #stderr_gvar?) (const nil? :STDERR)}
27
+ :puts $_
26
28
  ...)
27
29
  PATTERN
28
30
 
@@ -40,6 +42,10 @@ module RuboCop
40
42
 
41
43
  private
42
44
 
45
+ def message(node)
46
+ format(MSG, bad: "#{node.receiver.source}.#{node.method_name}")
47
+ end
48
+
43
49
  def stderr_gvar?(sym)
44
50
  sym == :$stderr
45
51
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Performance
5
+ module Style
6
6
  # This cop identifies places where `lstrip.rstrip` can be replaced by
7
7
  # `strip`.
8
8
  #
@@ -13,7 +13,7 @@ module RuboCop
13
13
  #
14
14
  # # good
15
15
  # 'abc'.strip
16
- class LstripRstrip < Cop
16
+ class Strip < Cop
17
17
  include RangeHelp
18
18
 
19
19
  MSG = 'Use `strip` instead of `%<methods>s`.'.freeze
@@ -8,12 +8,20 @@ module RuboCop
8
8
  # @example
9
9
  # # bad
10
10
  # class Person < Struct.new(:first_name, :last_name)
11
+ # def age
12
+ # 42
13
+ # end
11
14
  # end
12
15
  #
13
16
  # # good
14
- # Person = Struct.new(:first_name, :last_name)
17
+ # Person = Struct.new(:first_name, :last_name) do
18
+ # def age
19
+ # 42
20
+ # end
21
+ # end
15
22
  class StructInheritance < Cop
16
- MSG = "Don't extend an instance initialized by `Struct.new`.".freeze
23
+ MSG = "Don't extend an instance initialized by `Struct.new`. " \
24
+ 'Use a block to customize the struct.'.freeze
17
25
 
18
26
  def on_class(node)
19
27
  _name, superclass, _body = *node
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- module Performance
5
+ module Style
6
6
  # This cop is used to identify instances of sorting and then
7
7
  # taking only the first or last element. The same behavior can
8
8
  # be accomplished without a relatively expensive sort by using
@@ -96,11 +96,11 @@ module RuboCop
96
96
  # Builds Ruby code which implements a pattern
97
97
  class Compiler
98
98
  SYMBOL = %r{:(?:[\w+@*/?!<>=~|%^-]+|\[\]=?)}.freeze
99
- IDENTIFIER = /[a-zA-Z_-]/.freeze
99
+ IDENTIFIER = /[a-zA-Z_][a-zA-Z0-9_-]*/.freeze
100
100
  META = /\(|\)|\{|\}|\[|\]|\$\.\.\.|\$|!|\^|\.\.\./.freeze
101
101
  NUMBER = /-?\d+(?:\.\d+)?/.freeze
102
102
  STRING = /".+?"/.freeze
103
- METHOD_NAME = /\#?#{IDENTIFIER}+[\!\?]?\(?/.freeze
103
+ METHOD_NAME = /\#?#{IDENTIFIER}[\!\?]?\(?/.freeze
104
104
  PARAM_NUMBER = /%\d*/.freeze
105
105
 
106
106
  SEPARATORS = /[\s]+/.freeze
@@ -109,9 +109,10 @@ module RuboCop
109
109
 
110
110
  TOKEN = /\G(?:#{SEPARATORS}|#{TOKENS}|.)/.freeze
111
111
 
112
- NODE = /\A#{IDENTIFIER}+\Z/.freeze
113
- PREDICATE = /\A#{IDENTIFIER}+\?\(?\Z/.freeze
114
- WILDCARD = /\A_#{IDENTIFIER}*\Z/.freeze
112
+ NODE = /\A#{IDENTIFIER}\Z/.freeze
113
+ PREDICATE = /\A#{IDENTIFIER}\?\(?\Z/.freeze
114
+ WILDCARD = /\A_(?:#{IDENTIFIER})?\Z/.freeze
115
+
115
116
  FUNCALL = /\A\##{METHOD_NAME}/.freeze
116
117
  LITERAL = /\A(?:#{SYMBOL}|#{NUMBER}|#{STRING})\Z/.freeze
117
118
  PARAM = /\A#{PARAM_NUMBER}\Z/.freeze
@@ -372,7 +373,8 @@ module RuboCop
372
373
  end
373
374
 
374
375
  def compile_nodetype(cur_node, type)
375
- "(#{cur_node} && #{cur_node}.#{type.tr('-', '_')}_type?)"
376
+ "(#{cur_node}.is_a?(RuboCop::AST::Node) && " \
377
+ "#{cur_node}.#{type.tr('-', '_')}_type?)"
376
378
  end
377
379
 
378
380
  def compile_param(cur_node, number, seq_head)
@@ -41,10 +41,10 @@ module RuboCop
41
41
  when Regexp
42
42
  begin
43
43
  path =~ pattern
44
- rescue ArgumentError => e
45
- return false if e.message.start_with?('invalid byte sequence')
44
+ rescue ArgumentError => ex
45
+ return false if ex.message.start_with?('invalid byte sequence')
46
46
 
47
- raise e
47
+ raise exception
48
48
  end
49
49
  end
50
50
  end
@@ -146,8 +146,8 @@ module RuboCop
146
146
 
147
147
  begin
148
148
  @buffer.source = source
149
- rescue EncodingError => error
150
- @parser_error = error
149
+ rescue EncodingError => ex
150
+ @parser_error = ex
151
151
  return
152
152
  end
153
153
 
@@ -47,8 +47,8 @@ module RuboCop
47
47
  generate_request(uri) do |request|
48
48
  begin
49
49
  handle_response(http.request(request), limit, &block)
50
- rescue SocketError => err
51
- handle_response(err, limit, &block)
50
+ rescue SocketError => ex
51
+ handle_response(ex, limit, &block)
52
52
  end
53
53
  end
54
54
  end
@@ -72,8 +72,10 @@ module RuboCop
72
72
  else
73
73
  begin
74
74
  response.error!
75
- rescue StandardError => e
76
- raise e, "#{e.message} while downloading remote config file #{uri}"
75
+ rescue StandardError => ex
76
+ message = "#{ex.message} while downloading remote config"\
77
+ " file #{uri}"
78
+ raise ex, message
77
79
  end
78
80
  end
79
81
  end
@@ -100,9 +100,9 @@ module RuboCop
100
100
 
101
101
  begin
102
102
  FileUtils.mkdir_p(dir)
103
- rescue Errno::EACCES => e
103
+ rescue Errno::EACCES => ex
104
104
  warn "Couldn't create cache directory. Continuing without cache."\
105
- "\n #{e.message}"
105
+ "\n #{ex.message}"
106
106
  return
107
107
  end
108
108
 
@@ -108,8 +108,8 @@ module RuboCop
108
108
  end
109
109
  formatter_set.file_finished(file, offenses)
110
110
  offenses
111
- rescue InfiniteCorrectionLoop => e
112
- formatter_set.file_finished(file, e.offenses.compact.sort.freeze)
111
+ rescue InfiniteCorrectionLoop => ex
112
+ formatter_set.file_finished(file, ex.offenses.compact.sort.freeze)
113
113
  raise
114
114
  end
115
115
 
@@ -145,8 +145,13 @@ module RuboCop
145
145
 
146
146
  first_line = File.open(file, &:readline)
147
147
  !(first_line =~ /#!.*(#{ruby_interpreters(file).join('|')})/).nil?
148
- rescue EOFError, ArgumentError => e
149
- warn "Unprocessable file #{file}: #{e.class}, #{e.message}" if debug?
148
+ rescue EOFError, ArgumentError => ex
149
+ if debug?
150
+ warn(
151
+ "Unprocessable file #{file}: #{ex.class}, #{ex.message}"
152
+ )
153
+ end
154
+
150
155
  false
151
156
  end
152
157
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.66.0'.freeze
6
+ STRING = '0.67.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.66.0
4
+ version: 0.67.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2019-03-18 00:00:00.000000000 Z
13
+ date: 2019-04-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jaro_winkler
@@ -315,9 +315,12 @@ files:
315
315
  - lib/rubocop/cop/layout/leading_blank_lines.rb
316
316
  - lib/rubocop/cop/layout/leading_comment_space.rb
317
317
  - lib/rubocop/cop/layout/multiline_array_brace_layout.rb
318
+ - lib/rubocop/cop/layout/multiline_array_line_breaks.rb
318
319
  - lib/rubocop/cop/layout/multiline_assignment_layout.rb
319
320
  - lib/rubocop/cop/layout/multiline_block_layout.rb
320
321
  - lib/rubocop/cop/layout/multiline_hash_brace_layout.rb
322
+ - lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb
323
+ - lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb
321
324
  - lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb
322
325
  - lib/rubocop/cop/layout/multiline_method_call_indentation.rb
323
326
  - lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb
@@ -472,6 +475,7 @@ files:
472
475
  - lib/rubocop/cop/mixin/method_complexity.rb
473
476
  - lib/rubocop/cop/mixin/method_preference.rb
474
477
  - lib/rubocop/cop/mixin/min_body_length.rb
478
+ - lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
475
479
  - lib/rubocop/cop/mixin/multiline_expression_indentation.rb
476
480
  - lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb
477
481
  - lib/rubocop/cop/mixin/negative_conditional.rb
@@ -512,6 +516,7 @@ files:
512
516
  - lib/rubocop/cop/naming/memoized_instance_variable_name.rb
513
517
  - lib/rubocop/cop/naming/method_name.rb
514
518
  - lib/rubocop/cop/naming/predicate_name.rb
519
+ - lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb
515
520
  - lib/rubocop/cop/naming/uncommunicative_block_param_name.rb
516
521
  - lib/rubocop/cop/naming/uncommunicative_method_param_name.rb
517
522
  - lib/rubocop/cop/naming/variable_name.rb
@@ -529,25 +534,22 @@ files:
529
534
  - lib/rubocop/cop/performance/fixed_size.rb
530
535
  - lib/rubocop/cop/performance/flat_map.rb
531
536
  - lib/rubocop/cop/performance/inefficient_hash_search.rb
532
- - lib/rubocop/cop/performance/lstrip_rstrip.rb
533
537
  - lib/rubocop/cop/performance/open_struct.rb
534
538
  - lib/rubocop/cop/performance/range_include.rb
535
539
  - lib/rubocop/cop/performance/redundant_block_call.rb
536
540
  - lib/rubocop/cop/performance/redundant_match.rb
537
541
  - lib/rubocop/cop/performance/redundant_merge.rb
538
- - lib/rubocop/cop/performance/redundant_sort_by.rb
539
542
  - lib/rubocop/cop/performance/regexp_match.rb
540
543
  - lib/rubocop/cop/performance/reverse_each.rb
541
- - lib/rubocop/cop/performance/sample.rb
542
544
  - lib/rubocop/cop/performance/size.rb
543
545
  - lib/rubocop/cop/performance/start_with.rb
544
546
  - lib/rubocop/cop/performance/string_replacement.rb
545
547
  - lib/rubocop/cop/performance/times_map.rb
546
548
  - lib/rubocop/cop/performance/unfreeze_string.rb
547
- - lib/rubocop/cop/performance/unneeded_sort.rb
548
549
  - lib/rubocop/cop/performance/uri_default_parser.rb
549
550
  - lib/rubocop/cop/rails/action_filter.rb
550
551
  - lib/rubocop/cop/rails/active_record_aliases.rb
552
+ - lib/rubocop/cop/rails/active_record_override.rb
551
553
  - lib/rubocop/cop/rails/active_support_aliases.rb
552
554
  - lib/rubocop/cop/rails/application_job.rb
553
555
  - lib/rubocop/cop/rails/application_record.rb
@@ -581,6 +583,7 @@ files:
581
583
  - lib/rubocop/cop/rails/presence.rb
582
584
  - lib/rubocop/cop/rails/present.rb
583
585
  - lib/rubocop/cop/rails/read_write_attribute.rb
586
+ - lib/rubocop/cop/rails/redundant_allow_nil.rb
584
587
  - lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb
585
588
  - lib/rubocop/cop/rails/reflection_class_name.rb
586
589
  - lib/rubocop/cop/rails/refute_methods.rb
@@ -719,11 +722,13 @@ files:
719
722
  - lib/rubocop/cop/style/redundant_parentheses.rb
720
723
  - lib/rubocop/cop/style/redundant_return.rb
721
724
  - lib/rubocop/cop/style/redundant_self.rb
725
+ - lib/rubocop/cop/style/redundant_sort_by.rb
722
726
  - lib/rubocop/cop/style/regexp_literal.rb
723
727
  - lib/rubocop/cop/style/rescue_modifier.rb
724
728
  - lib/rubocop/cop/style/rescue_standard_error.rb
725
729
  - lib/rubocop/cop/style/return_nil.rb
726
730
  - lib/rubocop/cop/style/safe_navigation.rb
731
+ - lib/rubocop/cop/style/sample.rb
727
732
  - lib/rubocop/cop/style/self_assignment.rb
728
733
  - lib/rubocop/cop/style/semicolon.rb
729
734
  - lib/rubocop/cop/style/send.rb
@@ -737,6 +742,7 @@ files:
737
742
  - lib/rubocop/cop/style/string_literals.rb
738
743
  - lib/rubocop/cop/style/string_literals_in_interpolation.rb
739
744
  - lib/rubocop/cop/style/string_methods.rb
745
+ - lib/rubocop/cop/style/strip.rb
740
746
  - lib/rubocop/cop/style/struct_inheritance.rb
741
747
  - lib/rubocop/cop/style/symbol_array.rb
742
748
  - lib/rubocop/cop/style/symbol_literal.rb
@@ -756,6 +762,7 @@ files:
756
762
  - lib/rubocop/cop/style/unneeded_condition.rb
757
763
  - lib/rubocop/cop/style/unneeded_interpolation.rb
758
764
  - lib/rubocop/cop/style/unneeded_percent_q.rb
765
+ - lib/rubocop/cop/style/unneeded_sort.rb
759
766
  - lib/rubocop/cop/style/unpack_first.rb
760
767
  - lib/rubocop/cop/style/variable_interpolation.rb
761
768
  - lib/rubocop/cop/style/when_then.rb
@@ -829,7 +836,22 @@ metadata:
829
836
  source_code_uri: https://github.com/rubocop-hq/rubocop/
830
837
  documentation_uri: https://docs.rubocop.org/
831
838
  bug_tracker_uri: https://github.com/rubocop-hq/rubocop/issues
832
- post_install_message:
839
+ post_install_message: |
840
+ Performance Cops will be removed from RuboCop 0.68. Use rubocop-performance gem instead.
841
+
842
+ Put this in your Gemfile.
843
+
844
+ gem 'rubocop-performance'
845
+
846
+ And then execute:
847
+
848
+ $ bundle install
849
+
850
+ Put this into your .rubocop.yml.
851
+
852
+ require: rubocop-performance
853
+
854
+ More information: https://github.com/rubocop-hq/rubocop-performance
833
855
  rdoc_options: []
834
856
  require_paths:
835
857
  - lib