rubocop 0.4.2 → 0.4.3

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.

@@ -18,11 +18,11 @@ Tab:
18
18
  TrailingWhitespace:
19
19
  Enabled: true
20
20
 
21
- # Use two spaces per indentation level.
21
+ # Indent when as deep as case.
22
22
  Indentation:
23
23
  Enabled: true
24
24
 
25
- # Use empty lines between defs and to break up a method into logical paragraphs.
25
+ # Use empty lines between defs.
26
26
  EmptyLines:
27
27
  Enabled: true
28
28
 
@@ -78,12 +78,15 @@ DefWithParentheses:
78
78
  DefWithoutParentheses:
79
79
  Enabled: true
80
80
 
81
+ # Never use if x; .... Use the ternary operator instead.
81
82
  IfWithSemicolon:
82
83
  Enabled: true
83
84
 
85
+ # Never use then for multi-line if/unless.
84
86
  MultilineIfThen:
85
87
  Enabled: true
86
88
 
89
+ # Favor the ternary operator(?:) over if/then/else/end constructs.
87
90
  OneLineConditional:
88
91
  Enabled: true
89
92
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
@@ -41,11 +41,12 @@ module Rubocop
41
41
  # means there's only one parameter.
42
42
  return nil if [:command, :command_call].include?(arg_paren[1][0][0])
43
43
 
44
- args_add_block = arg_paren[1]
45
- unless args_add_block[0] == :args_add_block
46
- fail "\n#{@file}: #{method_add_arg}"
44
+ if arg_paren[1][0] == :args_add_block
45
+ args_add_block = arg_paren[1]
46
+ args_add_block[1].empty? ? [args_add_block[2]] : args_add_block[1]
47
+ else
48
+ arg_paren[1]
47
49
  end
48
- args_add_block[1].empty? ? [args_add_block[2]] : args_add_block[1]
49
50
  end
50
51
 
51
52
  def divide_args(args)
@@ -10,8 +10,17 @@ module Rubocop
10
10
  Open3.capture3('ruby -wc', stdin_data: source.join("\n"))
11
11
 
12
12
  stderr.each_line do |line|
13
- line_no, warning = line.match(/.+:(\d+): warning: (.+)/).captures
14
- add_offence(:warning, line_no.to_i, warning.capitalize) if line_no
13
+ line_no, severity, message = process_line(line)
14
+ add_offence(severity, line_no, message)
15
+ end
16
+ end
17
+
18
+ def process_line(line)
19
+ line_no, message = line.match(/.+:(\d+): (.+)/).captures
20
+ if message.start_with?('warning: ')
21
+ [line_no.to_i, :warning, message.sub(/warning: /, '').capitalize]
22
+ else
23
+ [line_no.to_i, :error, message.capitalize]
15
24
  end
16
25
  end
17
26
  end
@@ -11,6 +11,9 @@ module Rubocop
11
11
  # when <value> <divider> <body>
12
12
  # where divider is either semicolon, then, or line break.
13
13
  last_pos_in_value = all_positions(s[1])[-1]
14
+
15
+ next unless last_pos_in_value # Give up if no positions found.
16
+
14
17
  start_index = tokens.index { |t| t.pos == last_pos_in_value }
15
18
  tokens[start_index..-1].each do |t|
16
19
  break if ['then', "\n"].include?(t.text)
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Rubocop
4
- VERSION = '0.4.2'
4
+ VERSION = IO.read(File.join(File.dirname(__FILE__), '../../VERSION'))
5
5
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rubocop"
8
- s.version = "0.4.2"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bozhidar Batsov"]
12
- s.date = "2013-04-13"
12
+ s.date = "2013-04-14"
13
13
  s.description = "Automatic Ruby code style checking tool. Aims to enforce the community-driven Ruby Style Guide."
14
14
  s.email = "bozhidar@batsov.com"
15
15
  s.executables = ["rubocop"]
