rubocop 0.7.1 → 0.7.2

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.

@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb18ed08073976272837da47ef0ba86606395c5b
4
+ data.tar.gz: f8c1cab8cf88ce7f1cbbb4815349e83cce88b5e3
5
+ SHA512:
6
+ metadata.gz: 19e21fa9f97a22498da1cf6fe7512e1fe64923ec9b87d10c4abcfbe7583acfc0f6f68bb32d6c4bf020425c20856c4fe9e323c7fda6e435f2dc694556111a819a
7
+ data.tar.gz: 4d9e3e6896f2a836d626ef81147288a5eec30bb084f22ad565de20805d52d3a5ee3f9c16cd96d833ae463beca321e6ba45e8dd9e216b5068cce6f549478db9e5
@@ -4,8 +4,16 @@
4
4
 
5
5
  ### New features
6
6
 
7
+ ## 0.7.2 (05/13/2013)
8
+
7
9
  ### Bugs fixed
8
10
 
11
+ * [#155](https://github.com/bbatsov/rubocop/issues/155) 'Do not use semicolons to terminate expressions.' is not implemented correctly
12
+ * `OpMethod` now handles definition of unary operators without crashing.
13
+ * `SymbolSnakeCase` now handles aliasing of operators without crashing.
14
+ * `RescueException` now handles the splat operator `*` in a `rescue` clause without crashing.
15
+ * [#159](https://github.com/bbatsov/rubocop/issues/159) AvoidFor cop misses many violations
16
+
9
17
  ## 0.7.1 (05/11/2013)
10
18
 
11
19
  ### Bugs fixed
@@ -116,17 +116,17 @@ module Rubocop
116
116
  end
117
117
 
118
118
  def keywords(tokens)
119
- # we need to keep track of the previous token to avoid
120
- # interpreting :some_keyword as the keyword some_keyword
119
+ # We need to keep track of the previous token to avoid
120
+ # interpreting :some_keyword as the keyword some_keyword.
121
121
  prev = Token.new(0, :init, '')
122
- # same goes for defs so we need to track those as well
122
+ # Same goes for defs so we need to track those as well.
123
123
  keywords = []
124
124
 
125
- tokens.each do |t|
126
- keywords << t if prev.type != :on_symbeg && t.type == :on_kw
127
- # def with name that's a kw confuses Ripper.lex
128
- penultimate = keywords[-2]
129
- keywords.pop if penultimate && penultimate.text == 'def'
125
+ tokens.reject { |t| whitespace?(t) }.each do |t|
126
+ if prev.type != :on_symbeg && t.type == :on_kw &&
127
+ [prev.type, prev.text] != [:on_kw, 'def']
128
+ keywords << t
129
+ end
130
130
  prev = t
131
131
  end
132
132
 
@@ -7,22 +7,30 @@ module Rubocop
7
7
 
8
8
  def inspect(file, source, tokens, sexp)
9
9
  each(:def, sexp) do |s|
10
- if s[1][0] == :@op && !%w([] []= <<).include?(s[1][1])
11
- if s[2][0] == :paren
12
- # param is surrounded by braces
13
- param = s[2][1][1][0]
14
- else
15
- param = s[2][1][0]
16
- end
17
-
18
- unless param[1] == 'other'
10
+ if binary_operator?(s) && !%w([] []= <<).include?(s[1][1])
11
+ params = parameters(s[2])
12
+ unless params[0][1] == 'other'
19
13
  add_offence(:convention,
20
- param[2].lineno,
14
+ params[0][2].lineno,
21
15
  sprintf(ERROR_MESSAGE, s[1][1]))
22
16
  end
23
17
  end
24
18
  end
25
19
  end
20
+
21
+ private
22
+
23
+ def binary_operator?(def_sexp)
24
+ def_sexp[1][0] == :@op && parameters(def_sexp[2]).size == 1
25
+ end
26
+
27
+ def parameters(param_sexp)
28
+ if param_sexp[0] == :paren # param is surrounded by braces?
29
+ parameters(param_sexp[1])
30
+ else
31
+ param_sexp[1] || []
32
+ end
33
+ end
26
34
  end
27
35
  end
28
36
  end
@@ -30,6 +30,9 @@ module Rubocop
30
30
  elsif s[1][0][0] == :const_path_ref
31
31
  # rescue Module::Class
32
32
  false
33
+ elsif s[1][0] == :mrhs_add_star
34
+ # rescue *ERRORS
35
+ false
33
36
  else
34
37
  true
35
38
  end
@@ -33,9 +33,10 @@ module Rubocop
33
33
  def index_of_first_token_on_line(ix, lineno)
34
34
  # Index of last token on the previous line
35
35
  prev_line_ix =
36
- @tokens[0...ix].rindex { |t| t.pos.lineno < lineno } || 0
36
+ @tokens[0...ix].rindex { |t| t.pos.lineno < lineno } || -1
37
+ first = prev_line_ix + 1
37
38
  # Index of first non-whitespace token on the current line.
38
- prev_line_ix + @tokens[prev_line_ix..ix].index { |t| !whitespace?(t) }
39
+ first + @tokens[first..ix].index { |t| !whitespace?(t) }
39
40
  end
40
41
 
41
42
  def handle_exceptions_to_the_rule(token_1_ix)
@@ -12,7 +12,7 @@ module Rubocop
12
12
  array_elems = s[1]
13
13
 
14
14
  # no need to check empty arrays
15
- return unless array_elems && array_elems.size > 1
15
+ next unless array_elems && array_elems.size > 1
16
16
 
17
17
  symbol_array = array_elems.all? { |e| e[0] == :symbol_literal }
18
18
 
@@ -14,7 +14,7 @@ module Rubocop
14
14
 
15
15
  def check_for_symbols(sexp)
16
16
  each(:symbol_literal, sexp) do |s|
17
- symbol_type = s[1][1][0]
17
+ symbol_type = s[1][0] == :symbol ? s[1][1][0] : s[1][0]
18
18
 
19
19
  # don't check operators
20
20
  next if symbol_type == :@op
@@ -10,7 +10,7 @@ module Rubocop
10
10
  array_elems = s[1]
11
11
 
12
12
  # no need to check empty arrays
13
- return unless array_elems && array_elems.size > 1
13
+ next unless array_elems && array_elems.size > 1
14
14
 
15
15
  string_array = array_elems.all? { |e| e[0] == :string_literal }
16
16
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubocop
4
4
  module Version
5
- STRING = '0.7.1'
5
+ STRING = '0.7.2'
6
6
  end
7
7
  end
@@ -1,4 +1,5 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
+
2
3
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
4
  require 'rubocop/version'
4
5
  require 'English'
@@ -191,7 +191,7 @@ module Rubocop
191
191
  end
192
192
 
193
193
  it 'exits with error if an incorrect cop name is passed to --only' do
194
- expect(cli.run(['--only', '123'])).to eq(1)
194
+ expect(cli.run(%w(--only 123))).to eq(1)
195
195
  expect($stdout.string).to eq("Unrecognized cop name: 123.\n")
196
196
  end
197
197
 
@@ -10,8 +10,10 @@ module Rubocop
10
10
  it 'registers an offence for for' do
11
11
  inspect_source(af,
12
12
  'file.rb',
13
- ['for n in [1, 2, 3] do',
14
- ' puts n',
13
+ ['def func',
14
+ ' for n in [1, 2, 3] do',
15
+ ' puts n',
16
+ ' end',
15
17
  'end'])
16
18
  expect(af.offences.size).to eq(1)
17
19
  expect(af.offences.map(&:message))
@@ -45,7 +45,8 @@ module Rubocop
45
45
  it 'does not register an offence for #! on first line' do
46
46
  inspect_source(lcs,
47
47
  'file.rb',
48
- ['#!/usr/bin/ruby'])
48
+ ['#!/usr/bin/ruby',
49
+ 'test'])
49
50
  expect(lcs.offences).to be_empty
50
51
  end
51
52
 
@@ -106,7 +106,7 @@ module Rubocop
106
106
 
107
107
  it 'properly counts lines when method ends with block' do
108
108
  inspect_source(method_length, '', ['def m()',
109
- ' do',
109
+ ' something do',
110
110
  ' a = 2',
111
111
  ' a = 3',
112
112
  ' a = 4',
@@ -64,6 +64,22 @@ module Rubocop
64
64
  'end'])
65
65
  expect(om.offences).to be_empty
66
66
  end
67
+
68
+ it 'does not register an offence for non binary operators' do
69
+ inspect_source(om,
70
+ 'file.rb',
71
+ ['def -@', # Unary minus
72
+ 'end',
73
+ '',
74
+ # This + is not a unary operator. It can only be
75
+ # called with dot notation.
76
+ 'def +',
77
+ 'end',
78
+ '',
79
+ 'def *(a, b)', # Quite strange, but legal ruby.
80
+ 'end'])
81
+ expect(om.offences).to be_empty
82
+ end
67
83
  end
68
84
  end
69
85
  end
@@ -68,6 +68,18 @@ module Rubocop
68
68
  'end'])
