rubocop 0.3.0 → 0.6.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 +176 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +60 -0
- data/CONTRIBUTING.md +13 -6
- data/Gemfile +1 -13
- data/README.md +131 -6
- data/Rakefile +1 -15
- data/bin/rubocop +2 -1
- data/lib/rubocop/cli.rb +133 -21
- data/lib/rubocop/cop/alias.rb +18 -0
- data/lib/rubocop/cop/align_parameters.rb +5 -4
- data/lib/rubocop/cop/array_literal.rb +22 -0
- data/lib/rubocop/cop/ascii_identifiers_and_comments.rb +18 -0
- 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 +46 -0
- data/lib/rubocop/cop/blocks.rb +1 -1
- data/lib/rubocop/cop/brace_after_percent.rb +28 -0
- data/lib/rubocop/cop/class_and_module_camel_case.rb +20 -0
- data/lib/rubocop/cop/collection_methods.rb +29 -0
- data/lib/rubocop/cop/cop.rb +16 -4
- data/lib/rubocop/cop/def_parentheses.rb +4 -1
- data/lib/rubocop/cop/encoding.rb +7 -5
- data/lib/rubocop/cop/end_of_line.rb +1 -3
- data/lib/rubocop/cop/ensure_return.rb +36 -0
- data/lib/rubocop/cop/favor_modifier.rb +82 -0
- data/lib/rubocop/cop/favor_percent_r.rb +19 -0
- data/lib/rubocop/cop/favor_sprintf.rb +37 -0
- data/lib/rubocop/cop/favor_unless_over_negated_if.rb +47 -0
- data/lib/rubocop/cop/grammar.rb +12 -8
- data/lib/rubocop/cop/handle_exceptions.rb +21 -0
- data/lib/rubocop/cop/hash_literal.rb +22 -0
- data/lib/rubocop/cop/indentation.rb +1 -1
- data/lib/rubocop/cop/line_length.rb +7 -3
- data/lib/rubocop/cop/method_and_variable_snake_case.rb +31 -0
- data/lib/rubocop/cop/method_length.rb +66 -0
- data/lib/rubocop/cop/new_lambda_literal.rb +17 -0
- data/lib/rubocop/cop/offence.rb +3 -1
- data/lib/rubocop/cop/op_method.rb +23 -0
- data/lib/rubocop/cop/parentheses_around_condition.rb +24 -0
- data/lib/rubocop/cop/percent_literals.rb +25 -0
- data/lib/rubocop/cop/percent_r.rb +19 -0
- data/lib/rubocop/cop/reduce_arguments.rb +67 -0
- data/lib/rubocop/cop/rescue_exception.rb +39 -0
- data/lib/rubocop/cop/rescue_modifier.rb +20 -0
- 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/surrounding_space.rb +48 -47
- data/lib/rubocop/cop/symbol_snake_case.rb +27 -0
- data/lib/rubocop/cop/syntax.rb +42 -0
- data/lib/rubocop/cop/tab.rb +1 -3
- 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/report/plain_text.rb +1 -1
- data/lib/rubocop/report/report.rb +5 -2
- data/lib/rubocop/version.rb +3 -1
- data/lib/rubocop.rb +37 -0
- data/rubocop.gemspec +36 -134
- data/spec/rubocop/cli_spec.rb +326 -48
- data/spec/rubocop/cops/alias_spec.rb +36 -0
- data/spec/rubocop/cops/align_parameters_spec.rb +43 -34
- data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +4 -4
- data/spec/rubocop/cops/array_literal_spec.rb +29 -0
- data/spec/rubocop/cops/ascii_identifiers_and_comments_spec.rb +38 -0
- 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 +44 -0
- data/spec/rubocop/cops/brace_after_percent_spec.rb +27 -0
- data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +34 -0
- data/spec/rubocop/cops/collection_methods_spec.rb +39 -0
- data/spec/rubocop/cops/cop_spec.rb +5 -5
- data/spec/rubocop/cops/def_with_parentheses_spec.rb +5 -5
- data/spec/rubocop/cops/def_without_parentheses_spec.rb +4 -4
- data/spec/rubocop/cops/empty_lines_spec.rb +8 -8
- data/spec/rubocop/cops/encoding_spec.rb +17 -11
- data/spec/rubocop/cops/end_of_line_spec.rb +5 -5
- data/spec/rubocop/cops/ensure_return_spec.rb +37 -0
- data/spec/rubocop/cops/favor_modifier_spec.rb +112 -0
- data/spec/rubocop/cops/favor_percent_r.rb +29 -0
- data/spec/rubocop/cops/favor_sprintf_spec.rb +57 -0
- data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +62 -0
- data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +45 -0
- data/spec/rubocop/cops/grammar_spec.rb +59 -44
- data/spec/rubocop/cops/handle_exceptions_spec.rb +36 -0
- data/spec/rubocop/cops/hash_literal_spec.rb +29 -0
- data/spec/rubocop/cops/hash_syntax_spec.rb +10 -10
- data/spec/rubocop/cops/if_with_semicolon_spec.rb +3 -3
- data/spec/rubocop/cops/indentation_spec.rb +7 -7
- data/spec/rubocop/cops/line_length_spec.rb +4 -4
- data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +47 -0
- data/spec/rubocop/cops/method_length_spec.rb +150 -0
- data/spec/rubocop/cops/multiline_blocks_spec.rb +4 -4
- data/spec/rubocop/cops/multiline_if_then_spec.rb +7 -7
- data/spec/rubocop/cops/new_lambda_literal_spec.rb +23 -0
- data/spec/rubocop/cops/numeric_literals_spec.rb +10 -10
- data/spec/rubocop/cops/offence_spec.rb +10 -4
- data/spec/rubocop/cops/one_line_conditional_spec.rb +2 -3
- data/spec/rubocop/cops/op_method_spec.rb +58 -0
- data/spec/rubocop/cops/parameter_lists_spec.rb +4 -4
- data/spec/rubocop/cops/parentheses_around_condition_spec.rb +64 -0
- data/spec/rubocop/cops/percent_literals_spec.rb +47 -0
- data/spec/rubocop/cops/percent_r_spec.rb +29 -0
- data/spec/rubocop/cops/reduce_arguments_spec.rb +57 -0
- data/spec/rubocop/cops/rescue_exception_spec.rb +73 -0
- data/spec/rubocop/cops/rescue_modifier.rb +40 -0
- data/spec/rubocop/cops/semicolon_spec.rb +29 -0
- data/spec/rubocop/cops/single_line_blocks_spec.rb +4 -4
- data/spec/rubocop/cops/space_after_colon_spec.rb +5 -5
- data/spec/rubocop/cops/space_after_comma_spec.rb +3 -3
- data/spec/rubocop/cops/space_after_semicolon_spec.rb +3 -3
- data/spec/rubocop/cops/space_around_braces_spec.rb +6 -6
- data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +22 -0
- data/spec/rubocop/cops/space_around_operators_spec.rb +57 -25
- data/spec/rubocop/cops/space_inside_brackets_spec.rb +8 -8
- data/spec/rubocop/cops/space_inside_parens_spec.rb +4 -4
- data/spec/rubocop/cops/string_literals_spec.rb +9 -6
- data/spec/rubocop/cops/symbol_snake_case_spec.rb +74 -0
- data/spec/rubocop/cops/syntax_spec.rb +34 -0
- data/spec/rubocop/cops/tab_spec.rb +4 -4
- data/spec/rubocop/cops/ternary_operator_spec.rb +8 -8
- data/spec/rubocop/cops/trailing_whitespace_spec.rb +4 -4
- data/spec/rubocop/cops/unless_else_spec.rb +4 -4
- data/spec/rubocop/cops/variable_interpolation_spec.rb +45 -0
- data/spec/rubocop/cops/when_then_spec.rb +12 -5
- data/spec/rubocop/reports/emacs_style_spec.rb +3 -3
- data/spec/rubocop/reports/report_spec.rb +5 -5
- data/spec/spec_helper.rb +6 -0
- metadata +165 -36
- data/.rbenv-version +0 -1
- data/.rvmrc +0 -1
- data/Gemfile.lock +0 -39
- data/VERSION +0 -1
- data/features/rubocop.feature +0 -9
- data/features/step_definitions/rubocop_steps.rb +0 -1
- data/features/support/env.rb +0 -15
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Rubocop
|
|
4
|
+
module Cop
|
|
5
|
+
class Semicolon < Cop
|
|
6
|
+
ERROR_MESSAGE = 'Do not use semicolons to terminate expressions.'
|
|
7
|
+
|
|
8
|
+
def inspect(file, source, tokens, sexp)
|
|
9
|
+
tokens.each_index do |ix|
|
|
10
|
+
t = tokens[ix]
|
|
11
|
+
if t.type == :on_semicolon
|
|
12
|
+
add_offence(:convention, t.pos.lineno, ERROR_MESSAGE)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -9,7 +9,8 @@ module Rubocop
|
|
|
9
9
|
tokens.each_index do |ix|
|
|
10
10
|
t = tokens[ix]
|
|
11
11
|
if kind(t) && !whitespace?(tokens[ix + 1])
|
|
12
|
-
add_offence(:convention, t.pos.lineno,
|
|
12
|
+
add_offence(:convention, t.pos.lineno,
|
|
13
|
+
sprintf(ERROR_MESSAGE, kind(t)))
|
|
13
14
|
end
|
|
14
15
|
end
|
|
15
16
|
end
|
|
@@ -19,6 +19,9 @@ module Rubocop
|
|
|
19
19
|
when [:double_quote, :on_embexpr_beg]
|
|
20
20
|
:embedded_expression
|
|
21
21
|
|
|
22
|
+
when [:double_quote, :on_embvar]
|
|
23
|
+
:embedded_variable
|
|
24
|
+
|
|
22
25
|
when [:double_quote, :on_tstring_end]
|
|
23
26
|
add_offence(:convention, t.pos.lineno, ERROR_MESSAGE)
|
|
24
27
|
:outside
|
|
@@ -26,6 +29,15 @@ module Rubocop
|
|
|
26
29
|
when [:embedded_expression, :on_rbrace]
|
|
27
30
|
:valid_double_quote
|
|
28
31
|
|
|
32
|
+
when [:embedded_variable, :on_ivar]
|
|
33
|
+
:valid_double_quote
|
|
34
|
+
|
|
35
|
+
when [:embedded_variable, :on_cvar]
|
|
36
|
+
:valid_double_quote
|
|
37
|
+
|
|
38
|
+
when [:embedded_variable, :on_gvar]
|
|
39
|
+
:valid_double_quote
|
|
40
|
+
|
|
29
41
|
when [:valid_double_quote, :on_tstring_end]
|
|
30
42
|
:outside
|
|
31
43
|
end || state
|
|
@@ -1,37 +1,26 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
|
|
3
|
-
require_relative 'grammar'
|
|
4
|
-
|
|
5
3
|
module Rubocop
|
|
6
4
|
module Cop
|
|
7
5
|
module SurroundingSpace
|
|
8
6
|
def inspect(file, source, tokens, sexp)
|
|
9
7
|
@correlations.sort.each do |ix, grammar_path|
|
|
10
|
-
|
|
8
|
+
check_missing_space(tokens, ix, grammar_path)
|
|
11
9
|
end
|
|
12
|
-
tokens.each_index { |ix|
|
|
10
|
+
tokens.each_index { |ix| check_unwanted_space(tokens, ix) }
|
|
13
11
|
end
|
|
14
12
|
|
|
15
13
|
private
|
|
16
14
|
|
|
17
|
-
def tokens_on_same_row?(t1, t2)
|
|
18
|
-
t1.pos.lineno == t2.pos.lineno
|
|
19
|
-
end
|
|
20
|
-
|
|
21
15
|
def previous_non_space(tokens, ix)
|
|
22
|
-
|
|
23
|
-
t = tokens[i]
|
|
24
|
-
return t unless whitespace?(t)
|
|
25
|
-
end
|
|
26
|
-
nil
|
|
16
|
+
tokens[0...ix].reverse.find { |t| not whitespace?(t) }
|
|
27
17
|
end
|
|
28
18
|
|
|
29
19
|
def ok_without_spaces?(grammar_path)
|
|
30
20
|
parent, child = grammar_path.values_at(-2, -1)
|
|
31
21
|
return true if [:unary, :symbol, :defs, :def, :call].include?(parent)
|
|
32
22
|
return true if [:**, :block_var].include?(child)
|
|
33
|
-
|
|
34
|
-
false
|
|
23
|
+
parent == :command_call && child == :'::'
|
|
35
24
|
end
|
|
36
25
|
|
|
37
26
|
def surrounded_by_whitespace?(nearby_tokens)
|
|
@@ -40,7 +29,7 @@ module Rubocop
|
|
|
40
29
|
end
|
|
41
30
|
|
|
42
31
|
# Default implementation for classes that don't need it.
|
|
43
|
-
def
|
|
32
|
+
def check_missing_space(tokens, ix, grammar_path)
|
|
44
33
|
end
|
|
45
34
|
end
|
|
46
35
|
|
|
@@ -48,7 +37,7 @@ module Rubocop
|
|
|
48
37
|
include SurroundingSpace
|
|
49
38
|
ERROR_MESSAGE = 'Surrounding space missing for operator '
|
|
50
39
|
|
|
51
|
-
def
|
|
40
|
+
def check_missing_space(tokens, ix, grammar_path)
|
|
52
41
|
t = tokens[ix]
|
|
53
42
|
if t.type == :on_op
|
|
54
43
|
unless surrounded_by_whitespace?(tokens[ix - 1, 3])
|
|
@@ -60,7 +49,7 @@ module Rubocop
|
|
|
60
49
|
end
|
|
61
50
|
end
|
|
62
51
|
|
|
63
|
-
def
|
|
52
|
+
def check_unwanted_space(tokens, ix)
|
|
64
53
|
prev, t, nxt = tokens.values_at(ix - 1, ix, ix + 1)
|
|
65
54
|
if t.type == :on_op && t.text == '**' &&
|
|
66
55
|
(whitespace?(prev) || whitespace?(nxt))
|
|
@@ -73,10 +62,10 @@ module Rubocop
|
|
|
73
62
|
class SpaceAroundBraces < Cop
|
|
74
63
|
include SurroundingSpace
|
|
75
64
|
|
|
76
|
-
def
|
|
65
|
+
def check_unwanted_space(tokens, ix)
|
|
77
66
|
end
|
|
78
67
|
|
|
79
|
-
def
|
|
68
|
+
def check_missing_space(tokens, ix, grammar_path)
|
|
80
69
|
t = tokens[ix]
|
|
81
70
|
case t.type
|
|
82
71
|
when :on_lbrace
|
|
@@ -93,48 +82,60 @@ module Rubocop
|
|
|
93
82
|
end
|
|
94
83
|
end
|
|
95
84
|
|
|
96
|
-
|
|
85
|
+
module SpaceInside
|
|
97
86
|
include SurroundingSpace
|
|
98
|
-
|
|
87
|
+
|
|
88
|
+
Paren = Struct.new :left, :right, :kind
|
|
89
|
+
|
|
90
|
+
def check_unwanted_space(tokens, ix)
|
|
91
|
+
paren = get_paren
|
|
99
92
|
prev, t, nxt = tokens.values_at(ix - 1, ix, ix + 1)
|
|
100
93
|
offence_detected = case t.type
|
|
101
|
-
when
|
|
94
|
+
when paren.left
|
|
102
95
|
nxt.type == :on_sp
|
|
103
|
-
when
|
|
96
|
+
when paren.right
|
|
104
97
|
if prev.type == :on_sp
|
|
105
98
|
prev_ns = previous_non_space(tokens, ix)
|
|
106
|
-
prev_ns &&
|
|
107
|
-
|
|
108
|
-
# Avoid double
|
|
109
|
-
prev_ns.type !=
|
|
99
|
+
prev_ns &&
|
|
100
|
+
prev_ns.pos.lineno == tokens[ix].pos.lineno &&
|
|
101
|
+
# Avoid double reporting
|
|
102
|
+
prev_ns.type != paren.left
|
|
110
103
|
end
|
|
111
104
|
end
|
|
112
105
|
if offence_detected
|
|
113
106
|
add_offence(:convention, t.pos.lineno,
|
|
114
|
-
|
|
107
|
+
"Space inside #{paren.kind} detected.")
|
|
115
108
|
end
|
|
116
109
|
end
|
|
117
110
|
end
|
|
118
111
|
|
|
112
|
+
class SpaceInsideParens < Cop
|
|
113
|
+
include SpaceInside
|
|
114
|
+
def get_paren
|
|
115
|
+
Paren.new(:on_lparen, :on_rparen, 'parentheses')
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
119
|
class SpaceInsideBrackets < Cop
|
|
120
|
-
include
|
|
121
|
-
def
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
120
|
+
include SpaceInside
|
|
121
|
+
def get_paren
|
|
122
|
+
Paren.new(:on_lbracket, :on_rbracket, 'square brackets')
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
class SpaceAroundEqualsInParameterDefault < Cop
|
|
127
|
+
def inspect(file, source, tokens, sexp)
|
|
128
|
+
each(:params, sexp) do |s|
|
|
129
|
+
(s[2] || []).each do |param, value|
|
|
130
|
+
value_pos = all_positions(value).first or next
|
|
131
|
+
if param[-1].lineno == value_pos.lineno
|
|
132
|
+
if value_pos.column - (param[-1].column + param[1].length) <= 2
|
|
133
|
+
add_offence(:convention, param[-1].lineno,
|
|
134
|
+
'Surrounding space missing in default value ' +
|
|
135
|
+
'assignment.')
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
138
139
|
end
|
|
139
140
|
end
|
|
140
141
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Rubocop
|
|
4
|
+
module Cop
|
|
5
|
+
class SymbolSnakeCase < Cop
|
|
6
|
+
ERROR_MESSAGE = 'Use snake_case for symbols.'
|
|
7
|
+
SNAKE_CASE = /^@?[\da-z_]+[!?=]?$/
|
|
8
|
+
def inspect(file, source, tokens, sexp)
|
|
9
|
+
each(:symbol_literal, sexp) do |s|
|
|
10
|
+
symbol_type = s[1][1][0]
|
|
11
|
+
|
|
12
|
+
# don't check operators
|
|
13
|
+
next if symbol_type == :@op
|
|
14
|
+
|
|
15
|
+
symbol_ident = s[1][1][1]
|
|
16
|
+
|
|
17
|
+
unless symbol_ident =~ SNAKE_CASE
|
|
18
|
+
line_no = s[1][1][2].lineno
|
|
19
|
+
add_offence(:convention,
|
|
20
|
+
line_no,
|
|
21
|
+
ERROR_MESSAGE)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'open3'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
class Syntax < Cop
|
|
8
|
+
def inspect(file, source, tokens, sexp)
|
|
9
|
+
stderr = nil
|
|
10
|
+
|
|
11
|
+
# it's extremely important to run the syntax check in a
|
|
12
|
+
# clean environment - otherwise it will be extremely slow
|
|
13
|
+
if defined? Bundler
|
|
14
|
+
Bundler.with_clean_env do
|
|
15
|
+
_, stderr, _ =
|
|
16
|
+
Open3.capture3('ruby -wc', stdin_data: source.join("\n"))
|
|
17
|
+
end
|
|
18
|
+
else
|
|
19
|
+
_, stderr, _ =
|
|
20
|
+
Open3.capture3('ruby -wc', stdin_data: source.join("\n"))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
stderr.each_line do |line|
|
|
24
|
+
# discard lines that are not containing relevant info
|
|
25
|
+
if line =~ /.+:(\d+): (.+)/
|
|
26
|
+
line_no, severity, message = process_line(line)
|
|
27
|
+
add_offence(severity, line_no, message)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def process_line(line)
|
|
33
|
+
line_no, message = line.match(/.+:(\d+): (.+)/).captures
|
|
34
|
+
if message.start_with?('warning: ')
|
|
35
|
+
[line_no.to_i, :warning, message.sub(/warning: /, '').capitalize]
|
|
36
|
+
else
|
|
37
|
+
[line_no.to_i, :error, message.capitalize]
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/rubocop/cop/tab.rb
CHANGED
|
@@ -7,9 +7,7 @@ module Rubocop
|
|
|
7
7
|
|
|
8
8
|
def inspect(file, source, tokens, sexp)
|
|
9
9
|
source.each_with_index do |line, index|
|
|
10
|
-
if line =~ /^ *\t/
|
|
11
|
-
add_offence(:convention, index + 1, ERROR_MESSAGE)
|
|
12
|
-
end
|
|
10
|
+
add_offence(:convention, index + 1, ERROR_MESSAGE) if line =~ /^ *\t/
|
|
13
11
|
end
|
|
14
12
|
end
|
|
15
13
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Rubocop
|
|
4
|
+
module Cop
|
|
5
|
+
class VariableInterpolation < Cop
|
|
6
|
+
def inspect(file, source, tokens, sexp)
|
|
7
|
+
each(:string_dvar, sexp) do |s|
|
|
8
|
+
var = s[1][1][1]
|
|
9
|
+
lineno = s[1][1][2].lineno
|
|
10
|
+
|
|
11
|
+
add_offence(
|
|
12
|
+
:convention,
|
|
13
|
+
lineno,
|
|
14
|
+
"Replace interpolated var #{var} with expression \#{#{var}}."
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
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)
|
|
@@ -7,8 +7,8 @@ module Rubocop
|
|
|
7
7
|
# Generates a string representation of the report
|
|
8
8
|
def generate
|
|
9
9
|
report = entries.map do |e|
|
|
10
|
-
'%s:%d: %s: %s'
|
|
11
|
-
|
|
10
|
+
sprintf('%s:%d: %s: %s', @filename,
|
|
11
|
+
e.line_number, e.encode_severity, e.message)
|
|
12
12
|
end
|
|
13
13
|
report.join("\n")
|
|
14
14
|
end
|
|
@@ -16,8 +16,7 @@ module Rubocop
|
|
|
16
16
|
module_function :create
|
|
17
17
|
|
|
18
18
|
class Report
|
|
19
|
-
|
|
20
|
-
attr_accessor :filename
|
|
19
|
+
attr_reader :filename
|
|
21
20
|
|
|
22
21
|
# @param [String] the filename for this report
|
|
23
22
|
def initialize(filename)
|
|
@@ -33,6 +32,10 @@ module Rubocop
|
|
|
33
32
|
end
|
|
34
33
|
end
|
|
35
34
|
|
|
35
|
+
def entries
|
|
36
|
+
@entries.sort_by(&:line_number)
|
|
37
|
+
end
|
|
38
|
+
|
|
36
39
|
def empty?
|
|
37
40
|
entries.empty?
|
|
38
41
|
end
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
|
|
3
3
|
require 'ripper'
|
|
4
|
+
require 'term/ansicolor'
|
|
5
|
+
|
|
6
|
+
class String
|
|
7
|
+
include Term::ANSIColor
|
|
8
|
+
end
|
|
4
9
|
|
|
5
10
|
require 'rubocop/cop/offence'
|
|
6
11
|
require 'rubocop/cop/cop'
|
|
7
12
|
require 'rubocop/cop/encoding'
|
|
8
13
|
require 'rubocop/cop/line_length'
|
|
14
|
+
require 'rubocop/cop/syntax'
|
|
9
15
|
require 'rubocop/cop/tab'
|
|
10
16
|
require 'rubocop/cop/trailing_whitespace'
|
|
11
17
|
require 'rubocop/cop/indentation'
|
|
@@ -25,9 +31,40 @@ require 'rubocop/cop/ternary_operator'
|
|
|
25
31
|
require 'rubocop/cop/unless_else'
|
|
26
32
|
require 'rubocop/cop/ampersands_pipes_vs_and_or'
|
|
27
33
|
require 'rubocop/cop/when_then'
|
|
34
|
+
require 'rubocop/cop/favor_modifier'
|
|
35
|
+
require 'rubocop/cop/favor_unless_over_negated_if'
|
|
36
|
+
require 'rubocop/cop/new_lambda_literal'
|
|
37
|
+
require 'rubocop/cop/parentheses_around_condition'
|
|
38
|
+
require 'rubocop/cop/method_and_variable_snake_case'
|
|
39
|
+
require 'rubocop/cop/class_and_module_camel_case'
|
|
40
|
+
require 'rubocop/cop/collection_methods'
|
|
41
|
+
require 'rubocop/cop/avoid_for'
|
|
42
|
+
require 'rubocop/cop/avoid_perlisms'
|
|
43
|
+
require 'rubocop/cop/avoid_perl_backrefs'
|
|
44
|
+
require 'rubocop/cop/avoid_class_vars'
|
|
45
|
+
require 'rubocop/cop/symbol_snake_case'
|
|
46
|
+
require 'rubocop/cop/variable_interpolation'
|
|
47
|
+
require 'rubocop/cop/semicolon'
|
|
48
|
+
require 'rubocop/cop/favor_sprintf'
|
|
49
|
+
require 'rubocop/cop/alias'
|
|
50
|
+
require 'rubocop/cop/rescue_modifier'
|
|
51
|
+
require 'rubocop/cop/percent_literals'
|
|
52
|
+
require 'rubocop/cop/brace_after_percent'
|
|
53
|
+
require 'rubocop/cop/ensure_return'
|
|
54
|
+
require 'rubocop/cop/handle_exceptions'
|
|
55
|
+
require 'rubocop/cop/rescue_exception'
|
|
56
|
+
require 'rubocop/cop/ascii_identifiers_and_comments'
|
|
57
|
+
require 'rubocop/cop/hash_literal'
|
|
58
|
+
require 'rubocop/cop/array_literal'
|
|
59
|
+
require 'rubocop/cop/method_length'
|
|
60
|
+
require 'rubocop/cop/op_method'
|
|
61
|
+
require 'rubocop/cop/reduce_arguments'
|
|
62
|
+
require 'rubocop/cop/percent_r'
|
|
63
|
+
require 'rubocop/cop/favor_percent_r'
|
|
28
64
|
|
|
29
65
|
require 'rubocop/report/report'
|
|
30
66
|
require 'rubocop/report/plain_text'
|
|
31
67
|
require 'rubocop/report/emacs_style'
|
|
32
68
|
|
|
33
69
|
require 'rubocop/cli'
|
|
70
|
+
require 'rubocop/version'
|
data/rubocop.gemspec
CHANGED
|
@@ -1,140 +1,42 @@
|
|
|
1
|
-
# Generated by jeweler
|
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
|
3
|
+
require 'rubocop/version'
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name =
|
|
8
|
-
s.version =
|
|
6
|
+
s.name = 'rubocop'
|
|
7
|
+
s.version = Rubocop::Version::STRING
|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
|
9
|
+
s.required_ruby_version = '>= 1.9.2'
|
|
10
|
+
s.authors = ['Bozhidar Batsov']
|
|
11
|
+
s.date = '2013-04-17'
|
|
12
|
+
s.description = 'Automatic Ruby code style checking tool. Aims to enforce the community-driven Ruby Style Guide.'
|
|
13
|
+
s.email = 'bozhidar@batsov.com'
|
|
14
|
+
s.executables = ['rubocop']
|
|
15
|
+
s.extra_rdoc_files = ['LICENSE.txt', 'README.md']
|
|
16
|
+
s.files = ['.document',
|
|
17
|
+
'.rspec',
|
|
18
|
+
'.rubocop.yml',
|
|
19
|
+
'.travis.yml',
|
|
20
|
+
'CHANGELOG.md',
|
|
21
|
+
'CONTRIBUTING.md',
|
|
22
|
+
'Gemfile',
|
|
23
|
+
'LICENSE.txt',
|
|
24
|
+
'README.md',
|
|
25
|
+
'Rakefile',
|
|
26
|
+
'bin/rubocop',
|
|
27
|
+
'rubocop.gemspec'] + Dir['lib/**/*.rb']
|
|
9
28
|
|
|
10
|
-
s.
|
|
11
|
-
s.
|
|
12
|
-
s.
|
|
13
|
-
s.
|
|
14
|
-
s.
|
|
15
|
-
s.
|
|
16
|
-
s.extra_rdoc_files = [
|
|
17
|
-
"LICENSE.txt",
|
|
18
|
-
"README.md"
|
|
19
|
-
]
|
|
20
|
-
s.files = [
|
|
21
|
-
".document",
|
|
22
|
-
".rbenv-version",
|
|
23
|
-
".rspec",
|
|
24
|
-
".rubocop.yml",
|
|
25
|
-
".rvmrc",
|
|
26
|
-
".travis.yml",
|
|
27
|
-
"CONTRIBUTING.md",
|
|
28
|
-
"Gemfile",
|
|
29
|
-
"Gemfile.lock",
|
|
30
|
-
"LICENSE.txt",
|
|
31
|
-
"README.md",
|
|
32
|
-
"Rakefile",
|
|
33
|
-
"VERSION",
|
|
34
|
-
"bin/rubocop",
|
|
35
|
-
"features/rubocop.feature",
|
|
36
|
-
"features/step_definitions/rubocop_steps.rb",
|
|
37
|
-
"features/support/env.rb",
|
|
38
|
-
"lib/rubocop.rb",
|
|
39
|
-
"lib/rubocop/cli.rb",
|
|
40
|
-
"lib/rubocop/cop/align_parameters.rb",
|
|
41
|
-
"lib/rubocop/cop/ampersands_pipes_vs_and_or.rb",
|
|
42
|
-
"lib/rubocop/cop/blocks.rb",
|
|
43
|
-
"lib/rubocop/cop/cop.rb",
|
|
44
|
-
"lib/rubocop/cop/def_parentheses.rb",
|
|
45
|
-
"lib/rubocop/cop/empty_lines.rb",
|
|
46
|
-
"lib/rubocop/cop/encoding.rb",
|
|
47
|
-
"lib/rubocop/cop/end_of_line.rb",
|
|
48
|
-
"lib/rubocop/cop/grammar.rb",
|
|
49
|
-
"lib/rubocop/cop/hash_syntax.rb",
|
|
50
|
-
"lib/rubocop/cop/if_then_else.rb",
|
|
51
|
-
"lib/rubocop/cop/indentation.rb",
|
|
52
|
-
"lib/rubocop/cop/line_length.rb",
|
|
53
|
-
"lib/rubocop/cop/numeric_literals.rb",
|
|
54
|
-
"lib/rubocop/cop/offence.rb",
|
|
55
|
-
"lib/rubocop/cop/parameter_lists.rb",
|
|
56
|
-
"lib/rubocop/cop/space_after_comma_etc.rb",
|
|
57
|
-
"lib/rubocop/cop/string_literals.rb",
|
|
58
|
-
"lib/rubocop/cop/surrounding_space.rb",
|
|
59
|
-
"lib/rubocop/cop/tab.rb",
|
|
60
|
-
"lib/rubocop/cop/ternary_operator.rb",
|
|
61
|
-
"lib/rubocop/cop/trailing_whitespace.rb",
|
|
62
|
-
"lib/rubocop/cop/unless_else.rb",
|
|
63
|
-
"lib/rubocop/cop/when_then.rb",
|
|
64
|
-
"lib/rubocop/report/emacs_style.rb",
|
|
65
|
-
"lib/rubocop/report/plain_text.rb",
|
|
66
|
-
"lib/rubocop/report/report.rb",
|
|
67
|
-
"lib/rubocop/version.rb",
|
|
68
|
-
"rubocop.gemspec",
|
|
69
|
-
"spec/rubocop/cli_spec.rb",
|
|
70
|
-
"spec/rubocop/cops/align_parameters_spec.rb",
|
|
71
|
-
"spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb",
|
|
72
|
-
"spec/rubocop/cops/cop_spec.rb",
|
|
73
|
-
"spec/rubocop/cops/def_with_parentheses_spec.rb",
|
|
74
|
-
"spec/rubocop/cops/def_without_parentheses_spec.rb",
|
|
75
|
-
"spec/rubocop/cops/empty_lines_spec.rb",
|
|
76
|
-
"spec/rubocop/cops/encoding_spec.rb",
|
|
77
|
-
"spec/rubocop/cops/end_of_line_spec.rb",
|
|
78
|
-
"spec/rubocop/cops/grammar_spec.rb",
|
|
79
|
-
"spec/rubocop/cops/hash_syntax_spec.rb",
|
|
80
|
-
"spec/rubocop/cops/if_with_semicolon_spec.rb",
|
|
81
|
-
"spec/rubocop/cops/indentation_spec.rb",
|
|
82
|
-
"spec/rubocop/cops/line_length_spec.rb",
|
|
83
|
-
"spec/rubocop/cops/multiline_blocks_spec.rb",
|
|
84
|
-
"spec/rubocop/cops/multiline_if_then_spec.rb",
|
|
85
|
-
"spec/rubocop/cops/numeric_literals_spec.rb",
|
|
86
|
-
"spec/rubocop/cops/offence_spec.rb",
|
|
87
|
-
"spec/rubocop/cops/one_line_conditional_spec.rb",
|
|
88
|
-
"spec/rubocop/cops/parameter_lists_spec.rb",
|
|
89
|
-
"spec/rubocop/cops/single_line_blocks_spec.rb",
|
|
90
|
-
"spec/rubocop/cops/space_after_colon_spec.rb",
|
|
91
|
-
"spec/rubocop/cops/space_after_comma_spec.rb",
|
|
92
|
-
"spec/rubocop/cops/space_after_semicolon_spec.rb",
|
|
93
|
-
"spec/rubocop/cops/space_around_braces_spec.rb",
|
|
94
|
-
"spec/rubocop/cops/space_around_operators_spec.rb",
|
|
95
|
-
"spec/rubocop/cops/space_inside_brackets_spec.rb",
|
|
96
|
-
"spec/rubocop/cops/space_inside_parens_spec.rb",
|
|
97
|
-
"spec/rubocop/cops/string_literals_spec.rb",
|
|
98
|
-
"spec/rubocop/cops/tab_spec.rb",
|
|
99
|
-
"spec/rubocop/cops/ternary_operator_spec.rb",
|
|
100
|
-
"spec/rubocop/cops/trailing_whitespace_spec.rb",
|
|
101
|
-
"spec/rubocop/cops/unless_else_spec.rb",
|
|
102
|
-
"spec/rubocop/cops/when_then_spec.rb",
|
|
103
|
-
"spec/rubocop/reports/emacs_style_spec.rb",
|
|
104
|
-
"spec/rubocop/reports/report_spec.rb",
|
|
105
|
-
"spec/spec_helper.rb"
|
|
106
|
-
]
|
|
107
|
-
s.homepage = "http://github.com/bbatsov/rubocop"
|
|
108
|
-
s.licenses = ["MIT"]
|
|
109
|
-
s.require_paths = ["lib"]
|
|
110
|
-
s.rubygems_version = "1.8.23"
|
|
111
|
-
s.summary = "Automatic Ruby code style checking tool."
|
|
29
|
+
s.test_files = Dir['spec/**/*.rb']
|
|
30
|
+
s.homepage = 'http://github.com/bbatsov/rubocop'
|
|
31
|
+
s.licenses = ['MIT']
|
|
32
|
+
s.require_paths = ['lib']
|
|
33
|
+
s.rubygems_version = '1.8.23'
|
|
34
|
+
s.summary = 'Automatic Ruby code style checking tool.'
|
|
112
35
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
s.add_development_dependency(%q<yard>, ["~> 0.8.0"])
|
|
120
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.2.0"])
|
|
121
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
122
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
|
123
|
-
else
|
|
124
|
-
s.add_dependency(%q<rake>, ["~> 10.0.0"])
|
|
125
|
-
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
|
126
|
-
s.add_dependency(%q<yard>, ["~> 0.8.0"])
|
|
127
|
-
s.add_dependency(%q<bundler>, ["~> 1.2.0"])
|
|
128
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
129
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
|
130
|
-
end
|
|
131
|
-
else
|
|
132
|
-
s.add_dependency(%q<rake>, ["~> 10.0.0"])
|
|
133
|
-
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
|
134
|
-
s.add_dependency(%q<yard>, ["~> 0.8.0"])
|
|
135
|
-
s.add_dependency(%q<bundler>, ["~> 1.2.0"])
|
|
136
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
137
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
|
138
|
-
end
|
|
36
|
+
s.add_runtime_dependency(%q<term-ansicolor>, '~> 1.1')
|
|
37
|
+
s.add_development_dependency(%q<rake>, '~> 10.0')
|
|
38
|
+
s.add_development_dependency(%q<rspec>, '~> 2.13')
|
|
39
|
+
s.add_development_dependency(%q<yard>, '~> 0.8')
|
|
40
|
+
s.add_development_dependency(%q<bundler>, '~> 1.3')
|
|
41
|
+
s.add_development_dependency(%q<simplecov>, '~> 0.7')
|
|
139
42
|
end
|
|
140
|
-
|