rubocop 1.2.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -10
- data/config/default.yml +84 -13
- data/lib/rubocop.rb +5 -0
- data/lib/rubocop/cli/command/execute_runner.rb +26 -11
- data/lib/rubocop/config_loader.rb +14 -5
- data/lib/rubocop/config_regeneration.rb +1 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +21 -6
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +3 -3
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +1 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.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 +2 -9
- 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 +15 -3
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +80 -10
- data/lib/rubocop/cop/layout/line_length.rb +8 -1
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
- 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 -27
- 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/empty_block.rb +23 -0
- data/lib/rubocop/cop/lint/empty_class.rb +93 -0
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +22 -4
- data/lib/rubocop/cop/lint/loop.rb +4 -0
- data/lib/rubocop/cop/lint/missing_super.rb +7 -4
- 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/to_enum_arguments.rb +6 -15
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +17 -6
- data/lib/rubocop/cop/lint/useless_method_definition.rb +2 -4
- data/lib/rubocop/cop/metrics/method_length.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/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -4
- data/lib/rubocop/cop/mixin/visibility_help.rb +1 -3
- data/lib/rubocop/cop/naming/variable_number.rb +16 -0
- data/lib/rubocop/cop/style/and_or.rb +1 -3
- data/lib/rubocop/cop/style/collection_compact.rb +6 -0
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +107 -5
- data/lib/rubocop/cop/style/documentation.rb +12 -1
- data/lib/rubocop/cop/style/format_string.rb +8 -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 +7 -3
- data/lib/rubocop/cop/style/infinite_loop.rb +4 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/multiple_comparison.rb +3 -2
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +10 -3
- data/lib/rubocop/cop/style/nil_lambda.rb +52 -0
- data/lib/rubocop/cop/style/redundant_argument.rb +75 -0
- data/lib/rubocop/cop/style/static_class.rb +97 -0
- data/lib/rubocop/cop/style/while_until_modifier.rb +9 -0
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/variable_force/branch.rb +1 -1
- data/lib/rubocop/cop/variable_force/scope.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +21 -6
- data/lib/rubocop/options.rb +5 -0
- data/lib/rubocop/rake_task.rb +2 -2
- 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 +1 -1
- metadata +10 -8
- data/bin/console +0 -10
- data/bin/rubocop-profile +0 -32
- data/bin/setup +0 -7
@@ -24,6 +24,15 @@ module RuboCop
|
|
24
24
|
#
|
25
25
|
# # good
|
26
26
|
# x += 1 until x > 10
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# # bad
|
30
|
+
# x += 100 while x < 500 # a long comment that makes code too long if it were a single line
|
31
|
+
#
|
32
|
+
# # good
|
33
|
+
# while x < 500 # a long comment that makes code too long if it were a single line
|
34
|
+
# x += 100
|
35
|
+
# end
|
27
36
|
class WhileUntilModifier < Base
|
28
37
|
include StatementModifier
|
29
38
|
extend AutoCorrector
|
data/lib/rubocop/cop/util.rb
CHANGED
@@ -53,7 +53,7 @@ module RuboCop
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def on_node(syms, sexp, excludes = [], &block)
|
56
|
-
return to_enum(:on_node, syms, sexp, excludes) unless
|
56
|
+
return to_enum(:on_node, syms, sexp, excludes) unless block
|
57
57
|
|
58
58
|
yield sexp if Array(syms).include?(sexp.type)
|
59
59
|
return if Array(excludes).include?(sexp.type)
|
@@ -78,7 +78,7 @@ module RuboCop
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def each_ancestor(include_self: false, &block)
|
81
|
-
return to_enum(__method__, include_self: include_self) unless
|
81
|
+
return to_enum(__method__, include_self: include_self) unless block
|
82
82
|
|
83
83
|
yield self if include_self
|
84
84
|
scan_ancestors(&block)
|
@@ -5,6 +5,8 @@ module RuboCop
|
|
5
5
|
# This formatter displays a YAML configuration file where all cops that
|
6
6
|
# detected any offenses are configured to not detect the offense.
|
7
7
|
class DisabledConfigFormatter < BaseFormatter
|
8
|
+
include PathUtil
|
9
|
+
|
8
10
|
HEADING = <<~COMMENTS
|
9
11
|
# This configuration was generated by
|
10
12
|
# `%<command>s`
|
@@ -195,15 +197,28 @@ module RuboCop
|
|
195
197
|
end
|
196
198
|
|
197
199
|
def excludes(offending_files, cop_name, parent)
|
198
|
-
# Exclude properties in .rubocop_todo.yml override default ones, as well
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
# just look at the current working directory
|
200
|
+
# Exclude properties in .rubocop_todo.yml override default ones, as well as any custom
|
201
|
+
# excludes in .rubocop.yml, so in order to retain those excludes we must copy them.
|
202
|
+
# There can be multiple .rubocop.yml files in subdirectories, but we just look at the
|
203
|
+
# current working directory.
|
203
204
|
config = ConfigStore.new.for(parent)
|
204
205
|
cfg = config[cop_name] || {}
|
205
206
|
|
206
|
-
(
|
207
|
+
if merge_mode_for_exclude?(config) || merge_mode_for_exclude?(cfg)
|
208
|
+
offending_files
|
209
|
+
else
|
210
|
+
cop_exclude = cfg['Exclude']
|
211
|
+
if cop_exclude && cop_exclude != default_config(cop_name)['Exclude']
|
212
|
+
warn "`#{cop_name}: Exclude` in `#{smart_path(config.loaded_path)}` overrides a " \
|
213
|
+
'generated `Exclude` in `.rubocop_todo.yml`. Either remove ' \
|
214
|
+
"`#{cop_name}: Exclude` or add `inherit_mode: merge: - Exclude`."
|
215
|
+
end
|
216
|
+
((cop_exclude || []) + offending_files).uniq
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def merge_mode_for_exclude?(cfg)
|
221
|
+
Array(cfg.to_h.dig('inherit_mode', 'merge')).include?('Exclude')
|
207
222
|
end
|
208
223
|
|
209
224
|
def output_exclude_path(output_buffer, exclude_path, parent)
|
data/lib/rubocop/options.rb
CHANGED
@@ -5,6 +5,7 @@ require 'shellwords'
|
|
5
5
|
|
6
6
|
module RuboCop
|
7
7
|
class IncorrectCopNameError < StandardError; end
|
8
|
+
|
8
9
|
class OptionArgumentError < StandardError; end
|
9
10
|
|
10
11
|
# This class handles command line options.
|
@@ -195,6 +196,7 @@ module RuboCop
|
|
195
196
|
|
196
197
|
option(opts, '--safe')
|
197
198
|
|
199
|
+
option(opts, '--stderr')
|
198
200
|
option(opts, '--[no-]color')
|
199
201
|
|
200
202
|
option(opts, '-v', '--version')
|
@@ -498,6 +500,9 @@ module RuboCop
|
|
498
500
|
extra_details: 'Display extra details in offense messages.',
|
499
501
|
lint: 'Run only lint cops.',
|
500
502
|
safe: 'Run only safe cops.',
|
503
|
+
stderr: ['Write all output to stderr except for the',
|
504
|
+
'autocorrected source. This is especially useful',
|
505
|
+
'when combined with --auto-correct and --stdin.'],
|
501
506
|
list_target_files: 'List all files RuboCop will inspect.',
|
502
507
|
auto_correct: 'Auto-correct offenses (only when it\'s safe).',
|
503
508
|
safe_auto_correct: '(same, deprecated)',
|
data/lib/rubocop/rake_task.rb
CHANGED
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
|
23
23
|
task(name, *args) do |_, task_args|
|
24
24
|
RakeFileUtils.verbose(verbose) do
|
25
|
-
yield(*[self, task_args].slice(0, task_block.arity)) if
|
25
|
+
yield(*[self, task_args].slice(0, task_block.arity)) if task_block
|
26
26
|
run_cli(verbose, full_options)
|
27
27
|
end
|
28
28
|
end
|
@@ -66,7 +66,7 @@ module RuboCop
|
|
66
66
|
|
67
67
|
task(:auto_correct, *args) do |_, task_args|
|
68
68
|
RakeFileUtils.verbose(verbose) do
|
69
|
-
yield(*[self, task_args].slice(0, task_block.arity)) if
|
69
|
+
yield(*[self, task_args].slice(0, task_block.arity)) if task_block
|
70
70
|
options = full_options.unshift('--auto-correct-all')
|
71
71
|
options.delete('--parallel')
|
72
72
|
run_cli(verbose, options)
|
data/lib/rubocop/runner.rb
CHANGED
@@ -64,7 +64,7 @@ module RuboCop
|
|
64
64
|
# instances that each inspects its allotted group of files.
|
65
65
|
def warm_cache(target_files)
|
66
66
|
puts 'Running parallel inspection' if @options[:debug]
|
67
|
-
Parallel.each(target_files
|
67
|
+
Parallel.each(target_files) { |target_file| file_offenses(target_file) }
|
68
68
|
end
|
69
69
|
|
70
70
|
def find_target_files(paths)
|
@@ -94,7 +94,7 @@ module RuboCop
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def wanted_dir_patterns(base_dir, exclude_pattern, flags)
|
97
|
-
dirs = Dir.glob(File.join(base_dir, '*/'), flags)
|
97
|
+
dirs = Dir.glob(File.join(base_dir.gsub('/**/', '/\**/'), '*/'), flags)
|
98
98
|
.reject do |dir|
|
99
99
|
dir.end_with?('/./', '/../') || File.fnmatch?(exclude_pattern, dir, flags)
|
100
100
|
end
|
data/lib/rubocop/target_ruby.rb
CHANGED
@@ -112,6 +112,70 @@ module RuboCop
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
# The target ruby version may be found in a .gemspec file.
|
116
|
+
# @api private
|
117
|
+
class GemspecFile < Source
|
118
|
+
extend NodePattern::Macros
|
119
|
+
|
120
|
+
GEMSPEC_EXTENSION = '.gemspec'
|
121
|
+
|
122
|
+
def_node_search :required_ruby_version, <<~PATTERN
|
123
|
+
(send _ :required_ruby_version= $_)
|
124
|
+
PATTERN
|
125
|
+
|
126
|
+
def_node_matcher :gem_requirement?, <<~PATTERN
|
127
|
+
(send (const(const _ :Gem):Requirement) :new $str)
|
128
|
+
PATTERN
|
129
|
+
|
130
|
+
def name
|
131
|
+
"`required_ruby_version` parameter (in #{gemspec_filename})"
|
132
|
+
end
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
def find_version
|
137
|
+
file = gemspec_filepath
|
138
|
+
return unless file && File.file?(file)
|
139
|
+
|
140
|
+
version = version_from_gemspec_file(file)
|
141
|
+
return if version.nil?
|
142
|
+
|
143
|
+
requirement = version.children.last
|
144
|
+
return version_from_array(version) if version.array_type?
|
145
|
+
return version_from_array(requirement) if gem_requirement? version
|
146
|
+
|
147
|
+
version_from_str(version.str_content)
|
148
|
+
end
|
149
|
+
|
150
|
+
def gemspec_filename
|
151
|
+
@gemspec_filename ||= begin
|
152
|
+
basename = Pathname.new(@config.base_dir_for_path_parameters).basename.to_s
|
153
|
+
"#{basename}#{GEMSPEC_EXTENSION}"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def gemspec_filepath
|
158
|
+
@gemspec_filepath ||=
|
159
|
+
@config.find_file_upwards(gemspec_filename, @config.base_dir_for_path_parameters)
|
160
|
+
end
|
161
|
+
|
162
|
+
def version_from_gemspec_file(file)
|
163
|
+
processed_source = ProcessedSource.from_file(file, DEFAULT_VERSION)
|
164
|
+
required_ruby_version(processed_source.ast).first
|
165
|
+
end
|
166
|
+
|
167
|
+
def version_from_array(array)
|
168
|
+
versions = array.children.map { |v| version_from_str(v.is_a?(String) ? v : v.str_content) }
|
169
|
+
versions.compact.min
|
170
|
+
end
|
171
|
+
|
172
|
+
def version_from_str(str)
|
173
|
+
str.match(/^(?:>=|<=)?\s*(?<version>\d+(?:\.\d+)*)/) do |md|
|
174
|
+
md[:version].to_f
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
115
179
|
# If all else fails, a default version will be picked.
|
116
180
|
# @api private
|
117
181
|
class Default < Source
|
@@ -130,7 +194,7 @@ module RuboCop
|
|
130
194
|
KNOWN_RUBIES
|
131
195
|
end
|
132
196
|
|
133
|
-
SOURCES = [RuboCopConfig, RubyVersionFile, BundlerLockFile, Default].freeze
|
197
|
+
SOURCES = [RuboCopConfig, RubyVersionFile, BundlerLockFile, GemspecFile, Default].freeze
|
134
198
|
private_constant :SOURCES
|
135
199
|
|
136
200
|
def initialize(config)
|
data/lib/rubocop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-11-
|
13
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parallel
|
@@ -94,14 +94,14 @@ dependencies:
|
|
94
94
|
requirements:
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: 1.
|
97
|
+
version: 1.1.1
|
98
98
|
type: :runtime
|
99
99
|
prerelease: false
|
100
100
|
version_requirements: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: 1.
|
104
|
+
version: 1.1.1
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
106
|
name: ruby-progressbar
|
107
107
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,9 +171,6 @@ files:
|
|
171
171
|
- README.md
|
172
172
|
- assets/logo.png
|
173
173
|
- assets/output.html.erb
|
174
|
-
- bin/console
|
175
|
-
- bin/rubocop-profile
|
176
|
-
- bin/setup
|
177
174
|
- config/default.yml
|
178
175
|
- exe/rubocop
|
179
176
|
- lib/rubocop.rb
|
@@ -347,6 +344,7 @@ files:
|
|
347
344
|
- lib/rubocop/cop/lint/deprecated_class_methods.rb
|
348
345
|
- lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb
|
349
346
|
- lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb
|
347
|
+
- lib/rubocop/cop/lint/duplicate_branch.rb
|
350
348
|
- lib/rubocop/cop/lint/duplicate_case_condition.rb
|
351
349
|
- lib/rubocop/cop/lint/duplicate_elsif_condition.rb
|
352
350
|
- lib/rubocop/cop/lint/duplicate_hash_key.rb
|
@@ -357,6 +355,7 @@ files:
|
|
357
355
|
- lib/rubocop/cop/lint/each_with_object_argument.rb
|
358
356
|
- lib/rubocop/cop/lint/else_layout.rb
|
359
357
|
- lib/rubocop/cop/lint/empty_block.rb
|
358
|
+
- lib/rubocop/cop/lint/empty_class.rb
|
360
359
|
- lib/rubocop/cop/lint/empty_conditional_body.rb
|
361
360
|
- lib/rubocop/cop/lint/empty_ensure.rb
|
362
361
|
- lib/rubocop/cop/lint/empty_expression.rb
|
@@ -663,6 +662,7 @@ files:
|
|
663
662
|
- lib/rubocop/cop/style/nested_ternary_operator.rb
|
664
663
|
- lib/rubocop/cop/style/next.rb
|
665
664
|
- lib/rubocop/cop/style/nil_comparison.rb
|
665
|
+
- lib/rubocop/cop/style/nil_lambda.rb
|
666
666
|
- lib/rubocop/cop/style/non_nil_check.rb
|
667
667
|
- lib/rubocop/cop/style/not.rb
|
668
668
|
- lib/rubocop/cop/style/numeric_literal_prefix.rb
|
@@ -682,6 +682,7 @@ files:
|
|
682
682
|
- lib/rubocop/cop/style/proc.rb
|
683
683
|
- lib/rubocop/cop/style/raise_args.rb
|
684
684
|
- lib/rubocop/cop/style/random_with_offset.rb
|
685
|
+
- lib/rubocop/cop/style/redundant_argument.rb
|
685
686
|
- lib/rubocop/cop/style/redundant_assignment.rb
|
686
687
|
- lib/rubocop/cop/style/redundant_begin.rb
|
687
688
|
- lib/rubocop/cop/style/redundant_capital_w.rb
|
@@ -718,6 +719,7 @@ files:
|
|
718
719
|
- lib/rubocop/cop/style/sole_nested_conditional.rb
|
719
720
|
- lib/rubocop/cop/style/special_global_vars.rb
|
720
721
|
- lib/rubocop/cop/style/stabby_lambda_parentheses.rb
|
722
|
+
- lib/rubocop/cop/style/static_class.rb
|
721
723
|
- lib/rubocop/cop/style/stderr_puts.rb
|
722
724
|
- lib/rubocop/cop/style/string_concatenation.rb
|
723
725
|
- lib/rubocop/cop/style/string_hash_keys.rb
|
@@ -817,7 +819,7 @@ metadata:
|
|
817
819
|
homepage_uri: https://rubocop.org/
|
818
820
|
changelog_uri: https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md
|
819
821
|
source_code_uri: https://github.com/rubocop-hq/rubocop/
|
820
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
822
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.4/
|
821
823
|
bug_tracker_uri: https://github.com/rubocop-hq/rubocop/issues
|
822
824
|
post_install_message:
|
823
825
|
rdoc_options: []
|
data/bin/console
DELETED
data/bin/rubocop-profile
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
if ARGV.include?('-h') || ARGV.include?('--help')
|
5
|
-
puts "Usage: same as main `rubocop` command but gathers profiling info"
|
6
|
-
puts "Additional option: `--memory` to print memory usage"
|
7
|
-
exit(0)
|
8
|
-
end
|
9
|
-
with_mem = ARGV.delete('--memory')
|
10
|
-
ARGV.unshift '--cache', 'false' unless ARGV.include?('--cache')
|
11
|
-
|
12
|
-
require 'stackprof'
|
13
|
-
if with_mem
|
14
|
-
require 'memory_profiler'
|
15
|
-
MemoryProfiler.start
|
16
|
-
end
|
17
|
-
StackProf.start
|
18
|
-
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
19
|
-
begin
|
20
|
-
load "#{__dir__}/../exe/rubocop"
|
21
|
-
ensure
|
22
|
-
delta = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
|
23
|
-
puts "Finished in #{delta.round(1)} seconds"
|
24
|
-
StackProf.stop
|
25
|
-
if with_mem
|
26
|
-
puts "Building memory report..."
|
27
|
-
report = MemoryProfiler.stop
|
28
|
-
end
|
29
|
-
Dir.mkdir('tmp') unless File.exist?('tmp')
|
30
|
-
StackProf.results('tmp/stackprof.dump')
|
31
|
-
report&.pretty_print(scale_bytes: true)
|
32
|
-
end
|