rubocop 0.41.2 → 0.42.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -3
  3. data/config/default.yml +13 -0
  4. data/config/disabled.yml +5 -0
  5. data/config/enabled.yml +20 -0
  6. data/lib/rubocop.rb +4 -0
  7. data/lib/rubocop/ast_node.rb +4 -3
  8. data/lib/rubocop/config.rb +1 -1
  9. data/lib/rubocop/config_loader.rb +2 -7
  10. data/lib/rubocop/cop/cop.rb +3 -3
  11. data/lib/rubocop/cop/lint/block_alignment.rb +18 -16
  12. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +34 -19
  13. data/lib/rubocop/cop/lint/next_without_accumulator.rb +9 -1
  14. data/lib/rubocop/cop/lint/shadowed_exception.rb +23 -3
  15. data/lib/rubocop/cop/lint/unneeded_disable.rb +1 -1
  16. data/lib/rubocop/cop/lint/useless_access_modifier.rb +41 -4
  17. data/lib/rubocop/cop/mixin/array_hash_indentation.rb +1 -1
  18. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +1 -1
  19. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -5
  20. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +4 -4
  21. data/lib/rubocop/cop/mixin/space_inside.rb +23 -8
  22. data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -1
  23. data/lib/rubocop/cop/offense.rb +33 -10
  24. data/lib/rubocop/cop/performance/case_when_splat.rb +16 -14
  25. data/lib/rubocop/cop/performance/sample.rb +0 -1
  26. data/lib/rubocop/cop/rails/save_bang.rb +77 -0
  27. data/lib/rubocop/cop/rails/validation.rb +15 -15
  28. data/lib/rubocop/cop/style/access_modifier_indentation.rb +1 -1
  29. data/lib/rubocop/cop/style/align_hash.rb +1 -1
  30. data/lib/rubocop/cop/style/block_comments.rb +1 -3
  31. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +19 -10
  32. data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +1 -1
  33. data/lib/rubocop/cop/style/comment_annotation.rb +14 -14
  34. data/lib/rubocop/cop/style/comment_indentation.rb +1 -1
  35. data/lib/rubocop/cop/style/conditional_assignment.rb +25 -26
  36. data/lib/rubocop/cop/style/dot_position.rb +24 -19
  37. data/lib/rubocop/cop/style/each_for_simple_loop.rb +22 -8
  38. data/lib/rubocop/cop/style/each_with_object.rb +11 -1
  39. data/lib/rubocop/cop/style/else_alignment.rb +1 -1
  40. data/lib/rubocop/cop/style/empty_lines.rb +22 -11
  41. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +9 -6
  42. data/lib/rubocop/cop/style/empty_lines_around_block_body.rb +14 -14
  43. data/lib/rubocop/cop/style/empty_lines_around_class_body.rb +8 -5
  44. data/lib/rubocop/cop/style/empty_lines_around_method_body.rb +12 -8
  45. data/lib/rubocop/cop/style/empty_lines_around_module_body.rb +17 -4
  46. data/lib/rubocop/cop/style/empty_literal.rb +12 -7
  47. data/lib/rubocop/cop/style/for.rb +1 -1
  48. data/lib/rubocop/cop/style/indent_array.rb +1 -1
  49. data/lib/rubocop/cop/style/indent_hash.rb +1 -1
  50. data/lib/rubocop/cop/style/indentation_width.rb +1 -1
  51. data/lib/rubocop/cop/style/initial_indentation.rb +1 -1
  52. data/lib/rubocop/cop/style/lambda.rb +2 -3
  53. data/lib/rubocop/cop/style/method_call_parentheses.rb +6 -4
  54. data/lib/rubocop/cop/style/method_missing.rb +74 -0
  55. data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +1 -1
  56. data/lib/rubocop/cop/style/multiline_operation_indentation.rb +1 -1
  57. data/lib/rubocop/cop/style/nested_modifier.rb +23 -13
  58. data/lib/rubocop/cop/style/next.rb +1 -1
  59. data/lib/rubocop/cop/style/numeric_predicate.rb +142 -0
  60. data/lib/rubocop/cop/style/op_method.rb +12 -4
  61. data/lib/rubocop/cop/style/parallel_assignment.rb +11 -3
  62. data/lib/rubocop/cop/style/rescue_ensure_alignment.rb +9 -6
  63. data/lib/rubocop/cop/style/single_line_block_params.rb +3 -2
  64. data/lib/rubocop/cop/style/space_inside_block_braces.rb +1 -1
  65. data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +1 -1
  66. data/lib/rubocop/cop/style/symbol_array.rb +18 -10
  67. data/lib/rubocop/cop/style/ternary_parentheses.rb +94 -0
  68. data/lib/rubocop/cop/style/trailing_blank_lines.rb +1 -1
  69. data/lib/rubocop/cop/style/unneeded_percent_q.rb +12 -6
  70. data/lib/rubocop/cop/util.rb +1 -1
  71. data/lib/rubocop/cop/variable_force/assignment.rb +1 -1
  72. data/lib/rubocop/cop/variable_force/locatable.rb +1 -1
  73. data/lib/rubocop/formatter/disabled_config_formatter.rb +18 -7
  74. data/lib/rubocop/formatter/html_formatter.rb +25 -11
  75. data/lib/rubocop/formatter/text_util.rb +1 -1
  76. data/lib/rubocop/node_pattern.rb +2 -0
  77. data/lib/rubocop/processed_source.rb +3 -0
  78. data/lib/rubocop/rake_task.rb +1 -1
  79. data/lib/rubocop/rspec/shared_contexts.rb +4 -0
  80. data/lib/rubocop/runner.rb +18 -7
  81. data/lib/rubocop/string_util.rb +2 -5
  82. data/lib/rubocop/version.rb +1 -1
  83. metadata +7 -3
