rubocop 0.17.0 → 0.18.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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +65 -42
  3. data/CONTRIBUTING.md +20 -3
  4. data/config/enabled.yml +10 -0
  5. data/lib/rubocop.rb +7 -0
  6. data/lib/rubocop/cop/cop.rb +4 -13
  7. data/lib/rubocop/cop/lint/ambiguous_operator.rb +1 -1
  8. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +1 -1
  9. data/lib/rubocop/cop/lint/loop.rb +1 -1
  10. data/lib/rubocop/cop/lint/require_parentheses.rb +72 -0
  11. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -1
  12. data/lib/rubocop/cop/style/access_modifier_indentation.rb +3 -1
  13. data/lib/rubocop/cop/style/align_array.rb +1 -1
  14. data/lib/rubocop/cop/style/align_hash.rb +1 -1
  15. data/lib/rubocop/cop/style/align_parameters.rb +1 -1
  16. data/lib/rubocop/cop/style/def_parentheses.rb +1 -1
  17. data/lib/rubocop/cop/style/line_end_concatenation.rb +53 -0
  18. data/lib/rubocop/cop/style/nested_ternary_operator.rb +1 -1
  19. data/lib/rubocop/cop/style/proc.rb +6 -0
  20. data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
  21. data/lib/rubocop/cop/style/space_after_method_name.rb +1 -1
  22. data/lib/rubocop/cop/style/trailing_comma.rb +7 -0
  23. data/lib/rubocop/cop/style/word_array.rb +27 -0
  24. data/lib/rubocop/cop/util.rb +1 -0
  25. data/lib/rubocop/formatter/simple_text_formatter.rb +6 -2
  26. data/lib/rubocop/options.rb +1 -1
  27. data/lib/rubocop/path_util.rb +22 -0
  28. data/lib/rubocop/rake_task.rb +17 -3
  29. data/lib/rubocop/version.rb +1 -1
  30. data/rubocop.gemspec +2 -2
  31. data/spec/project_spec.rb +93 -0
  32. data/spec/rubocop/cli_spec.rb +27 -22
  33. data/spec/rubocop/cop/cop_spec.rb +1 -1
  34. data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +2 -2
  35. data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +1 -1
  36. data/spec/rubocop/cop/lint/block_alignment_spec.rb +5 -5
  37. data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +2 -2
  38. data/spec/rubocop/cop/lint/require_parentheses_spec.rb +82 -0
  39. data/spec/rubocop/cop/lint/rescue_exception_spec.rb +1 -1
  40. data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +9 -9
  41. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +54 -54
  42. data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +6 -6
  43. data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +49 -8
  44. data/spec/rubocop/cop/style/align_array_spec.rb +1 -1
  45. data/spec/rubocop/cop/style/align_hash_spec.rb +1 -1
  46. data/spec/rubocop/cop/style/align_parameters_spec.rb +2 -2
  47. data/spec/rubocop/cop/style/blocks_spec.rb +1 -1
  48. data/spec/rubocop/cop/style/case_indentation_spec.rb +1 -1
  49. data/spec/rubocop/cop/style/dot_position_spec.rb +1 -1
  50. data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +2 -2
  51. data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +3 -3
  52. data/spec/rubocop/cop/style/indentation_consistency_spec.rb +4 -4
  53. data/spec/rubocop/cop/style/indentation_width_spec.rb +3 -3
  54. data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +27 -0
  55. data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +1 -1
  56. data/spec/rubocop/cop/style/proc_spec.rb +5 -0
  57. data/spec/rubocop/cop/style/regexp_literal_spec.rb +4 -4
  58. data/spec/rubocop/cop/style/string_literals_spec.rb +7 -7
  59. data/spec/rubocop/cop/style/trailing_comma_spec.rb +27 -6
  60. data/spec/rubocop/cop/style/unless_else_spec.rb +1 -1
  61. data/spec/rubocop/cop/style/variable_interpolation_spec.rb +2 -2
  62. data/spec/rubocop/cop/style/word_array_spec.rb +10 -0
  63. data/spec/rubocop/cop/variable_inspector/variable_table_spec.rb +4 -4
  64. data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +1 -1
  65. data/spec/rubocop/formatter/formatter_set_spec.rb +1 -1
  66. data/spec/rubocop/path_util_spec.rb +42 -0
  67. data/spec/spec_helper.rb +3 -1
  68. metadata +29 -8
