rubocop 0.75.0 → 0.79.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 +2 -2
- data/config/default.yml +341 -316
- data/lib/rubocop.rb +48 -31
- data/lib/rubocop/ast/builder.rb +43 -41
- data/lib/rubocop/ast/node.rb +5 -1
- 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/return_node.rb +24 -0
- data/lib/rubocop/ast/traversal.rb +11 -3
- data/lib/rubocop/cli.rb +11 -227
- 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 +2 -2
- data/lib/rubocop/config.rb +8 -1
- data/lib/rubocop/config_loader.rb +20 -20
- data/lib/rubocop/config_loader_resolver.rb +2 -1
- data/lib/rubocop/config_obsoletion.rb +73 -11
- data/lib/rubocop/config_validator.rb +77 -110
- 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/commissioner.rb +15 -7
- data/lib/rubocop/cop/cop.rb +31 -6
- data/lib/rubocop/cop/corrector.rb +8 -7
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- 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 +2 -2
- 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} +3 -2
- data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
- data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +22 -7
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +2 -2
- data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +14 -12
- 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} +4 -4
- 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} +16 -8
- data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +5 -5
- data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/{metrics → layout}/line_length.rb +41 -114
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
- 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/rescue_ensure_alignment.rb +2 -0
- data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +32 -7
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
- data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
- data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
- data/lib/rubocop/cop/lint/debugger.rb +2 -2
- 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/erb_new_arguments.rb +9 -8
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
- 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/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +26 -26
- data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +10 -12
- data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
- data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +6 -6
- 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/safe_navigation_chain.rb +5 -6
- data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
- data/lib/rubocop/cop/lint/unused_block_argument.rb +22 -6
- data/lib/rubocop/cop/lint/unused_method_argument.rb +23 -5
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +7 -26
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
- data/lib/rubocop/cop/migration/department_name.rb +16 -1
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -7
- data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
- 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 +7 -4
- data/lib/rubocop/cop/mixin/trailing_comma.rb +14 -9
- data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
- data/lib/rubocop/cop/naming/file_name.rb +12 -5
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
- 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 +8 -3
- 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 +10 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +6 -6
- data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/copyright.rb +11 -7
- data/lib/rubocop/cop/style/documentation_method.rb +44 -0
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +2 -2
- data/lib/rubocop/cop/style/empty_method.rb +5 -5
- 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/expand_path_arguments.rb +1 -1
- data/lib/rubocop/cop/style/format_string.rb +10 -7
- data/lib/rubocop/cop/style/format_string_token.rb +15 -34
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +10 -0
- data/lib/rubocop/cop/style/guard_clause.rb +3 -2
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +45 -3
- data/lib/rubocop/cop/style/infinite_loop.rb +5 -4
- data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
- data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
- data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +24 -227
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +168 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
- 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 +6 -2
- data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +5 -5
- data/lib/rubocop/cop/style/next.rb +5 -5
- data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
- 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/percent_literal_delimiters.rb +7 -7
- data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
- data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
- data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
- data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +39 -29
- data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +5 -5
- data/lib/rubocop/cop/style/safe_navigation.rb +19 -8
- data/lib/rubocop/cop/style/semicolon.rb +13 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
- 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/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +10 -18
- data/lib/rubocop/cop/variable_force.rb +7 -5
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/clang_style_formatter.rb +9 -6
- data/lib/rubocop/formatter/emacs_style_formatter.rb +22 -12
- data/lib/rubocop/formatter/file_list_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +16 -16
- data/lib/rubocop/formatter/json_formatter.rb +6 -5
- data/lib/rubocop/formatter/pacman_formatter.rb +3 -3
- data/lib/rubocop/formatter/simple_text_formatter.rb +7 -3
- data/lib/rubocop/formatter/tap_formatter.rb +9 -6
- data/lib/rubocop/node_pattern.rb +4 -2
- data/lib/rubocop/options.rb +20 -26
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/rake_task.rb +1 -0
- data/lib/rubocop/result_cache.rb +24 -8
- data/lib/rubocop/rspec/shared_contexts.rb +5 -0
- data/lib/rubocop/runner.rb +50 -29
- data/lib/rubocop/target_finder.rb +12 -6
- data/lib/rubocop/target_ruby.rb +151 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +50 -34
- data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
@@ -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
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
# This class parses the special `rubocop:disable` comments in a source
|
5
5
|
# and provides a way to check if each cop is enabled at arbitrary line.
|
6
6
|
class CommentConfig
|
7
|
-
|
7
|
+
REDUNDANT_DISABLE = 'Lint/RedundantCopDisableDirective'
|
8
8
|
|
9
9
|
COP_NAME_PATTERN = '([A-Z]\w+/)?(?:[A-Z]\w+)'
|
10
10
|
COP_NAMES_PATTERN = "(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}"
|
@@ -152,7 +152,7 @@ module RuboCop
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def all_cop_names
|
155
|
-
@all_cop_names ||= Cop::Cop.registry.names - [
|
155
|
+
@all_cop_names ||= Cop::Cop.registry.names - [REDUNDANT_DISABLE]
|
156
156
|
end
|
157
157
|
|
158
158
|
def comment_only_line?(line_number)
|
data/lib/rubocop/config.rb
CHANGED
@@ -53,6 +53,13 @@ module RuboCop
|
|
53
53
|
@signature ||= Digest::SHA1.hexdigest(to_s)
|
54
54
|
end
|
55
55
|
|
56
|
+
# True if this is a config file that is shipped with RuboCop
|
57
|
+
def internal?
|
58
|
+
base_config_path = File.expand_path(File.join(ConfigLoader::RUBOCOP_HOME,
|
59
|
+
'config'))
|
60
|
+
File.expand_path(loaded_path).start_with?(base_config_path)
|
61
|
+
end
|
62
|
+
|
56
63
|
def make_excludes_absolute
|
57
64
|
each_key do |key|
|
58
65
|
@validator.validate_section_presence(key)
|
@@ -108,7 +115,7 @@ module RuboCop
|
|
108
115
|
relative_file_path = path_relative_to_config(file)
|
109
116
|
|
110
117
|
# Optimization to quickly decide if the given file is hidden (on the top
|
111
|
-
# level) and
|
118
|
+
# level) and cannot be matched by any pattern.
|
112
119
|
is_hidden = relative_file_path.start_with?('.') &&
|
113
120
|
!relative_file_path.start_with?('..')
|
114
121
|
return false if is_hidden && !possibly_include_hidden?
|
@@ -46,7 +46,7 @@ module RuboCop
|
|
46
46
|
|
47
47
|
add_missing_namespaces(path, hash)
|
48
48
|
|
49
|
-
resolver.resolve_inheritance_from_gems(hash
|
49
|
+
resolver.resolve_inheritance_from_gems(hash)
|
50
50
|
resolver.resolve_inheritance(path, hash, file, debug?)
|
51
51
|
|
52
52
|
hash.delete('inherit_from')
|
@@ -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)
|
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(config)
|
120
|
+
pending_cops = config.keys.select do |key|
|
121
|
+
config[key]['Enabled'] == 'pending'
|
122
|
+
end
|
123
|
+
|
124
|
+
return if pending_cops.none?
|
125
|
+
|
126
|
+
warn Rainbow('The following cops were added to RuboCop, but are not ' \
|
127
|
+
'configured. Please set Enabled to either `true` or ' \
|
128
|
+
'`false` in your `.rubocop.yml` file:').yellow
|
129
|
+
|
130
|
+
pending_cops.each do |cop|
|
131
|
+
warn Rainbow(" - #{cop}").yellow
|
132
|
+
end
|
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.
|
@@ -35,7 +35,8 @@ module RuboCop
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def resolve_inheritance_from_gems(hash
|
38
|
+
def resolve_inheritance_from_gems(hash)
|
39
|
+
gems = hash.delete('inherit_gem')
|
39
40
|
(gems || {}).each_pair do |gem_name, config_path|
|
40
41
|
if gem_name == 'rubocop'
|
41
42
|
raise ArgumentError,
|
@@ -4,13 +4,39 @@ module RuboCop
|
|
4
4
|
# This class handles obsolete configuration.
|
5
5
|
class ConfigObsoletion
|
6
6
|
RENAMED_COPS = {
|
7
|
-
'
|
8
|
-
'
|
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',
|
25
|
+
'Lint/UnneededCopDisableDirective' => 'Lint/RedundantCopDisableDirective',
|
26
|
+
'Lint/UnneededCopEnableDirective' => 'Lint/RedundantCopEnableDirective',
|
27
|
+
'Lint/UnneededRequireStatement' => 'Lint/RedundantRequireStatement',
|
28
|
+
'Lint/UnneededSplatExpansion' => 'Lint/RedundantSplatExpansion',
|
29
|
+
'Naming/UncommunicativeBlockParamName' => 'Naming/BlockParameterName',
|
30
|
+
'Naming/UncommunicativeMethodParamName' => 'Naming/MethodParameterName',
|
9
31
|
'Style/DeprecatedHashMethods' => 'Style/PreferredHashMethods',
|
32
|
+
'Style/MethodCallParentheses' => 'Style/MethodCallWithoutArgsParentheses',
|
10
33
|
'Style/OpMethod' => 'Naming/BinaryOperatorParameterName',
|
11
|
-
'
|
12
|
-
'
|
13
|
-
'
|
34
|
+
'Style/SingleSpaceBeforeFirstArg' => 'Layout/SpaceBeforeFirstArg',
|
35
|
+
'Style/UnneededCapitalW' => 'Style/RedundantCapitalW',
|
36
|
+
'Style/UnneededCondition' => 'Style/RedundantCondition',
|
37
|
+
'Style/UnneededInterpolation' => 'Style/RedundantInterpolation',
|
38
|
+
'Style/UnneededPercentQ' => 'Style/RedundantPercentQ',
|
39
|
+
'Style/UnneededSort' => 'Style/RedundantSort'
|
14
40
|
}.map do |old_name, new_name|
|
15
41
|
[old_name, "The `#{old_name}` cop has been renamed to `#{new_name}`."]
|
16
42
|
end
|
@@ -22,7 +48,7 @@ module RuboCop
|
|
22
48
|
Style/VariableName Style/VariableNumber
|
23
49
|
Style/AccessorMethodName Style/AsciiIdentifiers],
|
24
50
|
'Layout' => %w[Lint/BlockAlignment Lint/EndAlignment
|
25
|
-
Lint/DefEndAlignment],
|
51
|
+
Lint/DefEndAlignment Metrics/LineLength],
|
26
52
|
'Lint' => 'Style/FlipFlop'
|
27
53
|
}.map do |new_department, old_names|
|
28
54
|
Array(old_names).map do |old_name|
|
@@ -32,9 +58,10 @@ module RuboCop
|
|
32
58
|
end
|
33
59
|
|
34
60
|
REMOVED_COPS = {
|
35
|
-
'Rails/DefaultScope' => nil,
|
36
61
|
'Layout/SpaceAfterControlKeyword' => 'Layout/SpaceAroundKeyword',
|
37
62
|
'Layout/SpaceBeforeModifierKeyword' => 'Layout/SpaceAroundKeyword',
|
63
|
+
'Lint/RescueWithoutErrorClass' => 'Style/RescueStandardError',
|
64
|
+
'Rails/DefaultScope' => nil,
|
38
65
|
'Style/SpaceAfterControlKeyword' => 'Layout/SpaceAroundKeyword',
|
39
66
|
'Style/SpaceBeforeModifierKeyword' => 'Layout/SpaceAroundKeyword',
|
40
67
|
'Style/TrailingComma' => 'Style/TrailingCommaInArguments, ' \
|
@@ -42,8 +69,7 @@ module RuboCop
|
|
42
69
|
'Style/TrailingCommaInHashLiteral',
|
43
70
|
'Style/TrailingCommaInLiteral' => 'Style/TrailingCommaInArrayLiteral ' \
|
44
71
|
'and/or ' \
|
45
|
-
'Style/TrailingCommaInHashLiteral'
|
46
|
-
'Lint/RescueWithoutErrorClass' => 'Style/RescueStandardError'
|
72
|
+
'Style/TrailingCommaInHashLiteral'
|
47
73
|
}.map do |old_name, other_cops|
|
48
74
|
if other_cops
|
49
75
|
more = ". Please use #{other_cops} instead".gsub(%r{[A-Z]\w+/\w+},
|
@@ -88,13 +114,13 @@ module RuboCop
|
|
88
114
|
cops: 'Style/IfUnlessModifier',
|
89
115
|
parameters: 'MaxLineLength',
|
90
116
|
alternative: '`Style/IfUnlessModifier: MaxLineLength` has been ' \
|
91
|
-
'removed. Use `
|
117
|
+
'removed. Use `Layout/LineLength: Max` instead'
|
92
118
|
},
|
93
119
|
{
|
94
120
|
cops: 'Style/WhileUntilModifier',
|
95
121
|
parameters: 'MaxLineLength',
|
96
122
|
alternative: '`Style/WhileUntilModifier: MaxLineLength` has been ' \
|
97
|
-
'removed. Use `
|
123
|
+
'removed. Use `Layout/LineLength: Max` instead'
|
98
124
|
},
|
99
125
|
{
|
100
126
|
cops: 'AllCops',
|
@@ -131,6 +157,42 @@ module RuboCop
|
|
131
157
|
parameters: 'SafeMode',
|
132
158
|
alternative: '`SafeMode` has been removed. ' \
|
133
159
|
'Use `SafeAutoCorrect` instead.'
|
160
|
+
},
|
161
|
+
{
|
162
|
+
cops: 'Bundler/GemComment',
|
163
|
+
parameters: 'Whitelist',
|
164
|
+
alternative: '`Whitelist` has been renamed to `IgnoredGems`.'
|
165
|
+
},
|
166
|
+
{
|
167
|
+
cops: %w[
|
168
|
+
Lint/SafeNavigationChain Lint/SafeNavigationConsistency
|
169
|
+
Style/NestedParenthesizedCalls Style/SafeNavigation
|
170
|
+
Style/TrivialAccessors
|
171
|
+
],
|
172
|
+
parameters: 'Whitelist',
|
173
|
+
alternative: '`Whitelist` has been renamed to `AllowedMethods`.'
|
174
|
+
},
|
175
|
+
{
|
176
|
+
cops: 'Style/IpAddresses',
|
177
|
+
parameters: 'Whitelist',
|
178
|
+
alternative: '`Whitelist` has been renamed to `AllowedAddresses`.'
|
179
|
+
},
|
180
|
+
{
|
181
|
+
cops: 'Naming/HeredocDelimiterNaming',
|
182
|
+
parameters: 'Blacklist',
|
183
|
+
alternative: '`Blacklist` has been renamed to `ForbiddenDelimiters`.'
|
184
|
+
},
|
185
|
+
{
|
186
|
+
cops: 'Naming/PredicateName',
|
187
|
+
parameters: 'NamePrefixBlacklist',
|
188
|
+
alternative: '`NamePrefixBlacklist` has been renamed to ' \
|
189
|
+
'`ForbiddenPrefixes`.'
|
190
|
+
},
|
191
|
+
{
|
192
|
+
cops: 'Naming/PredicateName',
|
193
|
+
parameters: 'NameWhitelist',
|
194
|
+
alternative: '`NameWhitelist` has been renamed to ' \
|
195
|
+
'`AllowedMethods`.'
|
134
196
|
}
|
135
197
|
].freeze
|
136
198
|
|