rubocop 0.16.0 → 0.17.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/.gitignore +1 -0
- data/.travis.yml +3 -1
- data/CHANGELOG.md +44 -0
- data/CONTRIBUTING.md +40 -8
- data/Gemfile +6 -0
- data/README.md +65 -20
- data/Rakefile +0 -1
- data/config/default.yml +15 -3
- data/config/enabled.yml +143 -109
- data/lib/rubocop.rb +45 -26
- data/lib/rubocop/cli.rb +26 -27
- data/lib/rubocop/config.rb +0 -1
- data/lib/rubocop/config_loader.rb +16 -23
- data/lib/rubocop/cop/commissioner.rb +2 -7
- data/lib/rubocop/cop/cop.rb +24 -51
- data/lib/rubocop/cop/ignored_node.rb +31 -0
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +50 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +36 -0
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +3 -11
- data/lib/rubocop/cop/lint/block_alignment.rb +6 -20
- data/lib/rubocop/cop/lint/condition_position.rb +52 -0
- data/lib/rubocop/cop/lint/else_layout.rb +57 -0
- data/lib/rubocop/cop/lint/end_alignment.rb +33 -8
- data/lib/rubocop/cop/lint/invalid_character_literal.rb +37 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +2 -4
- data/lib/rubocop/cop/lint/syntax.rb +6 -12
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +25 -0
- data/lib/rubocop/cop/mixin/array_syntax.rb +20 -0
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +76 -0
- data/lib/rubocop/cop/mixin/check_assignment.rb +26 -0
- data/lib/rubocop/cop/{check_methods.rb → mixin/check_methods.rb} +0 -0
- data/lib/rubocop/cop/mixin/code_length.rb +33 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +53 -0
- data/lib/rubocop/cop/mixin/configurable_max.rb +19 -0
- data/lib/rubocop/cop/mixin/configurable_naming.rb +45 -0
- data/lib/rubocop/cop/{style → mixin}/if_node.rb +0 -0
- data/lib/rubocop/cop/mixin/if_then_else.rb +23 -0
- data/lib/rubocop/cop/mixin/negative_conditional.rb +24 -0
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +34 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +19 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +32 -0
- data/lib/rubocop/cop/mixin/space_inside.rb +31 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +59 -0
- data/lib/rubocop/cop/mixin/string_help.rb +32 -0
- data/lib/rubocop/cop/mixin/surrounding_space.rb +42 -0
- data/lib/rubocop/cop/rails/default_scope.rb +3 -1
- data/lib/rubocop/cop/style/accessor_method_name.rb +4 -12
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +16 -1
- data/lib/rubocop/cop/style/case_indentation.rb +33 -16
- data/lib/rubocop/cop/style/character_literal.rb +10 -0
- data/lib/rubocop/cop/style/dot_position.rb +23 -6
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +5 -5
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +1 -32
- data/lib/rubocop/cop/style/favor_until_over_negated_while.rb +20 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +5 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +34 -0
- data/lib/rubocop/cop/style/if_with_semicolon.rb +1 -1
- data/lib/rubocop/cop/style/indentation_consistency.rb +51 -0
- data/lib/rubocop/cop/style/indentation_width.rb +0 -26
- data/lib/rubocop/cop/style/lambda_call.rb +12 -5
- data/lib/rubocop/cop/style/method_def_parentheses.rb +29 -11
- data/lib/rubocop/cop/style/multiline_if_then.rb +4 -9
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +22 -0
- data/lib/rubocop/cop/style/{ternary_operator.rb → nested_ternary_operator.rb} +0 -15
- data/lib/rubocop/cop/style/numeric_literals.rb +30 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -1
- data/lib/rubocop/cop/style/parameter_lists.rb +7 -3
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +9 -11
- data/lib/rubocop/cop/style/predicate_name.rb +4 -12
- data/lib/rubocop/cop/style/raise_args.rb +19 -11
- data/lib/rubocop/cop/style/regexp_literal.rb +19 -6
- data/lib/rubocop/cop/style/space_after_colon.rb +36 -0
- data/lib/rubocop/cop/style/space_after_comma.rb +16 -0
- data/lib/rubocop/cop/style/space_after_semicolon.rb +16 -0
- data/lib/rubocop/cop/style/space_around_block_braces.rb +38 -38
- data/lib/rubocop/cop/style/space_around_operators.rb +1 -2
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +6 -2
- data/lib/rubocop/cop/style/string_literals.rb +5 -5
- data/lib/rubocop/cop/style/trailing_comma.rb +94 -0
- data/lib/rubocop/cop/style/unless_else.rb +2 -2
- data/lib/rubocop/cop/style/while_until_modifier.rb +32 -0
- data/lib/rubocop/cop/style/word_array.rb +9 -1
- data/lib/rubocop/cop/util.rb +14 -0
- data/lib/rubocop/cop/variable_inspector.rb +11 -6
- data/lib/rubocop/cop/variable_inspector/scope.rb +4 -3
- data/lib/rubocop/file_inspector.rb +22 -6
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/colorizable.rb +37 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +27 -6
- data/lib/rubocop/formatter/progress_formatter.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +9 -5
- data/lib/rubocop/options.rb +19 -4
- data/lib/rubocop/target_finder.rb +4 -0
- data/lib/rubocop/version.rb +1 -1
- data/rubocop-todo.yml +10 -2
- data/rubocop.gemspec +3 -2
- data/spec/project_spec.rb +12 -7
- data/spec/rubocop/cli_spec.rb +262 -99
- data/spec/rubocop/config_loader_spec.rb +5 -5
- data/spec/rubocop/config_spec.rb +3 -3
- data/spec/rubocop/config_store_spec.rb +12 -11
- data/spec/rubocop/cop/commissioner_spec.rb +21 -5
- data/spec/rubocop/cop/cop_spec.rb +1 -1
- data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +113 -0
- data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +35 -0
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +2 -2
- data/spec/rubocop/cop/lint/condition_position_spec.rb +49 -0
- data/spec/rubocop/cop/lint/else_layout_spec.rb +65 -0
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +41 -1
- data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +33 -0
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +3 -3
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +12 -12
- data/spec/rubocop/cop/lint/syntax_spec.rb +2 -2
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +72 -54
- data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +48 -0
- data/spec/rubocop/cop/offence_spec.rb +1 -1
- data/spec/rubocop/cop/rails/default_scope_spec.rb +6 -0
- data/spec/rubocop/cop/rails/output_spec.rb +2 -1
- data/spec/rubocop/cop/style/align_hash_spec.rb +9 -9
- data/spec/rubocop/cop/style/align_parameters_spec.rb +1 -1
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +5 -0
- data/spec/rubocop/cop/style/case_indentation_spec.rb +53 -2
- data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +3 -3
- data/spec/rubocop/cop/style/documentation_spec.rb +0 -1
- data/spec/rubocop/cop/style/dot_position_spec.rb +18 -3
- data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +4 -4
- data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +13 -0
- data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +1 -1
- data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +1 -1
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +5 -0
- data/spec/rubocop/cop/style/{favor_modifier_spec.rb → if_unless_modifier_spec.rb} +4 -111
- data/spec/rubocop/cop/style/indentation_consistency_spec.rb +490 -0
- data/spec/rubocop/cop/style/indentation_width_spec.rb +19 -91
- data/spec/rubocop/cop/style/lambda_call_spec.rb +18 -0
- data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +2 -2
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +35 -1
- data/spec/rubocop/cop/style/method_length_spec.rb +1 -0
- data/spec/rubocop/cop/style/method_name_spec.rb +27 -5
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +4 -4
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +2 -2
- data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +18 -0
- data/spec/rubocop/cop/style/{ternary_operator_spec.rb → nested_ternary_operator_spec.rb} +0 -15
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +18 -1
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +2 -1
- data/spec/rubocop/cop/style/parameter_lists_spec.rb +1 -0
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +13 -4
- data/spec/rubocop/cop/style/raise_args_spec.rb +22 -0
- data/spec/rubocop/cop/style/redundant_self_spec.rb +4 -4
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +4 -0
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +12 -4
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +2 -2
- data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +30 -1
- data/spec/rubocop/cop/style/{space_around_equals_in_default_parameter_spec.rb → space_around_equals_in_parameter_default_spec.rb} +0 -0
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +2 -1
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +20 -3
- data/spec/rubocop/cop/style/string_literals_spec.rb +33 -0
- data/spec/rubocop/cop/style/trailing_comma_spec.rb +200 -0
- data/spec/rubocop/cop/style/variable_name_spec.rb +27 -3
- data/spec/rubocop/cop/style/while_until_modifier_spec.rb +75 -0
- data/spec/rubocop/cop/style/word_array_spec.rb +1 -0
- data/spec/rubocop/cop/team_spec.rb +1 -1
- data/spec/rubocop/cop/variable_inspector/scope_spec.rb +3 -4
- data/spec/rubocop/file_inspector_spec.rb +1 -1
- data/spec/rubocop/formatter/base_formatter_spec.rb +12 -11
- data/spec/rubocop/formatter/colorizable_spec.rb +107 -0
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +2 -0
- data/spec/rubocop/formatter/formatter_set_spec.rb +1 -1
- data/spec/rubocop/formatter/json_formatter_spec.rb +4 -3
- data/spec/rubocop/formatter/progress_formatter_spec.rb +2 -2
- data/spec/rubocop/options_spec.rb +3 -1
- data/spec/rubocop/target_finder_spec.rb +13 -11
- data/spec/spec_helper.rb +5 -1
- data/spec/support/shared_examples.rb +2 -2
- data/spec/support/statement_modifier_helper.rb +41 -0
- metadata +88 -30
- data/lib/rubocop/cop/check_assignment.rb +0 -43
- data/lib/rubocop/cop/style/array_syntax.rb +0 -22
- data/lib/rubocop/cop/style/autocorrect_alignment.rb +0 -78
- data/lib/rubocop/cop/style/code_length.rb +0 -35
- data/lib/rubocop/cop/style/configurable_enforced_style.rb +0 -51
- data/lib/rubocop/cop/style/configurable_max.rb +0 -17
- data/lib/rubocop/cop/style/configurable_naming.rb +0 -41
- data/lib/rubocop/cop/style/favor_modifier.rb +0 -118
- data/lib/rubocop/cop/style/if_then_else.rb +0 -27
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +0 -73
- data/lib/rubocop/cop/style/space_inside.rb +0 -33
- data/lib/rubocop/cop/style/string_help.rb +0 -30
- data/lib/rubocop/cop/style/surrounding_space.rb +0 -44
data/lib/rubocop.rb
CHANGED
@@ -7,8 +7,11 @@ require 'parser/current'
|
|
7
7
|
require 'ast/sexp'
|
8
8
|
require 'powerpack'
|
9
9
|
|
10
|
+
require 'rubocop/version'
|
11
|
+
|
10
12
|
require 'rubocop/cop/util'
|
11
13
|
require 'rubocop/cop/offence'
|
14
|
+
require 'rubocop/cop/ignored_node'
|
12
15
|
require 'rubocop/cop/cop'
|
13
16
|
require 'rubocop/cop/commissioner'
|
14
17
|
require 'rubocop/cop/corrector'
|
@@ -22,18 +25,39 @@ require 'rubocop/cop/variable_inspector/reference'
|
|
22
25
|
require 'rubocop/cop/variable_inspector/scope'
|
23
26
|
require 'rubocop/cop/variable_inspector/variable_table'
|
24
27
|
|
25
|
-
require 'rubocop/cop/
|
26
|
-
require 'rubocop/cop/
|
28
|
+
require 'rubocop/cop/mixin/array_syntax'
|
29
|
+
require 'rubocop/cop/mixin/autocorrect_alignment'
|
30
|
+
require 'rubocop/cop/mixin/check_assignment'
|
31
|
+
require 'rubocop/cop/mixin/check_methods'
|
32
|
+
require 'rubocop/cop/mixin/configurable_max'
|
33
|
+
require 'rubocop/cop/mixin/code_length'
|
34
|
+
require 'rubocop/cop/mixin/configurable_enforced_style'
|
35
|
+
require 'rubocop/cop/mixin/configurable_naming'
|
36
|
+
require 'rubocop/cop/mixin/if_node'
|
37
|
+
require 'rubocop/cop/mixin/if_then_else'
|
38
|
+
require 'rubocop/cop/mixin/negative_conditional'
|
39
|
+
require 'rubocop/cop/mixin/parser_diagnostic'
|
40
|
+
require 'rubocop/cop/mixin/safe_assignment'
|
41
|
+
require 'rubocop/cop/mixin/surrounding_space'
|
42
|
+
require 'rubocop/cop/mixin/space_inside'
|
43
|
+
require 'rubocop/cop/mixin/space_after_punctuation'
|
44
|
+
require 'rubocop/cop/mixin/statement_modifier'
|
45
|
+
require 'rubocop/cop/mixin/string_help'
|
27
46
|
|
47
|
+
require 'rubocop/cop/lint/ambiguous_operator'
|
48
|
+
require 'rubocop/cop/lint/ambiguous_regexp_literal'
|
28
49
|
require 'rubocop/cop/lint/assignment_in_condition'
|
29
50
|
require 'rubocop/cop/lint/block_alignment'
|
51
|
+
require 'rubocop/cop/lint/condition_position'
|
30
52
|
require 'rubocop/cop/lint/debugger'
|
53
|
+
require 'rubocop/cop/lint/else_layout'
|
31
54
|
require 'rubocop/cop/lint/empty_ensure'
|
32
55
|
require 'rubocop/cop/lint/end_alignment'
|
33
56
|
require 'rubocop/cop/lint/end_in_method'
|
34
57
|
require 'rubocop/cop/lint/ensure_return'
|
35
58
|
require 'rubocop/cop/lint/eval'
|
36
59
|
require 'rubocop/cop/lint/handle_exceptions'
|
60
|
+
require 'rubocop/cop/lint/invalid_character_literal'
|
37
61
|
require 'rubocop/cop/lint/literal_in_condition'
|
38
62
|
require 'rubocop/cop/lint/loop'
|
39
63
|
require 'rubocop/cop/lint/parentheses_as_grouped_expression'
|
@@ -43,16 +67,10 @@ require 'rubocop/cop/lint/syntax'
|
|
43
67
|
require 'rubocop/cop/lint/unreachable_code'
|
44
68
|
require 'rubocop/cop/lint/useless_assignment'
|
45
69
|
require 'rubocop/cop/lint/useless_comparison'
|
70
|
+
require 'rubocop/cop/lint/useless_else_without_rescue'
|
46
71
|
require 'rubocop/cop/lint/useless_setter_call'
|
47
72
|
require 'rubocop/cop/lint/void'
|
48
73
|
|
49
|
-
require 'rubocop/cop/style/autocorrect_alignment'
|
50
|
-
require 'rubocop/cop/style/configurable_enforced_style'
|
51
|
-
require 'rubocop/cop/style/configurable_max'
|
52
|
-
require 'rubocop/cop/style/configurable_naming'
|
53
|
-
require 'rubocop/cop/style/cyclomatic_complexity'
|
54
|
-
require 'rubocop/cop/style/string_help'
|
55
|
-
|
56
74
|
require 'rubocop/cop/style/access_modifier_indentation'
|
57
75
|
require 'rubocop/cop/style/accessor_method_name'
|
58
76
|
require 'rubocop/cop/style/alias'
|
@@ -60,7 +78,6 @@ require 'rubocop/cop/style/align_array'
|
|
60
78
|
require 'rubocop/cop/style/align_hash'
|
61
79
|
require 'rubocop/cop/style/align_parameters'
|
62
80
|
require 'rubocop/cop/style/and_or'
|
63
|
-
require 'rubocop/cop/style/array_syntax'
|
64
81
|
require 'rubocop/cop/style/ascii_comments'
|
65
82
|
require 'rubocop/cop/style/ascii_identifiers'
|
66
83
|
require 'rubocop/cop/style/attr'
|
@@ -68,11 +85,11 @@ require 'rubocop/cop/style/begin_block'
|
|
68
85
|
require 'rubocop/cop/style/block_comments'
|
69
86
|
require 'rubocop/cop/style/block_nesting'
|
70
87
|
require 'rubocop/cop/style/blocks'
|
88
|
+
require 'rubocop/cop/style/braces_around_hash_parameters'
|
71
89
|
require 'rubocop/cop/style/case_equality'
|
72
90
|
require 'rubocop/cop/style/case_indentation'
|
73
91
|
require 'rubocop/cop/style/character_literal'
|
74
92
|
require 'rubocop/cop/style/class_and_module_camel_case'
|
75
|
-
require 'rubocop/cop/style/code_length'
|
76
93
|
require 'rubocop/cop/style/class_length'
|
77
94
|
require 'rubocop/cop/style/class_methods'
|
78
95
|
require 'rubocop/cop/style/class_vars'
|
@@ -80,44 +97,47 @@ require 'rubocop/cop/style/collection_methods'
|
|
80
97
|
require 'rubocop/cop/style/colon_method_call'
|
81
98
|
require 'rubocop/cop/style/comment_annotation'
|
82
99
|
require 'rubocop/cop/style/constant_name'
|
100
|
+
require 'rubocop/cop/style/cyclomatic_complexity'
|
83
101
|
require 'rubocop/cop/style/def_parentheses'
|
84
102
|
require 'rubocop/cop/style/documentation'
|
85
103
|
require 'rubocop/cop/style/dot_position'
|
86
104
|
require 'rubocop/cop/style/empty_line_between_defs'
|
87
105
|
require 'rubocop/cop/style/empty_lines'
|
88
|
-
require 'rubocop/cop/style/empty_lines_around_body'
|
89
106
|
require 'rubocop/cop/style/empty_lines_around_access_modifier'
|
107
|
+
require 'rubocop/cop/style/empty_lines_around_body'
|
90
108
|
require 'rubocop/cop/style/empty_literal'
|
91
109
|
require 'rubocop/cop/style/encoding'
|
92
110
|
require 'rubocop/cop/style/end_block'
|
93
111
|
require 'rubocop/cop/style/end_of_line'
|
94
112
|
require 'rubocop/cop/style/even_odd'
|
95
113
|
require 'rubocop/cop/style/favor_join'
|
96
|
-
require 'rubocop/cop/style/if_node'
|
97
|
-
require 'rubocop/cop/style/favor_modifier'
|
98
114
|
require 'rubocop/cop/style/favor_sprintf'
|
99
115
|
require 'rubocop/cop/style/favor_unless_over_negated_if'
|
116
|
+
require 'rubocop/cop/style/favor_until_over_negated_while'
|
100
117
|
require 'rubocop/cop/style/final_newline'
|
101
118
|
require 'rubocop/cop/style/flip_flop'
|
102
119
|
require 'rubocop/cop/style/for'
|
103
120
|
require 'rubocop/cop/style/global_vars'
|
104
121
|
require 'rubocop/cop/style/hash_methods'
|
105
122
|
require 'rubocop/cop/style/hash_syntax'
|
106
|
-
require 'rubocop/cop/style/
|
123
|
+
require 'rubocop/cop/style/if_unless_modifier'
|
107
124
|
require 'rubocop/cop/style/if_with_semicolon'
|
125
|
+
require 'rubocop/cop/style/indentation_consistency'
|
108
126
|
require 'rubocop/cop/style/indentation_width'
|
109
127
|
require 'rubocop/cop/style/lambda'
|
110
128
|
require 'rubocop/cop/style/lambda_call'
|
111
129
|
require 'rubocop/cop/style/leading_comment_space'
|
112
130
|
require 'rubocop/cop/style/line_length'
|
113
|
-
require 'rubocop/cop/style/method_def_parentheses'
|
114
131
|
require 'rubocop/cop/style/method_call_parentheses'
|
115
132
|
require 'rubocop/cop/style/method_called_on_do_end_block'
|
133
|
+
require 'rubocop/cop/style/method_def_parentheses'
|
116
134
|
require 'rubocop/cop/style/method_length'
|
117
135
|
require 'rubocop/cop/style/method_name'
|
118
136
|
require 'rubocop/cop/style/module_function'
|
119
137
|
require 'rubocop/cop/style/multiline_block_chain'
|
120
138
|
require 'rubocop/cop/style/multiline_if_then'
|
139
|
+
require 'rubocop/cop/style/multiline_ternary_operator'
|
140
|
+
require 'rubocop/cop/style/nested_ternary_operator'
|
121
141
|
require 'rubocop/cop/style/nil_comparison'
|
122
142
|
require 'rubocop/cop/style/not'
|
123
143
|
require 'rubocop/cop/style/numeric_literals'
|
@@ -139,25 +159,25 @@ require 'rubocop/cop/style/semicolon'
|
|
139
159
|
require 'rubocop/cop/style/signal_exception'
|
140
160
|
require 'rubocop/cop/style/single_line_block_params'
|
141
161
|
require 'rubocop/cop/style/single_line_methods'
|
142
|
-
require 'rubocop/cop/style/
|
162
|
+
require 'rubocop/cop/style/space_after_colon'
|
163
|
+
require 'rubocop/cop/style/space_after_comma'
|
143
164
|
require 'rubocop/cop/style/space_after_control_keyword'
|
144
165
|
require 'rubocop/cop/style/space_after_method_name'
|
145
166
|
require 'rubocop/cop/style/space_after_not'
|
146
|
-
require 'rubocop/cop/style/
|
147
|
-
require 'rubocop/cop/style/space_before_modifier_keyword'
|
148
|
-
require 'rubocop/cop/style/string_literals'
|
149
|
-
require 'rubocop/cop/style/surrounding_space'
|
167
|
+
require 'rubocop/cop/style/space_after_semicolon'
|
150
168
|
require 'rubocop/cop/style/space_around_block_braces'
|
151
169
|
require 'rubocop/cop/style/space_around_equals_in_parameter_default'
|
152
170
|
require 'rubocop/cop/style/space_around_operators'
|
153
|
-
require 'rubocop/cop/style/
|
154
|
-
require 'rubocop/cop/style/space_inside_hash_literal_braces'
|
171
|
+
require 'rubocop/cop/style/space_before_modifier_keyword'
|
155
172
|
require 'rubocop/cop/style/space_inside_brackets'
|
173
|
+
require 'rubocop/cop/style/space_inside_hash_literal_braces'
|
156
174
|
require 'rubocop/cop/style/space_inside_parens'
|
175
|
+
require 'rubocop/cop/style/special_global_vars'
|
176
|
+
require 'rubocop/cop/style/string_literals'
|
157
177
|
require 'rubocop/cop/style/symbol_array'
|
158
178
|
require 'rubocop/cop/style/tab'
|
159
|
-
require 'rubocop/cop/style/ternary_operator'
|
160
179
|
require 'rubocop/cop/style/trailing_blank_lines'
|
180
|
+
require 'rubocop/cop/style/trailing_comma'
|
161
181
|
require 'rubocop/cop/style/trailing_whitespace'
|
162
182
|
require 'rubocop/cop/style/trivial_accessors'
|
163
183
|
require 'rubocop/cop/style/unless_else'
|
@@ -165,8 +185,8 @@ require 'rubocop/cop/style/variable_interpolation'
|
|
165
185
|
require 'rubocop/cop/style/variable_name'
|
166
186
|
require 'rubocop/cop/style/when_then'
|
167
187
|
require 'rubocop/cop/style/while_until_do'
|
188
|
+
require 'rubocop/cop/style/while_until_modifier'
|
168
189
|
require 'rubocop/cop/style/word_array'
|
169
|
-
require 'rubocop/cop/style/braces_around_hash_parameters'
|
170
190
|
|
171
191
|
require 'rubocop/cop/rails/default_scope'
|
172
192
|
require 'rubocop/cop/rails/has_and_belongs_to_many'
|
@@ -195,4 +215,3 @@ require 'rubocop/source_parser'
|
|
195
215
|
require 'rubocop/file_inspector'
|
196
216
|
require 'rubocop/cli'
|
197
217
|
require 'rubocop/options'
|
198
|
-
require 'rubocop/version'
|
data/lib/rubocop/cli.rb
CHANGED
@@ -57,47 +57,46 @@ module Rubocop
|
|
57
57
|
end
|
58
58
|
|
59
59
|
ConfigLoader.debug = @options[:debug]
|
60
|
+
ConfigLoader.auto_gen_config = @options[:auto_gen_config]
|
60
61
|
|
61
62
|
@config_store.options_config = @options[:config] if @options[:config]
|
62
63
|
|
63
|
-
|
64
|
+
Rainbow.enabled = false unless @options[:color]
|
64
65
|
|
65
66
|
puts Rubocop::Version.version(false) if @options[:version]
|
66
67
|
puts Rubocop::Version.version(true) if @options[:verbose_version]
|
67
68
|
exit(0) if @options[:version] || @options[:verbose_version]
|
68
|
-
|
69
|
-
if @options[:auto_gen_config]
|
70
|
-
target_finder.find(args).each do |file|
|
71
|
-
config = @config_store.for(file)
|
72
|
-
if config.contains_auto_generated_config
|
73
|
-
fail "Remove #{ConfigLoader::AUTO_GENERATED_FILE} from the " +
|
74
|
-
'current configuration before generating it again.'
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
69
|
end
|
79
70
|
|
80
71
|
def print_available_cops
|
81
72
|
cops = Cop::Cop.all
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
puts "Type '#{type.to_s.capitalize}' (#{coptypes.size}):"
|
87
|
-
coptypes.each do |cop|
|
88
|
-
puts " - #{cop.cop_name}"
|
89
|
-
cnf = dirconf.for_cop(cop).dup
|
90
|
-
print_conf_option('Description',
|
91
|
-
cnf.delete('Description') { 'None' })
|
92
|
-
cnf.each { |k, v| print_conf_option(k, v) }
|
93
|
-
print_conf_option('SupportsAutoCorrection',
|
94
|
-
cop.new.support_autocorrect?.to_s)
|
95
|
-
end
|
73
|
+
show_all = @options[:show_cops].empty?
|
74
|
+
|
75
|
+
if show_all
|
76
|
+
puts "# Available cops (#{cops.length}) + config for #{Dir.pwd.to_s}: "
|
96
77
|
end
|
78
|
+
|
79
|
+
cops.types.sort!.each { |type| print_cops_of_type(cops, type, show_all) }
|
97
80
|
end
|
98
81
|
|
99
|
-
def
|
100
|
-
|
82
|
+
def print_cops_of_type(cops, type, show_all)
|
83
|
+
cops_of_this_type = cops.with_type(type).sort_by!(&:cop_name)
|
84
|
+
|
85
|
+
if show_all
|
86
|
+
puts "# Type '#{type.to_s.capitalize}' (#{cops_of_this_type.size}):"
|
87
|
+
end
|
88
|
+
|
89
|
+
selected_cops = cops_of_this_type.select do |cop|
|
90
|
+
show_all || @options[:show_cops].include?(cop.cop_name)
|
91
|
+
end
|
92
|
+
|
93
|
+
selected_cops.each do |cop|
|
94
|
+
puts '# Supports --auto-correct' if cop.new.support_autocorrect?
|
95
|
+
puts "#{cop.cop_name}:"
|
96
|
+
cnf = @config_store.for(Dir.pwd.to_s).for_cop(cop)
|
97
|
+
puts cnf.to_yaml.lines.to_a[1..-1].map { |line| ' ' + line }
|
98
|
+
puts
|
99
|
+
end
|
101
100
|
end
|
102
101
|
|
103
102
|
def target_finder
|
data/lib/rubocop/config.rb
CHANGED
@@ -16,26 +16,22 @@ module Rubocop
|
|
16
16
|
AUTO_GENERATED_FILE = 'rubocop-todo.yml'
|
17
17
|
|
18
18
|
class << self
|
19
|
-
attr_accessor :debug
|
19
|
+
attr_accessor :debug, :auto_gen_config
|
20
20
|
attr_writer :root_level # The upwards search is stopped at this level.
|
21
|
+
|
21
22
|
alias_method :debug?, :debug
|
23
|
+
alias_method :auto_gen_config?, :auto_gen_config
|
22
24
|
|
23
25
|
def load_file(path)
|
24
26
|
path = File.absolute_path(path)
|
25
27
|
hash = YAML.load_file(path) || {}
|
26
28
|
puts "configuration from #{path}" if debug?
|
27
|
-
contains_auto_generated_config = false
|
28
29
|
|
29
|
-
resolve_inheritance(path, hash)
|
30
|
-
if base_config.loaded_path.include?(AUTO_GENERATED_FILE)
|
31
|
-
contains_auto_generated_config = true
|
32
|
-
end
|
33
|
-
end
|
30
|
+
resolve_inheritance(path, hash)
|
34
31
|
|
35
32
|
hash.delete('inherit_from')
|
36
33
|
config = Config.new(hash, path)
|
37
34
|
config.warn_unless_valid
|
38
|
-
config.contains_auto_generated_config = contains_auto_generated_config
|
39
35
|
config
|
40
36
|
end
|
41
37
|
|
@@ -73,6 +69,10 @@ module Rubocop
|
|
73
69
|
def base_configs(path, inherit_from)
|
74
70
|
Array(inherit_from).map do |f|
|
75
71
|
f = File.join(File.dirname(path), f) unless f.start_with?('/')
|
72
|
+
if auto_gen_config? && f.include?(AUTO_GENERATED_FILE)
|
73
|
+
fail "Remove #{AUTO_GENERATED_FILE} from the current " +
|
74
|
+
'configuration before generating it again.'
|
75
|
+
end
|
76
76
|
print 'Inheriting ' if debug?
|
77
77
|
load_file(f)
|
78
78
|
end
|
@@ -89,6 +89,8 @@ module Rubocop
|
|
89
89
|
|
90
90
|
def configuration_from_file(config_file)
|
91
91
|
config = load_file(config_file)
|
92
|
+
return config if config_file == DEFAULT_FILE
|
93
|
+
|
92
94
|
found_files = config_files_in_path(config_file)
|
93
95
|
if found_files.any? && found_files.last != config_file
|
94
96
|
print 'AllCops/Excludes ' if debug?
|
@@ -101,14 +103,13 @@ module Rubocop
|
|
101
103
|
def add_excludes_from_higher_level(config, highest_config)
|
102
104
|
if highest_config['AllCops'] && highest_config['AllCops']['Excludes']
|
103
105
|
config['AllCops'] ||= {}
|
104
|
-
config['AllCops']['Excludes'] ||= []
|
106
|
+
excludes = config['AllCops']['Excludes'] ||= []
|
105
107
|
highest_config['AllCops']['Excludes'].each do |path|
|
106
108
|
unless path.is_a?(Regexp) || path.start_with?('/')
|
107
109
|
path = File.join(File.dirname(highest_config.loaded_path), path)
|
108
110
|
end
|
109
|
-
|
111
|
+
excludes << path unless excludes.include?(path)
|
110
112
|
end
|
111
|
-
config['AllCops']['Excludes'].uniq!
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
@@ -120,10 +121,7 @@ module Rubocop
|
|
120
121
|
end
|
121
122
|
|
122
123
|
def merge_with_default(config, config_file)
|
123
|
-
|
124
|
-
result.contains_auto_generated_config =
|
125
|
-
config.contains_auto_generated_config
|
126
|
-
result
|
124
|
+
Config.new(merge(default_configuration, config), config_file)
|
127
125
|
end
|
128
126
|
|
129
127
|
private
|
@@ -133,12 +131,9 @@ module Rubocop
|
|
133
131
|
if File.basename(base_config.loaded_path) == DOTFILE
|
134
132
|
make_excludes_absolute(base_config)
|
135
133
|
end
|
136
|
-
base_config.each do |
|
137
|
-
if
|
138
|
-
hash[key] = hash.key?(key) ? merge(value, hash[key]) : value
|
139
|
-
end
|
134
|
+
base_config.each do |k, v|
|
135
|
+
hash[k] = hash.key?(k) ? merge(v, hash[k]) : v if v.is_a?(Hash)
|
140
136
|
end
|
141
|
-
yield base_config
|
142
137
|
end
|
143
138
|
end
|
144
139
|
|
@@ -151,13 +146,11 @@ module Rubocop
|
|
151
146
|
|
152
147
|
def dirs_to_search(target_dir)
|
153
148
|
dirs_to_search = []
|
154
|
-
|
155
|
-
target_dir_pathname.ascend do |dir_pathname|
|
149
|
+
Pathname.new(File.expand_path(target_dir)).ascend do |dir_pathname|
|
156
150
|
break if dir_pathname.to_s == @root_level
|
157
151
|
dirs_to_search << dir_pathname.to_s
|
158
152
|
end
|
159
153
|
dirs_to_search << Dir.home
|
160
|
-
dirs_to_search
|
161
154
|
end
|
162
155
|
end
|
163
156
|
end
|
@@ -54,15 +54,10 @@ module Rubocop
|
|
54
54
|
prepare(processed_source)
|
55
55
|
invoke_cops_callback(processed_source)
|
56
56
|
process(processed_source.ast) if processed_source.ast
|
57
|
-
@cops.
|
57
|
+
@cops.each_with_object([]) do |cop, offences|
|
58
58
|
filename = processed_source.buffer.name
|
59
59
|
# ignore files that are of no interest to the cop in question
|
60
|
-
if cop.relevant_file?(filename)
|
61
|
-
offences.concat(cop.offences)
|
62
|
-
offences
|
63
|
-
else
|
64
|
-
[]
|
65
|
-
end
|
60
|
+
offences.concat(cop.offences) if cop.relevant_file?(filename)
|
66
61
|
end
|
67
62
|
end
|
68
63
|
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -45,13 +45,7 @@ module Rubocop
|
|
45
45
|
class Cop
|
46
46
|
extend AST::Sexp
|
47
47
|
include Util
|
48
|
-
|
49
|
-
# http://phrogz.net/programmingruby/language.html#table_18.4
|
50
|
-
# Backtick is added last just to help editors parse this code.
|
51
|
-
OPERATOR_METHODS = %w(
|
52
|
-
| ^ & <=> == === =~ > >= < <= << >>
|
53
|
-
+ - * / % ** ~ +@ -@ [] []= ! != !~
|
54
|
-
).map(&:to_sym) + [:'`']
|
48
|
+
include IgnoredNode
|
55
49
|
|
56
50
|
attr_reader :config, :offences, :corrections
|
57
51
|
attr_accessor :processed_source # TODO: Bad design.
|
@@ -78,10 +72,6 @@ module Rubocop
|
|
78
72
|
name.to_s.split('::')[-2].downcase.to_sym
|
79
73
|
end
|
80
74
|
|
81
|
-
def self.style?
|
82
|
-
cop_type == :style
|
83
|
-
end
|
84
|
-
|
85
75
|
def self.lint?
|
86
76
|
cop_type == :lint
|
87
77
|
end
|
@@ -96,7 +86,6 @@ module Rubocop
|
|
96
86
|
|
97
87
|
@offences = []
|
98
88
|
@corrections = []
|
99
|
-
@ignored_nodes = []
|
100
89
|
end
|
101
90
|
|
102
91
|
def cop_config
|
@@ -111,6 +100,10 @@ module Rubocop
|
|
111
100
|
@options[:debug]
|
112
101
|
end
|
113
102
|
|
103
|
+
def display_cop_names?
|
104
|
+
debug? || @options[:display_cop_names]
|
105
|
+
end
|
106
|
+
|
114
107
|
def message(node = nil)
|
115
108
|
self.class::MSG
|
116
109
|
end
|
@@ -127,7 +120,7 @@ module Rubocop
|
|
127
120
|
severity = custom_severity || severity || default_severity
|
128
121
|
|
129
122
|
message = message ? message : message(node)
|
130
|
-
message =
|
123
|
+
message = display_cop_names? ? "#{name}: #{message}" : message
|
131
124
|
|
132
125
|
corrected = begin
|
133
126
|
autocorrect(node) if autocorrect?
|
@@ -154,32 +147,12 @@ module Rubocop
|
|
154
147
|
|
155
148
|
alias_method :name, :cop_name
|
156
149
|
|
157
|
-
def ignore_node(node)
|
158
|
-
@ignored_nodes << node
|
159
|
-
end
|
160
|
-
|
161
|
-
def include_paths
|
162
|
-
cop_config && cop_config['Include']
|
163
|
-
end
|
164
|
-
|
165
150
|
def include_file?(file)
|
166
|
-
|
167
|
-
|
168
|
-
include_paths.any? do |regex|
|
169
|
-
processed_source.buffer.name =~ /#{regex}/
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def exclude_paths
|
174
|
-
cop_config && cop_config['Exclude']
|
151
|
+
buffer_name_matches_any?('Include', true)
|
175
152
|
end
|
176
153
|
|
177
154
|
def exclude_file?(file)
|
178
|
-
|
179
|
-
|
180
|
-
exclude_paths.any? do |regex|
|
181
|
-
processed_source.buffer.name =~ /#{regex}/
|
182
|
-
end
|
155
|
+
buffer_name_matches_any?('Exclude', false)
|
183
156
|
end
|
184
157
|
|
185
158
|
def relevant_file?(file)
|
@@ -188,27 +161,27 @@ module Rubocop
|
|
188
161
|
|
189
162
|
private
|
190
163
|
|
191
|
-
def
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
disabled_lines.include?(line_number)
|
164
|
+
def buffer_name_matches_any?(parameter, default_result)
|
165
|
+
paths = cop_config && cop_config[parameter]
|
166
|
+
return default_result unless paths
|
167
|
+
paths.any? { |path| match_path?(path, processed_source.buffer.name) }
|
196
168
|
end
|
197
169
|
|
198
|
-
def
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
170
|
+
def match_path?(pattern, path)
|
171
|
+
case pattern
|
172
|
+
when String
|
173
|
+
basename = File.basename(path)
|
174
|
+
basename == pattern || File.fnmatch(pattern, basename)
|
175
|
+
when Regexp
|
176
|
+
path =~ pattern
|
205
177
|
end
|
206
|
-
|
207
|
-
false
|
208
178
|
end
|
209
179
|
|
210
|
-
def
|
211
|
-
|
180
|
+
def disabled_line?(line_number)
|
181
|
+
return false unless @processed_source
|
182
|
+
disabled_lines = @processed_source.disabled_lines_for_cops[name]
|
183
|
+
return false unless disabled_lines
|
184
|
+
disabled_lines.include?(line_number)
|
212
185
|
end
|
213
186
|
|
214
187
|
def default_severity
|