@@ -28,7 +28,7 @@ describe Rubocop::Cop::Style::TrailingComma, :config do
28
28
  expect(cop.highlights).to eq([','])
29
29
  end
30
30
 
31
- it 'registers an offence for trailing comma in a method call with hash' +
31
+ it 'registers an offence for trailing comma in a method call with hash' \
32
32
  ' parameters at the end' do
33
33
  inspect_source(cop, 'some_method(a, b, c: 0, d: 1, )')
34
34
  expect(cop.messages)
@@ -95,7 +95,7 @@ describe Rubocop::Cop::Style::TrailingComma, :config do
95
95
  expect(cop.highlights).to eq([','])
96
96
  end
97
97
 
98
- it 'registers an offence for trailing comma in a method call with ' +
98
+ it 'registers an offence for trailing comma in a method call with ' \
99
99
  'hash parameters at the end' do
100
100
  inspect_source(cop, ['some_method(',
101
101
  ' a,',
@@ -121,7 +121,7 @@ describe Rubocop::Cop::Style::TrailingComma, :config do
121
121
  expect(cop.offences).to be_empty
122
122
  end
123
123
 
124
- it 'accepts a method call with ' +
124
+ it 'accepts a method call with ' \
125
125
  'hash parameters at the end and no trailing comma' do
126
126
  inspect_source(cop, ['some_method(a,',
127
127
  ' b,',
@@ -130,6 +130,16 @@ describe Rubocop::Cop::Style::TrailingComma, :config do
130
130
  ' )'])
131
131
  expect(cop.offences).to be_empty
132
132
  end
133
+
134
+ it 'accepts comma inside a heredoc' \
135
+ ' parameters at the end' do
136
+ inspect_source(cop, ['route(help: {',
137
+ " 'auth' => <<-HELP.chomp",
138
+ ',',
139
+ 'HELP',
140
+ '})'])
141
+ expect(cop.offences).to be_empty
142
+ end
133
143
  end
134
144
 
135
145
  context 'when EnforcedStyleForMultiline is comma' do
@@ -154,7 +164,7 @@ describe Rubocop::Cop::Style::TrailingComma, :config do
154
164
  expect(cop.highlights).to eq(['c: 3333'])
155
165
  end
156
166
 
157
- it 'registers an offence for no trailing comma in a method call with' +
167
+ it 'registers an offence for no trailing comma in a method call with' \
158
168
  ' hash parameters at the end' do
159
169
  inspect_source(cop, ['some_method(',
160
170
  ' a,',
@@ -163,7 +173,7 @@ describe Rubocop::Cop::Style::TrailingComma, :config do
163
173
  ' d: 1',
164
174
  ' )'])
165
175
  expect(cop.messages)
166
- .to eq(['Put a comma after the last parameter of a multiline ' +
176
+ .to eq(['Put a comma after the last parameter of a multiline ' \
167
177
  'method call.'])
168
178
  expect(cop.highlights).to eq(['d: 1'])
169
179
  end
@@ -185,7 +195,7 @@ describe Rubocop::Cop::Style::TrailingComma, :config do
185
195
  expect(cop.offences).to be_empty
186
196
  end
187
197
 
188
- it 'accepts trailing comma in a method call with hash' +
198
+ it 'accepts trailing comma in a method call with hash' \
189
199
  ' parameters at the end' do
190
200
  inspect_source(cop, ['some_method(',
191
201
  ' a,',
@@ -195,6 +205,17 @@ describe Rubocop::Cop::Style::TrailingComma, :config do
195
205
  ' )'])
196
206
  expect(cop.offences).to be_empty
197
207
  end
208
+
209
+ it 'accepts missing comma after a heredoc' do
210
+ # A heredoc that's the last item in a literal or parameter list can not
211
+ # have a trailing comma. It's a syntax error.
212
+ inspect_source(cop, ['route(help: {',
213
+ " 'auth' => <<-HELP.chomp",
214
+ '...',
215
+ 'HELP',
216
+ '},)']) # We still need a comma after the hash.
217
+ expect(cop.offences).to be_empty
218
+ end
198
219
  end
199
220
  end
200
221
  end
@@ -12,7 +12,7 @@ describe Rubocop::Cop::Style::UnlessElse do
12
12
  ' a = 0',
13
13
  'end'])
14
14
  expect(cop.messages).to eq(
15
- ['Never use unless with else. Rewrite these with the ' +
15
+ ['Never use unless with else. Rewrite these with the ' \
16
16
  'positive case first.'])
17
17
  end
18
18
 
@@ -10,7 +10,7 @@ describe Rubocop::Cop::Style::VariableInterpolation do
10
10
  ['puts "this is a #$test"'])
11
11
  expect(cop.offences.size).to eq(1)
12
12
  expect(cop.messages)
13
- .to eq(['Replace interpolated var $test' +
13
+ .to eq(['Replace interpolated var $test' \
14
14
  ' with expression #{$test}.'])
15
15
  end
16
16
 
@@ -27,7 +27,7 @@ describe Rubocop::Cop::Style::VariableInterpolation do
27
27
  ['puts "this is a #@test"'])
28
28
  expect(cop.offences.size).to eq(1)
29
29
  expect(cop.messages)
30
- .to eq(['Replace interpolated var @test' +
30
+ .to eq(['Replace interpolated var @test' \
31
31
  ' with expression #{@test}.'])
32
32
  end
33
33
 
@@ -84,4 +84,14 @@ describe Rubocop::Cop::Style::WordArray, :config do
84
84
 
85
85
  expect(cop.offences.size).to eq(1)
86
86
  end
87
+
88
+ it 'auto-corrects an array of words' do
89
+ new_source = autocorrect_source(cop, "['one', %q(two), 'three']")
90
+ expect(new_source).to eq('%w(one two three)')
91
+ end
92
+
93
+ it 'auto-corrects an array of words and character constants' do
94
+ new_source = autocorrect_source(cop, '[%{one}, %Q(two), ?\n, ?\t]')
95
+ expect(new_source).to eq('%W(one two \n \t)')
96
+ end
87
97
  end
@@ -89,7 +89,7 @@ describe Rubocop::Cop::VariableInspector::VariableTable do
89
89
  variable_table.push_scope(s(:block))
90
90
  end
91
91
 
92
- context 'when a variable with the target name exists ' +
92
+ context 'when a variable with the target name exists ' \
93
93
  'in current scope' do
94
94
  before do
95
95
  variable_table.declare_variable(:foo, s(:lvasgn, :foo))
@@ -118,7 +118,7 @@ describe Rubocop::Cop::VariableInspector::VariableTable do
118
118
  end
119
119
  end
120
120
 
121
- context 'when a variable with the target name does not exist ' +
121
+ context 'when a variable with the target name does not exist ' \
122
122
  'in current scope' do
123
123
  context 'but exists in the direct outer scope' do
124
124
  it 'returns the direct outer scope variable' do
@@ -165,7 +165,7 @@ describe Rubocop::Cop::VariableInspector::VariableTable do
165
165
  variable_table.push_scope(s(:def))
166
166
  end
167
167
 
168
- context 'when a variable with the target name exists ' +
168
+ context 'when a variable with the target name exists ' \
169
169
  'in current scope' do
170
170
  before do
171
171
  variable_table.declare_variable(:foo, s(:lvasgn, :foo))
@@ -190,7 +190,7 @@ describe Rubocop::Cop::VariableInspector::VariableTable do
190
190
  end
191
191
  end
192
192
 
193
- context 'when a variable with the target name does not exist ' +
193
+ context 'when a variable with the target name does not exist ' \
194
194
  'in current scope' do
195
195
  context 'but exists in the direct outer scope' do
196
196
  it 'returns nil' do
@@ -40,7 +40,7 @@ module Rubocop
40
40
  expect($stdout.string)
41
41
  .to eq(['Created rubocop-todo.yml.',
42
42
  'Run rubocop with --config rubocop-todo.yml, or',
43
- 'add inherit_from: rubocop-todo.yml in a .rubocop.yml ' +
43
+ 'add inherit_from: rubocop-todo.yml in a .rubocop.yml ' \
44
44
  'file.',
45
45
  ''].join("\n"))
46
46
  end
@@ -96,7 +96,7 @@ module Rubocop
96
96
  .to eq(SimpleTextFormatter)
97
97
  end
98
98
 
99
- it 'returns class whose first letter of alias name ' +
99
+ it 'returns class whose first letter of alias name ' \
100
100
  'matches passed letter' do
101
101
  expect(builtin_formatter_class('s'))
102
102
  .to eq(SimpleTextFormatter)
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Rubocop::PathUtil do
6
+ describe '#relative_path' do
7
+ pending 'builds paths relative to the current project by default'
8
+ it 'builds paths relative to PWD by default as a stop-gap' do
9
+ relative = File.join(Dir.pwd, 'relative')
10
+ expect(subject.relative_path(relative)).to eq('relative')
11
+ end
12
+
13
+ it 'supports custom base paths' do
14
+ expect(subject.relative_path('/foo/bar', '/foo')).to eq('bar')
15
+ end
16
+ end
17
+
18
+ describe '#match_path?' do
19
+ it 'matches strings to the basename' do
20
+ expect(subject.match_path?('file', '/dir/file')).to be_true
21
+ expect(subject.match_path?('file', '/dir/files')).to be_false
22
+ expect(subject.match_path?('dir', '/dir/file')).to be_false
23
+ end
24
+
25
+ it 'matches strings to the full path' do
26
+ expect(subject.match_path?('/dir/file', '/dir/file')).to be_true
27
+ expect(subject.match_path?('/dir/file', '/dir/dir/file')).to be_false
28
+ end
29
+
30
+ it 'matches glob expressions' do
31
+ expect(subject.match_path?('dir/*', 'dir/file')).to be_true
32
+ expect(subject.match_path?('dir/*', 'dir/sub/file')).to be_true
33
+ expect(subject.match_path?('dir/**/*', 'dir/sub/file')).to be_true
34
+ expect(subject.match_path?('sub/*', 'dir/sub/file')).to be_false
35
+ end
36
+
37
+ it 'matches regexps' do
38
+ expect(subject.match_path?(/^d.*e$/, 'dir/file')).to be_true
39
+ expect(subject.match_path?(/^d.*e$/, 'dir/filez')).to be_false
40
+ end
41
+ end
42
+ end
@@ -91,7 +91,9 @@ end
91
91
 
92
92
  def parse_source(source, file = nil)
93
93
  source = source.join($RS) if source.is_a?(Array)
94
- if file
94
+ if file.is_a? String
95
+ Rubocop::SourceParser.parse(source, file)
96
+ elsif file
95
97
  file.write(source)
96
98
  file.rewind
97
99
  Rubocop::SourceParser.parse(source, file.path)
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-23 00:00:00.000000000 Z
11
+ date: 2014-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.99.1
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ~>
27
+ - - '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.99.1
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: parser
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +62,22 @@ dependencies:
56
62
  name: json
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
- - - ~>
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: 1.7.7
68
+ - - <
60
69
  - !ruby/object:Gem::Version
61
- version: '1.8'
70
+ version: '2'
62
71
  type: :runtime
63
72
  prerelease: false
64
73
  version_requirements: !ruby/object:Gem::Requirement
65
74
  requirements:
66
- - - ~>
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.7.7
78
+ - - <
67
79
  - !ruby/object:Gem::Version
68
- version: '1.8'
80
+ version: '2'
69
81
  - !ruby/object:Gem::Dependency
70
82
  name: rake
71
83
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +200,7 @@ files:
188
200
  - lib/rubocop/cop/lint/literal_in_condition.rb
189
201
  - lib/rubocop/cop/lint/loop.rb
190
202
  - lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb
203
+ - lib/rubocop/cop/lint/require_parentheses.rb
191
204
  - lib/rubocop/cop/lint/rescue_exception.rb
192
205
  - lib/rubocop/cop/lint/shadowing_outer_local_variable.rb
193
206
  - lib/rubocop/cop/lint/syntax.rb
@@ -277,6 +290,7 @@ files:
277
290
  - lib/rubocop/cop/style/lambda.rb
278
291
  - lib/rubocop/cop/style/lambda_call.rb
279
292
  - lib/rubocop/cop/style/leading_comment_space.rb
293
+ - lib/rubocop/cop/style/line_end_concatenation.rb
280
294
  - lib/rubocop/cop/style/line_length.rb
281
295
  - lib/rubocop/cop/style/method_call_parentheses.rb
282
296
  - lib/rubocop/cop/style/method_called_on_do_end_block.rb
@@ -359,6 +373,7 @@ files:
359
373
  - lib/rubocop/formatter/progress_formatter.rb
360
374
  - lib/rubocop/formatter/simple_text_formatter.rb
361
375
  - lib/rubocop/options.rb
376
+ - lib/rubocop/path_util.rb
362
377
  - lib/rubocop/processed_source.rb
363
378
  - lib/rubocop/rake_task.rb
364
379
  - lib/rubocop/source_parser.rb
@@ -394,6 +409,7 @@ files:
394
409
  - spec/rubocop/cop/lint/literal_in_condition_spec.rb
395
410
  - spec/rubocop/cop/lint/loop_spec.rb
396
411
  - spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb
412
+ - spec/rubocop/cop/lint/require_parentheses_spec.rb
397
413
  - spec/rubocop/cop/lint/rescue_exception_spec.rb
398
414
  - spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb
399
415
  - spec/rubocop/cop/lint/syntax_spec.rb
@@ -465,6 +481,7 @@ files:
465
481
  - spec/rubocop/cop/style/lambda_call_spec.rb
466
482
  - spec/rubocop/cop/style/lambda_spec.rb
467
483
  - spec/rubocop/cop/style/leading_comment_space_spec.rb
484
+ - spec/rubocop/cop/style/line_end_concatenation_spec.rb
468
485
  - spec/rubocop/cop/style/line_length_spec.rb
469
486
  - spec/rubocop/cop/style/method_call_parentheses_spec.rb
470
487
  - spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
@@ -546,6 +563,7 @@ files:
546
563
  - spec/rubocop/formatter/progress_formatter_spec.rb
547
564
  - spec/rubocop/formatter/simple_text_formatter_spec.rb
548
565
  - spec/rubocop/options_spec.rb
566
+ - spec/rubocop/path_util_spec.rb
549
567
  - spec/rubocop/processed_source_spec.rb
550
568
  - spec/rubocop/source_parser_spec.rb
551
569
  - spec/rubocop/target_finder_spec.rb
@@ -610,6 +628,7 @@ test_files:
610
628
  - spec/rubocop/cop/lint/literal_in_condition_spec.rb
611
629
  - spec/rubocop/cop/lint/loop_spec.rb
612
630
  - spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb
631
+ - spec/rubocop/cop/lint/require_parentheses_spec.rb
613
632
  - spec/rubocop/cop/lint/rescue_exception_spec.rb
614
633
  - spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb
615
634
  - spec/rubocop/cop/lint/syntax_spec.rb
@@ -681,6 +700,7 @@ test_files:
681
700
  - spec/rubocop/cop/style/lambda_call_spec.rb
682
701
  - spec/rubocop/cop/style/lambda_spec.rb
683
702
  - spec/rubocop/cop/style/leading_comment_space_spec.rb
703
+ - spec/rubocop/cop/style/line_end_concatenation_spec.rb
684
704
  - spec/rubocop/cop/style/line_length_spec.rb
685
705
  - spec/rubocop/cop/style/method_call_parentheses_spec.rb
686
706
  - spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
@@ -762,6 +782,7 @@ test_files:
762
782
  - spec/rubocop/formatter/progress_formatter_spec.rb
763
783
  - spec/rubocop/formatter/simple_text_formatter_spec.rb
764
784
  - spec/rubocop/options_spec.rb
785
+ - spec/rubocop/path_util_spec.rb
765
786
  - spec/rubocop/processed_source_spec.rb
766
787
  - spec/rubocop/source_parser_spec.rb
767
788
  - spec/rubocop/target_finder_spec.rb