rubocop 0.93.1 → 1.6.1
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 +36 -16
- data/config/default.yml +276 -82
- data/config/obsoletion.yml +196 -0
- data/exe/rubocop +1 -1
- data/lib/rubocop.rb +31 -2
- data/lib/rubocop/cli.rb +5 -1
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +1 -1
- data/lib/rubocop/cli/command/execute_runner.rb +26 -11
- data/lib/rubocop/cli/command/suggest_extensions.rb +80 -0
- data/lib/rubocop/cli/command/version.rb +1 -1
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +4 -0
- data/lib/rubocop/config_loader.rb +34 -8
- data/lib/rubocop/config_loader_resolver.rb +12 -6
- data/lib/rubocop/config_obsoletion.rb +65 -247
- data/lib/rubocop/config_obsoletion/changed_enforced_styles.rb +33 -0
- data/lib/rubocop/config_obsoletion/changed_parameter.rb +21 -0
- data/lib/rubocop/config_obsoletion/cop_rule.rb +34 -0
- data/lib/rubocop/config_obsoletion/extracted_cop.rb +44 -0
- data/lib/rubocop/config_obsoletion/parameter_rule.rb +44 -0
- data/lib/rubocop/config_obsoletion/removed_cop.rb +41 -0
- data/lib/rubocop/config_obsoletion/renamed_cop.rb +34 -0
- data/lib/rubocop/config_obsoletion/rule.rb +41 -0
- data/lib/rubocop/config_obsoletion/split_cop.rb +27 -0
- data/lib/rubocop/config_regeneration.rb +1 -1
- data/lib/rubocop/config_validator.rb +25 -10
- data/lib/rubocop/cop/autocorrect_logic.rb +21 -6
- data/lib/rubocop/cop/badge.rb +9 -24
- data/lib/rubocop/cop/base.rb +33 -16
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +26 -6
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +37 -23
- data/lib/rubocop/cop/cop.rb +2 -2
- data/lib/rubocop/cop/corrector.rb +3 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +6 -8
- data/lib/rubocop/cop/force.rb +1 -1
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +3 -3
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +4 -5
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator.rb +3 -10
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +1 -1
- data/lib/rubocop/cop/layout/block_alignment.rb +3 -4
- data/lib/rubocop/cop/layout/class_structure.rb +22 -3
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +15 -2
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +80 -10
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +6 -1
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -1
- data/lib/rubocop/cop/layout/end_alignment.rb +3 -3
- data/lib/rubocop/cop/layout/end_of_line.rb +5 -5
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +7 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +4 -4
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +12 -0
- data/lib/rubocop/cop/layout/line_length.rb +10 -13
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +7 -3
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +24 -18
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +4 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +35 -13
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +37 -13
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -1
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +26 -2
- data/lib/rubocop/cop/lint/debugger.rb +17 -28
- data/lib/rubocop/cop/lint/duplicate_branch.rb +93 -0
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +2 -12
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +77 -0
- data/lib/rubocop/cop/lint/else_layout.rb +29 -3
- data/lib/rubocop/cop/lint/empty_block.rb +82 -0
- data/lib/rubocop/cop/lint/empty_class.rb +93 -0
- data/lib/rubocop/cop/lint/flip_flop.rb +8 -2
- data/lib/rubocop/cop/lint/interpolation_check.rb +7 -2
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +39 -7
- data/lib/rubocop/cop/lint/loop.rb +4 -4
- data/lib/rubocop/cop/lint/missing_super.rb +7 -4
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +14 -0
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +58 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +46 -13
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +27 -8
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +19 -16
- data/lib/rubocop/cop/lint/shadowed_exception.rb +4 -5
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +13 -0
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +86 -0
- data/lib/rubocop/cop/lint/to_json.rb +1 -1
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +85 -0
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +199 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -2
- data/lib/rubocop/cop/lint/useless_method_definition.rb +2 -4
- data/lib/rubocop/cop/lint/useless_setter_call.rb +6 -1
- data/lib/rubocop/cop/metrics/abc_size.rb +25 -1
- data/lib/rubocop/cop/metrics/block_length.rb +13 -7
- data/lib/rubocop/cop/metrics/method_length.rb +7 -2
- data/lib/rubocop/cop/metrics/parameter_lists.rb +68 -2
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +20 -10
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +146 -0
- data/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb +6 -1
- data/lib/rubocop/cop/migration/department_name.rb +1 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +4 -3
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +9 -1
- data/lib/rubocop/cop/mixin/ignored_methods.rb +36 -3
- data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +6 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -4
- data/lib/rubocop/cop/mixin/string_help.rb +4 -1
- data/lib/rubocop/cop/mixin/visibility_help.rb +1 -3
- data/lib/rubocop/cop/naming/accessor_method_name.rb +15 -1
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +12 -2
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +11 -5
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +67 -18
- data/lib/rubocop/cop/naming/predicate_name.rb +2 -1
- data/lib/rubocop/cop/naming/variable_number.rb +100 -8
- data/lib/rubocop/cop/offense.rb +3 -3
- data/lib/rubocop/cop/security/open.rb +12 -10
- data/lib/rubocop/cop/style/accessor_grouping.rb +1 -1
- data/lib/rubocop/cop/style/and_or.rb +11 -3
- data/lib/rubocop/cop/style/arguments_forwarding.rb +142 -0
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +0 -4
- data/lib/rubocop/cop/style/case_like_if.rb +0 -4
- data/lib/rubocop/cop/style/character_literal.rb +10 -11
- data/lib/rubocop/cop/style/class_and_module_children.rb +8 -3
- data/lib/rubocop/cop/style/collection_compact.rb +91 -0
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +169 -0
- data/lib/rubocop/cop/style/documentation.rb +12 -1
- data/lib/rubocop/cop/style/double_negation.rb +6 -1
- data/lib/rubocop/cop/style/float_division.rb +44 -1
- data/lib/rubocop/cop/style/format_string.rb +8 -3
- data/lib/rubocop/cop/style/format_string_token.rb +47 -2
- data/lib/rubocop/cop/style/hash_syntax.rb +3 -3
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +7 -2
- data/lib/rubocop/cop/style/if_inside_else.rb +37 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +11 -3
- data/lib/rubocop/cop/style/if_with_semicolon.rb +39 -4
- data/lib/rubocop/cop/style/infinite_loop.rb +4 -0
- data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +12 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +10 -13
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +8 -13
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +7 -11
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +11 -2
- data/lib/rubocop/cop/style/mixin_grouping.rb +0 -4
- data/lib/rubocop/cop/style/multiple_comparison.rb +55 -7
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +106 -0
- data/lib/rubocop/cop/style/nil_lambda.rb +52 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +14 -11
- data/lib/rubocop/cop/style/perl_backrefs.rb +86 -9
- data/lib/rubocop/cop/style/raise_args.rb +21 -6
- data/lib/rubocop/cop/style/redundant_argument.rb +88 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +4 -0
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +7 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +24 -8
- data/lib/rubocop/cop/style/redundant_self.rb +3 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +16 -4
- data/lib/rubocop/cop/style/semicolon.rb +3 -0
- data/lib/rubocop/cop/style/single_line_block_params.rb +30 -7
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +65 -3
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -13
- data/lib/rubocop/cop/style/static_class.rb +97 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +39 -2
- data/lib/rubocop/cop/style/string_literals.rb +14 -8
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +4 -3
- data/lib/rubocop/cop/style/swap_values.rb +108 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +5 -3
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +3 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +9 -0
- data/lib/rubocop/cop/team.rb +6 -1
- data/lib/rubocop/cop/util.rb +6 -2
- data/lib/rubocop/cop/variable_force/branch.rb +1 -1
- data/lib/rubocop/cop/variable_force/scope.rb +1 -1
- data/lib/rubocop/core_ext/hash.rb +20 -0
- data/lib/rubocop/ext/regexp_node.rb +36 -11
- data/lib/rubocop/ext/regexp_parser.rb +95 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +21 -6
- data/lib/rubocop/formatter/emacs_style_formatter.rb +2 -0
- data/lib/rubocop/formatter/formatter_set.rb +2 -1
- data/lib/rubocop/formatter/git_hub_actions_formatter.rb +47 -0
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +2 -0
- data/lib/rubocop/formatter/tap_formatter.rb +2 -0
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
- data/lib/rubocop/lockfile.rb +40 -0
- data/lib/rubocop/magic_comment.rb +2 -2
- data/lib/rubocop/options.rb +11 -1
- data/lib/rubocop/rake_task.rb +2 -2
- data/lib/rubocop/rspec/shared_contexts.rb +4 -0
- data/lib/rubocop/runner.rb +1 -1
- data/lib/rubocop/target_finder.rb +1 -1
- data/lib/rubocop/target_ruby.rb +65 -1
- data/lib/rubocop/version.rb +56 -6
- metadata +50 -9
- data/bin/console +0 -10
- data/bin/rubocop-profile +0 -32
- data/bin/setup +0 -7
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class ConfigObsoletion
|
5
|
+
# Encapsulation of a ConfigObsoletion rule for changing a parameter
|
6
|
+
# @api private
|
7
|
+
class ChangedEnforcedStyles < ParameterRule
|
8
|
+
BASE_MESSAGE = 'obsolete `%<parameter>s: %<value>s` (for `%<cop>s`) found in %<path>s'
|
9
|
+
|
10
|
+
def violated?
|
11
|
+
super && config[cop][parameter] == value
|
12
|
+
end
|
13
|
+
|
14
|
+
def message
|
15
|
+
base = format(BASE_MESSAGE,
|
16
|
+
parameter: parameter, value: value, cop: cop, path: smart_loaded_path)
|
17
|
+
|
18
|
+
if alternative
|
19
|
+
"#{base}\n`#{parameter}: #{value}` has been renamed to " \
|
20
|
+
"`#{parameter}: #{alternative.chomp}`."
|
21
|
+
else
|
22
|
+
"#{base}\n#{reason.chomp}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def value
|
29
|
+
metadata['value']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class ConfigObsoletion
|
5
|
+
# Encapsulation of a ConfigObsoletion rule for changing a parameter
|
6
|
+
# @api private
|
7
|
+
class ChangedParameter < ParameterRule
|
8
|
+
BASE_MESSAGE = 'obsolete parameter `%<parameter>s` (for `%<cop>s`) found in %<path>s'
|
9
|
+
|
10
|
+
def message
|
11
|
+
base = format(BASE_MESSAGE, parameter: parameter, cop: cop, path: smart_loaded_path)
|
12
|
+
|
13
|
+
if alternative
|
14
|
+
"#{base}\n`#{parameter}` has been renamed to `#{alternative.chomp}`."
|
15
|
+
else
|
16
|
+
"#{base}\n#{reason.chomp}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class ConfigObsoletion
|
5
|
+
# Base class for ConfigObsoletion rules relating to cops
|
6
|
+
# @api private
|
7
|
+
class CopRule < Rule
|
8
|
+
attr_reader :old_name
|
9
|
+
|
10
|
+
def initialize(config, old_name)
|
11
|
+
super(config)
|
12
|
+
@old_name = old_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def cop_rule?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def message
|
20
|
+
rule_message + "\n(obsolete configuration found in " \
|
21
|
+
"#{smart_loaded_path}, please update it)"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Cop rules currently can only be failures, not warnings
|
25
|
+
def warning?
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
def violated?
|
30
|
+
config.key?(old_name) || config.key?(Cop::Badge.parse(old_name).cop_name)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class ConfigObsoletion
|
5
|
+
# Encapsulation of a ConfigObsoletion rule for splitting a cop's
|
6
|
+
# functionality into multiple new cops.
|
7
|
+
# @api private
|
8
|
+
class ExtractedCop < CopRule
|
9
|
+
attr_reader :gem, :department
|
10
|
+
|
11
|
+
def initialize(config, old_name, gem)
|
12
|
+
super(config, old_name)
|
13
|
+
@department, * = old_name.rpartition('/')
|
14
|
+
@gem = gem
|
15
|
+
end
|
16
|
+
|
17
|
+
def violated?
|
18
|
+
return false if feature_loaded?
|
19
|
+
|
20
|
+
affected_cops.any?
|
21
|
+
end
|
22
|
+
|
23
|
+
def rule_message
|
24
|
+
msg = '%<name>s been extracted to the `%<gem>s` gem.'
|
25
|
+
format(msg,
|
26
|
+
name: affected_cops.size > 1 ? "`#{department}` cops have" : "`#{old_name}` has",
|
27
|
+
gem: gem)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def affected_cops
|
33
|
+
return old_name unless old_name.end_with?('*')
|
34
|
+
|
35
|
+
# Handle whole departments (expressed as `Department/*`)
|
36
|
+
config.keys.grep(Regexp.new("^#{department}"))
|
37
|
+
end
|
38
|
+
|
39
|
+
def feature_loaded?
|
40
|
+
config.loaded_features.include?(gem)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class ConfigObsoletion
|
5
|
+
# Base class for ConfigObsoletion rules relating to parameters
|
6
|
+
# @api private
|
7
|
+
class ParameterRule < Rule
|
8
|
+
attr_reader :cop, :parameter, :metadata
|
9
|
+
|
10
|
+
def initialize(config, cop, parameter, metadata)
|
11
|
+
super(config)
|
12
|
+
@cop = cop
|
13
|
+
@parameter = parameter
|
14
|
+
@metadata = metadata
|
15
|
+
end
|
16
|
+
|
17
|
+
def parameter_rule?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def violated?
|
22
|
+
config[cop]&.key?(parameter)
|
23
|
+
end
|
24
|
+
|
25
|
+
def warning?
|
26
|
+
severity == 'warning'
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def alternative
|
32
|
+
metadata['alternative']
|
33
|
+
end
|
34
|
+
|
35
|
+
def reason
|
36
|
+
metadata['reason']
|
37
|
+
end
|
38
|
+
|
39
|
+
def severity
|
40
|
+
metadata['severity']
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class ConfigObsoletion
|
5
|
+
# Encapsulation of a ConfigObsoletion rule for removing
|
6
|
+
# a previously defined cop.
|
7
|
+
# @api private
|
8
|
+
class RemovedCop < CopRule
|
9
|
+
attr_reader :old_name, :metadata
|
10
|
+
|
11
|
+
BASE_MESSAGE = 'The `%<old_name>s` cop has been removed'
|
12
|
+
|
13
|
+
def initialize(config, old_name, metadata)
|
14
|
+
super(config, old_name)
|
15
|
+
@metadata = metadata.is_a?(Hash) ? metadata : {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def rule_message
|
19
|
+
base = format(BASE_MESSAGE, old_name: old_name)
|
20
|
+
|
21
|
+
if reason
|
22
|
+
"#{base} since #{reason.chomp}."
|
23
|
+
elsif alternatives
|
24
|
+
"#{base}. Please use #{to_sentence(alternatives, connector: 'and/or')} instead."
|
25
|
+
else
|
26
|
+
"#{base}."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def reason
|
33
|
+
metadata['reason']
|
34
|
+
end
|
35
|
+
|
36
|
+
def alternatives
|
37
|
+
Array(metadata['alternatives']).map { |name| "`#{name}`" }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class ConfigObsoletion
|
5
|
+
# Encapsulation of a ConfigObsoletion rule for renaming
|
6
|
+
# a cop or moving it to a new department.
|
7
|
+
# @api private
|
8
|
+
class RenamedCop < CopRule
|
9
|
+
attr_reader :new_name
|
10
|
+
|
11
|
+
def initialize(config, old_name, new_name)
|
12
|
+
super(config, old_name)
|
13
|
+
@new_name = new_name
|
14
|
+
end
|
15
|
+
|
16
|
+
def rule_message
|
17
|
+
"The `#{old_name}` cop has been #{verb} to `#{new_name}`."
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def moved?
|
23
|
+
old_badge = Cop::Badge.parse(old_name)
|
24
|
+
new_badge = Cop::Badge.parse(new_name)
|
25
|
+
|
26
|
+
old_badge.department != new_badge.department && old_badge.cop_name == new_badge.cop_name
|
27
|
+
end
|
28
|
+
|
29
|
+
def verb
|
30
|
+
moved? ? 'moved' : 'renamed'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class ConfigObsoletion
|
5
|
+
# Abstract base class for ConfigObsoletion rules
|
6
|
+
# @api private
|
7
|
+
class Rule
|
8
|
+
def initialize(config)
|
9
|
+
@config = config
|
10
|
+
end
|
11
|
+
|
12
|
+
# Does this rule relate to cops?
|
13
|
+
def cop_rule?
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
# Does this rule relate to parameters?
|
18
|
+
def parameter_rule?
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
def violated?
|
23
|
+
raise NotImplementedError
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :config
|
29
|
+
|
30
|
+
def to_sentence(collection, connector: 'and')
|
31
|
+
return collection.first if collection.size == 1
|
32
|
+
|
33
|
+
[collection[0..-2].join(', '), collection[-1]].join(" #{connector} ")
|
34
|
+
end
|
35
|
+
|
36
|
+
def smart_loaded_path
|
37
|
+
PathUtil.smart_path(config.loaded_path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class ConfigObsoletion
|
5
|
+
# Encapsulation of a ConfigObsoletion rule for splitting a cop's
|
6
|
+
# functionality into multiple new cops.
|
7
|
+
# @api private
|
8
|
+
class SplitCop < CopRule
|
9
|
+
attr_reader :metadata
|
10
|
+
|
11
|
+
def initialize(config, old_name, metadata)
|
12
|
+
super(config, old_name)
|
13
|
+
@metadata = metadata
|
14
|
+
end
|
15
|
+
|
16
|
+
def rule_message
|
17
|
+
"The `#{old_name}` cop has been split into #{to_sentence(alternatives)}."
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def alternatives
|
23
|
+
Array(metadata['alternatives']).map { |name| "`#{name}`" }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -18,6 +18,11 @@ module RuboCop
|
|
18
18
|
# @api private
|
19
19
|
NEW_COPS_VALUES = %w[pending disable enable].freeze
|
20
20
|
|
21
|
+
# @api private
|
22
|
+
CONFIG_CHECK_KEYS = %w[Enabled Safe SafeAutoCorrect AutoCorrect].to_set.freeze
|
23
|
+
CONFIG_CHECK_DEPARTMENTS = %w[pending override_department].freeze
|
24
|
+
private_constant :CONFIG_CHECK_KEYS, :CONFIG_CHECK_DEPARTMENTS
|
25
|
+
|
21
26
|
def_delegators :@config, :smart_loaded_path, :for_all_cops
|
22
27
|
|
23
28
|
def initialize(config)
|
@@ -37,7 +42,7 @@ module RuboCop
|
|
37
42
|
ConfigLoader.default_configuration.key?(key)
|
38
43
|
end
|
39
44
|
|
40
|
-
|
45
|
+
check_obsoletions
|
41
46
|
|
42
47
|
alert_about_unrecognized_cops(invalid_cop_names)
|
43
48
|
check_target_ruby
|
@@ -63,6 +68,13 @@ module RuboCop
|
|
63
68
|
|
64
69
|
attr_reader :target_ruby
|
65
70
|
|
71
|
+
def check_obsoletions
|
72
|
+
@config_obsoletion.reject_obsolete!
|
73
|
+
return unless @config_obsoletion.warnings.any?
|
74
|
+
|
75
|
+
warn Rainbow("Warning: #{@config_obsoletion.warnings.join("\n")}").yellow
|
76
|
+
end
|
77
|
+
|
66
78
|
def check_target_ruby
|
67
79
|
return if target_ruby.supported?
|
68
80
|
|
@@ -94,10 +106,17 @@ module RuboCop
|
|
94
106
|
# to do so than to pass the value around to various methods.
|
95
107
|
next if name == 'inherit_mode'
|
96
108
|
|
97
|
-
|
98
|
-
|
109
|
+
suggestions = NameSimilarity.find_similar_names(name, Cop::Registry.global.map(&:cop_name))
|
110
|
+
suggestion = "Did you mean `#{suggestions.join('`, `')}`?" if suggestions.any?
|
111
|
+
|
112
|
+
message = <<~MESSAGE.rstrip
|
113
|
+
unrecognized cop #{name} found in #{smart_loaded_path}
|
114
|
+
#{suggestion}
|
115
|
+
MESSAGE
|
116
|
+
|
117
|
+
unknown_cops << message
|
99
118
|
end
|
100
|
-
raise ValidationError, unknown_cops.join(
|
119
|
+
raise ValidationError, unknown_cops.join("\n") if unknown_cops.any?
|
101
120
|
end
|
102
121
|
|
103
122
|
def validate_syntax_cop
|
@@ -202,13 +221,9 @@ module RuboCop
|
|
202
221
|
hash.each do |key, value|
|
203
222
|
check_cop_config_value(value, key) if value.is_a?(Hash)
|
204
223
|
|
205
|
-
next unless
|
206
|
-
Safe
|
207
|
-
SafeAutoCorrect
|
208
|
-
AutoCorrect].include?(key) && value.is_a?(String)
|
224
|
+
next unless CONFIG_CHECK_KEYS.include?(key) && value.is_a?(String)
|
209
225
|
|
210
|
-
next if key == 'Enabled' &&
|
211
|
-
%w[pending override_department].include?(value)
|
226
|
+
next if key == 'Enabled' && CONFIG_CHECK_DEPARTMENTS.include?(value)
|
212
227
|
|
213
228
|
raise ValidationError, msg_not_boolean(parent, key, value)
|
214
229
|
end
|
@@ -39,16 +39,31 @@ module RuboCop
|
|
39
39
|
private
|
40
40
|
|
41
41
|
def disable_offense(range)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
disable_offense_at_end_of_line(range_of_first_line(range),
|
46
|
-
eol_comment)
|
42
|
+
heredoc_range = surrounding_heredoc(range)
|
43
|
+
if heredoc_range
|
44
|
+
disable_offense_before_and_after(range_by_lines(heredoc_range))
|
47
45
|
else
|
48
|
-
|
46
|
+
eol_comment = " # rubocop:todo #{cop_name}"
|
47
|
+
needed_line_length = (range.source_line + eol_comment).length
|
48
|
+
if needed_line_length <= max_line_length
|
49
|
+
disable_offense_at_end_of_line(range_of_first_line(range), eol_comment)
|
50
|
+
else
|
51
|
+
disable_offense_before_and_after(range_by_lines(range))
|
52
|
+
end
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
56
|
+
def surrounding_heredoc(offense_range)
|
57
|
+
# The empty offense range is an edge case that can be reached from the Lint/Syntax cop.
|
58
|
+
return nil if offense_range.empty?
|
59
|
+
|
60
|
+
heredoc_nodes = processed_source.ast.each_descendant.select do |node|
|
61
|
+
node.respond_to?(:heredoc?) && node.heredoc?
|
62
|
+
end
|
63
|
+
heredoc_nodes.map { |node| node.loc.expression.join(node.loc.heredoc_end) }
|
64
|
+
.find { |range| range.contains?(offense_range) }
|
65
|
+
end
|
66
|
+
|
52
67
|
def range_of_first_line(range)
|
53
68
|
begin_of_first_line = range.begin_pos - range.column
|
54
69
|
end_of_first_line = begin_of_first_line + range.source_line.length
|