From 5d189473412c744be4605a55aa2eb1e93e800df4 Mon Sep 17 00:00:00 2001 From: Ian Fleeton Date: Fri, 25 Aug 2023 10:42:42 +0100 Subject: [PATCH] Don't repeat global excludes in linter config (#325) This caused the config to keep growing which affected the file caching fingerprinting which relies on the config hash. --- lib/erb_lint/runner_config.rb | 2 +- spec/erb_lint/runner_config_spec.rb | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) 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