Skip to content

Commit a118624

Browse files
koicbbatsov
authored andcommitted
Prevent redundant plugin loading
This PR prevents redundant plugin loading when a duplicate plugin is specified in an inherited config.
1 parent b667815 commit a118624

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#13981](https://github.com/rubocop/rubocop/pull/13981): Prevent redundant plugin loading when a duplicate plugin is specified in an inherited config. ([@koic][])

lib/rubocop/config_loader_resolver.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module RuboCop
99
# @api private
1010
class ConfigLoaderResolver # rubocop:disable Metrics/ClassLength
1111
def resolve_plugins(rubocop_config, plugins)
12-
return if (plugins = Array(plugins)).empty?
12+
plugins = Array(plugins) - ConfigLoader.loaded_plugins.map { |plugin| plugin.about.name }
13+
return if plugins.empty?
1314

1415
Plugin.integrate_plugins(rubocop_config, plugins)
1516
end

spec/rubocop/version_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,48 @@ module FooBarBaz
104104
end
105105
end
106106

107+
context 'when plugins are specified' do
108+
before do
109+
create_file('.rubocop.yml', <<~YAML)
110+
plugins:
111+
- rubocop-performance
112+
- rubocop-rspec
113+
YAML
114+
end
115+
116+
it 'returns the extensions' do
117+
expect(extension_versions).to contain_exactly(
118+
/- rubocop-performance \d+\.\d+\.\d+/,
119+
/- rubocop-rspec \d+\.\d+\.\d+/
120+
)
121+
end
122+
end
123+
124+
context 'when a duplicate plugin is specified in an inherited config' do
125+
before do
126+
create_file('base.yml', <<~YAML)
127+
plugins:
128+
- rubocop-performance
129+
YAML
130+
131+
create_file('.rubocop.yml', <<~YAML)
132+
inherit_from:
133+
- base.yml
134+
135+
plugins:
136+
- rubocop-performance
137+
- rubocop-rspec
138+
YAML
139+
end
140+
141+
it 'returns each extension exactly once' do
142+
expect(extension_versions).to contain_exactly(
143+
/- rubocop-performance \d+\.\d+\.\d+/,
144+
/- rubocop-rspec \d+\.\d+\.\d+/
145+
)
146+
end
147+
end
148+
107149
context 'with an invalid cop in config' do
108150
before do
109151
create_file('.rubocop.yml', <<~YAML)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy