diff --git a/lib/erb_lint/runner_config.rb b/lib/erb_lint/runner_config.rb index c2b1fc7d..61e558a1 100644 --- a/lib/erb_lint/runner_config.rb +++ b/lib/erb_lint/runner_config.rb @@ -83,7 +83,7 @@ def linters_config def config_hash_for_linter(klass_name) config_hash = linters_config[klass_name] || {} config_hash["exclude"] ||= [] - config_hash["exclude"].concat(global_exclude) if config_hash["exclude"].is_a?(Array) + config_hash["exclude"].concat(global_exclude).uniq! if config_hash["exclude"].is_a?(Array) config_hash end diff --git a/spec/erb_lint/runner_config_spec.rb b/spec/erb_lint/runner_config_spec.rb index 63879132..61667fd9 100644 --- a/spec/erb_lint/runner_config_spec.rb +++ b/spec/erb_lint/runner_config_spec.rb @@ -138,7 +138,7 @@ class MySchema < ERBLint::LinterConfig let(:config_hash) do { linters: { - "MyCustomLinter" => { exclude: ["foo/bar.rb"] }, + "MyCustomLinter" => { exclude: linter_excludes }, }, exclude: [ "**/node_modules/**", @@ -146,8 +146,20 @@ class MySchema < ERBLint::LinterConfig } end - it "excluded files are merged" do - expect(subject.exclude).to(eq(["foo/bar.rb", "**/node_modules/**"])) + context "when linter excludes do not contain global excludes" do + let(:linter_excludes) { ["foo/bar.rb"] } + + it "excluded files are merged" do + expect(subject.exclude).to(eq(["foo/bar.rb", "**/node_modules/**"])) + end + end + + context "when linter excludes already contain global excludes" do + let(:linter_excludes) { ["foo/bar.rb", "**/node_modules/**"] } + + it "does not duplicate the global excluded files" do + expect(subject.exclude).to(eq(["foo/bar.rb", "**/node_modules/**"])) + end end end end