@@ -134,6 +134,7 @@ module RuboCop
134
134
  fail_due_to('unbalanced pattern') unless tokens.empty?
135
135
  end
136
136
 
137
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
137
138
  def compile_expr(tokens, cur_node, seq_head)
138
139
  # read a single pattern-matching expression from the token stream,
139
140
  # return Ruby code which performs the corresponding matching operation
@@ -160,6 +161,7 @@ module RuboCop
160
161
  else fail_due_to("invalid token #{token.inspect}")
161
162
  end
162
163
  end
164
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
163
165
 
164
166
  def compile_seq(tokens, cur_node, seq_head)
165
167
  fail_due_to('empty parentheses') if tokens.first == ')'
@@ -120,6 +120,9 @@ module RuboCop
120
120
  when 2.3
121
121
  require 'parser/ruby23'
122
122
  Parser::Ruby23
123
+ when 2.4
124
+ require 'parser/ruby24'
125
+ Parser::Ruby24
123
126
  else
124
127
  raise ArgumentError, "Unknown Ruby version: #{ruby_version.inspect}"
125
128
  end
@@ -47,7 +47,7 @@ module RuboCop
47
47
  cli = CLI.new
48
48
  puts 'Running RuboCop...' if verbose
49
49
  result = cli.run(options)
50
- abort('RuboCop failed!') if result != 0 && fail_on_error
50
+ abort('RuboCop failed!') if result.nonzero? && fail_on_error
51
51
  end
52
52
 
53
53
  def full_options
@@ -73,3 +73,7 @@ end
73
73
  shared_context 'ruby 2.3', :ruby23 do
74
74
  let(:ruby_version) { 2.3 }
75
75
  end
76
+
77
+ shared_context 'ruby 2.4', :ruby24 do
78
+ let(:ruby_version) { 2.4 }
79
+ end
@@ -79,21 +79,32 @@ module RuboCop
79
79
  puts "Scanning #{file}" if @options[:debug]
80
80
  file_started(file)
81
81
 
82
+ offenses = file_offenses(file)
83
+ formatter_set.file_finished(file, offenses)
84
+ offenses
85
+ rescue InfiniteCorrectionLoop => e
86
+ formatter_set.file_finished(file, e.offenses.compact.sort.freeze)
87
+ raise
88
+ end
89
+
90
+ def file_offenses(file)
91
+ file_offense_cache(file) do
92
+ source = get_processed_source(file)
93
+ source, offenses = do_inspection_loop(file, source)
94
+ add_unneeded_disables(file, offenses.compact.sort, source)
95
+ end
96
+ end
97
+
98
+ def file_offense_cache(file)
82
99
  cache = ResultCache.new(file, @options, @config_store) if cached_run?
83
100
  if cache && cache.valid?
84
101
  offenses = cache.load
85
102
  else
86
- source = get_processed_source(file)
87
- source, offenses = do_inspection_loop(file, source)
88
- offenses = add_unneeded_disables(file, offenses.compact.sort, source)
103
+ offenses = yield
89
104
  save_in_cache(cache, offenses)
