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,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/tasklib'
|
5
|
+
|
6
|
+
module RubbyCop
|
7
|
+
# Provides a custom rake task.
|
8
|
+
#
|
9
|
+
# require 'rubbycop/rake_task'
|
10
|
+
# RubbyCop::RakeTask.new
|
11
|
+
class RakeTask < Rake::TaskLib
|
12
|
+
attr_accessor :name
|
13
|
+
attr_accessor :verbose
|
14
|
+
attr_accessor :fail_on_error
|
15
|
+
attr_accessor :patterns
|
16
|
+
attr_accessor :formatters
|
17
|
+
attr_accessor :requires
|
18
|
+
attr_accessor :options
|
19
|
+
|
20
|
+
def initialize(*args, &task_block)
|
21
|
+
setup_ivars(args)
|
22
|
+
|
23
|
+
desc 'Run RubbyCop' unless ::Rake.application.last_description
|
24
|
+
|
25
|
+
task(name, *args) do |_, task_args|
|
26
|
+
RakeFileUtils.send(:verbose, verbose) do
|
27
|
+
yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
|
28
|
+
run_main_task(verbose)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
setup_subtasks(name, *args, &task_block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def run_main_task(verbose)
|
36
|
+
run_cli(verbose, full_options)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def run_cli(verbose, options)
|
42
|
+
# We lazy-load rubbycop so that the task doesn't dramatically impact the
|
43
|
+
# load time of your Rakefile.
|
44
|
+
require 'rubbycop'
|
45
|
+
|
46
|
+
cli = CLI.new
|
47
|
+
puts 'Running RubbyCop...' if verbose
|
48
|
+
result = cli.run(options)
|
49
|
+
abort('RubbyCop failed!') if result.nonzero? && fail_on_error
|
50
|
+
end
|
51
|
+
|
52
|
+
def full_options
|
53
|
+
[].tap do |result|
|
54
|
+
result.concat(formatters.map { |f| ['--format', f] }.flatten)
|
55
|
+
result.concat(requires.map { |r| ['--require', r] }.flatten)
|
56
|
+
result.concat(options.flatten)
|
57
|
+
result.concat(patterns)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def setup_ivars(args)
|
62
|
+
# More lazy-loading to keep load time down.
|
63
|
+
require 'rubbycop/options'
|
64
|
+
|
65
|
+
@name = args.shift || :rubbycop
|
66
|
+
@verbose = true
|
67
|
+
@fail_on_error = true
|
68
|
+
@patterns = []
|
69
|
+
@requires = []
|
70
|
+
@options = []
|
71
|
+
@formatters = []
|
72
|
+
end
|
73
|
+
|
74
|
+
def setup_subtasks(name, *args, &task_block)
|
75
|
+
namespace name do
|
76
|
+
desc 'Auto-correct RubbyCop offenses'
|
77
|
+
|
78
|
+
task(:auto_correct, *args) do |_, task_args|
|
79
|
+
yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
|
80
|
+
options = full_options.unshift('--auto-correct')
|
81
|
+
run_cli(verbose, options)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
module RubbyCop
|
7
|
+
# Common methods and behaviors for dealing with remote config files.
|
8
|
+
class RemoteConfig
|
9
|
+
CACHE_LIFETIME = 24 * 60 * 60
|
10
|
+
|
11
|
+
def initialize(url, base_dir)
|
12
|
+
@uri = URI.parse(url)
|
13
|
+
@base_dir = base_dir
|
14
|
+
end
|
15
|
+
|
16
|
+
def file
|
17
|
+
return cache_path unless cache_path_expired?
|
18
|
+
|
19
|
+
request do |response|
|
20
|
+
open cache_path, 'w' do |io|
|
21
|
+
io.write response.body
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
cache_path
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def request(uri = @uri, limit = 10, &block)
|
31
|
+
raise ArgumentError, 'HTTP redirect too deep' if limit.zero?
|
32
|
+
|
33
|
+
http = Net::HTTP.new(uri.hostname, uri.port)
|
34
|
+
http.use_ssl = true if uri.instance_of? URI::HTTPS
|
35
|
+
|
36
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
37
|
+
if cache_path_exists?
|
38
|
+
request['If-Modified-Since'] = File.stat(cache_path).mtime.rfc2822
|
39
|
+
end
|
40
|
+
|
41
|
+
handle_response(http.request(request), limit, &block)
|
42
|
+
end
|
43
|
+
|
44
|
+
def handle_response(response, limit, &block)
|
45
|
+
case response
|
46
|
+
when Net::HTTPSuccess
|
47
|
+
yield response
|
48
|
+
when Net::HTTPRedirection
|
49
|
+
request(URI.parse(response['location']), limit - 1, &block)
|
50
|
+
else
|
51
|
+
response.error!
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def cache_path
|
56
|
+
File.expand_path(".rubbycop-#{cache_name_from_uri}", @base_dir)
|
57
|
+
end
|
58
|
+
|
59
|
+
def cache_path_exists?
|
60
|
+
@cache_path_exists ||= File.exist?(cache_path)
|
61
|
+
end
|
62
|
+
|
63
|
+
def cache_path_expired?
|
64
|
+
return true unless cache_path_exists?
|
65
|
+
|
66
|
+
@cache_path_expired ||= begin
|
67
|
+
file_age = (Time.now - File.stat(cache_path).mtime).to_f
|
68
|
+
(file_age / CACHE_LIFETIME) > 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def cache_name_from_uri
|
73
|
+
uri = @uri.clone
|
74
|
+
uri.query = nil
|
75
|
+
uri.to_s.gsub!(/[^0-9A-Za-z]/, '-')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'find'
|
5
|
+
require 'tmpdir'
|
6
|
+
require 'etc'
|
7
|
+
|
8
|
+
module RubbyCop
|
9
|
+
# Provides functionality for caching rubbycop runs.
|
10
|
+
class ResultCache
|
11
|
+
NON_CHANGING = %i[color format formatters out debug fail_level
|
12
|
+
cache fail_fast stdin parallel].freeze
|
13
|
+
|
14
|
+
# Remove old files so that the cache doesn't grow too big. When the
|
15
|
+
# threshold MaxFilesInCache has been exceeded, the oldest 50% of all the
|
16
|
+
# files in the cache are removed. The reason for removing so much is that
|
17
|
+
# cleaning should be done relatively seldom, since there is a slight risk
|
18
|
+
# that some other RubbyCop process was just about to read the file, when
|
19
|
+
# there's parallel execution and the cache is shared.
|
20
|
+
def self.cleanup(config_store, verbose, cache_root = nil)
|
21
|
+
return if inhibit_cleanup # OPTIMIZE: For faster testing
|
22
|
+
cache_root ||= cache_root(config_store)
|
23
|
+
return unless File.exist?(cache_root)
|
24
|
+
|
25
|
+
files, dirs = Find.find(cache_root).partition { |path| File.file?(path) }
|
26
|
+
return unless requires_file_removal?(files.length, config_store)
|
27
|
+
|
28
|
+
remove_oldest_files(files, dirs, cache_root, verbose)
|
29
|
+
end
|
30
|
+
|
31
|
+
class << self
|
32
|
+
private
|
33
|
+
|
34
|
+
def requires_file_removal?(file_count, config_store)
|
35
|
+
file_count > 1 &&
|
36
|
+
file_count > config_store.for('.').for_all_cops['MaxFilesInCache']
|
37
|
+
end
|
38
|
+
|
39
|
+
def remove_oldest_files(files, dirs, cache_root, verbose)
|
40
|
+
# Add 1 to half the number of files, so that we remove the file if
|
41
|
+
# there's only 1 left.
|
42
|
+
remove_count = 1 + files.length / 2
|
43
|
+
if verbose
|
44
|
+
puts "Removing the #{remove_count} oldest files from #{cache_root}"
|
45
|
+
end
|
46
|
+
sorted = files.sort_by { |path| File.mtime(path) }
|
47
|
+
remove_files(sorted, dirs, remove_count)
|
48
|
+
rescue Errno::ENOENT
|
49
|
+
# This can happen if parallel RubbyCop invocations try to remove the
|
50
|
+
# same files. No problem.
|
51
|
+
puts $ERROR_INFO if verbose
|
52
|
+
end
|
53
|
+
|
54
|
+
def remove_files(files, dirs, remove_count)
|
55
|
+
# Batch file deletions, deleting over 130,000+ files will crash
|
56
|
+
# File.delete.
|
57
|
+
files[0, remove_count].each_slice(10_000).each do |files_slice|
|
58
|
+
File.delete(*files_slice)
|
59
|
+
end
|
60
|
+
dirs.each { |dir| Dir.rmdir(dir) if Dir["#{dir}/*"].empty? }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.cache_root(config_store)
|
65
|
+
root = config_store.for('.').for_all_cops['CacheRootDirectory']
|
66
|
+
if root == '/tmp'
|
67
|
+
tmpdir = File.realpath(Dir.tmpdir)
|
68
|
+
# Include user ID in the path to make sure the user has write access.
|
69
|
+
root = File.join(tmpdir, Process.uid.to_s)
|
70
|
+
end
|
71
|
+
File.join(root, 'rubbycop_cache')
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.allow_symlinks_in_cache_location?(config_store)
|
75
|
+
config_store.for('.').for_all_cops['AllowSymlinksInCacheRootDirectory']
|
76
|
+
end
|
77
|
+
|
78
|
+
def initialize(file, options, config_store, cache_root = nil)
|
79
|
+
cache_root ||= ResultCache.cache_root(config_store)
|
80
|
+
@allow_symlinks_in_cache_location =
|
81
|
+
ResultCache.allow_symlinks_in_cache_location?(config_store)
|
82
|
+
@path = File.join(cache_root, rubbycop_checksum,
|
83
|
+
relevant_options_digest(options),
|
84
|
+
file_checksum(file, config_store))
|
85
|
+
@cached_data = CachedData.new(file)
|
86
|
+
end
|
87
|
+
|
88
|
+
def valid?
|
89
|
+
File.exist?(@path)
|
90
|
+
end
|
91
|
+
|
92
|
+
def load
|
93
|
+
@cached_data.from_json(IO.read(@path, encoding: Encoding::UTF_8))
|
94
|
+
end
|
95
|
+
|
96
|
+
def save(offenses)
|
97
|
+
dir = File.dirname(@path)
|
98
|
+
FileUtils.mkdir_p(dir)
|
99
|
+
preliminary_path = "#{@path}_#{rand(1_000_000_000)}"
|
100
|
+
# RubbyCop must be in control of where its cached data is stored. A
|
101
|
+
# symbolic link anywhere in the cache directory tree can be an
|
102
|
+
# indication that a symlink attack is being waged.
|
103
|
+
return if symlink_protection_triggered?(dir)
|
104
|
+
|
105
|
+
File.open(preliminary_path, 'w', encoding: Encoding::UTF_8) do |f|
|
106
|
+
f.write(@cached_data.to_json(offenses))
|
107
|
+
end
|
108
|
+
# The preliminary path is used so that if there are multiple RubbyCop
|
109
|
+
# processes trying to save data for the same inspected file
|
110
|
+
# simultaneously, the only problem we run in to is a competition who gets
|
111
|
+
# to write to the final file. The contents are the same, so no corruption
|
112
|
+
# of data should occur.
|
113
|
+
FileUtils.mv(preliminary_path, @path)
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def symlink_protection_triggered?(path)
|
119
|
+
!@allow_symlinks_in_cache_location && any_symlink?(path)
|
120
|
+
end
|
121
|
+
|
122
|
+
def any_symlink?(path)
|
123
|
+
while path != File.dirname(path)
|
124
|
+
if File.symlink?(path)
|
125
|
+
warn "Warning: #{path} is a symlink, which is not allowed."
|
126
|
+
return true
|
127
|
+
end
|
128
|
+
path = File.dirname(path)
|
129
|
+
end
|
130
|
+
false
|
131
|
+
end
|
132
|
+
|
133
|
+
def file_checksum(file, config_store)
|
134
|
+
Digest::MD5.hexdigest(Dir.pwd + file + IO.read(file) +
|
135
|
+
config_store.for(file).to_s)
|
136
|
+
rescue Errno::ENOENT
|
137
|
+
# Spurious files that come and go should not cause a crash, at least not
|
138
|
+
# here.
|
139
|
+
'_'
|
140
|
+
end
|
141
|
+
|
142
|
+
class << self
|
143
|
+
attr_accessor :source_checksum, :inhibit_cleanup
|
144
|
+
end
|
145
|
+
|
146
|
+
# The checksum of the rubbycop program running the inspection.
|
147
|
+
def rubbycop_checksum
|
148
|
+
ResultCache.source_checksum ||=
|
149
|
+
begin
|
150
|
+
lib_root = File.join(File.dirname(__FILE__), '..')
|
151
|
+
bin_root = File.join(lib_root, '..', 'bin')
|
152
|
+
|
153
|
+
# These are all the files we have `require`d plus everything in the
|
154
|
+
# bin directory. A change to any of them could affect the cop output
|
155
|
+
# so we include them in the cache hash.
|
156
|
+
source_files = $LOADED_FEATURES + Find.find(bin_root).to_a
|
157
|
+
sources = source_files
|
158
|
+
.select { |path| File.file?(path) }
|
159
|
+
.sort
|
160
|
+
.map { |path| IO.read(path, encoding: Encoding::UTF_8) }
|
161
|
+
Digest::MD5.hexdigest(sources.join)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# Return a hash of the options given at invocation, minus the ones that have
|
166
|
+
# no effect on which offenses and disabled line ranges are found, and thus
|
167
|
+
# don't affect caching.
|
168
|
+
def relevant_options_digest(options)
|
169
|
+
options = options.reject { |key, _| NON_CHANGING.include?(key) }
|
170
|
+
options = options.to_s.gsub(/[^a-z]+/i, '_')
|
171
|
+
# We must avoid making file names too long for some filesystems to handle
|
172
|
+
# If they are short, we can leave them human-readable
|
173
|
+
options.length <= 32 ? options : Digest::MD5.hexdigest(options)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
# This module provides methods that make it easier to test Cops.
|
6
|
+
module CopHelper
|
7
|
+
extend RSpec::SharedContext
|
8
|
+
|
9
|
+
let(:ruby_version) { 2.2 }
|
10
|
+
let(:enabled_rails) { false }
|
11
|
+
let(:rails_version) { false }
|
12
|
+
|
13
|
+
def inspect_source_file(cop, source)
|
14
|
+
Tempfile.open('tmp') { |f| inspect_source(cop, source, f) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def inspect_gemfile(cop, source)
|
18
|
+
inspect_source(cop, source, 'Gemfile')
|
19
|
+
end
|
20
|
+
|
21
|
+
def inspect_source(cop, source, file = nil)
|
22
|
+
if source.is_a?(Array) && source.size == 1
|
23
|
+
raise "Don't use an array for a single line of code: #{source}"
|
24
|
+
end
|
25
|
+
RubbyCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {}
|
26
|
+
RubbyCop::Formatter::DisabledConfigFormatter.detected_styles = {}
|
27
|
+
processed_source = parse_source(source, file)
|
28
|
+
raise 'Error parsing example code' unless processed_source.valid_syntax?
|
29
|
+
_investigate(cop, processed_source)
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_source(source, file = nil)
|
33
|
+
source = source.join($RS) if source.is_a?(Array)
|
34
|
+
|
35
|
+
if file && file.respond_to?(:write)
|
36
|
+
file.write(source)
|
37
|
+
file.rewind
|
38
|
+
file = file.path
|
39
|
+
end
|
40
|
+
|
41
|
+
RubbyCop::ProcessedSource.new(source, ruby_version, file)
|
42
|
+
end
|
43
|
+
|
44
|
+
def autocorrect_source_file(cop, source)
|
45
|
+
Tempfile.open('tmp') { |f| autocorrect_source(cop, source, f) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def autocorrect_source(cop, source, file = nil)
|
49
|
+
cop.instance_variable_get(:@options)[:auto_correct] = true
|
50
|
+
processed_source = parse_source(source, file)
|
51
|
+
_investigate(cop, processed_source)
|
52
|
+
|
53
|
+
corrector =
|
54
|
+
RubbyCop::Cop::Corrector.new(processed_source.buffer, cop.corrections)
|
55
|
+
corrector.rewrite
|
56
|
+
end
|
57
|
+
|
58
|
+
def autocorrect_source_with_loop(cop, source, file = nil)
|
59
|
+
loop do
|
60
|
+
cop.instance_variable_set(:@corrections, [])
|
61
|
+
new_source = autocorrect_source(cop, source, file)
|
62
|
+
return new_source if new_source == source
|
63
|
+
source = new_source
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def _investigate(cop, processed_source)
|
68
|
+
forces = RubbyCop::Cop::Force.all.each_with_object([]) do |klass, instances|
|
69
|
+
next unless cop.join_force?(klass)
|
70
|
+
instances << klass.new([cop])
|
71
|
+
end
|
72
|
+
|
73
|
+
commissioner =
|
74
|
+
RubbyCop::Cop::Commissioner.new([cop], forces, raise_error: true)
|
75
|
+
commissioner.investigate(processed_source)
|
76
|
+
commissioner
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
module RubbyCop
|
81
|
+
module Cop
|
82
|
+
# Monkey-patch Cop for tests to provide easy access to messages and
|
83
|
+
# highlights.
|
84
|
+
class Cop
|
85
|
+
def messages
|
86
|
+
offenses.sort.map(&:message)
|
87
|
+
end
|
88
|
+
|
89
|
+
def highlights
|
90
|
+
offenses.sort.map { |o| o.location.source }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
RSpec.configure do |config|
|
97
|
+
config.include CopHelper
|
98
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# RubbyCop can be run in contexts where unexpected other libraries are included,
|
4
|
+
# which may interfere with its normal behavior. In order to test those
|
5
|
+
# situations, it may be necessary to require another library for the duration
|
6
|
+
# of one spec
|
7
|
+
module HostEnvironmentSimulatorHelper
|
8
|
+
def in_its_own_process_with(*files)
|
9
|
+
if ::Process.respond_to?(:fork)
|
10
|
+
pid = ::Process.fork do
|
11
|
+
# Need to write coverage result under different name
|
12
|
+
if defined?(SimpleCov)
|
13
|
+
SimpleCov.coverage_dir "coverage/ignored_results_#{Process.pid}"
|
14
|
+
SimpleCov.pid = Process.pid
|
15
|
+
end
|
16
|
+
|
17
|
+
files.each { |file| require file }
|
18
|
+
yield
|
19
|
+
end
|
20
|
+
::Process.wait(pid)
|
21
|
+
|
22
|
+
# assert that the block did not fail
|
23
|
+
expect($CHILD_STATUS).to be_success
|
24
|
+
else
|
25
|
+
warn 'Process.fork is not available.'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.include HostEnvironmentSimulatorHelper
|
32
|
+
end
|