rubocop 0.12.0 → 0.13.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.
- data/CHANGELOG.md +40 -0
- data/README.md +49 -8
- data/config/default.yml +40 -0
- data/config/enabled.yml +37 -9
- data/lib/rubocop.rb +24 -10
- data/lib/rubocop/cli.rb +41 -106
- data/lib/rubocop/config.rb +3 -2
- data/lib/rubocop/cop/commissioner.rb +15 -5
- data/lib/rubocop/cop/cop.rb +47 -32
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +2 -2
- data/lib/rubocop/cop/lint/block_alignment.rb +30 -9
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/end_alignment.rb +4 -4
- data/lib/rubocop/cop/lint/end_in_method.rb +1 -1
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/eval.rb +1 -3
- data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +6 -4
- 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 +5 -8
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +57 -60
- data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +85 -0
- data/lib/rubocop/cop/lint/void.rb +6 -8
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.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_control.rb +4 -6
- data/lib/rubocop/cop/style/alias.rb +1 -3
- data/lib/rubocop/cop/style/align_array.rb +47 -0
- data/lib/rubocop/cop/style/align_hash.rb +145 -0
- data/lib/rubocop/cop/style/align_parameters.rb +9 -3
- data/lib/rubocop/cop/style/and_or.rb +3 -4
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -3
- data/lib/rubocop/cop/style/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -4
- 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 +2 -2
- data/lib/rubocop/cop/style/blocks.rb +14 -2
- data/lib/rubocop/cop/style/case_equality.rb +1 -3
- data/lib/rubocop/cop/style/case_indentation.rb +1 -1
- data/lib/rubocop/cop/style/character_literal.rb +1 -2
- data/lib/rubocop/cop/style/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/style/class_methods.rb +1 -3
- data/lib/rubocop/cop/style/{avoid_class_vars.rb → class_vars.rb} +6 -2
- data/lib/rubocop/cop/style/collection_methods.rb +7 -9
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -2
- data/lib/rubocop/cop/style/comment_annotation.rb +6 -6
- data/lib/rubocop/cop/style/constant_name.rb +1 -3
- data/lib/rubocop/cop/style/def_parentheses.rb +4 -12
- data/lib/rubocop/cop/style/documentation.rb +2 -2
- data/lib/rubocop/cop/style/dot_position.rb +2 -4
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +21 -6
- data/lib/rubocop/cop/style/empty_lines.rb +1 -1
- data/lib/rubocop/cop/style/empty_literal.rb +3 -12
- data/lib/rubocop/cop/style/encoding.rb +6 -6
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/end_of_line.rb +5 -5
- data/lib/rubocop/cop/style/even_odd.rb +2 -2
- data/lib/rubocop/cop/style/favor_join.rb +1 -3
- data/lib/rubocop/cop/style/favor_modifier.rb +7 -3
- 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 +23 -0
- data/lib/rubocop/cop/style/{avoid_for.rb → for.rb} +2 -2
- data/lib/rubocop/cop/style/{avoid_global_vars.rb → global_vars.rb} +19 -6
- data/lib/rubocop/cop/style/hash_methods.rb +3 -5
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -4
- data/lib/rubocop/cop/style/if_then_else.rb +1 -1
- data/lib/rubocop/cop/style/indentation_width.rb +4 -4
- data/lib/rubocop/cop/style/lambda.rb +2 -2
- data/lib/rubocop/cop/style/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/style/line_length.rb +7 -8
- data/lib/rubocop/cop/style/method_and_variable_snake_case.rb +1 -1
- data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -4
- data/lib/rubocop/cop/style/method_length.rb +4 -4
- data/lib/rubocop/cop/style/module_function.rb +1 -3
- data/lib/rubocop/cop/style/multiline_block_chain.rb +44 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -3
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +26 -6
- data/lib/rubocop/cop/style/op_method.rb +2 -2
- data/lib/rubocop/cop/style/parameter_lists.rb +4 -4
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
- data/lib/rubocop/cop/style/perl_backrefs.rb +26 -0
- data/lib/rubocop/cop/style/proc.rb +1 -3
- data/lib/rubocop/cop/style/reduce_arguments.rb +7 -5
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +9 -2
- data/lib/rubocop/cop/style/redundant_self.rb +9 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +7 -8
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +10 -10
- data/lib/rubocop/cop/style/signal_exception.rb +2 -4
- data/lib/rubocop/cop/style/single_line_methods.rb +2 -4
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +1 -1
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -1
- data/lib/rubocop/cop/style/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +34 -0
- data/lib/rubocop/cop/style/{avoid_perlisms.rb → special_global_vars.rb} +17 -8
- data/lib/rubocop/cop/style/string_literals.rb +1 -2
- data/lib/rubocop/cop/style/surrounding_space.rb +9 -8
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_name.rb +9 -2
- data/lib/rubocop/cop/style/tab.rb +5 -5
- data/lib/rubocop/cop/style/ternary_operator.rb +2 -6
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +32 -0
- data/lib/rubocop/cop/style/trailing_whitespace.rb +5 -6
- data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -3
- data/lib/rubocop/cop/style/when_then.rb +1 -4
- data/lib/rubocop/cop/style/while_until_do.rb +7 -5
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/team.rb +100 -0
- data/lib/rubocop/cop/variable_inspector.rb +323 -235
- data/lib/rubocop/cop/variable_inspector/assignment.rb +103 -0
- data/lib/rubocop/cop/variable_inspector/locatable.rb +162 -0
- data/lib/rubocop/cop/variable_inspector/reference.rb +31 -0
- data/lib/rubocop/cop/variable_inspector/scope.rb +70 -0
- data/lib/rubocop/cop/variable_inspector/variable.rb +87 -0
- data/lib/rubocop/cop/variable_inspector/variable_table.rb +129 -0
- data/lib/rubocop/formatter/json_formatter.rb +8 -8
- data/lib/rubocop/formatter/progress_formatter.rb +4 -4
- data/lib/rubocop/processed_source.rb +22 -1
- data/lib/rubocop/version.rb +1 -1
- data/rubocop.gemspec +1 -1
- data/spec/rubocop/cli_spec.rb +32 -30
- data/spec/rubocop/config_spec.rb +4 -6
- data/spec/rubocop/cop/commissioner_spec.rb +4 -5
- data/spec/rubocop/cop/cop_spec.rb +8 -26
- data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +5 -9
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +105 -57
- data/spec/rubocop/cop/lint/empty_ensure_spec.rb +1 -1
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +1 -1
- data/spec/rubocop/cop/lint/end_in_method_spec.rb +1 -1
- data/spec/rubocop/cop/lint/ensure_return_spec.rb +1 -1
- data/spec/rubocop/cop/lint/eval_spec.rb +3 -3
- data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +2 -2
- data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +1 -1
- data/spec/rubocop/cop/lint/loop_spec.rb +1 -1
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +1 -1
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +5 -5
- data/spec/rubocop/cop/lint/unreachable_code_spec.rb +1 -1
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +1545 -108
- data/spec/rubocop/cop/lint/useless_comparison_spec.rb +1 -1
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +101 -0
- data/spec/rubocop/cop/lint/void_spec.rb +1 -1
- data/spec/rubocop/cop/offence_spec.rb +4 -4
- data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +1 -1
- data/spec/rubocop/cop/rails/read_attribute_spec.rb +1 -1
- data/spec/rubocop/cop/rails/validation_spec.rb +1 -1
- data/spec/rubocop/cop/style/access_control_spec.rb +20 -20
- data/spec/rubocop/cop/style/alias_spec.rb +3 -3
- data/spec/rubocop/cop/style/align_array_spec.rb +62 -0
- data/spec/rubocop/cop/style/align_hash_spec.rb +267 -0
- data/spec/rubocop/cop/style/align_parameters_spec.rb +2 -2
- data/spec/rubocop/cop/style/and_or_spec.rb +1 -1
- data/spec/rubocop/cop/style/ascii_comments_spec.rb +2 -2
- data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +2 -2
- data/spec/rubocop/cop/style/attr_spec.rb +1 -1
- data/spec/rubocop/cop/style/begin_block_spec.rb +1 -1
- data/spec/rubocop/cop/style/block_comments_spec.rb +1 -1
- data/spec/rubocop/cop/style/block_nesting_spec.rb +3 -3
- data/spec/rubocop/cop/style/blocks_spec.rb +25 -1
- data/spec/rubocop/cop/style/case_equality_spec.rb +1 -1
- data/spec/rubocop/cop/style/case_indentation_spec.rb +5 -5
- data/spec/rubocop/cop/style/character_literal_spec.rb +1 -1
- data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +1 -1
- data/spec/rubocop/cop/style/class_methods_spec.rb +1 -1
- data/spec/rubocop/cop/style/class_vars_spec.rb +25 -0
- data/spec/rubocop/cop/style/collection_methods_spec.rb +5 -6
- data/spec/rubocop/cop/style/colon_method_call_spec.rb +0 -3
- data/spec/rubocop/cop/style/comment_annotation_spec.rb +20 -18
- data/spec/rubocop/cop/style/constant_name_spec.rb +1 -1
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +1 -1
- data/spec/rubocop/cop/style/def_without_parentheses_spec.rb +1 -1
- data/spec/rubocop/cop/style/documentation_spec.rb +1 -1
- data/spec/rubocop/cop/style/dot_position_spec.rb +5 -5
- data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +35 -4
- data/spec/rubocop/cop/style/empty_lines_spec.rb +1 -1
- data/spec/rubocop/cop/style/empty_literal_spec.rb +7 -7
- data/spec/rubocop/cop/style/encoding_spec.rb +11 -5
- data/spec/rubocop/cop/style/end_block_spec.rb +1 -1
- data/spec/rubocop/cop/style/end_of_line_spec.rb +4 -3
- data/spec/rubocop/cop/style/even_odd_spec.rb +1 -1
- data/spec/rubocop/cop/style/favor_join_spec.rb +2 -2
- data/spec/rubocop/cop/style/favor_modifier_spec.rb +13 -10
- data/spec/rubocop/cop/style/favor_sprintf_spec.rb +4 -4
- 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 +4 -4
- data/spec/rubocop/cop/style/final_newline_spec.rb +25 -0
- data/spec/rubocop/cop/style/{avoid_for_spec.rb → for_spec.rb} +8 -12
- data/spec/rubocop/cop/style/{avoid_global_vars_spec.rb → global_vars_spec.rb} +13 -3
- data/spec/rubocop/cop/style/hash_methods_spec.rb +1 -1
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +20 -9
- data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +3 -3
- data/spec/rubocop/cop/style/indentation_width_spec.rb +19 -19
- data/spec/rubocop/cop/style/lambda_spec.rb +6 -6
- data/spec/rubocop/cop/style/leading_comment_space_spec.rb +1 -1
- data/spec/rubocop/cop/style/line_length_spec.rb +3 -3
- data/spec/rubocop/cop/style/method_and_variable_snake_case_spec.rb +8 -9
- data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +1 -1
- data/spec/rubocop/cop/style/method_length_spec.rb +18 -17
- data/spec/rubocop/cop/style/module_function_spec.rb +1 -1
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +84 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +2 -2
- data/spec/rubocop/cop/style/nil_comparison_spec.rb +1 -1
- data/spec/rubocop/cop/style/not_spec.rb +1 -1
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +15 -25
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +2 -2
- data/spec/rubocop/cop/style/op_method_spec.rb +3 -3
- data/spec/rubocop/cop/style/parameter_lists_spec.rb +5 -5
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +4 -8
- data/spec/rubocop/cop/style/perl_backrefs_spec.rb +23 -0
- data/spec/rubocop/cop/style/proc_spec.rb +1 -1
- data/spec/rubocop/cop/style/reduce_arguments_spec.rb +18 -11
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +1 -1
- data/spec/rubocop/cop/style/redundant_return_spec.rb +16 -1
- data/spec/rubocop/cop/style/redundant_self_spec.rb +6 -1
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +19 -23
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +3 -3
- data/spec/rubocop/cop/style/semicolon_spec.rb +3 -3
- data/spec/rubocop/cop/style/signal_exception_spec.rb +1 -1
- data/spec/rubocop/cop/style/single_line_methods_spec.rb +22 -18
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_after_comma_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_around_braces_spec.rb +13 -12
- data/spec/rubocop/cop/style/space_around_equals_in_default_parameter_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +25 -25
- data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +53 -0
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +9 -9
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +47 -61
- data/spec/rubocop/cop/style/space_inside_parens_spec.rb +4 -4
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +52 -0
- data/spec/rubocop/cop/style/string_literals_spec.rb +5 -5
- data/spec/rubocop/cop/style/symbol_array_spec.rb +1 -1
- data/spec/rubocop/cop/style/symbol_name_spec.rb +27 -18
- data/spec/rubocop/cop/style/tab_spec.rb +1 -1
- data/spec/rubocop/cop/style/ternary_operator_spec.rb +2 -2
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +24 -0
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +7 -7
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +6 -14
- data/spec/rubocop/cop/style/unless_else_spec.rb +3 -3
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +5 -5
- data/spec/rubocop/cop/style/when_then_spec.rb +15 -15
- data/spec/rubocop/cop/style/while_until_do_spec.rb +3 -3
- data/spec/rubocop/cop/style/word_array_spec.rb +1 -1
- data/spec/rubocop/cop/team_spec.rb +158 -0
- data/spec/rubocop/cop/variable_inspector/assignment_spec.rb +217 -0
- data/spec/rubocop/cop/variable_inspector/locatable_spec.rb +740 -0
- data/spec/rubocop/cop/variable_inspector/scope_spec.rb +191 -0
- data/spec/rubocop/cop/variable_inspector/variable_spec.rb +79 -0
- data/spec/rubocop/cop/variable_inspector/variable_table_spec.rb +275 -0
- data/spec/rubocop/cop/variable_inspector_spec.rb +13 -533
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +4 -4
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +3 -3
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +3 -3
- data/spec/rubocop/formatter/progress_formatter_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -1
- data/spec/support/ast_helper.rb +15 -0
- data/spec/support/shared_context.rb +18 -0
- data/spec/support/shared_examples.rb +1 -1
- metadata +95 -32
- checksums.yaml +0 -7
- data/lib/rubocop/cop/lint/unused_local_variable.rb +0 -32
- data/lib/rubocop/cop/style/avoid_perl_backrefs.rb +0 -19
- data/spec/rubocop/cop/lint/unused_local_variable_spec.rb +0 -588
- data/spec/rubocop/cop/style/avoid_class_vars_spec.rb +0 -27
- data/spec/rubocop/cop/style/avoid_perl_backrefs_spec.rb +0 -20
- data/spec/rubocop/cop/style/avoid_perlisms_spec.rb +0 -47
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,46 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
### New features
|
6
|
+
|
7
|
+
* New configuration parameter `AllowAdjacentOneLineDefs` for `EmptyLineBetweenDefs`.
|
8
|
+
* New cop `MultilineBlockChain` keeps track of chained blocks spanning multiple lines.
|
9
|
+
* `RedundantSelf` cop does auto-correction
|
10
|
+
* `AvoidPerlBackrefs` cop does auto-correction.
|
11
|
+
* `AvoidPerlisms` cop does auto-correction.
|
12
|
+
* `RedundantReturn` cop does auto-correction.
|
13
|
+
* `Blocks` cop does auto-correction.
|
14
|
+
* New cop `TrailingBlankLines` keeps track of extra blanks lines at the end of source file.
|
15
|
+
* New cop `AlignHash` keeps track of bad alignment in multi-line hash literals.
|
16
|
+
* New cop `AlignArray` keeps track of bad alignment in multi-line array literals.
|
17
|
+
* New cop `SpaceBeforeModifierKeyword` keeps track of missing space before a modifier keyword (`if`, `unless`, `while`, `until`).
|
18
|
+
* New cop `FinalNewline` keeps tracks of the required final newline in a source file.
|
19
|
+
* Highlightling corrected in `SpaceInsideHashLiteralBraces` and `SpaceAroundBraces` cops.
|
20
|
+
|
21
|
+
### Changes
|
22
|
+
|
23
|
+
* [#447](https://github.com/bbatsov/rubocop/issues/447) - `BlockAlignment` cop now allows `end` to be aligned with the start of the line containing `do`.
|
24
|
+
* `SymbolName` now has an `AllowDots` config option to allow symbols like `:'whatever.submit_button'`.
|
25
|
+
* [#469](https://github.com/bbatsov/rubocop/issues/469) - Extracted useless setter call tracking part of `UselessAssignment` cop to `UselessSetterCall`.
|
26
|
+
* [#469](https://github.com/bbatsov/rubocop/issues/469) - Merged `UnusedLocalVariable` cop into `UselessAssignment`.
|
27
|
+
* [#458](https://github.com/bbatsov/rubocop/issues/458) - The merged `UselessAssignment` cop now has advanced logic that tracks not only assignment at the end of the method but also every assignment in every scope.
|
28
|
+
* [#466](https://github.com/bbatsov/rubocop/issues/466) - Allow built-in JRuby global vars in `AvoidGlobalVars`
|
29
|
+
* Added a config option `AllowedVariables` to `AvoidGlobalVars` to allow users to whitelist certain global variables
|
30
|
+
* Renamed `AvoidGlobalVars` to `GlobalVars`
|
31
|
+
* Renamed `AvoidPerlisms` to `SpecialGlobalVars`
|
32
|
+
* Renamed `AvoidFor` to `For`
|
33
|
+
* Renamed `AvoidClassVars` to `ClassVars`
|
34
|
+
* Renamed `AvoidPerlBackrefs` to `PerlBackrefs`
|
35
|
+
* `NumericLiterals` now accepts a config param `MinDigits` - the minimal number of digits in the integer portion of number for the cop to check it.
|
36
|
+
|
37
|
+
### Bugs fixed
|
38
|
+
|
39
|
+
* [#449](https://github.com/bbatsov/rubocop/issues/449) - Remove whitespaces between condition and `do` with `WhileUntilDo` auto-correction
|
40
|
+
* Continue with file inspection after parser warnings. Give up only on syntax errors.
|
41
|
+
* Don’t trigger the HashSyntax cop on digit-starting keys.
|
42
|
+
* Fix crashes while inspecting class definition subclassing another class stored in a local variable in `UselessAssignment` (formerly of `UnusedLocalVariable`) and `ShadowingOuterLocalVariable` (like `clazz = Array; class SomeClass < clazz; end`).
|
43
|
+
* [#463](https://github.com/bbatsov/rubocop/issues/463) - Do not warn if using destructuring in second `reduce` argument (`ReduceArguments`)
|
44
|
+
|
5
45
|
## 0.12.0 (23/08/2013)
|
6
46
|
|
7
47
|
### New features
|
data/README.md
CHANGED
@@ -7,9 +7,15 @@
|
|
7
7
|
> Role models are important. <br/>
|
8
8
|
> -- Officer Alex J. Murphy / RoboCop
|
9
9
|
|
10
|
-
**RuboCop** is a Ruby code
|
10
|
+
**RuboCop** is a Ruby static code analyzer. Out of the box it will
|
11
|
+
enforce many of the guidelines outlined in the community
|
11
12
|
[Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide).
|
12
13
|
|
14
|
+
Most aspects of its behavior can be tweaked via various configuration options.
|
15
|
+
|
16
|
+
Apart from reporting problems in your code, RuboCop can also
|
17
|
+
automatically fix some of the problems for you.
|
18
|
+
|
13
19
|
## Installation
|
14
20
|
|
15
21
|
**RuboCop**'s installation is pretty standard:
|
@@ -79,11 +85,45 @@ Command flag | Description
|
|
79
85
|
`-R/--rails` | Run extra Rails cops
|
80
86
|
`-l/--lint` | Run only lint cops
|
81
87
|
`-a/--auto-correct` | Auto-correct certain offences *Note:* Experimental - use with caution
|
82
|
-
`-s/--silent` | Suppress the final summary
|
83
88
|
`--only` | Run only the specified cop
|
84
89
|
`--auto-gen-config` | Generate a configuration file acting as a TODO list
|
85
90
|
`--show-cops` | Shows available cops and their configuration
|
86
91
|
|
92
|
+
### Cops
|
93
|
+
|
94
|
+
In RuboCop lingo the various checks performed on the code are called cops. There are several cop departments.
|
95
|
+
|
96
|
+
#### Style
|
97
|
+
|
98
|
+
Most of the cops in RuboCop are so called style cops that check for
|
99
|
+
stylistics problems in your code. Almost all of the them are based on
|
100
|
+
the Ruby Style Guide. Many of the style cops have configurations
|
101
|
+
options allowing them to support different popular coding
|
102
|
+
conventions.
|
103
|
+
|
104
|
+
#### Lint
|
105
|
+
|
106
|
+
Lint cops check for possible errors and very bad practices in your
|
107
|
+
code. RuboCop implements in a portable way all built-in MRI lint
|
108
|
+
checks (`ruby -wc`) and adds a lot of extra lint checks of its
|
109
|
+
own. You can run only the lint cops like this:
|
110
|
+
|
111
|
+
```
|
112
|
+
$ rubocop -l
|
113
|
+
```
|
114
|
+
|
115
|
+
Disabling any of the lint cops in generally a bad idea.
|
116
|
+
|
117
|
+
#### Rails
|
118
|
+
|
119
|
+
Rails cops are specific to the Ruby on Rails framework. Unlike style
|
120
|
+
and lint cops they are not used by default and you have to request them
|
121
|
+
specifically:
|
122
|
+
|
123
|
+
```
|
124
|
+
$ rubocop -R
|
125
|
+
```
|
126
|
+
|
87
127
|
## Configuration
|
88
128
|
|
89
129
|
The behavior of RuboCop can be controlled via the
|
@@ -129,12 +169,13 @@ inherit_from:
|
|
129
169
|
|
130
170
|
### Defaults
|
131
171
|
|
132
|
-
The file
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
172
|
+
The file
|
173
|
+
[config/default.yml]([.rubocop.yml](https://github.com/bbatsov/rubocop/blob/master/config/.default.yml))
|
174
|
+
under the RuboCop home directory contains the default settings that
|
175
|
+
all configurations inherit from. Project and personal `.rubocop.yml`
|
176
|
+
files need only make settings that are different from the default
|
177
|
+
ones. If there is no `.rubocop.yml` file in the project or home
|
178
|
+
directory, `config/default.yml` will be used.
|
138
179
|
|
139
180
|
### Disabling Cops within Source Code
|
140
181
|
|
data/config/default.yml
CHANGED
@@ -50,6 +50,9 @@ BlockNesting:
|
|
50
50
|
Description: 'Avoid more than `Max` levels of nesting.'
|
51
51
|
Max: 3
|
52
52
|
|
53
|
+
NumericLiterals:
|
54
|
+
MinDigits: 5
|
55
|
+
|
53
56
|
RegexpLiteral:
|
54
57
|
Description: >
|
55
58
|
Use %r for regular expressions matching more than
|
@@ -58,6 +61,10 @@ RegexpLiteral:
|
|
58
61
|
`MaxSlashes` '/' character.
|
59
62
|
MaxSlashes: 1
|
60
63
|
|
64
|
+
# Built-in global variables are allowed by default.
|
65
|
+
GlobalVars:
|
66
|
+
AllowedVariables: []
|
67
|
+
|
61
68
|
# Align with the style guide.
|
62
69
|
CollectionMethods:
|
63
70
|
PreferredMethods:
|
@@ -111,3 +118,36 @@ CommentAnnotation:
|
|
111
118
|
- OPTIMIZE
|
112
119
|
- HACK
|
113
120
|
- REVIEW
|
121
|
+
|
122
|
+
# Use empty lines between defs.
|
123
|
+
EmptyLineBetweenDefs:
|
124
|
+
# If true, this parameter means that single line method definitions don't
|
125
|
+
# need an empty line between them.
|
126
|
+
AllowAdjacentOneLineDefs: false
|
127
|
+
|
128
|
+
# Align the elements of a hash literal if they span more than one line.
|
129
|
+
AlignHash:
|
130
|
+
# Alignment of entries using hash rocket as separator. Valid values are:
|
131
|
+
#
|
132
|
+
# key - left alignment of keys
|
133
|
+
# 'a' => 2
|
134
|
+
# 'bb' => 3
|
135
|
+
# separator - alignment of hash rockets, keys are right aligned
|
136
|
+
# 'a' => 2
|
137
|
+
# 'bb' => 3
|
138
|
+
# table - left alignment of keys, hash rockets, and values
|
139
|
+
# 'a' => 2
|
140
|
+
# 'bb' => 3
|
141
|
+
EnforcedHashRocketStyle: key
|
142
|
+
# Alignment of entries using colon as separator. Valid values are:
|
143
|
+
#
|
144
|
+
# key - left alignment of keys
|
145
|
+
# a: 0
|
146
|
+
# bb: 1
|
147
|
+
# separator - alignment of colons, keys are right aligned
|
148
|
+
# a: 0
|
149
|
+
# bb: 1
|
150
|
+
# table - left alignment of keys and values
|
151
|
+
# a: 0
|
152
|
+
# bb: 1
|
153
|
+
EnforcedColonStyle: key
|
data/config/enabled.yml
CHANGED
@@ -20,6 +20,14 @@ TrailingWhitespace:
|
|
20
20
|
Description: 'Avoid trailing whitespace.'
|
21
21
|
Enabled: true
|
22
22
|
|
23
|
+
TrailingBlankLines:
|
24
|
+
Description: 'Checks for superflous trailing blank lines.'
|
25
|
+
Enabled: true
|
26
|
+
|
27
|
+
FinalNewline:
|
28
|
+
Description: 'Checks for a final newline in a source file.'
|
29
|
+
Enabled: true
|
30
|
+
|
23
31
|
CaseIndentation:
|
24
32
|
Description: 'Indent when as deep as case.'
|
25
33
|
Enabled: true
|
@@ -208,19 +216,19 @@ CollectionMethods:
|
|
208
216
|
Description: 'Preferred collection methods.'
|
209
217
|
Enabled: true
|
210
218
|
|
211
|
-
|
219
|
+
For:
|
212
220
|
Description: 'Prefer each over for.'
|
213
221
|
Enabled: true
|
214
222
|
|
215
|
-
|
223
|
+
SpecialGlobalVars:
|
216
224
|
Description: 'Avoid Perl-style global variables.'
|
217
225
|
Enabled: true
|
218
226
|
|
219
|
-
|
227
|
+
PerlBackrefs:
|
220
228
|
Description: 'Avoid Perl-style regex back references.'
|
221
229
|
Enabled: true
|
222
230
|
|
223
|
-
|
231
|
+
ClassVars:
|
224
232
|
Description: 'Avoid the use of class variables.'
|
225
233
|
Enabled: true
|
226
234
|
|
@@ -326,7 +334,7 @@ ColonMethodCall:
|
|
326
334
|
Description: 'Do not use :: for method call.'
|
327
335
|
Enabled: true
|
328
336
|
|
329
|
-
|
337
|
+
GlobalVars:
|
330
338
|
Description: 'Do not introduce global variables.'
|
331
339
|
Enabled: true
|
332
340
|
|
@@ -436,6 +444,26 @@ HashMethods:
|
|
436
444
|
Description: Checks for use of deprecated Hash methods.
|
437
445
|
Enabled: true
|
438
446
|
|
447
|
+
MultilineBlockChain:
|
448
|
+
Description: Avoid multi-line chains of blocks.
|
449
|
+
Enabled: true
|
450
|
+
|
451
|
+
AlignHash:
|
452
|
+
Description: >
|
453
|
+
Align the elements of a hash literal if they span more than
|
454
|
+
one line.
|
455
|
+
Enabled: true
|
456
|
+
|
457
|
+
AlignArray:
|
458
|
+
Description: >
|
459
|
+
Align the elements of an array literal if they span more than
|
460
|
+
one line.
|
461
|
+
Enabled: true
|
462
|
+
|
463
|
+
SpaceBeforeModifierKeyword:
|
464
|
+
Description: Put a space before the modifier keyword.
|
465
|
+
Enabled: true
|
466
|
+
|
439
467
|
#################### Lint ################################
|
440
468
|
### Warnings
|
441
469
|
|
@@ -459,10 +487,6 @@ UnreachableCode:
|
|
459
487
|
Description: 'Unreachable code.'
|
460
488
|
Enabled: true
|
461
489
|
|
462
|
-
UnusedLocalVariable:
|
463
|
-
Description: 'Unused local variable.'
|
464
|
-
Enabled: true
|
465
|
-
|
466
490
|
ShadowingOuterLocalVariable:
|
467
491
|
Description: >
|
468
492
|
Do not use the same name as outer local variable
|
@@ -491,6 +515,10 @@ UselessAssignment:
|
|
491
515
|
Description: 'Checks for useless assignment to a local variable.'
|
492
516
|
Enabled: true
|
493
517
|
|
518
|
+
UselessSetterCall:
|
519
|
+
Description: 'Checks for useless setter call to a local variable.'
|
520
|
+
Enabled: true
|
521
|
+
|
494
522
|
UselessComparison:
|
495
523
|
Description: 'Checks for comparison of something with itself.'
|
496
524
|
Enabled: true
|
data/lib/rubocop.rb
CHANGED
@@ -8,11 +8,19 @@ require 'ast/sexp'
|
|
8
8
|
require 'powerpack'
|
9
9
|
|
10
10
|
require 'rubocop/cop/util'
|
11
|
-
require 'rubocop/cop/variable_inspector'
|
12
11
|
require 'rubocop/cop/offence'
|
13
12
|
require 'rubocop/cop/cop'
|
14
13
|
require 'rubocop/cop/commissioner'
|
15
14
|
require 'rubocop/cop/corrector'
|
15
|
+
require 'rubocop/cop/team'
|
16
|
+
|
17
|
+
require 'rubocop/cop/variable_inspector'
|
18
|
+
require 'rubocop/cop/variable_inspector/locatable'
|
19
|
+
require 'rubocop/cop/variable_inspector/variable'
|
20
|
+
require 'rubocop/cop/variable_inspector/assignment'
|
21
|
+
require 'rubocop/cop/variable_inspector/reference'
|
22
|
+
require 'rubocop/cop/variable_inspector/scope'
|
23
|
+
require 'rubocop/cop/variable_inspector/variable_table'
|
16
24
|
|
17
25
|
require 'rubocop/cop/lint/assignment_in_condition'
|
18
26
|
require 'rubocop/cop/lint/block_alignment'
|
@@ -28,32 +36,30 @@ require 'rubocop/cop/lint/parentheses_as_grouped_expression'
|
|
28
36
|
require 'rubocop/cop/lint/rescue_exception'
|
29
37
|
require 'rubocop/cop/lint/shadowing_outer_local_variable'
|
30
38
|
require 'rubocop/cop/lint/unreachable_code'
|
31
|
-
require 'rubocop/cop/lint/unused_local_variable'
|
32
39
|
require 'rubocop/cop/lint/useless_assignment'
|
33
40
|
require 'rubocop/cop/lint/useless_comparison'
|
41
|
+
require 'rubocop/cop/lint/useless_setter_call'
|
34
42
|
require 'rubocop/cop/lint/void'
|
35
43
|
|
36
44
|
require 'rubocop/cop/style/access_control'
|
37
45
|
require 'rubocop/cop/style/alias'
|
46
|
+
require 'rubocop/cop/style/align_array'
|
47
|
+
require 'rubocop/cop/style/align_hash'
|
38
48
|
require 'rubocop/cop/style/align_parameters'
|
39
49
|
require 'rubocop/cop/style/and_or'
|
40
50
|
require 'rubocop/cop/style/ascii_comments'
|
41
51
|
require 'rubocop/cop/style/ascii_identifiers'
|
42
52
|
require 'rubocop/cop/style/attr'
|
43
|
-
require 'rubocop/cop/style/avoid_class_vars'
|
44
|
-
require 'rubocop/cop/style/avoid_for'
|
45
|
-
require 'rubocop/cop/style/avoid_global_vars'
|
46
|
-
require 'rubocop/cop/style/avoid_perl_backrefs'
|
47
|
-
require 'rubocop/cop/style/avoid_perlisms'
|
48
53
|
require 'rubocop/cop/style/begin_block'
|
49
54
|
require 'rubocop/cop/style/block_comments'
|
50
55
|
require 'rubocop/cop/style/block_nesting'
|
51
56
|
require 'rubocop/cop/style/blocks'
|
52
|
-
require 'rubocop/cop/style/character_literal'
|
53
57
|
require 'rubocop/cop/style/case_equality'
|
54
58
|
require 'rubocop/cop/style/case_indentation'
|
59
|
+
require 'rubocop/cop/style/character_literal'
|
55
60
|
require 'rubocop/cop/style/class_and_module_camel_case'
|
56
61
|
require 'rubocop/cop/style/class_methods'
|
62
|
+
require 'rubocop/cop/style/class_vars'
|
57
63
|
require 'rubocop/cop/style/collection_methods'
|
58
64
|
require 'rubocop/cop/style/colon_method_call'
|
59
65
|
require 'rubocop/cop/style/comment_annotation'
|
@@ -72,13 +78,14 @@ require 'rubocop/cop/style/favor_join'
|
|
72
78
|
require 'rubocop/cop/style/favor_modifier'
|
73
79
|
require 'rubocop/cop/style/favor_sprintf'
|
74
80
|
require 'rubocop/cop/style/favor_unless_over_negated_if'
|
81
|
+
require 'rubocop/cop/style/final_newline'
|
82
|
+
require 'rubocop/cop/style/for'
|
83
|
+
require 'rubocop/cop/style/global_vars'
|
75
84
|
require 'rubocop/cop/style/hash_methods'
|
76
85
|
require 'rubocop/cop/style/hash_syntax'
|
77
86
|
require 'rubocop/cop/style/if_then_else'
|
78
87
|
require 'rubocop/cop/style/if_with_semicolon'
|
79
88
|
require 'rubocop/cop/style/indentation_width'
|
80
|
-
require 'rubocop/cop/style/multiline_if_then'
|
81
|
-
require 'rubocop/cop/style/one_line_conditional'
|
82
89
|
require 'rubocop/cop/style/lambda'
|
83
90
|
require 'rubocop/cop/style/leading_comment_space'
|
84
91
|
require 'rubocop/cop/style/line_length'
|
@@ -86,12 +93,16 @@ require 'rubocop/cop/style/method_and_variable_snake_case'
|
|
86
93
|
require 'rubocop/cop/style/method_call_parentheses'
|
87
94
|
require 'rubocop/cop/style/method_length'
|
88
95
|
require 'rubocop/cop/style/module_function'
|
96
|
+
require 'rubocop/cop/style/multiline_block_chain'
|
97
|
+
require 'rubocop/cop/style/multiline_if_then'
|
89
98
|
require 'rubocop/cop/style/nil_comparison'
|
90
99
|
require 'rubocop/cop/style/not'
|
91
100
|
require 'rubocop/cop/style/numeric_literals'
|
101
|
+
require 'rubocop/cop/style/one_line_conditional'
|
92
102
|
require 'rubocop/cop/style/op_method'
|
93
103
|
require 'rubocop/cop/style/parameter_lists'
|
94
104
|
require 'rubocop/cop/style/parentheses_around_condition'
|
105
|
+
require 'rubocop/cop/style/perl_backrefs'
|
95
106
|
require 'rubocop/cop/style/proc'
|
96
107
|
require 'rubocop/cop/style/reduce_arguments'
|
97
108
|
require 'rubocop/cop/style/redundant_begin'
|
@@ -105,12 +116,15 @@ require 'rubocop/cop/style/single_line_methods'
|
|
105
116
|
require 'rubocop/cop/style/space_after_comma_etc'
|
106
117
|
require 'rubocop/cop/style/space_after_control_keyword'
|
107
118
|
require 'rubocop/cop/style/space_after_method_name'
|
119
|
+
require 'rubocop/cop/style/special_global_vars'
|
120
|
+
require 'rubocop/cop/style/space_before_modifier_keyword'
|
108
121
|
require 'rubocop/cop/style/string_literals'
|
109
122
|
require 'rubocop/cop/style/surrounding_space'
|
110
123
|
require 'rubocop/cop/style/symbol_array'
|
111
124
|
require 'rubocop/cop/style/symbol_name'
|
112
125
|
require 'rubocop/cop/style/tab'
|
113
126
|
require 'rubocop/cop/style/ternary_operator'
|
127
|
+
require 'rubocop/cop/style/trailing_blank_lines'
|
114
128
|
require 'rubocop/cop/style/trailing_whitespace'
|
115
129
|
require 'rubocop/cop/style/trivial_accessors'
|
116
130
|
require 'rubocop/cop/style/unless_else'
|
data/lib/rubocop/cli.rb
CHANGED
@@ -16,7 +16,6 @@ module Rubocop
|
|
16
16
|
alias_method :wants_to_quit?, :wants_to_quit
|
17
17
|
|
18
18
|
def initialize
|
19
|
-
@cops = Cop::Cop.all
|
20
19
|
@errors = []
|
21
20
|
@options = {}
|
22
21
|
@config_store = ConfigStore.new
|
@@ -33,12 +32,6 @@ module Rubocop
|
|
33
32
|
|
34
33
|
Config.debug = @options[:debug]
|
35
34
|
|
36
|
-
# filter out Rails cops unless requested
|
37
|
-
@cops.reject!(&:rails?) unless @options[:rails]
|
38
|
-
|
39
|
-
# filter out style cops when --lint is passed
|
40
|
-
@cops.select!(&:lint?) if @options[:lint]
|
41
|
-
|
42
35
|
target_files = target_finder.find(args)
|
43
36
|
target_files.each(&:freeze).freeze
|
44
37
|
inspected_files = []
|
@@ -70,8 +63,34 @@ module Rubocop
|
|
70
63
|
return 1
|
71
64
|
end
|
72
65
|
|
66
|
+
def mobilized_cop_classes
|
67
|
+
@mobilized_cop_classes ||= begin
|
68
|
+
cop_classes = Cop::Cop.all
|
69
|
+
|
70
|
+
if @options[:only]
|
71
|
+
cop_classes.select! { |c| c.cop_name == @options[:only] }
|
72
|
+
else
|
73
|
+
# filter out Rails cops unless requested
|
74
|
+
cop_classes.reject!(&:rails?) unless @options[:rails]
|
75
|
+
|
76
|
+
# filter out style cops when --lint is passed
|
77
|
+
cop_classes.select!(&:lint?) if @options[:lint]
|
78
|
+
end
|
79
|
+
|
80
|
+
cop_classes
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def inspect_file(file)
|
85
|
+
config = @config_store.for(file)
|
86
|
+
team = Cop::Team.new(mobilized_cop_classes, config, @options)
|
87
|
+
offences = team.inspect_file(file)
|
88
|
+
@errors.concat(team.errors)
|
89
|
+
offences
|
90
|
+
end
|
91
|
+
|
73
92
|
def validate_only_option
|
74
|
-
if
|
93
|
+
if Cop::Cop.all.none? { |c| c.cop_name == @options[:only] }
|
75
94
|
fail ArgumentError, "Unrecognized cop name: #{@options[:only]}."
|
76
95
|
end
|
77
96
|
end
|
@@ -81,18 +100,26 @@ module Rubocop
|
|
81
100
|
fail ArgumentError,
|
82
101
|
'--auto-gen-config can not be combined with any other arguments.'
|
83
102
|
end
|
103
|
+
|
104
|
+
target_finder.find(args).each do |file|
|
105
|
+
config = @config_store.for(file)
|
106
|
+
if @options[:auto_gen_config] && config.contains_auto_generated_config
|
107
|
+
fail "Remove #{Config::AUTO_GENERATED_FILE} from the current " +
|
108
|
+
'configuration before generating it again.'
|
109
|
+
end
|
110
|
+
end
|
84
111
|
end
|
85
112
|
|
86
113
|
def print_available_cops
|
87
|
-
|
114
|
+
cops = Cop::Cop.all
|
115
|
+
puts "Available cops (#{cops.length}) + config for #{Dir.pwd.to_s}: "
|
88
116
|
dirconf = @config_store.for(Dir.pwd.to_s)
|
89
|
-
|
90
|
-
coptypes =
|
117
|
+
cops.types.sort!.each do |type|
|
118
|
+
coptypes = cops.with_type(type).sort_by!(&:cop_name)
|
91
119
|
puts "Type '#{type.to_s.capitalize}' (#{coptypes.size}):"
|
92
120
|
coptypes.each do |cop|
|
93
|
-
|
94
|
-
|
95
|
-
cnf = dirconf.for_cop(name).dup
|
121
|
+
puts " - #{cop.cop_name}"
|
122
|
+
cnf = dirconf.for_cop(cop).dup
|
96
123
|
print_conf_option('Description',
|
97
124
|
cnf.delete('Description') { 'None' })
|
98
125
|
cnf.each { |k, v| print_conf_option(k, v) }
|
@@ -104,81 +131,6 @@ module Rubocop
|
|
104
131
|
puts " - #{option}: #{value}"
|
105
132
|
end
|
106
133
|
|
107
|
-
def inspect_file(file)
|
108
|
-
begin
|
109
|
-
processed_source = SourceParser.parse_file(file)
|
110
|
-
rescue Encoding::UndefinedConversionError, ArgumentError => e
|
111
|
-
handle_error(e, "An error occurred while parsing #{file}.".color(:red))
|
112
|
-
return []
|
113
|
-
end
|
114
|
-
|
115
|
-
# If we got any syntax errors, return only the syntax offences.
|
116
|
-
# Parser may return nil for AST even though there are no syntax errors.
|
117
|
-
# e.g. sources which contain only comments
|
118
|
-
unless processed_source.diagnostics.empty?
|
119
|
-
return processed_source.diagnostics.map do |diagnostic|
|
120
|
-
Cop::Offence.from_diagnostic(diagnostic)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
config = @config_store.for(file)
|
125
|
-
if @options[:auto_gen_config] && config.contains_auto_generated_config
|
126
|
-
fail "Remove #{Config::AUTO_GENERATED_FILE} from the current " +
|
127
|
-
'configuration before generating it again.'
|
128
|
-
end
|
129
|
-
set_config_for_all_cops(config)
|
130
|
-
|
131
|
-
cops = []
|
132
|
-
@cops.each do |cop_class|
|
133
|
-
cop_name = cop_class.cop_name
|
134
|
-
next unless config.cop_enabled?(cop_name)
|
135
|
-
next unless !@options[:only] || @options[:only] == cop_name
|
136
|
-
cop = setup_cop(cop_class, processed_source.disabled_lines_for_cops)
|
137
|
-
cops << cop
|
138
|
-
end
|
139
|
-
commissioner = Cop::Commissioner.new(cops)
|
140
|
-
offences = commissioner.investigate(processed_source)
|
141
|
-
process_commissioner_errors(file, commissioner.errors)
|
142
|
-
autocorrect(processed_source.buffer, cops)
|
143
|
-
offences.sort
|
144
|
-
end
|
145
|
-
|
146
|
-
def process_commissioner_errors(file, file_errors)
|
147
|
-
file_errors.each do |cop, errors|
|
148
|
-
errors.each do |e|
|
149
|
-
handle_error(e,
|
150
|
-
"An error occurred while #{cop.name}".color(:red) +
|
151
|
-
" cop was inspecting #{file}.".color(:red))
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
def set_config_for_all_cops(config)
|
157
|
-
@cops.each do |cop_class|
|
158
|
-
cop_class.config = config.for_cop(cop_class.cop_name)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def setup_cop(cop_class, disabled_lines_for_cops = nil)
|
163
|
-
cop = cop_class.new
|
164
|
-
cop.debug = @options[:debug]
|
165
|
-
cop.autocorrect = @options[:autocorrect]
|
166
|
-
if disabled_lines_for_cops
|
167
|
-
cop.disabled_lines = disabled_lines_for_cops[cop_class.cop_name]
|
168
|
-
end
|
169
|
-
cop
|
170
|
-
end
|
171
|
-
|
172
|
-
def handle_error(e, message)
|
173
|
-
@errors << message
|
174
|
-
warn message
|
175
|
-
if @options[:debug]
|
176
|
-
puts e.message, e.backtrace
|
177
|
-
else
|
178
|
-
warn 'To see the complete backtrace run rubocop -d.'
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
134
|
# rubocop:disable MethodLength
|
183
135
|
def parse_options(args)
|
184
136
|
ignore_dropped_options(args)
|
@@ -306,23 +258,6 @@ module Rubocop
|
|
306
258
|
warn Rubocop::Version.version(true)
|
307
259
|
end
|
308
260
|
|
309
|
-
def autocorrect(buffer, cops)
|
310
|
-
return unless @options[:autocorrect]
|
311
|
-
|
312
|
-
corrections = cops.reduce([]) do |array, cop|
|
313
|
-
array.concat(cop.corrections)
|
314
|
-
array
|
315
|
-
end
|
316
|
-
|
317
|
-
corrector = Cop::Corrector.new(buffer, corrections)
|
318
|
-
new_source = corrector.rewrite
|
319
|
-
|
320
|
-
unless new_source == buffer.source
|
321
|
-
filename = buffer.instance_variable_get(:@name)
|
322
|
-
File.open(filename, 'w') { |f| f.write(new_source) }
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
261
|
private
|
327
262
|
|
328
263
|
def target_finder
|