rubocop 0.76.0 → 0.80.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +4 -4
- data/config/default.yml +325 -283
- data/lib/rubocop.rb +43 -23
- data/lib/rubocop/ast/builder.rb +43 -42
- data/lib/rubocop/ast/node.rb +1 -13
- data/lib/rubocop/ast/node/block_node.rb +2 -0
- data/lib/rubocop/ast/node/def_node.rb +11 -0
- data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
- data/lib/rubocop/ast/node/regexp_node.rb +2 -4
- data/lib/rubocop/ast/traversal.rb +20 -3
- data/lib/rubocop/cli.rb +11 -230
- data/lib/rubocop/cli/command.rb +21 -0
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
- data/lib/rubocop/cli/command/base.rb +33 -0
- data/lib/rubocop/cli/command/execute_runner.rb +76 -0
- data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
- data/lib/rubocop/cli/command/show_cops.rb +80 -0
- data/lib/rubocop/cli/command/version.rb +17 -0
- data/lib/rubocop/cli/environment.rb +21 -0
- data/lib/rubocop/comment_config.rb +6 -1
- data/lib/rubocop/config.rb +28 -10
- data/lib/rubocop/config_loader.rb +19 -19
- data/lib/rubocop/config_obsoletion.rb +65 -11
- data/lib/rubocop/config_validator.rb +56 -98
- data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
- data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
- data/lib/rubocop/cop/cop.rb +21 -0
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/generator.rb +3 -4
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
- data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +5 -5
- data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
- data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +3 -3
- data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
- data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +10 -6
- data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +5 -5
- data/lib/rubocop/cop/layout/leading_comment_space.rb +33 -2
- data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/{metrics → layout}/line_length.rb +67 -108
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +0 -4
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +50 -7
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +8 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -9
- data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
- data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +13 -8
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
- data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
- data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
- data/lib/rubocop/cop/lint/useless_setter_call.rb +5 -1
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/migration/department_name.rb +30 -2
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +4 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +7 -7
- data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +171 -0
- data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
- data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
- data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -12
- data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +4 -4
- data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
- data/lib/rubocop/cop/offense.rb +11 -0
- data/lib/rubocop/cop/registry.rb +7 -2
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +8 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +89 -11
- data/lib/rubocop/cop/style/guard_clause.rb +3 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +87 -0
- data/lib/rubocop/cop/style/hash_transform_keys.rb +79 -0
- data/lib/rubocop/cop/style/hash_transform_values.rb +79 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +38 -3
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +8 -4
- data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -205
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +169 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +5 -1
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +7 -7
- data/lib/rubocop/cop/style/next.rb +5 -5
- data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
- data/lib/rubocop/cop/style/numeric_predicate.rb +4 -3
- data/lib/rubocop/cop/style/option_hash.rb +3 -3
- data/lib/rubocop/cop/style/or_assignment.rb +3 -2
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
- data/lib/rubocop/cop/style/redundant_condition.rb +17 -4
- data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
- data/lib/rubocop/cop/style/redundant_return.rb +2 -8
- data/lib/rubocop/cop/style/redundant_sort.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +0 -22
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
- data/lib/rubocop/cop/team.rb +5 -0
- data/lib/rubocop/cop/variable_force.rb +4 -1
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -3
- data/lib/rubocop/formatter/formatter_set.rb +1 -0
- data/lib/rubocop/formatter/json_formatter.rb +6 -5
- data/lib/rubocop/formatter/junit_formatter.rb +63 -0
- data/lib/rubocop/formatter/tap_formatter.rb +1 -3
- data/lib/rubocop/node_pattern.rb +97 -11
- data/lib/rubocop/options.rb +8 -8
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/rake_task.rb +1 -0
- data/lib/rubocop/result_cache.rb +23 -7
- data/lib/rubocop/rspec/shared_contexts.rb +5 -0
- data/lib/rubocop/runner.rb +18 -2
- data/lib/rubocop/target_ruby.rb +151 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +60 -27
- data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class CLI
|
5
|
+
module Command
|
6
|
+
# Run all the selected cops and report the result.
|
7
|
+
class ExecuteRunner < Base
|
8
|
+
include Formatter::TextUtil
|
9
|
+
|
10
|
+
self.command_name = :execute_runner
|
11
|
+
|
12
|
+
def run
|
13
|
+
execute_runner(@paths)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def execute_runner(paths)
|
19
|
+
runner = Runner.new(@options, @config_store)
|
20
|
+
|
21
|
+
all_passed = runner.run(paths)
|
22
|
+
display_warning_summary(runner.warnings)
|
23
|
+
display_error_summary(runner.errors)
|
24
|
+
maybe_print_corrected_source
|
25
|
+
|
26
|
+
all_pass_or_excluded = all_passed || @options[:auto_gen_config]
|
27
|
+
|
28
|
+
if runner.aborting?
|
29
|
+
STATUS_INTERRUPTED
|
30
|
+
elsif all_pass_or_excluded && runner.errors.empty?
|
31
|
+
STATUS_SUCCESS
|
32
|
+
else
|
33
|
+
STATUS_OFFENSES
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def display_warning_summary(warnings)
|
38
|
+
return if warnings.empty?
|
39
|
+
|
40
|
+
warn Rainbow("\n#{pluralize(warnings.size, 'warning')}:").yellow
|
41
|
+
|
42
|
+
warnings.each { |warning| warn warning }
|
43
|
+
end
|
44
|
+
|
45
|
+
def display_error_summary(errors)
|
46
|
+
return if errors.empty?
|
47
|
+
|
48
|
+
warn Rainbow("\n#{pluralize(errors.size, 'error')} occurred:").red
|
49
|
+
|
50
|
+
errors.each { |error| warn error }
|
51
|
+
|
52
|
+
warn <<~WARNING
|
53
|
+
Errors are usually caused by RuboCop bugs.
|
54
|
+
Please, report your problems to RuboCop's issue tracker.
|
55
|
+
#{Gem.loaded_specs['rubocop'].metadata['bug_tracker_uri']}
|
56
|
+
|
57
|
+
Mention the following information in the issue report:
|
58
|
+
#{RuboCop::Version.version(true)}
|
59
|
+
WARNING
|
60
|
+
end
|
61
|
+
|
62
|
+
def maybe_print_corrected_source
|
63
|
+
# If we are asked to autocorrect source code read from stdin, the only
|
64
|
+
# reasonable place to write it is to stdout
|
65
|
+
# Unfortunately, we also write other information to stdout
|
66
|
+
# So a delimiter is needed for tools to easily identify where the
|
67
|
+
# autocorrected source begins
|
68
|
+
return unless @options[:stdin] && @options[:auto_correct]
|
69
|
+
|
70
|
+
puts '=' * 20
|
71
|
+
print @options[:stdin]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class CLI
|
5
|
+
module Command
|
6
|
+
# Generate a .rubocop.yml file in the current directory.
|
7
|
+
class InitDotfile < Base
|
8
|
+
DOTFILE = ConfigLoader::DOTFILE
|
9
|
+
|
10
|
+
self.command_name = :init
|
11
|
+
|
12
|
+
def run
|
13
|
+
path = File.expand_path(DOTFILE)
|
14
|
+
|
15
|
+
if File.exist?(DOTFILE)
|
16
|
+
warn Rainbow("#{DOTFILE} already exists at #{path}").red
|
17
|
+
|
18
|
+
STATUS_ERROR
|
19
|
+
else
|
20
|
+
description = <<~DESC
|
21
|
+
# The behavior of RuboCop can be controlled via the .rubocop.yml
|
22
|
+
# configuration file. It makes it possible to enable/disable
|
23
|
+
# certain cops (checks) and to alter their behavior if they accept
|
24
|
+
# any parameters. The file can be placed either in your home
|
25
|
+
# directory or in some project directory.
|
26
|
+
#
|
27
|
+
# RuboCop will start looking for the configuration file in the directory
|
28
|
+
# where the inspected file is and continue its way up to the root directory.
|
29
|
+
#
|
30
|
+
# See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
|
31
|
+
DESC
|
32
|
+
|
33
|
+
File.open(DOTFILE, 'w') do |f|
|
34
|
+
f.write(description)
|
35
|
+
end
|
36
|
+
|
37
|
+
puts "Writing new #{DOTFILE} to #{path}"
|
38
|
+
|
39
|
+
STATUS_SUCCESS
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class CLI
|
5
|
+
module Command
|
6
|
+
# Shows the given cops, or all cops by default, and their configurations
|
7
|
+
# for the current directory.
|
8
|
+
class ShowCops < Base
|
9
|
+
self.command_name = :show_cops
|
10
|
+
|
11
|
+
def initialize(env)
|
12
|
+
super
|
13
|
+
|
14
|
+
# Load the configs so the require()s are done for custom cops
|
15
|
+
@config = @config_store.for(Dir.pwd)
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
print_available_cops
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def print_available_cops
|
25
|
+
registry = Cop::Cop.registry
|
26
|
+
show_all = @options[:show_cops].empty?
|
27
|
+
|
28
|
+
if show_all
|
29
|
+
puts "# Available cops (#{registry.length}) " \
|
30
|
+
"+ config for #{Dir.pwd}: "
|
31
|
+
end
|
32
|
+
|
33
|
+
registry.departments.sort!.each do |department|
|
34
|
+
print_cops_of_department(registry, department, show_all)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def print_cops_of_department(registry, department, show_all)
|
39
|
+
selected_cops = if show_all
|
40
|
+
cops_of_department(registry, department)
|
41
|
+
else
|
42
|
+
selected_cops_of_department(registry, department)
|
43
|
+
end
|
44
|
+
|
45
|
+
if show_all
|
46
|
+
puts "# Department '#{department}' (#{selected_cops.length}):"
|
47
|
+
end
|
48
|
+
|
49
|
+
print_cop_details(selected_cops)
|
50
|
+
end
|
51
|
+
|
52
|
+
def print_cop_details(cops)
|
53
|
+
cops.each do |cop|
|
54
|
+
if cop.new(@config).support_autocorrect?
|
55
|
+
puts '# Supports --auto-correct'
|
56
|
+
end
|
57
|
+
puts "#{cop.cop_name}:"
|
58
|
+
puts config_lines(cop)
|
59
|
+
puts
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def selected_cops_of_department(cops, department)
|
64
|
+
cops_of_department(cops, department).select do |cop|
|
65
|
+
@options[:show_cops].include?(cop.cop_name)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def cops_of_department(cops, department)
|
70
|
+
cops.with_department(department).sort!
|
71
|
+
end
|
72
|
+
|
73
|
+
def config_lines(cop)
|
74
|
+
cnf = @config.for_cop(cop)
|
75
|
+
cnf.to_yaml.lines.to_a.drop(1).map { |line| ' ' + line }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class CLI
|
5
|
+
module Command
|
6
|
+
# Display version.
|
7
|
+
class Version < Base
|
8
|
+
self.command_name = :version
|
9
|
+
|
10
|
+
def run
|
11
|
+
puts RuboCop::Version.version(false) if @options[:version]
|
12
|
+
puts RuboCop::Version.version(true) if @options[:verbose_version]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class CLI
|
5
|
+
# Execution environment for a CLI command.
|
6
|
+
class Environment
|
7
|
+
attr_reader :options, :config_store, :paths
|
8
|
+
|
9
|
+
def initialize(options, config_store, paths)
|
10
|
+
@options = options
|
11
|
+
@config_store = config_store
|
12
|
+
@paths = paths
|
13
|
+
end
|
14
|
+
|
15
|
+
# Run a command in this environment.
|
16
|
+
def run(name)
|
17
|
+
Command.run(self, name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -113,7 +113,8 @@ module RuboCop
|
|
113
113
|
def each_mentioned_cop
|
114
114
|
each_directive do |comment, cop_names, disabled|
|
115
115
|
comment_line_number = comment.loc.expression.line
|
116
|
-
single_line = !comment_only_line?(comment_line_number)
|
116
|
+
single_line = !comment_only_line?(comment_line_number) ||
|
117
|
+
directive_on_comment_line?(comment)
|
117
118
|
|
118
119
|
cop_names.each do |cop_name|
|
119
120
|
yield qualified_cop_name(cop_name), disabled, comment_line_number,
|
@@ -122,6 +123,10 @@ module RuboCop
|
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
126
|
+
def directive_on_comment_line?(comment)
|
127
|
+
comment.text[1..-1].match(COMMENT_DIRECTIVE_REGEXP)
|
128
|
+
end
|
129
|
+
|
125
130
|
def each_directive
|
126
131
|
return if processed_source.comments.nil?
|
127
132
|
|
data/lib/rubocop/config.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'pathname'
|
4
4
|
|
5
|
+
# FIXME: Moving Rails department code to RuboCop Rails will remove
|
6
|
+
# the following rubocop:disable comment.
|
7
|
+
# rubocop:disable Metrics/ClassLength
|
5
8
|
module RuboCop
|
6
9
|
# This class represents the configuration of the RuboCop application
|
7
10
|
# and all its cops. A Config is associated with a YAML configuration
|
@@ -13,6 +16,8 @@ module RuboCop
|
|
13
16
|
include FileFinder
|
14
17
|
extend Forwardable
|
15
18
|
|
19
|
+
CopConfig = Struct.new(:name, :metadata)
|
20
|
+
|
16
21
|
DEFAULT_RAILS_VERSION = 5.0
|
17
22
|
attr_reader :loaded_path
|
18
23
|
|
@@ -115,7 +120,7 @@ module RuboCop
|
|
115
120
|
relative_file_path = path_relative_to_config(file)
|
116
121
|
|
117
122
|
# Optimization to quickly decide if the given file is hidden (on the top
|
118
|
-
# level) and
|
123
|
+
# level) and cannot be matched by any pattern.
|
119
124
|
is_hidden = relative_file_path.start_with?('.') &&
|
120
125
|
!relative_file_path.start_with?('..')
|
121
126
|
return false if is_hidden && !possibly_include_hidden?
|
@@ -215,6 +220,18 @@ module RuboCop
|
|
215
220
|
nil
|
216
221
|
end
|
217
222
|
|
223
|
+
def pending_cops
|
224
|
+
keys.each_with_object([]) do |qualified_cop_name, pending_cops|
|
225
|
+
department = department_of(qualified_cop_name)
|
226
|
+
next if department && department['Enabled'] == false
|
227
|
+
|
228
|
+
cop_metadata = self[qualified_cop_name]
|
229
|
+
next unless cop_metadata['Enabled'] == 'pending'
|
230
|
+
|
231
|
+
pending_cops << CopConfig.new(qualified_cop_name, cop_metadata)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
218
235
|
private
|
219
236
|
|
220
237
|
def target_rails_version_from_bundler_lock_file
|
@@ -235,17 +252,18 @@ module RuboCop
|
|
235
252
|
end
|
236
253
|
|
237
254
|
def enable_cop?(qualified_cop_name, cop_options)
|
238
|
-
|
239
|
-
department
|
240
|
-
|
241
|
-
unless department
|
242
|
-
department_options = self[cop_department]
|
243
|
-
if department_options && department_options['Enabled'] == false
|
244
|
-
return false
|
245
|
-
end
|
246
|
-
end
|
255
|
+
department = department_of(qualified_cop_name)
|
256
|
+
return false if department && department['Enabled'] == false
|
247
257
|
|
248
258
|
cop_options.fetch('Enabled') { !for_all_cops['DisabledByDefault'] }
|
249
259
|
end
|
260
|
+
|
261
|
+
def department_of(qualified_cop_name)
|
262
|
+
cop_department, cop_name = qualified_cop_name.split('/')
|
263
|
+
return nil if cop_name.nil?
|
264
|
+
|
265
|
+
self[cop_department]
|
266
|
+
end
|
250
267
|
end
|
251
268
|
end
|
269
|
+
# rubocop:enable Metrics/ClassLength
|
@@ -91,7 +91,9 @@ module RuboCop
|
|
91
91
|
else
|
92
92
|
add_excludes_from_files(config, config_file)
|
93
93
|
end
|
94
|
-
merge_with_default(config, config_file)
|
94
|
+
merge_with_default(config, config_file).tap do |merged_config|
|
95
|
+
warn_on_pending_cops(merged_config.pending_cops)
|
96
|
+
end
|
95
97
|
end
|
96
98
|
|
97
99
|
def add_excludes_from_files(config, config_file)
|
@@ -114,6 +116,22 @@ module RuboCop
|
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
119
|
+
def warn_on_pending_cops(pending_cops)
|
120
|
+
return if pending_cops.empty?
|
121
|
+
|
122
|
+
warn Rainbow('The following cops were added to RuboCop, but are not ' \
|
123
|
+
'configured. Please set Enabled to either `true` or ' \
|
124
|
+
'`false` in your `.rubocop.yml` file:').yellow
|
125
|
+
|
126
|
+
pending_cops.each do |cop|
|
127
|
+
warn Rainbow(
|
128
|
+
" - #{cop.name} (#{cop.metadata['VersionAdded']})"
|
129
|
+
).yellow
|
130
|
+
end
|
131
|
+
|
132
|
+
warn Rainbow('For more information: https://docs.rubocop.org/en/latest/versioning/').yellow
|
133
|
+
end
|
134
|
+
|
117
135
|
# Merges the given configuration with the default one. If
|
118
136
|
# AllCops:DisabledByDefault is true, it changes the Enabled params so
|
119
137
|
# that only cops from user configuration are enabled.
|
@@ -199,8 +217,6 @@ module RuboCop
|
|
199
217
|
raise(TypeError, "Malformed configuration in #{absolute_path}")
|
200
218
|
end
|
201
219
|
|
202
|
-
check_cop_config_value(hash)
|
203
|
-
|
204
220
|
hash
|
205
221
|
end
|
206
222
|
|
@@ -222,22 +238,6 @@ module RuboCop
|
|
222
238
|
end
|
223
239
|
end
|
224
240
|
|
225
|
-
def check_cop_config_value(hash, parent = nil)
|
226
|
-
hash.each do |key, value|
|
227
|
-
check_cop_config_value(value, key) if value.is_a?(Hash)
|
228
|
-
|
229
|
-
next unless %w[Enabled
|
230
|
-
Safe
|
231
|
-
SafeAutoCorrect
|
232
|
-
AutoCorrect].include?(key) && value.is_a?(String)
|
233
|
-
|
234
|
-
abort(
|
235
|
-
"Property #{Rainbow(key).yellow} of cop #{Rainbow(parent).yellow}" \
|
236
|
-
" is supposed to be a boolean and #{Rainbow(value).yellow} is not."
|
237
|
-
)
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
241
|
# Read the specified file, or exit with a friendly, concise message on
|
242
242
|
# stderr. Care is taken to use the standard OS exit code for a "file not
|
243
243
|
# found" error.
|
@@ -4,22 +4,39 @@ module RuboCop
|
|
4
4
|
# This class handles obsolete configuration.
|
5
5
|
class ConfigObsoletion
|
6
6
|
RENAMED_COPS = {
|
7
|
+
'Layout/AlignArguments' => 'Layout/ArgumentAlignment',
|
8
|
+
'Layout/AlignArray' => 'Layout/ArrayAlignment',
|
9
|
+
'Layout/AlignHash' => 'Layout/HashAlignment',
|
10
|
+
'Layout/AlignParameters' => 'Layout/ParameterAlignment',
|
11
|
+
'Layout/IndentArray' => 'Layout/FirstArrayElementIndentation',
|
12
|
+
'Layout/IndentAssignment' => 'Layout/AssignmentIndentation',
|
13
|
+
'Layout/IndentFirstArgument' => 'Layout/FirstArgumentIndentation',
|
14
|
+
'Layout/IndentFirstArrayElement' => 'Layout/FirstArrayElementIndentation',
|
15
|
+
'Layout/IndentFirstHashElement' => 'Layout/FirstHashElementIndentation',
|
16
|
+
'Layout/IndentFirstParameter' => 'Layout/FirstParameterIndentation',
|
17
|
+
'Layout/IndentHash' => 'Layout/FirstHashElementIndentation',
|
18
|
+
'Layout/IndentHeredoc' => 'Layout/HeredocIndentation',
|
19
|
+
'Layout/LeadingBlankLines' => 'Layout/LeadingEmptyLines',
|
20
|
+
'Layout/TrailingBlankLines' => 'Layout/TrailingEmptyLines',
|
21
|
+
'Lint/DuplicatedKey' => 'Lint/DuplicateHashKey',
|
22
|
+
'Lint/HandleExceptions' => 'Lint/SuppressedException',
|
23
|
+
'Lint/MultipleCompare' => 'Lint/MultipleComparison',
|
24
|
+
'Lint/StringConversionInInterpolation' => 'Lint/RedundantStringCoercion',
|
7
25
|
'Lint/UnneededCopDisableDirective' => 'Lint/RedundantCopDisableDirective',
|
8
26
|
'Lint/UnneededCopEnableDirective' => 'Lint/RedundantCopEnableDirective',
|
9
27
|
'Lint/UnneededRequireStatement' => 'Lint/RedundantRequireStatement',
|
10
28
|
'Lint/UnneededSplatExpansion' => 'Lint/RedundantSplatExpansion',
|
11
|
-
'
|
12
|
-
'
|
29
|
+
'Naming/UncommunicativeBlockParamName' => 'Naming/BlockParameterName',
|
30
|
+
'Naming/UncommunicativeMethodParamName' => 'Naming/MethodParameterName',
|
13
31
|
'Style/DeprecatedHashMethods' => 'Style/PreferredHashMethods',
|
32
|
+
'Style/MethodCallParentheses' => 'Style/MethodCallWithoutArgsParentheses',
|
14
33
|
'Style/OpMethod' => 'Naming/BinaryOperatorParameterName',
|
34
|
+
'Style/SingleSpaceBeforeFirstArg' => 'Layout/SpaceBeforeFirstArg',
|
15
35
|
'Style/UnneededCapitalW' => 'Style/RedundantCapitalW',
|
16
36
|
'Style/UnneededCondition' => 'Style/RedundantCondition',
|
17
37
|
'Style/UnneededInterpolation' => 'Style/RedundantInterpolation',
|
18
38
|
'Style/UnneededPercentQ' => 'Style/RedundantPercentQ',
|
19
|
-
'Style/UnneededSort' => 'Style/RedundantSort'
|
20
|
-
'Layout/FirstParameterIndentation' => 'Layout/IndentFirstArgument',
|
21
|
-
'Layout/IndentArray' => 'Layout/IndentFirstArrayElement',
|
22
|
-
'Layout/IndentHash' => 'Layout/IndentFirstHashElement'
|
39
|
+
'Style/UnneededSort' => 'Style/RedundantSort'
|
23
40
|
}.map do |old_name, new_name|
|
24
41
|
[old_name, "The `#{old_name}` cop has been renamed to `#{new_name}`."]
|
25
42
|
end
|
@@ -31,7 +48,7 @@ module RuboCop
|
|
31
48
|
Style/VariableName Style/VariableNumber
|
32
49
|
Style/AccessorMethodName Style/AsciiIdentifiers],
|
33
50
|
'Layout' => %w[Lint/BlockAlignment Lint/EndAlignment
|
34
|
-
Lint/DefEndAlignment],
|
51
|
+
Lint/DefEndAlignment Metrics/LineLength],
|
35
52
|
'Lint' => 'Style/FlipFlop'
|
36
53
|
}.map do |new_department, old_names|
|
37
54
|
Array(old_names).map do |old_name|
|
@@ -41,9 +58,10 @@ module RuboCop
|
|
41
58
|
end
|
42
59
|
|
43
60
|
REMOVED_COPS = {
|
44
|
-
'Rails/DefaultScope' => nil,
|
45
61
|
'Layout/SpaceAfterControlKeyword' => 'Layout/SpaceAroundKeyword',
|
46
62
|
'Layout/SpaceBeforeModifierKeyword' => 'Layout/SpaceAroundKeyword',
|
63
|
+
'Lint/RescueWithoutErrorClass' => 'Style/RescueStandardError',
|
64
|
+
'Rails/DefaultScope' => nil,
|
47
65
|
'Style/SpaceAfterControlKeyword' => 'Layout/SpaceAroundKeyword',
|
48
66
|
'Style/SpaceBeforeModifierKeyword' => 'Layout/SpaceAroundKeyword',
|
49
67
|
'Style/TrailingComma' => 'Style/TrailingCommaInArguments, ' \
|
@@ -52,7 +70,7 @@ module RuboCop
|
|
52
70
|
'Style/TrailingCommaInLiteral' => 'Style/TrailingCommaInArrayLiteral ' \
|
53
71
|
'and/or ' \
|
54
72
|
'Style/TrailingCommaInHashLiteral',
|
55
|
-
'
|
73
|
+
'Style/BracesAroundHashParameters' => nil
|
56
74
|
}.map do |old_name, other_cops|
|
57
75
|
if other_cops
|
58
76
|
more = ". Please use #{other_cops} instead".gsub(%r{[A-Z]\w+/\w+},
|
@@ -97,13 +115,13 @@ module RuboCop
|
|
97
115
|
cops: 'Style/IfUnlessModifier',
|
98
116
|
parameters: 'MaxLineLength',
|
99
117
|
alternative: '`Style/IfUnlessModifier: MaxLineLength` has been ' \
|
100
|
-
'removed. Use `
|
118
|
+
'removed. Use `Layout/LineLength: Max` instead'
|
101
119
|
},
|
102
120
|
{
|
103
121
|
cops: 'Style/WhileUntilModifier',
|
104
122
|
parameters: 'MaxLineLength',
|
105
123
|
alternative: '`Style/WhileUntilModifier: MaxLineLength` has been ' \
|
106
|
-
'removed. Use `
|
124
|
+
'removed. Use `Layout/LineLength: Max` instead'
|
107
125
|
},
|
108
126
|
{
|
109
127
|
cops: 'AllCops',
|
@@ -140,6 +158,42 @@ module RuboCop
|
|
140
158
|
parameters: 'SafeMode',
|
141
159
|
alternative: '`SafeMode` has been removed. ' \
|
142
160
|
'Use `SafeAutoCorrect` instead.'
|
161
|
+
},
|
162
|
+
{
|
163
|
+
cops: 'Bundler/GemComment',
|
164
|
+
parameters: 'Whitelist',
|
165
|
+
alternative: '`Whitelist` has been renamed to `IgnoredGems`.'
|
166
|
+
},
|
167
|
+
{
|
168
|
+
cops: %w[
|
169
|
+
Lint/SafeNavigationChain Lint/SafeNavigationConsistency
|
170
|
+
Style/NestedParenthesizedCalls Style/SafeNavigation
|
171
|
+
Style/TrivialAccessors
|
172
|
+
],
|
173
|
+
parameters: 'Whitelist',
|
174
|
+
alternative: '`Whitelist` has been renamed to `AllowedMethods`.'
|
175
|
+
},
|
176
|
+
{
|
177
|
+
cops: 'Style/IpAddresses',
|
178
|
+
parameters: 'Whitelist',
|
179
|
+
alternative: '`Whitelist` has been renamed to `AllowedAddresses`.'
|
180
|
+
},
|
181
|
+
{
|
182
|
+
cops: 'Naming/HeredocDelimiterNaming',
|
183
|
+
parameters: 'Blacklist',
|
184
|
+
alternative: '`Blacklist` has been renamed to `ForbiddenDelimiters`.'
|
185
|
+
},
|
186
|
+
{
|
187
|
+
cops: 'Naming/PredicateName',
|
188
|
+
parameters: 'NamePrefixBlacklist',
|
189
|
+
alternative: '`NamePrefixBlacklist` has been renamed to ' \
|
190
|
+
'`ForbiddenPrefixes`.'
|
191
|
+
},
|
192
|
+
{
|
193
|
+
cops: 'Naming/PredicateName',
|
194
|
+
parameters: 'NameWhitelist',
|
195
|
+
alternative: '`NameWhitelist` has been renamed to ' \
|
196
|
+
'`AllowedMethods`.'
|
143
197
|
}
|
144
198
|
].freeze
|
145
199
|
|