rubocop 0.4.0 → 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 +7 -0
- data/.gitignore +50 -0
- data/.rubocop.yml +5 -127
- data/.travis.yml +7 -1
- data/CHANGELOG.md +157 -0
- data/CONTRIBUTING.md +13 -6
- data/Gemfile +3 -8
- data/README.md +160 -9
- data/Rakefile +3 -17
- data/bin/rubocop +16 -10
- data/config/default.yml +46 -0
- data/config/disabled.yml +5 -0
- data/config/enabled.yml +322 -0
- data/lib/rubocop/cli.rb +248 -93
- data/lib/rubocop/config.rb +205 -0
- data/lib/rubocop/config_store.rb +37 -0
- data/lib/rubocop/cop/access_control.rb +41 -0
- data/lib/rubocop/cop/alias.rb +17 -0
- data/lib/rubocop/cop/align_parameters.rb +20 -95
- data/lib/rubocop/cop/and_or.rb +26 -0
- data/lib/rubocop/cop/ascii_comments.rb +13 -0
- data/lib/rubocop/cop/ascii_identifiers.rb +19 -0
- data/lib/rubocop/cop/avoid_class_vars.rb +15 -0
- data/lib/rubocop/cop/avoid_for.rb +17 -0
- data/lib/rubocop/cop/avoid_global_vars.rb +61 -0
- data/lib/rubocop/cop/avoid_perl_backrefs.rb +17 -0
- data/lib/rubocop/cop/avoid_perlisms.rb +47 -0
- data/lib/rubocop/cop/block_comments.rb +15 -0
- data/lib/rubocop/cop/blocks.rb +11 -47
- data/lib/rubocop/cop/case_indentation.rb +22 -0
- data/lib/rubocop/cop/class_and_module_camel_case.rb +20 -11
- data/lib/rubocop/cop/class_methods.rb +15 -0
- data/lib/rubocop/cop/collection_methods.rb +16 -16
- data/lib/rubocop/cop/colon_method_call.rb +20 -0
- data/lib/rubocop/cop/constant_name.rb +24 -0
- data/lib/rubocop/cop/cop.rb +34 -47
- data/lib/rubocop/cop/def_parentheses.rb +43 -35
- data/lib/rubocop/cop/empty_line_between_defs.rb +22 -0
- data/lib/rubocop/cop/empty_lines.rb +21 -13
- 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 +19 -0
- data/lib/rubocop/cop/eval.rb +19 -0
- data/lib/rubocop/cop/favor_join.rb +22 -0
- data/lib/rubocop/cop/favor_modifier.rb +38 -48
- data/lib/rubocop/cop/favor_percent_r.rb +19 -0
- data/lib/rubocop/cop/favor_sprintf.rb +21 -0
- data/lib/rubocop/cop/favor_unless_over_negated_if.rb +19 -17
- data/lib/rubocop/cop/handle_exceptions.rb +17 -0
- 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 +17 -0
- data/lib/rubocop/cop/line_continuation.rb +15 -0
- data/lib/rubocop/cop/line_length.rb +4 -4
- data/lib/rubocop/cop/loop.rb +33 -0
- data/lib/rubocop/cop/method_and_variable_snake_case.rb +41 -17
- data/lib/rubocop/cop/method_length.rb +52 -0
- data/lib/rubocop/cop/new_lambda_literal.rb +8 -6
- data/lib/rubocop/cop/not.rb +21 -0
- data/lib/rubocop/cop/numeric_literals.rb +9 -7
- data/lib/rubocop/cop/offence.rb +12 -1
- data/lib/rubocop/cop/op_method.rb +26 -0
- 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 +19 -0
- data/lib/rubocop/cop/reduce_arguments.rb +29 -0
- data/lib/rubocop/cop/rescue_exception.rb +26 -0
- data/lib/rubocop/cop/rescue_modifier.rb +17 -0
- data/lib/rubocop/cop/semicolon.rb +31 -0
- data/lib/rubocop/cop/single_line_methods.rb +44 -0
- data/lib/rubocop/cop/space_after_comma_etc.rb +30 -10
- data/lib/rubocop/cop/space_after_control_keyword.rb +29 -0
- data/lib/rubocop/cop/string_literals.rb +9 -23
- data/lib/rubocop/cop/surrounding_space.rb +223 -83
- data/lib/rubocop/cop/symbol_array.rb +31 -0
- data/lib/rubocop/cop/symbol_name.rb +23 -0
- data/lib/rubocop/cop/syntax.rb +35 -5
- 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 +26 -0
- data/lib/rubocop/cop/unless_else.rb +11 -7
- data/lib/rubocop/cop/util.rb +26 -0
- data/lib/rubocop/cop/variable_interpolation.rb +29 -0
- data/lib/rubocop/cop/when_then.rb +6 -14
- data/lib/rubocop/cop/word_array.rb +37 -0
- data/lib/rubocop/report/emacs_style.rb +2 -2
- data/lib/rubocop/report/plain_text.rb +1 -1
- data/lib/rubocop/version.rb +3 -1
- data/lib/rubocop.rb +48 -8
- data/rubocop.gemspec +32 -151
- data/spec/project_spec.rb +27 -0
- data/spec/rubocop/cli_spec.rb +573 -200
- data/spec/rubocop/config_spec.rb +409 -0
- data/spec/rubocop/config_store_spec.rb +66 -0
- data/spec/rubocop/cops/access_control_spec.rb +129 -0
- data/spec/rubocop/cops/alias_spec.rb +39 -0
- data/spec/rubocop/cops/align_parameters_spec.rb +66 -70
- data/spec/rubocop/cops/and_or_spec.rb +37 -0
- data/spec/rubocop/cops/ascii_comments_spec.rb +26 -0
- data/spec/rubocop/cops/ascii_identifiers_spec.rb +26 -0
- data/spec/rubocop/cops/avoid_class_vars_spec.rb +25 -0
- data/spec/rubocop/cops/avoid_for_spec.rb +35 -0
- data/spec/rubocop/cops/avoid_global_vars_spec.rb +32 -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/block_comments_spec.rb +25 -0
- data/spec/rubocop/cops/blocks_spec.rb +33 -0
- data/spec/rubocop/cops/{indentation_spec.rb → case_indentation_spec.rb} +7 -7
- data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +15 -5
- data/spec/rubocop/cops/class_methods_spec.rb +49 -0
- data/spec/rubocop/cops/collection_methods_spec.rb +9 -4
- data/spec/rubocop/cops/colon_method_call_spec.rb +53 -0
- 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 +83 -0
- data/spec/rubocop/cops/empty_lines_spec.rb +14 -59
- data/spec/rubocop/cops/empty_literal_spec.rb +90 -0
- data/spec/rubocop/cops/encoding_spec.rb +11 -11
- data/spec/rubocop/cops/end_of_line_spec.rb +2 -2
- data/spec/rubocop/cops/ensure_return_spec.rb +35 -0
- data/spec/rubocop/cops/eval_spec.rb +39 -0
- data/spec/rubocop/cops/favor_join_spec.rb +35 -0
- data/spec/rubocop/cops/favor_modifier_spec.rb +16 -14
- data/spec/rubocop/cops/favor_percent_r_spec.rb +29 -0
- data/spec/rubocop/cops/favor_sprintf_spec.rb +51 -0
- 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 +34 -0
- 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 +54 -0
- data/spec/rubocop/cops/line_continuation_spec.rb +24 -0
- data/spec/rubocop/cops/line_length_spec.rb +3 -2
- data/spec/rubocop/cops/loop_spec.rb +31 -0
- data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +55 -9
- data/spec/rubocop/cops/method_length_spec.rb +147 -0
- data/spec/rubocop/cops/multiline_if_then_spec.rb +15 -15
- data/spec/rubocop/cops/new_lambda_literal_spec.rb +5 -6
- data/spec/rubocop/cops/not_spec.rb +31 -0
- data/spec/rubocop/cops/numeric_literals_spec.rb +13 -13
- data/spec/rubocop/cops/offence_spec.rb +13 -0
- data/spec/rubocop/cops/one_line_conditional_spec.rb +1 -1
- data/spec/rubocop/cops/op_method_spec.rb +78 -0
- 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 +29 -0
- data/spec/rubocop/cops/reduce_arguments_spec.rb +57 -0
- data/spec/rubocop/cops/rescue_exception_spec.rb +125 -0
- data/spec/rubocop/cops/rescue_modifier_spec.rb +37 -0
- data/spec/rubocop/cops/semicolon_spec.rb +88 -0
- data/spec/rubocop/cops/single_line_methods_spec.rb +50 -0
- 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 +67 -0
- data/spec/rubocop/cops/space_after_semicolon_spec.rb +6 -1
- data/spec/rubocop/cops/space_around_braces_spec.rb +18 -3
- data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +12 -2
- data/spec/rubocop/cops/space_around_operators_spec.rb +88 -26
- data/spec/rubocop/cops/space_inside_brackets_spec.rb +13 -7
- data/spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb +79 -0
- data/spec/rubocop/cops/space_inside_parens_spec.rb +7 -3
- data/spec/rubocop/cops/string_literals_spec.rb +21 -6
- data/spec/rubocop/cops/symbol_array_spec.rb +41 -0
- data/spec/rubocop/cops/symbol_name_spec.rb +119 -0
- data/spec/rubocop/cops/syntax_spec.rb +28 -5
- 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 +329 -0
- data/spec/rubocop/cops/unless_else_spec.rb +8 -8
- data/spec/rubocop/cops/variable_interpolation_spec.rb +49 -0
- data/spec/rubocop/cops/when_then_spec.rb +14 -14
- data/spec/rubocop/cops/word_array_spec.rb +47 -0
- data/spec/spec_helper.rb +30 -9
- data/spec/support/file_helper.rb +21 -0
- data/spec/support/isolated_environment.rb +27 -0
- metadata +235 -76
- data/.document +0 -5
- data/Gemfile.lock +0 -41
- data/VERSION +0 -1
- data/lib/rubocop/cop/ampersands_pipes_vs_and_or.rb +0 -25
- data/lib/rubocop/cop/grammar.rb +0 -135
- data/lib/rubocop/cop/indentation.rb +0 -44
- data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +0 -57
- data/spec/rubocop/cops/grammar_spec.rb +0 -71
- data/spec/rubocop/cops/multiline_blocks_spec.rb +0 -24
- data/spec/rubocop/cops/single_line_blocks_spec.rb +0 -22
@@ -2,39 +2,41 @@
|
|
2
2
|
|
3
3
|
module Rubocop
|
4
4
|
module Cop
|
5
|
-
module TernaryOperator
|
6
|
-
def inspect(file, source, tokens, sexp)
|
7
|
-
each(:ifop, sexp) do |ifop|
|
8
|
-
if offends?(ifop)
|
9
|
-
add_offence(:convention, all_positions(ifop).first.lineno,
|
10
|
-
error_message)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
5
|
class MultilineTernaryOperator < Cop
|
17
|
-
|
18
|
-
|
19
|
-
def error_message
|
6
|
+
MSG =
|
20
7
|
'Avoid multi-line ?: (the ternary operator); use if/unless instead.'
|
21
|
-
end
|
22
8
|
|
23
|
-
def
|
24
|
-
|
9
|
+
def on_if(node)
|
10
|
+
loc = node.loc
|
11
|
+
|
12
|
+
# discard non-ternary ops
|
13
|
+
return unless loc.respond_to?(:question)
|
14
|
+
|
15
|
+
add_offence(:convention, loc.line, MSG) if loc.line != loc.colon.line
|
16
|
+
|
17
|
+
super
|
25
18
|
end
|
26
19
|
end
|
27
20
|
|
28
21
|
class NestedTernaryOperator < Cop
|
29
|
-
|
22
|
+
MSG = 'Ternary operators must not be nested. Prefer if/else ' +
|
23
|
+
'constructs instead.'
|
30
24
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
def on_if(node)
|
26
|
+
loc = node.loc
|
27
|
+
|
28
|
+
# discard non-ternary ops
|
29
|
+
return unless loc.respond_to?(:question)
|
30
|
+
|
31
|
+
node.children.each do |child|
|
32
|
+
on_node(:if, child) do |c|
|
33
|
+
if c.loc.respond_to?(:question)
|
34
|
+
add_offence(:convention, c.loc.line, MSG)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
35
38
|
|
36
|
-
|
37
|
-
ifop.flatten[1..-1].include?(:ifop)
|
39
|
+
super
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
@@ -3,13 +3,11 @@
|
|
3
3
|
module Rubocop
|
4
4
|
module Cop
|
5
5
|
class TrailingWhitespace < Cop
|
6
|
-
|
6
|
+
MSG = 'Trailing whitespace detected.'
|
7
7
|
|
8
|
-
def inspect(
|
8
|
+
def inspect(source, tokens, ast, comments)
|
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, MSG) if line =~ /.*[ \t]+$/
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Cop
|
5
|
+
class TrivialAccessors < Cop
|
6
|
+
MSG = 'Use attr_%s to define trivial %s methods.'
|
7
|
+
|
8
|
+
def on_def(node)
|
9
|
+
_, args, body = *node
|
10
|
+
|
11
|
+
kind = if body.type == :ivar
|
12
|
+
'reader'
|
13
|
+
elsif args.children.size == 1 && body.type == :ivasgn &&
|
14
|
+
body.children[1].type == :lvar
|
15
|
+
'writer'
|
16
|
+
end
|
17
|
+
if kind
|
18
|
+
add_offence(:convention, node.loc.keyword.line,
|
19
|
+
sprintf(MSG, kind, kind))
|
20
|
+
end
|
21
|
+
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -3,16 +3,20 @@
|
|
3
3
|
module Rubocop
|
4
4
|
module Cop
|
5
5
|
class UnlessElse < Cop
|
6
|
-
|
6
|
+
MSG = 'Never use unless with else. Rewrite these with the ' +
|
7
7
|
'positive case first.'
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
def on_if(node)
|
10
|
+
loc = node.loc
|
11
|
+
|
12
|
+
# discard ternary ops and modifier if/unless nodes
|
13
|
+
return unless loc.respond_to?(:keyword) && loc.respond_to?(:else)
|
14
|
+
|
15
|
+
if loc.keyword.source == 'unless' && loc.else
|
16
|
+
add_offence(:convention, loc.line, MSG)
|
15
17
|
end
|
18
|
+
|
19
|
+
super
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Cop
|
5
|
+
module Util
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def strip_quotes(str)
|
9
|
+
if str[0] == '"' || str[0] == "'"
|
10
|
+
str[0] = ''
|
11
|
+
str[-1] = ''
|
12
|
+
else
|
13
|
+
# we're dealing with %q or %Q
|
14
|
+
str[0, 3] = ''
|
15
|
+
str[-1] = ''
|
16
|
+
end
|
17
|
+
|
18
|
+
str
|
19
|
+
end
|
20
|
+
|
21
|
+
def block_length(block_node)
|
22
|
+
block_node.loc.end.line - block_node.loc.begin.line
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Cop
|
5
|
+
class VariableInterpolation < Cop
|
6
|
+
MSG = 'Replace interpolated var %s with expression #{%s}.'
|
7
|
+
|
8
|
+
def on_dstr(node)
|
9
|
+
var_nodes(node.children).each do |v|
|
10
|
+
var = (v.type == :nth_ref ? '$' : '') + v.to_a[0].to_s
|
11
|
+
|
12
|
+
if node.loc.expression.source.include?("##{var}")
|
13
|
+
add_offence(:convention,
|
14
|
+
v.loc.line,
|
15
|
+
sprintf(MSG, var, var))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def var_nodes(nodes)
|
25
|
+
nodes.select { |n| [:ivar, :cvar, :gvar, :nth_ref].include?(n.type) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -3,22 +3,14 @@
|
|
3
3
|
module Rubocop
|
4
4
|
module Cop
|
5
5
|
class WhenThen < Cop
|
6
|
-
|
6
|
+
MSG = 'Never use "when x;". Use "when x then" instead.'
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
# when <value> <divider> <body>
|
12
|
-
# where divider is either semicolon, then, or line break.
|
13
|
-
last_pos_in_value = all_positions(s[1])[-1]
|
14
|
-
start_index = tokens.index { |t| t.pos == last_pos_in_value }
|
15
|
-
tokens[start_index..-1].each do |t|
|
16
|
-
break if ['then', "\n"].include?(t.text)
|
17
|
-
if t.type == :on_semicolon
|
18
|
-
add_offence(:convention, t.pos.lineno, ERROR_MESSAGE)
|
19
|
-
end
|
20
|
-
end
|
8
|
+
def on_when(node)
|
9
|
+
if node.loc.begin && node.loc.begin.source == ';'
|
10
|
+
add_offence(:convention, node.loc.line, MSG)
|
21
11
|
end
|
12
|
+
|
13
|
+
super
|
22
14
|
end
|
23
15
|
end
|
24
16
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Cop
|
5
|
+
class WordArray < Cop
|
6
|
+
MSG = 'Use %w or %W for array of words.'
|
7
|
+
|
8
|
+
def on_array(node)
|
9
|
+
return unless node.loc.begin && node.loc.begin.source == '['
|
10
|
+
|
11
|
+
array_elems = node.children
|
12
|
+
|
13
|
+
# no need to check empty arrays
|
14
|
+
return unless array_elems && array_elems.size > 1
|
15
|
+
|
16
|
+
string_array = array_elems.all? { |e| e.type == :str }
|
17
|
+
|
18
|
+
if string_array && !complex_content?(array_elems)
|
19
|
+
add_offence(:convention, node.loc.line, MSG)
|
20
|
+
end
|
21
|
+
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def complex_content?(arr_sexp)
|
28
|
+
arr_sexp.each do |s|
|
29
|
+
str_content = Util.strip_quotes(s.loc.expression.source)
|
30
|
+
return true unless str_content =~ /\A[\w-]+\z/
|
31
|
+
end
|
32
|
+
|
33
|
+
false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -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
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
include Term::ANSIColor
|
8
|
-
end
|
3
|
+
require 'rainbow'
|
4
|
+
require 'English'
|
5
|
+
require 'parser/current'
|
6
|
+
require 'ast/sexp'
|
9
7
|
|
8
|
+
require 'rubocop/cop/util'
|
10
9
|
require 'rubocop/cop/offence'
|
11
10
|
require 'rubocop/cop/cop'
|
12
11
|
require 'rubocop/cop/encoding'
|
13
12
|
require 'rubocop/cop/line_length'
|
13
|
+
require 'rubocop/cop/line_continuation'
|
14
14
|
require 'rubocop/cop/syntax'
|
15
15
|
require 'rubocop/cop/tab'
|
16
16
|
require 'rubocop/cop/trailing_whitespace'
|
17
|
-
require 'rubocop/cop/
|
17
|
+
require 'rubocop/cop/case_indentation'
|
18
|
+
require 'rubocop/cop/empty_line_between_defs'
|
18
19
|
require 'rubocop/cop/empty_lines'
|
19
20
|
require 'rubocop/cop/surrounding_space'
|
20
21
|
require 'rubocop/cop/space_after_comma_etc'
|
22
|
+
require 'rubocop/cop/space_after_control_keyword'
|
21
23
|
require 'rubocop/cop/hash_syntax'
|
22
24
|
require 'rubocop/cop/end_of_line'
|
23
25
|
require 'rubocop/cop/numeric_literals'
|
@@ -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'
|
@@ -38,10 +40,48 @@ require 'rubocop/cop/parentheses_around_condition'
|
|
38
40
|
require 'rubocop/cop/method_and_variable_snake_case'
|
39
41
|
require 'rubocop/cop/class_and_module_camel_case'
|
40
42
|
require 'rubocop/cop/collection_methods'
|
43
|
+
require 'rubocop/cop/avoid_for'
|
44
|
+
require 'rubocop/cop/avoid_perlisms'
|
45
|
+
require 'rubocop/cop/avoid_perl_backrefs'
|
46
|
+
require 'rubocop/cop/avoid_global_vars'
|
47
|
+
require 'rubocop/cop/avoid_class_vars'
|
48
|
+
require 'rubocop/cop/symbol_name'
|
49
|
+
require 'rubocop/cop/constant_name'
|
50
|
+
require 'rubocop/cop/variable_interpolation'
|
51
|
+
require 'rubocop/cop/semicolon'
|
52
|
+
require 'rubocop/cop/favor_sprintf'
|
53
|
+
require 'rubocop/cop/favor_join'
|
54
|
+
require 'rubocop/cop/alias'
|
55
|
+
require 'rubocop/cop/rescue_modifier'
|
56
|
+
require 'rubocop/cop/ensure_return'
|
57
|
+
require 'rubocop/cop/handle_exceptions'
|
58
|
+
require 'rubocop/cop/rescue_exception'
|
59
|
+
require 'rubocop/cop/ascii_identifiers'
|
60
|
+
require 'rubocop/cop/ascii_comments'
|
61
|
+
require 'rubocop/cop/block_comments'
|
62
|
+
require 'rubocop/cop/empty_literal'
|
63
|
+
require 'rubocop/cop/method_length'
|
64
|
+
require 'rubocop/cop/op_method'
|
65
|
+
require 'rubocop/cop/reduce_arguments'
|
66
|
+
require 'rubocop/cop/percent_r'
|
67
|
+
require 'rubocop/cop/favor_percent_r'
|
68
|
+
require 'rubocop/cop/class_methods'
|
69
|
+
require 'rubocop/cop/single_line_methods'
|
70
|
+
require 'rubocop/cop/word_array'
|
71
|
+
require 'rubocop/cop/symbol_array'
|
72
|
+
require 'rubocop/cop/trivial_accessors'
|
73
|
+
require 'rubocop/cop/leading_comment_space'
|
74
|
+
require 'rubocop/cop/colon_method_call'
|
75
|
+
require 'rubocop/cop/not'
|
76
|
+
require 'rubocop/cop/eval'
|
77
|
+
require 'rubocop/cop/access_control'
|
78
|
+
require 'rubocop/cop/loop'
|
41
79
|
|
42
80
|
require 'rubocop/report/report'
|
43
81
|
require 'rubocop/report/plain_text'
|
44
82
|
require 'rubocop/report/emacs_style'
|
45
83
|
|
84
|
+
require 'rubocop/config'
|
85
|
+
require 'rubocop/config_store'
|
46
86
|
require 'rubocop/cli'
|
47
87
|
require 'rubocop/version'
|
data/rubocop.gemspec
CHANGED
@@ -1,156 +1,37 @@
|
|
1
|
-
#
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# encoding: utf-8
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
require 'rubocop/version'
|
5
|
+
require 'English'
|
9
6
|
|
10
|
-
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
16
|
-
s.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
".document",
|
22
|
-
".rspec",
|
23
|
-
".rubocop.yml",
|
24
|
-
".travis.yml",
|
25
|
-
"CONTRIBUTING.md",
|
26
|
-
"Gemfile",
|
27
|
-
"Gemfile.lock",
|
28
|
-
"LICENSE.txt",
|
29
|
-
"README.md",
|
30
|
-
"Rakefile",
|
31
|
-
"VERSION",
|
32
|
-
"bin/rubocop",
|
33
|
-
"lib/rubocop.rb",
|
34
|
-
"lib/rubocop/cli.rb",
|
35
|
-
"lib/rubocop/cop/align_parameters.rb",
|
36
|
-
"lib/rubocop/cop/ampersands_pipes_vs_and_or.rb",
|
37
|
-
"lib/rubocop/cop/blocks.rb",
|
38
|
-
"lib/rubocop/cop/class_and_module_camel_case.rb",
|
39
|
-
"lib/rubocop/cop/collection_methods.rb",
|
40
|
-
"lib/rubocop/cop/cop.rb",
|
41
|
-
"lib/rubocop/cop/def_parentheses.rb",
|
42
|
-
"lib/rubocop/cop/empty_lines.rb",
|
43
|
-
"lib/rubocop/cop/encoding.rb",
|
44
|
-
"lib/rubocop/cop/end_of_line.rb",
|
45
|
-
"lib/rubocop/cop/favor_modifier.rb",
|
46
|
-
"lib/rubocop/cop/favor_unless_over_negated_if.rb",
|
47
|
-
"lib/rubocop/cop/grammar.rb",
|
48
|
-
"lib/rubocop/cop/hash_syntax.rb",
|
49
|
-
"lib/rubocop/cop/if_then_else.rb",
|
50
|
-
"lib/rubocop/cop/indentation.rb",
|
51
|
-
"lib/rubocop/cop/line_length.rb",
|
52
|
-
"lib/rubocop/cop/method_and_variable_snake_case.rb",
|
53
|
-
"lib/rubocop/cop/new_lambda_literal.rb",
|
54
|
-
"lib/rubocop/cop/numeric_literals.rb",
|
55
|
-
"lib/rubocop/cop/offence.rb",
|
56
|
-
"lib/rubocop/cop/parameter_lists.rb",
|
57
|
-
"lib/rubocop/cop/parentheses_around_condition.rb",
|
58
|
-
"lib/rubocop/cop/space_after_comma_etc.rb",
|
59
|
-
"lib/rubocop/cop/string_literals.rb",
|
60
|
-
"lib/rubocop/cop/surrounding_space.rb",
|
61
|
-
"lib/rubocop/cop/syntax.rb",
|
62
|
-
"lib/rubocop/cop/tab.rb",
|
63
|
-
"lib/rubocop/cop/ternary_operator.rb",
|
64
|
-
"lib/rubocop/cop/trailing_whitespace.rb",
|
65
|
-
"lib/rubocop/cop/unless_else.rb",
|
66
|
-
"lib/rubocop/cop/when_then.rb",
|
67
|
-
"lib/rubocop/report/emacs_style.rb",
|
68
|
-
"lib/rubocop/report/plain_text.rb",
|
69
|
-
"lib/rubocop/report/report.rb",
|
70
|
-
"lib/rubocop/version.rb",
|
71
|
-
"rubocop.gemspec",
|
72
|
-
"spec/rubocop/cli_spec.rb",
|
73
|
-
"spec/rubocop/cops/align_parameters_spec.rb",
|
74
|
-
"spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb",
|
75
|
-
"spec/rubocop/cops/class_and_module_camel_case_spec.rb",
|
76
|
-
"spec/rubocop/cops/collection_methods_spec.rb",
|
77
|
-
"spec/rubocop/cops/cop_spec.rb",
|
78
|
-
"spec/rubocop/cops/def_with_parentheses_spec.rb",
|
79
|
-
"spec/rubocop/cops/def_without_parentheses_spec.rb",
|
80
|
-
"spec/rubocop/cops/empty_lines_spec.rb",
|
81
|
-
"spec/rubocop/cops/encoding_spec.rb",
|
82
|
-
"spec/rubocop/cops/end_of_line_spec.rb",
|
83
|
-
"spec/rubocop/cops/favor_modifier_spec.rb",
|
84
|
-
"spec/rubocop/cops/favor_unless_over_negated_if_spec.rb",
|
85
|
-
"spec/rubocop/cops/favor_until_over_negated_while_spec.rb",
|
86
|
-
"spec/rubocop/cops/grammar_spec.rb",
|
87
|
-
"spec/rubocop/cops/hash_syntax_spec.rb",
|
88
|
-
"spec/rubocop/cops/if_with_semicolon_spec.rb",
|
89
|
-
"spec/rubocop/cops/indentation_spec.rb",
|
90
|
-
"spec/rubocop/cops/line_length_spec.rb",
|
91
|
-
"spec/rubocop/cops/method_and_variable_snake_case_spec.rb",
|
92
|
-
"spec/rubocop/cops/multiline_blocks_spec.rb",
|
93
|
-
"spec/rubocop/cops/multiline_if_then_spec.rb",
|
94
|
-
"spec/rubocop/cops/new_lambda_literal_spec.rb",
|
95
|
-
"spec/rubocop/cops/numeric_literals_spec.rb",
|
96
|
-
"spec/rubocop/cops/offence_spec.rb",
|
97
|
-
"spec/rubocop/cops/one_line_conditional_spec.rb",
|
98
|
-
"spec/rubocop/cops/parameter_lists_spec.rb",
|
99
|
-
"spec/rubocop/cops/parentheses_around_condition_spec.rb",
|
100
|
-
"spec/rubocop/cops/single_line_blocks_spec.rb",
|
101
|
-
"spec/rubocop/cops/space_after_colon_spec.rb",
|
102
|
-
"spec/rubocop/cops/space_after_comma_spec.rb",
|
103
|
-
"spec/rubocop/cops/space_after_semicolon_spec.rb",
|
104
|
-
"spec/rubocop/cops/space_around_braces_spec.rb",
|
105
|
-
"spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb",
|
106
|
-
"spec/rubocop/cops/space_around_operators_spec.rb",
|
107
|
-
"spec/rubocop/cops/space_inside_brackets_spec.rb",
|
108
|
-
"spec/rubocop/cops/space_inside_parens_spec.rb",
|
109
|
-
"spec/rubocop/cops/string_literals_spec.rb",
|
110
|
-
"spec/rubocop/cops/syntax_spec.rb",
|
111
|
-
"spec/rubocop/cops/tab_spec.rb",
|
112
|
-
"spec/rubocop/cops/ternary_operator_spec.rb",
|
113
|
-
"spec/rubocop/cops/trailing_whitespace_spec.rb",
|
114
|
-
"spec/rubocop/cops/unless_else_spec.rb",
|
115
|
-
"spec/rubocop/cops/when_then_spec.rb",
|
116
|
-
"spec/rubocop/reports/emacs_style_spec.rb",
|
117
|
-
"spec/rubocop/reports/report_spec.rb",
|
118
|
-
"spec/spec_helper.rb"
|
119
|
-
]
|
120
|
-
s.homepage = "http://github.com/bbatsov/rubocop"
|
121
|
-
s.licenses = ["MIT"]
|
122
|
-
s.require_paths = ["lib"]
|
123
|
-
s.rubygems_version = "1.8.23"
|
124
|
-
s.summary = "Automatic Ruby code style checking tool."
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'rubocop'
|
9
|
+
s.version = Rubocop::Version::STRING
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.required_ruby_version = '>= 1.9.2'
|
12
|
+
s.authors = ['Bozhidar Batsov']
|
13
|
+
s.date = '2013-04-17'
|
14
|
+
s.description = <<-EOF
|
15
|
+
Automatic Ruby code style checking tool.
|
16
|
+
Aims to enforce the community-driven Ruby Style Guide.
|
17
|
+
EOF
|
125
18
|
|
126
|
-
|
127
|
-
|
19
|
+
s.email = 'bozhidar@batsov.com'
|
20
|
+
s.files = `git ls-files`.split($RS)
|
21
|
+
s.test_files = s.files.grep(/^spec\//)
|
22
|
+
s.executables = s.files.grep(/^bin\//) { |f| File.basename(f) }
|
23
|
+
s.extra_rdoc_files = ['LICENSE.txt', 'README.md']
|
24
|
+
s.homepage = 'http://github.com/bbatsov/rubocop'
|
25
|
+
s.licenses = ['MIT']
|
26
|
+
s.require_paths = ['lib']
|
27
|
+
s.rubygems_version = '1.8.23'
|
28
|
+
s.summary = 'Automatic Ruby code style checking tool.'
|
128
29
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
137
|
-
else
|
138
|
-
s.add_dependency(%q<term-ansicolor>, [">= 0"])
|
139
|
-
s.add_dependency(%q<rake>, [">= 0"])
|
140
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
141
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
142
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
143
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
144
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
145
|
-
end
|
146
|
-
else
|
147
|
-
s.add_dependency(%q<term-ansicolor>, [">= 0"])
|
148
|
-
s.add_dependency(%q<rake>, [">= 0"])
|
149
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
150
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
151
|
-
s.add_dependency(%q<bundler>, [">= 0"])
|
152
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
153
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
154
|
-
end
|
30
|
+
s.add_runtime_dependency('rainbow', '>= 1.1.4')
|
31
|
+
s.add_runtime_dependency('parser', '~> 2.0.0.beta2')
|
32
|
+
s.add_development_dependency('rake', '~> 10.0')
|
33
|
+
s.add_development_dependency('rspec', '~> 2.13')
|
34
|
+
s.add_development_dependency('yard', '~> 0.8')
|
35
|
+
s.add_development_dependency('bundler', '~> 1.3')
|
36
|
+
s.add_development_dependency('simplecov', '~> 0.7')
|
155
37
|
end
|
156
|
-
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'RuboCop Project' do
|
6
|
+
describe '.rubocop.yml' do
|
7
|
+
it 'has configuration for all cops' do
|
8
|
+
cop_names = Rubocop::Cop::Cop.all.map(&:cop_name)
|
9
|
+
expect(Rubocop::Config.load_file('.rubocop.yml').keys.sort)
|
10
|
+
.to eq((['AllCops'] + cop_names).sort)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'source codes', broken: true do
|
15
|
+
before { $stdout = StringIO.new }
|
16
|
+
after { $stdout = STDOUT }
|
17
|
+
|
18
|
+
it 'has no violations' do
|
19
|
+
# Need to pass an empty array explicitly
|
20
|
+
# so that the CLI does not refer arguments of `rspec`
|
21
|
+
Rubocop::CLI.new.run([])
|
22
|
+
expect($stdout.string).to match(
|
23
|
+
/files inspected, no offences detected\n/
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|