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/rubocop.gemspec
CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.required_ruby_version = '>= 1.9.2'
|
12
12
|
s.authors = ['Bozhidar Batsov']
|
13
|
-
s.date = '2013-04-17'
|
14
13
|
s.description = <<-EOF
|
15
14
|
Automatic Ruby code style checking tool.
|
16
15
|
Aims to enforce the community-driven Ruby Style Guide.
|
@@ -28,7 +27,7 @@ Gem::Specification.new do |s|
|
|
28
27
|
s.summary = 'Automatic Ruby code style checking tool.'
|
29
28
|
|
30
29
|
s.add_runtime_dependency('rainbow', '>= 1.1.4')
|
31
|
-
s.add_runtime_dependency('parser',
|
30
|
+
s.add_runtime_dependency('parser', '2.0.0.beta9')
|
32
31
|
s.add_development_dependency('rake', '~> 10.0')
|
33
32
|
s.add_development_dependency('rspec', '~> 2.13')
|
34
33
|
s.add_development_dependency('yard', '~> 0.8')
|
data/spec/.rubocop.yml
ADDED
data/spec/project_spec.rb
CHANGED
@@ -3,25 +3,22 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe 'RuboCop Project' do
|
6
|
-
describe '
|
6
|
+
describe 'default configuration file' do
|
7
7
|
it 'has configuration for all cops' do
|
8
8
|
cop_names = Rubocop::Cop::Cop.all.map(&:cop_name)
|
9
|
-
expect(Rubocop::Config.load_file('.
|
9
|
+
expect(Rubocop::Config.load_file('config/default.yml').keys.sort)
|
10
10
|
.to eq((['AllCops'] + cop_names).sort)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe 'source codes'
|
14
|
+
describe 'source codes' do
|
15
15
|
before { $stdout = StringIO.new }
|
16
16
|
after { $stdout = STDOUT }
|
17
17
|
|
18
18
|
it 'has no violations' do
|
19
19
|
# Need to pass an empty array explicitly
|
20
20
|
# so that the CLI does not refer arguments of `rspec`
|
21
|
-
Rubocop::CLI.new.run([])
|
22
|
-
expect($stdout.string).to match(
|
23
|
-
/files inspected, no offences detected\n/
|
24
|
-
)
|
21
|
+
expect(Rubocop::CLI.new.run([])).to eq(0)
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
data/spec/rubocop/cli_spec.rb
CHANGED
@@ -9,21 +9,51 @@ module Rubocop
|
|
9
9
|
include FileHelper
|
10
10
|
|
11
11
|
let(:cli) { CLI.new }
|
12
|
-
|
13
|
-
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
$stdout = StringIO.new
|
15
|
+
$stderr = StringIO.new
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:each) do
|
19
|
+
$stdout = STDOUT
|
20
|
+
$stderr = STDERR
|
21
|
+
end
|
22
|
+
|
23
|
+
def abs(path)
|
24
|
+
File.expand_path(path)
|
25
|
+
end
|
14
26
|
|
15
27
|
it 'exits cleanly when -h is used' do
|
16
28
|
expect { cli.run ['-h'] }.to exit_with_code(0)
|
17
29
|
expect { cli.run ['--help'] }.to exit_with_code(0)
|
18
|
-
message =
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
30
|
+
message = <<-END
|
31
|
+
Usage: rubocop [options] [file1, file2, ...]
|
32
|
+
-d, --debug Display debug info.
|
33
|
+
-c, --config FILE Specify configuration file.
|
34
|
+
--only COP Run just one cop.
|
35
|
+
-f, --format FORMATTER Choose an output formatter. This option
|
36
|
+
can be specified multiple times to enable
|
37
|
+
multiple formatters at the same time.
|
38
|
+
[p]rogress (default)
|
39
|
+
[s]imple
|
40
|
+
[c]lang
|
41
|
+
[e]macs
|
42
|
+
[j]son
|
43
|
+
custom formatter class name
|
44
|
+
-o, --out FILE Write output to a file instead of STDOUT.
|
45
|
+
This option applies to the previously
|
46
|
+
specified --format, or the default format
|
47
|
+
if no format is specified.
|
48
|
+
-r, --require FILE Require Ruby file.
|
49
|
+
-R, --rails Run extra Rails cops.
|
50
|
+
-a, --auto-correct Auto-correct offences.
|
51
|
+
-s, --silent Silence summary.
|
52
|
+
-n, --no-color Disable color output.
|
53
|
+
-v, --version Display version.
|
54
|
+
-V, --verbose-version Display verbose version.
|
55
|
+
END
|
56
|
+
expect($stdout.string).to eq(message * 2)
|
27
57
|
end
|
28
58
|
|
29
59
|
it 'exits cleanly when -v is used' do
|
@@ -38,78 +68,65 @@ module Rubocop
|
|
38
68
|
end
|
39
69
|
end
|
40
70
|
|
41
|
-
|
71
|
+
describe '#trap_interrupt' do
|
42
72
|
before do
|
43
73
|
@interrupt_handlers = []
|
44
74
|
Signal.stub(:trap).with('INT') do |&block|
|
45
75
|
@interrupt_handlers << block
|
46
76
|
end
|
47
|
-
|
48
|
-
$stderr = StringIO.new
|
49
|
-
|
50
|
-
create_file('example.rb', '# encoding: utf-8')
|
51
|
-
end
|
52
|
-
|
53
|
-
after do
|
54
|
-
$stderr = STDERR
|
55
|
-
@cli_thread.terminate if @cli_thread
|
56
77
|
end
|
57
78
|
|
58
79
|
def interrupt
|
59
80
|
@interrupt_handlers.each(&:call)
|
60
81
|
end
|
61
82
|
|
62
|
-
|
63
|
-
@
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
# Wait for start.
|
68
|
-
loop { break unless $stdout.string.empty? }
|
69
|
-
|
70
|
-
@cli_thread
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'exits with status 1' do
|
74
|
-
cli_thread = cli_run_in_thread
|
75
|
-
interrupt
|
76
|
-
expect(cli_thread.value).to eq(1)
|
83
|
+
it 'adds a handler for SIGINT' do
|
84
|
+
expect(@interrupt_handlers).to be_empty
|
85
|
+
cli.trap_interrupt
|
86
|
+
expect(@interrupt_handlers).to have(1).item
|
77
87
|
end
|
78
88
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
89
|
+
context 'with SIGINT once' do
|
90
|
+
it 'sets #wants_to_quit? to true' do
|
91
|
+
cli.trap_interrupt
|
92
|
+
expect(cli.wants_to_quit?).to be_false
|
93
|
+
interrupt
|
94
|
+
expect(cli.wants_to_quit?).to be_true
|
95
|
+
end
|
85
96
|
|
86
|
-
|
87
|
-
|
88
|
-
|
97
|
+
it 'does not exit immediately' do
|
98
|
+
Object.any_instance.should_not_receive(:exit)
|
99
|
+
Object.any_instance.should_not_receive(:exit!)
|
100
|
+
cli.trap_interrupt
|
89
101
|
interrupt
|
90
|
-
cli_thread.join
|
91
|
-
expect($stdout.string).to match(/files? inspected/)
|
92
102
|
end
|
93
103
|
end
|
94
104
|
|
95
|
-
context 'with
|
105
|
+
context 'with SIGINT twice' do
|
96
106
|
it 'exits immediately' do
|
97
107
|
Object.any_instance.should_receive(:exit!).with(1)
|
98
|
-
|
108
|
+
cli.trap_interrupt
|
99
109
|
interrupt
|
100
110
|
interrupt
|
101
|
-
cli_thread.join
|
102
111
|
end
|
103
112
|
end
|
104
113
|
end
|
105
114
|
|
115
|
+
context 'when #wants_to_quit? is true' do
|
116
|
+
it 'returns 1' do
|
117
|
+
create_file('example.rb', '# encoding: utf-8')
|
118
|
+
cli.wants_to_quit = true
|
119
|
+
expect(cli.run(['example.rb'])).to eq(1)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
106
123
|
it 'checks a given correct file and returns 0' do
|
107
124
|
create_file('example.rb', [
|
108
125
|
'# encoding: utf-8',
|
109
126
|
'x = 0',
|
110
127
|
'puts x'
|
111
128
|
])
|
112
|
-
expect(cli.run(['example.rb'])).to eq(0)
|
129
|
+
expect(cli.run(['--format', 'simple', 'example.rb'])).to eq(0)
|
113
130
|
expect($stdout.string)
|
114
131
|
.to eq("\n1 file inspected, no offences detected\n")
|
115
132
|
end
|
@@ -120,10 +137,10 @@ module Rubocop
|
|
120
137
|
'x = 0 ',
|
121
138
|
'puts x'
|
122
139
|
])
|
123
|
-
expect(cli.run(['example.rb'])).to eq(1)
|
140
|
+
expect(cli.run(['--format', 'simple', 'example.rb'])).to eq(1)
|
124
141
|
expect($stdout.string)
|
125
142
|
.to eq ['== example.rb ==',
|
126
|
-
'C: 2: Trailing whitespace detected.',
|
143
|
+
'C: 2: 6: Trailing whitespace detected.',
|
127
144
|
'',
|
128
145
|
'1 file inspected, 1 offence detected',
|
129
146
|
''].join("\n")
|
@@ -139,15 +156,17 @@ module Rubocop
|
|
139
156
|
"\tx = 0",
|
140
157
|
'puts x'
|
141
158
|
])
|
142
|
-
expect(cli.run(['--emacs', 'example1.rb', 'example2.rb']))
|
159
|
+
expect(cli.run(['--format', 'emacs', 'example1.rb', 'example2.rb']))
|
160
|
+
.to eq(1)
|
143
161
|
expect($stdout.string)
|
144
162
|
.to eq(
|
145
|
-
['example1.rb:1: C: Missing utf-8 encoding comment.
|
146
|
-
'example1.rb:1: C:
|
147
|
-
"
|
148
|
-
'example1.rb:
|
149
|
-
'
|
150
|
-
'example2.rb:1: C:
|
163
|
+
["#{abs('example1.rb')}:1:1: C: Missing utf-8 encoding comment.",
|
164
|
+
"#{abs('example1.rb')}:1:2: C: Surrounding space missing" +
|
165
|
+
" for operator '='.",
|
166
|
+
"#{abs('example1.rb')}:1:5: C: Trailing whitespace detected.",
|
167
|
+
"#{abs('example1.rb')}:2:2: C: Trailing whitespace detected.",
|
168
|
+
"#{abs('example2.rb')}:1:1: C: Missing utf-8 encoding comment.",
|
169
|
+
"#{abs('example2.rb')}:1:1: C: Tab detected.",
|
151
170
|
'',
|
152
171
|
'2 files inspected, 6 offences detected',
|
153
172
|
''].join("\n"))
|
@@ -163,18 +182,55 @@ module Rubocop
|
|
163
182
|
"\tx = 0",
|
164
183
|
'puts x'
|
165
184
|
])
|
166
|
-
expect(cli.run(['--emacs', 'example1.rb', 'example2.rb']))
|
185
|
+
expect(cli.run(['--format', 'emacs', 'example1.rb', 'example2.rb']))
|
186
|
+
.to eq(1)
|
167
187
|
expect($stdout.string)
|
168
188
|
.to eq(
|
169
|
-
['example1.rb:1: C:
|
170
|
-
"
|
171
|
-
'example1.rb:
|
172
|
-
'
|
189
|
+
["#{abs('example1.rb')}:1:2: C: Surrounding space missing" +
|
190
|
+
" for operator '='.",
|
191
|
+
"#{abs('example1.rb')}:1:5: C: Trailing whitespace detected.",
|
192
|
+
"#{abs('example1.rb')}:2:2: C: Trailing whitespace detected.",
|
193
|
+
"#{abs('example2.rb')}:1:1: C: Tab detected.",
|
173
194
|
'',
|
174
195
|
'2 files inspected, 4 offences detected',
|
175
196
|
''].join("\n"))
|
176
197
|
end
|
177
198
|
|
199
|
+
it 'can report in clang style' do
|
200
|
+
create_file('example1.rb', ['# encoding: utf-8',
|
201
|
+
'x= 0 ',
|
202
|
+
'#' * 85,
|
203
|
+
'y ',
|
204
|
+
'puts x'])
|
205
|
+
create_file('example2.rb', ['# encoding: utf-8',
|
206
|
+
"\tx = 0",
|
207
|
+
'puts x'])
|
208
|
+
expect(cli.run(['--format', 'clang', 'example1.rb', 'example2.rb']))
|
209
|
+
.to eq(1)
|
210
|
+
expect($stdout.string)
|
211
|
+
.to eq(['example1.rb:2:2: C: Surrounding space missing for operator ' +
|
212
|
+
"'='.",
|
213
|
+
'x= 0 ',
|
214
|
+
' ^',
|
215
|
+
'example1.rb:2:5: C: Trailing whitespace detected.',
|
216
|
+
'x= 0 ',
|
217
|
+
' ^',
|
218
|
+
'example1.rb:3:80: C: Line is too long. [85/79]',
|
219
|
+
'###########################################################' +
|
220
|
+
'##########################',
|
221
|
+
' ' +
|
222
|
+
' ^^^^^^',
|
223
|
+
'example1.rb:4:2: C: Trailing whitespace detected.',
|
224
|
+
'y ',
|
225
|
+
' ^',
|
226
|
+
'example2.rb:2:1: C: Tab detected.',
|
227
|
+
"\tx = 0",
|
228
|
+
'^',
|
229
|
+
'',
|
230
|
+
'2 files inspected, 5 offences detected',
|
231
|
+
''].join("\n"))
|
232
|
+
end
|
233
|
+
|
178
234
|
it 'runs just one cop if --only is passed' do
|
179
235
|
create_file('example.rb', ['if x== 0 ',
|
180
236
|
"\ty",
|
@@ -182,12 +238,13 @@ module Rubocop
|
|
182
238
|
# IfUnlessModifier depends on the configuration of LineLength.
|
183
239
|
# That configuration might have been set by other spec examples
|
184
240
|
# so we reset it to emulate a start from scratch.
|
185
|
-
Cop::LineLength.config = nil
|
241
|
+
Cop::Style::LineLength.config = nil
|
186
242
|
|
187
|
-
expect(cli.run(['--
|
243
|
+
expect(cli.run(['--format', 'simple',
|
244
|
+
'--only', 'IfUnlessModifier', 'example.rb'])).to eq(1)
|
188
245
|
expect($stdout.string)
|
189
246
|
.to eq(['== example.rb ==',
|
190
|
-
'C: 1: Favor modifier if/unless usage when you have a ' +
|
247
|
+
'C: 1: 1: Favor modifier if/unless usage when you have a ' +
|
191
248
|
'single-line body. Another good alternative is the usage of ' +
|
192
249
|
'control flow &&/||.',
|
193
250
|
'',
|
@@ -197,45 +254,48 @@ module Rubocop
|
|
197
254
|
|
198
255
|
it 'exits with error if an incorrect cop name is passed to --only' do
|
199
256
|
expect(cli.run(%w(--only 123))).to eq(1)
|
200
|
-
expect($
|
257
|
+
expect($stderr.string).to eq("Unrecognized cop name: 123.\n")
|
201
258
|
end
|
202
259
|
|
203
260
|
it 'ommits summary when --silent passed', ruby: 1.9 do
|
204
261
|
create_file('example1.rb', 'puts 0 ')
|
205
262
|
create_file('example2.rb', "\tputs 0")
|
206
|
-
expect(cli.run(['--
|
263
|
+
expect(cli.run(['--format',
|
264
|
+
'emacs',
|
207
265
|
'--silent',
|
208
266
|
'example1.rb',
|
209
267
|
'example2.rb'])).to eq(1)
|
210
268
|
expect($stdout.string).to eq(
|
211
|
-
['example1.rb:1: C: Missing utf-8 encoding comment.
|
212
|
-
'example1.rb:1: C: Trailing whitespace detected.
|
213
|
-
'example2.rb:1: C: Missing utf-8 encoding comment.
|
214
|
-
'example2.rb:1: C: Tab detected.
|
269
|
+
["#{abs('example1.rb')}:1:1: C: Missing utf-8 encoding comment.",
|
270
|
+
"#{abs('example1.rb')}:1:7: C: Trailing whitespace detected.",
|
271
|
+
"#{abs('example2.rb')}:1:1: C: Missing utf-8 encoding comment.",
|
272
|
+
"#{abs('example2.rb')}:1:1: C: Tab detected.",
|
215
273
|
''].join("\n"))
|
216
274
|
end
|
217
275
|
|
218
276
|
it 'ommits summary when --silent passed', ruby: 2.0 do
|
219
277
|
create_file('example1.rb', 'puts 0 ')
|
220
278
|
create_file('example2.rb', "\tputs 0")
|
221
|
-
expect(cli.run(['--
|
279
|
+
expect(cli.run(['--format',
|
280
|
+
'emacs',
|
222
281
|
'--silent',
|
223
282
|
'example1.rb',
|
224
283
|
'example2.rb'])).to eq(1)
|
225
284
|
expect($stdout.string).to eq(
|
226
|
-
['example1.rb:1: C: Trailing whitespace detected.
|
227
|
-
'example2.rb:1: C: Tab detected.
|
285
|
+
["#{abs('example1.rb')}:1:7: C: Trailing whitespace detected.",
|
286
|
+
"#{abs('example2.rb')}:1:1: C: Tab detected.",
|
228
287
|
''].join("\n"))
|
229
288
|
end
|
230
289
|
|
231
290
|
it 'shows cop names when --debug is passed', ruby: 2.0 do
|
232
291
|
create_file('example1.rb', "\tputs 0")
|
233
|
-
expect(cli.run(['--
|
292
|
+
expect(cli.run(['--format',
|
293
|
+
'emacs',
|
234
294
|
'--silent',
|
235
295
|
'--debug',
|
236
296
|
'example1.rb'])).to eq(1)
|
237
297
|
expect($stdout.string.lines[-1]).to eq(
|
238
|
-
['example1.rb:1: C: Tab: Tab detected.
|
298
|
+
["#{abs('example1.rb')}:1:1: C: Tab: Tab detected.",
|
239
299
|
''].join("\n"))
|
240
300
|
end
|
241
301
|
|
@@ -248,10 +308,11 @@ module Rubocop
|
|
248
308
|
'CaseIndentation:',
|
249
309
|
' Enabled: false'
|
250
310
|
])
|
251
|
-
expect(cli.run(['
|
311
|
+
expect(cli.run(['--format', 'simple',
|
312
|
+
'-c', 'rubocop.yml', 'example1.rb'])).to eq(1)
|
252
313
|
expect($stdout.string).to eq(
|
253
314
|
['== example1.rb ==',
|
254
|
-
'C: 1: Trailing whitespace detected.',
|
315
|
+
'C: 1: 7: Trailing whitespace detected.',
|
255
316
|
'',
|
256
317
|
'1 file inspected, 1 offence detected',
|
257
318
|
''].join("\n"))
|
@@ -268,11 +329,13 @@ module Rubocop
|
|
268
329
|
'LineLength:',
|
269
330
|
' Enabled: false'
|
270
331
|
])
|
271
|
-
result = cli.run(['
|
332
|
+
result = cli.run(['--format', 'simple',
|
333
|
+
'-c', 'rubocop.yml', 'example1.rb'])
|
272
334
|
expect($stdout.string).to eq(
|
273
335
|
['== example1.rb ==',
|
274
|
-
'C: 1: Favor modifier if/unless usage when you have a
|
275
|
-
'body. Another good alternative is the usage of
|
336
|
+
'C: 1: 1: Favor modifier if/unless usage when you have a ' +
|
337
|
+
'single-line body. Another good alternative is the usage of ' +
|
338
|
+
'control flow &&/||.',
|
276
339
|
'',
|
277
340
|
'1 file inspected, 1 offence detected',
|
278
341
|
''].join("\n"))
|
@@ -288,10 +351,11 @@ module Rubocop
|
|
288
351
|
'CaseIndentation:',
|
289
352
|
' Enabled: false'
|
290
353
|
])
|
291
|
-
expect(cli.run(['
|
354
|
+
expect(cli.run(['--format', 'simple',
|
355
|
+
'example_src/example1.rb'])).to eq(1)
|
292
356
|
expect($stdout.string).to eq(
|
293
357
|
['== example_src/example1.rb ==',
|
294
|
-
'C: 1: Trailing whitespace detected.',
|
358
|
+
'C: 1: 7: Trailing whitespace detected.',
|
295
359
|
'',
|
296
360
|
'1 file inspected, 1 offence detected',
|
297
361
|
''].join("\n"))
|
@@ -307,7 +371,8 @@ module Rubocop
|
|
307
371
|
' Enabled: true',
|
308
372
|
' Max: 100'
|
309
373
|
])
|
310
|
-
expect(cli.run(['
|
374
|
+
expect(cli.run(['--format', 'simple',
|
375
|
+
'example_src/example1.rb'])).to eq(0)
|
311
376
|
expect($stdout.string).to eq(
|
312
377
|
['', '1 file inspected, no offences detected',
|
313
378
|
''].join("\n"))
|
@@ -325,10 +390,10 @@ module Rubocop
|
|
325
390
|
' Enabled: true',
|
326
391
|
' Max: 100'
|
327
392
|
])
|
328
|
-
expect(cli.run(
|
393
|
+
expect(cli.run(%w(--format simple example))).to eq(1)
|
329
394
|
expect($stdout.string).to eq(
|
330
395
|
['== example/lib/example1.rb ==',
|
331
|
-
'C: 2: Line is too long. [90/79]',
|
396
|
+
'C: 2: 80: Line is too long. [90/79]',
|
332
397
|
'',
|
333
398
|
'2 files inspected, 1 offence detected',
|
334
399
|
''].join("\n"))
|
@@ -349,7 +414,8 @@ module Rubocop
|
|
349
414
|
' Enabled: true',
|
350
415
|
' Max: 80'
|
351
416
|
])
|
352
|
-
expect(cli.run(['
|
417
|
+
expect(cli.run(['--format', 'simple',
|
418
|
+
'example_src/example1.rb'])).to eq(0)
|
353
419
|
expect($stdout.string).to eq(
|
354
420
|
['', '1 file inspected, no offences detected',
|
355
421
|
''].join("\n"))
|
@@ -371,10 +437,10 @@ module Rubocop
|
|
371
437
|
' - tmp/spec/**'
|
372
438
|
])
|
373
439
|
|
374
|
-
expect(cli.run(
|
440
|
+
expect(cli.run(%w(--format simple example))).to eq(1)
|
375
441
|
expect($stdout.string).to eq(
|
376
442
|
['== example/tmp/test/example1.rb ==',
|
377
|
-
'C: 2: Line is too long. [90/79]',
|
443
|
+
'C: 2: 80: Line is too long. [90/79]',
|
378
444
|
'',
|
379
445
|
'1 file inspected, 1 offence detected',
|
380
446
|
''].join("\n"))
|
@@ -392,12 +458,12 @@ module Rubocop
|
|
392
458
|
' Max: 100'
|
393
459
|
])
|
394
460
|
|
395
|
-
expect(cli.run(
|
461
|
+
expect(cli.run(%w(--format simple example))).to eq(1)
|
396
462
|
expect($stdout.string).to eq(
|
397
463
|
['Warning: unrecognized cop LyneLenth found in ' +
|
398
464
|
File.expand_path('example/.rubocop.yml'),
|
399
465
|
'== example/example1.rb ==',
|
400
|
-
'C: 2: Line is too long. [90/79]',
|
466
|
+
'C: 2: 80: Line is too long. [90/79]',
|
401
467
|
'',
|
402
468
|
'1 file inspected, 1 offence detected',
|
403
469
|
''].join("\n"))
|
@@ -415,41 +481,52 @@ module Rubocop
|
|
415
481
|
' Min: 10'
|
416
482
|
])
|
417
483
|
|
418
|
-
expect(cli.run(
|
484
|
+
expect(cli.run(%w(--format simple example))).to eq(1)
|
419
485
|
expect($stdout.string).to eq(
|
420
486
|
['Warning: unrecognized parameter LineLength:Min found in ' +
|
421
487
|
File.expand_path('example/.rubocop.yml'),
|
422
488
|
'== example/example1.rb ==',
|
423
|
-
'C: 2: Line is too long. [90/79]',
|
489
|
+
'C: 2: 80: Line is too long. [90/79]',
|
424
490
|
'',
|
425
491
|
'1 file inspected, 1 offence detected',
|
426
492
|
''].join("\n"))
|
427
493
|
end
|
428
494
|
|
429
495
|
it 'registers an offence for a syntax error' do
|
430
|
-
pending
|
431
496
|
create_file('example.rb', [
|
432
497
|
'# encoding: utf-8',
|
433
498
|
'class Test',
|
434
499
|
'en'
|
435
500
|
])
|
436
|
-
expect(cli.run(['--emacs', 'example.rb'])).to eq(1)
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
501
|
+
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
|
502
|
+
expect($stdout.string)
|
503
|
+
.to eq(["#{abs('example.rb')}:3:3: E: unexpected " +
|
504
|
+
'token $end',
|
505
|
+
'',
|
506
|
+
'1 file inspected, 1 offence detected',
|
507
|
+
''].join("\n"))
|
508
|
+
end
|
509
|
+
|
510
|
+
it 'registers an offence for Parser warnings' do
|
511
|
+
create_file('example.rb', [
|
512
|
+
'# encoding: utf-8',
|
513
|
+
'puts *test'
|
514
|
+
])
|
515
|
+
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
|
516
|
+
expect($stdout.string)
|
517
|
+
.to eq(["#{abs('example.rb')}:2:6: W: " +
|
518
|
+
"`*' interpreted as argument prefix",
|
519
|
+
'',
|
520
|
+
'1 file inspected, 1 offence detected',
|
521
|
+
''].join("\n"))
|
444
522
|
end
|
445
523
|
|
446
524
|
it 'can process a file with an invalid UTF-8 byte sequence' do
|
447
|
-
pending
|
448
525
|
create_file('example.rb', [
|
449
526
|
'# encoding: utf-8',
|
450
527
|
"# #{'f9'.hex.chr}#{'29'.hex.chr}"
|
451
528
|
])
|
452
|
-
expect(cli.run(['--emacs', 'example.rb'])).to eq(0)
|
529
|
+
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(0)
|
453
530
|
end
|
454
531
|
|
455
532
|
it 'can have all cops disabled in a code section' do
|
@@ -466,13 +543,13 @@ module Rubocop
|
|
466
543
|
' y("123")',
|
467
544
|
'end'
|
468
545
|
])
|
469
|
-
expect(cli.run(['--emacs', 'example.rb'])).to eq(1)
|
546
|
+
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
|
470
547
|
# all cops were disabled, then 2 were enabled again, so we
|
471
548
|
# should get 2 offences reported.
|
472
549
|
expect($stdout.string).to eq(
|
473
|
-
['example.rb:8: C: Line is too long. [95/79]
|
474
|
-
"example.rb:10: C: Prefer single-quoted strings when
|
475
|
-
'need string interpolation or special symbols.
|
550
|
+
["#{abs('example.rb')}:8:80: C: Line is too long. [95/79]",
|
551
|
+
"#{abs('example.rb')}:10:5: C: Prefer single-quoted strings when " +
|
552
|
+
"you don't need string interpolation or special symbols.",
|
476
553
|
'',
|
477
554
|
'1 file inspected, 2 offences detected',
|
478
555
|
''].join("\n"))
|
@@ -492,13 +569,13 @@ module Rubocop
|
|
492
569
|
' y("123")',
|
493
570
|
'end'
|
494
571
|
])
|
495
|
-
expect(cli.run(['--emacs', 'example.rb'])).to eq(1)
|
572
|
+
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
|
496
573
|
# 3 cops were disabled, then 2 were enabled again, so we
|
497
574
|
# should get 2 offences reported.
|
498
575
|
expect($stdout.string).to eq(
|
499
|
-
['example.rb:8: C: Line is too long. [95/79]
|
500
|
-
"example.rb:10: C: Prefer single-quoted strings when
|
501
|
-
'need string interpolation or special symbols.
|
576
|
+
["#{abs('example.rb')}:8:80: C: Line is too long. [95/79]",
|
577
|
+
"#{abs('example.rb')}:10:5: C: Prefer single-quoted strings when " +
|
578
|
+
"you don't need string interpolation or special symbols.",
|
502
579
|
'',
|
503
580
|
'1 file inspected, 2 offences detected',
|
504
581
|
''].join("\n"))
|
@@ -509,7 +586,7 @@ module Rubocop
|
|
509
586
|
'# encoding: utf-8',
|
510
587
|
'y("123", 123456) # rubocop:disable all'
|
511
588
|
])
|
512
|
-
expect(cli.run(['--emacs', 'example.rb'])).to eq(0)
|
589
|
+
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(0)
|
513
590
|
expect($stdout.string).to eq(
|
514
591
|
['',
|
515
592
|
'1 file inspected, no offences detected',
|
@@ -523,9 +600,9 @@ module Rubocop
|
|
523
600
|
'#' * 95,
|
524
601
|
'y("123") # rubocop:disable LineLength,StringLiterals'
|
525
602
|
])
|
526
|
-
expect(cli.run(['--emacs', 'example.rb'])).to eq(1)
|
603
|
+
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
|
527
604
|
expect($stdout.string).to eq(
|
528
|
-
['example.rb:3: C: Line is too long. [95/79]
|
605
|
+
["#{abs('example.rb')}:3:80: C: Line is too long. [95/79]",
|
529
606
|
'',
|
530
607
|
'1 file inspected, 1 offence detected',
|
531
608
|
''].join("\n"))
|
@@ -538,9 +615,7 @@ module Rubocop
|
|
538
615
|
'x = 0',
|
539
616
|
'puts x'
|
540
617
|
])
|
541
|
-
|
542
|
-
# so that the CLI does not refer arguments of `rspec`
|
543
|
-
expect(cli.run([])).to eq(0)
|
618
|
+
expect(cli.run(%w(--format simple))).to eq(0)
|
544
619
|
expect($stdout.string).to eq(
|
545
620
|
['', '1 file inspected, no offences detected',
|
546
621
|
''].join("\n"))
|
@@ -563,9 +638,7 @@ module Rubocop
|
|
563
638
|
' - example',
|
564
639
|
' - !ruby/regexp /regexp$/'
|
565
640
|
])
|
566
|
-
|
567
|
-
# so that the CLI does not refer arguments of `rspec`
|
568
|
-
expect(cli.run([])).to eq(0)
|
641
|
+
expect(cli.run(%w(--format simple))).to eq(0)
|
569
642
|
expect($stdout.string).to eq(
|
570
643
|
['', '2 files inspected, no offences detected',
|
571
644
|
''].join("\n"))
|
@@ -595,37 +668,201 @@ module Rubocop
|
|
595
668
|
' - !ruby/regexp /regexp.rb$/',
|
596
669
|
' - "exclude_*"'
|
597
670
|
])
|
598
|
-
|
599
|
-
|
600
|
-
|
671
|
+
expect(cli.run(%w(--format simple))).to eq(0)
|
672
|
+
expect($stdout.string).to eq(
|
673
|
+
['', '0 files inspected, no offences detected',
|
674
|
+
''].join("\n"))
|
675
|
+
end
|
676
|
+
|
677
|
+
# With rubinius 2.0.0.rc1 + rspec 2.13.1,
|
678
|
+
# File.stub(:open).and_call_original causes SystemStackError.
|
679
|
+
it 'does not read files in excluded list', broken: :rbx do
|
680
|
+
%w(rb.rb non-rb.ext without-ext).each do |filename|
|
681
|
+
create_file("example/ignored/#{filename}", [
|
682
|
+
'# encoding: utf-8',
|
683
|
+
'#' * 90
|
684
|
+
])
|
685
|
+
end
|
686
|
+
|
687
|
+
create_file('example/.rubocop.yml', [
|
688
|
+
'AllCops:',
|
689
|
+
' Excludes:',
|
690
|
+
' - ignored/**',
|
691
|
+
])
|
692
|
+
File.should_not_receive(:open).with(%r(/ignored/))
|
693
|
+
File.stub(:open).and_call_original
|
694
|
+
expect(cli.run(%w(--format simple example))).to eq(0)
|
601
695
|
expect($stdout.string).to eq(
|
602
696
|
['', '0 files inspected, no offences detected',
|
603
697
|
''].join("\n"))
|
604
698
|
end
|
605
699
|
|
606
|
-
describe '
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
"
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
700
|
+
describe '--require option' do
|
701
|
+
let(:required_file_path) { './path/to/required_file.rb' }
|
702
|
+
|
703
|
+
before do
|
704
|
+
create_file('example.rb', '# encoding: utf-8')
|
705
|
+
|
706
|
+
create_file(required_file_path, [
|
707
|
+
'# encoding: utf-8',
|
708
|
+
"puts 'Hello from required file!'"
|
709
|
+
])
|
710
|
+
end
|
711
|
+
|
712
|
+
it 'requires the passed path' do
|
713
|
+
cli.run(['--require', required_file_path, 'example.rb'])
|
714
|
+
expect($stdout.string).to start_with('Hello from required file!')
|
715
|
+
end
|
716
|
+
end
|
717
|
+
|
718
|
+
describe '-f/--format option' do
|
719
|
+
let(:target_file) { 'example.rb' }
|
720
|
+
|
721
|
+
before do
|
722
|
+
create_file(target_file, [
|
723
|
+
'# encoding: utf-8',
|
724
|
+
'#' * 90
|
725
|
+
])
|
623
726
|
end
|
624
727
|
|
728
|
+
describe 'builtin formatters' do
|
729
|
+
context 'when simple format is specified' do
|
730
|
+
it 'outputs with simple format' do
|
731
|
+
cli.run(['--format', 'simple', 'example.rb'])
|
732
|
+
expect($stdout.string).to include([
|
733
|
+
"== #{target_file} ==",
|
734
|
+
'C: 2: 80: Line is too long. [90/79]'
|
735
|
+
].join("\n"))
|
736
|
+
end
|
737
|
+
end
|
738
|
+
|
739
|
+
context 'when emacs format is specified' do
|
740
|
+
it 'outputs with emacs format' do
|
741
|
+
cli.run(['--format', 'emacs', 'example.rb'])
|
742
|
+
expect($stdout.string).to include(
|
743
|
+
"#{abs(target_file)}:2:80: C: Line is too long. [90/79]")
|
744
|
+
end
|
745
|
+
end
|
746
|
+
|
747
|
+
context 'when unknown format name is specified' do
|
748
|
+
it 'aborts with error message' do
|
749
|
+
expect { cli.run(['--format', 'unknown', 'example.rb']) }
|
750
|
+
.to exit_with_code(1)
|
751
|
+
expect($stderr.string)
|
752
|
+
.to include('No formatter for "unknown"')
|
753
|
+
end
|
754
|
+
end
|
755
|
+
end
|
756
|
+
|
757
|
+
describe 'custom formatter' do
|
758
|
+
let(:target_file) { abs('example.rb') }
|
759
|
+
|
760
|
+
context 'when a class name is specified' do
|
761
|
+
it 'uses the class as a formatter' do
|
762
|
+
module ::MyTool
|
763
|
+
class RubocopFormatter < Rubocop::Formatter::BaseFormatter
|
764
|
+
def started(all_files)
|
765
|
+
output.puts "started: #{all_files.join(',')}"
|
766
|
+
end
|
767
|
+
|
768
|
+
def file_started(file, options)
|
769
|
+
output.puts "file_started: #{file}"
|
770
|
+
end
|
771
|
+
|
772
|
+
def file_finished(file, offences)
|
773
|
+
output.puts "file_finished: #{file}"
|
774
|
+
end
|
775
|
+
|
776
|
+
def finished(processed_files)
|
777
|
+
output.puts "finished: #{processed_files.join(',')}"
|
778
|
+
end
|
779
|
+
end
|
780
|
+
end
|
781
|
+
|
782
|
+
cli.run(['--format', 'MyTool::RubocopFormatter', 'example.rb'])
|
783
|
+
expect($stdout.string).to eq([
|
784
|
+
"started: #{target_file}",
|
785
|
+
"file_started: #{target_file}",
|
786
|
+
"file_finished: #{target_file}",
|
787
|
+
"finished: #{target_file}",
|
788
|
+
''
|
789
|
+
].join("\n"))
|
790
|
+
end
|
791
|
+
end
|
792
|
+
|
793
|
+
context 'when unknown class name is specified' do
|
794
|
+
it 'aborts with error message' do
|
795
|
+
expect { cli.run(['--format', 'UnknownFormatter', 'example.rb']) }
|
796
|
+
.to exit_with_code(1)
|
797
|
+
expect($stderr.string).to include('UnknownFormatter')
|
798
|
+
end
|
799
|
+
end
|
800
|
+
end
|
801
|
+
|
802
|
+
it 'can be used multiple times' do
|
803
|
+
cli.run(['--format', 'simple', '--format', 'emacs', 'example.rb'])
|
804
|
+
expect($stdout.string).to include([
|
805
|
+
"== #{target_file} ==",
|
806
|
+
'C: 2: 80: Line is too long. [90/79]',
|
807
|
+
"#{abs(target_file)}:2:80: C: Line is too long. [90/79]"
|
808
|
+
].join("\n"))
|
809
|
+
end
|
810
|
+
end
|
811
|
+
|
812
|
+
unless Rubocop::Version::STRING.start_with?('0')
|
813
|
+
describe '-e/--emacs option' do
|
814
|
+
it 'is dropped in RuboCop 1.0.0' do
|
815
|
+
# This spec can be removed once the option is dropped.
|
816
|
+
expect(cli.run(['--emacs'])).to eq(1)
|
817
|
+
expect($stderr.string).to include('invalid option: --emacs')
|
818
|
+
end
|
819
|
+
end
|
820
|
+
end
|
821
|
+
|
822
|
+
describe '-o/--out option' do
|
823
|
+
let(:target_file) { 'example.rb' }
|
824
|
+
|
825
|
+
before do
|
826
|
+
create_file(target_file, [
|
827
|
+
'# encoding: utf-8',
|
828
|
+
'#' * 90
|
829
|
+
])
|
830
|
+
end
|
831
|
+
|
832
|
+
it 'redirects output to the specified file' do
|
833
|
+
cli.run(['--out', 'output.txt', target_file])
|
834
|
+
expect(File.read('output.txt')).to include('Line is too long.')
|
835
|
+
end
|
836
|
+
|
837
|
+
it 'is applied to the previously specified formatter' do
|
838
|
+
cli.run([
|
839
|
+
'--format', 'simple',
|
840
|
+
'--format', 'emacs', '--out', 'emacs_output.txt',
|
841
|
+
target_file
|
842
|
+
])
|
843
|
+
|
844
|
+
expect($stdout.string).to eq([
|
845
|
+
"== #{target_file} ==",
|
846
|
+
'C: 2: 80: Line is too long. [90/79]',
|
847
|
+
'',
|
848
|
+
'1 file inspected, 1 offence detected',
|
849
|
+
''
|
850
|
+
].join("\n"))
|
851
|
+
|
852
|
+
expect(File.read('emacs_output.txt')).to eq([
|
853
|
+
"#{abs(target_file)}:2:80: C: Line is too long. [90/79]",
|
854
|
+
'',
|
855
|
+
'1 file inspected, 1 offence detected',
|
856
|
+
''
|
857
|
+
].join("\n"))
|
858
|
+
end
|
859
|
+
end
|
860
|
+
|
861
|
+
describe '#display_error_summary' do
|
625
862
|
it 'displays an error message when errors are present' do
|
626
863
|
msg = 'An error occurred while Encoding cop was inspecting file.rb.'
|
627
|
-
cli.
|
628
|
-
expect($stdout.string.lines.to_a[-
|
864
|
+
cli.display_error_summary([msg])
|
865
|
+
expect($stdout.string.lines.to_a[-6..-5])
|
629
866
|
.to eq(["1 error occurred:\n", "#{msg}\n"])
|
630
867
|
end
|
631
868
|
end
|