rubocop 0.83.0 → 0.87.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/README.md +26 -18
- data/config/default.yml +128 -23
- data/lib/rubocop.rb +21 -59
- data/lib/rubocop/ast_aliases.rb +8 -0
- data/lib/rubocop/cli.rb +2 -4
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +42 -7
- data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
- data/lib/rubocop/cli/command/show_cops.rb +2 -6
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_loader.rb +24 -70
- data/lib/rubocop/config_loader_resolver.rb +21 -9
- data/lib/rubocop/config_obsoletion.rb +0 -1
- data/lib/rubocop/config_store.rb +12 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +14 -25
- data/lib/rubocop/cop/base.rb +399 -0
- data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
- data/lib/rubocop/cop/commissioner.rb +48 -71
- data/lib/rubocop/cop/cop.rb +91 -227
- data/lib/rubocop/cop/corrector.rb +38 -115
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -6
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator.rb +2 -2
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/ignored_node.rb +1 -3
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
- data/lib/rubocop/cop/layout/case_indentation.rb +21 -22
- data/lib/rubocop/cop/layout/class_structure.rb +19 -16
- data/lib/rubocop/cop/layout/comment_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +57 -4
- data/lib/rubocop/cop/layout/end_of_line.rb +3 -3
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -4
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -3
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +8 -9
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +3 -7
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
- data/lib/rubocop/cop/layout/line_length.rb +17 -17
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -2
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
- data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +19 -25
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -3
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -4
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -3
- data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
- data/lib/rubocop/cop/legacy/corrector.rb +29 -0
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +5 -2
- data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -0
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -3
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +38 -2
- data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +69 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +7 -7
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +20 -5
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +12 -4
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +31 -25
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +9 -1
- data/lib/rubocop/cop/lint/suppressed_exception.rb +15 -2
- data/lib/rubocop/cop/lint/syntax.rb +11 -28
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -4
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +22 -0
- data/lib/rubocop/cop/metrics/class_length.rb +25 -2
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
- data/lib/rubocop/cop/metrics/method_length.rb +23 -0
- data/lib/rubocop/cop/metrics/module_length.rb +25 -2
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
- data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
- data/lib/rubocop/cop/migration/department_name.rb +7 -7
- data/lib/rubocop/cop/mixin/alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
- data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
- data/lib/rubocop/cop/mixin/code_length.rb +4 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +3 -5
- data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +3 -1
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
- data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +1 -1
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +43 -0
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +10 -5
- data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +7 -5
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +3 -3
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
- data/lib/rubocop/cop/naming/file_name.rb +28 -17
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +4 -6
- data/lib/rubocop/cop/naming/variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/variable_number.rb +1 -1
- data/lib/rubocop/cop/offense.rb +16 -2
- data/lib/rubocop/cop/registry.rb +63 -10
- data/lib/rubocop/cop/severity.rb +1 -3
- data/lib/rubocop/cop/style/accessor_grouping.rb +136 -0
- data/lib/rubocop/cop/style/and_or.rb +2 -2
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +2 -2
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +121 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +4 -12
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +21 -0
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -4
- data/lib/rubocop/cop/style/copyright.rb +5 -5
- data/lib/rubocop/cop/style/date_time.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +2 -2
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +2 -2
- data/lib/rubocop/cop/style/double_negation.rb +41 -4
- data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
- data/lib/rubocop/cop/style/empty_literal.rb +6 -8
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
- data/lib/rubocop/cop/style/exponential_notation.rb +5 -5
- data/lib/rubocop/cop/style/format_string_token.rb +2 -3
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -6
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +16 -7
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
- data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -0
- data/lib/rubocop/cop/style/inline_comment.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/multiline_block_chain.rb +10 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
- data/lib/rubocop/cop/style/mutable_constant.rb +4 -4
- data/lib/rubocop/cop/style/negated_if.rb +3 -3
- data/lib/rubocop/cop/style/negated_unless.rb +3 -3
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -5
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/non_nil_check.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -6
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
- data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
- data/lib/rubocop/cop/style/redundant_conditional.rb +4 -3
- data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +122 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +10 -8
- data/lib/rubocop/cop/style/redundant_percent_q.rb +3 -3
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +90 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +121 -0
- data/lib/rubocop/cop/style/redundant_self.rb +6 -9
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -6
- data/lib/rubocop/cop/style/sample.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/signal_exception.rb +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +2 -6
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +23 -2
- data/lib/rubocop/cop/style/symbol_array.rb +5 -5
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +3 -3
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +3 -3
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +13 -13
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +3 -3
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -3
- data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +2 -2
- data/lib/rubocop/cop/team.rb +141 -81
- data/lib/rubocop/cop/util.rb +3 -3
- data/lib/rubocop/cop/utils/format_string.rb +19 -2
- data/lib/rubocop/cop/variable_force.rb +3 -9
- data/lib/rubocop/cop/variable_force/branch.rb +1 -3
- data/lib/rubocop/cop/variable_force/variable.rb +2 -6
- data/lib/rubocop/ext/processed_source.rb +18 -0
- data/lib/rubocop/formatter/base_formatter.rb +0 -4
- data/lib/rubocop/formatter/disabled_config_formatter.rb +5 -13
- data/lib/rubocop/formatter/formatter_set.rb +2 -4
- data/lib/rubocop/formatter/junit_formatter.rb +14 -4
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/name_similarity.rb +7 -3
- data/lib/rubocop/options.rb +30 -15
- data/lib/rubocop/path_util.rb +2 -2
- data/lib/rubocop/platform.rb +1 -1
- data/lib/rubocop/rake_task.rb +6 -9
- data/lib/rubocop/remote_config.rb +1 -3
- data/lib/rubocop/result_cache.rb +5 -7
- data/lib/rubocop/rspec/cop_helper.rb +5 -28
- data/lib/rubocop/rspec/expect_offense.rb +60 -23
- data/lib/rubocop/rspec/shared_contexts.rb +55 -17
- data/lib/rubocop/runner.rb +42 -38
- data/lib/rubocop/target_finder.rb +2 -4
- data/lib/rubocop/target_ruby.rb +5 -2
- data/lib/rubocop/version.rb +5 -3
- metadata +60 -62
- data/lib/rubocop/ast/builder.rb +0 -85
- data/lib/rubocop/ast/node.rb +0 -637
- data/lib/rubocop/ast/node/alias_node.rb +0 -24
- data/lib/rubocop/ast/node/and_node.rb +0 -29
- data/lib/rubocop/ast/node/args_node.rb +0 -29
- data/lib/rubocop/ast/node/array_node.rb +0 -70
- data/lib/rubocop/ast/node/block_node.rb +0 -121
- data/lib/rubocop/ast/node/break_node.rb +0 -17
- data/lib/rubocop/ast/node/case_match_node.rb +0 -56
- data/lib/rubocop/ast/node/case_node.rb +0 -56
- data/lib/rubocop/ast/node/class_node.rb +0 -31
- data/lib/rubocop/ast/node/def_node.rb +0 -82
- data/lib/rubocop/ast/node/defined_node.rb +0 -17
- data/lib/rubocop/ast/node/ensure_node.rb +0 -17
- data/lib/rubocop/ast/node/float_node.rb +0 -12
- data/lib/rubocop/ast/node/for_node.rb +0 -53
- data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
- data/lib/rubocop/ast/node/hash_node.rb +0 -109
- data/lib/rubocop/ast/node/if_node.rb +0 -175
- data/lib/rubocop/ast/node/int_node.rb +0 -12
- data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
- data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
- data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
- data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -269
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
- data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
- data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
- data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
- data/lib/rubocop/ast/node/module_node.rb +0 -24
- data/lib/rubocop/ast/node/or_node.rb +0 -29
- data/lib/rubocop/ast/node/pair_node.rb +0 -63
- data/lib/rubocop/ast/node/range_node.rb +0 -18
- data/lib/rubocop/ast/node/regexp_node.rb +0 -33
- data/lib/rubocop/ast/node/resbody_node.rb +0 -24
- data/lib/rubocop/ast/node/retry_node.rb +0 -17
- data/lib/rubocop/ast/node/return_node.rb +0 -24
- data/lib/rubocop/ast/node/self_class_node.rb +0 -24
- data/lib/rubocop/ast/node/send_node.rb +0 -17
- data/lib/rubocop/ast/node/str_node.rb +0 -16
- data/lib/rubocop/ast/node/super_node.rb +0 -21
- data/lib/rubocop/ast/node/symbol_node.rb +0 -12
- data/lib/rubocop/ast/node/until_node.rb +0 -35
- data/lib/rubocop/ast/node/when_node.rb +0 -53
- data/lib/rubocop/ast/node/while_node.rb +0 -35
- data/lib/rubocop/ast/node/yield_node.rb +0 -21
- data/lib/rubocop/ast/sexp.rb +0 -16
- data/lib/rubocop/ast/traversal.rb +0 -202
- data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
- data/lib/rubocop/node_pattern.rb +0 -887
- data/lib/rubocop/processed_source.rb +0 -213
- data/lib/rubocop/token.rb +0 -114
@@ -263,9 +263,7 @@ module RuboCop
|
|
263
263
|
def offense(body_node, indentation, style)
|
264
264
|
# This cop only auto-corrects the first statement in a def body, for
|
265
265
|
# example.
|
266
|
-
if body_node.begin_type? && !parentheses?(body_node)
|
267
|
-
body_node = body_node.children.first
|
268
|
-
end
|
266
|
+
body_node = body_node.children.first if body_node.begin_type? && !parentheses?(body_node)
|
269
267
|
|
270
268
|
# Since autocorrect changes a number of lines, and not only the line
|
271
269
|
# where the reported offending range is, we avoid auto-correction if
|
@@ -21,23 +21,23 @@ module RuboCop
|
|
21
21
|
# are recommended to further format the broken lines.
|
22
22
|
# (Many of these are enabled by default.)
|
23
23
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
24
|
+
# * ArgumentAlignment
|
25
|
+
# * BlockAlignment
|
26
|
+
# * BlockDelimiters
|
27
|
+
# * BlockEndNewline
|
28
|
+
# * ClosingParenthesisIndentation
|
29
|
+
# * FirstArgumentIndentation
|
30
|
+
# * FirstArrayElementIndentation
|
31
|
+
# * FirstHashElementIndentation
|
32
|
+
# * FirstParameterIndentation
|
33
|
+
# * HashAlignment
|
34
|
+
# * IndentationWidth
|
35
|
+
# * MultilineArrayLineBreaks
|
36
|
+
# * MultilineBlockLayout
|
37
|
+
# * MultilineHashBraceLayout
|
38
|
+
# * MultilineHashKeyLineBreaks
|
39
|
+
# * MultilineMethodArgumentLineBreaks
|
40
|
+
# * ParameterAlignment
|
41
41
|
#
|
42
42
|
# Together, these cops will pretty print hashes, arrays,
|
43
43
|
# method calls, etc. For example, let's say the max columns
|
@@ -105,7 +105,6 @@ module RuboCop
|
|
105
105
|
def add_offense_for_expression(node, expr, msg)
|
106
106
|
expression = expr.source_range
|
107
107
|
range = range_between(expression.begin_pos, expression.end_pos)
|
108
|
-
|
109
108
|
add_offense(node, location: range, message: msg)
|
110
109
|
end
|
111
110
|
|
@@ -121,7 +120,7 @@ module RuboCop
|
|
121
120
|
end
|
122
121
|
|
123
122
|
def autocorrect_body(corrector, node, block_body)
|
124
|
-
first_node = if block_body.begin_type?
|
123
|
+
first_node = if block_body.begin_type? && !block_body.source.start_with?('(')
|
125
124
|
block_body.children.first
|
126
125
|
else
|
127
126
|
block_body
|
@@ -37,9 +37,7 @@ module RuboCop
|
|
37
37
|
# ...then each key/value pair is treated as a method 'argument'
|
38
38
|
# when determining where line breaks should appear.
|
39
39
|
if (last_arg = args.last)
|
40
|
-
if last_arg.hash_type? && !last_arg.braces?
|
41
|
-
args = args.concat(args.pop.children)
|
42
|
-
end
|
40
|
+
args = args.concat(args.pop.children) if last_arg.hash_type? && !last_arg.braces?
|
43
41
|
end
|
44
42
|
|
45
43
|
check_line_breaks(node, args)
|
@@ -24,9 +24,10 @@ module RuboCop
|
|
24
24
|
# # good
|
25
25
|
# {}.each { | x, y | puts x }
|
26
26
|
# ->( x, y ) { puts x }
|
27
|
-
class SpaceAroundBlockParameters <
|
27
|
+
class SpaceAroundBlockParameters < Base
|
28
28
|
include ConfigurableEnforcedStyle
|
29
29
|
include RangeHelp
|
30
|
+
extend AutoCorrector
|
30
31
|
|
31
32
|
def on_block(node)
|
32
33
|
arguments = node.arguments
|
@@ -38,23 +39,6 @@ module RuboCop
|
|
38
39
|
check_each_arg(arguments)
|
39
40
|
end
|
40
41
|
|
41
|
-
# @param target [RuboCop::AST::Node,Parser::Source::Range]
|
42
|
-
def autocorrect(target)
|
43
|
-
lambda do |corrector|
|
44
|
-
if target.is_a?(RuboCop::AST::Node)
|
45
|
-
if target.parent.children.first == target
|
46
|
-
corrector.insert_before(target, ' ')
|
47
|
-
else
|
48
|
-
corrector.insert_after(target, ' ')
|
49
|
-
end
|
50
|
-
elsif /^\s+$/.match?(target.source)
|
51
|
-
corrector.remove(target)
|
52
|
-
else
|
53
|
-
corrector.insert_after(target, ' ')
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
42
|
private
|
59
43
|
|
60
44
|
def pipes(arguments)
|
@@ -97,7 +81,7 @@ module RuboCop
|
|
97
81
|
|
98
82
|
check_no_space(opening_pipe.end_pos, first.begin_pos,
|
99
83
|
'Space before first')
|
100
|
-
check_no_space(last_end_pos_inside_pipes(last
|
84
|
+
check_no_space(last_end_pos_inside_pipes(last),
|
101
85
|
closing_pipe.begin_pos, 'Space after last')
|
102
86
|
end
|
103
87
|
|
@@ -118,7 +102,7 @@ module RuboCop
|
|
118
102
|
|
119
103
|
def check_closing_pipe_space(args, closing_pipe)
|
120
104
|
last = args.last.source_range
|
121
|
-
last_end_pos = last_end_pos_inside_pipes(last
|
105
|
+
last_end_pos = last_end_pos_inside_pipes(last)
|
122
106
|
|
123
107
|
check_space(last_end_pos, closing_pipe.begin_pos, last,
|
124
108
|
'after last block parameter')
|
@@ -126,8 +110,9 @@ module RuboCop
|
|
126
110
|
'Extra space after last')
|
127
111
|
end
|
128
112
|
|
129
|
-
def last_end_pos_inside_pipes(
|
130
|
-
|
113
|
+
def last_end_pos_inside_pipes(range)
|
114
|
+
pos = range.end_pos
|
115
|
+
range.source_buffer.source[pos] == ',' ? pos + 1 : pos
|
131
116
|
end
|
132
117
|
|
133
118
|
def check_each_arg(args)
|
@@ -151,7 +136,14 @@ module RuboCop
|
|
151
136
|
return if space_begin_pos != space_end_pos
|
152
137
|
|
153
138
|
target = node || range
|
154
|
-
|
139
|
+
message = "Space #{msg} missing."
|
140
|
+
add_offense(target, message: message) do |corrector|
|
141
|
+
if node
|
142
|
+
corrector.insert_before(node, ' ')
|
143
|
+
else
|
144
|
+
corrector.insert_after(target, ' ')
|
145
|
+
end
|
146
|
+
end
|
155
147
|
end
|
156
148
|
|
157
149
|
def check_no_space(space_begin_pos, space_end_pos, msg)
|
@@ -160,8 +152,10 @@ module RuboCop
|
|
160
152
|
range = range_between(space_begin_pos, space_end_pos)
|
161
153
|
return if range.source.include?("\n")
|
162
154
|
|
163
|
-
|
164
|
-
|
155
|
+
message = "#{msg} block parameter detected."
|
156
|
+
add_offense(range, message: message) do |corrector|
|
157
|
+
corrector.remove(range)
|
158
|
+
end
|
165
159
|
end
|
166
160
|
end
|
167
161
|
end
|
@@ -186,7 +186,7 @@ module RuboCop
|
|
186
186
|
pos = range.begin_pos - 1
|
187
187
|
return false if pos.negative?
|
188
188
|
|
189
|
-
range.source_buffer.source[pos]
|
189
|
+
!/[\s(|{\[;,*=]/.match?(range.source_buffer.source[pos])
|
190
190
|
end
|
191
191
|
|
192
192
|
def space_after_missing?(range)
|
@@ -198,7 +198,7 @@ module RuboCop
|
|
198
198
|
return false if accept_namespace_operator?(range) &&
|
199
199
|
namespace_operator?(range, pos)
|
200
200
|
|
201
|
-
|
201
|
+
!/[\s;,#\\)}\].]/.match?(char)
|
202
202
|
end
|
203
203
|
|
204
204
|
def accepted_opening_delimiter?(range, char)
|
@@ -121,9 +121,7 @@ module RuboCop
|
|
121
121
|
|
122
122
|
def right_token_for_auto_correction(operator)
|
123
123
|
right_token = next_token(operator)
|
124
|
-
if !right_token.comment? && valid_right_token?(right_token, operator)
|
125
|
-
return right_token
|
126
|
-
end
|
124
|
+
return right_token if !right_token.comment? && valid_right_token?(right_token, operator)
|
127
125
|
|
128
126
|
operator
|
129
127
|
end
|
@@ -134,7 +134,7 @@ module RuboCop
|
|
134
134
|
|
135
135
|
def autocorrect(range)
|
136
136
|
lambda do |corrector|
|
137
|
-
if range.source
|
137
|
+
if /\*\*/.match?(range.source) && !space_around_exponent_operator?
|
138
138
|
corrector.replace(range, '**')
|
139
139
|
elsif range.source.end_with?("\n")
|
140
140
|
corrector.replace(range, " #{range.source.strip}\n")
|
@@ -27,6 +27,20 @@ module RuboCop
|
|
27
27
|
# foo.map{ |a|
|
28
28
|
# a.bar.to_s
|
29
29
|
# }
|
30
|
+
#
|
31
|
+
# @example EnforcedStyleForEmptyBraces: space (default)
|
32
|
+
# # bad
|
33
|
+
# 7.times{}
|
34
|
+
#
|
35
|
+
# # good
|
36
|
+
# 7.times {}
|
37
|
+
#
|
38
|
+
# @example EnforcedStyleForEmptyBraces: no_space
|
39
|
+
# # bad
|
40
|
+
# 7.times {}
|
41
|
+
#
|
42
|
+
# # good
|
43
|
+
# 7.times{}
|
30
44
|
class SpaceBeforeBlockBraces < Cop
|
31
45
|
include ConfigurableEnforcedStyle
|
32
46
|
include RangeHelp
|
@@ -20,9 +20,7 @@ module RuboCop
|
|
20
20
|
next unless token2.comment?
|
21
21
|
next unless token1.line == token2.line
|
22
22
|
|
23
|
-
if token1.pos.end == token2.pos.begin
|
24
|
-
add_offense(token2.pos, location: token2.pos)
|
25
|
-
end
|
23
|
+
add_offense(token2.pos, location: token2.pos) if token1.pos.end == token2.pos.begin
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
@@ -78,9 +78,7 @@ module RuboCop
|
|
78
78
|
return unless node.square_brackets?
|
79
79
|
|
80
80
|
left, right = array_brackets(node)
|
81
|
-
if empty_brackets?(left, right)
|
82
|
-
return empty_offenses(node, left, right, EMPTY_MSG)
|
83
|
-
end
|
81
|
+
return empty_offenses(node, left, right, EMPTY_MSG) if empty_brackets?(left, right)
|
84
82
|
|
85
83
|
start_ok = next_to_newline?(node, left)
|
86
84
|
end_ok = node.single_line? ? false : end_has_own_line?(right)
|
@@ -132,7 +130,7 @@ module RuboCop
|
|
132
130
|
line, col = line_and_column_for(token)
|
133
131
|
return true if col == -1
|
134
132
|
|
135
|
-
processed_source.lines[line][0..col]
|
133
|
+
!/\S/.match?(processed_source.lines[line][0..col])
|
136
134
|
end
|
137
135
|
|
138
136
|
def index_for(node, token)
|
@@ -150,7 +150,7 @@ module RuboCop
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def check_right_brace(inner, left_brace, right_brace, single_line)
|
153
|
-
if single_line &&
|
153
|
+
if single_line && /\S$/.match?(inner)
|
154
154
|
no_space(right_brace.begin_pos, right_brace.end_pos,
|
155
155
|
'Space missing inside }.')
|
156
156
|
else
|
@@ -182,7 +182,7 @@ module RuboCop
|
|
182
182
|
def range_of_space_to_the_right(range)
|
183
183
|
src = range.source_buffer.source
|
184
184
|
end_pos = range.end_pos
|
185
|
-
end_pos += 1 while
|
185
|
+
end_pos += 1 while /[ \t]/.match?(src[end_pos])
|
186
186
|
|
187
187
|
range_between(range.begin_pos + 1, end_pos)
|
188
188
|
end
|
@@ -190,7 +190,7 @@ module RuboCop
|
|
190
190
|
def range_of_space_to_the_left(range)
|
191
191
|
src = range.source_buffer.source
|
192
192
|
begin_pos = range.begin_pos
|
193
|
-
begin_pos -= 1 while src[begin_pos - 1]
|
193
|
+
begin_pos -= 1 while /[ \t]/.match?(src[begin_pos - 1])
|
194
194
|
|
195
195
|
range_between(begin_pos, range.end_pos - 1)
|
196
196
|
end
|
@@ -130,9 +130,7 @@ module RuboCop
|
|
130
130
|
tokens[i..-1].each do |token|
|
131
131
|
inner_left_brackets_needing_closure += 1 if token.left_bracket?
|
132
132
|
inner_left_brackets_needing_closure -= 1 if token.right_bracket?
|
133
|
-
if inner_left_brackets_needing_closure.zero? && token.right_bracket?
|
134
|
-
return token
|
135
|
-
end
|
133
|
+
return token if inner_left_brackets_needing_closure.zero? && token.right_bracket?
|
136
134
|
end
|
137
135
|
end
|
138
136
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Legacy
|
6
|
+
# Legacy support for Corrector#corrections
|
7
|
+
# See https://docs.rubocop.org/rubocop/cop_api_v1_changelog.html
|
8
|
+
class CorrectionsProxy
|
9
|
+
def initialize(corrector)
|
10
|
+
@corrector = corrector
|
11
|
+
end
|
12
|
+
|
13
|
+
def <<(callable)
|
14
|
+
suppress_clobbering do
|
15
|
+
@corrector.transaction do
|
16
|
+
callable.call(@corrector)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def empty?
|
22
|
+
@corrector.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
def concat(corrections)
|
26
|
+
if corrections.is_a?(CorrectionsProxy)
|
27
|
+
suppress_clobbering do
|
28
|
+
corrector.merge!(corrections.corrector)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
corrections.each { |correction| self << correction }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
attr_reader :corrector
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def suppress_clobbering
|
42
|
+
yield
|
43
|
+
rescue ::Parser::ClobberingError
|
44
|
+
# ignore Clobbering errors
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Legacy
|
6
|
+
# Legacy Corrector for v0 API support.
|
7
|
+
# See https://docs.rubocop.org/rubocop/cop_api_v1_changelog.html
|
8
|
+
class Corrector < RuboCop::Cop::Corrector
|
9
|
+
# Support legacy second argument
|
10
|
+
def initialize(source, corr = [])
|
11
|
+
super(source)
|
12
|
+
if corr.is_a?(CorrectionsProxy)
|
13
|
+
merge!(corr.send(:corrector))
|
14
|
+
else
|
15
|
+
# warn "Corrector.new with corrections is deprecated." unless corr.empty? TODO
|
16
|
+
corr.each do |c|
|
17
|
+
corrections << c
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def corrections
|
23
|
+
# warn "#corrections is deprecated. Open an issue if you have a valid usecase." TODO
|
24
|
+
CorrectionsProxy.new(self)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -60,8 +60,11 @@ module RuboCop
|
|
60
60
|
end
|
61
61
|
|
62
62
|
ast.each_node(:send).find do |send_node|
|
63
|
-
|
64
|
-
|
63
|
+
first_argument = send_node.first_argument
|
64
|
+
|
65
|
+
first_argument &&
|
66
|
+
offense_position?(first_argument, diagnostic) &&
|
67
|
+
unary_operator?(first_argument, diagnostic)
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# Check that certain constants are fully qualified.
|
7
|
+
#
|
8
|
+
# This is not enabled by default because it would mark a lot of offenses
|
9
|
+
# unnecessarily.
|
10
|
+
#
|
11
|
+
# Generally, gems should fully qualify all constants to avoid conflicts with
|
12
|
+
# the code that uses the gem. Enable this cop without using `Only`/`Ignore`
|
13
|
+
#
|
14
|
+
# Large projects will over time end up with one or two constant names that
|
15
|
+
# are problematic because of a conflict with a library or just internally
|
16
|
+
# using the same name a namespace and a class. To avoid too many unnecessary
|
17
|
+
# offenses, Enable this cop with `Only: [The, Constant, Names, Causing, Issues]`
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# # By default checks every constant
|
21
|
+
#
|
22
|
+
# # bad
|
23
|
+
# User
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# User::Login
|
27
|
+
#
|
28
|
+
# # good
|
29
|
+
# ::User
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# ::User::Login
|
33
|
+
#
|
34
|
+
# @example Only: ['Login']
|
35
|
+
# # Restrict this cop to only being concerned about certain constants
|
36
|
+
#
|
37
|
+
# # bad
|
38
|
+
# Login
|
39
|
+
#
|
40
|
+
# # good
|
41
|
+
# ::Login
|
42
|
+
#
|
43
|
+
# # good
|
44
|
+
# User::Login
|
45
|
+
#
|
46
|
+
# @example Ignore: ['Login']
|
47
|
+
# # Restrict this cop not being concerned about certain constants
|
48
|
+
#
|
49
|
+
# # bad
|
50
|
+
# User
|
51
|
+
#
|
52
|
+
# # good
|
53
|
+
# ::User::Login
|
54
|
+
#
|
55
|
+
# # good
|
56
|
+
# Login
|
57
|
+
#
|
58
|
+
class ConstantResolution < Cop
|
59
|
+
MSG = 'Fully qualify this constant to avoid possibly ambiguous resolution.'
|
60
|
+
|
61
|
+
def_node_matcher :unqualified_const?, <<~PATTERN
|
62
|
+
(const nil? #const_name?)
|
63
|
+
PATTERN
|
64
|
+
|
65
|
+
def on_const(node)
|
66
|
+
return unless unqualified_const?(node)
|
67
|
+
|
68
|
+
add_offense(node)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def const_name?(name)
|
74
|
+
name = name.to_s
|
75
|
+
(allowed_names.empty? || allowed_names.include?(name)) &&
|
76
|
+
!ignored_names.include?(name)
|
77
|
+
end
|
78
|
+
|
79
|
+
def allowed_names
|
80
|
+
cop_config['Only']
|
81
|
+
end
|
82
|
+
|
83
|
+
def ignored_names
|
84
|
+
cop_config['Ignore']
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|