rubocop 0.29.1 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +73 -1
- data/README.md +11 -2
- data/config/default.yml +194 -6
- data/config/disabled.yml +25 -1
- data/config/enabled.yml +74 -12
- data/lib/rubocop.rb +19 -2
- data/lib/rubocop/config.rb +23 -3
- data/lib/rubocop/config_loader.rb +9 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +26 -0
- data/lib/rubocop/cop/cop.rb +33 -17
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +16 -4
- data/lib/rubocop/cop/lint/block_alignment.rb +5 -14
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +61 -0
- data/lib/rubocop/cop/lint/void.rb +11 -3
- data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +17 -0
- data/lib/rubocop/cop/performance/detect.rb +72 -0
- data/lib/rubocop/cop/performance/flat_map.rb +64 -0
- data/lib/rubocop/cop/performance/reverse_each.rb +43 -0
- data/lib/rubocop/cop/performance/sample.rb +58 -0
- data/lib/rubocop/cop/performance/size.rb +64 -0
- data/lib/rubocop/cop/rails/date.rb +121 -0
- data/lib/rubocop/cop/rails/find_by.rb +52 -0
- data/lib/rubocop/cop/rails/find_each.rb +41 -0
- data/lib/rubocop/cop/rails/time_zone.rb +93 -0
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +45 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +186 -0
- data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +76 -0
- data/lib/rubocop/cop/style/command_literal.rb +120 -0
- data/lib/rubocop/cop/style/copyright.rb +87 -0
- data/lib/rubocop/cop/style/documentation.rb +32 -0
- data/lib/rubocop/cop/style/empty_else.rb +85 -16
- data/lib/rubocop/cop/style/encoding.rb +14 -2
- data/lib/rubocop/cop/style/end_of_line.rb +5 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +86 -23
- data/lib/rubocop/cop/style/if_unless_modifier.rb +15 -0
- data/lib/rubocop/cop/style/indentation_consistency.rb +13 -6
- data/lib/rubocop/cop/style/indentation_width.rb +34 -10
- data/lib/rubocop/cop/style/lambda.rb +32 -17
- data/lib/rubocop/cop/style/line_end_concatenation.rb +4 -0
- data/lib/rubocop/cop/style/missing_else.rb +72 -0
- data/lib/rubocop/cop/style/regexp_literal.rb +89 -58
- data/lib/rubocop/cop/style/space_around_operators.rb +13 -2
- data/lib/rubocop/cop/style/space_before_block_braces.rb +3 -3
- data/lib/rubocop/cop/style/space_inside_block_braces.rb +9 -5
- data/lib/rubocop/cop/style/symbol_literal.rb +36 -0
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +7 -0
- data/lib/rubocop/cop/style/trailing_comma.rb +21 -7
- data/lib/rubocop/cop/style/trivial_accessors.rb +17 -3
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +4 -6
- data/lib/rubocop/cop/style/while_until_modifier.rb +10 -0
- data/lib/rubocop/cop/util.rb +24 -19
- data/lib/rubocop/cop/variable_force.rb +14 -0
- data/lib/rubocop/cop/variable_force/reference.rb +10 -4
- data/lib/rubocop/formatter/html_formatter.rb +10 -4
- data/lib/rubocop/formatter/text_util.rb +5 -7
- data/lib/rubocop/options.rb +47 -45
- data/lib/rubocop/path_util.rb +12 -8
- data/lib/rubocop/processed_source.rb +12 -1
- data/lib/rubocop/rake_task.rb +2 -2
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.30.0.md +145 -0
- data/rubocop.gemspec +15 -3
- metadata +22 -545
- data/.gitignore +0 -54
- data/.rspec +0 -1
- data/.rubocop.yml +0 -11
- data/.rubocop_todo.yml +0 -28
- data/.travis.yml +0 -22
- data/Gemfile +0 -15
- data/Rakefile +0 -41
- data/lib/rubocop/cop/style/blocks.rb +0 -80
- data/lib/rubocop/cop/style/unneeded_percent_x.rb +0 -25
- data/logo/rubocop-final-logo.eps +0 -0
- data/spec/.rubocop.yml +0 -5
- data/spec/fixtures/html_formatter/expected.html +0 -495
- data/spec/fixtures/html_formatter/project/app/controllers/application_controller.rb +0 -5
- data/spec/fixtures/html_formatter/project/app/controllers/books_controller.rb +0 -74
- data/spec/fixtures/html_formatter/project/app/models/book.rb +0 -5
- data/spec/isolated_environment_spec.rb +0 -24
- data/spec/project_spec.rb +0 -119
- data/spec/rubocop/cli_spec.rb +0 -2740
- data/spec/rubocop/comment_config_spec.rb +0 -105
- data/spec/rubocop/config_loader_spec.rb +0 -377
- data/spec/rubocop/config_spec.rb +0 -235
- data/spec/rubocop/config_store_spec.rb +0 -53
- data/spec/rubocop/cop/commissioner_spec.rb +0 -85
- data/spec/rubocop/cop/cop_spec.rb +0 -135
- data/spec/rubocop/cop/corrector_spec.rb +0 -59
- data/spec/rubocop/cop/force_spec.rb +0 -29
- data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +0 -113
- data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +0 -35
- data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +0 -130
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +0 -533
- data/spec/rubocop/cop/lint/condition_position_spec.rb +0 -51
- data/spec/rubocop/cop/lint/debugger_spec.rb +0 -73
- data/spec/rubocop/cop/lint/def_end_alignment_spec.rb +0 -108
- data/spec/rubocop/cop/lint/deprecated_class_methods_spec.rb +0 -38
- data/spec/rubocop/cop/lint/duplicate_methods_spec.rb +0 -189
- data/spec/rubocop/cop/lint/else_layout_spec.rb +0 -65
- data/spec/rubocop/cop/lint/empty_ensure_spec.rb +0 -27
- data/spec/rubocop/cop/lint/empty_interpolation_spec.rb +0 -18
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +0 -91
- data/spec/rubocop/cop/lint/end_in_method_spec.rb +0 -29
- data/spec/rubocop/cop/lint/ensure_return_spec.rb +0 -39
- data/spec/rubocop/cop/lint/eval_spec.rb +0 -33
- data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +0 -30
- data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +0 -33
- data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +0 -172
- data/spec/rubocop/cop/lint/literal_in_interpolation_spec.rb +0 -31
- data/spec/rubocop/cop/lint/loop_spec.rb +0 -27
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +0 -57
- data/spec/rubocop/cop/lint/require_parentheses_spec.rb +0 -82
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +0 -123
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +0 -237
- data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +0 -66
- data/spec/rubocop/cop/lint/string_conversion_in_interpolation_spec.rb +0 -51
- data/spec/rubocop/cop/lint/syntax_spec.rb +0 -34
- data/spec/rubocop/cop/lint/underscore_prefixed_variable_name_spec.rb +0 -179
- data/spec/rubocop/cop/lint/unreachable_code_spec.rb +0 -63
- data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +0 -231
- data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +0 -278
- data/spec/rubocop/cop/lint/useless_access_modifier_spec.rb +0 -192
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +0 -1778
- data/spec/rubocop/cop/lint/useless_comparison_spec.rb +0 -30
- data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +0 -48
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +0 -211
- data/spec/rubocop/cop/lint/void_spec.rb +0 -64
- data/spec/rubocop/cop/metrics/abc_size_spec.rb +0 -109
- data/spec/rubocop/cop/metrics/block_nesting_spec.rb +0 -156
- data/spec/rubocop/cop/metrics/class_length_spec.rb +0 -131
- data/spec/rubocop/cop/metrics/cyclomatic_complexity_spec.rb +0 -204
- data/spec/rubocop/cop/metrics/line_length_spec.rb +0 -136
- data/spec/rubocop/cop/metrics/method_length_spec.rb +0 -147
- data/spec/rubocop/cop/metrics/parameter_lists_spec.rb +0 -44
- data/spec/rubocop/cop/metrics/perceived_complexity_spec.rb +0 -222
- data/spec/rubocop/cop/offense_spec.rb +0 -133
- data/spec/rubocop/cop/rails/action_filter_spec.rb +0 -64
- data/spec/rubocop/cop/rails/default_scope_spec.rb +0 -37
- data/spec/rubocop/cop/rails/delegate_spec.rb +0 -177
- data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +0 -13
- data/spec/rubocop/cop/rails/output_spec.rb +0 -37
- data/spec/rubocop/cop/rails/read_write_attribute_spec.rb +0 -130
- data/spec/rubocop/cop/rails/scope_args_spec.rb +0 -25
- data/spec/rubocop/cop/rails/validation_spec.rb +0 -28
- data/spec/rubocop/cop/severity_spec.rb +0 -113
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +0 -421
- data/spec/rubocop/cop/style/accessor_method_name_spec.rb +0 -81
- data/spec/rubocop/cop/style/alias_spec.rb +0 -59
- data/spec/rubocop/cop/style/align_array_spec.rb +0 -123
- data/spec/rubocop/cop/style/align_hash_spec.rb +0 -411
- data/spec/rubocop/cop/style/align_parameters_spec.rb +0 -431
- data/spec/rubocop/cop/style/and_or_spec.rb +0 -235
- data/spec/rubocop/cop/style/array_join_spec.rb +0 -29
- data/spec/rubocop/cop/style/ascii_comments_spec.rb +0 -21
- data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +0 -36
- data/spec/rubocop/cop/style/attr_spec.rb +0 -29
- data/spec/rubocop/cop/style/bare_percent_literals_spec.rb +0 -132
- data/spec/rubocop/cop/style/begin_block_spec.rb +0 -13
- data/spec/rubocop/cop/style/block_comments_spec.rb +0 -45
- data/spec/rubocop/cop/style/block_end_newline_spec.rb +0 -61
- data/spec/rubocop/cop/style/blocks_spec.rb +0 -121
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +0 -288
- data/spec/rubocop/cop/style/case_equality_spec.rb +0 -13
- data/spec/rubocop/cop/style/case_indentation_spec.rb +0 -293
- data/spec/rubocop/cop/style/character_literal_spec.rb +0 -37
- data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +0 -40
- data/spec/rubocop/cop/style/class_and_module_children_spec.rb +0 -133
- data/spec/rubocop/cop/style/class_check_spec.rb +0 -41
- data/spec/rubocop/cop/style/class_methods_spec.rb +0 -80
- data/spec/rubocop/cop/style/class_vars_spec.rb +0 -19
- data/spec/rubocop/cop/style/collection_methods_spec.rb +0 -48
- data/spec/rubocop/cop/style/colon_method_call_spec.rb +0 -65
- data/spec/rubocop/cop/style/comment_annotation_spec.rb +0 -86
- data/spec/rubocop/cop/style/comment_indentation_spec.rb +0 -179
- data/spec/rubocop/cop/style/constant_name_spec.rb +0 -65
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +0 -43
- data/spec/rubocop/cop/style/deprecated_hash_methods_spec.rb +0 -45
- data/spec/rubocop/cop/style/documentation_spec.rb +0 -146
- data/spec/rubocop/cop/style/dot_position_spec.rb +0 -132
- data/spec/rubocop/cop/style/double_negation_spec.rb +0 -22
- data/spec/rubocop/cop/style/each_with_object_spec.rb +0 -73
- data/spec/rubocop/cop/style/else_alignment_spec.rb +0 -506
- data/spec/rubocop/cop/style/empty_else_spec.rb +0 -100
- data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +0 -135
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +0 -178
- data/spec/rubocop/cop/style/empty_lines_around_block_body_spec.rb +0 -103
- data/spec/rubocop/cop/style/empty_lines_around_class_body_spec.rb +0 -135
- data/spec/rubocop/cop/style/empty_lines_around_method_body_spec.rb +0 -90
- data/spec/rubocop/cop/style/empty_lines_around_module_body_spec.rb +0 -79
- data/spec/rubocop/cop/style/empty_lines_spec.rb +0 -51
- data/spec/rubocop/cop/style/empty_literal_spec.rb +0 -117
- data/spec/rubocop/cop/style/encoding_spec.rb +0 -139
- data/spec/rubocop/cop/style/end_block_spec.rb +0 -13
- data/spec/rubocop/cop/style/end_of_line_spec.rb +0 -65
- data/spec/rubocop/cop/style/even_odd_spec.rb +0 -164
- data/spec/rubocop/cop/style/extra_spacing_spec.rb +0 -68
- data/spec/rubocop/cop/style/file_name_spec.rb +0 -84
- data/spec/rubocop/cop/style/first_parameter_indentation_spec.rb +0 -304
- data/spec/rubocop/cop/style/flip_flop_spec.rb +0 -23
- data/spec/rubocop/cop/style/for_spec.rb +0 -105
- data/spec/rubocop/cop/style/format_string_spec.rb +0 -184
- data/spec/rubocop/cop/style/global_vars_spec.rb +0 -34
- data/spec/rubocop/cop/style/guard_clause_spec.rb +0 -172
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +0 -137
- data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +0 -146
- data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +0 -24
- data/spec/rubocop/cop/style/indent_array_spec.rb +0 -173
- data/spec/rubocop/cop/style/indent_hash_spec.rb +0 -367
- data/spec/rubocop/cop/style/indentation_consistency_spec.rb +0 -509
- data/spec/rubocop/cop/style/indentation_width_spec.rb +0 -885
- data/spec/rubocop/cop/style/infinite_loop_spec.rb +0 -48
- data/spec/rubocop/cop/style/inline_comment_spec.rb +0 -13
- data/spec/rubocop/cop/style/lambda_call_spec.rb +0 -65
- data/spec/rubocop/cop/style/lambda_spec.rb +0 -76
- data/spec/rubocop/cop/style/leading_comment_space_spec.rb +0 -64
- data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +0 -184
- data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +0 -59
- data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +0 -60
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +0 -108
- data/spec/rubocop/cop/style/method_name_spec.rb +0 -125
- data/spec/rubocop/cop/style/module_function_spec.rb +0 -24
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +0 -78
- data/spec/rubocop/cop/style/multiline_block_layout_spec.rb +0 -199
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +0 -134
- data/spec/rubocop/cop/style/multiline_operation_indentation_spec.rb +0 -464
- data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +0 -18
- data/spec/rubocop/cop/style/negated_if_spec.rb +0 -102
- data/spec/rubocop/cop/style/negated_while_spec.rb +0 -64
- data/spec/rubocop/cop/style/nested_ternary_operator_spec.rb +0 -21
- data/spec/rubocop/cop/style/next_spec.rb +0 -301
- data/spec/rubocop/cop/style/nil_comparison_spec.rb +0 -29
- data/spec/rubocop/cop/style/non_nil_check_spec.rb +0 -132
- data/spec/rubocop/cop/style/not_spec.rb +0 -28
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +0 -80
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +0 -13
- data/spec/rubocop/cop/style/op_method_spec.rb +0 -85
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +0 -161
- data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +0 -316
- data/spec/rubocop/cop/style/percent_q_literals_spec.rb +0 -122
- data/spec/rubocop/cop/style/perl_backrefs_spec.rb +0 -22
- data/spec/rubocop/cop/style/predicate_name_spec.rb +0 -57
- data/spec/rubocop/cop/style/proc_spec.rb +0 -27
- data/spec/rubocop/cop/style/raise_args_spec.rb +0 -87
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +0 -121
- data/spec/rubocop/cop/style/redundant_exception_spec.rb +0 -59
- data/spec/rubocop/cop/style/redundant_return_spec.rb +0 -171
- data/spec/rubocop/cop/style/redundant_self_spec.rb +0 -186
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +0 -188
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +0 -116
- data/spec/rubocop/cop/style/self_assignment_spec.rb +0 -49
- data/spec/rubocop/cop/style/semicolon_spec.rb +0 -114
- data/spec/rubocop/cop/style/signal_exception_spec.rb +0 -289
- data/spec/rubocop/cop/style/single_line_block_params_spec.rb +0 -82
- data/spec/rubocop/cop/style/single_line_methods_spec.rb +0 -94
- data/spec/rubocop/cop/style/single_space_before_first_arg_spec.rb +0 -63
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +0 -55
- data/spec/rubocop/cop/style/space_after_comma_spec.rb +0 -30
- data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +0 -84
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +0 -70
- data/spec/rubocop/cop/style/space_after_not_spec.rb +0 -22
- data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +0 -23
- data/spec/rubocop/cop/style/space_around_block_parameters_spec.rb +0 -155
- data/spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb +0 -95
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +0 -330
- data/spec/rubocop/cop/style/space_before_block_braces_spec.rb +0 -73
- data/spec/rubocop/cop/style/space_before_comma_spec.rb +0 -42
- data/spec/rubocop/cop/style/space_before_comment_spec.rb +0 -34
- data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +0 -70
- data/spec/rubocop/cop/style/space_before_semicolon_spec.rb +0 -28
- data/spec/rubocop/cop/style/space_inside_block_braces_spec.rb +0 -317
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +0 -83
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +0 -147
- data/spec/rubocop/cop/style/space_inside_parens_spec.rb +0 -44
- data/spec/rubocop/cop/style/space_inside_range_literal_spec.rb +0 -64
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +0 -62
- data/spec/rubocop/cop/style/string_literals_in_interpolation_spec.rb +0 -99
- data/spec/rubocop/cop/style/string_literals_spec.rb +0 -228
- data/spec/rubocop/cop/style/struct_inheritance_spec.rb +0 -44
- data/spec/rubocop/cop/style/symbol_array_spec.rb +0 -37
- data/spec/rubocop/cop/style/symbol_proc_spec.rb +0 -100
- data/spec/rubocop/cop/style/tab_spec.rb +0 -47
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +0 -83
- data/spec/rubocop/cop/style/trailing_comma_spec.rb +0 -390
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +0 -31
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +0 -558
- data/spec/rubocop/cop/style/unless_else_spec.rb +0 -23
- data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +0 -90
- data/spec/rubocop/cop/style/unneeded_percent_q_spec.rb +0 -127
- data/spec/rubocop/cop/style/unneeded_percent_x_spec.rb +0 -34
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +0 -76
- data/spec/rubocop/cop/style/variable_name_spec.rb +0 -107
- data/spec/rubocop/cop/style/when_then_spec.rb +0 -42
- data/spec/rubocop/cop/style/while_until_do_spec.rb +0 -55
- data/spec/rubocop/cop/style/while_until_modifier_spec.rb +0 -93
- data/spec/rubocop/cop/style/word_array_spec.rb +0 -117
- data/spec/rubocop/cop/team_spec.rb +0 -190
- data/spec/rubocop/cop/util_spec.rb +0 -102
- data/spec/rubocop/cop/variable_force/assignment_spec.rb +0 -200
- data/spec/rubocop/cop/variable_force/locatable_spec.rb +0 -699
- data/spec/rubocop/cop/variable_force/reference_spec.rb +0 -19
- data/spec/rubocop/cop/variable_force/scope_spec.rb +0 -319
- data/spec/rubocop/cop/variable_force/variable_spec.rb +0 -59
- data/spec/rubocop/cop/variable_force/variable_table_spec.rb +0 -276
- data/spec/rubocop/cop/variable_force_spec.rb +0 -26
- data/spec/rubocop/formatter/base_formatter_spec.rb +0 -191
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +0 -114
- data/spec/rubocop/formatter/colorizable_spec.rb +0 -107
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +0 -50
- data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +0 -67
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +0 -63
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +0 -33
- data/spec/rubocop/formatter/formatter_set_spec.rb +0 -141
- data/spec/rubocop/formatter/fuubar_style_formatter_spec.rb +0 -129
- data/spec/rubocop/formatter/html_formatter_spec.rb +0 -48
- data/spec/rubocop/formatter/json_formatter_spec.rb +0 -152
- data/spec/rubocop/formatter/offense_count_formatter_spec.rb +0 -75
- data/spec/rubocop/formatter/progress_formatter_spec.rb +0 -182
- data/spec/rubocop/formatter/simple_text_formatter_spec.rb +0 -135
- data/spec/rubocop/formatter/text_util_spec.rb +0 -55
- data/spec/rubocop/options_spec.rb +0 -181
- data/spec/rubocop/path_util_spec.rb +0 -77
- data/spec/rubocop/processed_source_spec.rb +0 -184
- data/spec/rubocop/rake_task_spec.rb +0 -122
- data/spec/rubocop/runner_spec.rb +0 -99
- data/spec/rubocop/string_util_spec.rb +0 -46
- data/spec/rubocop/target_finder_spec.rb +0 -245
- data/spec/rubocop/token_spec.rb +0 -29
- data/spec/spec_helper.rb +0 -39
- data/spec/support/cop_helper.rb +0 -75
- data/spec/support/cops/class_must_be_a_module_cop.rb +0 -19
- data/spec/support/cops/module_must_be_a_class_cop.rb +0 -19
- data/spec/support/coverage.rb +0 -15
- data/spec/support/custom_matchers.rb +0 -58
- data/spec/support/file_helper.rb +0 -23
- data/spec/support/jruby_workaround.rb +0 -15
- data/spec/support/mri_syntax_checker.rb +0 -73
- data/spec/support/shared_contexts.rb +0 -53
- data/spec/support/shared_examples.rb +0 -55
- data/spec/support/statement_modifier_helper.rb +0 -41
@@ -1,885 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe RuboCop::Cop::Style::IndentationWidth do
|
6
|
-
subject(:cop) { described_class.new(config) }
|
7
|
-
let(:config) do
|
8
|
-
RuboCop::Config.new('Style/IndentationWidth' => cop_config,
|
9
|
-
'Lint/EndAlignment' => end_alignment_config)
|
10
|
-
end
|
11
|
-
let(:end_alignment_config) do
|
12
|
-
{ 'Enabled' => true, 'AlignWith' => 'variable' }
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'with Width set to 4' do
|
16
|
-
let(:cop_config) { { 'Width' => 4 } }
|
17
|
-
|
18
|
-
context 'with if statement' do
|
19
|
-
it 'registers an offense for bad indentation of an if body' do
|
20
|
-
inspect_source(cop,
|
21
|
-
['if cond',
|
22
|
-
' func',
|
23
|
-
'end'])
|
24
|
-
expect(cop.messages).to eq(['Use 4 (not 1) spaces for indentation.'])
|
25
|
-
expect(cop.highlights).to eq([' '])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#autocorrect' do
|
30
|
-
it 'corrects bad indentation' do
|
31
|
-
corrected = autocorrect_source(cop,
|
32
|
-
['if a1',
|
33
|
-
' b1',
|
34
|
-
' b1',
|
35
|
-
'elsif a2',
|
36
|
-
' b2',
|
37
|
-
'else',
|
38
|
-
' c',
|
39
|
-
'end'])
|
40
|
-
expect(corrected)
|
41
|
-
.to eq ['if a1',
|
42
|
-
' b1',
|
43
|
-
' b1', # Will be corrected by IndentationConsistency.
|
44
|
-
'elsif a2',
|
45
|
-
' b2',
|
46
|
-
'else',
|
47
|
-
' c',
|
48
|
-
'end'].join("\n")
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'with Width set to 2' do
|
54
|
-
let(:cop_config) { { 'Width' => 2 } }
|
55
|
-
|
56
|
-
context 'with if statement' do
|
57
|
-
it 'registers an offense for bad indentation of an if body' do
|
58
|
-
inspect_source(cop,
|
59
|
-
['if cond',
|
60
|
-
' func',
|
61
|
-
'end'])
|
62
|
-
expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
|
63
|
-
expect(cop.highlights).to eq([' '])
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'registers an offense for bad indentation of an else body' do
|
67
|
-
inspect_source(cop,
|
68
|
-
['if cond',
|
69
|
-
' func1',
|
70
|
-
'else',
|
71
|
-
' func2',
|
72
|
-
'end'])
|
73
|
-
expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
|
74
|
-
expect(cop.highlights).to eq([' '])
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'registers an offense for bad indentation of an elsif body' do
|
78
|
-
inspect_source(cop,
|
79
|
-
['if a1',
|
80
|
-
' b1',
|
81
|
-
'elsif a2',
|
82
|
-
' b2',
|
83
|
-
'else',
|
84
|
-
' c',
|
85
|
-
'end'])
|
86
|
-
expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'registers offense for bad indentation of ternary inside else' do
|
90
|
-
inspect_source(cop,
|
91
|
-
['if a',
|
92
|
-
' b',
|
93
|
-
'else',
|
94
|
-
' x ? y : z',
|
95
|
-
'end'])
|
96
|
-
expect(cop.messages)
|
97
|
-
.to eq(['Use 2 (not 5) spaces for indentation.'])
|
98
|
-
expect(cop.highlights).to eq([' '])
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'registers offense for bad indentation of modifier if in else' do
|
102
|
-
inspect_source(cop,
|
103
|
-
['if a',
|
104
|
-
' b',
|
105
|
-
'else',
|
106
|
-
' x if y',
|
107
|
-
'end'])
|
108
|
-
expect(cop.messages)
|
109
|
-
.to eq(['Use 2 (not 3) spaces for indentation.'])
|
110
|
-
end
|
111
|
-
|
112
|
-
describe '#autocorrect' do
|
113
|
-
it 'corrects bad indentation' do
|
114
|
-
corrected = autocorrect_source(cop,
|
115
|
-
['if a1',
|
116
|
-
' b1',
|
117
|
-
' b1',
|
118
|
-
'elsif a2',
|
119
|
-
' b2',
|
120
|
-
'else',
|
121
|
-
' c',
|
122
|
-
'end'])
|
123
|
-
expect(corrected)
|
124
|
-
.to eq ['if a1',
|
125
|
-
' b1',
|
126
|
-
' b1', # Will be corrected by IndentationConsistency.
|
127
|
-
'elsif a2',
|
128
|
-
' b2',
|
129
|
-
'else',
|
130
|
-
' c',
|
131
|
-
'end'].join("\n")
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'does not correct in scopes that contain block comments' do
|
135
|
-
corrected = autocorrect_source(cop,
|
136
|
-
['module Foo',
|
137
|
-
'class Bar',
|
138
|
-
'=begin',
|
139
|
-
'This is a nice long',
|
140
|
-
'comment',
|
141
|
-
'which spans a few lines',
|
142
|
-
'=end',
|
143
|
-
'def baz',
|
144
|
-
'do_something',
|
145
|
-
'end',
|
146
|
-
'end',
|
147
|
-
'end'])
|
148
|
-
expect(corrected).to eq ['module Foo',
|
149
|
-
# The class has a block comment within, so
|
150
|
-
# it's not corrected.
|
151
|
-
'class Bar',
|
152
|
-
'=begin',
|
153
|
-
'This is a nice long',
|
154
|
-
'comment',
|
155
|
-
'which spans a few lines',
|
156
|
-
'=end',
|
157
|
-
# The method has no block comment inside, so
|
158
|
-
# it's corrected.
|
159
|
-
' def baz',
|
160
|
-
# Method contents are also corrected.
|
161
|
-
' do_something',
|
162
|
-
' end',
|
163
|
-
'end',
|
164
|
-
'end'].join("\n")
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'does not indent heredoc strings' do
|
168
|
-
corrected = autocorrect_source(cop,
|
169
|
-
['module Foo',
|
170
|
-
'module Bar',
|
171
|
-
' SOMETHING = <<GOO',
|
172
|
-
'text',
|
173
|
-
'more text',
|
174
|
-
'foo',
|
175
|
-
'GOO',
|
176
|
-
' def baz',
|
177
|
-
' do_something("#{x}")',
|
178
|
-
' end',
|
179
|
-
'end',
|
180
|
-
'end'])
|
181
|
-
expect(corrected).to eq ['module Foo',
|
182
|
-
' module Bar',
|
183
|
-
' SOMETHING = <<GOO',
|
184
|
-
'text',
|
185
|
-
'more text',
|
186
|
-
'foo',
|
187
|
-
'GOO',
|
188
|
-
' def baz',
|
189
|
-
' do_something("#{x}")',
|
190
|
-
' end',
|
191
|
-
' end',
|
192
|
-
'end'].join("\n")
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'indents parenthesized expressions' do
|
196
|
-
src = ['var1 = nil',
|
197
|
-
'array_list = []',
|
198
|
-
'if var1.attr1 != 0 || array_list.select{ |w|',
|
199
|
-
' (w.attr2 == var1.attr2)',
|
200
|
-
' }.blank?',
|
201
|
-
' array_list << var1',
|
202
|
-
'end']
|
203
|
-
corrected = autocorrect_source(cop, src)
|
204
|
-
expect(corrected)
|
205
|
-
.to eq ['var1 = nil',
|
206
|
-
'array_list = []',
|
207
|
-
'if var1.attr1 != 0 || array_list.select{ |w|',
|
208
|
-
' (w.attr2 == var1.attr2)',
|
209
|
-
' }.blank?',
|
210
|
-
' array_list << var1',
|
211
|
-
'end'].join("\n")
|
212
|
-
end
|
213
|
-
|
214
|
-
it 'leaves rescue ; end unchanged' do
|
215
|
-
src = ['if variable',
|
216
|
-
' begin',
|
217
|
-
' do_something',
|
218
|
-
' rescue ; end # consume any exception',
|
219
|
-
'end']
|
220
|
-
corrected = autocorrect_source(cop, src)
|
221
|
-
expect(corrected).to eq src.join("\n")
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'leaves block unchanged if block end is not on its own line' do
|
225
|
-
src = ['a_function {',
|
226
|
-
' # a comment',
|
227
|
-
' result = AObject.find_by_attr(attr) if attr',
|
228
|
-
' result || AObject.make(',
|
229
|
-
' :attr => attr,',
|
230
|
-
' :attr2 => Other.get_value(),',
|
231
|
-
' :attr3 => Another.get_value()) }']
|
232
|
-
corrected = autocorrect_source(cop, src)
|
233
|
-
expect(corrected).to eq src.join("\n")
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
it 'accepts a one line if statement' do
|
238
|
-
inspect_source(cop, 'if cond then func1 else func2 end')
|
239
|
-
expect(cop.offenses).to be_empty
|
240
|
-
end
|
241
|
-
|
242
|
-
it 'accepts a correctly aligned if/elsif/else/end' do
|
243
|
-
inspect_source(cop,
|
244
|
-
['if a1',
|
245
|
-
' b1',
|
246
|
-
'elsif a2',
|
247
|
-
' b2',
|
248
|
-
'else',
|
249
|
-
' c',
|
250
|
-
'end'])
|
251
|
-
expect(cop.offenses).to be_empty
|
252
|
-
end
|
253
|
-
|
254
|
-
it 'accepts a correctly aligned if/elsif/else/end as a method argument' do
|
255
|
-
inspect_source(cop,
|
256
|
-
['foo(',
|
257
|
-
' if a1',
|
258
|
-
' b1',
|
259
|
-
' elsif a2',
|
260
|
-
' b2',
|
261
|
-
' else',
|
262
|
-
' c',
|
263
|
-
' end',
|
264
|
-
')'])
|
265
|
-
expect(cop.offenses).to be_empty
|
266
|
-
end
|
267
|
-
|
268
|
-
it 'accepts if/elsif/else/end laid out as a table' do
|
269
|
-
inspect_source(cop,
|
270
|
-
['if @io == $stdout then str << "$stdout"',
|
271
|
-
'elsif @io == $stdin then str << "$stdin"',
|
272
|
-
'elsif @io == $stderr then str << "$stderr"',
|
273
|
-
'else str << @io.class.to_s',
|
274
|
-
'end'])
|
275
|
-
expect(cop.offenses).to be_empty
|
276
|
-
end
|
277
|
-
|
278
|
-
it 'accepts if/then/else/end laid out as another table' do
|
279
|
-
inspect_source(cop,
|
280
|
-
["if File.exist?('config.save')",
|
281
|
-
'then ConfigTable.load',
|
282
|
-
'else ConfigTable.new',
|
283
|
-
'end'])
|
284
|
-
expect(cop.offenses).to be_empty
|
285
|
-
end
|
286
|
-
|
287
|
-
it 'accepts an empty if' do
|
288
|
-
inspect_source(cop,
|
289
|
-
['if a',
|
290
|
-
'else',
|
291
|
-
'end'])
|
292
|
-
expect(cop.offenses).to be_empty
|
293
|
-
end
|
294
|
-
|
295
|
-
context 'with assignment' do
|
296
|
-
context 'when alignment style is variable' do
|
297
|
-
context 'and end is aligned with variable' do
|
298
|
-
it 'accepts an if with end aligned with setter' do
|
299
|
-
inspect_source(cop,
|
300
|
-
['foo.bar = if baz',
|
301
|
-
' derp',
|
302
|
-
'end'])
|
303
|
-
expect(cop.offenses).to be_empty
|
304
|
-
end
|
305
|
-
|
306
|
-
it 'accepts an if with end aligned with element assignment' do
|
307
|
-
inspect_source(cop,
|
308
|
-
['foo[bar] = if baz',
|
309
|
-
' derp',
|
310
|
-
'end'])
|
311
|
-
expect(cop.offenses).to be_empty
|
312
|
-
end
|
313
|
-
|
314
|
-
it 'accepts an if with end aligned with variable' do
|
315
|
-
inspect_source(cop,
|
316
|
-
['var = if a',
|
317
|
-
' 0',
|
318
|
-
'end',
|
319
|
-
'@var = if a',
|
320
|
-
' 0',
|
321
|
-
'end',
|
322
|
-
'$var = if a',
|
323
|
-
' 0',
|
324
|
-
'end',
|
325
|
-
'var ||= if a',
|
326
|
-
' 0',
|
327
|
-
'end',
|
328
|
-
'var &&= if a',
|
329
|
-
' 0',
|
330
|
-
'end',
|
331
|
-
'var -= if a',
|
332
|
-
' 0',
|
333
|
-
'end',
|
334
|
-
'VAR = if a',
|
335
|
-
' 0',
|
336
|
-
'end'])
|
337
|
-
expect(cop.offenses).to be_empty
|
338
|
-
end
|
339
|
-
|
340
|
-
it 'accepts an if/else' do
|
341
|
-
inspect_source(cop,
|
342
|
-
['var = if a',
|
343
|
-
' 0',
|
344
|
-
'else',
|
345
|
-
' 1',
|
346
|
-
'end'])
|
347
|
-
expect(cop.offenses).to be_empty
|
348
|
-
end
|
349
|
-
|
350
|
-
it 'accepts an if/else with chaining after the end' do
|
351
|
-
inspect_source(cop,
|
352
|
-
['var = if a',
|
353
|
-
' 0',
|
354
|
-
'else',
|
355
|
-
' 1',
|
356
|
-
'end.abc.join("")'])
|
357
|
-
expect(cop.offenses).to be_empty
|
358
|
-
end
|
359
|
-
|
360
|
-
it 'accepts an if/else with chaining with a block after the end' do
|
361
|
-
inspect_source(cop,
|
362
|
-
['var = if a',
|
363
|
-
' 0',
|
364
|
-
'else',
|
365
|
-
' 1',
|
366
|
-
'end.abc.tap {}'])
|
367
|
-
expect(cop.offenses).to be_empty
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
context 'and end is aligned with keyword' do
|
372
|
-
it 'registers an offense for an if with setter' do
|
373
|
-
inspect_source(cop,
|
374
|
-
['foo.bar = if baz',
|
375
|
-
' derp',
|
376
|
-
' end'])
|
377
|
-
expect(cop.messages)
|
378
|
-
.to eq(['Use 2 (not 12) spaces for indentation.'])
|
379
|
-
end
|
380
|
-
|
381
|
-
it 'registers an offense for an if with element assignment' do
|
382
|
-
inspect_source(cop,
|
383
|
-
['foo[bar] = if baz',
|
384
|
-
' derp',
|
385
|
-
' end'])
|
386
|
-
expect(cop.messages)
|
387
|
-
.to eq(['Use 2 (not 13) spaces for indentation.'])
|
388
|
-
end
|
389
|
-
|
390
|
-
it 'registers an offense for an if' do
|
391
|
-
inspect_source(cop,
|
392
|
-
['var = if a',
|
393
|
-
' 0',
|
394
|
-
' end'])
|
395
|
-
expect(cop.messages)
|
396
|
-
.to eq(['Use 2 (not 8) spaces for indentation.'])
|
397
|
-
end
|
398
|
-
|
399
|
-
it 'registers an offense for a while' do
|
400
|
-
inspect_source(cop,
|
401
|
-
['var = while a',
|
402
|
-
' b',
|
403
|
-
' end'])
|
404
|
-
expect(cop.messages)
|
405
|
-
.to eq(['Use 2 (not 8) spaces for indentation.'])
|
406
|
-
end
|
407
|
-
|
408
|
-
it 'registers an offense for an until' do
|
409
|
-
inspect_source(cop,
|
410
|
-
['var = until a',
|
411
|
-
' b',
|
412
|
-
' end'])
|
413
|
-
expect(cop.messages)
|
414
|
-
.to eq(['Use 2 (not 8) spaces for indentation.'])
|
415
|
-
end
|
416
|
-
end
|
417
|
-
end
|
418
|
-
|
419
|
-
shared_examples 'assignment and if with keyword alignment' do
|
420
|
-
context 'and end is aligned with variable' do
|
421
|
-
it 'registers an offense for an if' do
|
422
|
-
inspect_source(cop,
|
423
|
-
['var = if a',
|
424
|
-
' 0',
|
425
|
-
'end'])
|
426
|
-
expect(cop.messages)
|
427
|
-
.to eq(['Use 2 (not -4) spaces for indentation.'])
|
428
|
-
end
|
429
|
-
|
430
|
-
it 'registers an offense for a while' do
|
431
|
-
inspect_source(cop,
|
432
|
-
['var = while a',
|
433
|
-
' b',
|
434
|
-
'end'])
|
435
|
-
expect(cop.messages)
|
436
|
-
.to eq(['Use 2 (not -4) spaces for indentation.'])
|
437
|
-
end
|
438
|
-
|
439
|
-
it 'autocorrects bad indentation' do
|
440
|
-
corrected = autocorrect_source(cop,
|
441
|
-
['var = if a',
|
442
|
-
' b',
|
443
|
-
'end',
|
444
|
-
'',
|
445
|
-
'var = while a',
|
446
|
-
' b',
|
447
|
-
'end'])
|
448
|
-
expect(corrected).to eq ['var = if a',
|
449
|
-
' b',
|
450
|
-
'end', # Not this cop's job to fix end.
|
451
|
-
'',
|
452
|
-
'var = while a',
|
453
|
-
' b',
|
454
|
-
'end'].join("\n")
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
context 'and end is aligned with keyword' do
|
459
|
-
it 'accepts an if in assignment' do
|
460
|
-
inspect_source(cop,
|
461
|
-
['var = if a',
|
462
|
-
' 0',
|
463
|
-
' end'])
|
464
|
-
expect(cop.offenses).to be_empty
|
465
|
-
end
|
466
|
-
|
467
|
-
it 'accepts an if/else in assignment' do
|
468
|
-
inspect_source(cop,
|
469
|
-
['var = if a',
|
470
|
-
' 0',
|
471
|
-
' else',
|
472
|
-
' 1',
|
473
|
-
' end'])
|
474
|
-
expect(cop.offenses).to be_empty
|
475
|
-
end
|
476
|
-
|
477
|
-
it 'accepts an if/else in assignment on next line' do
|
478
|
-
inspect_source(cop,
|
479
|
-
['var =',
|
480
|
-
' if a',
|
481
|
-
' 0',
|
482
|
-
' else',
|
483
|
-
' 1',
|
484
|
-
' end'])
|
485
|
-
expect(cop.offenses).to be_empty
|
486
|
-
end
|
487
|
-
|
488
|
-
it 'accepts a while in assignment' do
|
489
|
-
inspect_source(cop,
|
490
|
-
['var = while a',
|
491
|
-
' b',
|
492
|
-
' end'])
|
493
|
-
expect(cop.offenses).to be_empty
|
494
|
-
end
|
495
|
-
|
496
|
-
it 'accepts an until in assignment' do
|
497
|
-
inspect_source(cop,
|
498
|
-
['var = until a',
|
499
|
-
' b',
|
500
|
-
' end'])
|
501
|
-
expect(cop.offenses).to be_empty
|
502
|
-
end
|
503
|
-
end
|
504
|
-
end
|
505
|
-
|
506
|
-
context 'when alignment style is keyword by choice' do
|
507
|
-
let(:end_alignment_config) do
|
508
|
-
{ 'Enabled' => true, 'AlignWith' => 'keyword' }
|
509
|
-
end
|
510
|
-
|
511
|
-
include_examples 'assignment and if with keyword alignment'
|
512
|
-
end
|
513
|
-
|
514
|
-
context 'when alignment style is keyword by default' do
|
515
|
-
let(:end_alignment_config) do
|
516
|
-
{ 'Enabled' => false, 'AlignWith' => 'variable' }
|
517
|
-
end
|
518
|
-
|
519
|
-
include_examples 'assignment and if with keyword alignment'
|
520
|
-
end
|
521
|
-
end
|
522
|
-
|
523
|
-
it 'accepts an if/else branches with rescue clauses' do
|
524
|
-
# Because of how the rescue clauses come out of Parser, these are
|
525
|
-
# special and need to be tested.
|
526
|
-
inspect_source(cop,
|
527
|
-
['if a',
|
528
|
-
' a rescue nil',
|
529
|
-
'else',
|
530
|
-
' a rescue nil',
|
531
|
-
'end'])
|
532
|
-
expect(cop.offenses).to be_empty
|
533
|
-
end
|
534
|
-
end
|
535
|
-
|
536
|
-
context 'with unless' do
|
537
|
-
it 'registers an offense for bad indentation of an unless body' do
|
538
|
-
inspect_source(cop,
|
539
|
-
['unless cond',
|
540
|
-
' func',
|
541
|
-
'end'])
|
542
|
-
expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
|
543
|
-
end
|
544
|
-
|
545
|
-
it 'accepts an empty unless' do
|
546
|
-
inspect_source(cop,
|
547
|
-
['unless a',
|
548
|
-
'else',
|
549
|
-
'end'])
|
550
|
-
expect(cop.offenses).to be_empty
|
551
|
-
end
|
552
|
-
end
|
553
|
-
|
554
|
-
context 'with case' do
|
555
|
-
it 'registers an offense for bad indentation in a case/when body' do
|
556
|
-
inspect_source(cop,
|
557
|
-
['case a',
|
558
|
-
'when b',
|
559
|
-
' c',
|
560
|
-
'end'])
|
561
|
-
expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
|
562
|
-
end
|
563
|
-
|
564
|
-
it 'registers an offense for bad indentation in a case/else body' do
|
565
|
-
inspect_source(cop,
|
566
|
-
['case a',
|
567
|
-
'when b',
|
568
|
-
' c',
|
569
|
-
'when d',
|
570
|
-
' e',
|
571
|
-
'else',
|
572
|
-
' f',
|
573
|
-
'end'])
|
574
|
-
expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
|
575
|
-
end
|
576
|
-
|
577
|
-
it 'accepts correctly indented case/when/else' do
|
578
|
-
inspect_source(cop,
|
579
|
-
['case a',
|
580
|
-
'when b',
|
581
|
-
' c',
|
582
|
-
' c',
|
583
|
-
'when d',
|
584
|
-
'else',
|
585
|
-
' f',
|
586
|
-
'end'])
|
587
|
-
expect(cop.offenses).to be_empty
|
588
|
-
end
|
589
|
-
|
590
|
-
it 'accepts aligned values in when clause' do
|
591
|
-
inspect_source(cop,
|
592
|
-
['case superclass',
|
593
|
-
'when /\A(#{NAMESPACEMATCH})(?:\s|\Z)/,',
|
594
|
-
' /\A(Struct|OStruct)\.new/,',
|
595
|
-
' /\ADelegateClass\((.+?)\)\s*\Z/,',
|
596
|
-
' /\A(#{NAMESPACEMATCH})\(/',
|
597
|
-
' $1',
|
598
|
-
'when "self"',
|
599
|
-
' namespace.path',
|
600
|
-
'end'])
|
601
|
-
expect(cop.offenses).to be_empty
|
602
|
-
end
|
603
|
-
|
604
|
-
it 'accepts case/when/else laid out as a table' do
|
605
|
-
inspect_source(cop,
|
606
|
-
['case sexp.loc.keyword.source',
|
607
|
-
"when 'if' then cond, body, _else = *sexp",
|
608
|
-
"when 'unless' then cond, _else, body = *sexp",
|
609
|
-
'else cond, body = *sexp',
|
610
|
-
'end'])
|
611
|
-
expect(cop.offenses).to be_empty
|
612
|
-
end
|
613
|
-
|
614
|
-
it 'accepts case/when/else with then beginning a line' do
|
615
|
-
inspect_source(cop,
|
616
|
-
['case sexp.loc.keyword.source',
|
617
|
-
"when 'if'",
|
618
|
-
'then cond, body, _else = *sexp',
|
619
|
-
'end'])
|
620
|
-
expect(cop.offenses).to be_empty
|
621
|
-
end
|
622
|
-
|
623
|
-
it 'accepts indented when/else plus indented body' do
|
624
|
-
# "Indent when as deep as case" is the job of another cop.
|
625
|
-
inspect_source(cop,
|
626
|
-
['case code_type',
|
627
|
-
" when 'ruby', 'sql', 'plain'",
|
628
|
-
' code_type',
|
629
|
-
" when 'erb'",
|
630
|
-
" 'ruby; html-script: true'",
|
631
|
-
' when "html"',
|
632
|
-
" 'xml'",
|
633
|
-
' else',
|
634
|
-
" 'plain'",
|
635
|
-
'end'])
|
636
|
-
expect(cop.offenses).to be_empty
|
637
|
-
end
|
638
|
-
end
|
639
|
-
|
640
|
-
context 'with while/until' do
|
641
|
-
it 'registers an offense for bad indentation of a while body' do
|
642
|
-
inspect_source(cop,
|
643
|
-
['while cond',
|
644
|
-
' func',
|
645
|
-
'end'])
|
646
|
-
expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
|
647
|
-
end
|
648
|
-
|
649
|
-
it 'registers an offense for bad indentation of begin/end/while' do
|
650
|
-
inspect_source(cop,
|
651
|
-
['something = begin',
|
652
|
-
' func1',
|
653
|
-
' func2',
|
654
|
-
'end while cond'])
|
655
|
-
expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
|
656
|
-
end
|
657
|
-
|
658
|
-
it 'registers an offense for bad indentation of an until body' do
|
659
|
-
inspect_source(cop,
|
660
|
-
['until cond',
|
661
|
-
' func',
|
662
|
-
'end'])
|
663
|
-
expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
|
664
|
-
end
|
665
|
-
|
666
|
-
it 'accepts an empty while' do
|
667
|
-
inspect_source(cop,
|
668
|
-
['while a',
|
669
|
-
'end'])
|
670
|
-
expect(cop.offenses).to be_empty
|
671
|
-
end
|
672
|
-
end
|
673
|
-
|
674
|
-
context 'with for' do
|
675
|
-
it 'registers an offense for bad indentation of a for body' do
|
676
|
-
inspect_source(cop,
|
677
|
-
['for var in 1..10',
|
678
|
-
' func',
|
679
|
-
'end'])
|
680
|
-
expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
|
681
|
-
end
|
682
|
-
|
683
|
-
it 'accepts an empty for' do
|
684
|
-
inspect_source(cop,
|
685
|
-
['for var in 1..10',
|
686
|
-
'end'])
|
687
|
-
expect(cop.offenses).to be_empty
|
688
|
-
end
|
689
|
-
end
|
690
|
-
|
691
|
-
context 'with def/defs' do
|
692
|
-
it 'registers an offense for bad indentation of a def body' do
|
693
|
-
inspect_source(cop,
|
694
|
-
['def test',
|
695
|
-
' func1',
|
696
|
-
' func2', # No offense registered for this.
|
697
|
-
'end'])
|
698
|
-
expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
|
699
|
-
end
|
700
|
-
|
701
|
-
it 'registers an offense for bad indentation of a defs body' do
|
702
|
-
inspect_source(cop,
|
703
|
-
['def self.test',
|
704
|
-
' func',
|
705
|
-
'end'])
|
706
|
-
expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
|
707
|
-
end
|
708
|
-
|
709
|
-
it 'accepts an empty def body' do
|
710
|
-
inspect_source(cop,
|
711
|
-
['def test',
|
712
|
-
'end'])
|
713
|
-
expect(cop.offenses).to be_empty
|
714
|
-
end
|
715
|
-
|
716
|
-
it 'accepts an empty defs body' do
|
717
|
-
inspect_source(cop,
|
718
|
-
['def self.test',
|
719
|
-
'end'])
|
720
|
-
expect(cop.offenses).to be_empty
|
721
|
-
end
|
722
|
-
|
723
|
-
if RUBY_VERSION >= '2.1'
|
724
|
-
context 'when modifier and def are on the same line' do
|
725
|
-
it 'accepts a correctly aligned body' do
|
726
|
-
inspect_source(cop,
|
727
|
-
['private def test',
|
728
|
-
' something',
|
729
|
-
'end'])
|
730
|
-
expect(cop.offenses).to be_empty
|
731
|
-
end
|
732
|
-
|
733
|
-
it 'registers an offense for bad indentation of a def body' do
|
734
|
-
inspect_source(cop,
|
735
|
-
['private def test',
|
736
|
-
' something',
|
737
|
-
' end'])
|
738
|
-
expect(cop.messages)
|
739
|
-
.to eq(['Use 2 (not 10) spaces for indentation.'])
|
740
|
-
end
|
741
|
-
end
|
742
|
-
end
|
743
|
-
end
|
744
|
-
|
745
|
-
context 'with class' do
|
746
|
-
it 'registers an offense for bad indentation of a class body' do
|
747
|
-
inspect_source(cop,
|
748
|
-
['class Test',
|
749
|
-
' def func',
|
750
|
-
' end',
|
751
|
-
'end'])
|
752
|
-
expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
|
753
|
-
end
|
754
|
-
|
755
|
-
it 'accepts an empty class body' do
|
756
|
-
inspect_source(cop,
|
757
|
-
['class Test',
|
758
|
-
'end'])
|
759
|
-
expect(cop.offenses).to be_empty
|
760
|
-
end
|
761
|
-
|
762
|
-
it 'accepts indented public, protected, and private' do
|
763
|
-
inspect_source(cop,
|
764
|
-
['class Test',
|
765
|
-
' public',
|
766
|
-
'',
|
767
|
-
' def e',
|
768
|
-
' end',
|
769
|
-
'',
|
770
|
-
' protected',
|
771
|
-
'',
|
772
|
-
' def f',
|
773
|
-
' end',
|
774
|
-
'',
|
775
|
-
' private',
|
776
|
-
'',
|
777
|
-
' def g',
|
778
|
-
' end',
|
779
|
-
'end'])
|
780
|
-
expect(cop.offenses).to be_empty
|
781
|
-
end
|
782
|
-
end
|
783
|
-
|
784
|
-
context 'with module' do
|
785
|
-
it 'registers an offense for bad indentation of a module body' do
|
786
|
-
inspect_source(cop,
|
787
|
-
['module Test',
|
788
|
-
' def func',
|
789
|
-
' end',
|
790
|
-
'end'])
|
791
|
-
expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
|
792
|
-
end
|
793
|
-
|
794
|
-
it 'accepts an empty module body' do
|
795
|
-
inspect_source(cop,
|
796
|
-
['module Test',
|
797
|
-
'end'])
|
798
|
-
expect(cop.offenses).to be_empty
|
799
|
-
end
|
800
|
-
end
|
801
|
-
|
802
|
-
context 'with begin/rescue/else/ensure/end' do
|
803
|
-
it 'registers an offense for bad indentation of bodies' do
|
804
|
-
inspect_source(cop,
|
805
|
-
['def my_func',
|
806
|
-
" puts 'do something outside block'",
|
807
|
-
' begin',
|
808
|
-
" puts 'do something error prone'",
|
809
|
-
' rescue SomeException, SomeOther => e',
|
810
|
-
" puts 'wrongly intended error handling'",
|
811
|
-
' rescue',
|
812
|
-
" puts 'wrongly intended error handling'",
|
813
|
-
' else',
|
814
|
-
" puts 'wrongly intended normal case handling'",
|
815
|
-
' ensure',
|
816
|
-
" puts 'wrongly intended common handling'",
|
817
|
-
' end',
|
818
|
-
'end'])
|
819
|
-
expect(cop.messages).to eq(['Use 2 (not 0) spaces for indentation.',
|
820
|
-
'Use 2 (not 1) spaces for indentation.',
|
821
|
-
'Use 2 (not 1) spaces for indentation.',
|
822
|
-
'Use 2 (not 3) spaces for indentation.',
|
823
|
-
'Use 2 (not 4) spaces for indentation.'])
|
824
|
-
end
|
825
|
-
end
|
826
|
-
|
827
|
-
context 'with def/rescue/end' do
|
828
|
-
it 'registers an offense for bad indentation of bodies' do
|
829
|
-
inspect_source(cop,
|
830
|
-
['def my_func',
|
831
|
-
" puts 'do something error prone'",
|
832
|
-
'rescue SomeException',
|
833
|
-
" puts 'wrongly intended error handling'",
|
834
|
-
'rescue',
|
835
|
-
" puts 'wrongly intended error handling'",
|
836
|
-
'end'])
|
837
|
-
expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.',
|
838
|
-
'Use 2 (not 1) spaces for indentation.'])
|
839
|
-
end
|
840
|
-
end
|
841
|
-
|
842
|
-
context 'with block' do
|
843
|
-
it 'registers an offense for bad indentation of a do/end body' do
|
844
|
-
inspect_source(cop,
|
845
|
-
['a = func do',
|
846
|
-
' b',
|
847
|
-
'end'])
|
848
|
-
expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
|
849
|
-
end
|
850
|
-
|
851
|
-
it 'registers an offense for bad indentation of a {} body' do
|
852
|
-
inspect_source(cop,
|
853
|
-
['func {',
|
854
|
-
' b',
|
855
|
-
'}'])
|
856
|
-
expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
|
857
|
-
end
|
858
|
-
|
859
|
-
it 'accepts a correctly indented block body' do
|
860
|
-
inspect_source(cop,
|
861
|
-
['a = func do',
|
862
|
-
' b',
|
863
|
-
'end'])
|
864
|
-
expect(cop.offenses).to be_empty
|
865
|
-
end
|
866
|
-
|
867
|
-
it 'accepts an empty block body' do
|
868
|
-
inspect_source(cop,
|
869
|
-
['a = func do',
|
870
|
-
'end'])
|
871
|
-
expect(cop.offenses).to be_empty
|
872
|
-
end
|
873
|
-
|
874
|
-
# The cop uses the block end/} as the base for indentation, so if it's not
|
875
|
-
# on its own line, all bets are off.
|
876
|
-
it 'accepts badly indented code if block end is not on separate line' do
|
877
|
-
inspect_source(cop,
|
878
|
-
['foo {',
|
879
|
-
'def baz',
|
880
|
-
'end }'])
|
881
|
-
expect(cop.offenses).to be_empty
|
882
|
-
end
|
883
|
-
end
|
884
|
-
end
|
885
|
-
end
|