69
69
  expect(re.offences).to be_empty
70
70
  end
71
+
72
+ it 'does not crash when the splat operator is used in a rescue' do
73
+ inspect_source(re,
74
+ 'file.rb',
75
+ ['ERRORS = [Exception]',
76
+ 'begin',
77
+ ' a = 3 / 0',
78
+ 'rescue *ERRORS',
79
+ ' puts e',
80
+ 'end'])
81
+ expect(re.offences).to be_empty
82
+ end
71
83
  end
72
84
  end
73
85
  end
@@ -29,9 +29,9 @@ module Rubocop
29
29
  inspect_source(rm,
30
30
  'file.rb',
31
31
  ['begin',
32
- 'test',
32
+ ' test',
33
33
  'rescue',
34
- 'handle',
34
+ ' handle',
35
35
  'end'])
36
36
  expect(rm.offences).to be_empty
37
37
  end
@@ -81,8 +81,20 @@ module Rubocop
81
81
  it 'accepts one line empty class definitions' do
82
82
  inspect_source(s,
83
83
  'file.rb',
84
- [' class Foo < Exception; end',
85
- ' class Bar; end'])
84
+ ['# Prefer a single-line format for class ...',
85
+ 'class Foo < Exception; end',
86
+ '',
87
+ 'class Bar; end'])
88
+ expect(s.offences).to be_empty
89
+ end
90
+
91
+ it 'accepts one line empty method definitions' do
92
+ inspect_source(s,
93
+ 'file.rb',
94
+ ['# One exception to the rule are empty-body methods',
95
+ 'def no_op; end',
96
+ '',
97
+ 'def foo; end'])
86
98
  expect(s.offences).to be_empty
