Skip to content

Commit

Permalink
Do not fork off extra processes if only a single file needs inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
WJWH committed Aug 29, 2022
1 parent 23a3924 commit 7f1e015
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_speed_up_single_file_inspection.md
@@ -0,0 +1 @@
* [#10903](https://github.com/rubocop/rubocop/pull/10903): Skip forking off extra processes for parallel inspection when only a single file needs to be inspected. ([@wjwh][])
4 changes: 4 additions & 0 deletions lib/rubocop/runner.rb
Expand Up @@ -64,6 +64,10 @@ def aborting?
# instances that each inspects its allotted group of files.
def warm_cache(target_files)
saved_options = @options.dup
if target_files.length <= 1
puts 'Skipping parallel inspection: only a single file needs inspection' if @options[:debug]
return
end
puts 'Running parallel inspection' if @options[:debug]
%i[autocorrect safe_autocorrect].each { |opt| @options[opt] = false }
Parallel.each(target_files) { |target_file| file_offenses(target_file) }
Expand Down
9 changes: 8 additions & 1 deletion spec/rubocop/cli/options_spec.rb
Expand Up @@ -14,6 +14,11 @@
describe '--parallel' do
if RuboCop::Platform.windows?
context 'on Windows' do
before do
create_file('test_1.rb', ['puts "hello world"'])
create_file('test_2.rb', ['puts "what a lovely day"'])
end

it 'prints a warning' do
cli.run ['-P']
expect($stderr.string).to include('Process.fork is not supported by this Ruby')
Expand All @@ -35,7 +40,9 @@
context 'on Unix-like systems' do
it 'prints a message if --debug is specified' do
cli.run ['--parallel', '--debug']
expect($stdout.string).to match(/Running parallel inspection/)
expect($stdout.string).to match(
/Skipping parallel inspection: only a single file needs inspection/
)
end

it 'does not print a message if --debug is not specified' do
Expand Down

0 comments on commit 7f1e015

Please sign in to comment.