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
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cops checks the indentation of hanging closing parentheses in
|
7
|
+
# method calls, method definitions, and grouped expressions. A hanging
|
8
|
+
# closing parenthesis means `)` preceded by a line break.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# # good: when x is on its own line, indent this way
|
13
|
+
# func(
|
14
|
+
# x,
|
15
|
+
# y
|
16
|
+
# )
|
17
|
+
#
|
18
|
+
# # good: when x follows opening parenthesis, align parentheses
|
19
|
+
# a = b * (x +
|
20
|
+
# y
|
21
|
+
# )
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# def func(
|
25
|
+
# x,
|
26
|
+
# y
|
27
|
+
# )
|
28
|
+
class ClosingParenthesisIndentation < Cop
|
29
|
+
include AutocorrectAlignment
|
30
|
+
include OnMethodDef
|
31
|
+
|
32
|
+
MSG_INDENT =
|
33
|
+
'Indent `)` the same as the start of the line where `(` is.'
|
34
|
+
MSG_ALIGN = 'Align `)` with `(`.'
|
35
|
+
|
36
|
+
def on_send(node)
|
37
|
+
_receiver, _method_name, *args = *node
|
38
|
+
check(node, args)
|
39
|
+
end
|
40
|
+
|
41
|
+
def on_begin(node)
|
42
|
+
check(node, node.children)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def on_method_def(_node, _method_name, args, _body)
|
48
|
+
check(args, args.children)
|
49
|
+
end
|
50
|
+
|
51
|
+
def check(node, elements)
|
52
|
+
right_paren = node.loc.end
|
53
|
+
return unless right_paren
|
54
|
+
return unless begins_its_line?(right_paren)
|
55
|
+
|
56
|
+
left_paren = node.loc.begin
|
57
|
+
|
58
|
+
correct_column = if line_break_after_left_paren?(left_paren, elements)
|
59
|
+
left_paren.source_line =~ /\S/
|
60
|
+
else
|
61
|
+
left_paren.column
|
62
|
+
end
|
63
|
+
@column_delta = correct_column - right_paren.column
|
64
|
+
return if @column_delta == 0
|
65
|
+
|
66
|
+
msg = correct_column == left_paren.column ? MSG_ALIGN : MSG_INDENT
|
67
|
+
add_offense(node.loc.end, node.loc.end, msg)
|
68
|
+
end
|
69
|
+
|
70
|
+
def line_break_after_left_paren?(left_paren, elements)
|
71
|
+
elements.first && elements.first.loc.line > left_paren.line
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop enforces using `` or %x around command literals.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # Good if EnforcedStyle is backticks or mixed, bad if percent_x.
|
10
|
+
# folders = `find . -type d`.split
|
11
|
+
#
|
12
|
+
# # Good if EnforcedStyle is percent_x, bad if backticks or mixed.
|
13
|
+
# folders = %x(find . -type d).split
|
14
|
+
#
|
15
|
+
# # Good if EnforcedStyle is backticks, bad if percent_x or mixed.
|
16
|
+
# `
|
17
|
+
# ln -s foo.example.yml foo.example
|
18
|
+
# ln -s bar.example.yml bar.example
|
19
|
+
# `
|
20
|
+
#
|
21
|
+
# # Good if EnforcedStyle is percent_x or mixed, bad if backticks.
|
22
|
+
# %x(
|
23
|
+
# ln -s foo.example.yml foo.example
|
24
|
+
# ln -s bar.example.yml bar.example
|
25
|
+
# )
|
26
|
+
#
|
27
|
+
# # Bad unless AllowInnerBackticks is true.
|
28
|
+
# `echo \`ls\``
|
29
|
+
class CommandLiteral < Cop
|
30
|
+
include ConfigurableEnforcedStyle
|
31
|
+
|
32
|
+
MSG_USE_BACKTICKS = 'Use backticks around command string.'
|
33
|
+
MSG_USE_PERCENT_X = 'Use `%x` around command string.'
|
34
|
+
|
35
|
+
def on_xstr(node)
|
36
|
+
return if heredoc_literal?(node)
|
37
|
+
|
38
|
+
if backtick_literal?(node)
|
39
|
+
check_backtick_literal(node)
|
40
|
+
else
|
41
|
+
check_percent_x_literal(node)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def check_backtick_literal(node)
|
48
|
+
return if style == :backticks && !contains_disallowed_backtick?(node)
|
49
|
+
return if style == :mixed &&
|
50
|
+
single_line?(node) &&
|
51
|
+
!contains_disallowed_backtick?(node)
|
52
|
+
|
53
|
+
add_offense(node, :expression, MSG_USE_PERCENT_X)
|
54
|
+
end
|
55
|
+
|
56
|
+
def check_percent_x_literal(node)
|
57
|
+
return if style == :backticks && contains_disallowed_backtick?(node)
|
58
|
+
return if style == :percent_x
|
59
|
+
return if style == :mixed && multi_line?(node)
|
60
|
+
return if style == :mixed && contains_disallowed_backtick?(node)
|
61
|
+
|
62
|
+
add_offense(node, :expression, MSG_USE_BACKTICKS)
|
63
|
+
end
|
64
|
+
|
65
|
+
def contains_disallowed_backtick?(node)
|
66
|
+
!allow_inner_backticks? && contains_backtick?(node)
|
67
|
+
end
|
68
|
+
|
69
|
+
def allow_inner_backticks?
|
70
|
+
cop_config['AllowInnerBackticks']
|
71
|
+
end
|
72
|
+
|
73
|
+
def contains_backtick?(node)
|
74
|
+
node_body(node) =~ /`/
|
75
|
+
end
|
76
|
+
|
77
|
+
def node_body(node)
|
78
|
+
loc = node.loc
|
79
|
+
loc.expression.source[loc.begin.length...-loc.end.length]
|
80
|
+
end
|
81
|
+
|
82
|
+
def heredoc_literal?(node)
|
83
|
+
node.loc.respond_to?(:heredoc_body)
|
84
|
+
end
|
85
|
+
|
86
|
+
def backtick_literal?(node)
|
87
|
+
node.loc.begin.source == '`'
|
88
|
+
end
|
89
|
+
|
90
|
+
def single_line?(node)
|
91
|
+
!multi_line?(node)
|
92
|
+
end
|
93
|
+
|
94
|
+
def multi_line?(node)
|
95
|
+
block_length(node) > 1
|
96
|
+
end
|
97
|
+
|
98
|
+
def preferred_delimiters
|
99
|
+
config.for_cop('Style/PercentLiteralDelimiters') \
|
100
|
+
['PreferredDelimiters']['%x'].split(//)
|
101
|
+
end
|
102
|
+
|
103
|
+
def autocorrect(node)
|
104
|
+
fail CorrectionNotPossible if contains_backtick?(node)
|
105
|
+
|
106
|
+
if backtick_literal?(node)
|
107
|
+
replacement = ['%x', ''].zip(preferred_delimiters).map(&:join)
|
108
|
+
else
|
109
|
+
replacement = %w(` `)
|
110
|
+
end
|
111
|
+
|
112
|
+
@corrections << lambda do |corrector|
|
113
|
+
corrector.replace(node.loc.begin, replacement.first)
|
114
|
+
corrector.replace(node.loc.end, replacement.last)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# Check that a copyright notice was given in each source file.
|
7
|
+
#
|
8
|
+
# The default regexp for an acceptable copyright notice can be found in
|
9
|
+
# config/default.yml. The default can be changed as follows:
|
10
|
+
#
|
11
|
+
# Style/Copyright:
|
12
|
+
# Notice: '^Copyright (\(c\) )?2\d{3} Acme Inc'
|
13
|
+
#
|
14
|
+
# This regex string is treated as an unanchored regex. For each file
|
15
|
+
# that RuboCop scans, a comment that matches this regex must be found or
|
16
|
+
# an offense is reported.
|
17
|
+
#
|
18
|
+
class Copyright < Cop
|
19
|
+
def message
|
20
|
+
"Include a copyright notice matching /#{notice}/" \
|
21
|
+
'before any code.'
|
22
|
+
end
|
23
|
+
|
24
|
+
def notice
|
25
|
+
cop_config['Notice']
|
26
|
+
end
|
27
|
+
|
28
|
+
def autocorrect_notice
|
29
|
+
cop_config['AutocorrectNotice']
|
30
|
+
end
|
31
|
+
|
32
|
+
def investigate(processed_source)
|
33
|
+
return if notice.empty?
|
34
|
+
return if notice_found?(processed_source)
|
35
|
+
range = source_range(processed_source.buffer, 1, 0)
|
36
|
+
add_offense(insert_notice_before(processed_source), range, message)
|
37
|
+
end
|
38
|
+
|
39
|
+
def insert_notice_before(processed_source)
|
40
|
+
token_index = 0
|
41
|
+
token_index += 1 if shebang_token?(processed_source, token_index)
|
42
|
+
token_index += 1 if encoding_token?(processed_source, token_index)
|
43
|
+
processed_source.tokens[token_index]
|
44
|
+
end
|
45
|
+
|
46
|
+
def shebang_token?(processed_source, token_index)
|
47
|
+
return false if token_index >= processed_source.tokens.size
|
48
|
+
token = processed_source.tokens[token_index]
|
49
|
+
token.type == :tCOMMENT && token.text =~ /^#!.*$/
|
50
|
+
end
|
51
|
+
|
52
|
+
def encoding_token?(processed_source, token_index)
|
53
|
+
return false if token_index >= processed_source.tokens.size
|
54
|
+
token = processed_source.tokens[token_index]
|
55
|
+
token.type == :tCOMMENT &&
|
56
|
+
token.text =~ /^#.*coding\s?[:=]\s?(?:UTF|utf)-8/
|
57
|
+
end
|
58
|
+
|
59
|
+
def notice_found?(processed_source)
|
60
|
+
notice_found = false
|
61
|
+
notice_regexp = Regexp.new(notice)
|
62
|
+
processed_source.tokens.each do |token|
|
63
|
+
break unless token.type == :tCOMMENT
|
64
|
+
notice_found = !((token.text =~ notice_regexp).nil?)
|
65
|
+
break if notice_found
|
66
|
+
end
|
67
|
+
notice_found
|
68
|
+
end
|
69
|
+
|
70
|
+
def autocorrect(token)
|
71
|
+
fail 'An AutocorrectNotice must be defined in ' \
|
72
|
+
'your RuboCop config' if autocorrect_notice.empty?
|
73
|
+
fail "AutocorrectNotice '#{autocorrect_notice}' must match " \
|
74
|
+
"Notice /#{notice}/" unless autocorrect_notice =~ Regexp.new(notice)
|
75
|
+
@corrections << lambda do |corrector|
|
76
|
+
if token.nil?
|
77
|
+
range = Parser::Source::Range.new('', 0, 0)
|
78
|
+
else
|
79
|
+
range = token.pos
|
80
|
+
end
|
81
|
+
corrector.insert_before(range, "#{autocorrect_notice}\n")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -7,6 +7,10 @@ module RuboCop
|
|
7
7
|
# classes and modules. Classes with no body are exempt from the
|
8
8
|
# check and so are namespace modules - modules that have nothing in
|
9
9
|
# their bodies except classes or other other modules.
|
10
|
+
#
|
11
|
+
# The documentation requirement is annulled if the class or module has
|
12
|
+
# a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the
|
13
|
+
# same for all its children.
|
10
14
|
class Documentation < Cop
|
11
15
|
include AnnotationComment
|
12
16
|
|
@@ -38,6 +42,7 @@ module RuboCop
|
|
38
42
|
next if node.type == :class && !body
|
39
43
|
next if namespace?(body)
|
40
44
|
next if associated_comment?(node, ast_with_comments)
|
45
|
+
next if nodoc?(node, ast_with_comments)
|
41
46
|
add_offense(node, :keyword, format(MSG, node.type.to_s))
|
42
47
|
end
|
43
48
|
end
|
@@ -65,11 +70,38 @@ module RuboCop
|
|
65
70
|
preceding_comment = ast_with_comments[node].last
|
66
71
|
distance = node.loc.keyword.line - preceding_comment.loc.line
|
67
72
|
return false if distance > 1
|
73
|
+
return false unless comment_line_only?(preceding_comment)
|
68
74
|
|
69
75
|
# As long as there's at least one comment line that isn't an
|
70
76
|
# annotation, it's OK.
|
71
77
|
ast_with_comments[node].any? { |comment| !annotation?(comment) }
|
72
78
|
end
|
79
|
+
|
80
|
+
def comment_line_only?(comment)
|
81
|
+
source_buffer = comment.loc.expression.source_buffer
|
82
|
+
comment_line = source_buffer.source_line(comment.loc.line)
|
83
|
+
comment_line =~ /^\s*#/
|
84
|
+
end
|
85
|
+
|
86
|
+
# The :nodoc: comment is not actually associated with the class/module
|
87
|
+
# ifself but its first commentable child node. Unless the element is
|
88
|
+
# tagged with :nodoc:, the search proceeds to check its ancestors for
|
89
|
+
# :nodoc: all.
|
90
|
+
def nodoc?(node, ast_with_comments, require_all = false)
|
91
|
+
return false unless node
|
92
|
+
nodoc_node = node.children.last
|
93
|
+
return false unless nodoc_node
|
94
|
+
|
95
|
+
nodoc_node = nodoc_node.children.first while nodoc_node.type == :begin
|
96
|
+
comment = ast_with_comments[nodoc_node].first
|
97
|
+
|
98
|
+
if comment && comment.loc.line == node.loc.line
|
99
|
+
regex = /^#\s*:nodoc:#{"\s+all\s*$" if require_all}/
|
100
|
+
return true if comment.text =~ regex
|
101
|
+
end
|
102
|
+
|
103
|
+
nodoc?(node.ancestors.first, ast_with_comments, true)
|
104
|
+
end
|
73
105
|
end
|
74
106
|
end
|
75
107
|
end
|
@@ -4,11 +4,72 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
6
|
# Checks for empty else-clauses, possibly including comments and/or an
|
7
|
-
# explicit `nil
|
7
|
+
# explicit `nil` depending on the EnforcedStyle.
|
8
|
+
#
|
9
|
+
# SupportedStyles:
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# # good for all styles
|
13
|
+
# if condition
|
14
|
+
# statement
|
15
|
+
# else
|
16
|
+
# statement
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# # good for all styles
|
20
|
+
# if condition
|
21
|
+
# statement
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# empty - warn only on empty else
|
25
|
+
# @example
|
26
|
+
# # bad
|
27
|
+
# if condition
|
28
|
+
# statement
|
29
|
+
# else
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # good
|
33
|
+
# if condition
|
34
|
+
# statement
|
35
|
+
# else
|
36
|
+
# nil
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# nil - warn on else with nil in it
|
40
|
+
# @example
|
41
|
+
# # bad
|
42
|
+
# if condition
|
43
|
+
# statement
|
44
|
+
# else
|
45
|
+
# nil
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# # good
|
49
|
+
# if condition
|
50
|
+
# statement
|
51
|
+
# else
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# both - warn on empty else and else with nil in it
|
55
|
+
# @example
|
56
|
+
# # bad
|
57
|
+
# if condition
|
58
|
+
# statement
|
59
|
+
# else
|
60
|
+
# nil
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# # bad
|
64
|
+
# if condition
|
65
|
+
# statement
|
66
|
+
# else
|
67
|
+
# end
|
8
68
|
class EmptyElse < Cop
|
9
69
|
include OnNormalIfUnless
|
70
|
+
include ConfigurableEnforcedStyle
|
10
71
|
|
11
|
-
MSG = 'Redundant
|
72
|
+
MSG = 'Redundant `else`-clause.'
|
12
73
|
|
13
74
|
def on_normal_if_unless(node)
|
14
75
|
check(node, if_else_clause(node))
|
@@ -21,25 +82,33 @@ module RuboCop
|
|
21
82
|
private
|
22
83
|
|
23
84
|
def check(node, else_clause)
|
24
|
-
|
25
|
-
|
85
|
+
case style
|
86
|
+
when :empty
|
87
|
+
empty_check(node, else_clause)
|
88
|
+
when :nil
|
89
|
+
nil_check(node, else_clause)
|
90
|
+
when :both
|
91
|
+
both_check(node, else_clause)
|
92
|
+
end
|
93
|
+
end
|
26
94
|
|
27
|
-
|
95
|
+
def empty_check(node, else_clause)
|
96
|
+
add_offense(node, :else, MSG) if node.loc.else && else_clause.nil?
|
28
97
|
end
|
29
98
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
node.children[2]
|
34
|
-
elsif keyword.is?('elsif')
|
35
|
-
node.children[2]
|
36
|
-
elsif keyword.is?('unless')
|
37
|
-
node.children[1]
|
38
|
-
end
|
99
|
+
def nil_check(node, else_clause)
|
100
|
+
return unless else_clause && else_clause.type == :nil
|
101
|
+
add_offense(node, node.location, MSG)
|
39
102
|
end
|
40
103
|
|
41
|
-
def
|
42
|
-
node.
|
104
|
+
def both_check(node, else_clause)
|
105
|
+
return if node.loc.else.nil?
|
106
|
+
|
107
|
+
if else_clause.nil?
|
108
|
+
add_offense(node, :else, MSG)
|
109
|
+
elsif else_clause.type == :nil
|
110
|
+
add_offense(node, :else, MSG)
|
111
|
+
end
|
43
112
|
end
|
44
113
|
end
|
45
114
|
end
|