87
99
  end
88
100
 
@@ -128,7 +128,7 @@ module Rubocop
128
128
  end
129
129
 
130
130
  it 'accepts an assignment followed by newline' do
131
- inspect_source(space, 'file.rb', ['x =\n 0'])
131
+ inspect_source(space, 'file.rb', ['x =', '0'])
132
132
  expect(space.offences).to be_empty
133
133
  end
134
134
 
@@ -77,6 +77,12 @@ module Rubocop
77
77
  expect(snake_case.offences).to be_empty
78
78
  end
79
79
 
80
+ it 'can handle an alias of and operator without crashing' do
81
+ inspect_source(snake_case, 'file.rb',
82
+ ['alias + add'])
83
+ expect(snake_case.offences).to be_empty
84
+ end
85
+
80
86
  it 'registers an offence for SCREAMING_SNAKE_CASE' do
81
87
  inspect_source(snake_case, 'file.rb',
82
88
  ['test = :BAD_IDEA'])
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
5
- prerelease:
4
+ version: 0.7.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Bozhidar Batsov
@@ -14,23 +13,20 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rainbow
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.1.4
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 1.1.4
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: yard
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: bundler
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: simplecov
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ~>
100
88
  - !ruby/object:Gem::Version
@@ -102,13 +90,13 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ~>
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0.7'
110
- description: ! " Automatic Ruby code style checking tool.\n Aims to enforce
111
- the community-driven Ruby Style Guide.\n"
97
+ description: |2
98
+ Automatic Ruby code style checking tool.
99
+ Aims to enforce the community-driven Ruby Style Guide.
112
100
  email: bozhidar@batsov.com
113
101
  executables:
114
102
  - rubocop
@@ -273,7 +261,7 @@ files:
273
261
  - spec/rubocop/cops/percent_r_spec.rb
274
262
  - spec/rubocop/cops/reduce_arguments_spec.rb
275
263
  - spec/rubocop/cops/rescue_exception_spec.rb
276
- - spec/rubocop/cops/rescue_modifier.rb
264
+ - spec/rubocop/cops/rescue_modifier_spec.rb
277
265
  - spec/rubocop/cops/semicolon_spec.rb
278
266
  - spec/rubocop/cops/single_line_blocks_spec.rb
279
267
  - spec/rubocop/cops/single_line_methods_spec.rb
@@ -307,30 +295,26 @@ files:
307
295
  homepage: http://github.com/bbatsov/rubocop
308
296
  licenses:
309
297
  - MIT
298
+ metadata: {}
310
299
  post_install_message:
311
300
  rdoc_options: []
312
301
  require_paths:
313
302
  - lib
314
303
  required_ruby_version: !ruby/object:Gem::Requirement
315
- none: false
316
304
  requirements:
317
- - - ! '>='
305
+ - - '>='
318
306
  - !ruby/object:Gem::Version
319
307
  version: 1.9.2
320
308
  required_rubygems_version: !ruby/object:Gem::Requirement
321
- none: false
322
309
  requirements:
323
- - - ! '>='
310
+ - - '>='
324
311
  - !ruby/object:Gem::Version
325
312
  version: '0'
326
- segments:
327
- - 0
328
- hash: 3818294500784627882
329
313
  requirements: []
330
314
  rubyforge_project:
331
- rubygems_version: 1.8.23
315
+ rubygems_version: 2.0.3
332
316
  signing_key:
333
- specification_version: 3
317
+ specification_version: 4
334
318
  summary: Automatic Ruby code style checking tool.
335
319
  test_files:
336
320
  - spec/project_spec.rb
@@ -394,7 +378,7 @@ test_files:
394
378
  - spec/rubocop/cops/percent_r_spec.rb
395
379
  - spec/rubocop/cops/reduce_arguments_spec.rb
396
380
  - spec/rubocop/cops/rescue_exception_spec.rb
397
- - spec/rubocop/cops/rescue_modifier.rb
381
+ - spec/rubocop/cops/rescue_modifier_spec.rb
398
382
  - spec/rubocop/cops/semicolon_spec.rb
399
383
  - spec/rubocop/cops/single_line_blocks_spec.rb
400
384
  - spec/rubocop/cops/single_line_methods_spec.rb