rubocop 0.7.2 → 0.8.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.
- checksums.yaml +4 -4
- data/.travis.yml +7 -1
- data/CHANGELOG.md +19 -0
- data/README.md +4 -8
- data/bin/rubocop +2 -2
- data/config/default.yml +8 -0
- data/config/enabled.yml +21 -24
- data/lib/rubocop.rb +9 -7
- data/lib/rubocop/cli.rb +73 -52
- data/lib/rubocop/config.rb +8 -5
- data/lib/rubocop/cop/access_control.rb +41 -0
- data/lib/rubocop/cop/alias.rb +7 -5
- data/lib/rubocop/cop/align_parameters.rb +20 -96
- data/lib/rubocop/cop/and_or.rb +26 -0
- data/lib/rubocop/cop/ascii_comments.rb +3 -8
- data/lib/rubocop/cop/ascii_identifiers.rb +6 -5
- data/lib/rubocop/cop/avoid_class_vars.rb +5 -10
- data/lib/rubocop/cop/avoid_for.rb +7 -5
- data/lib/rubocop/cop/avoid_global_vars.rb +19 -7
- data/lib/rubocop/cop/avoid_perl_backrefs.rb +7 -10
- data/lib/rubocop/cop/avoid_perlisms.rb +11 -10
- data/lib/rubocop/cop/block_comments.rb +4 -6
- data/lib/rubocop/cop/blocks.rb +11 -47
- data/lib/rubocop/cop/case_indentation.rb +9 -31
- data/lib/rubocop/cop/class_and_module_camel_case.rb +20 -11
- data/lib/rubocop/cop/class_methods.rb +5 -10
- data/lib/rubocop/cop/collection_methods.rb +16 -16
- data/lib/rubocop/cop/colon_method_call.rb +8 -32
- data/lib/rubocop/cop/constant_name.rb +24 -0
- data/lib/rubocop/cop/cop.rb +20 -78
- data/lib/rubocop/cop/def_parentheses.rb +43 -35
- data/lib/rubocop/cop/empty_line_between_defs.rb +11 -15
- data/lib/rubocop/cop/empty_lines.rb +20 -9
- data/lib/rubocop/cop/empty_literal.rb +47 -0
- data/lib/rubocop/cop/encoding.rb +3 -3
- data/lib/rubocop/cop/end_of_line.rb +3 -3
- data/lib/rubocop/cop/ensure_return.rb +6 -23
- data/lib/rubocop/cop/eval.rb +7 -10
- data/lib/rubocop/cop/favor_join.rb +9 -24
- data/lib/rubocop/cop/favor_modifier.rb +38 -48
- data/lib/rubocop/cop/favor_percent_r.rb +7 -7
- data/lib/rubocop/cop/favor_sprintf.rb +8 -24
- data/lib/rubocop/cop/favor_unless_over_negated_if.rb +19 -17
- data/lib/rubocop/cop/handle_exceptions.rb +7 -11
- data/lib/rubocop/cop/hash_syntax.rb +29 -14
- data/lib/rubocop/cop/if_then_else.rb +32 -29
- data/lib/rubocop/cop/leading_comment_space.rb +5 -8
- data/lib/rubocop/cop/line_continuation.rb +4 -7
- data/lib/rubocop/cop/line_length.rb +3 -3
- data/lib/rubocop/cop/loop.rb +33 -0
- data/lib/rubocop/cop/method_and_variable_snake_case.rb +42 -19
- data/lib/rubocop/cop/method_length.rb +34 -37
- data/lib/rubocop/cop/new_lambda_literal.rb +8 -6
- data/lib/rubocop/cop/not.rb +10 -4
- data/lib/rubocop/cop/numeric_literals.rb +9 -7
- data/lib/rubocop/cop/offence.rb +1 -1
- data/lib/rubocop/cop/op_method.rb +12 -22
- data/lib/rubocop/cop/parameter_lists.rb +12 -6
- data/lib/rubocop/cop/parentheses_around_condition.rb +11 -11
- data/lib/rubocop/cop/percent_r.rb +7 -7
- data/lib/rubocop/cop/reduce_arguments.rb +13 -51
- data/lib/rubocop/cop/rescue_exception.rb +13 -29
- data/lib/rubocop/cop/rescue_modifier.rb +5 -8
- data/lib/rubocop/cop/semicolon.rb +15 -74
- data/lib/rubocop/cop/single_line_methods.rb +28 -44
- data/lib/rubocop/cop/space_after_comma_etc.rb +29 -9
- data/lib/rubocop/cop/space_after_control_keyword.rb +16 -15
- data/lib/rubocop/cop/string_literals.rb +9 -35
- data/lib/rubocop/cop/surrounding_space.rb +213 -112
- data/lib/rubocop/cop/symbol_array.rb +9 -7
- data/lib/rubocop/cop/symbol_name.rb +23 -0
- data/lib/rubocop/cop/syntax.rb +14 -7
- data/lib/rubocop/cop/tab.rb +3 -3
- data/lib/rubocop/cop/ternary_operator.rb +26 -24
- data/lib/rubocop/cop/trailing_whitespace.rb +3 -5
- data/lib/rubocop/cop/trivial_accessors.rb +18 -95
- data/lib/rubocop/cop/unless_else.rb +11 -7
- data/lib/rubocop/cop/util.rb +26 -0
- data/lib/rubocop/cop/variable_interpolation.rb +18 -10
- data/lib/rubocop/cop/when_then.rb +6 -17
- data/lib/rubocop/cop/word_array.rb +18 -19
- data/lib/rubocop/version.rb +1 -1
- data/rubocop.gemspec +1 -0
- data/spec/project_spec.rb +1 -1
- data/spec/rubocop/cli_spec.rb +16 -9
- data/spec/rubocop/config_spec.rb +13 -3
- data/spec/rubocop/cops/access_control_spec.rb +129 -0
- data/spec/rubocop/cops/alias_spec.rb +2 -6
- data/spec/rubocop/cops/align_parameters_spec.rb +58 -71
- data/spec/rubocop/cops/and_or_spec.rb +37 -0
- data/spec/rubocop/cops/ascii_comments_spec.rb +3 -4
- data/spec/rubocop/cops/ascii_identifiers_spec.rb +3 -4
- data/spec/rubocop/cops/avoid_class_vars_spec.rb +7 -2
- data/spec/rubocop/cops/avoid_for_spec.rb +1 -4
- data/spec/rubocop/cops/{avoid_global_vars.rb → avoid_global_vars_spec.rb} +4 -4
- data/spec/rubocop/cops/avoid_perl_backrefs_spec.rb +1 -1
- data/spec/rubocop/cops/avoid_perlisms_spec.rb +5 -5
- data/spec/rubocop/cops/block_comments_spec.rb +0 -4
- data/spec/rubocop/cops/blocks_spec.rb +33 -0
- data/spec/rubocop/cops/case_indentation_spec.rb +5 -5
- data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +15 -5
- data/spec/rubocop/cops/class_methods_spec.rb +4 -4
- data/spec/rubocop/cops/collection_methods_spec.rb +9 -4
- data/spec/rubocop/cops/colon_method_call_spec.rb +11 -5
- data/spec/rubocop/cops/constant_name_spec.rb +42 -0
- data/spec/rubocop/cops/def_with_parentheses_spec.rb +13 -8
- data/spec/rubocop/cops/def_without_parentheses_spec.rb +11 -5
- data/spec/rubocop/cops/empty_line_between_defs_spec.rb +38 -38
- data/spec/rubocop/cops/empty_lines_spec.rb +15 -3
- data/spec/rubocop/cops/empty_literal_spec.rb +90 -0
- data/spec/rubocop/cops/encoding_spec.rb +9 -9
- data/spec/rubocop/cops/end_of_line_spec.rb +2 -2
- data/spec/rubocop/cops/ensure_return_spec.rb +1 -3
- data/spec/rubocop/cops/eval_spec.rb +8 -5
- data/spec/rubocop/cops/favor_join_spec.rb +1 -5
- data/spec/rubocop/cops/favor_modifier_spec.rb +16 -14
- data/spec/rubocop/cops/{favor_percent_r.rb → favor_percent_r_spec.rb} +6 -6
- data/spec/rubocop/cops/favor_sprintf_spec.rb +3 -9
- data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +4 -4
- data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +3 -3
- data/spec/rubocop/cops/handle_exceptions_spec.rb +1 -3
- data/spec/rubocop/cops/hash_syntax_spec.rb +11 -6
- data/spec/rubocop/cops/if_with_semicolon_spec.rb +7 -1
- data/spec/rubocop/cops/leading_comment_space_spec.rb +0 -7
- data/spec/rubocop/cops/line_continuation_spec.rb +2 -2
- data/spec/rubocop/cops/line_length_spec.rb +2 -2
- data/spec/rubocop/cops/loop_spec.rb +31 -0
- data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +38 -12
- data/spec/rubocop/cops/method_length_spec.rb +85 -85
- data/spec/rubocop/cops/multiline_if_then_spec.rb +15 -15
- data/spec/rubocop/cops/new_lambda_literal_spec.rb +3 -3
- data/spec/rubocop/cops/not_spec.rb +1 -4
- data/spec/rubocop/cops/numeric_literals_spec.rb +13 -13
- data/spec/rubocop/cops/one_line_conditional_spec.rb +1 -1
- data/spec/rubocop/cops/op_method_spec.rb +2 -9
- data/spec/rubocop/cops/parameter_lists_spec.rb +7 -7
- data/spec/rubocop/cops/parentheses_around_condition_spec.rb +41 -44
- data/spec/rubocop/cops/percent_r_spec.rb +6 -6
- data/spec/rubocop/cops/reduce_arguments_spec.rb +4 -4
- data/spec/rubocop/cops/rescue_exception_spec.rb +48 -8
- data/spec/rubocop/cops/rescue_modifier_spec.rb +2 -5
- data/spec/rubocop/cops/semicolon_spec.rb +2 -30
- data/spec/rubocop/cops/single_line_methods_spec.rb +13 -13
- data/spec/rubocop/cops/space_after_colon_spec.rb +3 -3
- data/spec/rubocop/cops/space_after_comma_spec.rb +14 -2
- data/spec/rubocop/cops/space_after_control_keyword_spec.rb +42 -3
- data/spec/rubocop/cops/space_after_semicolon_spec.rb +2 -2
- data/spec/rubocop/cops/space_around_braces_spec.rb +18 -3
- data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +4 -4
- data/spec/rubocop/cops/space_around_operators_spec.rb +82 -27
- data/spec/rubocop/cops/space_inside_brackets_spec.rb +13 -7
- data/spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb +14 -9
- data/spec/rubocop/cops/space_inside_parens_spec.rb +7 -3
- data/spec/rubocop/cops/string_literals_spec.rb +17 -5
- data/spec/rubocop/cops/symbol_array_spec.rb +18 -2
- data/spec/rubocop/cops/symbol_name_spec.rb +119 -0
- data/spec/rubocop/cops/syntax_spec.rb +25 -18
- data/spec/rubocop/cops/tab_spec.rb +2 -2
- data/spec/rubocop/cops/ternary_operator_spec.rb +13 -17
- data/spec/rubocop/cops/trailing_whitespace_spec.rb +3 -3
- data/spec/rubocop/cops/trivial_accessors_spec.rb +17 -20
- data/spec/rubocop/cops/unless_else_spec.rb +8 -8
- data/spec/rubocop/cops/variable_interpolation_spec.rb +0 -5
- data/spec/rubocop/cops/when_then_spec.rb +14 -21
- data/spec/rubocop/cops/word_array_spec.rb +12 -4
- data/spec/spec_helper.rb +12 -4
- metadata +40 -31
- data/.document +0 -5
- data/lib/rubocop/cop/ampersands_pipes_vs_and_or.rb +0 -25
- data/lib/rubocop/cop/array_literal.rb +0 -61
- data/lib/rubocop/cop/brace_after_percent.rb +0 -32
- data/lib/rubocop/cop/grammar.rb +0 -138
- data/lib/rubocop/cop/hash_literal.rb +0 -61
- data/lib/rubocop/cop/percent_literals.rb +0 -25
- data/lib/rubocop/cop/symbol_snake_case.rb +0 -47
- data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +0 -57
- data/spec/rubocop/cops/array_literal_spec.rb +0 -46
- data/spec/rubocop/cops/brace_after_percent_spec.rb +0 -33
- data/spec/rubocop/cops/grammar_spec.rb +0 -81
- data/spec/rubocop/cops/hash_literal_spec.rb +0 -46
- data/spec/rubocop/cops/multiline_blocks_spec.rb +0 -24
- data/spec/rubocop/cops/percent_literals_spec.rb +0 -47
- data/spec/rubocop/cops/single_line_blocks_spec.rb +0 -22
- data/spec/rubocop/cops/symbol_snake_case_spec.rb +0 -93
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c61251297391f7ee7286eb0e4482e975a42122f
|
4
|
+
data.tar.gz: 4375f2e36ceaa75510f7e4cdece56d3f1e22700f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a6ed60555b7fbc888b9a68190c79bb525ece1e3623e1025fe833016e13b635b947b0cf49fab267ab4bf886bb0c8438bea130011a8c9dd8efa3e6e863b218b8f
|
7
|
+
data.tar.gz: 2f4161c9a52973931d695f900045b46b55e56d62debac661ab25308b031e383906cf33b107f8cf8f6701dba4c251cf9bac7ae49f32550aaca278bae7d556d688
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,25 @@
|
|
4
4
|
|
5
5
|
### New features
|
6
6
|
|
7
|
+
### Changes
|
8
|
+
|
9
|
+
### Bugs fixed
|
10
|
+
|
11
|
+
## 0.8.0 (05/28/2012)
|
12
|
+
|
13
|
+
### Changes
|
14
|
+
|
15
|
+
* Folded `ArrayLiteral` and `HashLiteral` into `EmptyLiteral` cop
|
16
|
+
* The maximum number of params `ParameterLists` accepts in now configurable
|
17
|
+
* Reworked `SymbolSnakeCase` into `SymbolName`, which has an option `AllowCamelCase` enabled by default.
|
18
|
+
* Migrated from `Ripper` to the portable [Parser](https://github.com/whitequark/parser).
|
19
|
+
|
20
|
+
### New features
|
21
|
+
|
22
|
+
* New cop `ConstantName` checks for constant which are not using `SCREAMING_SNAKE_CASE`.
|
23
|
+
* New cop `AccessControl` checks private/protected indentation and surrounding blank lines.
|
24
|
+
* New cop `Loop` checks for `begin/end/while(until)` and suggests the use of `Kernel#loop`.
|
25
|
+
|
7
26
|
## 0.7.2 (05/13/2013)
|
8
27
|
|
9
28
|
### Bugs fixed
|
data/README.md
CHANGED
@@ -97,7 +97,7 @@ The file `config/default.yml` under the RuboCop home directory
|
|
97
97
|
contains the default settings that all configurations inherit
|
98
98
|
from. Project and personal `.rubocop.yml` files need only make
|
99
99
|
settings that are different from the default ones. If there is no
|
100
|
-
`.rubocop.yml` file in the project or home
|
100
|
+
`.rubocop.yml` file in the project or home directory,
|
101
101
|
`config/default.yml` will be used.
|
102
102
|
|
103
103
|
### Disabling Cops within Source Code
|
@@ -132,7 +132,7 @@ RuboCop checks all files recursively within the directory it is run
|
|
132
132
|
on. However, it does not recognize some files as Ruby(only files
|
133
133
|
ending with `.rb` or extensionless files with a `#!.*ruby` declaration
|
134
134
|
are automatically detected) files, and if you'd like it to check these
|
135
|
-
you'll need to manually pass them in. Files and directories can
|
135
|
+
you'll need to manually pass them in. Files and directories can
|
136
136
|
also be ignored through `.rubocop.yml`.
|
137
137
|
|
138
138
|
Here is an example that might be used for a Rails project:
|
@@ -155,12 +155,8 @@ Note: Files and directories are specified relative to the `.rubocop.yml` file.
|
|
155
155
|
|
156
156
|
## Compatibility
|
157
157
|
|
158
|
-
|
159
|
-
|
160
|
-
analyzer a daunting task.
|
161
|
-
|
162
|
-
RuboCop currently supports MRI 1.9 and MRI 2.0. Support for JRuby and
|
163
|
-
Rubinius is not planned at this point.
|
158
|
+
RuboCop supported only MRI 1.9 & MRI 2.0 prior to version 0.8. After
|
159
|
+
RuboCop 0.8, JRuby and Rubinius in 1.9 modes are also supported.
|
164
160
|
|
165
161
|
## Editor integration
|
166
162
|
|
data/bin/rubocop
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
if
|
4
|
+
if RUBY_VERSION >= '1.9.2'
|
5
5
|
$LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
6
6
|
|
7
7
|
require 'rubocop'
|
@@ -17,6 +17,6 @@ if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '1.9.2'
|
|
17
17
|
puts "Finished in #{time} seconds" if cli.options[:debug]
|
18
18
|
exit result
|
19
19
|
else
|
20
|
-
puts 'RuboCop supports only
|
20
|
+
puts 'RuboCop supports only Ruby 1.9.2+'
|
21
21
|
exit(-1)
|
22
22
|
end
|
data/config/default.yml
CHANGED
@@ -22,6 +22,10 @@ MethodLength:
|
|
22
22
|
CountComments: false # count full line comments?
|
23
23
|
Max: 10
|
24
24
|
|
25
|
+
# Avoid parameter lists longer than four parameters.
|
26
|
+
ParameterLists:
|
27
|
+
Max: 4
|
28
|
+
|
25
29
|
# Don't use semicolons to terminate expressions.
|
26
30
|
Semicolon:
|
27
31
|
# For example; def area(height, width); height * width end
|
@@ -36,3 +40,7 @@ SingleLineMethods:
|
|
36
40
|
# Use spaces inside hash literal braces - or don't.
|
37
41
|
SpaceInsideHashLiteralBraces:
|
38
42
|
EnforcedStyleIsWithSpaces: true
|
43
|
+
|
44
|
+
# Symbol literals should use snake_case.
|
45
|
+
SymbolName:
|
46
|
+
AllowCamelCase: true
|
data/config/enabled.yml
CHANGED
@@ -101,11 +101,8 @@ OneLineConditional:
|
|
101
101
|
Enabled: true
|
102
102
|
|
103
103
|
# Avoid using {...} for multi-line blocks (multiline chaining is always ugly).
|
104
|
-
MultilineBlocks:
|
105
|
-
Enabled: true
|
106
|
-
|
107
104
|
# Prefer {...} over do...end for single-line blocks.
|
108
|
-
|
105
|
+
Blocks:
|
109
106
|
Enabled: true
|
110
107
|
|
111
108
|
# Avoid parameter lists longer than three or four parameters.
|
@@ -128,8 +125,8 @@ NestedTernaryOperator:
|
|
128
125
|
UnlessElse:
|
129
126
|
Enabled: true
|
130
127
|
|
131
|
-
# Use &&/||
|
132
|
-
|
128
|
+
# Use &&/|| instead of and/or.
|
129
|
+
AndOr:
|
133
130
|
Enabled: true
|
134
131
|
|
135
132
|
# Use when x then ... for one-line cases.
|
@@ -196,10 +193,6 @@ AvoidPerlBackrefs:
|
|
196
193
|
AvoidClassVars:
|
197
194
|
Enabled: true
|
198
195
|
|
199
|
-
# Symbol literals should use snake_case.
|
200
|
-
SymbolSnakeCase:
|
201
|
-
Enabled: true
|
202
|
-
|
203
196
|
# Don't interpolate global, instance and class variables directly in strings.
|
204
197
|
VariableInterpolation:
|
205
198
|
Enabled: true
|
@@ -228,14 +221,6 @@ Not:
|
|
228
221
|
RescueModifier:
|
229
222
|
Enabled: true
|
230
223
|
|
231
|
-
# Avoid the use of %q, %Q, %s and %x.
|
232
|
-
PercentLiterals:
|
233
|
-
Enabled: true
|
234
|
-
|
235
|
-
# Prefer () as delimiters for all % literals.
|
236
|
-
BraceAfterPercent:
|
237
|
-
Enabled: true
|
238
|
-
|
239
224
|
# Never use return in an ensure block.
|
240
225
|
EnsureReturn:
|
241
226
|
Enabled: true
|
@@ -260,12 +245,8 @@ BlockComments:
|
|
260
245
|
RescueException:
|
261
246
|
Enabled: true
|
262
247
|
|
263
|
-
# Prefer
|
264
|
-
|
265
|
-
Enabled: true
|
266
|
-
|
267
|
-
# Prefer hash {} literail to Hash.new.
|
268
|
-
HashLiteral:
|
248
|
+
# Prefer literals to Array.new/Hash.new/String.new.
|
249
|
+
EmptyLiteral:
|
269
250
|
Enabled: true
|
270
251
|
|
271
252
|
# When defining binary operators, name the argument other.
|
@@ -323,3 +304,19 @@ AvoidGlobalVars:
|
|
323
304
|
# The use of eval represents a serious security risk.
|
324
305
|
Eval:
|
325
306
|
Enabled: true
|
307
|
+
|
308
|
+
# Symbol literals should use snake_case.
|
309
|
+
SymbolName:
|
310
|
+
Enabled: true
|
311
|
+
|
312
|
+
# Constants should use SCREAMING_SNAKE_CASE.
|
313
|
+
ConstantName:
|
314
|
+
Enabled: true
|
315
|
+
|
316
|
+
# Indent private/protected as deep as defs and keep blank lines around them.
|
317
|
+
AccessControl:
|
318
|
+
Enabled: true
|
319
|
+
|
320
|
+
# Use Kernel#loop with break rather than begin/end/until or begin/end/while for post-loop tests.
|
321
|
+
Loop:
|
322
|
+
Enabled: true
|
data/lib/rubocop.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'ripper'
|
4
3
|
require 'rainbow'
|
5
4
|
require 'English'
|
5
|
+
require 'parser/current'
|
6
|
+
require 'ast/sexp'
|
6
7
|
|
8
|
+
require 'rubocop/cop/util'
|
7
9
|
require 'rubocop/cop/offence'
|
8
10
|
require 'rubocop/cop/cop'
|
9
11
|
require 'rubocop/cop/encoding'
|
@@ -29,7 +31,7 @@ require 'rubocop/cop/parameter_lists'
|
|
29
31
|
require 'rubocop/cop/string_literals'
|
30
32
|
require 'rubocop/cop/ternary_operator'
|
31
33
|
require 'rubocop/cop/unless_else'
|
32
|
-
require 'rubocop/cop/
|
34
|
+
require 'rubocop/cop/and_or'
|
33
35
|
require 'rubocop/cop/when_then'
|
34
36
|
require 'rubocop/cop/favor_modifier'
|
35
37
|
require 'rubocop/cop/favor_unless_over_negated_if'
|
@@ -43,23 +45,21 @@ require 'rubocop/cop/avoid_perlisms'
|
|
43
45
|
require 'rubocop/cop/avoid_perl_backrefs'
|
44
46
|
require 'rubocop/cop/avoid_global_vars'
|
45
47
|
require 'rubocop/cop/avoid_class_vars'
|
46
|
-
require 'rubocop/cop/
|
48
|
+
require 'rubocop/cop/symbol_name'
|
49
|
+
require 'rubocop/cop/constant_name'
|
47
50
|
require 'rubocop/cop/variable_interpolation'
|
48
51
|
require 'rubocop/cop/semicolon'
|
49
52
|
require 'rubocop/cop/favor_sprintf'
|
50
53
|
require 'rubocop/cop/favor_join'
|
51
54
|
require 'rubocop/cop/alias'
|
52
55
|
require 'rubocop/cop/rescue_modifier'
|
53
|
-
require 'rubocop/cop/percent_literals'
|
54
|
-
require 'rubocop/cop/brace_after_percent'
|
55
56
|
require 'rubocop/cop/ensure_return'
|
56
57
|
require 'rubocop/cop/handle_exceptions'
|
57
58
|
require 'rubocop/cop/rescue_exception'
|
58
59
|
require 'rubocop/cop/ascii_identifiers'
|
59
60
|
require 'rubocop/cop/ascii_comments'
|
60
61
|
require 'rubocop/cop/block_comments'
|
61
|
-
require 'rubocop/cop/
|
62
|
-
require 'rubocop/cop/array_literal'
|
62
|
+
require 'rubocop/cop/empty_literal'
|
63
63
|
require 'rubocop/cop/method_length'
|
64
64
|
require 'rubocop/cop/op_method'
|
65
65
|
require 'rubocop/cop/reduce_arguments'
|
@@ -74,6 +74,8 @@ require 'rubocop/cop/leading_comment_space'
|
|
74
74
|
require 'rubocop/cop/colon_method_call'
|
75
75
|
require 'rubocop/cop/not'
|
76
76
|
require 'rubocop/cop/eval'
|
77
|
+
require 'rubocop/cop/access_control'
|
78
|
+
require 'rubocop/cop/loop'
|
77
79
|
|
78
80
|
require 'rubocop/report/report'
|
79
81
|
require 'rubocop/report/plain_text'
|
data/lib/rubocop/cli.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'pathname'
|
3
3
|
require 'optparse'
|
4
|
-
require_relative 'cop/grammar'
|
5
4
|
|
6
5
|
module Rubocop
|
7
6
|
# The CLI is a class responsible of handling all the command line interface
|
@@ -33,7 +32,7 @@ module Rubocop
|
|
33
32
|
parse_options(args)
|
34
33
|
|
35
34
|
begin
|
36
|
-
|
35
|
+
validate_only_option if @options[:only]
|
37
36
|
rescue ArgumentError => e
|
38
37
|
puts e.message
|
39
38
|
return 1
|
@@ -44,13 +43,12 @@ module Rubocop
|
|
44
43
|
|
45
44
|
config = ConfigStore.for(file)
|
46
45
|
report = Report.create(file, @options[:mode])
|
47
|
-
source = read_source(file)
|
48
46
|
|
49
47
|
puts "Scanning #{file}" if @options[:debug]
|
50
48
|
|
51
49
|
syntax_cop = Rubocop::Cop::Syntax.new
|
52
50
|
syntax_cop.debug = @options[:debug]
|
53
|
-
syntax_cop.
|
51
|
+
syntax_cop.inspect_file(file)
|
54
52
|
|
55
53
|
if syntax_cop.offences.map(&:severity).include?(:error)
|
56
54
|
# In case of a syntax error we just report that error and do
|
@@ -58,7 +56,7 @@ module Rubocop
|
|
58
56
|
report << syntax_cop
|
59
57
|
@total_offences += syntax_cop.offences.count
|
60
58
|
else
|
61
|
-
inspect_file(file,
|
59
|
+
inspect_file(file, config, report)
|
62
60
|
end
|
63
61
|
|
64
62
|
@processed_file_count += 1
|
@@ -72,41 +70,38 @@ module Rubocop
|
|
72
70
|
(@total_offences == 0) && !wants_to_quit ? 0 : 1
|
73
71
|
end
|
74
72
|
|
75
|
-
def
|
76
|
-
|
77
|
-
if @cops.empty?
|
73
|
+
def validate_only_option
|
74
|
+
if @cops.none? { |c| c.cop_name == @options[:only] }
|
78
75
|
fail ArgumentError, "Unrecognized cop name: #{@options[:only]}."
|
79
76
|
end
|
80
77
|
end
|
81
78
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
79
|
+
def inspect_file(file, config, report)
|
80
|
+
begin
|
81
|
+
ast, comments, tokens, source = CLI.parse(file) do |source_buffer|
|
82
|
+
source_buffer.read
|
83
|
+
end
|
84
|
+
rescue Parser::SyntaxError, Encoding::UndefinedConversionError,
|
85
|
+
ArgumentError => e
|
86
|
+
handle_error(e, "An error occurred while parsing #{file}.".color(:red))
|
87
|
+
return
|
88
|
+
end
|
85
89
|
|
86
|
-
def inspect_file(file, source, config, report)
|
87
|
-
tokens, sexp, correlations = CLI.rip_source(source)
|
88
90
|
disabled_lines = disabled_lines_in(source)
|
89
91
|
|
90
|
-
@cops.each do |
|
91
|
-
cop_name =
|
92
|
-
cop_config = config.for_cop(cop_name)
|
92
|
+
@cops.each do |cop_class|
|
93
|
+
cop_name = cop_class.cop_name
|
93
94
|
if config.cop_enabled?(cop_name)
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
@errors << message
|
105
|
-
warn message
|
106
|
-
if @options[:debug]
|
107
|
-
puts e.message, e.backtrace
|
108
|
-
else
|
109
|
-
warn 'To see the complete backtrace run rubocop -d.'
|
95
|
+
cop = setup_cop(cop_class,
|
96
|
+
config.for_cop(cop_name),
|
97
|
+
disabled_lines)
|
98
|
+
if !@options[:only] || @options[:only] == cop_name
|
99
|
+
begin
|
100
|
+
cop.inspect(source, tokens, ast, comments)
|
101
|
+
rescue => e
|
102
|
+
handle_error(e,
|
103
|
+
"An error occurred while #{cop.name}".color(:red) +
|
104
|
+
" cop was inspecting #{file}.".color(:red))
|
110
105
|
end
|
111
106
|
end
|
112
107
|
@total_offences += cop.offences.count
|
@@ -115,6 +110,24 @@ module Rubocop
|
|
115
110
|
end
|
116
111
|
end
|
117
112
|
|
113
|
+
def setup_cop(cop_class, cop_config, disabled_lines)
|
114
|
+
cop_class.config = cop_config
|
115
|
+
cop = cop_class.new
|
116
|
+
cop.debug = @options[:debug]
|
117
|
+
cop.disabled_lines = disabled_lines[cop_class.cop_name]
|
118
|
+
cop
|
119
|
+
end
|
120
|
+
|
121
|
+
def handle_error(e, message)
|
122
|
+
@errors << message
|
123
|
+
warn message
|
124
|
+
if @options[:debug]
|
125
|
+
puts e.message, e.backtrace
|
126
|
+
else
|
127
|
+
warn 'To see the complete backtrace run rubocop -d.'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
118
131
|
def parse_options(args)
|
119
132
|
OptionParser.new do |opts|
|
120
133
|
opts.banner = 'Usage: rubocop [options] [file1, file2, ...]'
|
@@ -207,21 +220,28 @@ module Rubocop
|
|
207
220
|
end
|
208
221
|
end
|
209
222
|
|
210
|
-
def
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
223
|
+
def self.parse(file)
|
224
|
+
parser = Parser::CurrentRuby.new
|
225
|
+
|
226
|
+
parser.diagnostics.all_errors_are_fatal = true
|
227
|
+
parser.diagnostics.ignore_warnings = true
|
228
|
+
|
229
|
+
parser.diagnostics.consumer = lambda do |diagnostic|
|
230
|
+
$stderr.puts(diagnostic.render)
|
231
|
+
end
|
232
|
+
|
233
|
+
source_buffer = Parser::Source::Buffer.new(file, 1)
|
234
|
+
yield source_buffer
|
218
235
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
236
|
+
ast, comments, tokens = parser.tokenize(source_buffer)
|
237
|
+
|
238
|
+
tokens = tokens.map do |t|
|
239
|
+
type, details = *t
|
240
|
+
text, range = *details
|
241
|
+
Rubocop::Cop::Token.new(range, type, text)
|
242
|
+
end
|
243
|
+
|
244
|
+
[ast, comments, tokens, source_buffer.source.split($RS)]
|
225
245
|
end
|
226
246
|
|
227
247
|
# Generate a list of target files by expanding globing patterns
|
@@ -261,12 +281,13 @@ module Rubocop
|
|
261
281
|
|
262
282
|
rb += files.select { |file| File.extname(file) == '.rb' }
|
263
283
|
rb += files.select do |file|
|
264
|
-
File.extname(file) == ''
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
284
|
+
if File.extname(file) == ''
|
285
|
+
begin
|
286
|
+
File.open(file) { |f| f.readline } =~ /#!.*ruby/
|
287
|
+
rescue EOFError, ArgumentError => e
|
288
|
+
log_error(e, "Unprocessable file #{file.inspect}: ")
|
289
|
+
false
|
290
|
+
end
|
270
291
|
end
|
271
292
|
end
|
272
293
|
|