From 11a71279fd2df30a12a9a4a13be3f87f4212d779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Charaoui?= Date: Thu, 23 Jan 2025 18:25:56 -0500 Subject: [PATCH] add --top-scope-variables cli argument, fix #228 --- .rubocop_todo.yml | 4 ++-- lib/puppet-lint/optparser.rb | 4 ++++ spec/fixtures/test/manifests/top_scope_variables.pp | 4 ++++ spec/unit/puppet-lint/bin_spec.rb | 12 ++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/test/manifests/top_scope_variables.pp diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 68404e74c..1ebcb6c65 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -60,10 +60,10 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 33 -# Offense count: 80 +# Offense count: 81 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 108 + Max: 111 # Offense count: 26 # Configuration parameters: AllowedMethods, AllowedPatterns. diff --git a/lib/puppet-lint/optparser.rb b/lib/puppet-lint/optparser.rb index 4dcb2930b..61a3fb5a7 100644 --- a/lib/puppet-lint/optparser.rb +++ b/lib/puppet-lint/optparser.rb @@ -128,6 +128,10 @@ def self.build(args = []) PuppetLint.configuration.ignore_paths = paths.split(',') end + opts.on('--top-scope-variables VARS', 'A comma separated list of allowed top scope variables') do |vars| + PuppetLint.configuration.top_scope_variables = vars.split(',') + end + PuppetLint.configuration.checks.each do |check| opts.on("--no-#{check}-check", "Skip the #{check} check.") do PuppetLint.configuration.send(:"disable_#{check}") diff --git a/spec/fixtures/test/manifests/top_scope_variables.pp b/spec/fixtures/test/manifests/top_scope_variables.pp new file mode 100644 index 000000000..1236063d7 --- /dev/null +++ b/spec/fixtures/test/manifests/top_scope_variables.pp @@ -0,0 +1,4 @@ +# dummy resource to test --top-scope-variables +define test::top_scope_variables() { + notice($role) +} diff --git a/spec/unit/puppet-lint/bin_spec.rb b/spec/unit/puppet-lint/bin_spec.rb index 118d054b9..542ef7e6a 100644 --- a/spec/unit/puppet-lint/bin_spec.rb +++ b/spec/unit/puppet-lint/bin_spec.rb @@ -121,6 +121,18 @@ def initialize(args) its(:stdout) { is_expected.to eq('') } end + context 'when passed top scope variables option' do + let(:args) do + [ + '--top-scope-variables=role', + 'spec/fixtures/test/manifests/top_scope_variables.pp', + ] + end + + its(:exitstatus) { is_expected.to eq(0) } + its(:stdout) { is_expected.to eq('') } + end + context 'when limited to errors only' do let(:args) do [