rubocop 0.15.0 → 0.16.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/.rubocop.yml +1 -10
- data/.travis.yml +2 -1
- data/CHANGELOG.md +55 -0
- data/Gemfile +3 -0
- data/README.md +37 -0
- data/config/default.yml +99 -16
- data/config/enabled.yml +28 -16
- data/lib/rubocop.rb +16 -2
- data/lib/rubocop/cli.rb +10 -91
- data/lib/rubocop/config.rb +4 -1
- data/lib/rubocop/config_loader.rb +18 -10
- data/lib/rubocop/config_store.rb +3 -2
- data/lib/rubocop/cop/check_assignment.rb +43 -0
- data/lib/rubocop/cop/check_methods.rb +18 -0
- data/lib/rubocop/cop/commissioner.rb +15 -3
- data/lib/rubocop/cop/cop.rb +51 -43
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +7 -7
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/end_alignment.rb +56 -19
- data/lib/rubocop/cop/lint/end_in_method.rb +4 -10
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/eval.rb +1 -1
- data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +2 -2
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -2
- data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +6 -16
- data/lib/rubocop/cop/lint/void.rb +5 -5
- data/lib/rubocop/cop/rails/default_scope.rb +33 -0
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +2 -4
- data/lib/rubocop/cop/rails/output.rb +1 -1
- data/lib/rubocop/cop/rails/read_attribute.rb +1 -1
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +31 -16
- data/lib/rubocop/cop/style/accessor_method_name.rb +53 -0
- data/lib/rubocop/cop/style/alias.rb +14 -2
- data/lib/rubocop/cop/style/align_hash.rb +15 -16
- data/lib/rubocop/cop/style/and_or.rb +3 -3
- data/lib/rubocop/cop/style/array_syntax.rb +22 -0
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/ascii_identifiers.rb +1 -3
- data/lib/rubocop/cop/style/attr.rb +1 -1
- data/lib/rubocop/cop/style/autocorrect_alignment.rb +13 -12
- data/lib/rubocop/cop/style/begin_block.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_nesting.rb +5 -1
- data/lib/rubocop/cop/style/blocks.rb +4 -4
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +48 -22
- data/lib/rubocop/cop/style/case_equality.rb +1 -1
- data/lib/rubocop/cop/style/case_indentation.rb +25 -6
- data/lib/rubocop/cop/style/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/style/class_length.rb +7 -19
- data/lib/rubocop/cop/style/class_methods.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +1 -1
- data/lib/rubocop/cop/style/code_length.rb +35 -0
- data/lib/rubocop/cop/style/collection_methods.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
- data/lib/rubocop/cop/style/configurable_enforced_style.rb +51 -0
- data/lib/rubocop/cop/style/configurable_max.rb +17 -0
- data/lib/rubocop/cop/style/configurable_naming.rb +4 -10
- data/lib/rubocop/cop/style/constant_name.rb +5 -3
- data/lib/rubocop/cop/style/cyclomatic_complexity.rb +8 -13
- data/lib/rubocop/cop/style/def_parentheses.rb +4 -43
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/dot_position.rb +6 -2
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines.rb +5 -1
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +28 -13
- data/lib/rubocop/cop/style/empty_literal.rb +3 -3
- data/lib/rubocop/cop/style/encoding.rb +5 -5
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/end_of_line.rb +8 -6
- data/lib/rubocop/cop/style/even_odd.rb +6 -6
- data/lib/rubocop/cop/style/favor_join.rb +1 -1
- data/lib/rubocop/cop/style/favor_modifier.rb +20 -34
- data/lib/rubocop/cop/style/favor_sprintf.rb +1 -1
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +1 -1
- data/lib/rubocop/cop/style/final_newline.rb +1 -1
- data/lib/rubocop/cop/style/flip_flop.rb +20 -0
- data/lib/rubocop/cop/style/for.rb +34 -3
- data/lib/rubocop/cop/style/global_vars.rb +1 -1
- data/lib/rubocop/cop/style/hash_methods.rb +3 -3
- data/lib/rubocop/cop/style/hash_syntax.rb +8 -11
- data/lib/rubocop/cop/style/if_node.rb +25 -0
- data/lib/rubocop/cop/style/if_then_else.rb +1 -1
- data/lib/rubocop/cop/style/indentation_width.rb +77 -43
- data/lib/rubocop/cop/style/lambda.rb +2 -2
- data/lib/rubocop/cop/style/lambda_call.rb +4 -12
- data/lib/rubocop/cop/style/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/style/line_length.rb +9 -5
- data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -1
- data/lib/rubocop/cop/style/method_def_parentheses.rb +52 -0
- data/lib/rubocop/cop/style/method_length.rb +9 -22
- data/lib/rubocop/cop/style/module_function.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +11 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +2 -2
- data/lib/rubocop/cop/style/op_method.rb +2 -2
- data/lib/rubocop/cop/style/parameter_lists.rb +2 -2
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/predicate_name.rb +54 -0
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +4 -10
- data/lib/rubocop/cop/style/redundant_begin.rb +5 -15
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +9 -19
- data/lib/rubocop/cop/style/redundant_self.rb +8 -3
- data/lib/rubocop/cop/style/regexp_literal.rb +4 -3
- data/lib/rubocop/cop/style/rescue_modifier.rb +9 -17
- data/lib/rubocop/cop/style/semicolon.rb +20 -22
- data/lib/rubocop/cop/style/signal_exception.rb +10 -17
- data/lib/rubocop/cop/style/single_line_block_params.rb +62 -0
- data/lib/rubocop/cop/style/single_line_methods.rb +5 -15
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +1 -3
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -1
- data/lib/rubocop/cop/style/space_after_method_name.rb +4 -12
- data/lib/rubocop/cop/style/space_after_not.rb +1 -1
- data/lib/rubocop/cop/style/space_around_block_braces.rb +105 -94
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +1 -1
- data/lib/rubocop/cop/style/space_around_operators.rb +38 -123
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +1 -1
- data/lib/rubocop/cop/style/space_inside.rb +1 -3
- data/lib/rubocop/cop/style/space_inside_brackets.rb +0 -2
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +5 -5
- data/lib/rubocop/cop/style/space_inside_parens.rb +0 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/string_help.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +4 -11
- data/lib/rubocop/cop/style/surrounding_space.rb +0 -2
- data/lib/rubocop/cop/style/symbol_array.rb +3 -10
- data/lib/rubocop/cop/style/tab.rb +5 -5
- data/lib/rubocop/cop/style/ternary_operator.rb +2 -2
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +1 -1
- data/lib/rubocop/cop/style/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +4 -14
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +3 -1
- data/lib/rubocop/cop/style/while_until_do.rb +2 -2
- data/lib/rubocop/cop/style/word_array.rb +4 -10
- data/lib/rubocop/cop/util.rb +85 -12
- data/lib/rubocop/cop/variable_inspector.rb +4 -2
- data/lib/rubocop/file_inspector.rb +98 -0
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/disabled_config_formatter.rb +10 -2
- data/lib/rubocop/rake_task.rb +5 -1
- data/lib/rubocop/target_finder.rb +3 -3
- data/lib/rubocop/version.rb +1 -1
- data/rubocop-todo.yml +12 -0
- data/rubocop.gemspec +1 -1
- data/spec/isolated_environment_spec.rb +24 -0
- data/spec/rubocop/cli_spec.rb +120 -27
- data/spec/rubocop/config_loader_spec.rb +25 -11
- data/spec/rubocop/config_spec.rb +25 -9
- data/spec/rubocop/config_store_spec.rb +1 -1
- data/spec/rubocop/cop/cop_spec.rb +22 -3
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +4 -4
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +79 -47
- data/spec/rubocop/cop/lint/syntax_spec.rb +4 -3
- data/spec/rubocop/cop/rails/default_scope_spec.rb +31 -0
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +37 -2
- data/spec/rubocop/cop/style/accessor_method_name_spec.rb +81 -0
- data/spec/rubocop/cop/style/alias_spec.rb +10 -0
- data/spec/rubocop/cop/style/align_parameters_spec.rb +3 -3
- data/spec/rubocop/cop/style/block_nesting_spec.rb +4 -1
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +83 -0
- data/spec/rubocop/cop/style/case_indentation_spec.rb +227 -71
- data/spec/rubocop/cop/style/class_length_spec.rb +2 -0
- data/spec/rubocop/cop/style/constant_name_spec.rb +6 -0
- data/spec/rubocop/cop/style/cyclomatic_complexity_spec.rb +1 -0
- data/spec/rubocop/cop/style/documentation_spec.rb +12 -0
- data/spec/rubocop/cop/style/dot_position_spec.rb +10 -0
- data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +22 -0
- data/spec/rubocop/cop/style/empty_lines_spec.rb +6 -0
- data/spec/rubocop/cop/style/end_of_line_spec.rb +17 -0
- data/spec/rubocop/cop/style/favor_modifier_spec.rb +15 -0
- data/spec/rubocop/cop/style/flip_flop_spec.rb +23 -0
- data/spec/rubocop/cop/style/for_spec.rb +96 -18
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +8 -2
- data/spec/rubocop/cop/style/indentation_width_spec.rb +185 -20
- data/spec/rubocop/cop/style/line_length_spec.rb +1 -0
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +72 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +16 -0
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +34 -3
- data/spec/rubocop/cop/style/predicate_name_spec.rb +25 -0
- data/spec/rubocop/cop/style/redundant_self_spec.rb +15 -0
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +5 -0
- data/spec/rubocop/cop/style/semicolon_spec.rb +16 -16
- data/spec/rubocop/cop/style/{reduce_arguments_spec.rb → single_line_block_params_spec.rb} +12 -4
- data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +58 -8
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +71 -0
- data/spec/rubocop/cop/style/string_literals_spec.rb +18 -0
- data/spec/rubocop/file_inspector_spec.rb +78 -0
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +7 -7
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +3 -3
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +2 -2
- data/spec/rubocop/processed_source_spec.rb +7 -3
- data/spec/rubocop/token_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -2
- data/spec/support/isolated_environment.rb +7 -0
- data/spec/support/shared_context.rb +5 -1
- metadata +35 -12
- data/lib/rubocop/cop/style/reduce_arguments.rb +0 -34
- data/lib/rubocop/cop/style/symbol_name.rb +0 -45
- data/spec/rubocop/cop/style/def_without_parentheses_spec.rb +0 -33
- data/spec/rubocop/cop/style/symbol_name_spec.rb +0 -138
data/lib/rubocop.rb
CHANGED
@@ -22,6 +22,9 @@ require 'rubocop/cop/variable_inspector/reference'
|
|
22
22
|
require 'rubocop/cop/variable_inspector/scope'
|
23
23
|
require 'rubocop/cop/variable_inspector/variable_table'
|
24
24
|
|
25
|
+
require 'rubocop/cop/check_assignment'
|
26
|
+
require 'rubocop/cop/check_methods'
|
27
|
+
|
25
28
|
require 'rubocop/cop/lint/assignment_in_condition'
|
26
29
|
require 'rubocop/cop/lint/block_alignment'
|
27
30
|
require 'rubocop/cop/lint/debugger'
|
@@ -44,15 +47,20 @@ require 'rubocop/cop/lint/useless_setter_call'
|
|
44
47
|
require 'rubocop/cop/lint/void'
|
45
48
|
|
46
49
|
require 'rubocop/cop/style/autocorrect_alignment'
|
50
|
+
require 'rubocop/cop/style/configurable_enforced_style'
|
51
|
+
require 'rubocop/cop/style/configurable_max'
|
47
52
|
require 'rubocop/cop/style/configurable_naming'
|
48
53
|
require 'rubocop/cop/style/cyclomatic_complexity'
|
49
54
|
require 'rubocop/cop/style/string_help'
|
55
|
+
|
50
56
|
require 'rubocop/cop/style/access_modifier_indentation'
|
57
|
+
require 'rubocop/cop/style/accessor_method_name'
|
51
58
|
require 'rubocop/cop/style/alias'
|
52
59
|
require 'rubocop/cop/style/align_array'
|
53
60
|
require 'rubocop/cop/style/align_hash'
|
54
61
|
require 'rubocop/cop/style/align_parameters'
|
55
62
|
require 'rubocop/cop/style/and_or'
|
63
|
+
require 'rubocop/cop/style/array_syntax'
|
56
64
|
require 'rubocop/cop/style/ascii_comments'
|
57
65
|
require 'rubocop/cop/style/ascii_identifiers'
|
58
66
|
require 'rubocop/cop/style/attr'
|
@@ -64,6 +72,7 @@ require 'rubocop/cop/style/case_equality'
|
|
64
72
|
require 'rubocop/cop/style/case_indentation'
|
65
73
|
require 'rubocop/cop/style/character_literal'
|
66
74
|
require 'rubocop/cop/style/class_and_module_camel_case'
|
75
|
+
require 'rubocop/cop/style/code_length'
|
67
76
|
require 'rubocop/cop/style/class_length'
|
68
77
|
require 'rubocop/cop/style/class_methods'
|
69
78
|
require 'rubocop/cop/style/class_vars'
|
@@ -84,10 +93,12 @@ require 'rubocop/cop/style/end_block'
|
|
84
93
|
require 'rubocop/cop/style/end_of_line'
|
85
94
|
require 'rubocop/cop/style/even_odd'
|
86
95
|
require 'rubocop/cop/style/favor_join'
|
96
|
+
require 'rubocop/cop/style/if_node'
|
87
97
|
require 'rubocop/cop/style/favor_modifier'
|
88
98
|
require 'rubocop/cop/style/favor_sprintf'
|
89
99
|
require 'rubocop/cop/style/favor_unless_over_negated_if'
|
90
100
|
require 'rubocop/cop/style/final_newline'
|
101
|
+
require 'rubocop/cop/style/flip_flop'
|
91
102
|
require 'rubocop/cop/style/for'
|
92
103
|
require 'rubocop/cop/style/global_vars'
|
93
104
|
require 'rubocop/cop/style/hash_methods'
|
@@ -99,6 +110,7 @@ require 'rubocop/cop/style/lambda'
|
|
99
110
|
require 'rubocop/cop/style/lambda_call'
|
100
111
|
require 'rubocop/cop/style/leading_comment_space'
|
101
112
|
require 'rubocop/cop/style/line_length'
|
113
|
+
require 'rubocop/cop/style/method_def_parentheses'
|
102
114
|
require 'rubocop/cop/style/method_call_parentheses'
|
103
115
|
require 'rubocop/cop/style/method_called_on_do_end_block'
|
104
116
|
require 'rubocop/cop/style/method_length'
|
@@ -114,9 +126,9 @@ require 'rubocop/cop/style/op_method'
|
|
114
126
|
require 'rubocop/cop/style/parameter_lists'
|
115
127
|
require 'rubocop/cop/style/parentheses_around_condition'
|
116
128
|
require 'rubocop/cop/style/perl_backrefs'
|
129
|
+
require 'rubocop/cop/style/predicate_name'
|
117
130
|
require 'rubocop/cop/style/proc'
|
118
131
|
require 'rubocop/cop/style/raise_args'
|
119
|
-
require 'rubocop/cop/style/reduce_arguments'
|
120
132
|
require 'rubocop/cop/style/redundant_begin'
|
121
133
|
require 'rubocop/cop/style/redundant_exception'
|
122
134
|
require 'rubocop/cop/style/redundant_return'
|
@@ -125,6 +137,7 @@ require 'rubocop/cop/style/regexp_literal'
|
|
125
137
|
require 'rubocop/cop/style/rescue_modifier'
|
126
138
|
require 'rubocop/cop/style/semicolon'
|
127
139
|
require 'rubocop/cop/style/signal_exception'
|
140
|
+
require 'rubocop/cop/style/single_line_block_params'
|
128
141
|
require 'rubocop/cop/style/single_line_methods'
|
129
142
|
require 'rubocop/cop/style/space_after_comma_etc'
|
130
143
|
require 'rubocop/cop/style/space_after_control_keyword'
|
@@ -142,7 +155,6 @@ require 'rubocop/cop/style/space_inside_hash_literal_braces'
|
|
142
155
|
require 'rubocop/cop/style/space_inside_brackets'
|
143
156
|
require 'rubocop/cop/style/space_inside_parens'
|
144
157
|
require 'rubocop/cop/style/symbol_array'
|
145
|
-
require 'rubocop/cop/style/symbol_name'
|
146
158
|
require 'rubocop/cop/style/tab'
|
147
159
|
require 'rubocop/cop/style/ternary_operator'
|
148
160
|
require 'rubocop/cop/style/trailing_blank_lines'
|
@@ -156,6 +168,7 @@ require 'rubocop/cop/style/while_until_do'
|
|
156
168
|
require 'rubocop/cop/style/word_array'
|
157
169
|
require 'rubocop/cop/style/braces_around_hash_parameters'
|
158
170
|
|
171
|
+
require 'rubocop/cop/rails/default_scope'
|
159
172
|
require 'rubocop/cop/rails/has_and_belongs_to_many'
|
160
173
|
require 'rubocop/cop/rails/output'
|
161
174
|
require 'rubocop/cop/rails/read_attribute'
|
@@ -179,6 +192,7 @@ require 'rubocop/target_finder'
|
|
179
192
|
require 'rubocop/token'
|
180
193
|
require 'rubocop/processed_source'
|
181
194
|
require 'rubocop/source_parser'
|
195
|
+
require 'rubocop/file_inspector'
|
182
196
|
require 'rubocop/cli'
|
183
197
|
require 'rubocop/options'
|
184
198
|
require 'rubocop/version'
|
data/lib/rubocop/cli.rb
CHANGED
@@ -7,12 +7,11 @@ module Rubocop
|
|
7
7
|
# If set true while running,
|
8
8
|
# RuboCop will abort processing and exit gracefully.
|
9
9
|
attr_accessor :wants_to_quit
|
10
|
-
attr_reader :options
|
10
|
+
attr_reader :options, :config_store
|
11
11
|
|
12
12
|
alias_method :wants_to_quit?, :wants_to_quit
|
13
13
|
|
14
14
|
def initialize
|
15
|
-
@errors = []
|
16
15
|
@options = {}
|
17
16
|
@config_store = ConfigStore.new
|
18
17
|
end
|
@@ -25,13 +24,14 @@ module Rubocop
|
|
25
24
|
trap_interrupt
|
26
25
|
|
27
26
|
@options, remaining_args = Options.new.parse(args)
|
28
|
-
target_files = target_finder.find(remaining_args)
|
29
|
-
|
30
27
|
act_on_options(remaining_args)
|
28
|
+
target_files = target_finder.find(remaining_args)
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
inspector = FileInspector.new(@options)
|
31
|
+
any_failed = inspector.process_files(target_files, @config_store) do
|
32
|
+
wants_to_quit?
|
33
|
+
end
|
34
|
+
inspector.display_error_summary
|
35
35
|
|
36
36
|
!any_failed && !wants_to_quit ? 0 : 1
|
37
37
|
rescue => e
|
@@ -48,51 +48,17 @@ module Rubocop
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def display_error_summary(errors)
|
52
|
-
return if errors.empty?
|
53
|
-
plural = errors.count > 1 ? 's' : ''
|
54
|
-
warn "\n#{errors.count} error#{plural} occurred:".color(:red)
|
55
|
-
errors.each { |error| warn error }
|
56
|
-
warn 'Errors are usually caused by RuboCop bugs.'
|
57
|
-
warn 'Please, report your problems to RuboCop\'s issue tracker.'
|
58
|
-
warn 'Mention the following information in the issue report:'
|
59
|
-
warn Rubocop::Version.version(true)
|
60
|
-
end
|
61
|
-
|
62
51
|
private
|
63
52
|
|
64
|
-
def process_files(target_files)
|
65
|
-
target_files.each(&:freeze).freeze
|
66
|
-
inspected_files = []
|
67
|
-
any_failed = false
|
68
|
-
|
69
|
-
formatter_set.started(target_files)
|
70
|
-
|
71
|
-
target_files.each do |file|
|
72
|
-
break if wants_to_quit?
|
73
|
-
|
74
|
-
puts "Scanning #{file}" if @options[:debug]
|
75
|
-
formatter_set.file_started(file, {})
|
76
|
-
|
77
|
-
offences = inspect_file(file)
|
78
|
-
|
79
|
-
any_failed = true unless offences.empty?
|
80
|
-
inspected_files << file
|
81
|
-
formatter_set.file_finished(file, offences.freeze)
|
82
|
-
end
|
83
|
-
|
84
|
-
formatter_set.finished(inspected_files.freeze)
|
85
|
-
formatter_set.close_output_files
|
86
|
-
any_failed
|
87
|
-
end
|
88
|
-
|
89
53
|
def act_on_options(args)
|
90
54
|
if @options[:show_cops]
|
91
55
|
print_available_cops
|
92
56
|
exit(0)
|
93
57
|
end
|
94
58
|
|
95
|
-
|
59
|
+
ConfigLoader.debug = @options[:debug]
|
60
|
+
|
61
|
+
@config_store.options_config = @options[:config] if @options[:config]
|
96
62
|
|
97
63
|
Sickill::Rainbow.enabled = false if @options[:no_color]
|
98
64
|
|
@@ -100,8 +66,6 @@ module Rubocop
|
|
100
66
|
puts Rubocop::Version.version(true) if @options[:verbose_version]
|
101
67
|
exit(0) if @options[:version] || @options[:verbose_version]
|
102
68
|
|
103
|
-
ConfigLoader.debug = @options[:debug]
|
104
|
-
|
105
69
|
if @options[:auto_gen_config]
|
106
70
|
target_finder.find(args).each do |file|
|
107
71
|
config = @config_store.for(file)
|
@@ -113,33 +77,6 @@ module Rubocop
|
|
113
77
|
end
|
114
78
|
end
|
115
79
|
|
116
|
-
def mobilized_cop_classes(config)
|
117
|
-
@mobilized_cop_classes ||= {}
|
118
|
-
@mobilized_cop_classes[config.object_id] ||= begin
|
119
|
-
cop_classes = Cop::Cop.all
|
120
|
-
|
121
|
-
if @options[:only]
|
122
|
-
cop_classes.select! { |c| c.cop_name == @options[:only] }
|
123
|
-
else
|
124
|
-
# filter out Rails cops unless requested
|
125
|
-
cop_classes.reject!(&:rails?) unless run_rails_cops?(config)
|
126
|
-
|
127
|
-
# filter out style cops when --lint is passed
|
128
|
-
cop_classes.select!(&:lint?) if @options[:lint]
|
129
|
-
end
|
130
|
-
|
131
|
-
cop_classes
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def inspect_file(file)
|
136
|
-
config = @config_store.for(file)
|
137
|
-
team = Cop::Team.new(mobilized_cop_classes(config), config, @options)
|
138
|
-
offences = team.inspect_file(file)
|
139
|
-
@errors.concat(team.errors)
|
140
|
-
offences
|
141
|
-
end
|
142
|
-
|
143
80
|
def print_available_cops
|
144
81
|
cops = Cop::Cop.all
|
145
82
|
puts "Available cops (#{cops.length}) + config for #{Dir.pwd.to_s}: "
|
@@ -166,23 +103,5 @@ module Rubocop
|
|
166
103
|
def target_finder
|
167
104
|
@target_finder ||= TargetFinder.new(@config_store, @options[:debug])
|
168
105
|
end
|
169
|
-
|
170
|
-
def run_rails_cops?(config)
|
171
|
-
@options[:rails] || config['AllCops']['RunRailsCops']
|
172
|
-
end
|
173
|
-
|
174
|
-
def formatter_set
|
175
|
-
@formatter_set ||= begin
|
176
|
-
set = Formatter::FormatterSet.new
|
177
|
-
pairs = @options[:formatters] || [[Options::DEFAULT_FORMATTER]]
|
178
|
-
pairs.each do |formatter_key, output_path|
|
179
|
-
set.add_formatter(formatter_key, output_path)
|
180
|
-
end
|
181
|
-
set
|
182
|
-
rescue => error
|
183
|
-
warn error.message
|
184
|
-
exit(1)
|
185
|
-
end
|
186
|
-
end
|
187
106
|
end
|
188
107
|
end
|
data/lib/rubocop/config.rb
CHANGED
@@ -12,6 +12,8 @@ module Rubocop
|
|
12
12
|
class Config < DelegateClass(Hash)
|
13
13
|
class ValidationError < StandardError; end
|
14
14
|
|
15
|
+
COMMON_PARAMS = %w(Exclude Include Severity)
|
16
|
+
|
15
17
|
attr_reader :loaded_path
|
16
18
|
attr_accessor :contains_auto_generated_config
|
17
19
|
|
@@ -54,7 +56,8 @@ module Rubocop
|
|
54
56
|
|
55
57
|
valid_cop_names.each do |name|
|
56
58
|
@hash[name].each_key do |param|
|
57
|
-
unless
|
59
|
+
unless COMMON_PARAMS.include?(param) ||
|
60
|
+
default_config[name].key?(param)
|
58
61
|
fail ValidationError,
|
59
62
|
"unrecognized parameter #{name}:#{param} found " +
|
60
63
|
"in #{loaded_path || self}"
|
@@ -17,23 +17,16 @@ module Rubocop
|
|
17
17
|
|
18
18
|
class << self
|
19
19
|
attr_accessor :debug
|
20
|
+
attr_writer :root_level # The upwards search is stopped at this level.
|
20
21
|
alias_method :debug?, :debug
|
21
22
|
|
22
23
|
def load_file(path)
|
23
24
|
path = File.absolute_path(path)
|
24
|
-
hash = YAML.load_file(path)
|
25
|
+
hash = YAML.load_file(path) || {}
|
25
26
|
puts "configuration from #{path}" if debug?
|
26
27
|
contains_auto_generated_config = false
|
27
28
|
|
28
|
-
|
29
|
-
if File.basename(base_config.loaded_path) == DOTFILE
|
30
|
-
make_excludes_absolute(base_config)
|
31
|
-
end
|
32
|
-
base_config.each do |key, value|
|
33
|
-
if value.is_a?(Hash)
|
34
|
-
hash[key] = hash.key?(key) ? merge(value, hash[key]) : value
|
35
|
-
end
|
36
|
-
end
|
29
|
+
resolve_inheritance(path, hash) do |base_config|
|
37
30
|
if base_config.loaded_path.include?(AUTO_GENERATED_FILE)
|
38
31
|
contains_auto_generated_config = true
|
39
32
|
end
|
@@ -135,6 +128,20 @@ module Rubocop
|
|
135
128
|
|
136
129
|
private
|
137
130
|
|
131
|
+
def resolve_inheritance(path, hash)
|
132
|
+
base_configs(path, hash['inherit_from']).reverse_each do |base_config|
|
133
|
+
if File.basename(base_config.loaded_path) == DOTFILE
|
134
|
+
make_excludes_absolute(base_config)
|
135
|
+
end
|
136
|
+
base_config.each do |key, value|
|
137
|
+
if value.is_a?(Hash)
|
138
|
+
hash[key] = hash.key?(key) ? merge(value, hash[key]) : value
|
139
|
+
end
|
140
|
+
end
|
141
|
+
yield base_config
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
138
145
|
def config_files_in_path(target)
|
139
146
|
possible_config_files = dirs_to_search(target).map do |dir|
|
140
147
|
File.join(dir, DOTFILE)
|
@@ -146,6 +153,7 @@ module Rubocop
|
|
146
153
|
dirs_to_search = []
|
147
154
|
target_dir_pathname = Pathname.new(File.expand_path(target_dir))
|
148
155
|
target_dir_pathname.ascend do |dir_pathname|
|
156
|
+
break if dir_pathname.to_s == @root_level
|
149
157
|
dirs_to_search << dir_pathname.to_s
|
150
158
|
end
|
151
159
|
dirs_to_search << Dir.home
|
data/lib/rubocop/config_store.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Rubocop
|
4
|
-
# Handles
|
4
|
+
# Handles caching of configurations and association of inspected
|
5
5
|
# ruby files to configurations.
|
6
6
|
class ConfigStore
|
7
7
|
def initialize
|
@@ -19,8 +19,9 @@ module Rubocop
|
|
19
19
|
@object_cache = {}
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def options_config=(options_config)
|
23
23
|
loaded_config = ConfigLoader.load_file(options_config)
|
24
|
+
ConfigLoader.make_excludes_absolute(loaded_config)
|
24
25
|
@options_config = ConfigLoader.merge_with_default(loaded_config,
|
25
26
|
options_config)
|
26
27
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Cop
|
5
|
+
# Common functionality for checking assignment nodes.
|
6
|
+
module CheckAssignment
|
7
|
+
def on_lvasgn(node)
|
8
|
+
_lhs, rhs = *node
|
9
|
+
check_assignment(node, rhs)
|
10
|
+
end
|
11
|
+
|
12
|
+
def on_ivasgn(node)
|
13
|
+
_lhs, rhs = *node
|
14
|
+
check_assignment(node, rhs)
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_gvasgn(node)
|
18
|
+
_lhs, rhs = *node
|
19
|
+
check_assignment(node, rhs)
|
20
|
+
end
|
21
|
+
|
22
|
+
def on_or_asgn(node)
|
23
|
+
_lhs, rhs = *node
|
24
|
+
check_assignment(node, rhs)
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_and_asgn(node)
|
28
|
+
_lhs, rhs = *node
|
29
|
+
check_assignment(node, rhs)
|
30
|
+
end
|
31
|
+
|
32
|
+
def on_casgn(node)
|
33
|
+
_scope, _lhs, rhs = *node
|
34
|
+
check_assignment(node, rhs)
|
35
|
+
end
|
36
|
+
|
37
|
+
def on_op_asgn(node)
|
38
|
+
_lhs, _op, rhs = *node
|
39
|
+
check_assignment(node, rhs)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Cop
|
5
|
+
# Common functionality for checking instance methods and singeton methods.
|
6
|
+
module CheckMethods
|
7
|
+
def on_def(node)
|
8
|
+
method_name, args, body = *node
|
9
|
+
check(node, method_name, args, body)
|
10
|
+
end
|
11
|
+
|
12
|
+
def on_defs(node)
|
13
|
+
_scope, method_name, args, body = *node
|
14
|
+
check(node, method_name, args, body)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -55,8 +55,14 @@ module Rubocop
|
|
55
55
|
invoke_cops_callback(processed_source)
|
56
56
|
process(processed_source.ast) if processed_source.ast
|
57
57
|
@cops.reduce([]) do |offences, cop|
|
58
|
-
|
59
|
-
|
58
|
+
filename = processed_source.buffer.name
|
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
66
|
end
|
61
67
|
end
|
62
68
|
|
@@ -72,12 +78,18 @@ module Rubocop
|
|
72
78
|
end
|
73
79
|
|
74
80
|
# There are cops that require their own custom processing.
|
75
|
-
# If they define the #investigate method all input parameters passed
|
81
|
+
# If they define the #investigate method, all input parameters passed
|
76
82
|
# to the commissioner will be passed to the cop too in order to do
|
77
83
|
# its own processing.
|
78
84
|
def invoke_cops_callback(processed_source)
|
79
85
|
@cops.each do |cop|
|
80
86
|
next unless cop.respond_to?(:investigate)
|
87
|
+
|
88
|
+
filename = processed_source.buffer.name
|
89
|
+
|
90
|
+
# ignore files that are of no interest to the cop in question
|
91
|
+
next unless cop.relevant_file?(filename)
|
92
|
+
|
81
93
|
with_cop_error_handling(cop) do
|
82
94
|
cop.investigate(processed_source)
|
83
95
|
end
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -32,7 +32,7 @@ module Rubocop
|
|
32
32
|
# A commissioner object is responsible for traversing the AST and invoking
|
33
33
|
# the specific callbacks on each cop.
|
34
34
|
# If a cop needs to do its own processing of the AST or depends on
|
35
|
-
# something else it should define the `#investigate` method and do
|
35
|
+
# something else, it should define the `#investigate` method and do
|
36
36
|
# the processing there.
|
37
37
|
#
|
38
38
|
# @example
|
@@ -44,6 +44,7 @@ module Rubocop
|
|
44
44
|
# end
|
45
45
|
class Cop
|
46
46
|
extend AST::Sexp
|
47
|
+
include Util
|
47
48
|
|
48
49
|
# http://phrogz.net/programmingruby/language.html#table_18.4
|
49
50
|
# Backtick is added last just to help editors parse this code.
|
@@ -118,11 +119,13 @@ module Rubocop
|
|
118
119
|
respond_to?(:autocorrect, true)
|
119
120
|
end
|
120
121
|
|
121
|
-
def add_offence(
|
122
|
+
def add_offence(node, loc, message = nil, severity = nil)
|
122
123
|
location = loc.is_a?(Symbol) ? node.loc.send(loc) : loc
|
123
124
|
|
124
125
|
return if disabled_line?(location.line)
|
125
126
|
|
127
|
+
severity = custom_severity || severity || default_severity
|
128
|
+
|
126
129
|
message = message ? message : message(node)
|
127
130
|
message = debug? ? "#{name}: #{message}" : message
|
128
131
|
|
@@ -133,14 +136,16 @@ module Rubocop
|
|
133
136
|
false
|
134
137
|
end
|
135
138
|
@offences << Offence.new(severity, location, message, name, corrected)
|
139
|
+
yield if block_given?
|
136
140
|
end
|
137
141
|
|
138
|
-
def
|
139
|
-
|
142
|
+
def config_to_allow_offences
|
143
|
+
Formatter::DisabledConfigFormatter.config_to_allow_offences[cop_name]
|
140
144
|
end
|
141
145
|
|
142
|
-
def
|
143
|
-
|
146
|
+
def config_to_allow_offences=(hash)
|
147
|
+
Formatter::DisabledConfigFormatter.config_to_allow_offences[cop_name] =
|
148
|
+
hash
|
144
149
|
end
|
145
150
|
|
146
151
|
def cop_name
|
@@ -153,6 +158,34 @@ module Rubocop
|
|
153
158
|
@ignored_nodes << node
|
154
159
|
end
|
155
160
|
|
161
|
+
def include_paths
|
162
|
+
cop_config && cop_config['Include']
|
163
|
+
end
|
164
|
+
|
165
|
+
def include_file?(file)
|
166
|
+
return true unless include_paths
|
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']
|
175
|
+
end
|
176
|
+
|
177
|
+
def exclude_file?(file)
|
178
|
+
return false unless exclude_paths
|
179
|
+
|
180
|
+
exclude_paths.any? do |regex|
|
181
|
+
processed_source.buffer.name =~ /#{regex}/
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def relevant_file?(file)
|
186
|
+
include_file?(file) && !exclude_file?(file)
|
187
|
+
end
|
188
|
+
|
156
189
|
private
|
157
190
|
|
158
191
|
def disabled_line?(line_number)
|
@@ -178,47 +211,22 @@ module Rubocop
|
|
178
211
|
@ignored_nodes.any? { |n| n.eql?(node) } # Same object found in array?
|
179
212
|
end
|
180
213
|
|
181
|
-
def
|
182
|
-
|
183
|
-
|
184
|
-
return if Array(excludes).include?(sexp.type)
|
214
|
+
def default_severity
|
215
|
+
self.class.lint? ? :warning : :convention
|
216
|
+
end
|
185
217
|
|
186
|
-
|
187
|
-
|
188
|
-
|
218
|
+
def custom_severity
|
219
|
+
severity = cop_config && cop_config['Severity']
|
220
|
+
if severity
|
221
|
+
if Offence::SEVERITIES.include?(severity.to_sym)
|
222
|
+
severity.to_sym
|
223
|
+
else
|
224
|
+
warn "Warning: Invalid severity '#{severity}'. " +
|
225
|
+
"Valid severities are #{Offence::SEVERITIES.join(', ')}."
|
226
|
+
.color(:red)
|
189
227
|
end
|
190
228
|
end
|
191
229
|
end
|
192
|
-
|
193
|
-
def command?(name, node)
|
194
|
-
return unless node.type == :send
|
195
|
-
|
196
|
-
receiver, method_name, _args = *node
|
197
|
-
|
198
|
-
# commands have no explicit receiver
|
199
|
-
!receiver && method_name == name
|
200
|
-
end
|
201
|
-
|
202
|
-
def source_range(source_buffer, preceding_lines, begin_column,
|
203
|
-
column_count)
|
204
|
-
newline_length = 1
|
205
|
-
begin_pos = preceding_lines.reduce(0) do |a, e|
|
206
|
-
a + e.length + newline_length
|
207
|
-
end + begin_column
|
208
|
-
Parser::Source::Range.new(source_buffer, begin_pos,
|
209
|
-
begin_pos + column_count)
|
210
|
-
end
|
211
|
-
|
212
|
-
def range_with_surrounding_space(range, side = :both)
|
213
|
-
src = @processed_source.buffer.source
|
214
|
-
go_left = side == :left || side == :both
|
215
|
-
go_right = side == :right || side == :both
|
216
|
-
begin_pos = range.begin_pos
|
217
|
-
begin_pos -= 1 while go_left && src[begin_pos - 1] =~ /[ \t]/
|
218
|
-
end_pos = range.end_pos
|
219
|
-
end_pos += 1 while go_right && src[end_pos] =~ /[ \t]/
|
220
|
-
Parser::Source::Range.new(@processed_source.buffer, begin_pos, end_pos)
|
221
|
-
end
|
222
230
|
end
|
223
231
|
end
|
224
232
|
end
|