@@ -9,7 +9,7 @@ module Rubocop
9
9
 
10
10
  it 'registers an offence for parameters with single indent' do
11
11
  inspect_source(align, 'file.rb', ['function(a,',
12
- ' if b then c else d end)'])
12
+ ' if b then c else d end)'])
13
13
  expect(align.offences.map(&:message)).to eq(
14
14
  ['Align the parameters of a method call if they span more than ' +
15
15
  'one line.'])
@@ -17,7 +17,7 @@ module Rubocop
17
17
 
18
18
  it 'registers an offence for parameters with double indent' do
19
19
  inspect_source(align, 'file.rb', ['function(a,',
20
- ' if b then c else d end)'])
20
+ ' if b then c else d end)'])
21
21
  expect(align.offences.map(&:message)).to eq(
22
22
  ['Align the parameters of a method call if they span more than ' +
23
23
  'one line.'])
@@ -25,9 +25,9 @@ module Rubocop
25
25
 
26
26
  it 'accepts correctly aligned parameters' do
27
27
  inspect_source(align, 'file.rb', ['function(a,',
28
- ' 0, 1,',
29
- ' (x + y),',
30
- ' if b then c else d end)'])
28
+ ' 0, 1,',
29
+ ' (x + y),',
30
+ ' if b then c else d end)'])
31
31
  expect(align.offences.map(&:message)).to be_empty
32
32
  end
33
33
 
@@ -58,6 +58,15 @@ module Rubocop
58
58
  'more than one line.'])
59
59
  end
60
60
 
61
+ it "doesn't get confused by extra comma at the end" do
62
+ inspect_source(align, '',
63
+ ['func1(a,',
64
+ ' b,)'])
65
+ expect(align.offences.map(&:to_s)).to eq(
66
+ ['C: 2: Align the parameters of a method call if they span ' +
67
+ 'more than one line.'])
68
+ end
69
+
61
70
  it 'can handle a correctly aligned string literal as first argument' do
62
71
  inspect_source(align, '',
63
72
  ['add_offence(:convention, x,',
@@ -13,6 +13,22 @@ module Rubocop
13
13
  expect(sc.offences.first.message)
14
14
  .to eq('Assigned but unused variable - x')
15
15
  end
16
+
17
+ describe '#process_line' do
18
+ it 'processes warnings correctly' do
19
+ l, s, m = sc.process_line('admin.rb:1: warning: possibly useless')
20
+ expect(l).to eq(1)
21
+ expect(s).to eq(:warning)
22
+ expect(m).to eq('Possibly useless')
23
+ end
24
+
25
+ it 'processes errors correctly' do
26
+ l, s, m = sc.process_line('admin.rb:1: unterminated string meets')
27
+ expect(l).to eq(1)
28
+ expect(s).to eq(:error)
29
+ expect(m).to eq('Unterminated string meets')
30
+ end
31
+ end
16
32
  end
17
33
  end
18
34
  end
@@ -15,6 +15,13 @@ module Rubocop
15
15
  ['Never use "when x;". Use "when x then" instead.'])
16
16
  end
17
17
 
18
+ it 'misses semicolon but does not crash when there are no tokens' do
19
+ inspect_source(wt, 'file.rb', ['case a',
20
+ 'when []; {}',
21
+ 'end'])
22
+ expect(wt.offences.map(&:message)).to eq([])
23
+ end
24
+
18
25
  it 'accepts when x then' do
19
26
  inspect_source(wt, 'file.rb', ['case a',
20
27
  'when b then c',
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.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-13 00:00:00.000000000 Z
12
+ date: 2013-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: term-ansicolor
@@ -254,7 +254,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
254
254
  version: '0'
255
255
  segments:
256
256
  - 0
257
- hash: 3258861329978794858
257
+ hash: -2923028741214038028
258
258
  required_rubygems_version: !ruby/object:Gem::Requirement
259
259
  none: false
260
260
  requirements: