rubocop 0.82.0 → 0.86.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/README.md +27 -19
- data/config/default.yml +111 -23
- data/lib/rubocop.rb +16 -59
- data/lib/rubocop/ast_aliases.rb +8 -0
- data/lib/rubocop/cli.rb +3 -3
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +2 -2
- data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
- data/lib/rubocop/cli/command/show_cops.rb +2 -6
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +6 -2
- data/lib/rubocop/config_loader.rb +19 -24
- data/lib/rubocop/config_loader_resolver.rb +45 -6
- data/lib/rubocop/config_store.rb +12 -2
- data/lib/rubocop/config_validator.rb +2 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
- data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
- data/lib/rubocop/cop/commissioner.rb +0 -21
- data/lib/rubocop/cop/cop.rb +36 -21
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -6
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
- data/lib/rubocop/cop/generator.rb +4 -3
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/ignored_node.rb +1 -3
- data/lib/rubocop/cop/layout/case_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/class_structure.rb +19 -16
- data/lib/rubocop/cop/layout/comment_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/condition_position.rb +12 -2
- data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +128 -0
- data/lib/rubocop/cop/layout/end_of_line.rb +3 -3
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -4
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -3
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +7 -7
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +3 -7
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
- data/lib/rubocop/cop/layout/line_length.rb +21 -18
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +13 -4
- data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -3
- data/lib/rubocop/cop/layout/space_around_operators.rb +19 -2
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -4
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -3
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +41 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +14 -0
- data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -5
- data/lib/rubocop/cop/lint/empty_when.rb +29 -6
- data/lib/rubocop/cop/lint/ensure_return.rb +19 -2
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -3
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +38 -2
- data/lib/rubocop/cop/lint/literal_as_condition.rb +10 -13
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +69 -0
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +7 -7
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +33 -11
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +12 -4
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +5 -8
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
- data/lib/rubocop/cop/lint/suppressed_exception.rb +11 -4
- data/lib/rubocop/cop/lint/syntax.rb +1 -3
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +13 -3
- data/lib/rubocop/cop/lint/useless_assignment.rb +3 -2
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
- data/lib/rubocop/cop/migration/department_name.rb +7 -7
- data/lib/rubocop/cop/mixin/alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +2 -4
- data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +10 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +8 -1
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +3 -2
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +1 -1
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +43 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -23
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +3 -3
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
- data/lib/rubocop/cop/naming/file_name.rb +28 -17
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +1 -5
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
- data/lib/rubocop/cop/registry.rb +63 -10
- data/lib/rubocop/cop/severity.rb +1 -3
- data/lib/rubocop/cop/style/and_or.rb +2 -2
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +2 -2
- data/lib/rubocop/cop/style/block_delimiters.rb +4 -12
- data/lib/rubocop/cop/style/case_equality.rb +1 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -4
- data/lib/rubocop/cop/style/copyright.rb +5 -5
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +2 -2
- data/lib/rubocop/cop/style/double_negation.rb +41 -4
- data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
- data/lib/rubocop/cop/style/empty_literal.rb +1 -3
- data/lib/rubocop/cop/style/empty_method.rb +1 -5
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/exponential_notation.rb +5 -5
- data/lib/rubocop/cop/style/format_string_token.rb +2 -3
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -6
- data/lib/rubocop/cop/style/guard_clause.rb +25 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +16 -7
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
- data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
- data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -0
- data/lib/rubocop/cop/style/inline_comment.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
- data/lib/rubocop/cop/style/lambda_call.rb +0 -20
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
- data/lib/rubocop/cop/style/multiline_when_then.rb +16 -1
- data/lib/rubocop/cop/style/negated_if.rb +3 -3
- data/lib/rubocop/cop/style/negated_unless.rb +3 -3
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/non_nil_check.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -6
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/redundant_conditional.rb +4 -3
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +103 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -7
- data/lib/rubocop/cop/style/redundant_percent_q.rb +3 -3
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +89 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +121 -0
- data/lib/rubocop/cop/style/redundant_self.rb +6 -9
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -6
- data/lib/rubocop/cop/style/sample.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +39 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +2 -6
- data/lib/rubocop/cop/style/struct_inheritance.rb +21 -0
- data/lib/rubocop/cop/style/symbol_array.rb +5 -5
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +3 -3
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +3 -3
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +13 -13
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +3 -3
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -3
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
- data/lib/rubocop/cop/team.rb +69 -25
- data/lib/rubocop/cop/util.rb +27 -3
- data/lib/rubocop/cop/utils/format_string.rb +18 -0
- data/lib/rubocop/cop/variable_force.rb +3 -9
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
- data/lib/rubocop/cop/variable_force/branch.rb +1 -3
- data/lib/rubocop/cop/variable_force/scope.rb +1 -0
- data/lib/rubocop/cop/variable_force/variable.rb +3 -6
- data/lib/rubocop/ext/processed_source.rb +18 -0
- data/lib/rubocop/formatter/base_formatter.rb +0 -4
- data/lib/rubocop/formatter/disabled_config_formatter.rb +5 -13
- data/lib/rubocop/formatter/formatter_set.rb +2 -4
- data/lib/rubocop/formatter/junit_formatter.rb +14 -4
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/name_similarity.rb +18 -9
- data/lib/rubocop/options.rb +26 -11
- data/lib/rubocop/path_util.rb +2 -2
- data/lib/rubocop/platform.rb +1 -1
- data/lib/rubocop/remote_config.rb +1 -3
- data/lib/rubocop/result_cache.rb +5 -7
- data/lib/rubocop/rspec/cop_helper.rb +2 -25
- data/lib/rubocop/rspec/expect_offense.rb +58 -15
- data/lib/rubocop/rspec/shared_contexts.rb +54 -16
- data/lib/rubocop/runner.rb +20 -13
- data/lib/rubocop/target_finder.rb +8 -8
- data/lib/rubocop/target_ruby.rb +4 -1
- data/lib/rubocop/version.rb +5 -3
- metadata +51 -74
- data/lib/rubocop/ast/builder.rb +0 -85
- data/lib/rubocop/ast/node.rb +0 -637
- data/lib/rubocop/ast/node/alias_node.rb +0 -24
- data/lib/rubocop/ast/node/and_node.rb +0 -29
- data/lib/rubocop/ast/node/args_node.rb +0 -29
- data/lib/rubocop/ast/node/array_node.rb +0 -70
- data/lib/rubocop/ast/node/block_node.rb +0 -121
- data/lib/rubocop/ast/node/break_node.rb +0 -17
- data/lib/rubocop/ast/node/case_match_node.rb +0 -56
- data/lib/rubocop/ast/node/case_node.rb +0 -56
- data/lib/rubocop/ast/node/class_node.rb +0 -31
- data/lib/rubocop/ast/node/def_node.rb +0 -82
- data/lib/rubocop/ast/node/defined_node.rb +0 -17
- data/lib/rubocop/ast/node/ensure_node.rb +0 -17
- data/lib/rubocop/ast/node/float_node.rb +0 -12
- data/lib/rubocop/ast/node/for_node.rb +0 -53
- data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
- data/lib/rubocop/ast/node/hash_node.rb +0 -109
- data/lib/rubocop/ast/node/if_node.rb +0 -175
- data/lib/rubocop/ast/node/int_node.rb +0 -12
- data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
- data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
- data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
- data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -269
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
- data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
- data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
- data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
- data/lib/rubocop/ast/node/module_node.rb +0 -24
- data/lib/rubocop/ast/node/or_node.rb +0 -29
- data/lib/rubocop/ast/node/pair_node.rb +0 -63
- data/lib/rubocop/ast/node/range_node.rb +0 -18
- data/lib/rubocop/ast/node/regexp_node.rb +0 -33
- data/lib/rubocop/ast/node/resbody_node.rb +0 -24
- data/lib/rubocop/ast/node/retry_node.rb +0 -17
- data/lib/rubocop/ast/node/return_node.rb +0 -24
- data/lib/rubocop/ast/node/self_class_node.rb +0 -24
- data/lib/rubocop/ast/node/send_node.rb +0 -13
- data/lib/rubocop/ast/node/str_node.rb +0 -16
- data/lib/rubocop/ast/node/super_node.rb +0 -21
- data/lib/rubocop/ast/node/symbol_node.rb +0 -12
- data/lib/rubocop/ast/node/until_node.rb +0 -35
- data/lib/rubocop/ast/node/when_node.rb +0 -53
- data/lib/rubocop/ast/node/while_node.rb +0 -35
- data/lib/rubocop/ast/node/yield_node.rb +0 -21
- data/lib/rubocop/ast/sexp.rb +0 -16
- data/lib/rubocop/ast/traversal.rb +0 -202
- data/lib/rubocop/node_pattern.rb +0 -887
- data/lib/rubocop/processed_source.rb +0 -213
- data/lib/rubocop/string_util.rb +0 -14
- data/lib/rubocop/token.rb +0 -114
@@ -87,15 +87,15 @@ module RuboCop
|
|
87
87
|
return false unless token
|
88
88
|
|
89
89
|
if side == :left
|
90
|
-
String(token.space_after?)
|
90
|
+
SINGLE_SPACE_REGEXP.match?(String(token.space_after?))
|
91
91
|
else
|
92
|
-
String(token.space_before?)
|
92
|
+
SINGLE_SPACE_REGEXP.match?(String(token.space_before?))
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
def reposition(src, pos, step)
|
97
97
|
offset = step == -1 ? -1 : 0
|
98
|
-
pos += step while src[pos + offset]
|
98
|
+
pos += step while SINGLE_SPACE_REGEXP.match?(src[pos + offset])
|
99
99
|
pos.negative? ? 0 : pos
|
100
100
|
end
|
101
101
|
|
@@ -4,12 +4,16 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
# Common functionality for checking target ruby version.
|
6
6
|
module TargetRubyVersion
|
7
|
+
def required_minimum_ruby_version
|
8
|
+
@minimum_target_ruby_version
|
9
|
+
end
|
10
|
+
|
7
11
|
def minimum_target_ruby_version(version)
|
8
12
|
@minimum_target_ruby_version = version
|
9
13
|
end
|
10
14
|
|
11
15
|
def support_target_ruby_version?(version)
|
12
|
-
|
16
|
+
required_minimum_ruby_version <= version
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
# If there is any heredoc in items, then match the comma succeeding
|
32
32
|
# any whitespace (except newlines), otherwise allow for newlines
|
33
33
|
comma_regex = any_heredoc?(items) ? /\A[^\S\n]*,/ : /\A\s*,/
|
34
|
-
range.source
|
34
|
+
comma_regex.match?(range.source) && range.source.index(',')
|
35
35
|
end
|
36
36
|
|
37
37
|
def check_comma(node, kind, comma_pos)
|
@@ -184,9 +184,7 @@ module RuboCop
|
|
184
184
|
# ...
|
185
185
|
# SOURCE
|
186
186
|
# })
|
187
|
-
if node.pair_type? || node.hash_type?
|
188
|
-
return heredoc?(node.children.last)
|
189
|
-
end
|
187
|
+
return heredoc?(node.children.last) if node.pair_type? || node.hash_type?
|
190
188
|
|
191
189
|
false
|
192
190
|
end
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
full_name = arg.children.first.to_s
|
19
19
|
next if full_name == '_'
|
20
20
|
|
21
|
-
name = full_name.gsub(/\A(
|
21
|
+
name = full_name.gsub(/\A(_+)/, '')
|
22
22
|
next if (arg.restarg_type? || arg.kwrestarg_type?) && name.empty?
|
23
23
|
next if allowed_names.include?(name)
|
24
24
|
|
@@ -44,7 +44,7 @@ module RuboCop
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def uppercase?(name)
|
47
|
-
|
47
|
+
/[[:upper:]]/.match?(name)
|
48
48
|
end
|
49
49
|
|
50
50
|
def name_type(node)
|
@@ -62,7 +62,7 @@ module RuboCop
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def ends_with_num?(name)
|
65
|
-
name[-1]
|
65
|
+
/\d/.match?(name[-1])
|
66
66
|
end
|
67
67
|
|
68
68
|
def length_offense(node, range)
|
@@ -6,6 +6,12 @@ module RuboCop
|
|
6
6
|
# This cop checks for class and module names with
|
7
7
|
# an underscore in them.
|
8
8
|
#
|
9
|
+
# `AllowedNames` config takes an array of permitted names.
|
10
|
+
# Its default value is `['module_parent']`.
|
11
|
+
# These names can be full class/module names or part of the name.
|
12
|
+
# eg. Adding `my_class` to the `AllowedNames` config will allow names like
|
13
|
+
# `my_class`, `my_class::User`, `App::my_class`, `App::my_class::User`, etc.
|
14
|
+
#
|
9
15
|
# @example
|
10
16
|
# # bad
|
11
17
|
# class My_Class
|
@@ -18,11 +24,15 @@ module RuboCop
|
|
18
24
|
# end
|
19
25
|
# module MyModule
|
20
26
|
# end
|
27
|
+
# class module_parent::MyModule
|
28
|
+
# end
|
21
29
|
class ClassAndModuleCamelCase < Cop
|
22
30
|
MSG = 'Use CamelCase for classes and modules.'
|
23
31
|
|
24
32
|
def on_class(node)
|
25
|
-
|
33
|
+
allowed = /#{cop_config['AllowedNames'].join('|')}/
|
34
|
+
name = node.loc.name.source.gsub(allowed, '')
|
35
|
+
return unless /_/.match?(name)
|
26
36
|
|
27
37
|
add_offense(node, location: :name)
|
28
38
|
end
|
@@ -49,25 +49,36 @@ module RuboCop
|
|
49
49
|
|
50
50
|
def for_bad_filename(file_path)
|
51
51
|
basename = File.basename(file_path)
|
52
|
-
msg = if filename_good?(basename)
|
53
|
-
return if matching_definition?(file_path)
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
if filename_good?(basename)
|
54
|
+
msg = perform_class_and_module_naming_checks(file_path, basename)
|
55
|
+
else
|
56
|
+
msg = other_message(basename) unless bad_filename_allowed?
|
57
|
+
end
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
yield source_range(processed_source.buffer, 1, 0), msg if msg
|
60
|
+
end
|
61
61
|
|
62
|
-
|
62
|
+
def perform_class_and_module_naming_checks(file_path, basename)
|
63
|
+
return unless expect_matching_definition?
|
64
|
+
|
65
|
+
if check_definition_path_hierarchy? &&
|
66
|
+
!matching_definition?(file_path)
|
67
|
+
msg = no_definition_message(basename, file_path)
|
68
|
+
elsif !matching_class?(basename)
|
69
|
+
msg = no_definition_message(basename, basename)
|
70
|
+
end
|
71
|
+
msg
|
63
72
|
end
|
64
73
|
|
65
74
|
def matching_definition?(file_path)
|
66
|
-
return true unless expect_matching_definition?
|
67
|
-
|
68
75
|
find_class_or_module(processed_source.ast, to_namespace(file_path))
|
69
76
|
end
|
70
77
|
|
78
|
+
def matching_class?(file_name)
|
79
|
+
find_class_or_module(processed_source.ast, to_namespace(file_name))
|
80
|
+
end
|
81
|
+
|
71
82
|
def bad_filename_allowed?
|
72
83
|
ignore_executable_scripts? && processed_source.start_with?('#!')
|
73
84
|
end
|
@@ -94,6 +105,10 @@ module RuboCop
|
|
94
105
|
cop_config['ExpectMatchingDefinition']
|
95
106
|
end
|
96
107
|
|
108
|
+
def check_definition_path_hierarchy?
|
109
|
+
cop_config['CheckDefinitionPathHierarchy']
|
110
|
+
end
|
111
|
+
|
97
112
|
def regex
|
98
113
|
cop_config['Regex']
|
99
114
|
end
|
@@ -104,14 +119,13 @@ module RuboCop
|
|
104
119
|
|
105
120
|
def filename_good?(basename)
|
106
121
|
basename = basename.sub(/^\./, '')
|
107
|
-
basename = basename.sub(/\.[
|
122
|
+
basename = basename.sub(/\.[^.]+$/, '')
|
108
123
|
# special handling for Action Pack Variants file names like
|
109
124
|
# some_file.xlsx+mobile.axlsx
|
110
125
|
basename = basename.sub('+', '_')
|
111
|
-
basename
|
126
|
+
basename.match?(regex || SNAKE_CASE)
|
112
127
|
end
|
113
128
|
|
114
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
115
129
|
def find_class_or_module(node, namespace)
|
116
130
|
return nil unless node
|
117
131
|
|
@@ -130,7 +144,6 @@ module RuboCop
|
|
130
144
|
|
131
145
|
nil
|
132
146
|
end
|
133
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
134
147
|
|
135
148
|
def match_namespace(node, namespace, expected)
|
136
149
|
match_partial = partial_matcher!(expected)
|
@@ -153,9 +166,7 @@ module RuboCop
|
|
153
166
|
|
154
167
|
namespace, name = *namespace
|
155
168
|
|
156
|
-
if name == expected.last || match_acronym?(expected.last, name)
|
157
|
-
expected.pop
|
158
|
-
end
|
169
|
+
expected.pop if name == expected.last || match_acronym?(expected.last, name)
|
159
170
|
end
|
160
171
|
|
161
172
|
false
|
@@ -35,15 +35,11 @@ module RuboCop
|
|
35
35
|
|
36
36
|
MSG = 'Use %<style>s for method names.'
|
37
37
|
|
38
|
-
def_node_matcher :attr?, <<~PATTERN
|
39
|
-
(send nil? ${:attr_reader :attr_writer :attr_accessor :attr} $...)
|
40
|
-
PATTERN
|
41
|
-
|
42
38
|
def_node_matcher :sym_name, '(sym $_name)'
|
43
39
|
def_node_matcher :str_name, '(str $_name)'
|
44
40
|
|
45
41
|
def on_send(node)
|
46
|
-
return unless (attrs =
|
42
|
+
return unless (attrs = node.attribute_accessor?)
|
47
43
|
|
48
44
|
attrs.last.each do |name_item|
|
49
45
|
name = attr_name(name_item)
|
@@ -67,7 +67,7 @@ module RuboCop
|
|
67
67
|
private
|
68
68
|
|
69
69
|
def allowed_method_name?(method_name, prefix)
|
70
|
-
!method_name.match(/^#{prefix}[^0-9]/) ||
|
70
|
+
!method_name.match?(/^#{prefix}[^0-9]/) ||
|
71
71
|
method_name == expected_name(method_name, prefix) ||
|
72
72
|
method_name.end_with?('=') ||
|
73
73
|
allowed_methods.include?(method_name)
|
data/lib/rubocop/cop/registry.rb
CHANGED
@@ -22,34 +22,42 @@ module RuboCop
|
|
22
22
|
|
23
23
|
# Registry that tracks all cops by their badge and department.
|
24
24
|
class Registry
|
25
|
+
include Enumerable
|
26
|
+
|
27
|
+
attr_reader :options
|
28
|
+
|
25
29
|
def initialize(cops = [], options = {})
|
26
30
|
@registry = {}
|
27
31
|
@departments = {}
|
28
32
|
@cops_by_cop_name = Hash.new { |hash, key| hash[key] = [] }
|
29
33
|
|
30
|
-
|
34
|
+
@enrollment_queue = cops
|
31
35
|
@options = options
|
32
36
|
end
|
33
37
|
|
34
38
|
def enlist(cop)
|
35
|
-
@
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
@enrollment_queue << cop
|
40
|
+
end
|
41
|
+
|
42
|
+
def dismiss(cop)
|
43
|
+
raise "Cop #{cop} could not be dismissed" unless @enrollment_queue.delete(cop)
|
39
44
|
end
|
40
45
|
|
41
46
|
# @return [Array<Symbol>] list of departments for current cops.
|
42
47
|
def departments
|
48
|
+
clear_enrollment_queue
|
43
49
|
@departments.keys
|
44
50
|
end
|
45
51
|
|
46
52
|
# @return [Registry] Cops for that specific department.
|
47
53
|
def with_department(department)
|
54
|
+
clear_enrollment_queue
|
48
55
|
with(@departments.fetch(department, []))
|
49
56
|
end
|
50
57
|
|
51
58
|
# @return [Registry] Cops not for a specific department.
|
52
59
|
def without_department(department)
|
60
|
+
clear_enrollment_queue
|
53
61
|
without_department = @departments.dup
|
54
62
|
without_department.delete(department)
|
55
63
|
|
@@ -94,9 +102,7 @@ module RuboCop
|
|
94
102
|
# @return [String] Qualified cop name
|
95
103
|
def qualified_cop_name(name, path, shall_warn = true)
|
96
104
|
badge = Badge.parse(name)
|
97
|
-
if shall_warn && department_missing?(badge, name)
|
98
|
-
print_warning(name, path)
|
99
|
-
end
|
105
|
+
print_warning(name, path) if shall_warn && department_missing?(badge, name)
|
100
106
|
return name if registered?(badge)
|
101
107
|
|
102
108
|
potential_badges = qualify_badge(badge)
|
@@ -121,6 +127,7 @@ module RuboCop
|
|
121
127
|
end
|
122
128
|
|
123
129
|
def unqualified_cop_names
|
130
|
+
clear_enrollment_queue
|
124
131
|
@unqualified_cop_names ||=
|
125
132
|
Set.new(@cops_by_cop_name.keys.map { |qn| File.basename(qn) }) <<
|
126
133
|
'RedundantCopDisableDirective'
|
@@ -128,18 +135,21 @@ module RuboCop
|
|
128
135
|
|
129
136
|
# @return [Hash{String => Array<Class>}]
|
130
137
|
def to_h
|
138
|
+
clear_enrollment_queue
|
131
139
|
@cops_by_cop_name
|
132
140
|
end
|
133
141
|
|
134
142
|
def cops
|
143
|
+
clear_enrollment_queue
|
135
144
|
@registry.values
|
136
145
|
end
|
137
146
|
|
138
147
|
def length
|
148
|
+
clear_enrollment_queue
|
139
149
|
@registry.size
|
140
150
|
end
|
141
151
|
|
142
|
-
def enabled(config, only, only_safe = false)
|
152
|
+
def enabled(config, only = [], only_safe = false)
|
143
153
|
select do |cop|
|
144
154
|
only.include?(cop.cop_name) || enabled?(cop, config, only_safe)
|
145
155
|
end
|
@@ -174,6 +184,7 @@ module RuboCop
|
|
174
184
|
end
|
175
185
|
|
176
186
|
def sort!
|
187
|
+
clear_enrollment_queue
|
177
188
|
@registry = Hash[@registry.sort_by { |badge, _| badge.cop_name }]
|
178
189
|
|
179
190
|
self
|
@@ -190,16 +201,57 @@ module RuboCop
|
|
190
201
|
# @param [String] cop_name
|
191
202
|
# @return [Class, nil]
|
192
203
|
def find_by_cop_name(cop_name)
|
193
|
-
|
204
|
+
to_h[cop_name].first
|
205
|
+
end
|
206
|
+
|
207
|
+
@global = new
|
208
|
+
|
209
|
+
class << self
|
210
|
+
attr_reader :global
|
211
|
+
end
|
212
|
+
|
213
|
+
def self.all
|
214
|
+
global.without_department(:Test).cops
|
215
|
+
end
|
216
|
+
|
217
|
+
def self.qualified_cop_name(name, origin)
|
218
|
+
global.qualified_cop_name(name, origin)
|
219
|
+
end
|
220
|
+
|
221
|
+
# Changes momentarily the global registry
|
222
|
+
# Intended for testing purposes
|
223
|
+
def self.with_temporary_global(temp_global = global.dup)
|
224
|
+
previous = @global
|
225
|
+
@global = temp_global
|
226
|
+
yield
|
227
|
+
ensure
|
228
|
+
@global = previous
|
194
229
|
end
|
195
230
|
|
196
231
|
private
|
197
232
|
|
233
|
+
def initialize_copy(reg)
|
234
|
+
initialize(reg.cops, reg.options)
|
235
|
+
end
|
236
|
+
|
237
|
+
def clear_enrollment_queue
|
238
|
+
return if @enrollment_queue.empty?
|
239
|
+
|
240
|
+
@enrollment_queue.each do |cop|
|
241
|
+
@registry[cop.badge] = cop
|
242
|
+
@departments[cop.department] ||= []
|
243
|
+
@departments[cop.department] << cop
|
244
|
+
@cops_by_cop_name[cop.cop_name] << cop
|
245
|
+
end
|
246
|
+
@enrollment_queue = []
|
247
|
+
end
|
248
|
+
|
198
249
|
def with(cops)
|
199
250
|
self.class.new(cops)
|
200
251
|
end
|
201
252
|
|
202
253
|
def qualify_badge(badge)
|
254
|
+
clear_enrollment_queue
|
203
255
|
@departments
|
204
256
|
.map { |department, _| badge.with_department(department) }
|
205
257
|
.select { |potential_badge| registered?(potential_badge) }
|
@@ -216,6 +268,7 @@ module RuboCop
|
|
216
268
|
end
|
217
269
|
|
218
270
|
def registered?(badge)
|
271
|
+
clear_enrollment_queue
|
219
272
|
@registry.key?(badge)
|
220
273
|
end
|
221
274
|
end
|
data/lib/rubocop/cop/severity.rb
CHANGED
@@ -31,9 +31,7 @@ module RuboCop
|
|
31
31
|
# @api private
|
32
32
|
def initialize(name_or_code)
|
33
33
|
name = Severity.name_from_code(name_or_code)
|
34
|
-
unless NAMES.include?(name)
|
35
|
-
raise ArgumentError, "Unknown severity: #{name}"
|
36
|
-
end
|
34
|
+
raise ArgumentError, "Unknown severity: #{name}" unless NAMES.include?(name)
|
37
35
|
|
38
36
|
@name = name.freeze
|
39
37
|
freeze
|
@@ -7,7 +7,7 @@ module RuboCop
|
|
7
7
|
# `||` instead. It can be configured to check only in conditions or in
|
8
8
|
# all contexts.
|
9
9
|
#
|
10
|
-
# @example EnforcedStyle: always
|
10
|
+
# @example EnforcedStyle: always
|
11
11
|
# # bad
|
12
12
|
# foo.save and return
|
13
13
|
#
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
# if foo && bar
|
23
23
|
# end
|
24
24
|
#
|
25
|
-
# @example EnforcedStyle: conditionals
|
25
|
+
# @example EnforcedStyle: conditionals (default)
|
26
26
|
# # bad
|
27
27
|
# if foo and bar
|
28
28
|
# end
|