90
105
  end
91
106
 
92
- formatter_set.file_finished(file, offenses)
93
107
  offenses
94
- rescue InfiniteCorrectionLoop => e
95
- formatter_set.file_finished(file, e.offenses.compact.sort.freeze)
96
- raise
97
108
  end
98
109
 
99
110
  def add_unneeded_disables(file, offenses, source)
@@ -55,12 +55,9 @@ module RuboCop
55
55
  common_chars_of_shorter = Array.new(shorter.size)
56
56
  common_chars_of_longer = Array.new(longer.size)
57
57
 
58
- # In Ruby 1.9 String#chars returns Enumerator rather than Array.
59
- longer_chars = longer.each_char.to_a
60
-
61
58
  shorter.each_char.with_index do |shorter_char, shorter_index|
62
59
  matching_index_range(shorter_index).each do |longer_index|
63
- longer_char = longer_chars[longer_index]
60
+ longer_char = longer.chars[longer_index]
64
61
 
65
62
  next unless shorter_char == longer_char
66
63
 
@@ -68,7 +65,7 @@ module RuboCop
68
65
  common_chars_of_longer[longer_index] = longer_char
69
66
 
70
67
  # Mark the matching character as already used
71
- longer_chars[longer_index] = nil
68
+ longer.chars[longer_index] = nil
72
69
 
73
70
  break
74
71
  end
@@ -4,7 +4,7 @@
4
4
  module RuboCop
5
5
  # This module holds the RuboCop version information.
6
6
  module Version
7
- STRING = '0.41.2'.freeze
7
+ STRING = '0.42.0'.freeze
8
8
 
9
9
  MSG = '%s (using Parser %s, running on %s %s %s)'.freeze
10
10
 
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.41.2
4
+ version: 0.42.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: 2016-07-07 00:00:00.000000000 Z
13
+ date: 2016-07-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rainbow
@@ -290,6 +290,7 @@ files:
290
290
  - lib/rubocop/cop/rails/pluralization_grammar.rb
291
291
  - lib/rubocop/cop/rails/read_write_attribute.rb
292
292
  - lib/rubocop/cop/rails/request_referer.rb
293
+ - lib/rubocop/cop/rails/save_bang.rb
293
294
  - lib/rubocop/cop/rails/scope_args.rb
294
295
  - lib/rubocop/cop/rails/time_zone.rb
295
296
  - lib/rubocop/cop/rails/uniq_before_pluck.rb
@@ -386,6 +387,7 @@ files:
386
387
  - lib/rubocop/cop/style/method_call_parentheses.rb
387
388
  - lib/rubocop/cop/style/method_called_on_do_end_block.rb
388
389
  - lib/rubocop/cop/style/method_def_parentheses.rb
390
+ - lib/rubocop/cop/style/method_missing.rb
389
391
  - lib/rubocop/cop/style/method_name.rb
390
392
  - lib/rubocop/cop/style/missing_else.rb
391
393
  - lib/rubocop/cop/style/module_function.rb
@@ -412,6 +414,7 @@ files:
412
414
  - lib/rubocop/cop/style/not.rb
413
415
  - lib/rubocop/cop/style/numeric_literal_prefix.rb
414
416
  - lib/rubocop/cop/style/numeric_literals.rb
417
+ - lib/rubocop/cop/style/numeric_predicate.rb
415
418
  - lib/rubocop/cop/style/one_line_conditional.rb
416
419
  - lib/rubocop/cop/style/op_method.rb
417
420
  - lib/rubocop/cop/style/option_hash.rb
@@ -472,6 +475,7 @@ files:
472
475
  - lib/rubocop/cop/style/symbol_literal.rb
473
476
  - lib/rubocop/cop/style/symbol_proc.rb
474
477
  - lib/rubocop/cop/style/tab.rb
478
+ - lib/rubocop/cop/style/ternary_parentheses.rb
475
479
  - lib/rubocop/cop/style/trailing_blank_lines.rb
476
480
  - lib/rubocop/cop/style/trailing_comma_in_arguments.rb
477
481
  - lib/rubocop/cop/style/trailing_comma_in_literal.rb
@@ -547,7 +551,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
547
551
  requirements:
548
552
  - - ">="
549
553
  - !ruby/object:Gem::Version
550
- version: 1.9.3
554
+ version: 2.0.0
551
555
  required_rubygems_version: !ruby/object:Gem::Requirement
552
556
  requirements:
553
557
  - - ">="