rubocop 0.8.3 → 0.9.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/.travis.yml +0 -4
- data/.yardopts +2 -0
- data/CHANGELOG.md +70 -1
- data/README.md +101 -11
- data/config/default.yml +10 -2
- data/config/enabled.yml +85 -11
- data/lib/rubocop.rb +97 -73
- data/lib/rubocop/cli.rb +177 -92
- data/lib/rubocop/config.rb +56 -11
- data/lib/rubocop/config_store.rb +2 -0
- data/lib/rubocop/cop/cop.rb +52 -8
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +54 -0
- data/lib/rubocop/cop/lint/end_alignment.rb +180 -0
- data/lib/rubocop/cop/lint/end_in_method.rb +30 -0
- data/lib/rubocop/cop/lint/ensure_return.rb +22 -0
- data/lib/rubocop/cop/lint/eval.rb +22 -0
- data/lib/rubocop/cop/lint/handle_exceptions.rb +20 -0
- data/lib/rubocop/cop/lint/literal_in_condition.rb +63 -0
- data/lib/rubocop/cop/lint/loop.rb +29 -0
- data/lib/rubocop/cop/lint/rescue_exception.rb +29 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +33 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +35 -0
- data/lib/rubocop/cop/lint/unused_local_variable.rb +32 -0
- data/lib/rubocop/cop/lint/void.rb +58 -0
- data/lib/rubocop/cop/offence.rb +112 -12
- data/lib/rubocop/cop/rails/validation.rb +34 -0
- data/lib/rubocop/cop/style/access_control.rb +58 -0
- data/lib/rubocop/cop/style/alias.rb +28 -0
- data/lib/rubocop/cop/style/align_parameters.rb +39 -0
- data/lib/rubocop/cop/style/and_or.rb +45 -0
- data/lib/rubocop/cop/style/ascii_comments.rb +21 -0
- data/lib/rubocop/cop/style/ascii_identifiers.rb +22 -0
- data/lib/rubocop/cop/style/attr.rb +20 -0
- data/lib/rubocop/cop/style/avoid_class_vars.rb +20 -0
- data/lib/rubocop/cop/style/avoid_for.rb +18 -0
- data/lib/rubocop/cop/style/avoid_global_vars.rb +65 -0
- data/lib/rubocop/cop/style/avoid_perl_backrefs.rb +21 -0
- data/lib/rubocop/cop/style/avoid_perlisms.rb +50 -0
- data/lib/rubocop/cop/style/begin_block.rb +18 -0
- data/lib/rubocop/cop/style/block_comments.rb +20 -0
- data/lib/rubocop/cop/style/block_nesting.rb +47 -0
- data/lib/rubocop/cop/style/blocks.rb +27 -0
- data/lib/rubocop/cop/style/case_equality.rb +22 -0
- data/lib/rubocop/cop/style/case_indentation.rb +28 -0
- data/lib/rubocop/cop/style/character_literal.rb +37 -0
- data/lib/rubocop/cop/style/class_and_module_camel_case.rb +33 -0
- data/lib/rubocop/cop/style/class_methods.rb +22 -0
- data/lib/rubocop/cop/style/collection_methods.rb +37 -0
- data/lib/rubocop/cop/style/colon_method_call.rb +29 -0
- data/lib/rubocop/cop/style/constant_name.rb +31 -0
- data/lib/rubocop/cop/style/def_parentheses.rb +70 -0
- data/lib/rubocop/cop/style/documentation.rb +58 -0
- data/lib/rubocop/cop/style/dot_position.rb +25 -0
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +26 -0
- data/lib/rubocop/cop/style/empty_lines.rb +40 -0
- data/lib/rubocop/cop/style/empty_literal.rb +53 -0
- data/lib/rubocop/cop/style/encoding.rb +29 -0
- data/lib/rubocop/cop/style/end_block.rb +18 -0
- data/lib/rubocop/cop/style/end_of_line.rb +23 -0
- data/lib/rubocop/cop/style/favor_join.rb +29 -0
- data/lib/rubocop/cop/style/favor_modifier.rb +118 -0
- data/lib/rubocop/cop/style/favor_sprintf.rb +28 -0
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +54 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +47 -0
- data/lib/rubocop/cop/style/if_then_else.rb +80 -0
- data/lib/rubocop/cop/style/lambda.rb +47 -0
- data/lib/rubocop/cop/style/leading_comment_space.rb +25 -0
- data/lib/rubocop/cop/style/line_continuation.rb +26 -0
- data/lib/rubocop/cop/style/line_length.rb +30 -0
- data/lib/rubocop/cop/style/method_and_variable_snake_case.rb +61 -0
- data/lib/rubocop/cop/style/method_call_parentheses.rb +22 -0
- data/lib/rubocop/cop/style/method_length.rb +57 -0
- data/lib/rubocop/cop/style/not.rb +24 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +25 -0
- data/lib/rubocop/cop/{op_method.rb → style/op_method.rb} +4 -3
- data/lib/rubocop/cop/style/parameter_lists.rb +42 -0
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +42 -0
- data/lib/rubocop/cop/style/proc.rb +30 -0
- data/lib/rubocop/cop/style/reduce_arguments.rb +34 -0
- data/lib/rubocop/cop/style/regexp_literal.rb +39 -0
- data/lib/rubocop/cop/style/rescue_modifier.rb +55 -0
- data/lib/rubocop/cop/style/semicolon.rb +51 -0
- data/lib/rubocop/cop/style/single_line_methods.rb +48 -0
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +69 -0
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +32 -0
- data/lib/rubocop/cop/style/string_literals.rb +36 -0
- data/lib/rubocop/cop/style/surrounding_space.rb +314 -0
- data/lib/rubocop/cop/style/symbol_array.rb +31 -0
- data/lib/rubocop/cop/style/symbol_name.rb +27 -0
- data/lib/rubocop/cop/style/tab.rb +25 -0
- data/lib/rubocop/cop/style/ternary_operator.rb +49 -0
- data/lib/rubocop/cop/style/trailing_whitespace.rb +24 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +32 -0
- data/lib/rubocop/cop/style/unless_else.rb +26 -0
- data/lib/rubocop/cop/style/variable_interpolation.rb +32 -0
- data/lib/rubocop/cop/style/when_then.rb +25 -0
- data/lib/rubocop/cop/style/while_until_do.rb +45 -0
- data/lib/rubocop/cop/style/word_array.rb +44 -0
- data/lib/rubocop/cop/util.rb +1 -0
- data/lib/rubocop/cop/variable_inspector.rb +280 -0
- data/lib/rubocop/formatter/base_formatter.rb +119 -0
- data/lib/rubocop/formatter/clang_style_formatter.rb +21 -0
- data/lib/rubocop/formatter/emacs_style_formatter.rb +17 -0
- data/lib/rubocop/formatter/formatter_set.rb +77 -0
- data/lib/rubocop/formatter/json_formatter.rb +76 -0
- data/lib/rubocop/formatter/progress_formatter.rb +63 -0
- data/lib/rubocop/formatter/simple_text_formatter.rb +62 -0
- data/lib/rubocop/version.rb +15 -1
- data/rubocop.gemspec +1 -2
- data/spec/.rubocop.yml +5 -0
- data/spec/project_spec.rb +4 -7
- data/spec/rubocop/cli_spec.rb +383 -146
- data/spec/rubocop/config_spec.rb +61 -0
- data/spec/rubocop/config_store_spec.rb +2 -2
- data/spec/rubocop/cops/cop_spec.rb +14 -7
- data/spec/rubocop/cops/lint/assignment_in_condition_spec.rb +111 -0
- data/spec/rubocop/cops/lint/end_alignment_spec.rb +426 -0
- data/spec/rubocop/cops/lint/end_in_method_spec.rb +35 -0
- data/spec/rubocop/cops/lint/ensure_return_spec.rb +37 -0
- data/spec/rubocop/cops/lint/eval_spec.rb +41 -0
- data/spec/rubocop/cops/lint/handle_exceptions_spec.rb +36 -0
- data/spec/rubocop/cops/lint/literal_in_condition_spec.rb +35 -0
- data/spec/rubocop/cops/lint/loop_spec.rb +33 -0
- data/spec/rubocop/cops/lint/rescue_exception_spec.rb +127 -0
- data/spec/rubocop/cops/lint/shadowing_outer_local_variable_spec.rb +180 -0
- data/spec/rubocop/cops/lint/unreachable_code_spec.rb +69 -0
- data/spec/rubocop/cops/lint/unused_local_variable_spec.rb +484 -0
- data/spec/rubocop/cops/lint/void_spec.rb +63 -0
- data/spec/rubocop/cops/offence_spec.rb +107 -10
- data/spec/rubocop/cops/rails/validation_spec.rb +27 -0
- data/spec/rubocop/cops/style/access_control_spec.rb +142 -0
- data/spec/rubocop/cops/style/alias_spec.rb +47 -0
- data/spec/rubocop/cops/style/align_parameters_spec.rb +199 -0
- data/spec/rubocop/cops/style/and_or_spec.rb +39 -0
- data/spec/rubocop/cops/style/ascii_comments_spec.rb +28 -0
- data/spec/rubocop/cops/style/ascii_identifiers_spec.rb +28 -0
- data/spec/rubocop/cops/style/attr_spec.rb +20 -0
- data/spec/rubocop/cops/style/avoid_class_vars_spec.rb +27 -0
- data/spec/rubocop/cops/style/avoid_for_spec.rb +37 -0
- data/spec/rubocop/cops/style/avoid_global_vars_spec.rb +34 -0
- data/spec/rubocop/cops/style/avoid_perl_backrefs_spec.rb +20 -0
- data/spec/rubocop/cops/style/avoid_perlisms_spec.rb +47 -0
- data/spec/rubocop/cops/style/begin_block_spec.rb +19 -0
- data/spec/rubocop/cops/style/block_comments_spec.rb +27 -0
- data/spec/rubocop/cops/style/block_nesting_spec.rb +159 -0
- data/spec/rubocop/cops/style/blocks_spec.rb +35 -0
- data/spec/rubocop/cops/style/case_equality_spec.rb +18 -0
- data/spec/rubocop/cops/style/case_indentation_spec.rb +88 -0
- data/spec/rubocop/cops/style/character_literal_spec.rb +28 -0
- data/spec/rubocop/cops/style/class_and_module_camel_case_spec.rb +46 -0
- data/spec/rubocop/cops/style/class_methods_spec.rb +51 -0
- data/spec/rubocop/cops/style/collection_methods_spec.rb +46 -0
- data/spec/rubocop/cops/style/colon_method_call_spec.rb +55 -0
- data/spec/rubocop/cops/style/constant_name_spec.rb +56 -0
- data/spec/rubocop/cops/style/def_with_parentheses_spec.rb +40 -0
- data/spec/rubocop/cops/style/def_without_parentheses_spec.rb +34 -0
- data/spec/rubocop/cops/style/documentation_spec.rb +79 -0
- data/spec/rubocop/cops/style/dot_position_spec.rb +30 -0
- data/spec/rubocop/cops/style/empty_line_between_defs_spec.rb +85 -0
- data/spec/rubocop/cops/style/empty_lines_spec.rb +40 -0
- data/spec/rubocop/cops/style/empty_literal_spec.rb +91 -0
- data/spec/rubocop/cops/style/encoding_spec.rb +49 -0
- data/spec/rubocop/cops/style/end_block_spec.rb +19 -0
- data/spec/rubocop/cops/style/end_of_line_spec.rb +25 -0
- data/spec/rubocop/cops/style/favor_join_spec.rb +37 -0
- data/spec/rubocop/cops/style/favor_modifier_spec.rb +160 -0
- data/spec/rubocop/cops/style/favor_sprintf_spec.rb +53 -0
- data/spec/rubocop/cops/style/favor_unless_over_negated_if_spec.rb +64 -0
- data/spec/rubocop/cops/style/favor_until_over_negated_while_spec.rb +47 -0
- data/spec/rubocop/cops/style/hash_syntax_spec.rb +51 -0
- data/spec/rubocop/cops/style/if_with_semicolon_spec.rb +25 -0
- data/spec/rubocop/cops/style/lambda_spec.rb +45 -0
- data/spec/rubocop/cops/style/leading_comment_space_spec.rb +65 -0
- data/spec/rubocop/cops/style/line_continuation_spec.rb +26 -0
- data/spec/rubocop/cops/style/line_length_spec.rb +25 -0
- data/spec/rubocop/cops/style/method_and_variable_snake_case_spec.rb +95 -0
- data/spec/rubocop/cops/style/method_call_parentheses_spec.rb +25 -0
- data/spec/rubocop/cops/style/method_length_spec.rb +151 -0
- data/spec/rubocop/cops/style/multiline_if_then_spec.rb +81 -0
- data/spec/rubocop/cops/style/not_spec.rb +28 -0
- data/spec/rubocop/cops/style/numeric_literals_spec.rb +51 -0
- data/spec/rubocop/cops/style/one_line_conditional_spec.rb +18 -0
- data/spec/rubocop/cops/style/op_method_spec.rb +80 -0
- data/spec/rubocop/cops/style/parameter_lists_spec.rb +49 -0
- data/spec/rubocop/cops/style/parentheses_around_condition_spec.rb +59 -0
- data/spec/rubocop/cops/style/proc_spec.rb +28 -0
- data/spec/rubocop/cops/style/reduce_arguments_spec.rb +59 -0
- data/spec/rubocop/cops/style/regexp_literal_spec.rb +83 -0
- data/spec/rubocop/cops/style/rescue_modifier_spec.rb +122 -0
- data/spec/rubocop/cops/style/semicolon_spec.rb +95 -0
- data/spec/rubocop/cops/style/single_line_methods_spec.rb +54 -0
- data/spec/rubocop/cops/style/space_after_colon_spec.rb +29 -0
- data/spec/rubocop/cops/style/space_after_comma_spec.rb +31 -0
- data/spec/rubocop/cops/style/space_after_control_keyword_spec.rb +69 -0
- data/spec/rubocop/cops/style/space_after_semicolon_spec.rb +24 -0
- data/spec/rubocop/cops/style/space_around_braces_spec.rb +49 -0
- data/spec/rubocop/cops/style/space_around_equals_in_default_parameter_spec.rb +34 -0
- data/spec/rubocop/cops/style/space_around_operators_spec.rb +216 -0
- data/spec/rubocop/cops/style/space_inside_brackets_spec.rb +51 -0
- data/spec/rubocop/cops/style/space_inside_hash_literal_braces_spec.rb +99 -0
- data/spec/rubocop/cops/style/space_inside_parens_spec.rb +33 -0
- data/spec/rubocop/cops/style/string_literals_spec.rb +62 -0
- data/spec/rubocop/cops/style/symbol_array_spec.rb +45 -0
- data/spec/rubocop/cops/style/symbol_name_spec.rb +122 -0
- data/spec/rubocop/cops/style/tab_spec.rb +23 -0
- data/spec/rubocop/cops/style/ternary_operator_spec.rb +42 -0
- data/spec/rubocop/cops/style/trailing_whitespace_spec.rb +29 -0
- data/spec/rubocop/cops/style/trivial_accessors_spec.rb +338 -0
- data/spec/rubocop/cops/style/unless_else_spec.rb +31 -0
- data/spec/rubocop/cops/style/variable_interpolation_spec.rb +53 -0
- data/spec/rubocop/cops/style/when_then_spec.rb +40 -0
- data/spec/rubocop/cops/style/while_until_do_spec.rb +47 -0
- data/spec/rubocop/cops/style/word_array_spec.rb +61 -0
- data/spec/rubocop/cops/variable_inspector_spec.rb +374 -0
- data/spec/rubocop/formatter/base_formatter_spec.rb +190 -0
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +70 -0
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +32 -0
- data/spec/rubocop/formatter/formatter_set_spec.rb +132 -0
- data/spec/rubocop/formatter/json_formatter_spec.rb +142 -0
- data/spec/rubocop/formatter/progress_formatter_spec.rb +196 -0
- data/spec/rubocop/formatter/simple_text_formatter_spec.rb +74 -0
- data/spec/spec_helper.rb +23 -8
- data/spec/support/mri_syntax_checker.rb +69 -0
- data/spec/support/shared_examples.rb +33 -0
- metadata +315 -243
- data/lib/rubocop/cop/access_control.rb +0 -41
- data/lib/rubocop/cop/alias.rb +0 -17
- data/lib/rubocop/cop/align_parameters.rb +0 -37
- data/lib/rubocop/cop/and_or.rb +0 -36
- data/lib/rubocop/cop/ascii_comments.rb +0 -17
- data/lib/rubocop/cop/ascii_identifiers.rb +0 -19
- data/lib/rubocop/cop/avoid_class_vars.rb +0 -15
- data/lib/rubocop/cop/avoid_for.rb +0 -17
- data/lib/rubocop/cop/avoid_global_vars.rb +0 -61
- data/lib/rubocop/cop/avoid_perl_backrefs.rb +0 -17
- data/lib/rubocop/cop/avoid_perlisms.rb +0 -47
- data/lib/rubocop/cop/block_comments.rb +0 -17
- data/lib/rubocop/cop/block_nesting.rb +0 -35
- data/lib/rubocop/cop/blocks.rb +0 -23
- data/lib/rubocop/cop/case_indentation.rb +0 -22
- data/lib/rubocop/cop/class_and_module_camel_case.rb +0 -29
- data/lib/rubocop/cop/class_methods.rb +0 -15
- data/lib/rubocop/cop/collection_methods.rb +0 -29
- data/lib/rubocop/cop/colon_method_call.rb +0 -20
- data/lib/rubocop/cop/constant_name.rb +0 -24
- data/lib/rubocop/cop/def_parentheses.rb +0 -62
- data/lib/rubocop/cop/empty_line_between_defs.rb +0 -22
- data/lib/rubocop/cop/empty_lines.rb +0 -34
- data/lib/rubocop/cop/empty_literal.rb +0 -49
- data/lib/rubocop/cop/encoding.rb +0 -19
- data/lib/rubocop/cop/end_of_line.rb +0 -15
- data/lib/rubocop/cop/ensure_return.rb +0 -19
- data/lib/rubocop/cop/eval.rb +0 -19
- data/lib/rubocop/cop/favor_join.rb +0 -22
- data/lib/rubocop/cop/favor_modifier.rb +0 -92
- data/lib/rubocop/cop/favor_percent_r.rb +0 -19
- data/lib/rubocop/cop/favor_sprintf.rb +0 -21
- data/lib/rubocop/cop/favor_unless_over_negated_if.rb +0 -49
- data/lib/rubocop/cop/handle_exceptions.rb +0 -17
- data/lib/rubocop/cop/hash_syntax.rb +0 -41
- data/lib/rubocop/cop/if_then_else.rb +0 -75
- data/lib/rubocop/cop/lambda.rb +0 -42
- data/lib/rubocop/cop/leading_comment_space.rb +0 -19
- data/lib/rubocop/cop/line_continuation.rb +0 -15
- data/lib/rubocop/cop/line_length.rb +0 -23
- data/lib/rubocop/cop/loop.rb +0 -33
- data/lib/rubocop/cop/method_and_variable_snake_case.rb +0 -55
- data/lib/rubocop/cop/method_length.rb +0 -52
- data/lib/rubocop/cop/not.rb +0 -21
- data/lib/rubocop/cop/numeric_literals.rb +0 -21
- data/lib/rubocop/cop/parameter_lists.rb +0 -23
- data/lib/rubocop/cop/parentheses_around_condition.rb +0 -40
- data/lib/rubocop/cop/percent_r.rb +0 -19
- data/lib/rubocop/cop/proc.rb +0 -26
- data/lib/rubocop/cop/reduce_arguments.rb +0 -29
- data/lib/rubocop/cop/rescue_exception.rb +0 -26
- data/lib/rubocop/cop/rescue_modifier.rb +0 -15
- data/lib/rubocop/cop/semicolon.rb +0 -31
- data/lib/rubocop/cop/single_line_methods.rb +0 -44
- data/lib/rubocop/cop/space_after_comma_etc.rb +0 -62
- data/lib/rubocop/cop/space_after_control_keyword.rb +0 -29
- data/lib/rubocop/cop/string_literals.rb +0 -25
- data/lib/rubocop/cop/surrounding_space.rb +0 -285
- data/lib/rubocop/cop/symbol_array.rb +0 -31
- data/lib/rubocop/cop/symbol_name.rb +0 -23
- data/lib/rubocop/cop/syntax.rb +0 -49
- data/lib/rubocop/cop/tab.rb +0 -15
- data/lib/rubocop/cop/ternary_operator.rb +0 -43
- data/lib/rubocop/cop/trailing_whitespace.rb +0 -15
- data/lib/rubocop/cop/trivial_accessors.rb +0 -26
- data/lib/rubocop/cop/unless_else.rb +0 -23
- data/lib/rubocop/cop/variable_interpolation.rb +0 -29
- data/lib/rubocop/cop/when_then.rb +0 -17
- data/lib/rubocop/cop/word_array.rb +0 -37
- data/lib/rubocop/report/emacs_style.rb +0 -17
- data/lib/rubocop/report/plain_text.rb +0 -18
- data/lib/rubocop/report/report.rb +0 -44
- data/spec/rubocop/cops/access_control_spec.rb +0 -129
- data/spec/rubocop/cops/alias_spec.rb +0 -39
- data/spec/rubocop/cops/align_parameters_spec.rb +0 -197
- data/spec/rubocop/cops/and_or_spec.rb +0 -37
- data/spec/rubocop/cops/ascii_comments_spec.rb +0 -26
- data/spec/rubocop/cops/ascii_identifiers_spec.rb +0 -26
- data/spec/rubocop/cops/avoid_class_vars_spec.rb +0 -25
- data/spec/rubocop/cops/avoid_for_spec.rb +0 -35
- data/spec/rubocop/cops/avoid_global_vars_spec.rb +0 -32
- data/spec/rubocop/cops/avoid_perl_backrefs_spec.rb +0 -18
- data/spec/rubocop/cops/avoid_perlisms_spec.rb +0 -44
- data/spec/rubocop/cops/block_comments_spec.rb +0 -25
- data/spec/rubocop/cops/block_nesting_spec.rb +0 -148
- data/spec/rubocop/cops/blocks_spec.rb +0 -33
- data/spec/rubocop/cops/case_indentation_spec.rb +0 -86
- data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +0 -44
- data/spec/rubocop/cops/class_methods_spec.rb +0 -49
- data/spec/rubocop/cops/collection_methods_spec.rb +0 -44
- data/spec/rubocop/cops/colon_method_call_spec.rb +0 -53
- data/spec/rubocop/cops/constant_name_spec.rb +0 -42
- data/spec/rubocop/cops/def_with_parentheses_spec.rb +0 -38
- data/spec/rubocop/cops/def_without_parentheses_spec.rb +0 -32
- data/spec/rubocop/cops/empty_line_between_defs_spec.rb +0 -83
- data/spec/rubocop/cops/empty_lines_spec.rb +0 -38
- data/spec/rubocop/cops/empty_literal_spec.rb +0 -90
- data/spec/rubocop/cops/encoding_spec.rb +0 -47
- data/spec/rubocop/cops/end_of_line_spec.rb +0 -23
- data/spec/rubocop/cops/ensure_return_spec.rb +0 -35
- data/spec/rubocop/cops/eval_spec.rb +0 -39
- data/spec/rubocop/cops/favor_join_spec.rb +0 -35
- data/spec/rubocop/cops/favor_modifier_spec.rb +0 -146
- data/spec/rubocop/cops/favor_percent_r_spec.rb +0 -29
- data/spec/rubocop/cops/favor_sprintf_spec.rb +0 -51
- data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +0 -62
- data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +0 -45
- data/spec/rubocop/cops/handle_exceptions_spec.rb +0 -34
- data/spec/rubocop/cops/hash_syntax_spec.rb +0 -49
- data/spec/rubocop/cops/if_with_semicolon_spec.rb +0 -23
- data/spec/rubocop/cops/lambda_spec.rb +0 -43
- data/spec/rubocop/cops/leading_comment_space_spec.rb +0 -54
- data/spec/rubocop/cops/line_continuation_spec.rb +0 -24
- data/spec/rubocop/cops/line_length_spec.rb +0 -23
- data/spec/rubocop/cops/loop_spec.rb +0 -31
- data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +0 -93
- data/spec/rubocop/cops/method_length_spec.rb +0 -147
- data/spec/rubocop/cops/multiline_if_then_spec.rb +0 -79
- data/spec/rubocop/cops/not_spec.rb +0 -26
- data/spec/rubocop/cops/numeric_literals_spec.rb +0 -49
- data/spec/rubocop/cops/one_line_conditional_spec.rb +0 -16
- data/spec/rubocop/cops/op_method_spec.rb +0 -78
- data/spec/rubocop/cops/parameter_lists_spec.rb +0 -24
- data/spec/rubocop/cops/parentheses_around_condition_spec.rb +0 -61
- data/spec/rubocop/cops/percent_r_spec.rb +0 -29
- data/spec/rubocop/cops/proc_spec.rb +0 -26
- data/spec/rubocop/cops/reduce_arguments_spec.rb +0 -57
- data/spec/rubocop/cops/rescue_exception_spec.rb +0 -125
- data/spec/rubocop/cops/rescue_modifier_spec.rb +0 -37
- data/spec/rubocop/cops/semicolon_spec.rb +0 -88
- data/spec/rubocop/cops/single_line_methods_spec.rb +0 -50
- data/spec/rubocop/cops/space_after_colon_spec.rb +0 -27
- data/spec/rubocop/cops/space_after_comma_spec.rb +0 -29
- data/spec/rubocop/cops/space_after_control_keyword_spec.rb +0 -67
- data/spec/rubocop/cops/space_after_semicolon_spec.rb +0 -22
- data/spec/rubocop/cops/space_around_braces_spec.rb +0 -47
- data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +0 -32
- data/spec/rubocop/cops/space_around_operators_spec.rb +0 -209
- data/spec/rubocop/cops/space_inside_brackets_spec.rb +0 -49
- data/spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb +0 -86
- data/spec/rubocop/cops/space_inside_parens_spec.rb +0 -31
- data/spec/rubocop/cops/string_literals_spec.rb +0 -58
- data/spec/rubocop/cops/symbol_array_spec.rb +0 -41
- data/spec/rubocop/cops/symbol_name_spec.rb +0 -119
- data/spec/rubocop/cops/syntax_spec.rb +0 -41
- data/spec/rubocop/cops/tab_spec.rb +0 -21
- data/spec/rubocop/cops/ternary_operator_spec.rb +0 -40
- data/spec/rubocop/cops/trailing_whitespace_spec.rb +0 -27
- data/spec/rubocop/cops/trivial_accessors_spec.rb +0 -337
- data/spec/rubocop/cops/unless_else_spec.rb +0 -29
- data/spec/rubocop/cops/variable_interpolation_spec.rb +0 -49
- data/spec/rubocop/cops/when_then_spec.rb +0 -38
- data/spec/rubocop/cops/word_array_spec.rb +0 -47
- data/spec/rubocop/reports/emacs_style_spec.rb +0 -25
- data/spec/rubocop/reports/report_spec.rb +0 -29
data/lib/rubocop/cli.rb
CHANGED
@@ -6,6 +6,8 @@ module Rubocop
|
|
6
6
|
# The CLI is a class responsible of handling all the command line interface
|
7
7
|
# logic.
|
8
8
|
class CLI
|
9
|
+
DEFAULT_FORMATTER = 'progress'
|
10
|
+
|
9
11
|
# If set true while running,
|
10
12
|
# RuboCop will abort processing and exit gracefully.
|
11
13
|
attr_accessor :wants_to_quit
|
@@ -15,10 +17,8 @@ module Rubocop
|
|
15
17
|
|
16
18
|
def initialize
|
17
19
|
@cops = Cop::Cop.all
|
18
|
-
@processed_file_count = 0
|
19
|
-
@total_offences = 0
|
20
20
|
@errors = []
|
21
|
-
@options = {
|
21
|
+
@options = {}
|
22
22
|
ConfigStore.prepare
|
23
23
|
end
|
24
24
|
|
@@ -29,45 +29,42 @@ module Rubocop
|
|
29
29
|
def run(args = ARGV)
|
30
30
|
trap_interrupt
|
31
31
|
|
32
|
-
parse_options(args)
|
33
|
-
|
34
32
|
begin
|
35
|
-
|
36
|
-
rescue
|
37
|
-
puts e.message
|
33
|
+
parse_options(args)
|
34
|
+
rescue => e
|
35
|
+
$stderr.puts e.message
|
38
36
|
return 1
|
39
37
|
end
|
40
38
|
|
41
|
-
|
42
|
-
|
39
|
+
# filter out Rails cops unless requested
|
40
|
+
@cops.reject! { |cop_klass| cop_klass.rails? } unless @options[:rails]
|
43
41
|
|
44
|
-
|
45
|
-
|
42
|
+
target_files = target_files(args)
|
43
|
+
target_files.each(&:freeze).freeze
|
44
|
+
inspected_files = []
|
45
|
+
any_failed = false
|
46
46
|
|
47
|
-
|
47
|
+
formatter_set.started(target_files)
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
syntax_cop.inspect_file(file)
|
49
|
+
target_files.each do |file|
|
50
|
+
break if wants_to_quit?
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
unless syntax_cop.offences.map(&:severity).include?(:error)
|
56
|
-
inspect_file(file, config, report)
|
57
|
-
end
|
52
|
+
puts "Scanning #{file}" if @options[:debug]
|
53
|
+
formatter_set.file_started(file, {})
|
58
54
|
|
59
|
-
|
60
|
-
@total_offences += syntax_cop.offences.count
|
55
|
+
offences = inspect_file(file)
|
61
56
|
|
62
|
-
|
63
|
-
|
57
|
+
any_failed = true unless offences.empty?
|
58
|
+
inspected_files << file
|
59
|
+
formatter_set.file_finished(file, offences.freeze)
|
64
60
|
end
|
65
61
|
|
66
|
-
|
67
|
-
|
68
|
-
end
|
62
|
+
formatter_set.finished(inspected_files.freeze)
|
63
|
+
formatter_set.close_output_files
|
69
64
|
|
70
|
-
(@
|
65
|
+
display_error_summary(@errors) unless @options[:silent]
|
66
|
+
|
67
|
+
!any_failed && !wants_to_quit ? 0 : 1
|
71
68
|
end
|
72
69
|
|
73
70
|
def validate_only_option
|
@@ -76,44 +73,56 @@ module Rubocop
|
|
76
73
|
end
|
77
74
|
end
|
78
75
|
|
79
|
-
def inspect_file(file
|
76
|
+
def inspect_file(file)
|
80
77
|
begin
|
81
|
-
ast, comments, tokens, source =
|
82
|
-
|
83
|
-
|
84
|
-
rescue
|
85
|
-
ArgumentError => e
|
78
|
+
ast, comments, tokens, source_buffer, source, syntax_offences =
|
79
|
+
CLI.parse(file) { |sb| sb.read }
|
80
|
+
|
81
|
+
rescue Encoding::UndefinedConversionError, ArgumentError => e
|
86
82
|
handle_error(e, "An error occurred while parsing #{file}.".color(:red))
|
87
|
-
return
|
83
|
+
return []
|
88
84
|
end
|
89
85
|
|
86
|
+
# If we got any syntax errors, return only the syntax offences.
|
87
|
+
# Parser may return nil for AST even though there are no syntax errors.
|
88
|
+
# e.g. sources which contain only comments
|
89
|
+
return syntax_offences unless syntax_offences.empty?
|
90
|
+
|
91
|
+
config = ConfigStore.for(file)
|
90
92
|
disabled_lines = disabled_lines_in(source)
|
91
93
|
|
92
|
-
|
94
|
+
set_config_for_all_cops(config)
|
95
|
+
|
96
|
+
@cops.reduce([]) do |offences, cop_class|
|
93
97
|
cop_name = cop_class.cop_name
|
94
|
-
cop_class.config = config.for_cop(cop_name)
|
95
98
|
if config.cop_enabled?(cop_name)
|
96
|
-
cop = setup_cop(cop_class,
|
97
|
-
disabled_lines)
|
99
|
+
cop = setup_cop(cop_class, disabled_lines)
|
98
100
|
if !@options[:only] || @options[:only] == cop_name
|
99
101
|
begin
|
100
|
-
cop.inspect(source, tokens, ast, comments)
|
102
|
+
cop.inspect(source_buffer, source, tokens, ast, comments)
|
101
103
|
rescue => e
|
102
104
|
handle_error(e,
|
103
105
|
"An error occurred while #{cop.name}".color(:red) +
|
104
106
|
" cop was inspecting #{file}.".color(:red))
|
105
107
|
end
|
106
108
|
end
|
107
|
-
|
108
|
-
report << cop if cop.has_report?
|
109
|
+
offences.concat(cop.offences)
|
109
110
|
end
|
111
|
+
offences
|
112
|
+
end.sort
|
113
|
+
end
|
114
|
+
|
115
|
+
def set_config_for_all_cops(config)
|
116
|
+
@cops.each do |cop_class|
|
117
|
+
cop_class.config = config.for_cop(cop_class.cop_name)
|
110
118
|
end
|
111
119
|
end
|
112
120
|
|
113
|
-
def setup_cop(cop_class, disabled_lines)
|
121
|
+
def setup_cop(cop_class, disabled_lines = nil)
|
114
122
|
cop = cop_class.new
|
115
123
|
cop.debug = @options[:debug]
|
116
|
-
cop.
|
124
|
+
cop.autocorrect = @options[:autocorrect]
|
125
|
+
cop.disabled_lines = disabled_lines[cop_class.cop_name] if disabled_lines
|
117
126
|
cop
|
118
127
|
end
|
119
128
|
|
@@ -127,35 +136,83 @@ module Rubocop
|
|
127
136
|
end
|
128
137
|
end
|
129
138
|
|
139
|
+
# rubocop:disable MethodLength
|
130
140
|
def parse_options(args)
|
141
|
+
convert_deprecated_options!(args)
|
142
|
+
|
131
143
|
OptionParser.new do |opts|
|
132
144
|
opts.banner = 'Usage: rubocop [options] [file1, file2, ...]'
|
133
145
|
|
134
|
-
opts.on('-d', '--debug', 'Display debug info') do |d|
|
146
|
+
opts.on('-d', '--debug', 'Display debug info.') do |d|
|
135
147
|
@options[:debug] = d
|
136
148
|
end
|
137
|
-
opts.on('-
|
138
|
-
@options[:mode] = :emacs_style
|
139
|
-
end
|
140
|
-
opts.on('-c FILE', '--config FILE', 'Configuration file') do |f|
|
149
|
+
opts.on('-c', '--config FILE', 'Specify configuration file.') do |f|
|
141
150
|
@options[:config] = f
|
142
151
|
ConfigStore.set_options_config(@options[:config])
|
143
152
|
end
|
144
|
-
opts.on('--only COP', 'Run just one cop') do |s|
|
153
|
+
opts.on('--only COP', 'Run just one cop.') do |s|
|
145
154
|
@options[:only] = s
|
155
|
+
validate_only_option
|
156
|
+
end
|
157
|
+
opts.on('-f', '--format FORMATTER',
|
158
|
+
'Choose an output formatter. This option',
|
159
|
+
'can be specified multiple times to enable',
|
160
|
+
'multiple formatters at the same time.',
|
161
|
+
' [p]rogress (default)',
|
162
|
+
' [s]imple',
|
163
|
+
' [c]lang',
|
164
|
+
' [e]macs',
|
165
|
+
' [j]son',
|
166
|
+
' custom formatter class name') do |key|
|
167
|
+
@options[:formatters] ||= []
|
168
|
+
@options[:formatters] << [key]
|
169
|
+
end
|
170
|
+
opts.on('-o', '--out FILE',
|
171
|
+
'Write output to a file instead of STDOUT.',
|
172
|
+
'This option applies to the previously',
|
173
|
+
'specified --format, or the default format',
|
174
|
+
'if no format is specified.') do |path|
|
175
|
+
@options[:formatters] ||= [[DEFAULT_FORMATTER]]
|
176
|
+
@options[:formatters].last << path
|
177
|
+
end
|
178
|
+
opts.on('-r', '--require FILE', 'Require Ruby file.') do |f|
|
179
|
+
require f
|
180
|
+
end
|
181
|
+
opts.on('-R', '--rails', 'Run extra Rails cops.') do |r|
|
182
|
+
@options[:rails] = r
|
146
183
|
end
|
147
|
-
opts.on('-
|
184
|
+
opts.on('-a', '--auto-correct', 'Auto-correct offences.') do |a|
|
185
|
+
@options[:autocorrect] = a
|
186
|
+
end
|
187
|
+
opts.on('-s', '--silent', 'Silence summary.') do |s|
|
148
188
|
@options[:silent] = s
|
149
189
|
end
|
150
|
-
opts.on('-n', '--no-color', 'Disable color output') do |s|
|
190
|
+
opts.on('-n', '--no-color', 'Disable color output.') do |s|
|
151
191
|
Sickill::Rainbow.enabled = false
|
152
192
|
end
|
153
|
-
opts.on('-v', '--version', 'Display version') do
|
154
|
-
puts Rubocop::Version
|
193
|
+
opts.on('-v', '--version', 'Display version.') do
|
194
|
+
puts Rubocop::Version.version(false)
|
195
|
+
exit(0)
|
196
|
+
end
|
197
|
+
opts.on('-V', '--verbose-version', 'Display verbose version.') do
|
198
|
+
puts Rubocop::Version.version(true)
|
155
199
|
exit(0)
|
156
200
|
end
|
157
201
|
end.parse!(args)
|
158
202
|
end
|
203
|
+
# rubocop:enable MethodLength
|
204
|
+
|
205
|
+
def convert_deprecated_options!(args)
|
206
|
+
args.map! do |arg|
|
207
|
+
case arg
|
208
|
+
when '-e', '--emacs'
|
209
|
+
deprecate("#{arg} option", '--format emacs', '1.0.0')
|
210
|
+
%w(--format emacs)
|
211
|
+
else
|
212
|
+
arg
|
213
|
+
end
|
214
|
+
end.flatten!
|
215
|
+
end
|
159
216
|
|
160
217
|
def trap_interrupt
|
161
218
|
Signal.trap('INT') do
|
@@ -166,26 +223,15 @@ module Rubocop
|
|
166
223
|
end
|
167
224
|
end
|
168
225
|
|
169
|
-
def
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
end
|
179
|
-
puts "#{offences_string} detected"
|
180
|
-
.color(total_offences.zero? ? :green : :red)
|
181
|
-
|
182
|
-
if errors.count > 0
|
183
|
-
plural = errors.count > 1 ? 's' : ''
|
184
|
-
puts "\n#{errors.count} error#{plural} occurred:".color(:red)
|
185
|
-
errors.each { |error| puts error }
|
186
|
-
puts 'Errors are usually caused by RuboCop bugs.'
|
187
|
-
puts 'Please, report your problems to RuboCop\'s issue tracker.'
|
188
|
-
end
|
226
|
+
def display_error_summary(errors)
|
227
|
+
return if errors.empty?
|
228
|
+
plural = errors.count > 1 ? 's' : ''
|
229
|
+
puts "\n#{errors.count} error#{plural} occurred:".color(:red)
|
230
|
+
errors.each { |error| puts error }
|
231
|
+
puts 'Errors are usually caused by RuboCop bugs.'
|
232
|
+
puts 'Please, report your problems to RuboCop\'s issue tracker.'
|
233
|
+
puts 'Mention the following information in the issue report:'
|
234
|
+
puts Rubocop::Version.version(true)
|
189
235
|
end
|
190
236
|
|
191
237
|
def disabled_lines_in(source)
|
@@ -222,25 +268,41 @@ module Rubocop
|
|
222
268
|
def self.parse(file)
|
223
269
|
parser = Parser::CurrentRuby.new
|
224
270
|
|
225
|
-
|
226
|
-
|
271
|
+
# On JRuby and Rubinius, there's a risk that we hang in
|
272
|
+
# tokenize() if we don't set the all errors as fatal flag.
|
273
|
+
parser.diagnostics.all_errors_are_fatal = RUBY_ENGINE != 'ruby'
|
274
|
+
parser.diagnostics.ignore_warnings = false
|
227
275
|
|
276
|
+
diagnostics = []
|
228
277
|
parser.diagnostics.consumer = lambda do |diagnostic|
|
229
|
-
|
278
|
+
diagnostics << diagnostic
|
230
279
|
end
|
231
280
|
|
232
281
|
source_buffer = Parser::Source::Buffer.new(file, 1)
|
233
282
|
yield source_buffer
|
234
283
|
|
235
|
-
|
284
|
+
begin
|
285
|
+
ast, comments, tokens = parser.tokenize(source_buffer)
|
286
|
+
rescue Parser::SyntaxError # rubocop:disable HandleExceptions
|
287
|
+
# All errors are in diagnostics. No need to handle exception.
|
288
|
+
end
|
289
|
+
|
290
|
+
if tokens
|
291
|
+
tokens = tokens.map do |t|
|
292
|
+
type, details = *t
|
293
|
+
text, range = *details
|
294
|
+
Rubocop::Cop::Token.new(range, type, text)
|
295
|
+
end
|
296
|
+
end
|
236
297
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
Rubocop::Cop::Token.new(range, type, text)
|
298
|
+
syntax_offences = diagnostics.map do |d|
|
299
|
+
Cop::Offence.new(d.level, d.location, "#{d.message}",
|
300
|
+
'Syntax')
|
241
301
|
end
|
242
302
|
|
243
|
-
|
303
|
+
source = source_buffer.source.split($RS)
|
304
|
+
|
305
|
+
[ast, comments, tokens, source_buffer, source, syntax_offences]
|
244
306
|
end
|
245
307
|
|
246
308
|
# Generate a list of target files by expanding globing patterns
|
@@ -262,7 +324,7 @@ module Rubocop
|
|
262
324
|
end
|
263
325
|
end
|
264
326
|
|
265
|
-
files.uniq
|
327
|
+
files.map { |f| File.expand_path(f) }.uniq
|
266
328
|
end
|
267
329
|
|
268
330
|
# Finds all Ruby source files under the current or other supplied
|
@@ -274,13 +336,13 @@ module Rubocop
|
|
274
336
|
# @param root Root directory under which to search for ruby source files
|
275
337
|
# @return [Array] Array of filenames
|
276
338
|
def ruby_files(root = Dir.pwd)
|
277
|
-
files = Dir["#{root}/**/*"].
|
339
|
+
files = Dir["#{root}/**/*"].select { |file| FileTest.file?(file) }
|
278
340
|
|
279
341
|
rb = []
|
280
342
|
|
281
343
|
rb += files.select { |file| File.extname(file) == '.rb' }
|
282
344
|
rb += files.select do |file|
|
283
|
-
if File.extname(file) == ''
|
345
|
+
if File.extname(file) == '' && !excluded_file?(file)
|
284
346
|
begin
|
285
347
|
File.open(file) { |f| f.readline } =~ /#!.*ruby/
|
286
348
|
rescue EOFError, ArgumentError => e
|
@@ -295,10 +357,7 @@ module Rubocop
|
|
295
357
|
config.file_to_include?(file)
|
296
358
|
end
|
297
359
|
|
298
|
-
rb.reject
|
299
|
-
config = ConfigStore.for(file)
|
300
|
-
config.file_to_exclude?(file)
|
301
|
-
end.uniq
|
360
|
+
rb.reject { |file| excluded_file?(file) }.uniq
|
302
361
|
end
|
303
362
|
|
304
363
|
private
|
@@ -306,8 +365,34 @@ module Rubocop
|
|
306
365
|
def log_error(e, msg = '')
|
307
366
|
if @options[:debug]
|
308
367
|
error_message = "#{e.class}, #{e.message}"
|
309
|
-
|
368
|
+
warn "#{msg}\t#{error_message}"
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
def formatter_set
|
373
|
+
@formatter_set ||= begin
|
374
|
+
set = Formatter::FormatterSet.new(!@options[:silent])
|
375
|
+
pairs = @options[:formatters] || [[DEFAULT_FORMATTER]]
|
376
|
+
pairs.each do |formatter_key, output_path|
|
377
|
+
set.add_formatter(formatter_key, output_path)
|
378
|
+
end
|
379
|
+
set
|
380
|
+
rescue => error
|
381
|
+
warn error.message
|
382
|
+
exit(1)
|
310
383
|
end
|
311
384
|
end
|
385
|
+
|
386
|
+
def deprecate(subject, alternative = nil, version = nil)
|
387
|
+
message = "#{subject} is deprecated"
|
388
|
+
message << " and will be removed in RuboCop #{version}" if version
|
389
|
+
message << '.'
|
390
|
+
message << " Please use #{alternative} instead." if alternative
|
391
|
+
warn message
|
392
|
+
end
|
393
|
+
|
394
|
+
def excluded_file?(file)
|
395
|
+
ConfigStore.for(file).file_to_exclude?(file)
|
396
|
+
end
|
312
397
|
end
|
313
398
|
end
|
data/lib/rubocop/config.rb
CHANGED
@@ -5,6 +5,11 @@ require 'yaml'
|
|
5
5
|
require 'pathname'
|
6
6
|
|
7
7
|
module Rubocop
|
8
|
+
# This class represents the configuration of the RuboCop application
|
9
|
+
# and all its cops. A Config is associated with a YAML configuration
|
10
|
+
# file from which it was read. Several different Configs can be used
|
11
|
+
# during a run of the rubocop program, if files in several
|
12
|
+
# directories are inspected.
|
8
13
|
class Config < DelegateClass(Hash)
|
9
14
|
class ValidationError < StandardError; end
|
10
15
|
|
@@ -16,22 +21,43 @@ module Rubocop
|
|
16
21
|
|
17
22
|
class << self
|
18
23
|
def load_file(path)
|
24
|
+
path = File.absolute_path(path)
|
19
25
|
hash = YAML.load_file(path)
|
20
26
|
|
21
27
|
base_configs(path, hash['inherit_from']).reverse.each do |base_config|
|
22
28
|
base_config.each do |key, value|
|
23
29
|
if value.is_a?(Hash)
|
30
|
+
if key == 'AllCops' && value['Excludes']
|
31
|
+
correct_relative_excludes(value, base_config, path)
|
32
|
+
end
|
24
33
|
hash[key] = hash.has_key?(key) ? merge(value, hash[key]) : value
|
25
34
|
end
|
26
35
|
end
|
27
36
|
end
|
28
37
|
|
29
38
|
hash.delete('inherit_from')
|
30
|
-
config = new(hash,
|
39
|
+
config = new(hash, path)
|
31
40
|
config.warn_unless_valid
|
32
41
|
config
|
33
42
|
end
|
34
43
|
|
44
|
+
def correct_relative_excludes(all_cops, base_config, path)
|
45
|
+
all_cops['Excludes'].map! do |exclude_elem|
|
46
|
+
if exclude_elem.is_a?(String) && exclude_elem =~ %r([^/].*/)
|
47
|
+
rel_path = relative_path(base_config.loaded_path,
|
48
|
+
File.dirname(path))
|
49
|
+
rel_path.to_s.sub(/#{DOTFILE}$/, '') + exclude_elem
|
50
|
+
else
|
51
|
+
exclude_elem
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def relative_path(path, base)
|
57
|
+
path_name = Pathname.new(File.expand_path(path))
|
58
|
+
path_name.relative_path_from(Pathname.new(base)).to_s
|
59
|
+
end
|
60
|
+
|
35
61
|
# Return a recursive merge of two hashes. That is, a normal hash
|
36
62
|
# merge, with the addition that any value that is a hash, and
|
37
63
|
# occurs in both arguments, will also be merged. And so on.
|
@@ -72,21 +98,34 @@ module Rubocop
|
|
72
98
|
# user's home directory is checked. If there's no .rubocop.yml
|
73
99
|
# there either, the path to the default file is returned.
|
74
100
|
def configuration_file_for(target_dir)
|
75
|
-
|
76
|
-
File.join(dir, DOTFILE)
|
77
|
-
end
|
78
|
-
|
79
|
-
found_file = possible_config_files.find do |config_file|
|
80
|
-
File.exist?(config_file)
|
81
|
-
end
|
82
|
-
found_file || DEFAULT_FILE
|
101
|
+
config_files_in_path(target_dir).first || DEFAULT_FILE
|
83
102
|
end
|
84
103
|
|
85
104
|
def configuration_from_file(config_file)
|
86
105
|
config = load_file(config_file)
|
106
|
+
found_files = config_files_in_path(config_file)
|
107
|
+
if found_files.any? && found_files.last != config_file
|
108
|
+
add_excludes_from_higher_level(config, load_file(found_files.last))
|
109
|
+
end
|
87
110
|
merge_with_default(config, config_file)
|
88
111
|
end
|
89
112
|
|
113
|
+
def add_excludes_from_higher_level(config, highest_config)
|
114
|
+
if highest_config['AllCops'] && highest_config['AllCops']['Excludes']
|
115
|
+
config['AllCops'] ||= {}
|
116
|
+
config['AllCops']['Excludes'] ||= []
|
117
|
+
highest_config['AllCops']['Excludes'].each do |path|
|
118
|
+
unless path.is_a?(Regexp) || path.start_with?('/')
|
119
|
+
diff_in_level = config.loaded_path.count('/') -
|
120
|
+
highest_config.loaded_path.count('/')
|
121
|
+
path = '../' * diff_in_level + path
|
122
|
+
end
|
123
|
+
config['AllCops']['Excludes'] << path
|
124
|
+
end
|
125
|
+
config['AllCops']['Excludes'].uniq!
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
90
129
|
def default_configuration
|
91
130
|
@default_configuration ||= load_file(DEFAULT_FILE)
|
92
131
|
end
|
@@ -97,6 +136,13 @@ module Rubocop
|
|
97
136
|
|
98
137
|
private
|
99
138
|
|
139
|
+
def config_files_in_path(target)
|
140
|
+
possible_config_files = dirs_to_search(target).map do |dir|
|
141
|
+
File.join(dir, DOTFILE)
|
142
|
+
end
|
143
|
+
possible_config_files.select { |config_file| File.exist?(config_file) }
|
144
|
+
end
|
145
|
+
|
100
146
|
def dirs_to_search(target_dir)
|
101
147
|
dirs_to_search = []
|
102
148
|
target_dir_pathname = Pathname.new(File.expand_path(target_dir))
|
@@ -181,8 +227,7 @@ module Rubocop
|
|
181
227
|
|
182
228
|
def relative_path_to_loaded_dir(file)
|
183
229
|
return file unless loaded_path
|
184
|
-
|
185
|
-
file_pathname.relative_path_from(loaded_dir_pathname).to_s
|
230
|
+
Config.relative_path(file, loaded_dir_pathname)
|
186
231
|
end
|
187
232
|
|
188
233
|
def loaded_dir_pathname
|