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
data/lib/rubocop.rb
CHANGED
@@ -16,6 +16,7 @@ require 'unicode/display_width'
|
|
16
16
|
require_relative 'rubocop/version'
|
17
17
|
|
18
18
|
require_relative 'rubocop/path_util'
|
19
|
+
require_relative 'rubocop/file_finder'
|
19
20
|
require_relative 'rubocop/platform'
|
20
21
|
require_relative 'rubocop/string_util'
|
21
22
|
require_relative 'rubocop/name_similarity'
|
@@ -101,7 +102,8 @@ require_relative 'rubocop/cop/mixin/configurable_numbering'
|
|
101
102
|
require_relative 'rubocop/cop/mixin/def_node'
|
102
103
|
require_relative 'rubocop/cop/mixin/documentation_comment'
|
103
104
|
require_relative 'rubocop/cop/mixin/duplication'
|
104
|
-
require_relative 'rubocop/cop/mixin/
|
105
|
+
require_relative 'rubocop/cop/mixin/range_help'
|
106
|
+
require_relative 'rubocop/cop/mixin/empty_lines_around_body' # relies on range
|
105
107
|
require_relative 'rubocop/cop/mixin/empty_parameter'
|
106
108
|
require_relative 'rubocop/cop/mixin/end_keyword_alignment'
|
107
109
|
require_relative 'rubocop/cop/mixin/enforce_superclass'
|
@@ -118,6 +120,7 @@ require_relative 'rubocop/cop/mixin/multiline_expression_indentation'
|
|
118
120
|
require_relative 'rubocop/cop/mixin/multiline_literal_brace_layout'
|
119
121
|
require_relative 'rubocop/cop/mixin/negative_conditional'
|
120
122
|
require_relative 'rubocop/cop/mixin/heredoc'
|
123
|
+
require_relative 'rubocop/cop/mixin/nil_methods'
|
121
124
|
require_relative 'rubocop/cop/mixin/on_normal_if_unless'
|
122
125
|
require_relative 'rubocop/cop/mixin/ordered_gem_node'
|
123
126
|
require_relative 'rubocop/cop/mixin/parentheses'
|
@@ -137,12 +140,15 @@ require_relative 'rubocop/cop/mixin/string_literals_help'
|
|
137
140
|
require_relative 'rubocop/cop/mixin/target_ruby_version'
|
138
141
|
require_relative 'rubocop/cop/mixin/target_rails_version'
|
139
142
|
require_relative 'rubocop/cop/mixin/too_many_lines'
|
143
|
+
require_relative 'rubocop/cop/mixin/trailing_body'
|
140
144
|
require_relative 'rubocop/cop/mixin/trailing_comma'
|
145
|
+
require_relative 'rubocop/cop/mixin/uncommunicative_name'
|
141
146
|
require_relative 'rubocop/cop/mixin/unused_argument'
|
142
147
|
|
143
148
|
require_relative 'rubocop/cop/correctors/alignment_corrector'
|
144
149
|
require_relative 'rubocop/cop/correctors/condition_corrector'
|
145
150
|
require_relative 'rubocop/cop/correctors/empty_line_corrector'
|
151
|
+
require_relative 'rubocop/cop/correctors/line_break_corrector'
|
146
152
|
require_relative 'rubocop/cop/correctors/multiline_literal_brace_corrector'
|
147
153
|
require_relative 'rubocop/cop/correctors/ordered_gem_corrector'
|
148
154
|
require_relative 'rubocop/cop/correctors/parentheses_corrector'
|
@@ -163,13 +169,17 @@ require_relative 'rubocop/cop/layout/access_modifier_indentation'
|
|
163
169
|
require_relative 'rubocop/cop/layout/align_array'
|
164
170
|
require_relative 'rubocop/cop/layout/align_hash'
|
165
171
|
require_relative 'rubocop/cop/layout/align_parameters'
|
172
|
+
require_relative 'rubocop/cop/layout/block_alignment'
|
166
173
|
require_relative 'rubocop/cop/layout/block_end_newline'
|
167
174
|
require_relative 'rubocop/cop/layout/case_indentation'
|
168
175
|
require_relative 'rubocop/cop/layout/class_structure'
|
169
176
|
require_relative 'rubocop/cop/layout/closing_parenthesis_indentation'
|
170
177
|
require_relative 'rubocop/cop/layout/comment_indentation'
|
178
|
+
require_relative 'rubocop/cop/layout/condition_position'
|
179
|
+
require_relative 'rubocop/cop/layout/def_end_alignment'
|
171
180
|
require_relative 'rubocop/cop/layout/dot_position'
|
172
181
|
require_relative 'rubocop/cop/layout/else_alignment'
|
182
|
+
require_relative 'rubocop/cop/layout/empty_comment'
|
173
183
|
require_relative 'rubocop/cop/layout/empty_line_after_magic_comment'
|
174
184
|
require_relative 'rubocop/cop/layout/empty_line_between_defs'
|
175
185
|
require_relative 'rubocop/cop/layout/empty_lines_around_access_modifier'
|
@@ -181,6 +191,7 @@ require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywo
|
|
181
191
|
require_relative 'rubocop/cop/layout/empty_lines_around_method_body'
|
182
192
|
require_relative 'rubocop/cop/layout/empty_lines_around_module_body'
|
183
193
|
require_relative 'rubocop/cop/layout/empty_lines'
|
194
|
+
require_relative 'rubocop/cop/layout/end_alignment'
|
184
195
|
require_relative 'rubocop/cop/layout/end_of_line'
|
185
196
|
require_relative 'rubocop/cop/layout/extra_spacing'
|
186
197
|
require_relative 'rubocop/cop/layout/first_array_element_line_break'
|
@@ -237,12 +248,10 @@ require_relative 'rubocop/cop/lint/ambiguous_block_association'
|
|
237
248
|
require_relative 'rubocop/cop/lint/ambiguous_operator'
|
238
249
|
require_relative 'rubocop/cop/lint/ambiguous_regexp_literal'
|
239
250
|
require_relative 'rubocop/cop/lint/assignment_in_condition'
|
240
|
-
require_relative 'rubocop/cop/lint/
|
251
|
+
require_relative 'rubocop/cop/lint/big_decimal_new'
|
241
252
|
require_relative 'rubocop/cop/lint/boolean_symbol'
|
242
253
|
require_relative 'rubocop/cop/lint/circular_argument_reference'
|
243
|
-
require_relative 'rubocop/cop/lint/condition_position'
|
244
254
|
require_relative 'rubocop/cop/lint/debugger'
|
245
|
-
require_relative 'rubocop/cop/lint/def_end_alignment'
|
246
255
|
require_relative 'rubocop/cop/lint/deprecated_class_methods'
|
247
256
|
require_relative 'rubocop/cop/lint/duplicate_case_condition'
|
248
257
|
require_relative 'rubocop/cop/lint/duplicate_methods'
|
@@ -253,7 +262,6 @@ require_relative 'rubocop/cop/lint/empty_ensure'
|
|
253
262
|
require_relative 'rubocop/cop/lint/empty_expression'
|
254
263
|
require_relative 'rubocop/cop/lint/empty_interpolation'
|
255
264
|
require_relative 'rubocop/cop/lint/empty_when'
|
256
|
-
require_relative 'rubocop/cop/lint/end_alignment'
|
257
265
|
require_relative 'rubocop/cop/lint/end_in_method'
|
258
266
|
require_relative 'rubocop/cop/lint/ensure_return'
|
259
267
|
require_relative 'rubocop/cop/lint/float_out_of_range'
|
@@ -272,6 +280,8 @@ require_relative 'rubocop/cop/lint/nested_method_definition'
|
|
272
280
|
require_relative 'rubocop/cop/lint/nested_percent_literal'
|
273
281
|
require_relative 'rubocop/cop/lint/next_without_accumulator'
|
274
282
|
require_relative 'rubocop/cop/lint/non_local_exit_from_iterator'
|
283
|
+
require_relative 'rubocop/cop/lint/number_conversion'
|
284
|
+
require_relative 'rubocop/cop/lint/ordered_magic_comments'
|
275
285
|
require_relative 'rubocop/cop/lint/parentheses_as_grouped_expression'
|
276
286
|
require_relative 'rubocop/cop/lint/percent_string_array'
|
277
287
|
require_relative 'rubocop/cop/lint/percent_symbol_array'
|
@@ -292,7 +302,8 @@ require_relative 'rubocop/cop/lint/string_conversion_in_interpolation'
|
|
292
302
|
require_relative 'rubocop/cop/lint/syntax'
|
293
303
|
require_relative 'rubocop/cop/lint/underscore_prefixed_variable_name'
|
294
304
|
require_relative 'rubocop/cop/lint/unified_integer'
|
295
|
-
require_relative 'rubocop/cop/lint/
|
305
|
+
require_relative 'rubocop/cop/lint/unneeded_cop_disable_directive'
|
306
|
+
require_relative 'rubocop/cop/lint/unneeded_cop_enable_directive'
|
296
307
|
require_relative 'rubocop/cop/lint/unneeded_require_statement'
|
297
308
|
require_relative 'rubocop/cop/lint/unneeded_splat_expansion'
|
298
309
|
require_relative 'rubocop/cop/lint/unreachable_code'
|
@@ -326,9 +337,12 @@ require_relative 'rubocop/cop/naming/constant_name'
|
|
326
337
|
require_relative 'rubocop/cop/naming/file_name'
|
327
338
|
require_relative 'rubocop/cop/naming/heredoc_delimiter_case'
|
328
339
|
require_relative 'rubocop/cop/naming/heredoc_delimiter_naming'
|
340
|
+
require_relative 'rubocop/cop/naming/memoized_instance_variable_name'
|
329
341
|
require_relative 'rubocop/cop/naming/method_name'
|
330
342
|
require_relative 'rubocop/cop/naming/binary_operator_parameter_name'
|
331
343
|
require_relative 'rubocop/cop/naming/predicate_name'
|
344
|
+
require_relative 'rubocop/cop/naming/uncommunicative_block_param_name'
|
345
|
+
require_relative 'rubocop/cop/naming/uncommunicative_method_param_name'
|
332
346
|
require_relative 'rubocop/cop/naming/variable_name'
|
333
347
|
require_relative 'rubocop/cop/naming/variable_number'
|
334
348
|
|
@@ -341,7 +355,6 @@ require_relative 'rubocop/cop/performance/double_start_end_with'
|
|
341
355
|
require_relative 'rubocop/cop/performance/end_with'
|
342
356
|
require_relative 'rubocop/cop/performance/fixed_size'
|
343
357
|
require_relative 'rubocop/cop/performance/flat_map'
|
344
|
-
require_relative 'rubocop/cop/performance/hash_each_methods'
|
345
358
|
require_relative 'rubocop/cop/performance/lstrip_rstrip'
|
346
359
|
require_relative 'rubocop/cop/performance/range_include'
|
347
360
|
require_relative 'rubocop/cop/performance/redundant_block_call'
|
@@ -396,12 +409,14 @@ require_relative 'rubocop/cop/style/empty_block_parameter'
|
|
396
409
|
require_relative 'rubocop/cop/style/empty_case_condition'
|
397
410
|
require_relative 'rubocop/cop/style/empty_else'
|
398
411
|
require_relative 'rubocop/cop/style/empty_lambda_parameter'
|
412
|
+
require_relative 'rubocop/cop/style/empty_line_after_guard_clause'
|
399
413
|
require_relative 'rubocop/cop/style/empty_literal'
|
400
414
|
require_relative 'rubocop/cop/style/empty_method'
|
401
415
|
require_relative 'rubocop/cop/style/encoding'
|
402
416
|
require_relative 'rubocop/cop/style/end_block'
|
403
417
|
require_relative 'rubocop/cop/style/eval_with_location'
|
404
418
|
require_relative 'rubocop/cop/style/even_odd'
|
419
|
+
require_relative 'rubocop/cop/style/expand_path_arguments'
|
405
420
|
require_relative 'rubocop/cop/style/flip_flop'
|
406
421
|
require_relative 'rubocop/cop/style/for'
|
407
422
|
require_relative 'rubocop/cop/style/format_string'
|
@@ -494,9 +509,12 @@ require_relative 'rubocop/cop/style/symbol_array'
|
|
494
509
|
require_relative 'rubocop/cop/style/symbol_literal'
|
495
510
|
require_relative 'rubocop/cop/style/symbol_proc'
|
496
511
|
require_relative 'rubocop/cop/style/ternary_parentheses'
|
512
|
+
require_relative 'rubocop/cop/style/trailing_body_on_class'
|
497
513
|
require_relative 'rubocop/cop/style/trailing_body_on_method_definition'
|
514
|
+
require_relative 'rubocop/cop/style/trailing_body_on_module'
|
498
515
|
require_relative 'rubocop/cop/style/trailing_comma_in_arguments'
|
499
|
-
require_relative 'rubocop/cop/style/
|
516
|
+
require_relative 'rubocop/cop/style/trailing_comma_in_array_literal'
|
517
|
+
require_relative 'rubocop/cop/style/trailing_comma_in_hash_literal'
|
500
518
|
require_relative 'rubocop/cop/style/trailing_method_end_statement'
|
501
519
|
require_relative 'rubocop/cop/style/trailing_underscore_variable'
|
502
520
|
require_relative 'rubocop/cop/style/trivial_accessors'
|
@@ -513,6 +531,7 @@ require_relative 'rubocop/cop/style/yoda_condition'
|
|
513
531
|
require_relative 'rubocop/cop/style/zero_length_predicate'
|
514
532
|
|
515
533
|
require_relative 'rubocop/cop/rails/action_filter'
|
534
|
+
require_relative 'rubocop/cop/rails/active_record_aliases'
|
516
535
|
require_relative 'rubocop/cop/rails/active_support_aliases'
|
517
536
|
require_relative 'rubocop/cop/rails/application_job'
|
518
537
|
require_relative 'rubocop/cop/rails/application_record'
|
@@ -556,6 +575,7 @@ require_relative 'rubocop/cop/rails/validation'
|
|
556
575
|
require_relative 'rubocop/cop/security/eval'
|
557
576
|
require_relative 'rubocop/cop/security/json_load'
|
558
577
|
require_relative 'rubocop/cop/security/marshal_load'
|
578
|
+
require_relative 'rubocop/cop/security/open'
|
559
579
|
require_relative 'rubocop/cop/security/yaml_load'
|
560
580
|
|
561
581
|
require_relative 'rubocop/cop/team'
|
data/lib/rubocop/ast/builder.rb
CHANGED
@@ -2,41 +2,49 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module AST
|
5
|
-
# `RuboCop::Builder` is an AST builder that is utilized to let `Parser`
|
5
|
+
# `RuboCop::AST::Builder` is an AST builder that is utilized to let `Parser`
|
6
6
|
# generate ASTs with {RuboCop::AST::Node}.
|
7
7
|
#
|
8
8
|
# @example
|
9
9
|
# buffer = Parser::Source::Buffer.new('(string)')
|
10
10
|
# buffer.source = 'puts :foo'
|
11
11
|
#
|
12
|
-
# builder = RuboCop::Builder.new
|
13
|
-
# parser
|
12
|
+
# builder = RuboCop::AST::Builder.new
|
13
|
+
# require 'parser/ruby25'
|
14
|
+
# parser = Parser::Ruby25.new(builder)
|
14
15
|
# root_node = parser.parse(buffer)
|
15
16
|
class Builder < Parser::Builders::Default
|
16
17
|
NODE_MAP = {
|
17
|
-
AndNode
|
18
|
-
ArgsNode
|
19
|
-
ArrayNode
|
20
|
-
BlockNode
|
21
|
-
CaseNode
|
22
|
-
DefNode
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
18
|
+
and: AndNode,
|
19
|
+
args: ArgsNode,
|
20
|
+
array: ArrayNode,
|
21
|
+
block: BlockNode,
|
22
|
+
case: CaseNode,
|
23
|
+
def: DefNode,
|
24
|
+
defs: DefNode,
|
25
|
+
ensure: EnsureNode,
|
26
|
+
for: ForNode,
|
27
|
+
hash: HashNode,
|
28
|
+
if: IfNode,
|
29
|
+
kwsplat: KeywordSplatNode,
|
30
|
+
or: OrNode,
|
31
|
+
pair: PairNode,
|
32
|
+
regexp: RegexpNode,
|
33
|
+
resbody: ResbodyNode,
|
34
|
+
csend: SendNode,
|
35
|
+
send: SendNode,
|
36
|
+
str: StrNode,
|
37
|
+
dstr: StrNode,
|
38
|
+
xstr: StrNode,
|
39
|
+
super: SuperNode,
|
40
|
+
zsuper: SuperNode,
|
41
|
+
sym: SymbolNode,
|
42
|
+
until: UntilNode,
|
43
|
+
until_post: UntilNode,
|
44
|
+
when: WhenNode,
|
45
|
+
while: WhileNode,
|
46
|
+
while_post: WhileNode,
|
47
|
+
yield: YieldNode
|
40
48
|
}.freeze
|
41
49
|
|
42
50
|
# Generates {Node} from the given information.
|
@@ -55,17 +63,7 @@ module RuboCop
|
|
55
63
|
private
|
56
64
|
|
57
65
|
def node_klass(type)
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
# Take the human readable constant and generate a hash map where each
|
62
|
-
# (mapped) node type is a key with its constant as the value.
|
63
|
-
def node_map
|
64
|
-
@node_map ||= begin
|
65
|
-
NODE_MAP.each_pair.each_with_object({}) do |(klass, types), map|
|
66
|
-
types.each { |type| map[type] = klass }
|
67
|
-
end
|
68
|
-
end
|
66
|
+
NODE_MAP[type] || Node
|
69
67
|
end
|
70
68
|
end
|
71
69
|
end
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -100,7 +100,8 @@ module RuboCop
|
|
100
100
|
# part of it is changed.
|
101
101
|
def updated(type = nil, children = nil, properties = {})
|
102
102
|
properties[:location] ||= @location
|
103
|
-
|
103
|
+
klass = RuboCop::AST::Builder::NODE_MAP[type || @type] || Node
|
104
|
+
klass.new(type || @type, children || @children, properties)
|
104
105
|
end
|
105
106
|
|
106
107
|
# Returns the index of the receiver node in its siblings. (Sibling index
|
@@ -111,6 +112,16 @@ module RuboCop
|
|
111
112
|
parent.children.index { |sibling| sibling.equal?(self) }
|
112
113
|
end
|
113
114
|
|
115
|
+
# Common destructuring method. This can be used to normalize
|
116
|
+
# destructuring for different variations of the node.
|
117
|
+
# Some node types override this with their own custom
|
118
|
+
# destructuring method.
|
119
|
+
#
|
120
|
+
# @return [Array<Node>] the different parts of the ndde
|
121
|
+
def node_parts
|
122
|
+
to_a
|
123
|
+
end
|
124
|
+
|
114
125
|
# Calls the given block for each ancestor node from parent to root.
|
115
126
|
# If no block is given, an `Enumerator` is returned.
|
116
127
|
#
|
@@ -453,6 +464,10 @@ module RuboCop
|
|
453
464
|
source_range.begin_pos != loc.selector.begin_pos
|
454
465
|
end
|
455
466
|
|
467
|
+
def parenthesized_call?
|
468
|
+
loc.begin && loc.begin.is?('(')
|
469
|
+
end
|
470
|
+
|
456
471
|
def chained?
|
457
472
|
return false unless argument?
|
458
473
|
|
@@ -24,14 +24,6 @@ module RuboCop
|
|
24
24
|
def inverse_operator
|
25
25
|
logical_operator? ? LOGICAL_OR : SEMANTIC_OR
|
26
26
|
end
|
27
|
-
|
28
|
-
# Custom destructuring method. This can be used to normalize
|
29
|
-
# destructuring for different variations of the node.
|
30
|
-
#
|
31
|
-
# @return [Array<Node>] the different parts of the `and` predicate
|
32
|
-
def node_parts
|
33
|
-
to_a
|
34
|
-
end
|
35
27
|
end
|
36
28
|
end
|
37
29
|
end
|
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# A `block` node is essentially a method send with a block. Parser nests
|
10
10
|
# the `send` node inside the `block` node.
|
11
11
|
class BlockNode < Node
|
12
|
-
VOID_CONTEXT_METHODS = %i[each].freeze
|
12
|
+
VOID_CONTEXT_METHODS = %i[each tap].freeze
|
13
13
|
|
14
14
|
# The `send` node associated with this block.
|
15
15
|
#
|
@@ -103,14 +103,6 @@ module RuboCop
|
|
103
103
|
def void_context?
|
104
104
|
VOID_CONTEXT_METHODS.include?(send_node.method_name)
|
105
105
|
end
|
106
|
-
|
107
|
-
# Custom destructuring method. This can be used to normalize
|
108
|
-
# destructuring for different variations of the node.
|
109
|
-
#
|
110
|
-
# @return [Array] the different parts of the `block` node
|
111
|
-
def node_parts
|
112
|
-
to_a
|
113
|
-
end
|
114
106
|
end
|
115
107
|
end
|
116
108
|
end
|
@@ -51,14 +51,6 @@ module RuboCop
|
|
51
51
|
def else?
|
52
52
|
loc.else
|
53
53
|
end
|
54
|
-
|
55
|
-
# Custom destructuring method. This can be used to normalize
|
56
|
-
# destructuring for different variations of the node.
|
57
|
-
#
|
58
|
-
# @return [Array<Node>] the different parts of the `case` statement
|
59
|
-
def node_parts
|
60
|
-
to_a
|
61
|
-
end
|
62
54
|
end
|
63
55
|
end
|
64
56
|
end
|
@@ -12,14 +12,6 @@ module RuboCop
|
|
12
12
|
def body
|
13
13
|
node_parts[1]
|
14
14
|
end
|
15
|
-
|
16
|
-
# Custom destructuring method. This can be used to normalize
|
17
|
-
# destructuring for different variations of the node.
|
18
|
-
#
|
19
|
-
# @return [Array<Node>] the different parts of the `ensure` statement
|
20
|
-
def node_parts
|
21
|
-
to_a
|
22
|
-
end
|
23
15
|
end
|
24
16
|
end
|
25
17
|
end
|
@@ -48,14 +48,6 @@ module RuboCop
|
|
48
48
|
def body
|
49
49
|
node_parts[2]
|
50
50
|
end
|
51
|
-
|
52
|
-
# Custom destructuring method. This can be used to normalize
|
53
|
-
# destructuring for different variations of the node.
|
54
|
-
#
|
55
|
-
# @return [Array<Node>] the different parts of the `until` statement
|
56
|
-
def node_parts
|
57
|
-
to_a
|
58
|
-
end
|
59
51
|
end
|
60
52
|
end
|
61
53
|
end
|
@@ -24,14 +24,6 @@ module RuboCop
|
|
24
24
|
def inverse_operator
|
25
25
|
logical_operator? ? LOGICAL_AND : SEMANTIC_AND
|
26
26
|
end
|
27
|
-
|
28
|
-
# Custom destructuring method. This can be used to normalize
|
29
|
-
# destructuring for different variations of the node.
|
30
|
-
#
|
31
|
-
# @return [Array<Node>] the different parts of the `or` predicate
|
32
|
-
def node_parts
|
33
|
-
to_a
|
34
|
-
end
|
35
27
|
end
|
36
28
|
end
|
37
29
|
end
|
@@ -51,14 +51,6 @@ module RuboCop
|
|
51
51
|
hash_rocket? ? COLON : HASH_ROCKET
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
55
|
-
# Custom destructuring method. This is used to normalize the branches
|
56
|
-
# for `pair` and `kwsplat` nodes, to add duck typing to `hash` elements.
|
57
|
-
#
|
58
|
-
# @return [Array<Node>] the different parts of the `pair`
|
59
|
-
def node_parts
|
60
|
-
to_a
|
61
|
-
end
|
62
54
|
end
|
63
55
|
end
|
64
56
|
end
|
@@ -12,14 +12,6 @@ module RuboCop
|
|
12
12
|
def body
|
13
13
|
node_parts[2]
|
14
14
|
end
|
15
|
-
|
16
|
-
# Custom destructuring method. This can be used to normalize
|
17
|
-
# destructuring for different variations of the node.
|
18
|
-
#
|
19
|
-
# @return [Array<Node>] the different parts of the `resbody` statement
|
20
|
-
def node_parts
|
21
|
-
to_a
|
22
|
-
end
|
23
15
|
end
|
24
16
|
end
|
25
17
|
end
|
@@ -10,14 +10,6 @@ module RuboCop
|
|
10
10
|
include MethodDispatchNode
|
11
11
|
ARROW = '->'.freeze
|
12
12
|
|
13
|
-
# Custom destructuring method. This can be used to normalize
|
14
|
-
# destructuring for different variations of the node.
|
15
|
-
#
|
16
|
-
# @return [Array] the different parts of the `send` node
|
17
|
-
def node_parts
|
18
|
-
to_a
|
19
|
-
end
|
20
|
-
|
21
13
|
# Checks whether this is a negation method, i.e. `!` or keyword `not`.
|
22
14
|
#
|
23
15
|
# @return [Boolean] whether this method is a negation method
|