rubbycop 0.49.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +211 -0
- data/assets/logo.png +0 -0
- data/assets/output.html.erb +261 -0
- data/bin/rubbycop +17 -0
- data/config/default.yml +1548 -0
- data/config/disabled.yml +119 -0
- data/config/enabled.yml +1734 -0
- data/lib/rubbycop.rb +510 -0
- data/lib/rubbycop/ast/builder.rb +64 -0
- data/lib/rubbycop/ast/node.rb +610 -0
- data/lib/rubbycop/ast/node/and_node.rb +37 -0
- data/lib/rubbycop/ast/node/array_node.rb +48 -0
- data/lib/rubbycop/ast/node/case_node.rb +64 -0
- data/lib/rubbycop/ast/node/ensure_node.rb +25 -0
- data/lib/rubbycop/ast/node/for_node.rb +53 -0
- data/lib/rubbycop/ast/node/hash_node.rb +109 -0
- data/lib/rubbycop/ast/node/if_node.rb +138 -0
- data/lib/rubbycop/ast/node/keyword_splat_node.rb +45 -0
- data/lib/rubbycop/ast/node/mixin/binary_operator_node.rb +23 -0
- data/lib/rubbycop/ast/node/mixin/conditional_node.rb +45 -0
- data/lib/rubbycop/ast/node/mixin/hash_element_node.rb +125 -0
- data/lib/rubbycop/ast/node/mixin/modifier_node.rb +17 -0
- data/lib/rubbycop/ast/node/mixin/predicate_operator_node.rb +35 -0
- data/lib/rubbycop/ast/node/or_node.rb +37 -0
- data/lib/rubbycop/ast/node/pair_node.rb +64 -0
- data/lib/rubbycop/ast/node/resbody_node.rb +25 -0
- data/lib/rubbycop/ast/node/send_node.rb +209 -0
- data/lib/rubbycop/ast/node/until_node.rb +43 -0
- data/lib/rubbycop/ast/node/when_node.rb +61 -0
- data/lib/rubbycop/ast/node/while_node.rb +43 -0
- data/lib/rubbycop/ast/sexp.rb +16 -0
- data/lib/rubbycop/ast/traversal.rb +171 -0
- data/lib/rubbycop/cached_data.rb +63 -0
- data/lib/rubbycop/cli.rb +199 -0
- data/lib/rubbycop/comment_config.rb +155 -0
- data/lib/rubbycop/config.rb +444 -0
- data/lib/rubbycop/config_loader.rb +244 -0
- data/lib/rubbycop/config_loader_resolver.rb +43 -0
- data/lib/rubbycop/config_store.rb +48 -0
- data/lib/rubbycop/cop/autocorrect_logic.rb +26 -0
- data/lib/rubbycop/cop/badge.rb +73 -0
- data/lib/rubbycop/cop/bundler/duplicated_gem.rb +69 -0
- data/lib/rubbycop/cop/bundler/ordered_gems.rb +113 -0
- data/lib/rubbycop/cop/commissioner.rb +118 -0
- data/lib/rubbycop/cop/cop.rb +222 -0
- data/lib/rubbycop/cop/corrector.rb +135 -0
- data/lib/rubbycop/cop/force.rb +41 -0
- data/lib/rubbycop/cop/ignored_node.rb +38 -0
- data/lib/rubbycop/cop/layout/access_modifier_indentation.rb +109 -0
- data/lib/rubbycop/cop/layout/align_array.rb +35 -0
- data/lib/rubbycop/cop/layout/align_hash.rb +235 -0
- data/lib/rubbycop/cop/layout/align_parameters.rb +97 -0
- data/lib/rubbycop/cop/layout/block_end_newline.rb +56 -0
- data/lib/rubbycop/cop/layout/case_indentation.rb +163 -0
- data/lib/rubbycop/cop/layout/closing_parenthesis_indentation.rb +88 -0
- data/lib/rubbycop/cop/layout/comment_indentation.rb +71 -0
- data/lib/rubbycop/cop/layout/dot_position.rb +84 -0
- data/lib/rubbycop/cop/layout/else_alignment.rb +105 -0
- data/lib/rubbycop/cop/layout/empty_line_after_magic_comment.rb +63 -0
- data/lib/rubbycop/cop/layout/empty_line_between_defs.rb +143 -0
- data/lib/rubbycop/cop/layout/empty_lines.rb +60 -0
- data/lib/rubbycop/cop/layout/empty_lines_around_access_modifier.rb +90 -0
- data/lib/rubbycop/cop/layout/empty_lines_around_begin_body.rb +42 -0
- data/lib/rubbycop/cop/layout/empty_lines_around_block_body.rb +41 -0
- data/lib/rubbycop/cop/layout/empty_lines_around_class_body.rb +39 -0
- data/lib/rubbycop/cop/layout/empty_lines_around_exception_handling_keywords.rb +127 -0
- data/lib/rubbycop/cop/layout/empty_lines_around_method_body.rb +41 -0
- data/lib/rubbycop/cop/layout/empty_lines_around_module_body.rb +44 -0
- data/lib/rubbycop/cop/layout/end_of_line.rb +52 -0
- data/lib/rubbycop/cop/layout/extra_spacing.rb +237 -0
- data/lib/rubbycop/cop/layout/first_array_element_line_break.rb +41 -0
- data/lib/rubbycop/cop/layout/first_hash_element_line_break.rb +33 -0
- data/lib/rubbycop/cop/layout/first_method_argument_line_break.rb +49 -0
- data/lib/rubbycop/cop/layout/first_method_parameter_line_break.rb +42 -0
- data/lib/rubbycop/cop/layout/first_parameter_indentation.rb +109 -0
- data/lib/rubbycop/cop/layout/indent_array.rb +114 -0
- data/lib/rubbycop/cop/layout/indent_assignment.rb +42 -0
- data/lib/rubbycop/cop/layout/indent_hash.rb +134 -0
- data/lib/rubbycop/cop/layout/indent_heredoc.rb +173 -0
- data/lib/rubbycop/cop/layout/indentation_consistency.rb +51 -0
- data/lib/rubbycop/cop/layout/indentation_width.rb +303 -0
- data/lib/rubbycop/cop/layout/initial_indentation.rb +42 -0
- data/lib/rubbycop/cop/layout/leading_comment_space.rb +43 -0
- data/lib/rubbycop/cop/layout/multiline_array_brace_layout.rb +81 -0
- data/lib/rubbycop/cop/layout/multiline_assignment_layout.rb +88 -0
- data/lib/rubbycop/cop/layout/multiline_block_layout.rb +134 -0
- data/lib/rubbycop/cop/layout/multiline_hash_brace_layout.rb +81 -0
- data/lib/rubbycop/cop/layout/multiline_method_call_brace_layout.rb +97 -0
- data/lib/rubbycop/cop/layout/multiline_method_call_indentation.rb +215 -0
- data/lib/rubbycop/cop/layout/multiline_method_definition_brace_layout.rb +82 -0
- data/lib/rubbycop/cop/layout/multiline_operation_indentation.rb +89 -0
- data/lib/rubbycop/cop/layout/rescue_ensure_alignment.rb +86 -0
- data/lib/rubbycop/cop/layout/space_after_colon.rb +40 -0
- data/lib/rubbycop/cop/layout/space_after_comma.rb +21 -0
- data/lib/rubbycop/cop/layout/space_after_method_name.rb +37 -0
- data/lib/rubbycop/cop/layout/space_after_not.rb +38 -0
- data/lib/rubbycop/cop/layout/space_after_semicolon.rb +21 -0
- data/lib/rubbycop/cop/layout/space_around_block_parameters.rb +109 -0
- data/lib/rubbycop/cop/layout/space_around_equals_in_parameter_default.rb +68 -0
- data/lib/rubbycop/cop/layout/space_around_keyword.rb +224 -0
- data/lib/rubbycop/cop/layout/space_around_operators.rb +142 -0
- data/lib/rubbycop/cop/layout/space_before_block_braces.rb +54 -0
- data/lib/rubbycop/cop/layout/space_before_comma.rb +16 -0
- data/lib/rubbycop/cop/layout/space_before_comment.rb +27 -0
- data/lib/rubbycop/cop/layout/space_before_first_arg.rb +64 -0
- data/lib/rubbycop/cop/layout/space_before_semicolon.rb +16 -0
- data/lib/rubbycop/cop/layout/space_in_lambda_literal.rb +87 -0
- data/lib/rubbycop/cop/layout/space_inside_array_percent_literal.rb +53 -0
- data/lib/rubbycop/cop/layout/space_inside_block_braces.rb +158 -0
- data/lib/rubbycop/cop/layout/space_inside_brackets.rb +20 -0
- data/lib/rubbycop/cop/layout/space_inside_hash_literal_braces.rb +150 -0
- data/lib/rubbycop/cop/layout/space_inside_parens.rb +16 -0
- data/lib/rubbycop/cop/layout/space_inside_percent_literal_delimiters.rb +64 -0
- data/lib/rubbycop/cop/layout/space_inside_range_literal.rb +63 -0
- data/lib/rubbycop/cop/layout/space_inside_string_interpolation.rb +65 -0
- data/lib/rubbycop/cop/layout/tab.rb +57 -0
- data/lib/rubbycop/cop/layout/trailing_blank_lines.rb +78 -0
- data/lib/rubbycop/cop/layout/trailing_whitespace.rb +28 -0
- data/lib/rubbycop/cop/lint/ambiguous_block_association.rb +66 -0
- data/lib/rubbycop/cop/lint/ambiguous_operator.rb +55 -0
- data/lib/rubbycop/cop/lint/ambiguous_regexp_literal.rb +43 -0
- data/lib/rubbycop/cop/lint/assignment_in_condition.rb +80 -0
- data/lib/rubbycop/cop/lint/block_alignment.rb +229 -0
- data/lib/rubbycop/cop/lint/circular_argument_reference.rb +83 -0
- data/lib/rubbycop/cop/lint/condition_position.rb +52 -0
- data/lib/rubbycop/cop/lint/debugger.rb +72 -0
- data/lib/rubbycop/cop/lint/def_end_alignment.rb +78 -0
- data/lib/rubbycop/cop/lint/deprecated_class_methods.rb +90 -0
- data/lib/rubbycop/cop/lint/duplicate_case_condition.rb +53 -0
- data/lib/rubbycop/cop/lint/duplicate_methods.rb +151 -0
- data/lib/rubbycop/cop/lint/duplicated_key.rb +38 -0
- data/lib/rubbycop/cop/lint/each_with_object_argument.rb +39 -0
- data/lib/rubbycop/cop/lint/else_layout.rb +65 -0
- data/lib/rubbycop/cop/lint/empty_ensure.rb +60 -0
- data/lib/rubbycop/cop/lint/empty_expression.rb +42 -0
- data/lib/rubbycop/cop/lint/empty_interpolation.rb +36 -0
- data/lib/rubbycop/cop/lint/empty_when.rb +38 -0
- data/lib/rubbycop/cop/lint/end_alignment.rb +157 -0
- data/lib/rubbycop/cop/lint/end_in_method.rb +40 -0
- data/lib/rubbycop/cop/lint/ensure_return.rb +43 -0
- data/lib/rubbycop/cop/lint/float_out_of_range.rb +35 -0
- data/lib/rubbycop/cop/lint/format_parameter_mismatch.rb +182 -0
- data/lib/rubbycop/cop/lint/handle_exceptions.rb +56 -0
- data/lib/rubbycop/cop/lint/implicit_string_concatenation.rb +95 -0
- data/lib/rubbycop/cop/lint/ineffective_access_modifier.rb +143 -0
- data/lib/rubbycop/cop/lint/inherit_exception.rb +83 -0
- data/lib/rubbycop/cop/lint/invalid_character_literal.rb +41 -0
- data/lib/rubbycop/cop/lint/literal_in_condition.rb +127 -0
- data/lib/rubbycop/cop/lint/literal_in_interpolation.rb +76 -0
- data/lib/rubbycop/cop/lint/loop.rb +63 -0
- data/lib/rubbycop/cop/lint/multiple_compare.rb +48 -0
- data/lib/rubbycop/cop/lint/nested_method_definition.rb +105 -0
- data/lib/rubbycop/cop/lint/next_without_accumulator.rb +50 -0
- data/lib/rubbycop/cop/lint/non_local_exit_from_iterator.rb +85 -0
- data/lib/rubbycop/cop/lint/parentheses_as_grouped_expression.rb +60 -0
- data/lib/rubbycop/cop/lint/percent_string_array.rb +84 -0
- data/lib/rubbycop/cop/lint/percent_symbol_array.rb +66 -0
- data/lib/rubbycop/cop/lint/rand_one.rb +39 -0
- data/lib/rubbycop/cop/lint/require_parentheses.rb +61 -0
- data/lib/rubbycop/cop/lint/rescue_exception.rb +45 -0
- data/lib/rubbycop/cop/lint/safe_navigation_chain.rb +70 -0
- data/lib/rubbycop/cop/lint/shadowed_exception.rb +132 -0
- data/lib/rubbycop/cop/lint/shadowing_outer_local_variable.rb +53 -0
- data/lib/rubbycop/cop/lint/string_conversion_in_interpolation.rb +58 -0
- data/lib/rubbycop/cop/lint/syntax.rb +55 -0
- data/lib/rubbycop/cop/lint/underscore_prefixed_variable_name.rb +62 -0
- data/lib/rubbycop/cop/lint/unified_integer.rb +42 -0
- data/lib/rubbycop/cop/lint/unneeded_disable.rb +231 -0
- data/lib/rubbycop/cop/lint/unneeded_splat_expansion.rb +141 -0
- data/lib/rubbycop/cop/lint/unreachable_code.rb +52 -0
- data/lib/rubbycop/cop/lint/unused_block_argument.rb +145 -0
- data/lib/rubbycop/cop/lint/unused_method_argument.rb +61 -0
- data/lib/rubbycop/cop/lint/useless_access_modifier.rb +229 -0
- data/lib/rubbycop/cop/lint/useless_assignment.rb +132 -0
- data/lib/rubbycop/cop/lint/useless_comparison.rb +28 -0
- data/lib/rubbycop/cop/lint/useless_else_without_rescue.rb +46 -0
- data/lib/rubbycop/cop/lint/useless_setter_call.rb +162 -0
- data/lib/rubbycop/cop/lint/void.rb +108 -0
- data/lib/rubbycop/cop/message_annotator.rb +116 -0
- data/lib/rubbycop/cop/metrics/abc_size.rb +39 -0
- data/lib/rubbycop/cop/metrics/block_length.rb +32 -0
- data/lib/rubbycop/cop/metrics/block_nesting.rb +64 -0
- data/lib/rubbycop/cop/metrics/class_length.rb +24 -0
- data/lib/rubbycop/cop/metrics/cyclomatic_complexity.rb +31 -0
- data/lib/rubbycop/cop/metrics/line_length.rb +168 -0
- data/lib/rubbycop/cop/metrics/method_length.rb +27 -0
- data/lib/rubbycop/cop/metrics/module_length.rb +24 -0
- data/lib/rubbycop/cop/metrics/parameter_lists.rb +45 -0
- data/lib/rubbycop/cop/metrics/perceived_complexity.rb +61 -0
- data/lib/rubbycop/cop/mixin/access_modifier_node.rb +41 -0
- data/lib/rubbycop/cop/mixin/annotation_comment.rb +36 -0
- data/lib/rubbycop/cop/mixin/array_hash_indentation.rb +82 -0
- data/lib/rubbycop/cop/mixin/array_min_size.rb +59 -0
- data/lib/rubbycop/cop/mixin/array_syntax.rb +15 -0
- data/lib/rubbycop/cop/mixin/autocorrect_alignment.rb +149 -0
- data/lib/rubbycop/cop/mixin/check_assignment.rb +40 -0
- data/lib/rubbycop/cop/mixin/classish_length.rb +36 -0
- data/lib/rubbycop/cop/mixin/code_length.rb +32 -0
- data/lib/rubbycop/cop/mixin/configurable_enforced_style.rb +97 -0
- data/lib/rubbycop/cop/mixin/configurable_formatting.rb +48 -0
- data/lib/rubbycop/cop/mixin/configurable_max.rb +19 -0
- data/lib/rubbycop/cop/mixin/configurable_naming.rb +16 -0
- data/lib/rubbycop/cop/mixin/configurable_numbering.rb +17 -0
- data/lib/rubbycop/cop/mixin/def_node.rb +27 -0
- data/lib/rubbycop/cop/mixin/documentation_comment.rb +46 -0
- data/lib/rubbycop/cop/mixin/duplication.rb +46 -0
- data/lib/rubbycop/cop/mixin/empty_lines_around_body.rb +161 -0
- data/lib/rubbycop/cop/mixin/end_keyword_alignment.rb +85 -0
- data/lib/rubbycop/cop/mixin/enforce_superclass.rb +36 -0
- data/lib/rubbycop/cop/mixin/first_element_line_break.rb +41 -0
- data/lib/rubbycop/cop/mixin/frozen_string_literal.rb +37 -0
- data/lib/rubbycop/cop/mixin/hash_alignment.rb +116 -0
- data/lib/rubbycop/cop/mixin/ignored_pattern.rb +27 -0
- data/lib/rubbycop/cop/mixin/integer_node.rb +12 -0
- data/lib/rubbycop/cop/mixin/match_range.rb +22 -0
- data/lib/rubbycop/cop/mixin/method_complexity.rb +30 -0
- data/lib/rubbycop/cop/mixin/method_preference.rb +30 -0
- data/lib/rubbycop/cop/mixin/min_body_length.rb +19 -0
- data/lib/rubbycop/cop/mixin/multiline_expression_indentation.rb +183 -0
- data/lib/rubbycop/cop/mixin/multiline_literal_brace_layout.rb +152 -0
- data/lib/rubbycop/cop/mixin/negative_conditional.rb +43 -0
- data/lib/rubbycop/cop/mixin/on_method_def.rb +44 -0
- data/lib/rubbycop/cop/mixin/on_normal_if_unless.rb +14 -0
- data/lib/rubbycop/cop/mixin/parentheses.rb +22 -0
- data/lib/rubbycop/cop/mixin/parser_diagnostic.rb +34 -0
- data/lib/rubbycop/cop/mixin/percent_literal.rb +100 -0
- data/lib/rubbycop/cop/mixin/preceding_following_alignment.rb +89 -0
- data/lib/rubbycop/cop/mixin/rescue_node.rb +21 -0
- data/lib/rubbycop/cop/mixin/safe_assignment.rb +20 -0
- data/lib/rubbycop/cop/mixin/safe_mode.rb +22 -0
- data/lib/rubbycop/cop/mixin/space_after_punctuation.rb +55 -0
- data/lib/rubbycop/cop/mixin/space_before_punctuation.rb +48 -0
- data/lib/rubbycop/cop/mixin/space_inside.rb +76 -0
- data/lib/rubbycop/cop/mixin/statement_modifier.rb +69 -0
- data/lib/rubbycop/cop/mixin/string_help.rb +33 -0
- data/lib/rubbycop/cop/mixin/string_literals_help.rb +33 -0
- data/lib/rubbycop/cop/mixin/surrounding_space.rb +40 -0
- data/lib/rubbycop/cop/mixin/target_rails_version.rb +16 -0
- data/lib/rubbycop/cop/mixin/target_ruby_version.rb +16 -0
- data/lib/rubbycop/cop/mixin/too_many_lines.rb +39 -0
- data/lib/rubbycop/cop/mixin/trailing_comma.rb +161 -0
- data/lib/rubbycop/cop/mixin/unused_argument.rb +42 -0
- data/lib/rubbycop/cop/offense.rb +188 -0
- data/lib/rubbycop/cop/performance/caller.rb +41 -0
- data/lib/rubbycop/cop/performance/case_when_splat.rb +176 -0
- data/lib/rubbycop/cop/performance/casecmp.rb +107 -0
- data/lib/rubbycop/cop/performance/compare_with_block.rb +107 -0
- data/lib/rubbycop/cop/performance/count.rb +98 -0
- data/lib/rubbycop/cop/performance/detect.rb +107 -0
- data/lib/rubbycop/cop/performance/double_start_end_with.rb +102 -0
- data/lib/rubbycop/cop/performance/end_with.rb +55 -0
- data/lib/rubbycop/cop/performance/fixed_size.rb +56 -0
- data/lib/rubbycop/cop/performance/flat_map.rb +73 -0
- data/lib/rubbycop/cop/performance/hash_each_methods.rb +84 -0
- data/lib/rubbycop/cop/performance/lstrip_rstrip.rb +41 -0
- data/lib/rubbycop/cop/performance/range_include.rb +41 -0
- data/lib/rubbycop/cop/performance/redundant_block_call.rb +93 -0
- data/lib/rubbycop/cop/performance/redundant_match.rb +55 -0
- data/lib/rubbycop/cop/performance/redundant_merge.rb +149 -0
- data/lib/rubbycop/cop/performance/redundant_sort_by.rb +45 -0
- data/lib/rubbycop/cop/performance/regexp_match.rb +215 -0
- data/lib/rubbycop/cop/performance/reverse_each.rb +40 -0
- data/lib/rubbycop/cop/performance/sample.rb +140 -0
- data/lib/rubbycop/cop/performance/size.rb +71 -0
- data/lib/rubbycop/cop/performance/start_with.rb +58 -0
- data/lib/rubbycop/cop/performance/string_replacement.rb +170 -0
- data/lib/rubbycop/cop/performance/times_map.rb +61 -0
- data/lib/rubbycop/cop/rails/action_filter.rb +96 -0
- data/lib/rubbycop/cop/rails/active_support_aliases.rb +68 -0
- data/lib/rubbycop/cop/rails/application_job.rb +32 -0
- data/lib/rubbycop/cop/rails/application_record.rb +32 -0
- data/lib/rubbycop/cop/rails/blank.rb +138 -0
- data/lib/rubbycop/cop/rails/date.rb +127 -0
- data/lib/rubbycop/cop/rails/delegate.rb +106 -0
- data/lib/rubbycop/cop/rails/delegate_allow_blank.rb +51 -0
- data/lib/rubbycop/cop/rails/dynamic_find_by.rb +81 -0
- data/lib/rubbycop/cop/rails/enum_uniqueness.rb +43 -0
- data/lib/rubbycop/cop/rails/exit.rb +61 -0
- data/lib/rubbycop/cop/rails/file_path.rb +75 -0
- data/lib/rubbycop/cop/rails/find_by.rb +51 -0
- data/lib/rubbycop/cop/rails/find_each.rb +47 -0
- data/lib/rubbycop/cop/rails/has_and_belongs_to_many.rb +18 -0
- data/lib/rubbycop/cop/rails/http_positional_arguments.rb +106 -0
- data/lib/rubbycop/cop/rails/not_null_column.rb +67 -0
- data/lib/rubbycop/cop/rails/output.rb +23 -0
- data/lib/rubbycop/cop/rails/output_safety.rb +58 -0
- data/lib/rubbycop/cop/rails/pluralization_grammar.rb +106 -0
- data/lib/rubbycop/cop/rails/present.rb +143 -0
- data/lib/rubbycop/cop/rails/read_write_attribute.rb +65 -0
- data/lib/rubbycop/cop/rails/relative_date_constant.rb +88 -0
- data/lib/rubbycop/cop/rails/request_referer.rb +56 -0
- data/lib/rubbycop/cop/rails/reversible_migration.rb +216 -0
- data/lib/rubbycop/cop/rails/safe_navigation.rb +91 -0
- data/lib/rubbycop/cop/rails/save_bang.rb +160 -0
- data/lib/rubbycop/cop/rails/scope_args.rb +29 -0
- data/lib/rubbycop/cop/rails/skips_model_validations.rb +63 -0
- data/lib/rubbycop/cop/rails/time_zone.rb +197 -0
- data/lib/rubbycop/cop/rails/uniq_before_pluck.rb +93 -0
- data/lib/rubbycop/cop/rails/validation.rb +64 -0
- data/lib/rubbycop/cop/registry.rb +171 -0
- data/lib/rubbycop/cop/security/eval.rb +30 -0
- data/lib/rubbycop/cop/security/json_load.rb +44 -0
- data/lib/rubbycop/cop/security/marshal_load.rb +37 -0
- data/lib/rubbycop/cop/security/yaml_load.rb +37 -0
- data/lib/rubbycop/cop/severity.rb +76 -0
- data/lib/rubbycop/cop/style/accessor_method_name.rb +45 -0
- data/lib/rubbycop/cop/style/alias.rb +119 -0
- data/lib/rubbycop/cop/style/and_or.rb +125 -0
- data/lib/rubbycop/cop/style/array_join.rb +30 -0
- data/lib/rubbycop/cop/style/ascii_comments.rb +38 -0
- data/lib/rubbycop/cop/style/ascii_identifiers.rb +36 -0
- data/lib/rubbycop/cop/style/attr.rb +50 -0
- data/lib/rubbycop/cop/style/auto_resource_cleanup.rb +42 -0
- data/lib/rubbycop/cop/style/bare_percent_literals.rb +57 -0
- data/lib/rubbycop/cop/style/begin_block.rb +16 -0
- data/lib/rubbycop/cop/style/block_comments.rb +46 -0
- data/lib/rubbycop/cop/style/block_delimiters.rb +228 -0
- data/lib/rubbycop/cop/style/braces_around_hash_parameters.rb +138 -0
- data/lib/rubbycop/cop/style/case_equality.rb +18 -0
- data/lib/rubbycop/cop/style/character_literal.rb +43 -0
- data/lib/rubbycop/cop/style/class_and_module_camel_case.rb +29 -0
- data/lib/rubbycop/cop/style/class_and_module_children.rb +69 -0
- data/lib/rubbycop/cop/style/class_check.rb +40 -0
- data/lib/rubbycop/cop/style/class_methods.rb +67 -0
- data/lib/rubbycop/cop/style/class_vars.rb +23 -0
- data/lib/rubbycop/cop/style/collection_methods.rb +51 -0
- data/lib/rubbycop/cop/style/colon_method_call.rb +33 -0
- data/lib/rubbycop/cop/style/command_literal.rb +119 -0
- data/lib/rubbycop/cop/style/comment_annotation.rb +62 -0
- data/lib/rubbycop/cop/style/conditional_assignment.rb +691 -0
- data/lib/rubbycop/cop/style/constant_name.rb +29 -0
- data/lib/rubbycop/cop/style/copyright.rb +89 -0
- data/lib/rubbycop/cop/style/def_with_parentheses.rb +31 -0
- data/lib/rubbycop/cop/style/documentation.rb +79 -0
- data/lib/rubbycop/cop/style/documentation_method.rb +80 -0
- data/lib/rubbycop/cop/style/double_negation.rb +35 -0
- data/lib/rubbycop/cop/style/each_for_simple_loop.rb +57 -0
- data/lib/rubbycop/cop/style/each_with_object.rb +91 -0
- data/lib/rubbycop/cop/style/empty_case_condition.rb +84 -0
- data/lib/rubbycop/cop/style/empty_else.rb +138 -0
- data/lib/rubbycop/cop/style/empty_literal.rb +108 -0
- data/lib/rubbycop/cop/style/empty_method.rb +102 -0
- data/lib/rubbycop/cop/style/encoding.rb +92 -0
- data/lib/rubbycop/cop/style/end_block.rb +17 -0
- data/lib/rubbycop/cop/style/even_odd.rb +56 -0
- data/lib/rubbycop/cop/style/file_name.rb +183 -0
- data/lib/rubbycop/cop/style/flip_flop.rb +20 -0
- data/lib/rubbycop/cop/style/for.rb +50 -0
- data/lib/rubbycop/cop/style/format_string.rb +46 -0
- data/lib/rubbycop/cop/style/format_string_token.rb +141 -0
- data/lib/rubbycop/cop/style/frozen_string_literal_comment.rb +96 -0
- data/lib/rubbycop/cop/style/global_vars.rb +70 -0
- data/lib/rubbycop/cop/style/guard_clause.rb +90 -0
- data/lib/rubbycop/cop/style/hash_syntax.rb +214 -0
- data/lib/rubbycop/cop/style/identical_conditional_branches.rb +130 -0
- data/lib/rubbycop/cop/style/if_inside_else.rb +45 -0
- data/lib/rubbycop/cop/style/if_unless_modifier.rb +80 -0
- data/lib/rubbycop/cop/style/if_unless_modifier_of_if_unless.rb +38 -0
- data/lib/rubbycop/cop/style/if_with_semicolon.rb +20 -0
- data/lib/rubbycop/cop/style/implicit_runtime_error.rb +31 -0
- data/lib/rubbycop/cop/style/infinite_loop.rb +91 -0
- data/lib/rubbycop/cop/style/inline_comment.rb +32 -0
- data/lib/rubbycop/cop/style/inverse_methods.rb +130 -0
- data/lib/rubbycop/cop/style/lambda.rb +209 -0
- data/lib/rubbycop/cop/style/lambda_call.rb +66 -0
- data/lib/rubbycop/cop/style/line_end_concatenation.rb +115 -0
- data/lib/rubbycop/cop/style/method_call_with_args_parentheses.rb +107 -0
- data/lib/rubbycop/cop/style/method_call_without_args_parentheses.rb +75 -0
- data/lib/rubbycop/cop/style/method_called_on_do_end_block.rb +44 -0
- data/lib/rubbycop/cop/style/method_def_parentheses.rb +83 -0
- data/lib/rubbycop/cop/style/method_missing.rb +81 -0
- data/lib/rubbycop/cop/style/method_name.rb +28 -0
- data/lib/rubbycop/cop/style/missing_else.rb +100 -0
- data/lib/rubbycop/cop/style/mixin_grouping.rb +135 -0
- data/lib/rubbycop/cop/style/module_function.rb +64 -0
- data/lib/rubbycop/cop/style/multiline_block_chain.rb +42 -0
- data/lib/rubbycop/cop/style/multiline_if_modifier.rb +63 -0
- data/lib/rubbycop/cop/style/multiline_if_then.rb +47 -0
- data/lib/rubbycop/cop/style/multiline_memoization.rb +77 -0
- data/lib/rubbycop/cop/style/multiline_ternary_operator.rb +19 -0
- data/lib/rubbycop/cop/style/mutable_constant.rb +68 -0
- data/lib/rubbycop/cop/style/negated_if.rb +103 -0
- data/lib/rubbycop/cop/style/negated_while.rb +32 -0
- data/lib/rubbycop/cop/style/nested_modifier.rb +87 -0
- data/lib/rubbycop/cop/style/nested_parenthesized_calls.rb +61 -0
- data/lib/rubbycop/cop/style/nested_ternary_operator.rb +21 -0
- data/lib/rubbycop/cop/style/next.rb +225 -0
- data/lib/rubbycop/cop/style/nil_comparison.rb +35 -0
- data/lib/rubbycop/cop/style/non_nil_check.rb +121 -0
- data/lib/rubbycop/cop/style/not.rb +69 -0
- data/lib/rubbycop/cop/style/numeric_literal_prefix.rb +97 -0
- data/lib/rubbycop/cop/style/numeric_literals.rb +101 -0
- data/lib/rubbycop/cop/style/numeric_predicate.rb +140 -0
- data/lib/rubbycop/cop/style/one_line_conditional.rb +75 -0
- data/lib/rubbycop/cop/style/op_method.rb +41 -0
- data/lib/rubbycop/cop/style/option_hash.rb +58 -0
- data/lib/rubbycop/cop/style/optional_arguments.rb +62 -0
- data/lib/rubbycop/cop/style/parallel_assignment.rb +287 -0
- data/lib/rubbycop/cop/style/parentheses_around_condition.rb +56 -0
- data/lib/rubbycop/cop/style/percent_literal_delimiters.rb +100 -0
- data/lib/rubbycop/cop/style/percent_q_literals.rb +52 -0
- data/lib/rubbycop/cop/style/perl_backrefs.rb +31 -0
- data/lib/rubbycop/cop/style/predicate_name.rb +67 -0
- data/lib/rubbycop/cop/style/preferred_hash_methods.rb +78 -0
- data/lib/rubbycop/cop/style/proc.rb +26 -0
- data/lib/rubbycop/cop/style/raise_args.rb +140 -0
- data/lib/rubbycop/cop/style/redundant_begin.rb +47 -0
- data/lib/rubbycop/cop/style/redundant_exception.rb +55 -0
- data/lib/rubbycop/cop/style/redundant_freeze.rb +45 -0
- data/lib/rubbycop/cop/style/redundant_parentheses.rb +199 -0
- data/lib/rubbycop/cop/style/redundant_return.rb +121 -0
- data/lib/rubbycop/cop/style/redundant_self.rb +144 -0
- data/lib/rubbycop/cop/style/regexp_literal.rb +114 -0
- data/lib/rubbycop/cop/style/rescue_modifier.rb +37 -0
- data/lib/rubbycop/cop/style/safe_navigation.rb +145 -0
- data/lib/rubbycop/cop/style/self_assignment.rb +93 -0
- data/lib/rubbycop/cop/style/semicolon.rb +70 -0
- data/lib/rubbycop/cop/style/send.rb +21 -0
- data/lib/rubbycop/cop/style/signal_exception.rb +109 -0
- data/lib/rubbycop/cop/style/single_line_block_params.rb +68 -0
- data/lib/rubbycop/cop/style/single_line_methods.rb +77 -0
- data/lib/rubbycop/cop/style/special_global_vars.rb +156 -0
- data/lib/rubbycop/cop/style/stabby_lambda_parentheses.rb +113 -0
- data/lib/rubbycop/cop/style/string_literals.rb +102 -0
- data/lib/rubbycop/cop/style/string_literals_in_interpolation.rb +30 -0
- data/lib/rubbycop/cop/style/string_methods.rb +34 -0
- data/lib/rubbycop/cop/style/struct_inheritance.rb +32 -0
- data/lib/rubbycop/cop/style/symbol_array.rb +109 -0
- data/lib/rubbycop/cop/style/symbol_literal.rb +32 -0
- data/lib/rubbycop/cop/style/symbol_proc.rb +143 -0
- data/lib/rubbycop/cop/style/ternary_parentheses.rb +200 -0
- data/lib/rubbycop/cop/style/trailing_comma_in_arguments.rb +64 -0
- data/lib/rubbycop/cop/style/trailing_comma_in_literal.rb +56 -0
- data/lib/rubbycop/cop/style/trailing_underscore_variable.rb +113 -0
- data/lib/rubbycop/cop/style/trivial_accessors.rb +176 -0
- data/lib/rubbycop/cop/style/unless_else.rb +39 -0
- data/lib/rubbycop/cop/style/unneeded_capital_w.rb +41 -0
- data/lib/rubbycop/cop/style/unneeded_interpolation.rb +98 -0
- data/lib/rubbycop/cop/style/unneeded_percent_q.rb +96 -0
- data/lib/rubbycop/cop/style/variable_interpolation.rb +44 -0
- data/lib/rubbycop/cop/style/variable_name.rb +39 -0
- data/lib/rubbycop/cop/style/variable_number.rb +78 -0
- data/lib/rubbycop/cop/style/when_then.rb +24 -0
- data/lib/rubbycop/cop/style/while_until_do.rb +36 -0
- data/lib/rubbycop/cop/style/while_until_modifier.rb +41 -0
- data/lib/rubbycop/cop/style/word_array.rb +114 -0
- data/lib/rubbycop/cop/style/zero_length_predicate.rb +90 -0
- data/lib/rubbycop/cop/team.rb +193 -0
- data/lib/rubbycop/cop/util.rb +309 -0
- data/lib/rubbycop/cop/variable_force.rb +458 -0
- data/lib/rubbycop/cop/variable_force/assignment.rb +90 -0
- data/lib/rubbycop/cop/variable_force/branch.rb +318 -0
- data/lib/rubbycop/cop/variable_force/branchable.rb +21 -0
- data/lib/rubbycop/cop/variable_force/reference.rb +49 -0
- data/lib/rubbycop/cop/variable_force/scope.rb +107 -0
- data/lib/rubbycop/cop/variable_force/variable.rb +103 -0
- data/lib/rubbycop/cop/variable_force/variable_table.rb +128 -0
- data/lib/rubbycop/error.rb +11 -0
- data/lib/rubbycop/formatter/base_formatter.rb +123 -0
- data/lib/rubbycop/formatter/clang_style_formatter.rb +54 -0
- data/lib/rubbycop/formatter/colorizable.rb +41 -0
- data/lib/rubbycop/formatter/disabled_config_formatter.rb +181 -0
- data/lib/rubbycop/formatter/disabled_lines_formatter.rb +57 -0
- data/lib/rubbycop/formatter/emacs_style_formatter.rb +24 -0
- data/lib/rubbycop/formatter/file_list_formatter.rb +19 -0
- data/lib/rubbycop/formatter/formatter_set.rb +102 -0
- data/lib/rubbycop/formatter/fuubar_style_formatter.rb +80 -0
- data/lib/rubbycop/formatter/html_formatter.rb +134 -0
- data/lib/rubbycop/formatter/json_formatter.rb +74 -0
- data/lib/rubbycop/formatter/offense_count_formatter.rb +55 -0
- data/lib/rubbycop/formatter/progress_formatter.rb +63 -0
- data/lib/rubbycop/formatter/simple_text_formatter.rb +136 -0
- data/lib/rubbycop/formatter/text_util.rb +20 -0
- data/lib/rubbycop/formatter/worst_offenders_formatter.rb +60 -0
- data/lib/rubbycop/magic_comment.rb +210 -0
- data/lib/rubbycop/name_similarity.rb +21 -0
- data/lib/rubbycop/node_pattern.rb +543 -0
- data/lib/rubbycop/options.rb +355 -0
- data/lib/rubbycop/path_util.rb +36 -0
- data/lib/rubbycop/platform.rb +11 -0
- data/lib/rubbycop/processed_source.rb +151 -0
- data/lib/rubbycop/rake_task.rb +86 -0
- data/lib/rubbycop/remote_config.rb +78 -0
- data/lib/rubbycop/result_cache.rb +176 -0
- data/lib/rubbycop/rspec/cop_helper.rb +98 -0
- data/lib/rubbycop/rspec/host_environment_simulation_helper.rb +32 -0
- data/lib/rubbycop/rspec/shared_contexts.rb +98 -0
- data/lib/rubbycop/rspec/shared_examples.rb +92 -0
- data/lib/rubbycop/rspec/support.rb +8 -0
- data/lib/rubbycop/runner.rb +338 -0
- data/lib/rubbycop/string_interpreter.rb +57 -0
- data/lib/rubbycop/string_util.rb +156 -0
- data/lib/rubbycop/target_finder.rb +201 -0
- data/lib/rubbycop/token.rb +25 -0
- data/lib/rubbycop/version.rb +19 -0
- data/lib/rubbycop/warning.rb +11 -0
- metadata +663 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubbyCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks for multiple expressions placed on the same line.
|
7
|
+
# It also checks for lines terminated with a semicolon.
|
8
|
+
class Semicolon < Cop
|
9
|
+
MSG = 'Do not use semicolons to terminate expressions.'.freeze
|
10
|
+
|
11
|
+
def investigate(processed_source)
|
12
|
+
return unless processed_source.ast
|
13
|
+
@processed_source = processed_source
|
14
|
+
|
15
|
+
check_for_line_terminator_or_opener
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_begin(node)
|
19
|
+
return if cop_config['AllowAsExpressionSeparator']
|
20
|
+
exprs = node.children
|
21
|
+
|
22
|
+
return if exprs.size < 2
|
23
|
+
|
24
|
+
# create a map matching lines to the number of expressions on them
|
25
|
+
exprs_lines = exprs.map { |e| e.source_range.line }
|
26
|
+
lines = exprs_lines.group_by { |i| i }
|
27
|
+
|
28
|
+
# every line with more than 1 expression on it is an offense
|
29
|
+
lines.each do |line, expr_on_line|
|
30
|
+
next unless expr_on_line.size > 1
|
31
|
+
# TODO: Find the correct position of the semicolon. We don't know
|
32
|
+
# if the first semicolon on the line is a separator of
|
33
|
+
# expressions. It's just a guess.
|
34
|
+
column = @processed_source[line - 1].index(';')
|
35
|
+
convention_on(line, column, false)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def check_for_line_terminator_or_opener
|
42
|
+
each_semicolon { |line, column| convention_on(line, column, true) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def each_semicolon
|
46
|
+
tokens_for_lines.each do |line, tokens|
|
47
|
+
yield line, tokens.last.pos.column if tokens.last.type == :tSEMI
|
48
|
+
yield line, tokens.first.pos.column if tokens.first.type == :tSEMI
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def tokens_for_lines
|
53
|
+
@processed_source.tokens.group_by { |token| token.pos.line }
|
54
|
+
end
|
55
|
+
|
56
|
+
def convention_on(line, column, autocorrect)
|
57
|
+
range = source_range(@processed_source.buffer, line, column)
|
58
|
+
# Don't attempt to autocorrect if semicolon is separating statements
|
59
|
+
# on the same line
|
60
|
+
add_offense(autocorrect ? range : nil, range)
|
61
|
+
end
|
62
|
+
|
63
|
+
def autocorrect(range)
|
64
|
+
return unless range
|
65
|
+
->(corrector) { corrector.remove(range) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubbyCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks for the use of the send method.
|
7
|
+
class Send < Cop
|
8
|
+
MSG = 'Prefer `Object#__send__` or `Object#public_send` to ' \
|
9
|
+
'`send`.'.freeze
|
10
|
+
|
11
|
+
def_node_matcher :sending?, '(send _ :send ...)'
|
12
|
+
|
13
|
+
def on_send(node)
|
14
|
+
return unless sending?(node) && node.arguments?
|
15
|
+
|
16
|
+
add_offense(node, :selector)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubbyCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks for uses of `fail` and `raise`.
|
7
|
+
class SignalException < Cop
|
8
|
+
include ConfigurableEnforcedStyle
|
9
|
+
|
10
|
+
FAIL_MSG = 'Use `fail` instead of `raise` to signal exceptions.'.freeze
|
11
|
+
RAISE_MSG = 'Use `raise` instead of `fail` to ' \
|
12
|
+
'rethrow exceptions.'.freeze
|
13
|
+
|
14
|
+
def_node_matcher :kernel_call?, '(send (const nil :Kernel) %1 ...)'
|
15
|
+
def_node_search :custom_fail_methods,
|
16
|
+
'{(def :fail ...) (defs _ :fail ...)}'
|
17
|
+
|
18
|
+
def investigate(processed_source)
|
19
|
+
ast = processed_source.ast
|
20
|
+
@custom_fail_defined = ast && custom_fail_methods(ast).any?
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_rescue(node)
|
24
|
+
return unless style == :semantic
|
25
|
+
|
26
|
+
begin_node, *rescue_nodes, _else_node = *node
|
27
|
+
check_scope(:raise, begin_node)
|
28
|
+
|
29
|
+
rescue_nodes.each do |rescue_node|
|
30
|
+
check_scope(:fail, rescue_node)
|
31
|
+
allow(:raise, rescue_node)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def on_send(node)
|
36
|
+
case style
|
37
|
+
when :semantic
|
38
|
+
check_send(:raise, node) unless ignored_node?(node)
|
39
|
+
when :only_raise
|
40
|
+
return if @custom_fail_defined
|
41
|
+
check_send(:fail, node)
|
42
|
+
when :only_fail
|
43
|
+
check_send(:raise, node)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def autocorrect(node)
|
48
|
+
lambda do |corrector|
|
49
|
+
name =
|
50
|
+
case style
|
51
|
+
when :semantic
|
52
|
+
command_or_kernel_call?(:raise, node) ? 'fail' : 'raise'
|
53
|
+
when :only_raise then 'raise'
|
54
|
+
when :only_fail then 'fail'
|
55
|
+
end
|
56
|
+
|
57
|
+
corrector.replace(node.loc.selector, name)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def message(method_name)
|
64
|
+
case style
|
65
|
+
when :semantic
|
66
|
+
method_name == :fail ? RAISE_MSG : FAIL_MSG
|
67
|
+
when :only_raise
|
68
|
+
'Always use `raise` to signal exceptions.'
|
69
|
+
when :only_fail
|
70
|
+
'Always use `fail` to signal exceptions.'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def check_scope(method_name, node)
|
75
|
+
return unless node
|
76
|
+
|
77
|
+
each_command_or_kernel_call(method_name, node) do |send_node|
|
78
|
+
next if ignored_node?(send_node)
|
79
|
+
|
80
|
+
add_offense(send_node, :selector, message(method_name))
|
81
|
+
ignore_node(send_node)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def check_send(method_name, node)
|
86
|
+
return unless node && command_or_kernel_call?(method_name, node)
|
87
|
+
|
88
|
+
add_offense(node, :selector, message(method_name))
|
89
|
+
end
|
90
|
+
|
91
|
+
def command_or_kernel_call?(name, node)
|
92
|
+
node.command?(name) || kernel_call?(node, name)
|
93
|
+
end
|
94
|
+
|
95
|
+
def allow(method_name, node)
|
96
|
+
each_command_or_kernel_call(method_name, node) do |send_node|
|
97
|
+
ignore_node(send_node)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def each_command_or_kernel_call(method_name, node)
|
102
|
+
on_node(:send, node, :rescue) do |send_node|
|
103
|
+
yield send_node if command_or_kernel_call?(method_name, send_node)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubbyCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks whether the block parameters of a single-line
|
7
|
+
# method accepting a block match the names specified via configuration.
|
8
|
+
#
|
9
|
+
# For instance one can configure `reduce`(`inject`) to use |a, e| as
|
10
|
+
# parameters.
|
11
|
+
class SingleLineBlockParams < Cop
|
12
|
+
def on_block(node)
|
13
|
+
# we care only for single line blocks
|
14
|
+
return unless block_length(node).zero?
|
15
|
+
|
16
|
+
method_node, args_node, _body_node = *node
|
17
|
+
receiver, method_name, _method_args = *method_node
|
18
|
+
|
19
|
+
# discard other scenarios
|
20
|
+
return unless receiver
|
21
|
+
return unless method_names.include?(method_name)
|
22
|
+
|
23
|
+
args = *args_node
|
24
|
+
|
25
|
+
return if args.empty?
|
26
|
+
# discard cases with argument destructuring
|
27
|
+
return true unless args.all?(&:arg_type?)
|
28
|
+
return if args_match?(method_name, args)
|
29
|
+
|
30
|
+
add_offense(args_node, :expression, message(method_name))
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def message(method_name)
|
36
|
+
args = target_args(method_name).join(', ')
|
37
|
+
"Name `#{method_name}` block params `|#{args}|`."
|
38
|
+
end
|
39
|
+
|
40
|
+
def methods
|
41
|
+
cop_config['Methods']
|
42
|
+
end
|
43
|
+
|
44
|
+
def method_names
|
45
|
+
methods.map { |e| e.keys.first.to_sym }
|
46
|
+
end
|
47
|
+
|
48
|
+
def target_args(method_name)
|
49
|
+
method_name = method_name.to_s
|
50
|
+
method_hash = methods.find { |m| m.keys.first == method_name }
|
51
|
+
method_hash[method_name]
|
52
|
+
end
|
53
|
+
|
54
|
+
def args_match?(method_name, args)
|
55
|
+
actual_args = args.flat_map(&:to_a)
|
56
|
+
|
57
|
+
# Prepending an underscore to mark an unused parameter is allowed, so
|
58
|
+
# we remove any leading underscores before comparing.
|
59
|
+
actual_args_no_underscores = actual_args.map do |arg|
|
60
|
+
arg.to_s.sub(/^_+/, '')
|
61
|
+
end
|
62
|
+
|
63
|
+
actual_args_no_underscores == target_args(method_name)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubbyCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks for single-line method definitions.
|
7
|
+
# It can optionally accept single-line methods with no body.
|
8
|
+
class SingleLineMethods < Cop
|
9
|
+
include AutocorrectAlignment
|
10
|
+
include OnMethodDef
|
11
|
+
|
12
|
+
MSG = 'Avoid single-line method definitions.'.freeze
|
13
|
+
|
14
|
+
def allow_empty?
|
15
|
+
cop_config['AllowIfMethodIsEmpty']
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def on_method_def(node, _method_name, _args, body)
|
21
|
+
start_line = node.loc.keyword.line
|
22
|
+
end_line = node.loc.end.line
|
23
|
+
|
24
|
+
empty_body = body.nil?
|
25
|
+
return unless start_line == end_line && !(allow_empty? && empty_body)
|
26
|
+
|
27
|
+
@body = body
|
28
|
+
add_offense(node, :expression)
|
29
|
+
end
|
30
|
+
|
31
|
+
def autocorrect(node)
|
32
|
+
body = @body
|
33
|
+
|
34
|
+
lambda do |corrector|
|
35
|
+
each_part(body) do |part|
|
36
|
+
break_line_before(part, node, corrector, 1)
|
37
|
+
end
|
38
|
+
|
39
|
+
break_line_before(node.loc.end, node, corrector, 0)
|
40
|
+
|
41
|
+
eol_comment = end_of_line_comment(node.source_range.line)
|
42
|
+
move_comment(eol_comment, node, corrector) if eol_comment
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def end_of_line_comment(line)
|
47
|
+
processed_source.comments.find { |c| c.loc.line == line }
|
48
|
+
end
|
49
|
+
|
50
|
+
def each_part(body)
|
51
|
+
return unless body
|
52
|
+
|
53
|
+
if body.begin_type?
|
54
|
+
body.each_child_node { |part| yield part.source_range }
|
55
|
+
else
|
56
|
+
yield body.source_range
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def break_line_before(range, node, corrector, indent_steps)
|
61
|
+
corrector.insert_before(
|
62
|
+
range,
|
63
|
+
"\n" + ' ' * (node.loc.keyword.column +
|
64
|
+
indent_steps * configured_indentation_width)
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
def move_comment(eol_comment, node, corrector)
|
69
|
+
text = eol_comment.loc.expression.source
|
70
|
+
corrector.insert_before(node.source_range,
|
71
|
+
text + "\n" + (' ' * node.loc.keyword.column))
|
72
|
+
corrector.remove(eol_comment.loc.expression)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubbyCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop looks for uses of Perl-style global variables.
|
7
|
+
class SpecialGlobalVars < Cop
|
8
|
+
include ConfigurableEnforcedStyle
|
9
|
+
|
10
|
+
MSG_BOTH = 'Prefer `%s` from the stdlib \'English\' module ' \
|
11
|
+
'(don\'t forget to require it), or `%s` over `%s`.'.freeze
|
12
|
+
MSG_ENGLISH = 'Prefer `%s` from the stdlib \'English\' module ' \
|
13
|
+
'(don\'t forget to require it) over `%s`.'.freeze
|
14
|
+
MSG_REGULAR = 'Prefer `%s` over `%s`.'.freeze
|
15
|
+
|
16
|
+
ENGLISH_VARS = { # rubbycop:disable Style/MutableConstant
|
17
|
+
:$: => [:$LOAD_PATH],
|
18
|
+
:$" => [:$LOADED_FEATURES],
|
19
|
+
:$0 => [:$PROGRAM_NAME],
|
20
|
+
:$! => [:$ERROR_INFO],
|
21
|
+
:$@ => [:$ERROR_POSITION],
|
22
|
+
:$; => %i[$FIELD_SEPARATOR $FS],
|
23
|
+
:$, => %i[$OUTPUT_FIELD_SEPARATOR $OFS],
|
24
|
+
:$/ => %i[$INPUT_RECORD_SEPARATOR $RS],
|
25
|
+
:$\ => %i[$OUTPUT_RECORD_SEPARATOR $ORS],
|
26
|
+
:$. => %i[$INPUT_LINE_NUMBER $NR],
|
27
|
+
:$_ => [:$LAST_READ_LINE],
|
28
|
+
:$> => [:$DEFAULT_OUTPUT],
|
29
|
+
:$< => [:$DEFAULT_INPUT],
|
30
|
+
:$$ => %i[$PROCESS_ID $PID],
|
31
|
+
:$? => [:$CHILD_STATUS],
|
32
|
+
:$~ => [:$LAST_MATCH_INFO],
|
33
|
+
:$= => [:$IGNORECASE],
|
34
|
+
:$* => %i[$ARGV ARGV],
|
35
|
+
:$& => [:$MATCH],
|
36
|
+
:$` => [:$PREMATCH],
|
37
|
+
:$' => [:$POSTMATCH],
|
38
|
+
:$+ => [:$LAST_PAREN_MATCH]
|
39
|
+
}
|
40
|
+
|
41
|
+
PERL_VARS =
|
42
|
+
Hash[ENGLISH_VARS.flat_map { |k, vs| vs.map { |v| [v, [k]] } }]
|
43
|
+
|
44
|
+
ENGLISH_VARS.merge!(
|
45
|
+
Hash[ENGLISH_VARS.flat_map { |_, vs| vs.map { |v| [v, [v]] } }]
|
46
|
+
)
|
47
|
+
PERL_VARS.merge!(
|
48
|
+
Hash[PERL_VARS.flat_map { |_, vs| vs.map { |v| [v, [v]] } }]
|
49
|
+
)
|
50
|
+
ENGLISH_VARS.each { |_, v| v.freeze }.freeze
|
51
|
+
PERL_VARS.each { |_, v| v.freeze }.freeze
|
52
|
+
|
53
|
+
# Anything *not* in this set is provided by the English library.
|
54
|
+
NON_ENGLISH_VARS = Set.new(%i[
|
55
|
+
$LOAD_PATH
|
56
|
+
$LOADED_FEATURES
|
57
|
+
$PROGRAM_NAME
|
58
|
+
ARGV
|
59
|
+
]).freeze
|
60
|
+
|
61
|
+
def on_gvar(node)
|
62
|
+
global_var, = *node
|
63
|
+
|
64
|
+
return unless (preferred = preferred_names(global_var))
|
65
|
+
|
66
|
+
if preferred.include?(global_var)
|
67
|
+
correct_style_detected
|
68
|
+
else
|
69
|
+
opposite_style_detected
|
70
|
+
add_offense(node, :expression)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def message(node)
|
75
|
+
global_var, = *node
|
76
|
+
|
77
|
+
if style == :use_english_names
|
78
|
+
format_english_message(global_var)
|
79
|
+
else
|
80
|
+
format(MSG_REGULAR, preferred_names(global_var).first, global_var)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def autocorrect(node)
|
85
|
+
lambda do |corrector|
|
86
|
+
global_var, = *node
|
87
|
+
|
88
|
+
while node.parent && node.parent.begin_type? &&
|
89
|
+
node.parent.children.one?
|
90
|
+
node = node.parent
|
91
|
+
end
|
92
|
+
|
93
|
+
corrector.replace(node.source_range, replacement(node, global_var))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def format_english_message(global_var)
|
100
|
+
regular, english = ENGLISH_VARS[global_var].partition do |var|
|
101
|
+
NON_ENGLISH_VARS.include? var
|
102
|
+
end
|
103
|
+
|
104
|
+
format_message(english, regular, global_var)
|
105
|
+
end
|
106
|
+
|
107
|
+
def format_message(english, regular, global_var)
|
108
|
+
if !regular.empty? && !english.empty?
|
109
|
+
format(MSG_BOTH, format_list(english), format_list(regular),
|
110
|
+
global_var)
|
111
|
+
elsif !regular.empty?
|
112
|
+
format(MSG_REGULAR, format_list(regular), global_var)
|
113
|
+
elsif !english.empty?
|
114
|
+
format(MSG_ENGLISH, format_list(english), global_var)
|
115
|
+
else
|
116
|
+
raise 'Bug in SpecialGlobalVars - global var w/o preferred vars!'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# For now, we assume that lists are 2 items or less. Easy grammar!
|
121
|
+
def format_list(items)
|
122
|
+
items.join('` or `')
|
123
|
+
end
|
124
|
+
|
125
|
+
def replacement(node, global_var)
|
126
|
+
parent_type = node.parent && node.parent.type
|
127
|
+
preferred_name = preferred_names(global_var).first
|
128
|
+
|
129
|
+
unless %i[dstr xstr regexp].include?(parent_type)
|
130
|
+
return preferred_name.to_s
|
131
|
+
end
|
132
|
+
|
133
|
+
if style == :use_english_names
|
134
|
+
return english_name_replacement(preferred_name, node)
|
135
|
+
end
|
136
|
+
|
137
|
+
"##{preferred_name}"
|
138
|
+
end
|
139
|
+
|
140
|
+
def preferred_names(global)
|
141
|
+
if style == :use_english_names
|
142
|
+
ENGLISH_VARS[global]
|
143
|
+
else
|
144
|
+
PERL_VARS[global]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def english_name_replacement(preferred_name, node)
|
149
|
+
return "\#{#{preferred_name}}" if node.begin_type?
|
150
|
+
|
151
|
+
"{#{preferred_name}}"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|