rubocop 0.52.1 → 0.53.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -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 for do
|
7
7
|
# end blocks.
|
8
8
|
#
|
@@ -63,8 +63,9 @@ module RuboCop
|
|
63
63
|
# end
|
64
64
|
class BlockAlignment < Cop
|
65
65
|
include ConfigurableEnforcedStyle
|
66
|
+
include RangeHelp
|
66
67
|
|
67
|
-
MSG = '
|
68
|
+
MSG = '%<current>s is not aligned with %<prefer>s%<alt_prefer>s.'.freeze
|
68
69
|
|
69
70
|
def_node_matcher :block_end_align_target?, <<-PATTERN
|
70
71
|
{assignment?
|
@@ -169,9 +170,11 @@ module RuboCop
|
|
169
170
|
error_source_line_column)
|
170
171
|
format(
|
171
172
|
MSG,
|
172
|
-
format_source_line_column(
|
173
|
-
|
174
|
-
|
173
|
+
current: format_source_line_column(
|
174
|
+
loc_to_source_line_column(end_loc)
|
175
|
+
),
|
176
|
+
prefer: format_source_line_column(error_source_line_column),
|
177
|
+
alt_prefer: alt_start_msg(start_loc, do_source_line_column)
|
175
178
|
)
|
176
179
|
end
|
177
180
|
|
@@ -25,6 +25,8 @@ module RuboCop
|
|
25
25
|
# foo(i)
|
26
26
|
# }
|
27
27
|
class BlockEndNewline < Cop
|
28
|
+
include Alignment
|
29
|
+
|
28
30
|
MSG = 'Expression at %<line>d, %<column>d should be on its own line.'
|
29
31
|
.freeze
|
30
32
|
|
@@ -41,9 +43,8 @@ module RuboCop
|
|
41
43
|
|
42
44
|
def autocorrect(node)
|
43
45
|
lambda do |corrector|
|
44
|
-
|
45
|
-
|
46
|
-
corrector.replace(delimiter_range(node), new_block_end)
|
46
|
+
corrector.replace(delimiter_range(node),
|
47
|
+
"\n#{node.loc.end.source}#{offset(node)}")
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
@@ -53,21 +54,10 @@ module RuboCop
|
|
53
54
|
format(MSG, line: node.loc.end.line, column: node.loc.end.column + 1)
|
54
55
|
end
|
55
56
|
|
56
|
-
def indentation_of_block_start_line(node)
|
57
|
-
match = /\S.*/.match(node.loc.begin.source_line)
|
58
|
-
match.begin(0)
|
59
|
-
end
|
60
|
-
|
61
57
|
def delimiter_range(node)
|
62
|
-
Parser::Source::Range.new(
|
63
|
-
|
64
|
-
|
65
|
-
node.source.length
|
66
|
-
)
|
67
|
-
end
|
68
|
-
|
69
|
-
def index_of_delimiter_with_whitespaces(node)
|
70
|
-
node.source =~ /\s*#{node.closing_delimiter}/
|
58
|
+
Parser::Source::Range.new(node.loc.expression.source_buffer,
|
59
|
+
node.children.last.loc.expression.end_pos,
|
60
|
+
node.loc.expression.end_pos)
|
71
61
|
end
|
72
62
|
end
|
73
63
|
end
|
@@ -112,7 +112,8 @@ module RuboCop
|
|
112
112
|
}.freeze
|
113
113
|
|
114
114
|
VISIBILITY_SCOPES = %i[private protected public].freeze
|
115
|
-
MSG = '
|
115
|
+
MSG = '`%<category>s` is supposed to appear before ' \
|
116
|
+
'`%<previous>s`.'.freeze
|
116
117
|
|
117
118
|
def_node_matcher :visibility_block?, <<-PATTERN
|
118
119
|
(send nil? { :private :protected :public })
|
@@ -125,7 +126,8 @@ module RuboCop
|
|
125
126
|
walk_over_nested_class_definition(class_node) do |node, category|
|
126
127
|
index = expected_order.index(category)
|
127
128
|
if index < previous
|
128
|
-
message = format(MSG, category,
|
129
|
+
message = format(MSG, category: category,
|
130
|
+
previous: expected_order[previous])
|
129
131
|
add_offense(node, message: message)
|
130
132
|
end
|
131
133
|
previous = index
|
@@ -267,7 +269,8 @@ module RuboCop
|
|
267
269
|
annotation_line = node.first_line - 1
|
268
270
|
first_comment = nil
|
269
271
|
|
270
|
-
comments_before_line(annotation_line)
|
272
|
+
processed_source.comments_before_line(annotation_line)
|
273
|
+
.reverse_each do |comment|
|
271
274
|
if comment.location.line == annotation_line
|
272
275
|
first_comment = comment
|
273
276
|
annotation_line -= 1
|
@@ -281,10 +284,6 @@ module RuboCop
|
|
281
284
|
buffer.line_range(node.first_line).begin_pos - 1
|
282
285
|
end
|
283
286
|
|
284
|
-
def comments_before_line(line)
|
285
|
-
processed_source.comments.select { |c| c.location.line <= line }
|
286
|
-
end
|
287
|
-
|
288
287
|
def buffer
|
289
288
|
processed_source.buffer
|
290
289
|
end
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
'instead of %<correct_comment_indentation>d).'.freeze
|
40
40
|
|
41
41
|
def investigate(processed_source)
|
42
|
-
processed_source.
|
42
|
+
processed_source.each_comment { |comment| check(comment) }
|
43
43
|
end
|
44
44
|
|
45
45
|
def autocorrect(node)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
module
|
5
|
+
module Layout
|
6
6
|
# This cop checks for conditions that are not on the same line as
|
7
7
|
# if/while/until.
|
8
8
|
#
|
@@ -23,7 +23,7 @@ module RuboCop
|
|
23
23
|
# do_something
|
24
24
|
# end
|
25
25
|
class ConditionPosition < Cop
|
26
|
-
MSG = 'Place the condition on the same line as
|
26
|
+
MSG = 'Place the condition on the same line as `%<keyword>s`.'.freeze
|
27
27
|
|
28
28
|
def on_if(node)
|
29
29
|
return if node.ternary?
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def message(node)
|
51
|
-
format(MSG, node.parent.keyword)
|
51
|
+
format(MSG, keyword: node.parent.keyword)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -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 of method definitions are
|
7
7
|
# aligned properly.
|
8
8
|
#
|
@@ -35,6 +35,7 @@ module RuboCop
|
|
35
35
|
# end
|
36
36
|
class DefEndAlignment < Cop
|
37
37
|
include EndKeywordAlignment
|
38
|
+
include RangeHelp
|
38
39
|
|
39
40
|
MSG = '`end` at %d, %d is not aligned with `%s` at %d, %d.'.freeze
|
40
41
|
|
@@ -102,7 +102,7 @@ module RuboCop
|
|
102
102
|
rhs = first_part_of_call_chain(rhs)
|
103
103
|
return unless rhs
|
104
104
|
|
105
|
-
end_config = config.for_cop('
|
105
|
+
end_config = config.for_cop('Layout/EndAlignment')
|
106
106
|
style = end_config['EnforcedStyleAlignWith'] || 'keyword'
|
107
107
|
base = variable_alignment?(node.loc, rhs, style.to_sym) ? node : rhs
|
108
108
|
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Layout
|
6
|
+
# This cop checks empty comment.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
#
|
11
|
+
# #
|
12
|
+
# class Foo
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
#
|
17
|
+
# #
|
18
|
+
# # Description of `Foo` class.
|
19
|
+
# #
|
20
|
+
# class Foo
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# @example AllowBorderComment: true (default)
|
24
|
+
# # good
|
25
|
+
#
|
26
|
+
# def foo
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# #################
|
30
|
+
#
|
31
|
+
# def bar
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# @example AllowBorderComment: false
|
35
|
+
# # bad
|
36
|
+
#
|
37
|
+
# def foo
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# #################
|
41
|
+
#
|
42
|
+
# def bar
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# @example AllowMarginComment: true (default)
|
46
|
+
# # good
|
47
|
+
#
|
48
|
+
# #
|
49
|
+
# # Description of `Foo` class.
|
50
|
+
# #
|
51
|
+
# class Foo
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# @example AllowMarginComment: false
|
55
|
+
# # bad
|
56
|
+
#
|
57
|
+
# #
|
58
|
+
# # Description of `Foo` class.
|
59
|
+
# #
|
60
|
+
# class Foo
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
class EmptyComment < Cop
|
64
|
+
include RangeHelp
|
65
|
+
|
66
|
+
MSG = 'Source code comment is empty.'.freeze
|
67
|
+
|
68
|
+
def investigate(processed_source)
|
69
|
+
if allow_margin_comment?
|
70
|
+
comments = concat_consecutive_comments(processed_source.comments)
|
71
|
+
|
72
|
+
comments.each do |comment|
|
73
|
+
next unless empty_comment_only?(comment[0])
|
74
|
+
|
75
|
+
comment[1].each do |offense_comment|
|
76
|
+
add_offense(offense_comment)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
else
|
80
|
+
processed_source.comments.each do |comment|
|
81
|
+
next unless empty_comment_only?(comment_text(comment))
|
82
|
+
|
83
|
+
add_offense(comment)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def autocorrect(node)
|
89
|
+
lambda do |corrector|
|
90
|
+
range = range_by_whole_lines(node.loc.expression,
|
91
|
+
include_final_newline: true)
|
92
|
+
|
93
|
+
corrector.remove(range)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def concat_consecutive_comments(comments)
|
100
|
+
prev_line = nil
|
101
|
+
|
102
|
+
comments.each_with_object([]) do |comment, concatenated_comments|
|
103
|
+
if prev_line && comment.loc.line == prev_line.next
|
104
|
+
last_concatenated_comment = concatenated_comments.last
|
105
|
+
|
106
|
+
last_concatenated_comment[0] << comment_text(comment)
|
107
|
+
last_concatenated_comment[1] << comment
|
108
|
+
else
|
109
|
+
concatenated_comments << [comment_text(comment).dup, [comment]]
|
110
|
+
end
|
111
|
+
|
112
|
+
prev_line = comment.loc.line
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def empty_comment_only?(comment_text)
|
117
|
+
empty_comment_pattern = if allow_border_comment?
|
118
|
+
/\A(#\n)+\z/
|
119
|
+
else
|
120
|
+
/\A(#+\n)+\z/
|
121
|
+
end
|
122
|
+
|
123
|
+
!(comment_text =~ empty_comment_pattern).nil?
|
124
|
+
end
|
125
|
+
|
126
|
+
def comment_text(comment)
|
127
|
+
"#{comment.text.strip}\n"
|
128
|
+
end
|
129
|
+
|
130
|
+
def allow_border_comment?
|
131
|
+
cop_config['AllowBorderComment']
|
132
|
+
end
|
133
|
+
|
134
|
+
def allow_margin_comment?
|
135
|
+
cop_config['AllowMarginComment']
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -21,6 +21,8 @@ module RuboCop
|
|
21
21
|
# some_method
|
22
22
|
#
|
23
23
|
class EmptyLines < Cop
|
24
|
+
include RangeHelp
|
25
|
+
|
24
26
|
MSG = 'Extra blank line detected.'.freeze
|
25
27
|
LINE_OFFSET = 2
|
26
28
|
|
@@ -28,7 +30,7 @@ module RuboCop
|
|
28
30
|
return if processed_source.tokens.empty?
|
29
31
|
|
30
32
|
lines = Set.new
|
31
|
-
processed_source.
|
33
|
+
processed_source.each_token do |token|
|
32
34
|
lines << token.line
|
33
35
|
end
|
34
36
|
|
@@ -23,9 +23,11 @@ module RuboCop
|
|
23
23
|
# def baz; end
|
24
24
|
# end
|
25
25
|
class EmptyLinesAroundAccessModifier < Cop
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
include RangeHelp
|
27
|
+
|
28
|
+
MSG_AFTER = 'Keep a blank line after `%<modifier>s`.'.freeze
|
29
|
+
MSG_BEFORE_AND_AFTER = 'Keep a blank line before and after ' \
|
30
|
+
'`%<modifier>s`.'.freeze
|
29
31
|
|
30
32
|
def on_send(node)
|
31
33
|
return unless node.access_modifier?
|
@@ -96,9 +98,9 @@ module RuboCop
|
|
96
98
|
|
97
99
|
if block_start?(previous_line) ||
|
98
100
|
class_def?(previous_line)
|
99
|
-
format(MSG_AFTER, node.loc.selector.source)
|
101
|
+
format(MSG_AFTER, modifier: node.loc.selector.source)
|
100
102
|
else
|
101
|
-
format(MSG_BEFORE_AND_AFTER,
|
103
|
+
format(MSG_BEFORE_AND_AFTER, modifier: node.loc.selector.source)
|
102
104
|
end
|
103
105
|
end
|
104
106
|
end
|
@@ -39,6 +39,8 @@ module RuboCop
|
|
39
39
|
# )
|
40
40
|
#
|
41
41
|
class EmptyLinesAroundArguments < Cop
|
42
|
+
include RangeHelp
|
43
|
+
|
42
44
|
MSG = 'Empty line detected around arguments.'.freeze
|
43
45
|
|
44
46
|
def on_send(node)
|
@@ -55,7 +57,7 @@ module RuboCop
|
|
55
57
|
private
|
56
58
|
|
57
59
|
def empty_lines(node)
|
58
|
-
lines = processed_lines(node)
|
60
|
+
lines = processed_lines(node)
|
59
61
|
lines.select! { |code, _| code.empty? }
|
60
62
|
lines.map { |_, line| line }
|
61
63
|
end
|
@@ -67,19 +69,27 @@ module RuboCop
|
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
70
|
-
def
|
71
|
-
node.
|
72
|
+
def processed_lines(node)
|
73
|
+
line_numbers(node).each_with_object([]) do |num, array|
|
74
|
+
array << [processed_source.lines[num - 1], num]
|
75
|
+
end
|
72
76
|
end
|
73
77
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
78
|
+
def line_numbers(node)
|
79
|
+
inner_lines = []
|
80
|
+
line_nums = node.arguments.each_with_object([]) do |arg_node, lines|
|
81
|
+
lines << outer_lines(arg_node)
|
82
|
+
inner_lines << inner_lines(arg_node) if arg_node.multiline?
|
83
|
+
end
|
84
|
+
line_nums.flatten.uniq - inner_lines.flatten - outer_lines(node)
|
77
85
|
end
|
78
86
|
|
79
|
-
def
|
80
|
-
|
81
|
-
|
82
|
-
|
87
|
+
def inner_lines(node)
|
88
|
+
[node.first_line + 1, node.last_line - 1]
|
89
|
+
end
|
90
|
+
|
91
|
+
def outer_lines(node)
|
92
|
+
[node.first_line - 1, node.last_line + 1]
|
83
93
|
end
|
84
94
|
end
|
85
95
|
end
|