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
@@ -20,6 +20,7 @@ module RuboCop
|
|
20
20
|
# var = "This is the #{ space } example"
|
21
21
|
class SpaceInsideStringInterpolation < Cop
|
22
22
|
include ConfigurableEnforcedStyle
|
23
|
+
include RangeHelp
|
23
24
|
|
24
25
|
NO_SPACE_MSG = 'Space inside string interpolation detected.'.freeze
|
25
26
|
SPACE_MSG = 'Missing space around string interpolation detected.'.freeze
|
@@ -6,23 +6,39 @@ module RuboCop
|
|
6
6
|
module Cop
|
7
7
|
module Layout
|
8
8
|
# This cop checks for tabs inside the source code.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# # This example uses a tab to indent bar.
|
13
|
+
# def foo
|
14
|
+
# bar
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# # This example uses spaces to indent bar.
|
19
|
+
# def foo
|
20
|
+
# bar
|
21
|
+
# end
|
22
|
+
#
|
9
23
|
class Tab < Cop
|
10
24
|
include Alignment
|
25
|
+
include RangeHelp
|
11
26
|
|
12
27
|
MSG = 'Tab detected.'.freeze
|
13
28
|
|
14
29
|
def investigate(processed_source)
|
15
|
-
|
30
|
+
str_ranges = string_literal_ranges(processed_source.ast)
|
16
31
|
|
17
|
-
processed_source.lines.
|
18
|
-
match = line.match(/^(
|
32
|
+
processed_source.lines.each.with_index(1) do |line, lineno|
|
33
|
+
match = line.match(/^([^\t]*)\t+/)
|
19
34
|
next unless match
|
20
|
-
|
35
|
+
prefix = match.captures[0]
|
36
|
+
col = prefix.length
|
37
|
+
next if in_string_literal?(str_ranges, lineno, col)
|
21
38
|
|
22
|
-
spaces = match.captures[0]
|
23
39
|
range = source_range(processed_source.buffer,
|
24
|
-
|
25
|
-
|
40
|
+
lineno,
|
41
|
+
col...match.end(0))
|
26
42
|
|
27
43
|
add_offense(range, location: range)
|
28
44
|
end
|
@@ -37,21 +53,31 @@ module RuboCop
|
|
37
53
|
|
38
54
|
private
|
39
55
|
|
40
|
-
|
56
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
57
|
+
def in_string_literal?(ranges, line, col)
|
58
|
+
ranges.any? do |range|
|
59
|
+
(range.line == line && range.column <= col) ||
|
60
|
+
(range.line < line && line < range.last_line) ||
|
61
|
+
(range.line != line && range.last_line == line &&
|
62
|
+
range.last_column >= col)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
66
|
+
|
67
|
+
def string_literal_ranges(ast)
|
41
68
|
# which lines start inside a string literal?
|
42
69
|
return [] if ast.nil?
|
43
70
|
|
44
|
-
ast.each_node(:str, :dstr).each_with_object(Set.new) do |str,
|
71
|
+
ast.each_node(:str, :dstr).each_with_object(Set.new) do |str, ranges|
|
45
72
|
loc = str.location
|
46
73
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
74
|
+
range = if str.heredoc?
|
75
|
+
loc.heredoc_body
|
76
|
+
else
|
77
|
+
loc.expression
|
78
|
+
end
|
53
79
|
|
54
|
-
|
80
|
+
ranges << range
|
55
81
|
end
|
56
82
|
end
|
57
83
|
end
|
@@ -5,12 +5,45 @@ module RuboCop
|
|
5
5
|
module Layout
|
6
6
|
# This cop looks for trailing blank lines and a final newline in the
|
7
7
|
# source code.
|
8
|
+
#
|
9
|
+
# @example EnforcedStyle: final_blank_line
|
10
|
+
# # `final_blank_line` looks for one blank line followed by a new line
|
11
|
+
# # at the end of files.
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# class Foo; end
|
15
|
+
# # EOF
|
16
|
+
#
|
17
|
+
# # bad
|
18
|
+
# class Foo; end # EOF
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# class Foo; end
|
22
|
+
#
|
23
|
+
# # EOF
|
24
|
+
#
|
25
|
+
# @example EnforcedStyle: final_newline (default)
|
26
|
+
# # `final_newline` looks for one newline at the end of files.
|
27
|
+
#
|
28
|
+
# # bad
|
29
|
+
# class Foo; end
|
30
|
+
#
|
31
|
+
# # EOF
|
32
|
+
#
|
33
|
+
# # bad
|
34
|
+
# class Foo; end # EOF
|
35
|
+
#
|
36
|
+
# # good
|
37
|
+
# class Foo; end
|
38
|
+
# # EOF
|
39
|
+
#
|
8
40
|
class TrailingBlankLines < Cop
|
9
41
|
include ConfigurableEnforcedStyle
|
42
|
+
include RangeHelp
|
10
43
|
|
11
44
|
def investigate(processed_source)
|
12
|
-
|
13
|
-
return if
|
45
|
+
buffer = processed_source.buffer
|
46
|
+
return if buffer.source.empty?
|
14
47
|
|
15
48
|
# The extra text that comes after the last token could be __END__
|
16
49
|
# followed by some data to read. If so, we don't check it because
|
@@ -18,13 +51,13 @@ module RuboCop
|
|
18
51
|
# number of newlines.
|
19
52
|
return if ends_in_end?(processed_source)
|
20
53
|
|
21
|
-
whitespace_at_end =
|
54
|
+
whitespace_at_end = buffer.source[/\s*\Z/]
|
22
55
|
blank_lines = whitespace_at_end.count("\n") - 1
|
23
56
|
wanted_blank_lines = style == :final_newline ? 0 : 1
|
24
57
|
|
25
58
|
return unless blank_lines != wanted_blank_lines
|
26
59
|
|
27
|
-
offense_detected(
|
60
|
+
offense_detected(buffer, wanted_blank_lines, blank_lines,
|
28
61
|
whitespace_at_end)
|
29
62
|
end
|
30
63
|
|
@@ -36,12 +69,12 @@ module RuboCop
|
|
36
69
|
|
37
70
|
private
|
38
71
|
|
39
|
-
def offense_detected(
|
72
|
+
def offense_detected(buffer, wanted_blank_lines, blank_lines,
|
40
73
|
whitespace_at_end)
|
41
|
-
begin_pos =
|
42
|
-
autocorrect_range = range_between(begin_pos,
|
74
|
+
begin_pos = buffer.source.length - whitespace_at_end.length
|
75
|
+
autocorrect_range = range_between(begin_pos, buffer.source.length)
|
43
76
|
begin_pos += 1 unless whitespace_at_end.empty?
|
44
|
-
report_range = range_between(begin_pos,
|
77
|
+
report_range = range_between(begin_pos, buffer.source.length)
|
45
78
|
|
46
79
|
add_offense(autocorrect_range,
|
47
80
|
location: report_range,
|
@@ -49,12 +82,12 @@ module RuboCop
|
|
49
82
|
end
|
50
83
|
|
51
84
|
def ends_in_end?(processed_source)
|
52
|
-
|
85
|
+
buffer = processed_source.buffer
|
53
86
|
|
54
|
-
return true if
|
87
|
+
return true if buffer.source.strip.start_with?('__END__')
|
55
88
|
return false if processed_source.tokens.empty?
|
56
89
|
|
57
|
-
extra =
|
90
|
+
extra = buffer.source[processed_source.tokens.last.end_pos..-1]
|
58
91
|
extra && extra.strip.start_with?('__END__')
|
59
92
|
end
|
60
93
|
|
@@ -70,8 +103,8 @@ module RuboCop
|
|
70
103
|
else
|
71
104
|
"instead of #{wanted_blank_lines} "
|
72
105
|
end
|
73
|
-
format('
|
74
|
-
instead_of)
|
106
|
+
format('%<current>d trailing blank lines %<prefer>sdetected.',
|
107
|
+
current: blank_lines, prefer: instead_of)
|
75
108
|
end
|
76
109
|
end
|
77
110
|
end
|
@@ -4,7 +4,19 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Layout
|
6
6
|
# This cop looks for trailing whitespace in the source code.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # The line in this example contains spaces after the 0.
|
10
|
+
# # bad
|
11
|
+
# x = 0
|
12
|
+
#
|
13
|
+
# # The line in this example ends directly after the 0.
|
14
|
+
# # good
|
15
|
+
# x = 0
|
16
|
+
#
|
7
17
|
class TrailingWhitespace < Cop
|
18
|
+
include RangeHelp
|
19
|
+
|
8
20
|
MSG = 'Trailing whitespace detected.'.freeze
|
9
21
|
|
10
22
|
def investigate(processed_source)
|
@@ -25,8 +25,9 @@ module RuboCop
|
|
25
25
|
# # Lambda arguments require no disambiguation
|
26
26
|
# foo = ->(bar) { bar.baz }
|
27
27
|
class AmbiguousBlockAssociation < Cop
|
28
|
-
MSG = 'Parenthesize the param
|
29
|
-
' associated with the
|
28
|
+
MSG = 'Parenthesize the param `%<param>s` to make sure that the ' \
|
29
|
+
'block will be associated with the `%<method>s` method ' \
|
30
|
+
'call.'.freeze
|
30
31
|
|
31
32
|
def on_send(node)
|
32
33
|
return if !node.arguments? || node.parenthesized? ||
|
@@ -51,7 +52,8 @@ module RuboCop
|
|
51
52
|
def message(send_node)
|
52
53
|
block_param = send_node.last_argument
|
53
54
|
|
54
|
-
format(MSG, block_param.source,
|
55
|
+
format(MSG, param: block_param.source,
|
56
|
+
method: block_param.send_node.source)
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# `BigDecimal.new()` is deprecated since BigDecimal 1.3.3.
|
7
|
+
# This cop identifies places where `BigDecimal.new()`
|
8
|
+
# can be replaced by `BigDecimal()`.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# BigDecimal.new(123.456, 3)
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# BigDecimal(123.456, 3)
|
16
|
+
#
|
17
|
+
class BigDecimalNew < Cop
|
18
|
+
MSG = '`%<double_colon>sBigDecimal.new()` is deprecated. ' \
|
19
|
+
'Use `%<double_colon>sBigDecimal()` instead.'.freeze
|
20
|
+
|
21
|
+
def_node_matcher :big_decimal_new, <<-PATTERN
|
22
|
+
(send
|
23
|
+
(const ${nil? cbase} :BigDecimal) :new ...)
|
24
|
+
PATTERN
|
25
|
+
|
26
|
+
def on_send(node)
|
27
|
+
return unless big_decimal_new(node) do |captured_value|
|
28
|
+
double_colon = captured_value ? '::' : ''
|
29
|
+
message = format(MSG, double_colon: double_colon)
|
30
|
+
|
31
|
+
add_offense(node, location: :selector, message: message)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def autocorrect(node)
|
36
|
+
lambda do |corrector|
|
37
|
+
corrector.remove(node.loc.selector)
|
38
|
+
corrector.remove(node.loc.dot)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -23,14 +23,14 @@ module RuboCop
|
|
23
23
|
# false
|
24
24
|
class BooleanSymbol < Cop
|
25
25
|
MSG = 'Symbol with a boolean name - ' \
|
26
|
-
'you probably meant to use
|
26
|
+
'you probably meant to use `%<boolean>s`.'.freeze
|
27
27
|
|
28
28
|
def_node_matcher :boolean_symbol?, '(sym {:true :false})'
|
29
29
|
|
30
30
|
def on_sym(node)
|
31
31
|
return unless boolean_symbol?(node)
|
32
32
|
|
33
|
-
add_offense(node, message: format(MSG, node.value))
|
33
|
+
add_offense(node, message: format(MSG, boolean: node.value))
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
# dry_ingredients.combine
|
49
49
|
# end
|
50
50
|
class CircularArgumentReference < Cop
|
51
|
-
MSG = 'Circular argument reference -
|
51
|
+
MSG = 'Circular argument reference - `%<arg_name>s`.'.freeze
|
52
52
|
|
53
53
|
def on_kwoptarg(node)
|
54
54
|
check_for_circular_argument_references(*node)
|
@@ -64,7 +64,7 @@ module RuboCop
|
|
64
64
|
return unless arg_value.lvar_type?
|
65
65
|
return unless arg_value.to_a == [arg_name]
|
66
66
|
|
67
|
-
add_offense(arg_value, message: format(MSG, arg_name))
|
67
|
+
add_offense(arg_value, message: format(MSG, arg_name: arg_name))
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -33,7 +33,7 @@ module RuboCop
|
|
33
33
|
# do_something
|
34
34
|
# end
|
35
35
|
class Debugger < Cop
|
36
|
-
MSG = 'Remove debugger entry point
|
36
|
+
MSG = 'Remove debugger entry point `%<source>s`.'.freeze
|
37
37
|
|
38
38
|
def_node_matcher :kernel?, <<-PATTERN
|
39
39
|
{
|
@@ -67,7 +67,7 @@ module RuboCop
|
|
67
67
|
private
|
68
68
|
|
69
69
|
def message(node)
|
70
|
-
format(MSG, node.source)
|
70
|
+
format(MSG, source: node.source)
|
71
71
|
end
|
72
72
|
|
73
73
|
def binding_irb?(node)
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
MSG = '
|
42
|
+
MSG = '`%<current>s` is deprecated in favor of `%<prefer>s`.'.freeze
|
43
43
|
DEPRECATED_METHODS_OBJECT = [
|
44
44
|
DeprecatedClassMethod.new(:File, :exists?, :exist?),
|
45
45
|
DeprecatedClassMethod.new(:Dir, :exists?, :exist?)
|
@@ -47,8 +47,8 @@ module RuboCop
|
|
47
47
|
|
48
48
|
def on_send(node)
|
49
49
|
check(node) do |data|
|
50
|
-
message = format(MSG, deprecated_method(data),
|
51
|
-
|
50
|
+
message = format(MSG, current: deprecated_method(data),
|
51
|
+
prefer: replacement_method(data))
|
52
52
|
|
53
53
|
add_offense(node, location: :selector, message: message)
|
54
54
|
end
|
@@ -82,7 +82,8 @@ module RuboCop
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def method_call(class_constant, method)
|
85
|
-
format('
|
85
|
+
format('%<constant>s.%<method>s', constant: class_constant,
|
86
|
+
method: method)
|
86
87
|
end
|
87
88
|
end
|
88
89
|
end
|
@@ -10,11 +10,11 @@ module RuboCop
|
|
10
10
|
#
|
11
11
|
# # bad
|
12
12
|
#
|
13
|
-
# def
|
13
|
+
# def foo
|
14
14
|
# 1
|
15
15
|
# end
|
16
16
|
#
|
17
|
-
# def
|
17
|
+
# def foo
|
18
18
|
# 2
|
19
19
|
# end
|
20
20
|
#
|
@@ -22,25 +22,36 @@ module RuboCop
|
|
22
22
|
#
|
23
23
|
# # bad
|
24
24
|
#
|
25
|
-
# def
|
25
|
+
# def foo
|
26
26
|
# 1
|
27
27
|
# end
|
28
28
|
#
|
29
|
-
# alias
|
29
|
+
# alias foo bar
|
30
30
|
#
|
31
31
|
# @example
|
32
32
|
#
|
33
33
|
# # good
|
34
34
|
#
|
35
|
-
# def
|
35
|
+
# def foo
|
36
36
|
# 1
|
37
37
|
# end
|
38
38
|
#
|
39
|
-
# def
|
39
|
+
# def bar
|
40
40
|
# 2
|
41
41
|
# end
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
#
|
45
|
+
# # good
|
46
|
+
#
|
47
|
+
# def foo
|
48
|
+
# 1
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# alias bar foo
|
42
52
|
class DuplicateMethods < Cop
|
43
|
-
MSG = 'Method
|
53
|
+
MSG = 'Method `%<method>s` is defined at both %<defined>s and ' \
|
54
|
+
'%<current>s.'.freeze
|
44
55
|
|
45
56
|
def initialize(config = nil, options = nil)
|
46
57
|
super
|
@@ -121,8 +132,8 @@ module RuboCop
|
|
121
132
|
end
|
122
133
|
|
123
134
|
def message_for_dup(node, method_name)
|
124
|
-
format(MSG, method_name, @definitions[method_name],
|
125
|
-
|
135
|
+
format(MSG, method: method_name, defined: @definitions[method_name],
|
136
|
+
current: source_location(node))
|
126
137
|
end
|
127
138
|
|
128
139
|
def found_instance_method(node, name)
|
@@ -20,8 +20,8 @@ module RuboCop
|
|
20
20
|
# format('A value: %s and another: %i', a_value, another)
|
21
21
|
class FormatParameterMismatch < Cop
|
22
22
|
# http://rubular.com/r/CvpbxkcTzy
|
23
|
-
MSG = "Number of arguments (
|
24
|
-
'fields (
|
23
|
+
MSG = "Number of arguments (%<arg_num>i) to `%<method>s` doesn't " \
|
24
|
+
'match the number of fields (%<field_num>i).'.freeze
|
25
25
|
FIELD_REGEX =
|
26
26
|
/(%(([\s#+-0\*]*)(\d*)?(\.\d+)?[bBdiouxXeEfgGaAcps]|%))/
|
27
27
|
NAMED_FIELD_REGEX = /%\{[_a-zA-Z][_a-zA-Z]+\}/
|
@@ -169,7 +169,8 @@ module RuboCop
|
|
169
169
|
|
170
170
|
method_name = node.method?(:%) ? 'String#%' : node.method_name
|
171
171
|
|
172
|
-
format(MSG, num_args_for_format, method_name,
|
172
|
+
format(MSG, arg_num: num_args_for_format, method: method_name,
|
173
|
+
field_num: num_expected_fields)
|
173
174
|
end
|
174
175
|
end
|
175
176
|
end
|