rubocop 0.2.1 → 0.3.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.
- data/.rubocop.yml +89 -0
- data/Rakefile +4 -3
- data/VERSION +1 -1
- data/lib/rubocop.rb +3 -0
- data/lib/rubocop/cli.rb +45 -7
- data/lib/rubocop/cop/ampersands_pipes_vs_and_or.rb +25 -0
- data/lib/rubocop/cop/blocks.rb +39 -28
- data/lib/rubocop/cop/cop.rb +7 -12
- data/lib/rubocop/cop/def_parentheses.rb +37 -24
- data/lib/rubocop/cop/encoding.rb +4 -4
- data/lib/rubocop/cop/if_then_else.rb +28 -15
- data/lib/rubocop/cop/offence.rb +1 -1
- data/lib/rubocop/cop/space_after_comma_etc.rb +27 -10
- data/lib/rubocop/cop/surrounding_space.rb +102 -53
- data/lib/rubocop/cop/ternary_operator.rb +27 -10
- data/lib/rubocop/cop/unless_else.rb +19 -0
- data/lib/rubocop/cop/when_then.rb +25 -0
- data/lib/rubocop/report/emacs_style.rb +2 -1
- data/rubocop.gemspec +24 -7
- data/spec/rubocop/cli_spec.rb +71 -1
- data/spec/rubocop/cops/align_parameters_spec.rb +4 -4
- data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +57 -0
- data/spec/rubocop/cops/cop_spec.rb +2 -2
- data/spec/rubocop/cops/{def_parentheses_spec.rb → def_with_parentheses_spec.rb} +3 -18
- data/spec/rubocop/cops/def_without_parentheses_spec.rb +26 -0
- data/spec/rubocop/cops/encoding_spec.rb +41 -0
- data/spec/rubocop/cops/end_of_line_spec.rb +6 -0
- data/spec/rubocop/cops/if_with_semicolon_spec.rb +17 -0
- data/spec/rubocop/cops/indentation_spec.rb +2 -1
- data/spec/rubocop/cops/{blocks_spec.rb → multiline_blocks_spec.rb} +2 -13
- data/spec/rubocop/cops/multiline_if_then_spec.rb +56 -0
- data/spec/rubocop/cops/one_line_conditional_spec.rb +17 -0
- data/spec/rubocop/cops/single_line_blocks_spec.rb +22 -0
- data/spec/rubocop/cops/{space_after_comma_etc_spec.rb → space_after_colon_spec.rb} +2 -14
- data/spec/rubocop/cops/space_after_comma_spec.rb +17 -0
- data/spec/rubocop/cops/space_after_semicolon_spec.rb +17 -0
- data/spec/rubocop/cops/space_around_braces_spec.rb +32 -0
- data/spec/rubocop/cops/{surrounding_space_spec.rb → space_around_operators_spec.rb} +4 -73
- data/spec/rubocop/cops/space_inside_brackets_spec.rb +43 -0
- data/spec/rubocop/cops/space_inside_parens_spec.rb +27 -0
- data/spec/rubocop/cops/ternary_operator_spec.rb +26 -6
- data/spec/rubocop/cops/unless_else_spec.rb +29 -0
- data/spec/rubocop/cops/when_then_spec.rb +38 -0
- data/spec/spec_helper.rb +5 -0
- metadata +25 -8
- data/spec/rubocop/cops/if_then_else_spec.rb +0 -74
@@ -1,74 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Rubocop
|
6
|
-
module Cop
|
7
|
-
describe IfThenElse do
|
8
|
-
let (:if_then_else) { IfThenElse.new }
|
9
|
-
|
10
|
-
# if
|
11
|
-
|
12
|
-
it 'registers an offence for then in multiline if' do
|
13
|
-
inspect_source(if_then_else, '', ['if cond then',
|
14
|
-
'end',
|
15
|
-
"if cond then\t",
|
16
|
-
'end',
|
17
|
-
'if cond then ',
|
18
|
-
'end',
|
19
|
-
'if cond then # bad',
|
20
|
-
'end'])
|
21
|
-
if_then_else.offences.size.should == 4
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'accepts multiline if without then' do
|
25
|
-
inspect_source(if_then_else, '', ['if cond',
|
26
|
-
'end'])
|
27
|
-
if_then_else.offences.map(&:message).sort.should == []
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'registers an offence for one line if/then/end' do
|
31
|
-
inspect_source(if_then_else, '', ['if cond then run else dont end'])
|
32
|
-
if_then_else.offences.map(&:message).sort.should ==
|
33
|
-
['Favor the ternary operator (?:) over if/then/else/end constructs.']
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'registers an offence for one line if/;/end' do
|
37
|
-
inspect_source(if_then_else, '', ['if cond; run else dont end'])
|
38
|
-
if_then_else.offences.map(&:message).sort.should ==
|
39
|
-
['Never use if x; Use the ternary operator instead.']
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'accepts table style if/then/elsif/ends' do
|
43
|
-
inspect_source(if_then_else, '',
|
44
|
-
['if @io == $stdout then str << "$stdout"',
|
45
|
-
'elsif @io == $stdin then str << "$stdin"',
|
46
|
-
'elsif @io == $stderr then str << "$stderr"',
|
47
|
-
'else str << @io.class.to_s',
|
48
|
-
'end'])
|
49
|
-
if_then_else.offences.map(&:message).sort.should == []
|
50
|
-
end
|
51
|
-
|
52
|
-
# unless
|
53
|
-
|
54
|
-
it 'registers an offence for then in multiline unless' do
|
55
|
-
inspect_source(if_then_else, '', ['unless cond then',
|
56
|
-
'end'])
|
57
|
-
if_then_else.offences.map(&:message).sort.should ==
|
58
|
-
['Never use then for multi-line if/unless.']
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'accepts multiline unless without then' do
|
62
|
-
inspect_source(if_then_else, '', ['unless cond',
|
63
|
-
'end'])
|
64
|
-
if_then_else.offences.map(&:message).sort.should == []
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'registers an offence for one line unless/then/ends' do
|
68
|
-
inspect_source(if_then_else, '', ['unless cond then run end'])
|
69
|
-
if_then_else.offences.map(&:message).sort.should ==
|
70
|
-
['Favor the ternary operator (?:) over if/then/else/end constructs.']
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|