rubocop 0.52.1 → 0.53.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.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/config/default.yml +118 -46
- data/config/disabled.yml +8 -8
- data/config/enabled.yml +84 -28
- data/lib/rubocop.rb +28 -8
- data/lib/rubocop/ast/builder.rb +35 -37
- data/lib/rubocop/ast/node.rb +16 -1
- data/lib/rubocop/ast/node/and_node.rb +0 -8
- data/lib/rubocop/ast/node/block_node.rb +1 -9
- data/lib/rubocop/ast/node/case_node.rb +0 -8
- data/lib/rubocop/ast/node/ensure_node.rb +0 -8
- data/lib/rubocop/ast/node/for_node.rb +0 -8
- data/lib/rubocop/ast/node/or_node.rb +0 -8
- data/lib/rubocop/ast/node/pair_node.rb +0 -8
- data/lib/rubocop/ast/node/resbody_node.rb +0 -8
- data/lib/rubocop/ast/node/send_node.rb +0 -8
- data/lib/rubocop/ast/node/symbol_node.rb +0 -8
- data/lib/rubocop/ast/node/until_node.rb +0 -8
- data/lib/rubocop/ast/node/when_node.rb +0 -8
- data/lib/rubocop/ast/node/while_node.rb +0 -8
- data/lib/rubocop/cli.rb +17 -7
- data/lib/rubocop/comment_config.rb +24 -3
- data/lib/rubocop/config.rb +75 -6
- data/lib/rubocop/config_loader.rb +18 -28
- data/lib/rubocop/config_loader_resolver.rb +61 -9
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +3 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +4 -2
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +2 -2
- data/lib/rubocop/cop/cop.rb +4 -0
- data/lib/rubocop/cop/corrector.rb +11 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +3 -6
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +59 -0
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +13 -0
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +1 -1
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +3 -1
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +3 -5
- data/lib/rubocop/cop/generator.rb +29 -8
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +2 -0
- data/lib/rubocop/cop/layout/align_hash.rb +106 -37
- data/lib/rubocop/cop/{lint → layout}/block_alignment.rb +8 -5
- data/lib/rubocop/cop/layout/block_end_newline.rb +7 -17
- data/lib/rubocop/cop/layout/case_indentation.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +6 -7
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/{lint → layout}/condition_position.rb +3 -3
- data/lib/rubocop/cop/{lint → layout}/def_end_alignment.rb +2 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +140 -0
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +2 -0
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -0
- data/lib/rubocop/cop/layout/empty_lines.rb +3 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +7 -5
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +20 -10
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +20 -0
- data/lib/rubocop/cop/{lint → layout}/end_alignment.rb +37 -6
- data/lib/rubocop/cop/layout/end_of_line.rb +1 -0
- data/lib/rubocop/cop/layout/extra_spacing.rb +30 -37
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -0
- data/lib/rubocop/cop/layout/indent_heredoc.rb +38 -2
- data/lib/rubocop/cop/layout/indentation_consistency.rb +105 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +4 -3
- data/lib/rubocop/cop/layout/initial_indentation.rb +15 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +4 -2
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +62 -29
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +74 -33
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +16 -2
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -1
- data/lib/rubocop/cop/layout/space_after_method_name.rb +2 -0
- data/lib/rubocop/cop/layout/space_after_not.rb +2 -0
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -0
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +15 -2
- data/lib/rubocop/cop/layout/space_around_operators.rb +15 -13
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +13 -1
- data/lib/rubocop/cop/layout/space_before_comment.rb +6 -4
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -0
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +30 -45
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +3 -2
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +48 -18
- data/lib/rubocop/cop/layout/space_inside_parens.rb +8 -7
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +57 -11
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +1 -0
- data/lib/rubocop/cop/layout/tab.rb +42 -16
- data/lib/rubocop/cop/layout/trailing_blank_lines.rb +46 -13
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +12 -0
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +5 -3
- data/lib/rubocop/cop/lint/big_decimal_new.rb +44 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +2 -2
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -2
- data/lib/rubocop/cop/lint/debugger.rb +2 -2
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +5 -4
- data/lib/rubocop/cop/lint/duplicate_methods.rb +20 -9
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +4 -3
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +16 -10
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +5 -4
- data/lib/rubocop/cop/lint/inherit_exception.rb +2 -2
- data/lib/rubocop/cop/lint/interpolation_check.rb +4 -3
- data/lib/rubocop/cop/lint/literal_as_condition.rb +2 -2
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +2 -0
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +7 -5
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +59 -0
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +86 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +2 -0
- data/lib/rubocop/cop/lint/percent_string_array.rb +0 -2
- data/lib/rubocop/cop/lint/rand_one.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -0
- data/lib/rubocop/cop/lint/require_parentheses.rb +2 -0
- data/lib/rubocop/cop/lint/rescue_type.rb +6 -3
- data/lib/rubocop/cop/lint/return_in_void_context.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +17 -21
- data/lib/rubocop/cop/lint/script_permission.rb +30 -10
- data/lib/rubocop/cop/lint/shadowed_argument.rb +3 -3
- data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +2 -2
- data/lib/rubocop/cop/lint/unified_integer.rb +2 -2
- data/lib/rubocop/cop/lint/{unneeded_disable.rb → unneeded_cop_disable_directive.rb} +13 -7
- data/lib/rubocop/cop/lint/unneeded_cop_enable_directive.rb +97 -0
- data/lib/rubocop/cop/lint/unneeded_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +3 -3
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +11 -10
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +7 -5
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -2
- data/lib/rubocop/cop/lint/useless_setter_call.rb +2 -2
- data/lib/rubocop/cop/lint/void.rb +49 -10
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- data/lib/rubocop/cop/metrics/line_length.rb +5 -2
- data/lib/rubocop/cop/mixin/alignment.rb +4 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -1
- data/lib/rubocop/cop/mixin/def_node.rb +4 -0
- data/lib/rubocop/cop/mixin/documentation_comment.rb +11 -3
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +12 -2
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +20 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +4 -0
- data/lib/rubocop/cop/mixin/hash_alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/match_range.rb +2 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +6 -0
- data/lib/rubocop/cop/mixin/nil_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/percent_literal.rb +57 -9
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +6 -5
- data/lib/rubocop/cop/mixin/range_help.rb +102 -0
- data/lib/rubocop/cop/mixin/rescue_node.rb +1 -1
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +8 -7
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +11 -9
- data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -10
- data/lib/rubocop/cop/mixin/surrounding_space.rb +38 -8
- data/lib/rubocop/cop/mixin/trailing_body.rb +26 -0
- data/lib/rubocop/cop/mixin/trailing_comma.rb +15 -3
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +104 -0
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +3 -1
- data/lib/rubocop/cop/naming/file_name.rb +5 -10
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +76 -0
- data/lib/rubocop/cop/naming/uncommunicative_block_param_name.rb +48 -0
- data/lib/rubocop/cop/naming/uncommunicative_method_param_name.rb +57 -0
- data/lib/rubocop/cop/offense.rb +3 -2
- data/lib/rubocop/cop/performance/case_when_splat.rb +1 -0
- data/lib/rubocop/cop/performance/casecmp.rb +17 -8
- data/lib/rubocop/cop/performance/compare_with_block.rb +2 -0
- data/lib/rubocop/cop/performance/count.rb +1 -0
- data/lib/rubocop/cop/performance/fixed_size.rb +41 -0
- data/lib/rubocop/cop/performance/flat_map.rb +2 -0
- data/lib/rubocop/cop/performance/lstrip_rstrip.rb +2 -0
- data/lib/rubocop/cop/performance/redundant_merge.rb +1 -1
- data/lib/rubocop/cop/performance/redundant_sort_by.rb +2 -0
- data/lib/rubocop/cop/performance/regexp_match.rb +4 -0
- data/lib/rubocop/cop/performance/reverse_each.rb +2 -0
- data/lib/rubocop/cop/performance/string_replacement.rb +2 -0
- data/lib/rubocop/cop/rails/active_record_aliases.rb +46 -0
- data/lib/rubocop/cop/rails/blank.rb +3 -3
- data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +6 -0
- data/lib/rubocop/cop/rails/delegate.rb +6 -6
- data/lib/rubocop/cop/rails/file_path.rb +7 -1
- data/lib/rubocop/cop/rails/find_by.rb +2 -0
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +17 -5
- data/lib/rubocop/cop/rails/inverse_of.rb +21 -2
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +45 -9
- data/lib/rubocop/cop/rails/presence.rb +8 -2
- data/lib/rubocop/cop/rails/present.rb +5 -5
- data/lib/rubocop/cop/rails/read_write_attribute.rb +4 -3
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -0
- data/lib/rubocop/cop/rails/relative_date_constant.rb +4 -3
- data/lib/rubocop/cop/rails/request_referer.rb +3 -2
- data/lib/rubocop/cop/rails/reversible_migration.rb +9 -8
- data/lib/rubocop/cop/rails/safe_navigation.rb +3 -2
- data/lib/rubocop/cop/rails/save_bang.rb +11 -12
- data/lib/rubocop/cop/rails/skips_model_validations.rb +2 -2
- data/lib/rubocop/cop/rails/time_zone.rb +38 -16
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +26 -16
- data/lib/rubocop/cop/rails/validation.rb +30 -2
- data/lib/rubocop/cop/security/open.rb +48 -0
- data/lib/rubocop/cop/style/and_or.rb +1 -0
- data/lib/rubocop/cop/style/ascii_comments.rb +3 -1
- data/lib/rubocop/cop/style/attr.rb +2 -0
- data/lib/rubocop/cop/style/block_comments.rb +3 -1
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +2 -5
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -0
- data/lib/rubocop/cop/style/class_vars.rb +23 -0
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -2
- data/lib/rubocop/cop/style/comment_annotation.rb +6 -4
- data/lib/rubocop/cop/style/commented_keyword.rb +3 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
- data/lib/rubocop/cop/style/copyright.rb +3 -1
- data/lib/rubocop/cop/style/each_with_object.rb +15 -1
- data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -0
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -0
- data/lib/rubocop/cop/style/empty_else.rb +9 -5
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -0
- data/lib/rubocop/cop/style/empty_line_after_guard_clause.rb +80 -0
- data/lib/rubocop/cop/style/empty_literal.rb +1 -0
- data/lib/rubocop/cop/style/encoding.rb +2 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +194 -0
- data/lib/rubocop/cop/style/for.rb +33 -0
- data/lib/rubocop/cop/style/format_string.rb +1 -1
- data/lib/rubocop/cop/style/format_string_token.rb +4 -5
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +2 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -1
- data/lib/rubocop/cop/style/inline_comment.rb +1 -1
- data/lib/rubocop/cop/style/lambda.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +2 -0
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -0
- data/lib/rubocop/cop/style/missing_else.rb +72 -7
- data/lib/rubocop/cop/style/mixin_usage.rb +3 -5
- data/lib/rubocop/cop/style/module_function.rb +10 -0
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -0
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -0
- data/lib/rubocop/cop/style/nested_modifier.rb +2 -0
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -0
- data/lib/rubocop/cop/style/next.rb +1 -0
- data/lib/rubocop/cop/style/not.rb +2 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -2
- data/lib/rubocop/cop/style/redundant_exception.rb +8 -3
- data/lib/rubocop/cop/style/redundant_return.rb +37 -3
- data/lib/rubocop/cop/style/redundant_self.rb +1 -1
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +74 -32
- data/lib/rubocop/cop/style/semicolon.rb +3 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +14 -23
- data/lib/rubocop/cop/style/stderr_puts.rb +2 -0
- data/lib/rubocop/cop/style/string_hash_keys.rb +12 -0
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +29 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +2 -0
- data/lib/rubocop/cop/style/trailing_body_on_class.rb +43 -0
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +7 -54
- data/lib/rubocop/cop/style/trailing_body_on_module.rb +43 -0
- data/lib/rubocop/cop/style/{trailing_comma_in_literal.rb → trailing_comma_in_array_literal.rb} +2 -20
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +56 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +17 -20
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -0
- data/lib/rubocop/cop/style/unless_else.rb +2 -0
- data/lib/rubocop/cop/style/word_array.rb +0 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -0
- data/lib/rubocop/cop/team.rb +5 -5
- data/lib/rubocop/cop/util.rb +23 -188
- data/lib/rubocop/cop/variable_force.rb +1 -1
- data/lib/rubocop/file_finder.rb +45 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +23 -14
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/html_formatter.rb +12 -5
- data/lib/rubocop/formatter/json_formatter.rb +1 -1
- data/lib/rubocop/node_pattern.rb +8 -5
- data/lib/rubocop/options.rb +40 -33
- data/lib/rubocop/path_util.rb +5 -8
- data/lib/rubocop/processed_source.rb +53 -0
- data/lib/rubocop/remote_config.rb +1 -1
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +0 -4
- data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -4
- data/lib/rubocop/rspec/shared_contexts.rb +3 -1
- data/lib/rubocop/rspec/shared_examples.rb +23 -25
- data/lib/rubocop/rspec/support.rb +5 -0
- data/lib/rubocop/runner.rb +3 -2
- data/lib/rubocop/string_util.rb +10 -9
- data/lib/rubocop/target_finder.rb +4 -1
- data/lib/rubocop/token.rb +26 -16
- data/lib/rubocop/version.rb +6 -4
- metadata +31 -17
- data/lib/rubocop/cop/performance/hash_each_methods.rb +0 -129
@@ -36,6 +36,26 @@ module RuboCop
|
|
36
36
|
#
|
37
37
|
# end
|
38
38
|
#
|
39
|
+
# @example Enforcedstyle: beginning_only
|
40
|
+
# # good
|
41
|
+
#
|
42
|
+
# class Foo
|
43
|
+
#
|
44
|
+
# def bar
|
45
|
+
# # ...
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# @example Enforcedstyle: ending_only
|
50
|
+
# # good
|
51
|
+
#
|
52
|
+
# class Foo
|
53
|
+
# def bar
|
54
|
+
# # ...
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# end
|
58
|
+
#
|
39
59
|
# @example EnforcedStyle: no_empty_lines (default)
|
40
60
|
# # good
|
41
61
|
#
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
module
|
5
|
+
module Layout
|
6
6
|
# This cop checks whether the end keywords are aligned properly.
|
7
7
|
#
|
8
8
|
# Three modes are supported through the `EnforcedStyleAlignWith`
|
@@ -28,6 +28,10 @@ module RuboCop
|
|
28
28
|
# variable = if true
|
29
29
|
# end
|
30
30
|
#
|
31
|
+
# variable =
|
32
|
+
# if true
|
33
|
+
# end
|
34
|
+
#
|
31
35
|
# @example EnforcedStyleAlignWith: variable
|
32
36
|
# # bad
|
33
37
|
#
|
@@ -39,19 +43,34 @@ module RuboCop
|
|
39
43
|
# variable = if true
|
40
44
|
# end
|
41
45
|
#
|
46
|
+
# variable =
|
47
|
+
# if true
|
48
|
+
# end
|
49
|
+
#
|
42
50
|
# @example EnforcedStyleAlignWith: start_of_line
|
43
51
|
# # bad
|
44
52
|
#
|
45
53
|
# variable = if true
|
46
54
|
# end
|
47
55
|
#
|
56
|
+
# puts(if true
|
57
|
+
# end)
|
58
|
+
#
|
48
59
|
# # good
|
49
60
|
#
|
61
|
+
# variable = if true
|
62
|
+
# end
|
63
|
+
#
|
50
64
|
# puts(if true
|
51
65
|
# end)
|
66
|
+
#
|
67
|
+
# variable =
|
68
|
+
# if true
|
69
|
+
# end
|
52
70
|
class EndAlignment < Cop
|
53
71
|
include CheckAssignment
|
54
72
|
include EndKeywordAlignment
|
73
|
+
include RangeHelp
|
55
74
|
|
56
75
|
def on_class(node)
|
57
76
|
check_other_alignment(node)
|
@@ -103,7 +122,7 @@ module RuboCop
|
|
103
122
|
def check_asgn_alignment(outer_node, inner_node)
|
104
123
|
align_with = {
|
105
124
|
keyword: inner_node.loc.keyword,
|
106
|
-
start_of_line: start_line_range(
|
125
|
+
start_of_line: start_line_range(inner_node),
|
107
126
|
variable: asgn_variable_align_with(outer_node, inner_node)
|
108
127
|
}
|
109
128
|
|
@@ -134,15 +153,27 @@ module RuboCop
|
|
134
153
|
if style == :keyword
|
135
154
|
node
|
136
155
|
elsif style == :variable
|
137
|
-
|
138
|
-
# Fall back to 'keyword' style if this node is not on the RHS
|
139
|
-
# of an assignment
|
140
|
-
node.ancestors.find(&:assignment?) || node
|
156
|
+
alignment_node_for_variable_style(node)
|
141
157
|
else
|
142
158
|
start_line_range(node)
|
143
159
|
end
|
144
160
|
end
|
145
161
|
|
162
|
+
def alignment_node_for_variable_style(node)
|
163
|
+
return node.parent if node.case_type? && node.argument?
|
164
|
+
|
165
|
+
assignment = node.ancestors.find(&:assignment?)
|
166
|
+
if assignment && !line_break_before_keyword?(assignment.source_range,
|
167
|
+
node)
|
168
|
+
assignment
|
169
|
+
else
|
170
|
+
# Fall back to 'keyword' style if this node is not on the RHS of an
|
171
|
+
# assignment, or if it is but there's a line break between LHS and
|
172
|
+
# RHS.
|
173
|
+
node
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
146
177
|
def start_line_range(node)
|
147
178
|
expr = node.source_range
|
148
179
|
buffer = expr.source_buffer
|
@@ -6,6 +6,7 @@ module RuboCop
|
|
6
6
|
# This cop checks for Windows-style line endings in the source code.
|
7
7
|
class EndOfLine < Cop
|
8
8
|
include ConfigurableEnforcedStyle
|
9
|
+
include RangeHelp
|
9
10
|
|
10
11
|
MSG_DETECTED = 'Carriage return character detected.'.freeze
|
11
12
|
MSG_MISSING = 'Carriage return character missing.'.freeze
|
@@ -21,13 +21,14 @@ module RuboCop
|
|
21
21
|
# website = "https://github.com/bbatsov/rubocop"
|
22
22
|
class ExtraSpacing < Cop
|
23
23
|
include PrecedingFollowingAlignment
|
24
|
+
include RangeHelp
|
24
25
|
|
25
26
|
MSG_UNNECESSARY = 'Unnecessary spacing detected.'.freeze
|
26
27
|
MSG_UNALIGNED_ASGN = '`=` is not aligned with the %<location>s ' \
|
27
28
|
'assignment.'.freeze
|
28
29
|
|
29
30
|
def investigate(processed_source)
|
30
|
-
return if processed_source.
|
31
|
+
return if processed_source.blank?
|
31
32
|
|
32
33
|
if force_equal_sign_alignment?
|
33
34
|
@asgn_tokens = assignment_tokens
|
@@ -36,8 +37,8 @@ module RuboCop
|
|
36
37
|
@corrected = Set.new
|
37
38
|
end
|
38
39
|
|
39
|
-
processed_source.tokens.each_cons(2) do |
|
40
|
-
check_tokens(processed_source.ast,
|
40
|
+
processed_source.tokens.each_cons(2) do |token1, token2|
|
41
|
+
check_tokens(processed_source.ast, token1, token2)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
@@ -64,16 +65,16 @@ module RuboCop
|
|
64
65
|
Set.new(tokens.uniq(&:line))
|
65
66
|
end
|
66
67
|
|
67
|
-
def check_tokens(ast,
|
68
|
-
return if
|
68
|
+
def check_tokens(ast, token1, token2)
|
69
|
+
return if token2.type == :tNL
|
69
70
|
|
70
71
|
if force_equal_sign_alignment? &&
|
71
|
-
@asgn_tokens.include?(
|
72
|
-
(@asgn_lines.include?(
|
73
|
-
@asgn_lines.include?(
|
74
|
-
check_assignment(
|
72
|
+
@asgn_tokens.include?(token2) &&
|
73
|
+
(@asgn_lines.include?(token2.line - 1) ||
|
74
|
+
@asgn_lines.include?(token2.line + 1))
|
75
|
+
check_assignment(token2)
|
75
76
|
else
|
76
|
-
check_other(
|
77
|
+
check_other(token1, token2, ast)
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
@@ -81,10 +82,10 @@ module RuboCop
|
|
81
82
|
assignment_line = ''
|
82
83
|
message = ''
|
83
84
|
if should_aligned_with_preceding_line?(token)
|
84
|
-
assignment_line = preceding_line(token)
|
85
|
+
assignment_line = processed_source.preceding_line(token)
|
85
86
|
message = format(MSG_UNALIGNED_ASGN, location: 'preceding')
|
86
87
|
else
|
87
|
-
assignment_line = following_line(token)
|
88
|
+
assignment_line = processed_source.following_line(token)
|
88
89
|
message = format(MSG_UNALIGNED_ASGN, location: 'following')
|
89
90
|
end
|
90
91
|
return if aligned_assignment?(token.pos, assignment_line)
|
@@ -95,16 +96,8 @@ module RuboCop
|
|
95
96
|
@asgn_lines.include?(token.line - 1)
|
96
97
|
end
|
97
98
|
|
98
|
-
def
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
def following_line(token)
|
103
|
-
processed_source.lines[token.line]
|
104
|
-
end
|
105
|
-
|
106
|
-
def check_other(t1, t2, ast)
|
107
|
-
extra_space_range(t1, t2) do |range|
|
99
|
+
def check_other(token1, token2, ast)
|
100
|
+
extra_space_range(token1, token2) do |range|
|
108
101
|
# Unary + doesn't appear as a token and needs special handling.
|
109
102
|
next if ignored_range?(ast, range.begin_pos)
|
110
103
|
next if unary_plus_non_offense?(range)
|
@@ -113,14 +106,14 @@ module RuboCop
|
|
113
106
|
end
|
114
107
|
end
|
115
108
|
|
116
|
-
def extra_space_range(
|
117
|
-
return if
|
109
|
+
def extra_space_range(token1, token2)
|
110
|
+
return if token1.line != token2.line
|
118
111
|
|
119
|
-
start_pos =
|
120
|
-
end_pos =
|
112
|
+
start_pos = token1.end_pos
|
113
|
+
end_pos = token2.begin_pos - 1
|
121
114
|
return if end_pos <= start_pos
|
122
115
|
|
123
|
-
return if allow_for_alignment? && aligned_tok?(
|
116
|
+
return if allow_for_alignment? && aligned_tok?(token2)
|
124
117
|
|
125
118
|
yield range_between(start_pos, end_pos)
|
126
119
|
end
|
@@ -155,24 +148,24 @@ module RuboCop
|
|
155
148
|
end.compact
|
156
149
|
end
|
157
150
|
|
158
|
-
def aligned_comments?(
|
159
|
-
ix = processed_source.comments.index do |
|
160
|
-
|
151
|
+
def aligned_comments?(comment_token)
|
152
|
+
ix = processed_source.comments.index do |comment|
|
153
|
+
comment.loc.expression.begin_pos == comment_token.begin_pos
|
161
154
|
end
|
162
155
|
aligned_with_previous_comment?(ix) || aligned_with_next_comment?(ix)
|
163
156
|
end
|
164
157
|
|
165
|
-
def aligned_with_previous_comment?(
|
166
|
-
|
158
|
+
def aligned_with_previous_comment?(index)
|
159
|
+
index > 0 && comment_column(index - 1) == comment_column(index)
|
167
160
|
end
|
168
161
|
|
169
|
-
def aligned_with_next_comment?(
|
170
|
-
|
171
|
-
comment_column(
|
162
|
+
def aligned_with_next_comment?(index)
|
163
|
+
index < processed_source.comments.length - 1 &&
|
164
|
+
comment_column(index + 1) == comment_column(index)
|
172
165
|
end
|
173
166
|
|
174
|
-
def comment_column(
|
175
|
-
processed_source.comments[
|
167
|
+
def comment_column(index)
|
168
|
+
processed_source.comments[index].loc.column
|
176
169
|
end
|
177
170
|
|
178
171
|
def force_equal_sign_alignment?
|
@@ -12,26 +12,62 @@ module RuboCop
|
|
12
12
|
# this cop does not add any offenses for long here documents to
|
13
13
|
# avoid `Metrics/LineLength`'s offenses.
|
14
14
|
#
|
15
|
-
# @example
|
16
|
-
#
|
15
|
+
# @example EnforcedStyle: auto_detection (default)
|
17
16
|
# # bad
|
18
17
|
# <<-RUBY
|
19
18
|
# something
|
20
19
|
# RUBY
|
21
20
|
#
|
22
21
|
# # good
|
22
|
+
# # When using Ruby 2.3 or higher.
|
23
|
+
# <<~RUBY
|
24
|
+
# something
|
25
|
+
# RUBY
|
26
|
+
#
|
27
|
+
# # good
|
28
|
+
# # When using Ruby 2.2 or lower and enabled Rails department.
|
29
|
+
# # The following is possible to enable Rails department by
|
30
|
+
# # adding for example:
|
31
|
+
# #
|
32
|
+
# # Rails:
|
33
|
+
# # Enabled: true
|
34
|
+
# #
|
35
|
+
# <<-RUBY.strip_heredoc
|
36
|
+
# something
|
37
|
+
# RUBY
|
38
|
+
#
|
39
|
+
# @example EnforcedStyle: squiggly
|
40
|
+
# # good
|
23
41
|
# # When EnforcedStyle is squiggly, bad code is auto-corrected to the
|
24
42
|
# # following code.
|
25
43
|
# <<~RUBY
|
26
44
|
# something
|
27
45
|
# RUBY
|
28
46
|
#
|
47
|
+
# @example EnforcedStyle: active_support
|
29
48
|
# # good
|
30
49
|
# # When EnforcedStyle is active_support, bad code is auto-corrected to
|
31
50
|
# # the following code.
|
32
51
|
# <<-RUBY.strip_heredoc
|
33
52
|
# something
|
34
53
|
# RUBY
|
54
|
+
#
|
55
|
+
# @example EnforcedStyle: powerpack
|
56
|
+
# # good
|
57
|
+
# # When EnforcedStyle is powerpack, bad code is auto-corrected to
|
58
|
+
# # the following code.
|
59
|
+
# <<-RUBY.strip_indent
|
60
|
+
# something
|
61
|
+
# RUBY
|
62
|
+
#
|
63
|
+
# @example EnforcedStyle: unindent
|
64
|
+
# # good
|
65
|
+
# # When EnforcedStyle is unindent, bad code is auto-corrected to
|
66
|
+
# # the following code.
|
67
|
+
# <<-RUBY.unindent
|
68
|
+
# something
|
69
|
+
# RUBY
|
70
|
+
#
|
35
71
|
class IndentHeredoc < Cop
|
36
72
|
include Heredoc
|
37
73
|
include ConfigurableEnforcedStyle
|
@@ -5,14 +5,118 @@ module RuboCop
|
|
5
5
|
module Layout
|
6
6
|
# This cops checks for inconsistent indentation.
|
7
7
|
#
|
8
|
-
#
|
8
|
+
# The difference between `rails` and `normal` is that the `rails` style
|
9
|
+
# prescribes that in classes and modules the `protected` and `private`
|
10
|
+
# modifier keywords shall be indented the same as public methods and that
|
11
|
+
# protected and private members shall be indented one step more than the
|
12
|
+
# modifiers. Other than that, both styles mean that entities on the same
|
13
|
+
# logical depth shall have the same indentation.
|
9
14
|
#
|
15
|
+
# @example EnforcedStyle: normal (default)
|
16
|
+
# # bad
|
10
17
|
# class A
|
11
18
|
# def test
|
12
19
|
# puts 'hello'
|
13
20
|
# puts 'world'
|
14
21
|
# end
|
15
22
|
# end
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# class A
|
26
|
+
# def test
|
27
|
+
# puts 'hello'
|
28
|
+
# puts 'world'
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# protected
|
32
|
+
#
|
33
|
+
# def foo
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# private
|
37
|
+
#
|
38
|
+
# def bar
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# # good
|
43
|
+
# class A
|
44
|
+
# def test
|
45
|
+
# puts 'hello'
|
46
|
+
# puts 'world'
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# # good
|
51
|
+
# class A
|
52
|
+
# def test
|
53
|
+
# puts 'hello'
|
54
|
+
# puts 'world'
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# protected
|
58
|
+
#
|
59
|
+
# def foo
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# private
|
63
|
+
#
|
64
|
+
# def bar
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# @example EnforcedStyle: rails
|
69
|
+
# # bad
|
70
|
+
# class A
|
71
|
+
# def test
|
72
|
+
# puts 'hello'
|
73
|
+
# puts 'world'
|
74
|
+
# end
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# # bad
|
78
|
+
# class A
|
79
|
+
# def test
|
80
|
+
# puts 'hello'
|
81
|
+
# puts 'world'
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# protected
|
85
|
+
#
|
86
|
+
# def foo
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# private
|
90
|
+
#
|
91
|
+
# def bar
|
92
|
+
# end
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# # good
|
96
|
+
# class A
|
97
|
+
# def test
|
98
|
+
# puts 'hello'
|
99
|
+
# puts 'world'
|
100
|
+
# end
|
101
|
+
# end
|
102
|
+
#
|
103
|
+
# # good
|
104
|
+
# class A
|
105
|
+
# def test
|
106
|
+
# puts 'hello'
|
107
|
+
# puts 'world'
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# protected
|
111
|
+
#
|
112
|
+
# def foo
|
113
|
+
# end
|
114
|
+
#
|
115
|
+
# private
|
116
|
+
#
|
117
|
+
# def bar
|
118
|
+
# end
|
119
|
+
# end
|
16
120
|
class IndentationConsistency < Cop
|
17
121
|
include Alignment
|
18
122
|
include ConfigurableEnforcedStyle
|