rubocop 1.9.0 → 1.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -14
- data/assets/output.html.erb +1 -1
- data/config/default.yml +70 -17
- data/config/obsoletion.yml +4 -0
- data/lib/rubocop.rb +5 -0
- data/lib/rubocop/cli/command/execute_runner.rb +1 -1
- data/lib/rubocop/cli/command/suggest_extensions.rb +3 -2
- data/lib/rubocop/comment_config.rb +43 -94
- data/lib/rubocop/config.rb +4 -1
- data/lib/rubocop/cop/base.rb +1 -0
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -0
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -0
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +3 -6
- data/lib/rubocop/cop/exclude_limit.rb +26 -0
- data/lib/rubocop/cop/gemspec/date_assignment.rb +57 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -0
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -0
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +2 -0
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +2 -0
- data/lib/rubocop/cop/generator.rb +2 -2
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +151 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +3 -0
- data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +4 -0
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +11 -8
- data/lib/rubocop/cop/layout/argument_alignment.rb +6 -5
- data/lib/rubocop/cop/layout/array_alignment.rb +7 -6
- data/lib/rubocop/cop/layout/assignment_indentation.rb +6 -3
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/block_end_newline.rb +4 -8
- data/lib/rubocop/cop/layout/class_structure.rb +1 -0
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +14 -15
- data/lib/rubocop/cop/layout/comment_indentation.rb +16 -16
- data/lib/rubocop/cop/layout/else_alignment.rb +9 -6
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +20 -3
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +37 -17
- data/lib/rubocop/cop/layout/extra_spacing.rb +2 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +27 -7
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +9 -6
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +22 -15
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +6 -5
- data/lib/rubocop/cop/layout/indentation_consistency.rb +9 -6
- data/lib/rubocop/cop/layout/indentation_style.rb +27 -30
- data/lib/rubocop/cop/layout/indentation_width.rb +20 -9
- data/lib/rubocop/cop/layout/line_length.rb +2 -1
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +26 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +18 -5
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +10 -5
- data/lib/rubocop/cop/layout/parameter_alignment.rb +6 -5
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_brackets.rb +9 -4
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -0
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +2 -0
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -0
- data/lib/rubocop/cop/lint/debugger.rb +60 -14
- data/lib/rubocop/cop/lint/deprecated_constants.rb +5 -0
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +14 -4
- data/lib/rubocop/cop/lint/duplicate_branch.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -0
- data/lib/rubocop/cop/lint/duplicate_require.rb +3 -2
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
- data/lib/rubocop/cop/lint/else_layout.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -0
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -0
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +1 -0
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -0
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -0
- data/lib/rubocop/cop/lint/multiple_comparison.rb +5 -4
- data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -0
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -0
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +7 -0
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +11 -2
- data/lib/rubocop/cop/lint/raise_exception.rb +2 -0
- data/lib/rubocop/cop/lint/rand_one.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -2
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +7 -3
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -0
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -0
- data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
- data/lib/rubocop/cop/lint/suppressed_exception.rb +44 -1
- data/lib/rubocop/cop/lint/symbol_conversion.rb +91 -3
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +3 -0
- data/lib/rubocop/cop/lint/unified_integer.rb +1 -0
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +5 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -0
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -0
- data/lib/rubocop/cop/lint/useless_times.rb +3 -0
- data/lib/rubocop/cop/message_annotator.rb +4 -1
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
- data/lib/rubocop/cop/metrics/module_length.rb +1 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +6 -2
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +6 -4
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +2 -0
- data/lib/rubocop/cop/mixin/alignment.rb +10 -3
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +3 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +5 -1
- data/lib/rubocop/cop/mixin/configurable_max.rb +1 -0
- data/lib/rubocop/cop/mixin/def_node.rb +1 -0
- data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -0
- data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -0
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -0
- data/lib/rubocop/cop/mixin/line_length_help.rb +11 -6
- data/lib/rubocop/cop/mixin/method_complexity.rb +4 -1
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +3 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +4 -23
- data/lib/rubocop/cop/mixin/negative_conditional.rb +3 -0
- data/lib/rubocop/cop/mixin/preferred_delimiters.rb +3 -3
- data/lib/rubocop/cop/mixin/rational_literal.rb +1 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +5 -0
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +4 -6
- data/lib/rubocop/cop/mixin/visibility_help.rb +1 -0
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -0
- data/lib/rubocop/cop/naming/constant_name.rb +2 -0
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +6 -0
- data/lib/rubocop/cop/naming/method_name.rb +3 -0
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -0
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -0
- data/lib/rubocop/cop/registry.rb +10 -1
- data/lib/rubocop/cop/security/eval.rb +1 -0
- data/lib/rubocop/cop/security/json_load.rb +1 -0
- data/lib/rubocop/cop/security/marshal_load.rb +1 -0
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/security/yaml_load.rb +1 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +3 -2
- data/lib/rubocop/cop/style/alias.rb +1 -0
- data/lib/rubocop/cop/style/and_or.rb +3 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -0
- data/lib/rubocop/cop/style/array_coercion.rb +2 -0
- data/lib/rubocop/cop/style/array_join.rb +1 -0
- data/lib/rubocop/cop/style/attr.rb +1 -0
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +59 -71
- data/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb +62 -0
- data/lib/rubocop/cop/style/case_equality.rb +2 -1
- data/lib/rubocop/cop/style/case_like_if.rb +15 -4
- data/lib/rubocop/cop/style/class_equality_comparison.rb +3 -0
- data/lib/rubocop/cop/style/collection_compact.rb +2 -0
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -0
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +10 -10
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -0
- data/lib/rubocop/cop/style/constant_visibility.rb +28 -0
- data/lib/rubocop/cop/style/date_time.rb +3 -0
- data/lib/rubocop/cop/style/dir.rb +1 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
- data/lib/rubocop/cop/style/documentation.rb +30 -3
- data/lib/rubocop/cop/style/documentation_method.rb +1 -0
- data/lib/rubocop/cop/style/double_negation.rb +3 -2
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -0
- data/lib/rubocop/cop/style/each_with_object.rb +1 -0
- data/lib/rubocop/cop/style/empty_literal.rb +9 -0
- data/lib/rubocop/cop/style/endless_method.rb +1 -0
- data/lib/rubocop/cop/style/eval_with_location.rb +90 -28
- data/lib/rubocop/cop/style/even_odd.rb +1 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -0
- data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -1
- data/lib/rubocop/cop/style/exponential_notation.rb +6 -7
- data/lib/rubocop/cop/style/float_division.rb +4 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -0
- data/lib/rubocop/cop/style/format_string_token.rb +1 -0
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +0 -3
- data/lib/rubocop/cop/style/global_std_stream.rb +1 -0
- data/lib/rubocop/cop/style/hash_conversion.rb +108 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -0
- data/lib/rubocop/cop/style/hash_except.rb +1 -0
- data/lib/rubocop/cop/style/hash_like_case.rb +1 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +16 -15
- data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -0
- data/lib/rubocop/cop/style/hash_transform_values.rb +4 -0
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +37 -11
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +2 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +46 -2
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +19 -3
- data/lib/rubocop/cop/style/min_max.rb +1 -0
- data/lib/rubocop/cop/style/mixin_usage.rb +2 -0
- data/lib/rubocop/cop/style/module_function.rb +5 -0
- data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -3
- data/lib/rubocop/cop/style/multiple_comparison.rb +21 -2
- data/lib/rubocop/cop/style/mutable_constant.rb +3 -0
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +16 -2
- data/lib/rubocop/cop/style/nil_comparison.rb +6 -1
- data/lib/rubocop/cop/style/nil_lambda.rb +1 -0
- data/lib/rubocop/cop/style/non_nil_check.rb +7 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +6 -9
- data/lib/rubocop/cop/style/numeric_predicate.rb +4 -1
- data/lib/rubocop/cop/style/option_hash.rb +1 -0
- data/lib/rubocop/cop/style/or_assignment.rb +2 -0
- data/lib/rubocop/cop/style/parallel_assignment.rb +6 -0
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -0
- data/lib/rubocop/cop/style/proc.rb +1 -0
- data/lib/rubocop/cop/style/random_with_offset.rb +5 -0
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +44 -4
- data/lib/rubocop/cop/style/redundant_conditional.rb +2 -0
- data/lib/rubocop/cop/style/redundant_exception.rb +2 -0
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +2 -0
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -0
- data/lib/rubocop/cop/style/redundant_return.rb +4 -0
- data/lib/rubocop/cop/style/redundant_self.rb +7 -3
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -0
- data/lib/rubocop/cop/style/redundant_sort.rb +1 -0
- data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -0
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/rescue_modifier.rb +17 -14
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -0
- data/lib/rubocop/cop/style/return_nil.rb +6 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -0
- data/lib/rubocop/cop/style/sample.rb +1 -0
- data/lib/rubocop/cop/style/signal_exception.rb +3 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
- data/lib/rubocop/cop/style/single_line_methods.rb +4 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -0
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +20 -4
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -3
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
- data/lib/rubocop/cop/style/string_chars.rb +38 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +1 -0
- data/lib/rubocop/cop/style/string_hash_keys.rb +2 -0
- data/lib/rubocop/cop/style/strip.rb +1 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +3 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +25 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -0
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +5 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -0
- data/lib/rubocop/cop/style/unless_logical_operators.rb +105 -0
- data/lib/rubocop/cop/style/unpack_first.rb +1 -0
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -0
- data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -0
- data/lib/rubocop/cop/util.rb +4 -1
- data/lib/rubocop/directive_comment.rb +69 -9
- data/lib/rubocop/ext/regexp_parser.rb +3 -6
- data/lib/rubocop/formatter/clang_style_formatter.rb +4 -2
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +2 -1
- data/lib/rubocop/formatter/tap_formatter.rb +4 -2
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/name_similarity.rb +1 -1
- data/lib/rubocop/target_finder.rb +1 -0
- data/lib/rubocop/target_ruby.rb +21 -13
- data/lib/rubocop/version.rb +1 -1
- metadata +14 -7
@@ -4,10 +4,12 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
# Common functionality for checking length of code segments.
|
6
6
|
module CodeLength
|
7
|
-
|
7
|
+
extend ExcludeLimit
|
8
8
|
|
9
9
|
MSG = '%<label>s has too many lines. [%<length>d/%<max>d]'
|
10
10
|
|
11
|
+
exclude_limit 'Max'
|
12
|
+
|
11
13
|
private
|
12
14
|
|
13
15
|
def message(length, max_length)
|
@@ -23,7 +23,11 @@ module RuboCop
|
|
23
23
|
def begin_pos_with_comment(node)
|
24
24
|
first_comment = processed_source.ast_with_comments[node].first
|
25
25
|
|
26
|
-
|
26
|
+
if first_comment && (first_comment.loc.line < node.loc.line)
|
27
|
+
start_line_position(first_comment)
|
28
|
+
else
|
29
|
+
start_line_position(node)
|
30
|
+
end
|
27
31
|
end
|
28
32
|
|
29
33
|
def start_line_position(node)
|
@@ -18,7 +18,10 @@ module RuboCop
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
+
# @!method constant_definition?(node)
|
21
22
|
def_node_matcher :constant_definition?, '{class module}'
|
23
|
+
|
24
|
+
# @!method empty_line_required?(node)
|
22
25
|
def_node_matcher :empty_line_required?,
|
23
26
|
'{def defs class module (send nil? {:private :protected :public})}'
|
24
27
|
|
@@ -13,10 +13,12 @@ module RuboCop
|
|
13
13
|
# @api private
|
14
14
|
module EnforceSuperclass
|
15
15
|
def self.included(base)
|
16
|
+
# @!method class_definition(node)
|
16
17
|
base.def_node_matcher :class_definition, <<~PATTERN
|
17
18
|
(class (const _ !:#{base::SUPERCLASS}) #{base::BASE_PATTERN} ...)
|
18
19
|
PATTERN
|
19
20
|
|
21
|
+
# @!method class_new_definition(node)
|
20
22
|
base.def_node_matcher :class_new_definition, <<~PATTERN
|
21
23
|
[!^(casgn {nil? cbase} :#{base::SUPERCLASS} ...)
|
22
24
|
!^^(casgn {nil? cbase} :#{base::SUPERCLASS} (block ...))
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
|
17
17
|
return false unless comment
|
18
18
|
|
19
|
-
|
19
|
+
!!DirectiveComment.new(comment).match_captures
|
20
20
|
end
|
21
21
|
|
22
22
|
def allow_uri?
|
@@ -24,9 +24,7 @@ module RuboCop
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def allowed_uri_position?(line, uri_range)
|
27
|
-
uri_range.begin < max_line_length &&
|
28
|
-
(uri_range.end == line_length(line) ||
|
29
|
-
uri_range.end == line_length(line) - 1)
|
27
|
+
uri_range.begin < max_line_length && uri_range.end == line_length(line)
|
30
28
|
end
|
31
29
|
|
32
30
|
def line_length(line)
|
@@ -40,6 +38,14 @@ module RuboCop
|
|
40
38
|
begin_position, end_position = last_uri_match.offset(0).map do |pos|
|
41
39
|
pos + indentation_difference(line)
|
42
40
|
end
|
41
|
+
|
42
|
+
# Extend the end position until the start of the next word, if any.
|
43
|
+
# This allows for URIs that are wrapped in quotes or parens to be handled properly
|
44
|
+
# while not allowing additional words to be added after the URL.
|
45
|
+
if (match = line[end_position..line_length(line)]&.match(/^\S+(?=\s|$)/))
|
46
|
+
end_position += match.offset(0).last
|
47
|
+
end
|
48
|
+
|
43
49
|
return nil if begin_position < max_line_length &&
|
44
50
|
end_position < max_line_length
|
45
51
|
|
@@ -79,8 +85,7 @@ module RuboCop
|
|
79
85
|
end
|
80
86
|
|
81
87
|
def line_length_without_directive(line)
|
82
|
-
before_comment
|
83
|
-
before_comment.rstrip.length
|
88
|
+
DirectiveComment.before_comment(line).rstrip.length
|
84
89
|
end
|
85
90
|
end
|
86
91
|
end
|
@@ -6,10 +6,12 @@ module RuboCop
|
|
6
6
|
#
|
7
7
|
# This module handles measurement and reporting of complexity in methods.
|
8
8
|
module MethodComplexity
|
9
|
-
include ConfigurableMax
|
10
9
|
include IgnoredMethods
|
11
10
|
include Metrics::Utils::RepeatedCsendDiscount
|
12
11
|
extend NodePattern::Macros
|
12
|
+
extend ExcludeLimit
|
13
|
+
|
14
|
+
exclude_limit 'Max'
|
13
15
|
|
14
16
|
# Ensure cops that include `MethodComplexity` have the config
|
15
17
|
# `attr_accessor`s that `ignored_method?` needs.
|
@@ -34,6 +36,7 @@ module RuboCop
|
|
34
36
|
|
35
37
|
private
|
36
38
|
|
39
|
+
# @!method define_method?(node)
|
37
40
|
def_node_matcher :define_method?, <<~PATTERN
|
38
41
|
(block
|
39
42
|
(send nil? :define_method ({sym str} $_))
|
@@ -77,7 +77,9 @@ module RuboCop
|
|
77
77
|
def incorrect_style_detected(styles, first, left_parenthesis)
|
78
78
|
msg = message(base_description(left_parenthesis))
|
79
79
|
|
80
|
-
add_offense(first, message: msg) do
|
80
|
+
add_offense(first, message: msg) do |corrector|
|
81
|
+
autocorrect(corrector, first)
|
82
|
+
|
81
83
|
ambiguous_style_detected(*styles)
|
82
84
|
end
|
83
85
|
end
|
@@ -35,26 +35,6 @@ module RuboCop
|
|
35
35
|
lhs
|
36
36
|
end
|
37
37
|
|
38
|
-
def right_hand_side(send_node)
|
39
|
-
if send_node.operator_method? && send_node.arguments?
|
40
|
-
send_node.first_argument.source_range # not used for method calls
|
41
|
-
else
|
42
|
-
regular_method_right_hand_side(send_node)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def regular_method_right_hand_side(send_node)
|
47
|
-
dot = send_node.loc.dot
|
48
|
-
selector = send_node.loc.selector
|
49
|
-
if send_node.dot? && selector && dot.line == selector.line
|
50
|
-
dot.join(selector)
|
51
|
-
elsif selector
|
52
|
-
selector
|
53
|
-
elsif send_node.implicit_call?
|
54
|
-
dot.join(send_node.loc.begin)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
38
|
# The correct indentation of `node` is usually `IndentationWidth`, with
|
59
39
|
# one exception: prefix keywords.
|
60
40
|
#
|
@@ -91,9 +71,10 @@ module RuboCop
|
|
91
71
|
end
|
92
72
|
|
93
73
|
def incorrect_style_detected(range, node, lhs, rhs)
|
94
|
-
add_offense(range,
|
95
|
-
|
96
|
-
|
74
|
+
add_offense(range, message: message(node, lhs, rhs)) do |corrector|
|
75
|
+
autocorrect(corrector, range)
|
76
|
+
|
77
|
+
if supported_styles.size > 2 || offending_range(node, lhs, rhs, alternative_style)
|
97
78
|
unrecognized_style_detected
|
98
79
|
else
|
99
80
|
opposite_style_detected
|
@@ -12,7 +12,10 @@ module RuboCop
|
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
+
# @!method single_negative?(node)
|
15
16
|
def_node_matcher :single_negative?, '(send !(send _ :!) :!)'
|
17
|
+
|
18
|
+
# @!method empty_condition?(node)
|
16
19
|
def_node_matcher :empty_condition?, '(begin)'
|
17
20
|
|
18
21
|
def check_negative_conditional(node, message:, &block)
|
@@ -15,7 +15,7 @@ module RuboCop
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def delimiters
|
18
|
-
preferred_delimiters[type].
|
18
|
+
preferred_delimiters[type].chars
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
@@ -35,10 +35,10 @@ module RuboCop
|
|
35
35
|
ensure_valid_preferred_delimiters
|
36
36
|
|
37
37
|
if preferred_delimiters_config.key?('default')
|
38
|
-
|
38
|
+
PERCENT_LITERAL_TYPES.map do |type|
|
39
39
|
[type, preferred_delimiters_config[type] ||
|
40
40
|
preferred_delimiters_config['default']]
|
41
|
-
end
|
41
|
+
end.to_h
|
42
42
|
else
|
43
43
|
preferred_delimiters_config
|
44
44
|
end
|
@@ -10,8 +10,13 @@ module RuboCop
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
+
# @!method empty_condition?(node)
|
13
14
|
def_node_matcher :empty_condition?, '(begin)'
|
15
|
+
|
16
|
+
# @!method setter_method?(node)
|
14
17
|
def_node_matcher :setter_method?, '[(send ...) setter_method?]'
|
18
|
+
|
19
|
+
# @!method safe_assignment?(node)
|
15
20
|
def_node_matcher :safe_assignment?,
|
16
21
|
'(begin {equals_asgn? #setter_method?})'
|
17
22
|
|
@@ -53,12 +53,10 @@ module RuboCop
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def name_type(node)
|
56
|
-
@name_type ||=
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
56
|
+
@name_type ||= case node.type
|
57
|
+
when :block then 'block parameter'
|
58
|
+
when :def, :defs then 'method parameter'
|
59
|
+
end
|
62
60
|
end
|
63
61
|
|
64
62
|
def num_offense(node, range)
|
@@ -22,6 +22,7 @@ module RuboCop
|
|
22
22
|
OP_LIKE_METHODS = %i[eql? equal?].freeze
|
23
23
|
EXCLUDED = %i[+@ -@ [] []= << === ` =~].freeze
|
24
24
|
|
25
|
+
# @!method op_method_candidate?(node)
|
25
26
|
def_node_matcher :op_method_candidate?, <<~PATTERN
|
26
27
|
(def [#op_method? $_] (args $(arg [!:other !:_other])) _)
|
27
28
|
PATTERN
|
@@ -23,6 +23,7 @@ module RuboCop
|
|
23
23
|
# than just standard ASCII characters
|
24
24
|
SNAKE_CASE = /^[[:digit:][:upper:]_]+$/.freeze
|
25
25
|
|
26
|
+
# @!method class_or_struct_return_method?(node)
|
26
27
|
def_node_matcher :class_or_struct_return_method?, <<~PATTERN
|
27
28
|
(send
|
28
29
|
(const _ {:Class :Struct}) :new
|
@@ -64,6 +65,7 @@ module RuboCop
|
|
64
65
|
(node.receiver.nil? || !literal_receiver?(node))
|
65
66
|
end
|
66
67
|
|
68
|
+
# @!method literal_receiver?(node)
|
67
69
|
def_node_matcher :literal_receiver?, <<~PATTERN
|
68
70
|
{(send literal? ...)
|
69
71
|
(send (begin literal?) ...)}
|
@@ -139,6 +139,10 @@ module RuboCop
|
|
139
139
|
# define_method(:foo) do
|
140
140
|
# @_foo ||= calculate_expensive_thing
|
141
141
|
# end
|
142
|
+
#
|
143
|
+
# This cop relies on the pattern `@instance_var ||= ...`,
|
144
|
+
# but this is sometimes used for other purposes than memoization
|
145
|
+
# so this cop is considered unsafe.
|
142
146
|
class MemoizedInstanceVariableName < Base
|
143
147
|
include ConfigurableEnforcedStyle
|
144
148
|
|
@@ -148,6 +152,7 @@ module RuboCop
|
|
148
152
|
'with `_`. Use `@%<suggested_var>s` instead.'
|
149
153
|
DYNAMIC_DEFINE_METHODS = %i[define_method define_singleton_method].to_set.freeze
|
150
154
|
|
155
|
+
# @!method method_definition?(node)
|
151
156
|
def_node_matcher :method_definition?, <<~PATTERN
|
152
157
|
${
|
153
158
|
(block (send _ %DYNAMIC_DEFINE_METHODS ({sym str} $_)) ...)
|
@@ -179,6 +184,7 @@ module RuboCop
|
|
179
184
|
end
|
180
185
|
# rubocop:enable Metrics/AbcSize
|
181
186
|
|
187
|
+
# @!method defined_memoized?(node, ivar)
|
182
188
|
def_node_matcher :defined_memoized?, <<~PATTERN
|
183
189
|
(begin
|
184
190
|
(if (defined $(ivar %1)) (return $(ivar %1)) nil?)
|
@@ -9,6 +9,11 @@ module RuboCop
|
|
9
9
|
# The `PreferredName` config option takes a `String`. It represents
|
10
10
|
# the required name of the variable. Its default is `e`.
|
11
11
|
#
|
12
|
+
# NOTE: This cop does not consider nested rescues because it cannot
|
13
|
+
# guarantee that the variable from the outer rescue is not used within
|
14
|
+
# the inner rescue (in which case, changing the inner variable would
|
15
|
+
# shadow the outer variable).
|
16
|
+
#
|
12
17
|
# @example PreferredName: e (default)
|
13
18
|
# # bad
|
14
19
|
# begin
|
@@ -62,6 +67,11 @@ module RuboCop
|
|
62
67
|
offending_name = variable_name(node)
|
63
68
|
return unless offending_name
|
64
69
|
|
70
|
+
# Handle nested rescues by only requiring the outer one to use the
|
71
|
+
# configured variable name, so that nested rescues don't use the same
|
72
|
+
# variable.
|
73
|
+
return if node.each_ancestor(:resbody).any?
|
74
|
+
|
65
75
|
preferred_name = preferred_name(offending_name)
|
66
76
|
return if preferred_name.to_sym == offending_name
|
67
77
|
|
data/lib/rubocop/cop/registry.rb
CHANGED
@@ -64,6 +64,11 @@ module RuboCop
|
|
64
64
|
with(without_department.values.flatten)
|
65
65
|
end
|
66
66
|
|
67
|
+
# @return [Boolean] Checks if given name is department
|
68
|
+
def department?(name)
|
69
|
+
departments.include? name.to_sym
|
70
|
+
end
|
71
|
+
|
67
72
|
def contains_cop_matching?(names)
|
68
73
|
cops.any? { |cop| cop.match?(names) }
|
69
74
|
end
|
@@ -179,13 +184,17 @@ module RuboCop
|
|
179
184
|
cops.map(&:cop_name)
|
180
185
|
end
|
181
186
|
|
187
|
+
def names_for_department(department)
|
188
|
+
cops.select { |cop| cop.department == department.to_sym }.map(&:cop_name)
|
189
|
+
end
|
190
|
+
|
182
191
|
def ==(other)
|
183
192
|
cops == other.cops
|
184
193
|
end
|
185
194
|
|
186
195
|
def sort!
|
187
196
|
clear_enrollment_queue
|
188
|
-
@registry =
|
197
|
+
@registry = @registry.sort_by { |badge, _| badge.cop_name }.to_h
|
189
198
|
|
190
199
|
self
|
191
200
|
end
|