rubocop 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rubocop.yml +78 -0
- data/CHANGELOG.md +22 -0
- data/CONTRIBUTING.md +13 -6
- data/Gemfile.lock +3 -3
- data/README.md +42 -1
- data/VERSION +1 -1
- data/bin/rubocop +1 -0
- data/lib/rubocop/cli.rb +47 -18
- data/lib/rubocop/cop/alias.rb +21 -0
- data/lib/rubocop/cop/align_parameters.rb +5 -4
- data/lib/rubocop/cop/avoid_class_vars.rb +20 -0
- data/lib/rubocop/cop/avoid_for.rb +17 -0
- data/lib/rubocop/cop/avoid_perl_backrefs.rb +20 -0
- data/lib/rubocop/cop/avoid_perlisms.rb +55 -0
- data/lib/rubocop/cop/blocks.rb +1 -1
- data/lib/rubocop/cop/cop.rb +1 -1
- data/lib/rubocop/cop/favor_sprintf.rb +45 -0
- data/lib/rubocop/cop/grammar.rb +3 -3
- data/lib/rubocop/cop/offence.rb +3 -1
- data/lib/rubocop/cop/semicolon.rb +18 -0
- data/lib/rubocop/cop/space_after_comma_etc.rb +2 -1
- data/lib/rubocop/cop/string_literals.rb +12 -0
- data/lib/rubocop/cop/symbol_snake_case.rb +27 -0
- data/lib/rubocop/cop/syntax.rb +14 -2
- data/lib/rubocop/cop/variable_interpolation.rb +20 -0
- data/lib/rubocop/cop/when_then.rb +3 -0
- data/lib/rubocop/report/emacs_style.rb +2 -2
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +9 -0
- data/rubocop.gemspec +21 -2
- data/spec/rubocop/cli_spec.rb +68 -1
- data/spec/rubocop/cops/alias_spec.rb +27 -0
- data/spec/rubocop/cops/align_parameters_spec.rb +14 -5
- data/spec/rubocop/cops/avoid_class_vars_spec.rb +20 -0
- data/spec/rubocop/cops/avoid_for_spec.rb +22 -0
- data/spec/rubocop/cops/avoid_perl_backrefs_spec.rb +18 -0
- data/spec/rubocop/cops/avoid_perlisms_spec.rb +32 -0
- data/spec/rubocop/cops/favor_sprintf_spec.rb +50 -0
- data/spec/rubocop/cops/grammar_spec.rb +3 -7
- data/spec/rubocop/cops/offence_spec.rb +6 -0
- data/spec/rubocop/cops/semicolon_spec.rb +29 -0
- data/spec/rubocop/cops/string_literals_spec.rb +4 -1
- data/spec/rubocop/cops/symbol_snake_case_spec.rb +62 -0
- data/spec/rubocop/cops/syntax_spec.rb +16 -0
- data/spec/rubocop/cops/variable_interpolation_spec.rb +45 -0
- data/spec/rubocop/cops/when_then_spec.rb +7 -0
- metadata +22 -3
|
@@ -18,6 +18,12 @@ module Rubocop
|
|
|
18
18
|
|
|
19
19
|
expect(offence.to_s).to eq('C: 1: message')
|
|
20
20
|
end
|
|
21
|
+
|
|
22
|
+
it 'does not blow up if a message contains %' do
|
|
23
|
+
offence = Offence.new(:convention, 1, 'message % test')
|
|
24
|
+
|
|
25
|
+
expect(offence.to_s).to eq('C: 1: message % test')
|
|
26
|
+
end
|
|
21
27
|
end
|
|
22
28
|
end
|
|
23
29
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
describe Semicolon do
|
|
8
|
+
let(:s) { Semicolon.new }
|
|
9
|
+
|
|
10
|
+
it 'registers an offence for a single expression' do
|
|
11
|
+
inspect_source(s,
|
|
12
|
+
'file.rb',
|
|
13
|
+
['puts "this is a test";'])
|
|
14
|
+
expect(s.offences.size).to eq(1)
|
|
15
|
+
expect(s.offences.map(&:message))
|
|
16
|
+
.to eq([Semicolon::ERROR_MESSAGE])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'registers an offence for several expressions' do
|
|
20
|
+
inspect_source(s,
|
|
21
|
+
'file.rb',
|
|
22
|
+
['puts "this is a test"; puts "So is this"'])
|
|
23
|
+
expect(s.offences.size).to eq(1)
|
|
24
|
+
expect(s.offences.map(&:message))
|
|
25
|
+
.to eq([Semicolon::ERROR_MESSAGE])
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -17,7 +17,10 @@ module Rubocop
|
|
|
17
17
|
it 'accepts double quotes when they are needed' do
|
|
18
18
|
src = ['a = "\n"',
|
|
19
19
|
'b = "#{encode_severity}:#{sprintf("%3d", line_number)}: #{m}"',
|
|
20
|
-
'c = "\'"'
|
|
20
|
+
'c = "\'"',
|
|
21
|
+
'd = "#@test"',
|
|
22
|
+
'e = "#$test"',
|
|
23
|
+
'f = "#@@test"']
|
|
21
24
|
inspect_source(sl, 'file.rb', src)
|
|
22
25
|
expect(sl.offences.map(&:message)).to be_empty
|
|
23
26
|
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
describe SymbolSnakeCase do
|
|
8
|
+
let(:snake_case) { SymbolSnakeCase.new }
|
|
9
|
+
|
|
10
|
+
it 'registers an offence for camel case in names' do
|
|
11
|
+
inspect_source(snake_case, 'file.rb',
|
|
12
|
+
['test = :BadIdea'])
|
|
13
|
+
expect(snake_case.offences.map(&:message)).to eq(
|
|
14
|
+
['Use snake_case for symbols.'])
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'accepts snake case in names' do
|
|
18
|
+
inspect_source(snake_case, 'file.rb',
|
|
19
|
+
['test = :good_idea'])
|
|
20
|
+
expect(snake_case.offences.map(&:message)).to be_empty
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'accepts snake case with a prefix @ in names' do
|
|
24
|
+
inspect_source(snake_case, 'file.rb',
|
|
25
|
+
['test = :@good_idea'])
|
|
26
|
+
expect(snake_case.offences.map(&:message)).to be_empty
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'accepts snake case with ? suffix' do
|
|
30
|
+
inspect_source(snake_case, 'file.rb',
|
|
31
|
+
['test = :good_idea?'])
|
|
32
|
+
expect(snake_case.offences.map(&:message)).to be_empty
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'accepts snake case with ! suffix' do
|
|
36
|
+
inspect_source(snake_case, 'file.rb',
|
|
37
|
+
['test = :good_idea!'])
|
|
38
|
+
expect(snake_case.offences.map(&:message)).to be_empty
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'accepts snake case with = suffix' do
|
|
42
|
+
inspect_source(snake_case, 'file.rb',
|
|
43
|
+
['test = :good_idea='])
|
|
44
|
+
expect(snake_case.offences.map(&:message)).to be_empty
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'accepts special cases - !, [] and **' do
|
|
48
|
+
inspect_source(snake_case, 'file.rb',
|
|
49
|
+
['test = :**',
|
|
50
|
+
'test = :!',
|
|
51
|
+
'test = :[]'])
|
|
52
|
+
expect(snake_case.offences.map(&:message)).to be_empty
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'registers an offence for SCREAMING_SNAKE_CASE' do
|
|
56
|
+
inspect_source(snake_case, 'file.rb',
|
|
57
|
+
['test = :BAD_IDEA'])
|
|
58
|
+
expect(snake_case.offences.size).to eq(1)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -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
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
describe VariableInterpolation do
|
|
8
|
+
let(:vi) { VariableInterpolation.new }
|
|
9
|
+
|
|
10
|
+
it 'registers an offence for interpolated global variables' do
|
|
11
|
+
inspect_source(vi,
|
|
12
|
+
'file.rb',
|
|
13
|
+
['puts "this is a #$test"'])
|
|
14
|
+
expect(vi.offences.size).to eq(1)
|
|
15
|
+
expect(vi.offences.map(&:message))
|
|
16
|
+
.to eq(['Replace interpolated var $test with expression #{$test}.'])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'registers an offence for interpolated instance variables' do
|
|
20
|
+
inspect_source(vi,
|
|
21
|
+
'file.rb',
|
|
22
|
+
['puts "this is a #@test"'])
|
|
23
|
+
expect(vi.offences.size).to eq(1)
|
|
24
|
+
expect(vi.offences.map(&:message))
|
|
25
|
+
.to eq(['Replace interpolated var @test with expression #{@test}.'])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'registers an offence for interpolated class variables' do
|
|
29
|
+
inspect_source(vi,
|
|
30
|
+
'file.rb',
|
|
31
|
+
['puts "this is a #@@t"'])
|
|
32
|
+
expect(vi.offences.size).to eq(1)
|
|
33
|
+
expect(vi.offences.map(&:message))
|
|
34
|
+
.to eq(['Replace interpolated var @@t with expression #{@@t}.'])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'does not register an offence for variables in expressions' do
|
|
38
|
+
inspect_source(vi,
|
|
39
|
+
'file.rb',
|
|
40
|
+
['puts "this is a #{@test}"'])
|
|
41
|
+
expect(vi.offences).to be_empty
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
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
|
+
version: 0.5.0
|
|
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-
|
|
12
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: term-ansicolor
|
|
@@ -137,6 +137,7 @@ files:
|
|
|
137
137
|
- .rspec
|
|
138
138
|
- .rubocop.yml
|
|
139
139
|
- .travis.yml
|
|
140
|
+
- CHANGELOG.md
|
|
140
141
|
- CONTRIBUTING.md
|
|
141
142
|
- Gemfile
|
|
142
143
|
- Gemfile.lock
|
|
@@ -147,8 +148,13 @@ files:
|
|
|
147
148
|
- bin/rubocop
|
|
148
149
|
- lib/rubocop.rb
|
|
149
150
|
- lib/rubocop/cli.rb
|
|
151
|
+
- lib/rubocop/cop/alias.rb
|
|
150
152
|
- lib/rubocop/cop/align_parameters.rb
|
|
151
153
|
- lib/rubocop/cop/ampersands_pipes_vs_and_or.rb
|
|
154
|
+
- lib/rubocop/cop/avoid_class_vars.rb
|
|
155
|
+
- lib/rubocop/cop/avoid_for.rb
|
|
156
|
+
- lib/rubocop/cop/avoid_perl_backrefs.rb
|
|
157
|
+
- lib/rubocop/cop/avoid_perlisms.rb
|
|
152
158
|
- lib/rubocop/cop/blocks.rb
|
|
153
159
|
- lib/rubocop/cop/class_and_module_camel_case.rb
|
|
154
160
|
- lib/rubocop/cop/collection_methods.rb
|
|
@@ -158,6 +164,7 @@ files:
|
|
|
158
164
|
- lib/rubocop/cop/encoding.rb
|
|
159
165
|
- lib/rubocop/cop/end_of_line.rb
|
|
160
166
|
- lib/rubocop/cop/favor_modifier.rb
|
|
167
|
+
- lib/rubocop/cop/favor_sprintf.rb
|
|
161
168
|
- lib/rubocop/cop/favor_unless_over_negated_if.rb
|
|
162
169
|
- lib/rubocop/cop/grammar.rb
|
|
163
170
|
- lib/rubocop/cop/hash_syntax.rb
|
|
@@ -170,14 +177,17 @@ files:
|
|
|
170
177
|
- lib/rubocop/cop/offence.rb
|
|
171
178
|
- lib/rubocop/cop/parameter_lists.rb
|
|
172
179
|
- lib/rubocop/cop/parentheses_around_condition.rb
|
|
180
|
+
- lib/rubocop/cop/semicolon.rb
|
|
173
181
|
- lib/rubocop/cop/space_after_comma_etc.rb
|
|
174
182
|
- lib/rubocop/cop/string_literals.rb
|
|
175
183
|
- lib/rubocop/cop/surrounding_space.rb
|
|
184
|
+
- lib/rubocop/cop/symbol_snake_case.rb
|
|
176
185
|
- lib/rubocop/cop/syntax.rb
|
|
177
186
|
- lib/rubocop/cop/tab.rb
|
|
178
187
|
- lib/rubocop/cop/ternary_operator.rb
|
|
179
188
|
- lib/rubocop/cop/trailing_whitespace.rb
|
|
180
189
|
- lib/rubocop/cop/unless_else.rb
|
|
190
|
+
- lib/rubocop/cop/variable_interpolation.rb
|
|
181
191
|
- lib/rubocop/cop/when_then.rb
|
|
182
192
|
- lib/rubocop/report/emacs_style.rb
|
|
183
193
|
- lib/rubocop/report/plain_text.rb
|
|
@@ -185,8 +195,13 @@ files:
|
|
|
185
195
|
- lib/rubocop/version.rb
|
|
186
196
|
- rubocop.gemspec
|
|
187
197
|
- spec/rubocop/cli_spec.rb
|
|
198
|
+
- spec/rubocop/cops/alias_spec.rb
|
|
188
199
|
- spec/rubocop/cops/align_parameters_spec.rb
|
|
189
200
|
- spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb
|
|
201
|
+
- spec/rubocop/cops/avoid_class_vars_spec.rb
|
|
202
|
+
- spec/rubocop/cops/avoid_for_spec.rb
|
|
203
|
+
- spec/rubocop/cops/avoid_perl_backrefs_spec.rb
|
|
204
|
+
- spec/rubocop/cops/avoid_perlisms_spec.rb
|
|
190
205
|
- spec/rubocop/cops/class_and_module_camel_case_spec.rb
|
|
191
206
|
- spec/rubocop/cops/collection_methods_spec.rb
|
|
192
207
|
- spec/rubocop/cops/cop_spec.rb
|
|
@@ -196,6 +211,7 @@ files:
|
|
|
196
211
|
- spec/rubocop/cops/encoding_spec.rb
|
|
197
212
|
- spec/rubocop/cops/end_of_line_spec.rb
|
|
198
213
|
- spec/rubocop/cops/favor_modifier_spec.rb
|
|
214
|
+
- spec/rubocop/cops/favor_sprintf_spec.rb
|
|
199
215
|
- spec/rubocop/cops/favor_unless_over_negated_if_spec.rb
|
|
200
216
|
- spec/rubocop/cops/favor_until_over_negated_while_spec.rb
|
|
201
217
|
- spec/rubocop/cops/grammar_spec.rb
|
|
@@ -212,6 +228,7 @@ files:
|
|
|
212
228
|
- spec/rubocop/cops/one_line_conditional_spec.rb
|
|
213
229
|
- spec/rubocop/cops/parameter_lists_spec.rb
|
|
214
230
|
- spec/rubocop/cops/parentheses_around_condition_spec.rb
|
|
231
|
+
- spec/rubocop/cops/semicolon_spec.rb
|
|
215
232
|
- spec/rubocop/cops/single_line_blocks_spec.rb
|
|
216
233
|
- spec/rubocop/cops/space_after_colon_spec.rb
|
|
217
234
|
- spec/rubocop/cops/space_after_comma_spec.rb
|
|
@@ -222,11 +239,13 @@ files:
|
|
|
222
239
|
- spec/rubocop/cops/space_inside_brackets_spec.rb
|
|
223
240
|
- spec/rubocop/cops/space_inside_parens_spec.rb
|
|
224
241
|
- spec/rubocop/cops/string_literals_spec.rb
|
|
242
|
+
- spec/rubocop/cops/symbol_snake_case_spec.rb
|
|
225
243
|
- spec/rubocop/cops/syntax_spec.rb
|
|
226
244
|
- spec/rubocop/cops/tab_spec.rb
|
|
227
245
|
- spec/rubocop/cops/ternary_operator_spec.rb
|
|
228
246
|
- spec/rubocop/cops/trailing_whitespace_spec.rb
|
|
229
247
|
- spec/rubocop/cops/unless_else_spec.rb
|
|
248
|
+
- spec/rubocop/cops/variable_interpolation_spec.rb
|
|
230
249
|
- spec/rubocop/cops/when_then_spec.rb
|
|
231
250
|
- spec/rubocop/reports/emacs_style_spec.rb
|
|
232
251
|
- spec/rubocop/reports/report_spec.rb
|
|
@@ -246,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
246
265
|
version: '0'
|
|
247
266
|
segments:
|
|
248
267
|
- 0
|
|
249
|
-
hash:
|
|
268
|
+
hash: -3879767922505531373
|
|
250
269
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
270
|
none: false
|
|
252
271
|
requirements:
|