rubocop 0.18.1 → 0.19.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 +1 -1
- data/CHANGELOG.md +65 -1
- data/Gemfile +0 -3
- data/LICENSE.txt +1 -1
- data/README.md +179 -77
- data/Rakefile +8 -0
- data/config/default.yml +151 -14
- data/config/enabled.yml +65 -8
- data/lib/rubocop.rb +19 -4
- data/lib/rubocop/cli.rb +2 -1
- data/lib/rubocop/comment_config.rb +97 -0
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_loader.rb +3 -2
- data/lib/rubocop/config_store.rb +6 -2
- data/lib/rubocop/cop/commissioner.rb +2 -2
- data/lib/rubocop/cop/cop.rb +22 -26
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +1 -1
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +6 -6
- data/lib/rubocop/cop/lint/condition_position.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +60 -0
- data/lib/rubocop/cop/lint/else_layout.rb +1 -1
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/end_alignment.rb +14 -12
- 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 -1
- data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +13 -2
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +28 -0
- data/lib/rubocop/cop/lint/loop.rb +4 -4
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/require_parentheses.rb +6 -6
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +2 -2
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +30 -0
- data/lib/rubocop/cop/lint/syntax.rb +5 -5
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +5 -5
- data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +5 -5
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +8 -5
- data/lib/rubocop/cop/mixin/code_length.rb +2 -2
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +7 -7
- data/lib/rubocop/cop/mixin/configurable_max.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
- data/lib/rubocop/cop/mixin/if_then_else.rb +1 -1
- data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -1
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +2 -2
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +3 -2
- data/lib/rubocop/cop/mixin/space_inside.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -0
- data/lib/rubocop/cop/mixin/string_help.rb +4 -4
- data/lib/rubocop/cop/{offence.rb → offense.rb} +7 -7
- data/lib/rubocop/cop/rails/action_filter.rb +73 -0
- data/lib/rubocop/cop/rails/default_scope.rb +1 -1
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
- data/lib/rubocop/cop/rails/output.rb +1 -10
- data/lib/rubocop/cop/rails/read_attribute.rb +1 -1
- data/lib/rubocop/cop/rails/scope_args.rb +33 -0
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +1 -1
- data/lib/rubocop/cop/style/accessor_method_name.rb +2 -2
- data/lib/rubocop/cop/style/alias.rb +2 -2
- data/lib/rubocop/cop/style/align_array.rb +1 -1
- data/lib/rubocop/cop/style/align_hash.rb +29 -2
- data/lib/rubocop/cop/style/align_parameters.rb +16 -2
- data/lib/rubocop/cop/style/and_or.rb +2 -2
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -1
- 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 +1 -1
- data/lib/rubocop/cop/style/blocks.rb +2 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +2 -2
- data/lib/rubocop/cop/style/case_equality.rb +1 -1
- data/lib/rubocop/cop/style/case_indentation.rb +2 -2
- data/lib/rubocop/cop/style/character_literal.rb +2 -2
- data/lib/rubocop/cop/style/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +69 -0
- data/lib/rubocop/cop/style/class_methods.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +3 -3
- data/lib/rubocop/cop/style/collection_methods.rb +4 -4
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
- data/lib/rubocop/cop/style/constant_name.rb +1 -1
- data/lib/rubocop/cop/style/cyclomatic_complexity.rb +2 -2
- data/lib/rubocop/cop/style/def_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/dot_position.rb +10 -11
- data/lib/rubocop/cop/style/double_negation.rb +40 -0
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +8 -1
- data/lib/rubocop/cop/style/empty_lines.rb +3 -2
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +1 -1
- data/lib/rubocop/cop/style/empty_literal.rb +3 -3
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/end_of_line.rb +2 -2
- data/lib/rubocop/cop/style/even_odd.rb +2 -2
- data/lib/rubocop/cop/style/favor_join.rb +1 -1
- data/lib/rubocop/cop/style/file_name.rb +29 -0
- data/lib/rubocop/cop/style/final_newline.rb +1 -1
- data/lib/rubocop/cop/style/flip_flop.rb +2 -2
- data/lib/rubocop/cop/style/for.rb +2 -2
- data/lib/rubocop/cop/style/format_string.rb +66 -0
- data/lib/rubocop/cop/style/global_vars.rb +2 -2
- data/lib/rubocop/cop/style/hash_methods.rb +1 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +3 -3
- data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -1
- data/lib/rubocop/cop/style/indent_array.rb +41 -0
- data/lib/rubocop/cop/style/indent_hash.rb +119 -0
- data/lib/rubocop/cop/style/indentation_consistency.rb +3 -11
- data/lib/rubocop/cop/style/indentation_width.rb +44 -23
- data/lib/rubocop/cop/style/lambda.rb +2 -2
- data/lib/rubocop/cop/style/lambda_call.rb +3 -3
- data/lib/rubocop/cop/style/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +7 -3
- data/lib/rubocop/cop/style/line_length.rb +2 -2
- data/lib/rubocop/cop/style/method_call_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -2
- data/lib/rubocop/cop/style/method_def_parentheses.rb +9 -7
- data/lib/rubocop/cop/style/module_function.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +2 -2
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +5 -5
- data/lib/rubocop/cop/style/op_method.rb +2 -2
- data/lib/rubocop/cop/style/parameter_lists.rb +1 -1
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +5 -4
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +143 -0
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/predicate_name.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +2 -2
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +2 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +45 -19
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/self_assignment.rb +73 -0
- data/lib/rubocop/cop/style/semicolon.rb +12 -8
- data/lib/rubocop/cop/style/signal_exception.rb +2 -2
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +38 -1
- data/lib/rubocop/cop/style/space_after_colon.rb +3 -3
- data/lib/rubocop/cop/style/space_after_comma.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 +11 -3
- data/lib/rubocop/cop/style/space_after_not.rb +1 -1
- data/lib/rubocop/cop/style/space_after_semicolon.rb +1 -1
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +41 -6
- data/lib/rubocop/cop/style/space_around_operators.rb +4 -4
- data/lib/rubocop/cop/style/space_before_block_braces.rb +63 -0
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +1 -1
- data/lib/rubocop/cop/style/{space_around_block_braces.rb → space_inside_block_braces.rb} +15 -24
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +14 -7
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/tab.rb +1 -1
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +2 -2
- data/lib/rubocop/cop/style/trailing_comma.rb +4 -4
- data/lib/rubocop/cop/style/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +2 -2
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- data/lib/rubocop/cop/style/while_until_do.rb +1 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +2 -1
- data/lib/rubocop/cop/style/word_array.rb +2 -2
- data/lib/rubocop/cop/team.rb +24 -7
- data/lib/rubocop/cop/util.rb +3 -3
- data/lib/rubocop/cop/variable_inspector.rb +25 -13
- data/lib/rubocop/cop/variable_inspector/assignment.rb +1 -1
- data/lib/rubocop/cop/variable_inspector/reference.rb +1 -1
- data/lib/rubocop/cop/variable_inspector/scope.rb +1 -1
- data/lib/rubocop/cop/variable_inspector/variable.rb +2 -2
- data/lib/rubocop/cop/variable_inspector/variable_table.rb +1 -1
- data/lib/rubocop/file_inspector.rb +12 -13
- data/lib/rubocop/formatter/base_formatter.rb +4 -4
- data/lib/rubocop/formatter/clang_style_formatter.rb +2 -2
- data/lib/rubocop/formatter/disabled_config_formatter.rb +12 -12
- data/lib/rubocop/formatter/emacs_style_formatter.rb +3 -2
- data/lib/rubocop/formatter/file_list_formatter.rb +4 -4
- data/lib/rubocop/formatter/formatter_set.rb +2 -1
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +76 -0
- data/lib/rubocop/formatter/json_formatter.rb +17 -16
- data/lib/rubocop/formatter/offense_count_formatter.rb +54 -0
- data/lib/rubocop/formatter/progress_formatter.rb +16 -16
- data/lib/rubocop/formatter/simple_text_formatter.rb +25 -25
- data/lib/rubocop/options.rb +8 -7
- data/lib/rubocop/processed_source.rb +3 -2
- data/lib/rubocop/source_parser.rb +1 -59
- data/lib/rubocop/version.rb +3 -3
- data/relnotes/0.19.0.md +70 -0
- data/rubocop-todo.yml +6 -6
- data/rubocop.gemspec +2 -1
- data/spec/rubocop/cli_spec.rb +431 -268
- data/spec/rubocop/comment_config_spec.rb +103 -0
- data/spec/rubocop/config_loader_spec.rb +4 -4
- data/spec/rubocop/cop/commissioner_spec.rb +7 -7
- data/spec/rubocop/cop/cop_spec.rb +17 -17
- data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +16 -16
- data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +5 -5
- data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +19 -19
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +52 -52
- data/spec/rubocop/cop/lint/condition_position_spec.rb +7 -7
- data/spec/rubocop/cop/lint/debugger_spec.rb +10 -10
- data/spec/rubocop/cop/lint/deprecated_class_methods_spec.rb +33 -0
- data/spec/rubocop/cop/lint/else_layout_spec.rb +7 -7
- data/spec/rubocop/cop/lint/empty_ensure_spec.rb +4 -4
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +33 -34
- data/spec/rubocop/cop/lint/end_in_method_spec.rb +5 -5
- data/spec/rubocop/cop/lint/ensure_return_spec.rb +4 -4
- data/spec/rubocop/cop/lint/eval_spec.rb +8 -8
- data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +4 -4
- data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +3 -3
- data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +65 -10
- data/spec/rubocop/cop/lint/literal_in_interpolation_spec.rb +21 -0
- data/spec/rubocop/cop/lint/loop_spec.rb +6 -6
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +14 -14
- data/spec/rubocop/cop/lint/require_parentheses_spec.rb +15 -15
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +21 -21
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +16 -16
- data/spec/rubocop/cop/lint/string_conversion_in_interpolation_spec.rb +27 -0
- data/spec/rubocop/cop/lint/syntax_spec.rb +11 -11
- data/spec/rubocop/cop/lint/unreachable_code_spec.rb +8 -8
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +207 -169
- data/spec/rubocop/cop/lint/useless_comparison_spec.rb +5 -5
- data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +4 -4
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +17 -17
- data/spec/rubocop/cop/lint/void_spec.rb +8 -8
- data/spec/rubocop/cop/{offence_spec.rb → offense_spec.rb} +17 -17
- data/spec/rubocop/cop/rails/action_filter_spec.rb +69 -0
- data/spec/rubocop/cop/rails/default_scope_spec.rb +9 -9
- data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +2 -2
- data/spec/rubocop/cop/rails/output_spec.rb +8 -18
- data/spec/rubocop/cop/rails/read_attribute_spec.rb +2 -2
- data/spec/rubocop/cop/rails/scope_args_spec.rb +25 -0
- data/spec/rubocop/cop/rails/validation_spec.rb +3 -3
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +38 -38
- data/spec/rubocop/cop/style/accessor_method_name_spec.rb +14 -14
- data/spec/rubocop/cop/style/alias_spec.rb +11 -11
- data/spec/rubocop/cop/style/align_array_spec.rb +23 -7
- data/spec/rubocop/cop/style/align_hash_spec.rb +111 -30
- data/spec/rubocop/cop/style/align_parameters_spec.rb +260 -187
- data/spec/rubocop/cop/style/and_or_spec.rb +6 -6
- data/spec/rubocop/cop/style/ascii_comments_spec.rb +3 -3
- data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +5 -5
- data/spec/rubocop/cop/style/attr_spec.rb +2 -2
- data/spec/rubocop/cop/style/begin_block_spec.rb +2 -2
- data/spec/rubocop/cop/style/block_comments_spec.rb +3 -3
- data/spec/rubocop/cop/style/block_nesting_spec.rb +26 -26
- data/spec/rubocop/cop/style/blocks_spec.rb +8 -8
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +8 -8
- data/spec/rubocop/cop/style/case_equality_spec.rb +2 -2
- data/spec/rubocop/cop/style/case_indentation_spec.rb +21 -21
- data/spec/rubocop/cop/style/character_literal_spec.rb +6 -6
- data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +4 -4
- data/spec/rubocop/cop/style/class_and_module_children_spec.rb +129 -0
- data/spec/rubocop/cop/style/class_length_spec.rb +9 -9
- data/spec/rubocop/cop/style/class_methods_spec.rb +8 -8
- data/spec/rubocop/cop/style/class_vars_spec.rb +4 -4
- data/spec/rubocop/cop/style/collection_methods_spec.rb +6 -6
- data/spec/rubocop/cop/style/colon_method_call_spec.rb +16 -16
- data/spec/rubocop/cop/style/comment_annotation_spec.rb +16 -16
- data/spec/rubocop/cop/style/constant_name_spec.rb +12 -12
- data/spec/rubocop/cop/style/cyclomatic_complexity_spec.rb +16 -16
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +6 -6
- data/spec/rubocop/cop/style/documentation_spec.rb +14 -14
- data/spec/rubocop/cop/style/dot_position_spec.rb +23 -26
- data/spec/rubocop/cop/style/double_negation_spec.rb +22 -0
- data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +22 -14
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +4 -4
- data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +20 -20
- data/spec/rubocop/cop/style/empty_lines_spec.rb +17 -6
- data/spec/rubocop/cop/style/empty_literal_spec.rb +20 -20
- data/spec/rubocop/cop/style/encoding_spec.rb +5 -5
- data/spec/rubocop/cop/style/end_block_spec.rb +2 -2
- data/spec/rubocop/cop/style/end_of_line_spec.rb +4 -4
- data/spec/rubocop/cop/style/even_odd_spec.rb +18 -18
- data/spec/rubocop/cop/style/favor_join_spec.rb +7 -7
- data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +7 -7
- data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +3 -3
- data/spec/rubocop/cop/style/file_name_spec.rb +71 -0
- data/spec/rubocop/cop/style/final_newline_spec.rb +4 -4
- data/spec/rubocop/cop/style/flip_flop_spec.rb +4 -4
- data/spec/rubocop/cop/style/for_spec.rb +13 -13
- data/spec/rubocop/cop/style/format_string_spec.rb +136 -0
- data/spec/rubocop/cop/style/global_vars_spec.rb +7 -7
- data/spec/rubocop/cop/style/hash_methods_spec.rb +6 -6
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +11 -11
- data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +29 -11
- data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +1 -1
- data/spec/rubocop/cop/style/indent_array_spec.rb +136 -0
- data/spec/rubocop/cop/style/indent_hash_spec.rb +238 -0
- data/spec/rubocop/cop/style/indentation_consistency_spec.rb +69 -49
- data/spec/rubocop/cop/style/indentation_width_spec.rb +264 -128
- data/spec/rubocop/cop/style/lambda_call_spec.rb +14 -14
- data/spec/rubocop/cop/style/lambda_spec.rb +7 -7
- data/spec/rubocop/cop/style/leading_comment_space_spec.rb +15 -15
- data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +11 -4
- data/spec/rubocop/cop/style/line_length_spec.rb +5 -5
- data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +5 -5
- data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +9 -9
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +19 -19
- data/spec/rubocop/cop/style/method_length_spec.rb +17 -17
- data/spec/rubocop/cop/style/method_name_spec.rb +21 -21
- data/spec/rubocop/cop/style/module_function_spec.rb +3 -3
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +13 -13
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +10 -10
- data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +3 -3
- data/spec/rubocop/cop/style/nested_ternary_operator_spec.rb +3 -3
- data/spec/rubocop/cop/style/nil_comparison_spec.rb +7 -7
- data/spec/rubocop/cop/style/not_spec.rb +6 -11
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +8 -8
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +1 -1
- data/spec/rubocop/cop/style/op_method_spec.rb +13 -13
- data/spec/rubocop/cop/style/parameter_lists_spec.rb +6 -6
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +11 -10
- data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +250 -0
- data/spec/rubocop/cop/style/perl_backrefs_spec.rb +2 -2
- data/spec/rubocop/cop/style/predicate_name_spec.rb +3 -3
- data/spec/rubocop/cop/style/proc_spec.rb +4 -4
- data/spec/rubocop/cop/style/raise_args_spec.rb +20 -20
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +6 -6
- data/spec/rubocop/cop/style/redundant_exception_spec.rb +6 -6
- data/spec/rubocop/cop/style/redundant_return_spec.rb +22 -22
- data/spec/rubocop/cop/style/redundant_self_spec.rb +14 -14
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +88 -67
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +17 -17
- data/spec/rubocop/cop/style/self_assignment_spec.rb +43 -0
- data/spec/rubocop/cop/style/semicolon_spec.rb +31 -17
- data/spec/rubocop/cop/style/signal_exception_spec.rb +29 -29
- data/spec/rubocop/cop/style/single_line_block_params_spec.rb +6 -6
- data/spec/rubocop/cop/style/single_line_methods_spec.rb +44 -6
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_after_comma_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +12 -12
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +8 -8
- data/spec/rubocop/cop/style/space_after_not_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb +63 -21
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +24 -24
- data/spec/rubocop/cop/style/space_before_block_braces_spec.rb +72 -0
- data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +4 -4
- data/spec/rubocop/cop/style/{space_around_block_braces_spec.rb → space_inside_block_braces_spec.rb} +39 -41
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +15 -15
- data/spec/rubocop/cop/style/space_inside_parens_spec.rb +1 -1
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +10 -10
- data/spec/rubocop/cop/style/string_literals_spec.rb +31 -31
- data/spec/rubocop/cop/style/symbol_array_spec.rb +9 -9
- data/spec/rubocop/cop/style/tab_spec.rb +3 -3
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +3 -3
- data/spec/rubocop/cop/style/trailing_comma_spec.rb +32 -32
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +5 -5
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +39 -39
- data/spec/rubocop/cop/style/unless_else_spec.rb +1 -1
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +12 -12
- data/spec/rubocop/cop/style/variable_name_spec.rb +21 -21
- data/spec/rubocop/cop/style/when_then_spec.rb +1 -1
- data/spec/rubocop/cop/style/while_until_do_spec.rb +8 -8
- data/spec/rubocop/cop/style/while_until_modifier_spec.rb +25 -7
- data/spec/rubocop/cop/style/word_array_spec.rb +23 -23
- data/spec/rubocop/cop/team_spec.rb +14 -14
- data/spec/rubocop/file_inspector_spec.rb +14 -12
- data/spec/rubocop/formatter/base_formatter_spec.rb +19 -19
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +14 -14
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +7 -7
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +7 -7
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +4 -4
- data/spec/rubocop/formatter/fuubar_style_formatter_spec.rb +129 -0
- data/spec/rubocop/formatter/json_formatter_spec.rb +23 -19
- data/spec/rubocop/formatter/offense_count_formatter_spec.rb +77 -0
- data/spec/rubocop/formatter/progress_formatter_spec.rb +27 -27
- data/spec/rubocop/formatter/simple_text_formatter_spec.rb +16 -16
- data/spec/rubocop/options_spec.rb +7 -8
- data/spec/rubocop/source_parser_spec.rb +0 -54
- data/spec/spec_helper.rb +11 -7
- data/spec/support/file_helper.rb +1 -1
- data/spec/support/mri_syntax_checker.rb +4 -4
- data/spec/support/shared_examples.rb +6 -6
- data/spec/support/statement_modifier_helper.rb +3 -3
- metadata +76 -16
- data/lib/rubocop/cop/style/favor_sprintf.rb +0 -26
- data/lib/rubocop/formatter/offence_count_formatter.rb +0 -49
- data/spec/rubocop/cop/style/favor_sprintf_spec.rb +0 -47
- data/spec/rubocop/formatter/offence_count_formatter_spec.rb +0 -52
data/lib/rubocop/options.rb
CHANGED
@@ -45,10 +45,11 @@ module Rubocop
|
|
45
45
|
' [p]rogress (default)',
|
46
46
|
' [s]imple',
|
47
47
|
' [c]lang',
|
48
|
+
' [fu]ubar',
|
48
49
|
' [e]macs',
|
49
50
|
' [j]son',
|
50
|
-
' [
|
51
|
-
' [o]
|
51
|
+
' [fi]les',
|
52
|
+
' [o]ffenses',
|
52
53
|
' custom formatter class name']
|
53
54
|
|
54
55
|
def add_formatting_options(opts, args)
|
@@ -88,10 +89,10 @@ module Rubocop
|
|
88
89
|
option(opts, '-d', '--debug', 'Display debug info.')
|
89
90
|
option(opts,
|
90
91
|
'-D', '--display-cop-names',
|
91
|
-
'Display cop names in
|
92
|
+
'Display cop names in offense messages.')
|
92
93
|
option(opts, '-R', '--rails', 'Run extra Rails cops.')
|
93
94
|
option(opts, '-l', '--lint', 'Run only lint cops.')
|
94
|
-
option(opts, '-a', '--auto-correct', 'Auto-correct
|
95
|
+
option(opts, '-a', '--auto-correct', 'Auto-correct offenses.')
|
95
96
|
|
96
97
|
@options[:color] = true
|
97
98
|
opts.on('-n', '--no-color', 'Disable color output.') do
|
@@ -124,7 +125,7 @@ module Rubocop
|
|
124
125
|
rejected = args.reject! { |a| %w(-s --silent).include?(a) }
|
125
126
|
if rejected
|
126
127
|
warn '-s/--silent options is dropped. ' \
|
127
|
-
|
128
|
+
'`emacs` and `files` formatters no longer display summary.'
|
128
129
|
end
|
129
130
|
end
|
130
131
|
|
@@ -156,8 +157,8 @@ module Rubocop
|
|
156
157
|
|
157
158
|
def validate_auto_gen_config_option(args)
|
158
159
|
if args.any?
|
159
|
-
|
160
|
-
|
160
|
+
warn '--auto-gen-config can not be combined with any other arguments.'
|
161
|
+
exit(1)
|
161
162
|
end
|
162
163
|
end
|
163
164
|
end
|
@@ -5,8 +5,8 @@ module Rubocop
|
|
5
5
|
# and other information such as disabled lines for cops.
|
6
6
|
# It also provides a convenient way to access source lines.
|
7
7
|
class ProcessedSource
|
8
|
-
attr_reader :buffer, :ast, :comments, :tokens, :diagnostics
|
9
|
-
|
8
|
+
attr_reader :buffer, :ast, :comments, :tokens, :diagnostics,
|
9
|
+
:comment_config
|
10
10
|
|
11
11
|
def initialize(buffer, ast, comments, tokens, diagnostics)
|
12
12
|
@buffer = buffer
|
@@ -14,6 +14,7 @@ module Rubocop
|
|
14
14
|
@comments = comments
|
15
15
|
@tokens = tokens
|
16
16
|
@diagnostics = diagnostics
|
17
|
+
@comment_config = CommentConfig.new(self)
|
17
18
|
end
|
18
19
|
|
19
20
|
def lines
|
@@ -4,25 +4,13 @@ module Rubocop
|
|
4
4
|
# SourceParser provides a way to parse Ruby source with Parser gem
|
5
5
|
# and also parses comment directives which disable arbitrary cops.
|
6
6
|
module SourceParser
|
7
|
-
COMMENT_DIRECTIVE_REGEXP = Regexp.new(
|
8
|
-
'^.*?(\S)?.*# rubocop : ((?:dis|en)able)\b ((?:\w+,? )+)'
|
9
|
-
.gsub(' ', '\s*')
|
10
|
-
)
|
11
|
-
|
12
7
|
module_function
|
13
8
|
|
14
|
-
def parse(string, name = '(string)')
|
15
|
-
processed_source = parse_with_parser(string, name)
|
16
|
-
processed_source.disabled_lines_for_cops =
|
17
|
-
cop_disabled_lines_in(processed_source.lines)
|
18
|
-
processed_source
|
19
|
-
end
|
20
|
-
|
21
9
|
def parse_file(path)
|
22
10
|
parse(File.read(path), path)
|
23
11
|
end
|
24
12
|
|
25
|
-
def
|
13
|
+
def parse(string, name = '(string)')
|
26
14
|
source_buffer = Parser::Source::Buffer.new(name, 1)
|
27
15
|
source_buffer.source = string
|
28
16
|
|
@@ -55,51 +43,5 @@ module Rubocop
|
|
55
43
|
|
56
44
|
parser
|
57
45
|
end
|
58
|
-
|
59
|
-
def cop_disabled_lines_in(source_lines)
|
60
|
-
disabled_lines_for_cops = {}
|
61
|
-
current_disabled_cops = {}
|
62
|
-
|
63
|
-
source_lines.each_with_index do |line, index|
|
64
|
-
line_number = index + 1
|
65
|
-
|
66
|
-
each_mentioned_cop(line) do |cop_name, disabled, single_line|
|
67
|
-
if single_line
|
68
|
-
next unless disabled
|
69
|
-
disabled_lines_for_cops[cop_name] ||= []
|
70
|
-
disabled_lines_for_cops[cop_name] << line_number
|
71
|
-
else
|
72
|
-
current_disabled_cops[cop_name] = disabled
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
current_disabled_cops.each do |cop_name, disabled|
|
77
|
-
next unless disabled
|
78
|
-
disabled_lines_for_cops[cop_name] ||= []
|
79
|
-
disabled_lines_for_cops[cop_name] << line_number
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
disabled_lines_for_cops
|
84
|
-
end
|
85
|
-
|
86
|
-
def each_mentioned_cop(line)
|
87
|
-
match = line.match(COMMENT_DIRECTIVE_REGEXP)
|
88
|
-
|
89
|
-
return unless match
|
90
|
-
|
91
|
-
non_whitespace_before_comment, switch, cops_string = match.captures
|
92
|
-
|
93
|
-
if cops_string.include?('all')
|
94
|
-
cop_names = Cop::Cop.all.map(&:cop_name)
|
95
|
-
else
|
96
|
-
cop_names = cops_string.split(/,\s*/)
|
97
|
-
end
|
98
|
-
|
99
|
-
disabled = (switch == 'disable')
|
100
|
-
single_line = !non_whitespace_before_comment.nil?
|
101
|
-
|
102
|
-
cop_names.each { |cop_name| yield cop_name, disabled, single_line }
|
103
|
-
end
|
104
46
|
end
|
105
47
|
end
|
data/lib/rubocop/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module Rubocop
|
4
4
|
# This module holds the RuboCop version information.
|
5
5
|
module Version
|
6
|
-
STRING = '0.
|
6
|
+
STRING = '0.19.0'
|
7
7
|
|
8
8
|
MSG = '%s (using Parser %s, running on %s %s %s)'
|
9
9
|
|
@@ -11,8 +11,8 @@ module Rubocop
|
|
11
11
|
|
12
12
|
def version(debug = false)
|
13
13
|
if debug
|
14
|
-
|
15
|
-
|
14
|
+
format(MSG, STRING, Parser::VERSION,
|
15
|
+
RUBY_ENGINE, RUBY_VERSION, RUBY_PLATFORM)
|
16
16
|
else
|
17
17
|
STRING
|
18
18
|
end
|
data/relnotes/0.19.0.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
This is the biggest RuboCop release we've done in a while. The highlights include
|
2
|
+
about a dozen new cops, more cop configuration options, improved auto-correct and so many bugfixes.
|
3
|
+
|
4
|
+
You'll might note that we changed the use of `offence` with `offense`. This was done to keep the spelling
|
5
|
+
in our code consistent. Hopefully this won't cause anyone problems, but we're obliged to mention it as
|
6
|
+
the `Offence` class itself got renamed.
|
7
|
+
|
8
|
+
Below is the list of all the gory details. Enjoy!
|
9
|
+
|
10
|
+
## RuboCop 0.19.0
|
11
|
+
|
12
|
+
### New features
|
13
|
+
|
14
|
+
* New cop `FileName` makes sure that source files have snake_case names. ([@bbatsov][])
|
15
|
+
* New cop `DeprecatedClassMethods` checks for deprecated class methods. ([@bbatsov][])
|
16
|
+
* New cop `StringConversionInInterpolation` checks for redundant `Object#to_s` in string interpolation. ([@bbatsov][])
|
17
|
+
* New cop `LiteralInInterpolation` checks for interpolated string literals. ([@bbatsov][])
|
18
|
+
* New cop `SelfAssignment` checks for places where the self-assignment shorthand should have been used. ([@bbatsov][])
|
19
|
+
* New cop `DoubleNegation` checks for uses of `!!`. ([@bbatsov][])
|
20
|
+
* New cop `PercentLiteralDelimiters` enforces consistent usage of `%`-literal delimiters. ([@hannestyden][])
|
21
|
+
* New Rails cop `ActionFilter` enforces the use of `_filter` or `_action` action filter methods. ([@bbatsov][])
|
22
|
+
* New Rails cop `ScopeArgs` makes sure you invoke the `scope` method properly. ([@bbatsov][])
|
23
|
+
* Add `with_fixed_indentation` style to `AlignParameters` cop. ([@hannestyden][])
|
24
|
+
* Add `IgnoreLastArgumentHash` option to `AlignHash` cop. ([@hannestyden][])
|
25
|
+
* [#743](https://github.com/bbatsov/rubocop/issues/743): `SingleLineMethods` cop does auto-correction. ([@jonas054][])
|
26
|
+
* [#743](https://github.com/bbatsov/rubocop/issues/743): `Semicolon` cop does auto-correction. ([@jonas054][])
|
27
|
+
* [#743](https://github.com/bbatsov/rubocop/issues/743): `EmptyLineBetweenDefs` cop does auto-correction. ([@jonas054][])
|
28
|
+
* [#743](https://github.com/bbatsov/rubocop/issues/743): `IndentationWidth` cop does auto-correction. ([@jonas054][])
|
29
|
+
* [#743](https://github.com/bbatsov/rubocop/issues/743): `IndentationConsistency` cop does auto-correction. ([@jonas054][])
|
30
|
+
* [#809](https://github.com/bbatsov/rubocop/issues/809): New formatter `fuubar` displays a progress bar and shows details of offenses as soon as they are detected. ([@yujinakayama][])
|
31
|
+
* [#797](https://github.com/bbatsov/rubocop/issues/797): New cop `IndentHash` checks the indentation of the first key in multi-line hash literals. ([@jonas054][])
|
32
|
+
* [#797](https://github.com/bbatsov/rubocop/issues/797): New cop `IndentArray` checks the indentation of the first element in multi-line array literals. ([@jonas054][])
|
33
|
+
* [#806](https://github.com/bbatsov/rubocop/issues/806): Now excludes files in `vendor/**` by default. ([@jeremyolliver][])
|
34
|
+
* [#795](https://github.com/bbatsov/rubocop/issues/795): `IfUnlessModifier` and `WhileUntilModifier` supports `MaxLineLength`, which is independent of `LineLength` parameter `Max`. ([@agrimm][])
|
35
|
+
* [#868](https://github.com/bbatsov/rubocop/issues/868): New cop `ClassAndModuleChildren` checks the style of children definitions at classes and modules: nested / compact. ([@geniou][])
|
36
|
+
|
37
|
+
### Changes
|
38
|
+
|
39
|
+
* [#793](https://github.com/bbatsov/rubocop/issues/793): Add printing total count when `rubocop --format offences`. ([@ma2gedev][])
|
40
|
+
* Remove `Ignore` param from the Rails `Output` cop. The standard `Exclude/Include` should be used instead. ([@bbatsov][])
|
41
|
+
* Renamed `FavorSprintf` to `FormatString` and made it configurable. ([@bbatsov][])
|
42
|
+
* Renamed `Offence` to `Offense`. ([@bbatsov][])
|
43
|
+
* Use `offense` in all messages instead of `offence`. ([@bbatsov][])
|
44
|
+
* For indentation of `if`/`unless`/`while`/`until` bodies when the result is assigned to a variable, instead of supporting two styles simultaneously, `IndentationWidth` now supports one style of indentation at a time, specified by `EndAlignment`/`AlignWith`. ([@jonas054][])
|
45
|
+
* Renamed `Style` param of `DotPosition` cop to `EnforcedStyle`. ([@bbatsov][])
|
46
|
+
* Add `length` value to locations of offense in JSON formatter. ([@yujinakayama][])
|
47
|
+
* `SpaceAroundBlockBraces` cop replaced by `SpaceBeforeBlockBraces` and `SpaceInsideBlockBraces`. ([@jonas054][])
|
48
|
+
* `SpaceAroundEqualsInParameterDefault` cop is now configurable with the `EnforcedStyle` option. ([@jonas054][])
|
49
|
+
|
50
|
+
### Bugs fixed
|
51
|
+
|
52
|
+
* [#790](https://github.com/bbatsov/rubocop/issues/790): Fix auto-correction interference problem between `MethodDefParentheses` and other cops. ([@jonas054][])
|
53
|
+
* [#794](https://github.com/bbatsov/rubocop/issues/794): Fix handling of modifier keywords with required parentheses in `ParenthesesAroundCondition`. ([@bbatsov][])
|
54
|
+
* [#804](https://github.com/bbatsov/rubocop/issues/804): Fix a false positive with operator assignments in a loop (including `begin..rescue..end` with `retry`) in `UselessAssignment`. ([@yujinakayama][])
|
55
|
+
* [#815](https://github.com/bbatsov/rubocop/issues/815): Fix a false positive for heredocs with blank lines in them in `EmptyLines`. ([@bbatsov][])
|
56
|
+
* Auto-correction is now more robust and less likely to die because of `RangeError` or "clobbering". ([@jonas054][])
|
57
|
+
* Offenses always reported in order of position in file, also during `--auto-correct` runs. ([@jonas054][])
|
58
|
+
* Fix problem with `[Corrected]` tag sometimes missing in output from `--auto-correct` runs. ([@jonas054][])
|
59
|
+
* Fix message from `EndAlignment` cop when `AlignWith` is `keyword`. ([@jonas054][])
|
60
|
+
* Handle `case` conditions in `LiteralInCondition`. ([@bbatsov][])
|
61
|
+
* [#822](https://github.com/bbatsov/rubocop/issues/822): Fix a false positive in `DotPosition` when enforced style is set to `trailing`. ([@bbatsov][])
|
62
|
+
* Handle properly dynamic strings in `LineEndConcatenation`. ([@bbatsov][])
|
63
|
+
* [#832](https://github.com/bbatsov/rubocop/issues/832): Fix auto-correction interference problem between `BracesAroundHashParameters` and `SpaceInsideHashLiteralBraces`. ([@jonas054][])
|
64
|
+
* Fix bug in auto-correction of alignment so that only space can be removed. ([@jonas054][])
|
65
|
+
* Fix bug in `IndentationWidth` auto-correction so it doesn't correct things that `IndentationConsistency` should correct. ([@jonas054][])
|
66
|
+
* [#847](https://github.com/bbatsov/rubocop/issues/847): Fix bug in `RegexpLiteral` concerning `--auto-gen-config`. ([@jonas054][])
|
67
|
+
* [#848](https://github.com/bbatsov/rubocop/issues/848): Fix bug in `--show-cops` that made it print the default configuration rather than the current configuration. ([@jonas054][])
|
68
|
+
* [#862](https://github.com/bbatsov/rubocop/issues/862): Fix a bug where single line `rubocop:disable` comments with indentations were treated as multiline cop disabling comments. ([@yujinakayama][])
|
69
|
+
* Fix a bug where `rubocop:disable` comments with a cop name including `all` (e.g. `MethodCallParentheses`) were disabling all cops. ([@yujinakayama][])
|
70
|
+
* Fix a bug where string and regexp literals including `# rubocop:disable` were confused with real comments. ([@yujinakayama][])
|
data/rubocop-todo.yml
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2014-01
|
2
|
+
# on 2014-03-01 12:00:46 +1100 using RuboCop version 0.18.1.
|
3
3
|
# The point is for the user to remove these configuration records
|
4
|
-
# one by one as the
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
5
|
# Note that changes in the inspected code, or installation of new
|
6
6
|
# versions of RuboCop, may require this file to be generated again.
|
7
7
|
|
8
|
-
#
|
8
|
+
# Offense count: 6
|
9
9
|
# Configuration parameters: CountComments.
|
10
10
|
ClassLength:
|
11
|
-
Max:
|
11
|
+
Max: 125
|
12
12
|
|
13
|
-
#
|
13
|
+
# Offense count: 16
|
14
14
|
CyclomaticComplexity:
|
15
15
|
Max: 10
|
16
16
|
|
17
|
-
#
|
17
|
+
# Offense count: 105
|
18
18
|
# Configuration parameters: CountComments.
|
19
19
|
MethodLength:
|
20
20
|
Max: 20
|
data/rubocop.gemspec
CHANGED
@@ -27,9 +27,10 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.summary = 'Automatic Ruby code style checking tool.'
|
28
28
|
|
29
29
|
s.add_runtime_dependency('rainbow', '>= 1.99.1', '< 3.0')
|
30
|
-
s.add_runtime_dependency('parser', '~> 2.1.
|
30
|
+
s.add_runtime_dependency('parser', '~> 2.1.7')
|
31
31
|
s.add_runtime_dependency('powerpack', '~> 0.0.6')
|
32
32
|
s.add_runtime_dependency('json', '>= 1.7.7', '< 2')
|
33
|
+
s.add_runtime_dependency('ruby-progressbar', '~> 1.4')
|
33
34
|
s.add_development_dependency('rake', '~> 10.1')
|
34
35
|
s.add_development_dependency('rspec', '~> 2.14')
|
35
36
|
s.add_development_dependency('yard', '~> 0.8')
|
data/spec/rubocop/cli_spec.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'tmpdir'
|
5
5
|
require 'spec_helper'
|
6
|
+
require 'timeout'
|
6
7
|
|
7
8
|
describe Rubocop::CLI, :isolated_environment do
|
8
9
|
include FileHelper
|
@@ -48,6 +49,122 @@ describe Rubocop::CLI, :isolated_environment do
|
|
48
49
|
'end'].join("\n") + "\n")
|
49
50
|
end
|
50
51
|
|
52
|
+
it 'can handle spaces when removing braces' do
|
53
|
+
create_file('example.rb',
|
54
|
+
['# encoding: utf-8',
|
55
|
+
"assert_post_status_code 400, 's', {:type => 'bad'}"])
|
56
|
+
expect(cli.run(%w(--auto-correct --format emacs))).to eq(1)
|
57
|
+
expect(IO.read('example.rb'))
|
58
|
+
.to eq(['# encoding: utf-8',
|
59
|
+
"assert_post_status_code 400, 's', type: 'bad'",
|
60
|
+
''].join("\n"))
|
61
|
+
e = abs('example.rb')
|
62
|
+
expect($stdout.string)
|
63
|
+
.to eq(["#{e}:2:35: C: [Corrected] Redundant curly braces around " \
|
64
|
+
"a hash parameter.",
|
65
|
+
"#{e}:2:35: C: [Corrected] Use the new Ruby 1.9 hash " \
|
66
|
+
"syntax.",
|
67
|
+
# TODO: Don't report that a problem is corrected when it
|
68
|
+
# actually went away due to another correction.
|
69
|
+
"#{e}:2:35: C: [Corrected] Space inside { missing.",
|
70
|
+
# TODO: Don't report duplicates (HashSyntax in this case).
|
71
|
+
"#{e}:2:36: C: [Corrected] Use the new Ruby 1.9 hash " \
|
72
|
+
"syntax.",
|
73
|
+
"#{e}:2:50: C: [Corrected] Space inside } missing.",
|
74
|
+
''].join("\n"))
|
75
|
+
end
|
76
|
+
|
77
|
+
# A case where two cops, EmptyLinesAroundBody and EmptyLines, try to
|
78
|
+
# remove the same line in autocorrect.
|
79
|
+
it 'can correct two empty lines at end of class body' do
|
80
|
+
create_file('example.rb', ['class Test',
|
81
|
+
' def f',
|
82
|
+
' end',
|
83
|
+
'',
|
84
|
+
'',
|
85
|
+
'end'])
|
86
|
+
expect(cli.run(['--auto-correct'])).to eq(1)
|
87
|
+
expect($stderr.string).to eq('')
|
88
|
+
expect(IO.read('example.rb')).to eq(['class Test',
|
89
|
+
' def f',
|
90
|
+
' end',
|
91
|
+
'end'].join("\n") + "\n")
|
92
|
+
end
|
93
|
+
|
94
|
+
# A case where WordArray's correction can be clobbered by
|
95
|
+
# AccessModifierIndentation's correction.
|
96
|
+
it 'can correct indentation and another thing' do
|
97
|
+
create_file('example.rb', ['# encoding: utf-8',
|
98
|
+
'class Dsl',
|
99
|
+
'private',
|
100
|
+
' A = ["git", "path"]',
|
101
|
+
'end'])
|
102
|
+
expect(cli.run(%w(--auto-correct --format emacs))).to eq(1)
|
103
|
+
expect(IO.read('example.rb')).to eq(['# encoding: utf-8',
|
104
|
+
'class Dsl',
|
105
|
+
' private',
|
106
|
+
' A = %w(git path)',
|
107
|
+
'end'].join("\n") + "\n")
|
108
|
+
e = abs('example.rb')
|
109
|
+
expect($stdout.string)
|
110
|
+
.to eq(["#{e}:2:1: C: Missing top-level class documentation " \
|
111
|
+
'comment.',
|
112
|
+
"#{e}:3:1: C: [Corrected] Indent access modifiers like " \
|
113
|
+
'private.',
|
114
|
+
"#{e}:3:1: C: Keep a blank line before and after private.",
|
115
|
+
# An offense that moves around during auto-correction will
|
116
|
+
# appear to be duplicated:
|
117
|
+
"#{e}:3:3: C: Keep a blank line before and after private.",
|
118
|
+
"#{e}:4:7: C: [Corrected] Use %w or %W for array of words.",
|
119
|
+
"#{e}:4:8: C: [Corrected] Prefer single-quoted strings " \
|
120
|
+
"when you don't need string interpolation or special " \
|
121
|
+
'symbols.',
|
122
|
+
# Another instance of the same offense reported twice:
|
123
|
+
"#{e}:4:15: C: [Corrected] Prefer single-quoted strings " \
|
124
|
+
"when you don't need string interpolation or special " \
|
125
|
+
'symbols.',
|
126
|
+
''].join("\n"))
|
127
|
+
end
|
128
|
+
|
129
|
+
# A case where the same cop could try to correct an offense twice in one
|
130
|
+
# place.
|
131
|
+
it 'can correct empty line inside special form of nested modules' do
|
132
|
+
create_file('example.rb', ['module A module B',
|
133
|
+
'',
|
134
|
+
'end end'])
|
135
|
+
expect(cli.run(['--auto-correct'])).to eq(1)
|
136
|
+
expect(IO.read('example.rb')).to eq(['module A module B',
|
137
|
+
'end end'].join("\n") + "\n")
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'can correct single line methods' do
|
141
|
+
create_file('example.rb', ['# encoding: utf-8',
|
142
|
+
'def func1; do_something end # comment',
|
143
|
+
'def func2() do_1; do_2; end'])
|
144
|
+
expect(cli.run(%w(--auto-correct --format offenses))).to eq(1)
|
145
|
+
expect(IO.read('example.rb')).to eq(['# encoding: utf-8',
|
146
|
+
'# comment',
|
147
|
+
'def func1',
|
148
|
+
' do_something',
|
149
|
+
'end',
|
150
|
+
'',
|
151
|
+
'def func2',
|
152
|
+
' do_1',
|
153
|
+
' do_2',
|
154
|
+
'end',
|
155
|
+
''].join("\n"))
|
156
|
+
expect($stdout.string).to eq(['',
|
157
|
+
'6 TrailingWhitespace',
|
158
|
+
'4 Semicolon',
|
159
|
+
'2 SingleLineMethods',
|
160
|
+
'1 DefWithParentheses',
|
161
|
+
'1 EmptyLineBetweenDefs',
|
162
|
+
'--',
|
163
|
+
'14 Total',
|
164
|
+
'',
|
165
|
+
''].join("\n"))
|
166
|
+
end
|
167
|
+
|
51
168
|
# In this example, the auto-correction (changing "raise" to "fail")
|
52
169
|
# creates a new problem (alignment of parameters), which is also
|
53
170
|
# corrected automatically.
|
@@ -66,7 +183,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
66
183
|
.to eq(['Inspecting 1 file',
|
67
184
|
'C',
|
68
185
|
'',
|
69
|
-
'
|
186
|
+
'Offenses:',
|
70
187
|
'',
|
71
188
|
'example.rb:2:1: C: [Corrected] Use `fail` instead of ' \
|
72
189
|
'`raise` to signal exceptions.',
|
@@ -77,7 +194,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
77
194
|
" 'Method should be overridden in child classes'",
|
78
195
|
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^',
|
79
196
|
'',
|
80
|
-
'1 file inspected, 2
|
197
|
+
'1 file inspected, 2 offenses detected, 2 offenses ' \
|
81
198
|
'corrected',
|
82
199
|
''].join("\n"))
|
83
200
|
end
|
@@ -106,17 +223,116 @@ describe Rubocop::CLI, :isolated_environment do
|
|
106
223
|
.to eq(['Inspecting 1 file',
|
107
224
|
'C',
|
108
225
|
'',
|
109
|
-
'
|
226
|
+
'Offenses:',
|
110
227
|
'',
|
111
|
-
'example.rb:4:1: C: [Corrected] Trailing whitespace ' \
|
112
|
-
'detected.',
|
113
228
|
'example.rb:4:1: C: [Corrected] Extra empty line detected ' \
|
114
229
|
'at body beginning.',
|
230
|
+
'example.rb:4:1: C: [Corrected] Trailing whitespace ' \
|
231
|
+
'detected.',
|
115
232
|
'',
|
116
|
-
'1 file inspected, 2
|
233
|
+
'1 file inspected, 2 offenses detected, 2 offenses ' \
|
117
234
|
'corrected',
|
118
235
|
''].join("\n"))
|
119
236
|
end
|
237
|
+
|
238
|
+
it 'can correct MethodDefParentheses and other offense' do
|
239
|
+
create_file('example.rb',
|
240
|
+
['# encoding: utf-8',
|
241
|
+
'def primes limit',
|
242
|
+
' 1.upto(limit).find_all { |i| is_prime[i] }',
|
243
|
+
'end'])
|
244
|
+
expect(cli.run(%w(-D --auto-correct))).to eq(1)
|
245
|
+
expect($stderr.string).to eq('')
|
246
|
+
expect(IO.read('example.rb'))
|
247
|
+
.to eq(['# encoding: utf-8',
|
248
|
+
'def primes(limit)',
|
249
|
+
' 1.upto(limit).select { |i| is_prime[i] }',
|
250
|
+
'end'].join("\n") + "\n")
|
251
|
+
expect($stdout.string)
|
252
|
+
.to eq(['Inspecting 1 file',
|
253
|
+
'C',
|
254
|
+
'',
|
255
|
+
'Offenses:',
|
256
|
+
'',
|
257
|
+
'example.rb:2:12: C: [Corrected] MethodDefParentheses: ' \
|
258
|
+
'Use def with parentheses when there are parameters.',
|
259
|
+
'def primes limit',
|
260
|
+
' ^^^^^',
|
261
|
+
'example.rb:3:17: C: [Corrected] CollectionMethods: ' \
|
262
|
+
'Prefer select over find_all.',
|
263
|
+
' 1.upto(limit).find_all { |i| is_prime[i] }',
|
264
|
+
' ^^^^^^^^',
|
265
|
+
'',
|
266
|
+
'1 file inspected, 2 offenses detected, 2 offenses ' \
|
267
|
+
'corrected',
|
268
|
+
''].join("\n"))
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'can correct HashSyntax and SpaceAroundOperators offenses' do
|
272
|
+
create_file('example.rb',
|
273
|
+
['# encoding: utf-8',
|
274
|
+
'{ :b=>1 }'])
|
275
|
+
expect(cli.run(%w(-D --auto-correct --format emacs))).to eq(1)
|
276
|
+
expect($stderr.string).to eq('')
|
277
|
+
expect(IO.read('example.rb')).to eq(['# encoding: utf-8',
|
278
|
+
'{ b: 1 }',
|
279
|
+
''].join("\n"))
|
280
|
+
expect($stdout.string)
|
281
|
+
.to eq(["#{abs('example.rb')}:2:3: C: [Corrected] HashSyntax: Use " \
|
282
|
+
"the new Ruby 1.9 hash syntax.",
|
283
|
+
"#{abs('example.rb')}:2:5: C: [Corrected] " \
|
284
|
+
"SpaceAroundOperators: Surrounding space missing for " \
|
285
|
+
"operator '=>'.",
|
286
|
+
''].join("\n"))
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'can correct TrailingBlankLines and TrailingWhitespace offenses' do
|
290
|
+
create_file('example.rb',
|
291
|
+
['# encoding: utf-8',
|
292
|
+
'',
|
293
|
+
' ',
|
294
|
+
'',
|
295
|
+
''])
|
296
|
+
expect(cli.run(%w(--auto-correct --format emacs))).to eq(1)
|
297
|
+
expect($stderr.string).to eq('')
|
298
|
+
expect(IO.read('example.rb')).to eq("# encoding: utf-8\n")
|
299
|
+
expect($stdout.string)
|
300
|
+
.to eq(["#{abs('example.rb')}:2:1: C: [Corrected] 3 trailing " \
|
301
|
+
"blank lines detected.",
|
302
|
+
"#{abs('example.rb')}:3:1: C: [Corrected] Trailing " \
|
303
|
+
"whitespace detected.",
|
304
|
+
''].join("\n"))
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'can correct MethodCallParentheses and EmptyLiteral offenses' do
|
308
|
+
create_file('example.rb',
|
309
|
+
['# encoding: utf-8',
|
310
|
+
'Hash.new()'])
|
311
|
+
expect(cli.run(%w(--auto-correct --format emacs))).to eq(1)
|
312
|
+
expect($stderr.string).to eq('')
|
313
|
+
expect(IO.read('example.rb')).to eq(['# encoding: utf-8',
|
314
|
+
'{}',
|
315
|
+
''].join("\n"))
|
316
|
+
expect($stdout.string)
|
317
|
+
.to eq(["#{abs('example.rb')}:2:1: C: [Corrected] Use hash " \
|
318
|
+
"literal {} instead of Hash.new.",
|
319
|
+
"#{abs('example.rb')}:2:9: C: [Corrected] Do not use " \
|
320
|
+
"parentheses for method calls with no arguments.",
|
321
|
+
''].join("\n"))
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'should not hang SpaceAfterPunctuation and SpaceInsideParens' do
|
325
|
+
create_file('example.rb',
|
326
|
+
['# encoding: utf-8',
|
327
|
+
'some_method(a, )'])
|
328
|
+
Timeout.timeout(10) do
|
329
|
+
expect(cli.run(%w(--auto-correct))).to eq(1)
|
330
|
+
end
|
331
|
+
expect($stderr.string).to eq('')
|
332
|
+
expect(IO.read('example.rb')).to eq(['# encoding: utf-8',
|
333
|
+
'some_method(a,)',
|
334
|
+
''].join("\n"))
|
335
|
+
end
|
120
336
|
end
|
121
337
|
|
122
338
|
describe '--auto-gen-config' do
|
@@ -136,9 +352,9 @@ describe Rubocop::CLI, :isolated_environment do
|
|
136
352
|
expect(IO.read('rubocop-todo.yml'))
|
137
353
|
.to eq(todo_contents.join("\n") + "\n")
|
138
354
|
create_file('.rubocop.yml', ['inherit_from: rubocop-todo.yml'])
|
139
|
-
expect
|
355
|
+
expect { cli.run(['--auto-gen-config']) }.to exit_with_code(1)
|
140
356
|
expect($stderr.string).to eq('Remove rubocop-todo.yml from the ' \
|
141
|
-
'current configuration before '
|
357
|
+
'current configuration before ' \
|
142
358
|
"generating it again.\n")
|
143
359
|
end
|
144
360
|
|
@@ -148,7 +364,8 @@ describe Rubocop::CLI, :isolated_environment do
|
|
148
364
|
'#' * 85,
|
149
365
|
'y ',
|
150
366
|
'puts x'])
|
151
|
-
expect
|
367
|
+
expect { cli.run(['--auto-gen-config', 'example1.rb']) }
|
368
|
+
.to exit_with_code(1)
|
152
369
|
expect($stderr.string)
|
153
370
|
.to eq('--auto-gen-config can not be combined with any other ' \
|
154
371
|
"arguments.\n")
|
@@ -168,8 +385,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
168
385
|
expect(cli.run(['--auto-gen-config'])).to eq(1)
|
169
386
|
expect($stderr.string).to eq('')
|
170
387
|
expect($stdout.string)
|
171
|
-
.to include([
|
172
|
-
'Created rubocop-todo.yml.',
|
388
|
+
.to include(['Created rubocop-todo.yml.',
|
173
389
|
'Run rubocop with --config rubocop-todo.yml, or',
|
174
390
|
'add inherit_from: rubocop-todo.yml in a ' \
|
175
391
|
'.rubocop.yml file.',
|
@@ -178,34 +394,35 @@ describe Rubocop::CLI, :isolated_environment do
|
|
178
394
|
['# This configuration was generated by `rubocop --auto-gen-config`',
|
179
395
|
/# on .* using RuboCop version .*/,
|
180
396
|
'# The point is for the user to remove these configuration records',
|
181
|
-
'# one by one as the
|
397
|
+
'# one by one as the offenses are removed from the code base.',
|
182
398
|
'# Note that changes in the inspected code, or installation of new',
|
183
399
|
'# versions of RuboCop, may require this file to be generated ' \
|
184
400
|
'again.',
|
185
401
|
'',
|
186
|
-
'#
|
402
|
+
'# Offense count: 1',
|
187
403
|
'# Configuration parameters: AllowedVariables.',
|
188
404
|
'GlobalVars:',
|
189
405
|
' Enabled: false',
|
190
406
|
'',
|
191
|
-
'#
|
407
|
+
'# Offense count: 1',
|
408
|
+
'# Cop supports --auto-correct.',
|
192
409
|
'IndentationConsistency:',
|
193
410
|
' Enabled: false',
|
194
411
|
'',
|
195
|
-
'#
|
412
|
+
'# Offense count: 2',
|
196
413
|
'LineLength:',
|
197
414
|
' Max: 90',
|
198
415
|
'',
|
199
|
-
'#
|
416
|
+
'# Offense count: 1',
|
200
417
|
'# Cop supports --auto-correct.',
|
201
418
|
'SpaceAroundOperators:',
|
202
419
|
' Enabled: false',
|
203
420
|
'',
|
204
|
-
'#
|
421
|
+
'# Offense count: 1',
|
205
422
|
'Tab:',
|
206
423
|
' Enabled: false',
|
207
424
|
'',
|
208
|
-
'#
|
425
|
+
'# Offense count: 2',
|
209
426
|
'# Cop supports --auto-correct.',
|
210
427
|
'TrailingWhitespace:',
|
211
428
|
' Enabled: false']
|
@@ -218,6 +435,41 @@ describe Rubocop::CLI, :isolated_environment do
|
|
218
435
|
end
|
219
436
|
end
|
220
437
|
end
|
438
|
+
|
439
|
+
it 'generates a todo list that removes the reports' do
|
440
|
+
create_file('example.rb', ['# encoding: utf-8',
|
441
|
+
'y.gsub!(%r{abc/xyz}, "#{x}")'])
|
442
|
+
expect(cli.run(%w(--format emacs))).to eq(1)
|
443
|
+
expect($stdout.string)
|
444
|
+
.to eq(["#{abs('example.rb')}:2:9: C: Use %r only for regular " \
|
445
|
+
"expressions matching more than 1 '/' character.",
|
446
|
+
''].join("\n"))
|
447
|
+
expect(cli.run(['--auto-gen-config'])).to eq(1)
|
448
|
+
expected =
|
449
|
+
['# This configuration was generated by `rubocop --auto-gen-config`',
|
450
|
+
/# on .* using RuboCop version .*/,
|
451
|
+
'# The point is for the user to remove these configuration records',
|
452
|
+
'# one by one as the offenses are removed from the code base.',
|
453
|
+
'# Note that changes in the inspected code, or installation of new',
|
454
|
+
'# versions of RuboCop, may require this file to be generated ' \
|
455
|
+
'again.',
|
456
|
+
'',
|
457
|
+
'# Offense count: 1',
|
458
|
+
'RegexpLiteral:',
|
459
|
+
' MaxSlashes: 0']
|
460
|
+
actual = IO.read('rubocop-todo.yml').split($RS)
|
461
|
+
expected.each_with_index do |line, ix|
|
462
|
+
if line.is_a?(String)
|
463
|
+
expect(actual[ix]).to eq(line)
|
464
|
+
else
|
465
|
+
expect(actual[ix]).to match(line)
|
466
|
+
end
|
467
|
+
end
|
468
|
+
$stdout = StringIO.new
|
469
|
+
result = cli.run(%w(--config rubocop-todo.yml --format emacs))
|
470
|
+
expect($stdout.string).to eq('')
|
471
|
+
expect(result).to eq(0)
|
472
|
+
end
|
221
473
|
end
|
222
474
|
|
223
475
|
describe '--only' do
|
@@ -233,10 +485,10 @@ describe Rubocop::CLI, :isolated_environment do
|
|
233
485
|
expect($stdout.string)
|
234
486
|
.to eq(['== example.rb ==',
|
235
487
|
'C: 1: 1: Favor modifier if usage when you ' \
|
236
|
-
'have a single-line body. Another good alternative is '
|
488
|
+
'have a single-line body. Another good alternative is ' \
|
237
489
|
'the usage of control flow &&/||.',
|
238
490
|
'',
|
239
|
-
'1 file inspected, 1
|
491
|
+
'1 file inspected, 1 offense detected',
|
240
492
|
''].join("\n"))
|
241
493
|
end
|
242
494
|
end
|
@@ -254,7 +506,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
254
506
|
.to eq(['== example.rb ==',
|
255
507
|
'W: 1: 4: Literal 0 appeared in a condition.',
|
256
508
|
'',
|
257
|
-
'1 file inspected, 1
|
509
|
+
'1 file inspected, 1 offense detected',
|
258
510
|
''].join("\n"))
|
259
511
|
end
|
260
512
|
end
|
@@ -265,7 +517,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
265
517
|
expect(cli.run(['--debug', 'example1.rb'])).to eq(1)
|
266
518
|
home = File.dirname(File.dirname(File.dirname(__FILE__)))
|
267
519
|
expect($stdout.string.lines.grep(/configuration/).map(&:chomp))
|
268
|
-
.to eq(["For #{abs('')}:"
|
520
|
+
.to eq(["For #{abs('')}:" \
|
269
521
|
" configuration from #{home}/config/default.yml",
|
270
522
|
"Inheriting configuration from #{home}/config/enabled.yml",
|
271
523
|
"Inheriting configuration from #{home}/config/disabled.yml"
|
@@ -323,6 +575,8 @@ describe Rubocop::CLI, :isolated_environment do
|
|
323
575
|
let(:stdout) { $stdout.string }
|
324
576
|
|
325
577
|
before do
|
578
|
+
create_file('.rubocop.yml', ['LineLength:',
|
579
|
+
' Max: 110'])
|
326
580
|
expect { cli.run ['--show-cops'] + cop_list }.to exit_with_code(0)
|
327
581
|
end
|
328
582
|
|
@@ -415,10 +669,8 @@ describe Rubocop::CLI, :isolated_environment do
|
|
415
669
|
let(:target_file) { 'example.rb' }
|
416
670
|
|
417
671
|
before do
|
418
|
-
create_file(target_file, [
|
419
|
-
'#
|
420
|
-
'#' * 90
|
421
|
-
])
|
672
|
+
create_file(target_file, ['# encoding: utf-8',
|
673
|
+
'#' * 90])
|
422
674
|
end
|
423
675
|
|
424
676
|
describe 'builtin formatters' do
|
@@ -426,10 +678,8 @@ describe Rubocop::CLI, :isolated_environment do
|
|
426
678
|
it 'outputs with simple format' do
|
427
679
|
cli.run(['--format', 'simple', 'example.rb'])
|
428
680
|
expect($stdout.string)
|
429
|
-
.to include([
|
430
|
-
|
431
|
-
'C: 2: 80: Line is too long. [90/79]'
|
432
|
-
].join("\n"))
|
681
|
+
.to include(["== #{target_file} ==",
|
682
|
+
'C: 2: 80: Line is too long. [90/79]'].join("\n"))
|
433
683
|
end
|
434
684
|
end
|
435
685
|
|
@@ -476,7 +726,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
476
726
|
'example2.rb:3:1: C: Inconsistent indentation ' \
|
477
727
|
'detected.',
|
478
728
|
'def a',
|
479
|
-
'',
|
729
|
+
'^^^^^',
|
480
730
|
'example2.rb:4:1: C: Use 2 (not 3) spaces for ' \
|
481
731
|
'indentation.',
|
482
732
|
' puts',
|
@@ -485,7 +735,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
485
735
|
'def badName',
|
486
736
|
' ^^^^^^^',
|
487
737
|
'example3.rb:3:3: C: Favor modifier if usage ' \
|
488
|
-
'when you have a single-line body. Another good '
|
738
|
+
'when you have a single-line body. Another good ' \
|
489
739
|
'alternative is the usage of control flow &&/||.',
|
490
740
|
' if something',
|
491
741
|
' ^^',
|
@@ -494,7 +744,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
494
744
|
' end',
|
495
745
|
' ^^^',
|
496
746
|
'',
|
497
|
-
'3 files inspected, 10
|
747
|
+
'3 files inspected, 10 offenses detected',
|
498
748
|
''].join("\n"))
|
499
749
|
end
|
500
750
|
end
|
@@ -511,12 +761,12 @@ describe Rubocop::CLI, :isolated_environment do
|
|
511
761
|
expect(cli.run(['--format', 'emacs', 'example1.rb',
|
512
762
|
'example2.rb'])).to eq(1)
|
513
763
|
expected_output =
|
514
|
-
["#{abs('example1.rb')}:2:2: C: Surrounding space missing"
|
764
|
+
["#{abs('example1.rb')}:2:2: C: Surrounding space missing" \
|
515
765
|
" for operator '='.",
|
516
766
|
"#{abs('example1.rb')}:2:5: C: Trailing whitespace detected.",
|
517
767
|
"#{abs('example1.rb')}:3:2: C: Trailing whitespace detected.",
|
518
768
|
"#{abs('example2.rb')}:2:1: C: Tab detected.",
|
519
|
-
"#{abs('example2.rb')}:3:1: C: Inconsistent indentation "
|
769
|
+
"#{abs('example2.rb')}:3:1: C: Inconsistent indentation " \
|
520
770
|
'detected.',
|
521
771
|
''].join("\n")
|
522
772
|
expect($stdout.string).to eq(expected_output)
|
@@ -538,7 +788,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
538
788
|
|
539
789
|
context 'when a class name is specified' do
|
540
790
|
it 'uses the class as a formatter' do
|
541
|
-
module
|
791
|
+
module MyTool
|
542
792
|
class RubocopFormatter < Rubocop::Formatter::BaseFormatter
|
543
793
|
def started(all_files)
|
544
794
|
output.puts "started: #{all_files.join(',')}"
|
@@ -548,7 +798,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
548
798
|
output.puts "file_started: #{file}"
|
549
799
|
end
|
550
800
|
|
551
|
-
def file_finished(file,
|
801
|
+
def file_finished(file, offenses)
|
552
802
|
output.puts "file_finished: #{file}"
|
553
803
|
end
|
554
804
|
|
@@ -559,13 +809,11 @@ describe Rubocop::CLI, :isolated_environment do
|
|
559
809
|
end
|
560
810
|
|
561
811
|
cli.run(['--format', 'MyTool::RubocopFormatter', 'example.rb'])
|
562
|
-
expect($stdout.string).to eq([
|
563
|
-
"started: #{target_file}",
|
812
|
+
expect($stdout.string).to eq(["started: #{target_file}",
|
564
813
|
"file_started: #{target_file}",
|
565
814
|
"file_finished: #{target_file}",
|
566
815
|
"finished: #{target_file}",
|
567
|
-
''
|
568
|
-
].join("\n"))
|
816
|
+
''].join("\n"))
|
569
817
|
end
|
570
818
|
end
|
571
819
|
|
@@ -581,12 +829,10 @@ describe Rubocop::CLI, :isolated_environment do
|
|
581
829
|
it 'can be used multiple times' do
|
582
830
|
cli.run(['--format', 'simple', '--format', 'emacs', 'example.rb'])
|
583
831
|
expect($stdout.string)
|
584
|
-
.to include([
|
585
|
-
"== #{target_file} ==",
|
832
|
+
.to include(["== #{target_file} ==",
|
586
833
|
'C: 2: 80: Line is too long. [90/79]',
|
587
|
-
"#{abs(target_file)}:2:80: C: Line is too long. "
|
588
|
-
'[90/79]'
|
589
|
-
].join("\n"))
|
834
|
+
"#{abs(target_file)}:2:80: C: Line is too long. " \
|
835
|
+
'[90/79]'].join("\n"))
|
590
836
|
end
|
591
837
|
end
|
592
838
|
|
@@ -594,10 +840,8 @@ describe Rubocop::CLI, :isolated_environment do
|
|
594
840
|
let(:target_file) { 'example.rb' }
|
595
841
|
|
596
842
|
before do
|
597
|
-
create_file(target_file, [
|
598
|
-
'#
|
599
|
-
'#' * 90
|
600
|
-
])
|
843
|
+
create_file(target_file, ['# encoding: utf-8',
|
844
|
+
'#' * 90])
|
601
845
|
end
|
602
846
|
|
603
847
|
it 'redirects output to the specified file' do
|
@@ -606,19 +850,15 @@ describe Rubocop::CLI, :isolated_environment do
|
|
606
850
|
end
|
607
851
|
|
608
852
|
it 'is applied to the previously specified formatter' do
|
609
|
-
cli.run([
|
610
|
-
'--format', 'simple',
|
853
|
+
cli.run(['--format', 'simple',
|
611
854
|
'--format', 'emacs', '--out', 'emacs_output.txt',
|
612
|
-
target_file
|
613
|
-
])
|
855
|
+
target_file])
|
614
856
|
|
615
|
-
expect($stdout.string).to eq([
|
616
|
-
"== #{target_file} ==",
|
857
|
+
expect($stdout.string).to eq(["== #{target_file} ==",
|
617
858
|
'C: 2: 80: Line is too long. [90/79]',
|
618
859
|
'',
|
619
|
-
'1 file inspected, 1
|
620
|
-
''
|
621
|
-
].join("\n"))
|
860
|
+
'1 file inspected, 1 offense detected',
|
861
|
+
''].join("\n"))
|
622
862
|
|
623
863
|
expect(File.read('emacs_output.txt'))
|
624
864
|
.to eq("#{abs(target_file)}:2:80: C: Line is too long. [90/79]\n")
|
@@ -685,67 +925,57 @@ describe Rubocop::CLI, :isolated_environment do
|
|
685
925
|
end
|
686
926
|
|
687
927
|
it 'checks a given correct file and returns 0' do
|
688
|
-
create_file('example.rb', [
|
689
|
-
'# encoding: utf-8',
|
928
|
+
create_file('example.rb', ['# encoding: utf-8',
|
690
929
|
'x = 0',
|
691
|
-
'puts x'
|
692
|
-
])
|
930
|
+
'puts x'])
|
693
931
|
expect(cli.run(['--format', 'simple', 'example.rb'])).to eq(0)
|
694
932
|
expect($stdout.string)
|
695
|
-
.to eq("\n1 file inspected, no
|
933
|
+
.to eq("\n1 file inspected, no offenses detected\n")
|
696
934
|
end
|
697
935
|
|
698
936
|
it 'checks a given file with faults and returns 1' do
|
699
|
-
create_file('example.rb', [
|
700
|
-
'# encoding: utf-8',
|
937
|
+
create_file('example.rb', ['# encoding: utf-8',
|
701
938
|
'x = 0 ',
|
702
|
-
'puts x'
|
703
|
-
])
|
939
|
+
'puts x'])
|
704
940
|
expect(cli.run(['--format', 'simple', 'example.rb'])).to eq(1)
|
705
941
|
expect($stdout.string)
|
706
942
|
.to eq ['== example.rb ==',
|
707
943
|
'C: 2: 6: Trailing whitespace detected.',
|
708
944
|
'',
|
709
|
-
'1 file inspected, 1
|
945
|
+
'1 file inspected, 1 offense detected',
|
710
946
|
''].join("\n")
|
711
947
|
end
|
712
948
|
|
713
|
-
it 'registers an
|
714
|
-
create_file('example.rb', [
|
715
|
-
'# encoding: utf-8',
|
949
|
+
it 'registers an offense for a syntax error' do
|
950
|
+
create_file('example.rb', ['# encoding: utf-8',
|
716
951
|
'class Test',
|
717
|
-
'en'
|
718
|
-
])
|
952
|
+
'en'])
|
719
953
|
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
|
720
954
|
expect($stdout.string)
|
721
|
-
.to eq(["#{abs('example.rb')}:4:1: E: unexpected "
|
955
|
+
.to eq(["#{abs('example.rb')}:4:1: E: unexpected " \
|
722
956
|
'token $end',
|
723
957
|
''].join("\n"))
|
724
958
|
end
|
725
959
|
|
726
|
-
it 'registers an
|
727
|
-
create_file('example.rb', [
|
728
|
-
'# encoding: utf-8',
|
960
|
+
it 'registers an offense for Parser warnings' do
|
961
|
+
create_file('example.rb', ['# encoding: utf-8',
|
729
962
|
'puts *test',
|
730
|
-
'if a then b else c end'
|
731
|
-
])
|
963
|
+
'if a then b else c end'])
|
732
964
|
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
|
733
965
|
expect($stdout.string)
|
734
|
-
.to eq(["#{abs('example.rb')}:2:6: W: "
|
735
|
-
'Ambiguous splat operator. Parenthesize the method arguments '
|
736
|
-
"if it's surely a splat operator, or add a whitespace to the "
|
966
|
+
.to eq(["#{abs('example.rb')}:2:6: W: " \
|
967
|
+
'Ambiguous splat operator. Parenthesize the method arguments ' \
|
968
|
+
"if it's surely a splat operator, or add a whitespace to the " \
|
737
969
|
'right of the * if it should be a multiplication.',
|
738
|
-
"#{abs('example.rb')}:3:1: C: "
|
739
|
-
'Favor the ternary operator (?:) over if/then/else/end '
|
970
|
+
"#{abs('example.rb')}:3:1: C: " \
|
971
|
+
'Favor the ternary operator (?:) over if/then/else/end ' \
|
740
972
|
'constructs.',
|
741
973
|
''].join("\n"))
|
742
974
|
end
|
743
975
|
|
744
976
|
it 'can process a file with an invalid UTF-8 byte sequence' do
|
745
|
-
create_file('example.rb', [
|
746
|
-
|
747
|
-
"# #{'f9'.hex.chr}#{'29'.hex.chr}"
|
748
|
-
])
|
977
|
+
create_file('example.rb', ['# encoding: utf-8',
|
978
|
+
"# #{'f9'.hex.chr}#{'29'.hex.chr}"])
|
749
979
|
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
|
750
980
|
expect($stdout.string)
|
751
981
|
.to eq(["#{abs('example.rb')}:1:1: F: Invalid byte sequence in utf-8.",
|
@@ -768,11 +998,11 @@ describe Rubocop::CLI, :isolated_environment do
|
|
768
998
|
'end'])
|
769
999
|
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
|
770
1000
|
# all cops were disabled, then 2 were enabled again, so we
|
771
|
-
# should get 2
|
1001
|
+
# should get 2 offenses reported.
|
772
1002
|
expect($stdout.string)
|
773
1003
|
.to eq(["#{abs('example.rb')}:8:80: C: Line is too long. [95/79]",
|
774
|
-
"#{abs('example.rb')}:10:5: C: Prefer single-quoted "
|
775
|
-
"strings when you don't need string interpolation or "
|
1004
|
+
"#{abs('example.rb')}:10:5: C: Prefer single-quoted " \
|
1005
|
+
"strings when you don't need string interpolation or " \
|
776
1006
|
'special symbols.',
|
777
1007
|
''].join("\n"))
|
778
1008
|
end
|
@@ -780,7 +1010,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
780
1010
|
it 'can disable selected cops in a code section' do
|
781
1011
|
create_file('example.rb',
|
782
1012
|
['# encoding: utf-8',
|
783
|
-
'# rubocop:disable LineLength,NumericLiterals,'
|
1013
|
+
'# rubocop:disable LineLength,NumericLiterals,' \
|
784
1014
|
'StringLiterals',
|
785
1015
|
'#' * 90,
|
786
1016
|
'x(123456)',
|
@@ -793,18 +1023,17 @@ describe Rubocop::CLI, :isolated_environment do
|
|
793
1023
|
'end'])
|
794
1024
|
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
|
795
1025
|
# 3 cops were disabled, then 2 were enabled again, so we
|
796
|
-
# should get 2
|
1026
|
+
# should get 2 offenses reported.
|
797
1027
|
expect($stdout.string)
|
798
1028
|
.to eq(["#{abs('example.rb')}:8:80: C: Line is too long. [95/79]",
|
799
|
-
"#{abs('example.rb')}:10:5: C: Prefer single-quoted "
|
800
|
-
"strings when you don't need string interpolation or "
|
1029
|
+
"#{abs('example.rb')}:10:5: C: Prefer single-quoted " \
|
1030
|
+
"strings when you don't need string interpolation or " \
|
801
1031
|
'special symbols.',
|
802
1032
|
''].join("\n"))
|
803
1033
|
end
|
804
1034
|
|
805
1035
|
it 'can disable all cops on a single line' do
|
806
|
-
create_file('example.rb', [
|
807
|
-
'# encoding: utf-8',
|
1036
|
+
create_file('example.rb', ['# encoding: utf-8',
|
808
1037
|
'y("123", 123456) # rubocop:disable all'
|
809
1038
|
])
|
810
1039
|
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(0)
|
@@ -813,9 +1042,8 @@ describe Rubocop::CLI, :isolated_environment do
|
|
813
1042
|
|
814
1043
|
it 'can disable selected cops on a single line' do
|
815
1044
|
create_file('example.rb',
|
816
|
-
[
|
817
|
-
'#
|
818
|
-
'#' * 90 + ' # rubocop:disable LineLength',
|
1045
|
+
['# encoding: utf-8',
|
1046
|
+
'a' * 90 + ' # rubocop:disable LineLength',
|
819
1047
|
'#' * 95,
|
820
1048
|
'y("123") # rubocop:disable LineLength,StringLiterals'
|
821
1049
|
])
|
@@ -828,15 +1056,14 @@ describe Rubocop::CLI, :isolated_environment do
|
|
828
1056
|
end
|
829
1057
|
|
830
1058
|
it 'finds a file with no .rb extension but has a shebang line' do
|
831
|
-
create_file('example', [
|
832
|
-
'#!/usr/bin/env ruby',
|
1059
|
+
create_file('example', ['#!/usr/bin/env ruby',
|
833
1060
|
'# encoding: utf-8',
|
834
1061
|
'x = 0',
|
835
1062
|
'puts x'
|
836
1063
|
])
|
837
1064
|
expect(cli.run(%w(--format simple))).to eq(0)
|
838
1065
|
expect($stdout.string)
|
839
|
-
.to eq(['', '1 file inspected, no
|
1066
|
+
.to eq(['', '1 file inspected, no offenses detected', ''].join("\n"))
|
840
1067
|
end
|
841
1068
|
|
842
1069
|
describe 'enabling/disabling rails cops' do
|
@@ -857,34 +1084,28 @@ describe Rubocop::CLI, :isolated_environment do
|
|
857
1084
|
|
858
1085
|
it 'with configation option true in one dir runs rails cops there' do
|
859
1086
|
create_file('dir1/app/models/example1.rb', ['# encoding: utf-8',
|
860
|
-
|
861
|
-
create_file('dir1/.rubocop.yml', [
|
862
|
-
'
|
863
|
-
' RunRailsCops: true',
|
864
|
-
])
|
1087
|
+
'read_attribute(:test)'])
|
1088
|
+
create_file('dir1/.rubocop.yml', ['AllCops:',
|
1089
|
+
' RunRailsCops: true'])
|
865
1090
|
create_file('dir2/app/models/example2.rb', ['# encoding: utf-8',
|
866
1091
|
'read_attribute(:test)'])
|
867
|
-
create_file('dir2/.rubocop.yml', [
|
868
|
-
'
|
869
|
-
|
870
|
-
])
|
871
|
-
expect(cli.run(['--format', 'simple', 'dir1', 'dir2'])).to eq(1)
|
1092
|
+
create_file('dir2/.rubocop.yml', ['AllCops:',
|
1093
|
+
' RunRailsCops: false'])
|
1094
|
+
expect(cli.run(%w(--format simple dir1 dir2))).to eq(1)
|
872
1095
|
expect($stdout.string)
|
873
1096
|
.to eq(['== dir1/app/models/example1.rb ==',
|
874
|
-
'C: 2: 1: Prefer self[:attribute] over read_attribute'
|
1097
|
+
'C: 2: 1: Prefer self[:attribute] over read_attribute' \
|
875
1098
|
'(:attribute).',
|
876
1099
|
'',
|
877
|
-
'2 files inspected, 1
|
1100
|
+
'2 files inspected, 1 offense detected',
|
878
1101
|
''].join("\n"))
|
879
1102
|
end
|
880
1103
|
|
881
1104
|
it 'with configation option false but -R given runs rails cops' do
|
882
1105
|
create_file('app/models/example1.rb', ['# encoding: utf-8',
|
883
1106
|
'read_attribute(:test)'])
|
884
|
-
create_file('.rubocop.yml', [
|
885
|
-
'
|
886
|
-
' RunRailsCops: false',
|
887
|
-
])
|
1107
|
+
create_file('.rubocop.yml', ['AllCops:',
|
1108
|
+
' RunRailsCops: false'])
|
888
1109
|
expect(cli.run(['--format', 'simple', '-R', 'app/models/example1.rb']))
|
889
1110
|
.to eq(1)
|
890
1111
|
expect($stdout.string).to include('Prefer self[:attribute]')
|
@@ -893,34 +1114,24 @@ describe Rubocop::CLI, :isolated_environment do
|
|
893
1114
|
|
894
1115
|
describe 'cops can exclude files based on config' do
|
895
1116
|
it 'ignores excluded files' do
|
896
|
-
create_file('example.rb', [
|
897
|
-
'
|
898
|
-
|
899
|
-
])
|
900
|
-
create_file('
|
901
|
-
'# encoding: utf-8',
|
902
|
-
'x = 0'
|
903
|
-
])
|
904
|
-
create_file('exclude_glob.rb', [
|
905
|
-
'#!/usr/bin/env ruby',
|
1117
|
+
create_file('example.rb', ['# encoding: utf-8',
|
1118
|
+
'x = 0'])
|
1119
|
+
create_file('regexp.rb', ['# encoding: utf-8',
|
1120
|
+
'x = 0'])
|
1121
|
+
create_file('exclude_glob.rb', ['#!/usr/bin/env ruby',
|
906
1122
|
'# encoding: utf-8',
|
907
|
-
'x = 0'
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
'x = 0'
|
912
|
-
])
|
913
|
-
create_file('.rubocop.yml', [
|
914
|
-
'UselessAssignment:',
|
1123
|
+
'x = 0'])
|
1124
|
+
create_file('dir/thing.rb', ['# encoding: utf-8',
|
1125
|
+
'x = 0'])
|
1126
|
+
create_file('.rubocop.yml', ['UselessAssignment:',
|
915
1127
|
' Exclude:',
|
916
1128
|
' - example.rb',
|
917
1129
|
' - !ruby/regexp /regexp.rb\z/',
|
918
1130
|
' - "exclude_*"',
|
919
|
-
' - "dir/*"'
|
920
|
-
])
|
1131
|
+
' - "dir/*"'])
|
921
1132
|
expect(cli.run(%w(--format simple))).to eq(0)
|
922
1133
|
expect($stdout.string)
|
923
|
-
.to eq(['', '4 files inspected, no
|
1134
|
+
.to eq(['', '4 files inspected, no offenses detected',
|
924
1135
|
''].join("\n"))
|
925
1136
|
end
|
926
1137
|
|
@@ -928,47 +1139,40 @@ describe Rubocop::CLI, :isolated_environment do
|
|
928
1139
|
|
929
1140
|
describe 'configuration from file' do
|
930
1141
|
it 'finds included files' do
|
931
|
-
create_file('example', [
|
932
|
-
'# encoding: utf-8',
|
1142
|
+
create_file('example', ['# encoding: utf-8',
|
933
1143
|
'x = 0',
|
934
1144
|
'puts x'
|
935
1145
|
])
|
936
|
-
create_file('regexp', [
|
937
|
-
'# encoding: utf-8',
|
1146
|
+
create_file('regexp', ['# encoding: utf-8',
|
938
1147
|
'x = 0',
|
939
1148
|
'puts x'
|
940
1149
|
])
|
941
|
-
create_file('.rubocop.yml', [
|
942
|
-
'AllCops:',
|
1150
|
+
create_file('.rubocop.yml', ['AllCops:',
|
943
1151
|
' Includes:',
|
944
1152
|
' - example',
|
945
1153
|
' - !ruby/regexp /regexp$/'
|
946
1154
|
])
|
947
1155
|
expect(cli.run(%w(--format simple))).to eq(0)
|
948
1156
|
expect($stdout.string)
|
949
|
-
.to eq(['', '2 files inspected, no
|
1157
|
+
.to eq(['', '2 files inspected, no offenses detected',
|
950
1158
|
''].join("\n"))
|
951
1159
|
end
|
952
1160
|
|
953
1161
|
it 'ignores excluded files' do
|
954
|
-
create_file('example.rb', [
|
955
|
-
'# encoding: utf-8',
|
1162
|
+
create_file('example.rb', ['# encoding: utf-8',
|
956
1163
|
'x = 0',
|
957
1164
|
'puts x'
|
958
1165
|
])
|
959
|
-
create_file('regexp.rb', [
|
960
|
-
'# encoding: utf-8',
|
1166
|
+
create_file('regexp.rb', ['# encoding: utf-8',
|
961
1167
|
'x = 0',
|
962
1168
|
'puts x'
|
963
1169
|
])
|
964
|
-
create_file('exclude_glob.rb', [
|
965
|
-
'#!/usr/bin/env ruby',
|
1170
|
+
create_file('exclude_glob.rb', ['#!/usr/bin/env ruby',
|
966
1171
|
'# encoding: utf-8',
|
967
1172
|
'x = 0',
|
968
1173
|
'puts x'
|
969
1174
|
])
|
970
|
-
create_file('.rubocop.yml', [
|
971
|
-
'AllCops:',
|
1175
|
+
create_file('.rubocop.yml', ['AllCops:',
|
972
1176
|
' Excludes:',
|
973
1177
|
' - example.rb',
|
974
1178
|
' - !ruby/regexp /regexp.rb$/',
|
@@ -976,7 +1180,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
976
1180
|
])
|
977
1181
|
expect(cli.run(%w(--format simple))).to eq(0)
|
978
1182
|
expect($stdout.string)
|
979
|
-
.to eq(['', '0 files inspected, no
|
1183
|
+
.to eq(['', '0 files inspected, no offenses detected',
|
980
1184
|
''].join("\n"))
|
981
1185
|
end
|
982
1186
|
|
@@ -984,49 +1188,43 @@ describe Rubocop::CLI, :isolated_environment do
|
|
984
1188
|
# File.stub(:open).and_call_original causes SystemStackError.
|
985
1189
|
it 'does not read files in excluded list', broken: :rbx do
|
986
1190
|
%w(rb.rb non-rb.ext without-ext).each do |filename|
|
987
|
-
create_file("example/ignored/#{filename}", [
|
988
|
-
'# encoding: utf-8',
|
1191
|
+
create_file("example/ignored/#{filename}", ['# encoding: utf-8',
|
989
1192
|
'#' * 90
|
990
1193
|
])
|
991
1194
|
end
|
992
1195
|
|
993
|
-
create_file('example/.rubocop.yml', [
|
994
|
-
'AllCops:',
|
1196
|
+
create_file('example/.rubocop.yml', ['AllCops:',
|
995
1197
|
' Excludes:',
|
996
|
-
' - ignored/**'
|
997
|
-
|
998
|
-
expect(File).not_to receive(:open).with(%r(/ignored/))
|
1198
|
+
' - ignored/**'])
|
1199
|
+
expect(File).not_to receive(:open).with(%r{/ignored/})
|
999
1200
|
allow(File).to receive(:open).and_call_original
|
1000
1201
|
expect(cli.run(%w(--format simple example))).to eq(0)
|
1001
1202
|
expect($stdout.string)
|
1002
|
-
.to eq(['', '0 files inspected, no
|
1203
|
+
.to eq(['', '0 files inspected, no offenses detected',
|
1003
1204
|
''].join("\n"))
|
1004
1205
|
end
|
1005
1206
|
|
1006
1207
|
it 'can be configured with option to disable a certain error' do
|
1007
1208
|
create_file('example1.rb', 'puts 0 ')
|
1008
|
-
create_file('rubocop.yml', [
|
1009
|
-
'Encoding:',
|
1209
|
+
create_file('rubocop.yml', ['Encoding:',
|
1010
1210
|
' Enabled: false',
|
1011
1211
|
'',
|
1012
1212
|
'CaseIndentation:',
|
1013
|
-
' Enabled: false'
|
1014
|
-
])
|
1213
|
+
' Enabled: false'])
|
1015
1214
|
expect(cli.run(['--format', 'simple',
|
1016
1215
|
'-c', 'rubocop.yml', 'example1.rb'])).to eq(1)
|
1017
1216
|
expect($stdout.string)
|
1018
1217
|
.to eq(['== example1.rb ==',
|
1019
1218
|
'C: 1: 7: Trailing whitespace detected.',
|
1020
1219
|
'',
|
1021
|
-
'1 file inspected, 1
|
1220
|
+
'1 file inspected, 1 offense detected',
|
1022
1221
|
''].join("\n"))
|
1023
1222
|
end
|
1024
1223
|
|
1025
|
-
it 'can disable parser-derived
|
1224
|
+
it 'can disable parser-derived offenses with warning severity' do
|
1026
1225
|
# `-' interpreted as argument prefix
|
1027
1226
|
create_file('example.rb', 'puts -1')
|
1028
|
-
create_file('.rubocop.yml', [
|
1029
|
-
'Encoding:',
|
1227
|
+
create_file('.rubocop.yml', ['Encoding:',
|
1030
1228
|
' Enabled: false',
|
1031
1229
|
'',
|
1032
1230
|
'AmbiguousOperator:',
|
@@ -1035,10 +1233,9 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1035
1233
|
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(0)
|
1036
1234
|
end
|
1037
1235
|
|
1038
|
-
it 'cannot disable Syntax
|
1236
|
+
it 'cannot disable Syntax offenses with fatal/error severity' do
|
1039
1237
|
create_file('example.rb', 'class Test')
|
1040
|
-
create_file('.rubocop.yml', [
|
1041
|
-
'Encoding:',
|
1238
|
+
create_file('.rubocop.yml', ['Encoding:',
|
1042
1239
|
' Enabled: false',
|
1043
1240
|
'',
|
1044
1241
|
'Syntax:',
|
@@ -1064,7 +1261,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1064
1261
|
.to eq(['== example1.rb ==',
|
1065
1262
|
'C: 2: 5: Prefer select over find_all.',
|
1066
1263
|
'',
|
1067
|
-
'1 file inspected, 1
|
1264
|
+
'1 file inspected, 1 offense detected',
|
1068
1265
|
''].join("\n"))
|
1069
1266
|
end
|
1070
1267
|
|
@@ -1072,8 +1269,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1072
1269
|
create_file('example1.rb', ['if a',
|
1073
1270
|
' b',
|
1074
1271
|
'end'])
|
1075
|
-
create_file('rubocop.yml', [
|
1076
|
-
'Encoding:',
|
1272
|
+
create_file('rubocop.yml', ['Encoding:',
|
1077
1273
|
' Enabled: false',
|
1078
1274
|
'',
|
1079
1275
|
'LineLength:',
|
@@ -1083,19 +1279,18 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1083
1279
|
'-c', 'rubocop.yml', 'example1.rb'])
|
1084
1280
|
expect($stdout.string)
|
1085
1281
|
.to eq(['== example1.rb ==',
|
1086
|
-
'C: 1: 1: Favor modifier if usage when you have '
|
1087
|
-
'a single-line body. Another good alternative is the '
|
1282
|
+
'C: 1: 1: Favor modifier if usage when you have ' \
|
1283
|
+
'a single-line body. Another good alternative is the ' \
|
1088
1284
|
'usage of control flow &&/||.',
|
1089
1285
|
'',
|
1090
|
-
'1 file inspected, 1
|
1286
|
+
'1 file inspected, 1 offense detected',
|
1091
1287
|
''].join("\n"))
|
1092
1288
|
expect(result).to eq(1)
|
1093
1289
|
end
|
1094
1290
|
|
1095
1291
|
it 'can be configured with project config to disable a certain error' do
|
1096
1292
|
create_file('example_src/example1.rb', 'puts 0 ')
|
1097
|
-
create_file('example_src/.rubocop.yml', [
|
1098
|
-
'Encoding:',
|
1293
|
+
create_file('example_src/.rubocop.yml', ['Encoding:',
|
1099
1294
|
' Enabled: false',
|
1100
1295
|
'',
|
1101
1296
|
'CaseIndentation:',
|
@@ -1107,35 +1302,31 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1107
1302
|
.to eq(['== example_src/example1.rb ==',
|
1108
1303
|
'C: 1: 7: Trailing whitespace detected.',
|
1109
1304
|
'',
|
1110
|
-
'1 file inspected, 1
|
1305
|
+
'1 file inspected, 1 offense detected',
|
1111
1306
|
''].join("\n"))
|
1112
1307
|
end
|
1113
1308
|
|
1114
1309
|
it 'can use an alternative max line length from a config file' do
|
1115
|
-
create_file('example_src/example1.rb', [
|
1116
|
-
'# encoding: utf-8',
|
1310
|
+
create_file('example_src/example1.rb', ['# encoding: utf-8',
|
1117
1311
|
'#' * 90
|
1118
1312
|
])
|
1119
|
-
create_file('example_src/.rubocop.yml', [
|
1120
|
-
'LineLength:',
|
1313
|
+
create_file('example_src/.rubocop.yml', ['LineLength:',
|
1121
1314
|
' Enabled: true',
|
1122
1315
|
' Max: 100'
|
1123
1316
|
])
|
1124
1317
|
expect(cli.run(['--format', 'simple',
|
1125
1318
|
'example_src/example1.rb'])).to eq(0)
|
1126
1319
|
expect($stdout.string)
|
1127
|
-
.to eq(['', '1 file inspected, no
|
1320
|
+
.to eq(['', '1 file inspected, no offenses detected', ''].join("\n"))
|
1128
1321
|
end
|
1129
1322
|
|
1130
1323
|
it 'can have different config files in different directories' do
|
1131
1324
|
%w(src lib).each do |dir|
|
1132
|
-
create_file("example/#{dir}/example1.rb", [
|
1133
|
-
'# encoding: utf-8',
|
1325
|
+
create_file("example/#{dir}/example1.rb", ['# encoding: utf-8',
|
1134
1326
|
'#' * 90
|
1135
1327
|
])
|
1136
1328
|
end
|
1137
|
-
create_file('example/src/.rubocop.yml', [
|
1138
|
-
'LineLength:',
|
1329
|
+
create_file('example/src/.rubocop.yml', ['LineLength:',
|
1139
1330
|
' Enabled: true',
|
1140
1331
|
' Max: 100'
|
1141
1332
|
])
|
@@ -1144,53 +1335,47 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1144
1335
|
['== example/lib/example1.rb ==',
|
1145
1336
|
'C: 2: 80: Line is too long. [90/79]',
|
1146
1337
|
'',
|
1147
|
-
'2 files inspected, 1
|
1338
|
+
'2 files inspected, 1 offense detected',
|
1148
1339
|
''].join("\n"))
|
1149
1340
|
end
|
1150
1341
|
|
1151
1342
|
it 'prefers a config file in ancestor directory to another in home' do
|
1152
|
-
create_file('example_src/example1.rb', [
|
1153
|
-
'# encoding: utf-8',
|
1343
|
+
create_file('example_src/example1.rb', ['# encoding: utf-8',
|
1154
1344
|
'#' * 90
|
1155
1345
|
])
|
1156
|
-
create_file('example_src/.rubocop.yml', [
|
1157
|
-
'LineLength:',
|
1346
|
+
create_file('example_src/.rubocop.yml', ['LineLength:',
|
1158
1347
|
' Enabled: true',
|
1159
1348
|
' Max: 100'
|
1160
1349
|
])
|
1161
|
-
create_file("#{Dir.home}/.rubocop.yml", [
|
1162
|
-
'LineLength:',
|
1350
|
+
create_file("#{Dir.home}/.rubocop.yml", ['LineLength:',
|
1163
1351
|
' Enabled: true',
|
1164
1352
|
' Max: 80'
|
1165
1353
|
])
|
1166
1354
|
expect(cli.run(['--format', 'simple',
|
1167
1355
|
'example_src/example1.rb'])).to eq(0)
|
1168
1356
|
expect($stdout.string)
|
1169
|
-
.to eq(['', '1 file inspected, no
|
1357
|
+
.to eq(['', '1 file inspected, no offenses detected', ''].join("\n"))
|
1170
1358
|
end
|
1171
1359
|
|
1172
1360
|
it 'can exclude directories relative to .rubocop.yml' do
|
1173
1361
|
%w(src etc/test etc/spec tmp/test tmp/spec).each do |dir|
|
1174
|
-
create_file("example/#{dir}/example1.rb", [
|
1175
|
-
'# encoding: utf-8',
|
1362
|
+
create_file("example/#{dir}/example1.rb", ['# encoding: utf-8',
|
1176
1363
|
'#' * 90
|
1177
1364
|
])
|
1178
1365
|
end
|
1179
1366
|
|
1180
|
-
create_file('example/.rubocop.yml', [
|
1181
|
-
'AllCops:',
|
1367
|
+
create_file('example/.rubocop.yml', ['AllCops:',
|
1182
1368
|
' Excludes:',
|
1183
1369
|
' - src/**',
|
1184
1370
|
' - etc/**',
|
1185
|
-
' - tmp/spec/**'
|
1186
|
-
])
|
1371
|
+
' - tmp/spec/**'])
|
1187
1372
|
|
1188
1373
|
expect(cli.run(%w(--format simple example))).to eq(1)
|
1189
1374
|
expect($stdout.string).to eq(
|
1190
1375
|
['== example/tmp/test/example1.rb ==',
|
1191
1376
|
'C: 2: 80: Line is too long. [90/79]',
|
1192
1377
|
'',
|
1193
|
-
'1 file inspected, 1
|
1378
|
+
'1 file inspected, 1 offense detected',
|
1194
1379
|
''].join("\n"))
|
1195
1380
|
end
|
1196
1381
|
|
@@ -1211,7 +1396,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1211
1396
|
|
1212
1397
|
cli.run(%w(--format simple))
|
1213
1398
|
expect($stdout.string)
|
1214
|
-
.to eq(['', '0 files inspected, no
|
1399
|
+
.to eq(['', '0 files inspected, no offenses detected',
|
1215
1400
|
''].join("\n"))
|
1216
1401
|
end
|
1217
1402
|
|
@@ -1236,7 +1421,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1236
1421
|
cli.run(%w(--format simple))
|
1237
1422
|
expect($stderr.string).to eq('')
|
1238
1423
|
expect($stdout.string)
|
1239
|
-
.to eq(['', '0 files inspected, no
|
1424
|
+
.to eq(['', '0 files inspected, no offenses detected',
|
1240
1425
|
''].join("\n"))
|
1241
1426
|
end
|
1242
1427
|
|
@@ -1263,21 +1448,17 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1263
1448
|
|
1264
1449
|
cli.run(%w(--format simple))
|
1265
1450
|
expect($stdout.string)
|
1266
|
-
.to eq(['', '0 files inspected, no
|
1451
|
+
.to eq(['', '0 files inspected, no offenses detected',
|
1267
1452
|
''].join("\n"))
|
1268
1453
|
end
|
1269
1454
|
|
1270
1455
|
it 'prints a warning for an unrecognized cop name in .rubocop.yml' do
|
1271
|
-
create_file('example/example1.rb', [
|
1272
|
-
'#
|
1273
|
-
'#' * 90
|
1274
|
-
])
|
1456
|
+
create_file('example/example1.rb', ['# encoding: utf-8',
|
1457
|
+
'#' * 90])
|
1275
1458
|
|
1276
|
-
create_file('example/.rubocop.yml', [
|
1277
|
-
'LyneLenth:',
|
1459
|
+
create_file('example/.rubocop.yml', ['LyneLenth:',
|
1278
1460
|
' Enabled: true',
|
1279
|
-
' Max: 100'
|
1280
|
-
])
|
1461
|
+
' Max: 100'])
|
1281
1462
|
|
1282
1463
|
expect(cli.run(%w(--format simple example))).to eq(1)
|
1283
1464
|
expect($stderr.string)
|
@@ -1288,16 +1469,12 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1288
1469
|
end
|
1289
1470
|
|
1290
1471
|
it 'prints a warning for an unrecognized configuration parameter' do
|
1291
|
-
create_file('example/example1.rb', [
|
1292
|
-
'#
|
1293
|
-
'#' * 90
|
1294
|
-
])
|
1472
|
+
create_file('example/example1.rb', ['# encoding: utf-8',
|
1473
|
+
'#' * 90])
|
1295
1474
|
|
1296
|
-
create_file('example/.rubocop.yml', [
|
1297
|
-
'LineLength:',
|
1475
|
+
create_file('example/.rubocop.yml', ['LineLength:',
|
1298
1476
|
' Enabled: true',
|
1299
|
-
' Min: 10'
|
1300
|
-
])
|
1477
|
+
' Min: 10'])
|
1301
1478
|
|
1302
1479
|
expect(cli.run(%w(--format simple example))).to eq(1)
|
1303
1480
|
expect($stderr.string)
|
@@ -1307,78 +1484,64 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1307
1484
|
''].join("\n"))
|
1308
1485
|
end
|
1309
1486
|
|
1310
|
-
it 'works when a configuration file passed by -c specifies Excludes
|
1311
|
-
|
1312
|
-
|
1313
|
-
'#' * 90
|
1314
|
-
])
|
1487
|
+
it 'works when a configuration file passed by -c specifies Excludes ' \
|
1488
|
+
'with regexp' do
|
1489
|
+
create_file('example/example1.rb', ['# encoding: utf-8',
|
1490
|
+
'#' * 90])
|
1315
1491
|
|
1316
|
-
create_file('rubocop.yml', [
|
1317
|
-
|
1318
|
-
|
1319
|
-
' - !ruby/regexp /example1\.rb$/'
|
1320
|
-
])
|
1492
|
+
create_file('rubocop.yml', ['AllCops:',
|
1493
|
+
' Excludes:',
|
1494
|
+
' - !ruby/regexp /example1\.rb$/'])
|
1321
1495
|
|
1322
1496
|
cli.run(%w(--format simple -c rubocop.yml))
|
1323
1497
|
expect($stdout.string)
|
1324
|
-
.to eq(['', '0 files inspected, no
|
1498
|
+
.to eq(['', '0 files inspected, no offenses detected',
|
1325
1499
|
''].join("\n"))
|
1326
1500
|
end
|
1327
1501
|
|
1328
|
-
it 'works when a configuration file passed by -c specifies Excludes
|
1329
|
-
|
1330
|
-
|
1331
|
-
'#' * 90
|
1332
|
-
])
|
1502
|
+
it 'works when a configuration file passed by -c specifies Excludes ' \
|
1503
|
+
'with strings' do
|
1504
|
+
create_file('example/example1.rb', ['# encoding: utf-8',
|
1505
|
+
'#' * 90])
|
1333
1506
|
|
1334
|
-
create_file('rubocop.yml', [
|
1335
|
-
'AllCops:',
|
1507
|
+
create_file('rubocop.yml', ['AllCops:',
|
1336
1508
|
' Excludes:',
|
1337
|
-
' - example/**'
|
1338
|
-
])
|
1509
|
+
' - example/**'])
|
1339
1510
|
|
1340
1511
|
cli.run(%w(--format simple -c rubocop.yml))
|
1341
1512
|
expect($stdout.string)
|
1342
|
-
.to eq(['', '0 files inspected, no
|
1513
|
+
.to eq(['', '0 files inspected, no offenses detected',
|
1343
1514
|
''].join("\n"))
|
1344
1515
|
end
|
1345
1516
|
|
1346
1517
|
it 'works when a configuration file specifies a Severity' do
|
1347
|
-
create_file('example/example1.rb', [
|
1348
|
-
'#
|
1349
|
-
'#' * 90
|
1350
|
-
])
|
1518
|
+
create_file('example/example1.rb', ['# encoding: utf-8',
|
1519
|
+
'#' * 90])
|
1351
1520
|
|
1352
|
-
create_file('rubocop.yml', [
|
1353
|
-
'
|
1354
|
-
' Severity: error',
|
1355
|
-
])
|
1521
|
+
create_file('rubocop.yml', ['LineLength:',
|
1522
|
+
' Severity: error'])
|
1356
1523
|
|
1357
1524
|
cli.run(%w(--format simple -c rubocop.yml))
|
1358
1525
|
expect($stdout.string)
|
1359
1526
|
.to eq(['== example/example1.rb ==',
|
1360
1527
|
'E: 2: 80: Line is too long. [90/79]',
|
1361
1528
|
'',
|
1362
|
-
'1 file inspected, 1
|
1529
|
+
'1 file inspected, 1 offense detected',
|
1363
1530
|
''].join("\n"))
|
1364
1531
|
expect($stderr.string).to eq('')
|
1365
1532
|
end
|
1366
1533
|
|
1367
1534
|
it 'fails when a configuration file specifies an invalid Severity' do
|
1368
|
-
create_file('example/example1.rb', [
|
1369
|
-
'#
|
1370
|
-
'#' * 90
|
1371
|
-
])
|
1535
|
+
create_file('example/example1.rb', ['# encoding: utf-8',
|
1536
|
+
'#' * 90])
|
1372
1537
|
|
1373
|
-
create_file('rubocop.yml', [
|
1374
|
-
'
|
1375
|
-
' Severity: superbad',
|
1376
|
-
])
|
1538
|
+
create_file('rubocop.yml', ['LineLength:',
|
1539
|
+
' Severity: superbad'])
|
1377
1540
|
|
1378
1541
|
cli.run(%w(--format simple -c rubocop.yml))
|
1379
1542
|
expect($stderr.string)
|
1380
|
-
.to eq("Warning: Invalid severity 'superbad'. "
|
1381
|
-
'Valid severities are refactor, convention, '
|
1543
|
+
.to eq("Warning: Invalid severity 'superbad'. " \
|
1544
|
+
'Valid severities are refactor, convention, ' \
|
1382
1545
|
"warning, error, fatal.\n")
|
1383
1546
|
end
|
1384
1547
|
end
|