From 89a8f966121980d9ee22a80b9a6916409f9005bb Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Tue, 16 Feb 2021 00:34:52 +0100 Subject: [PATCH] Add an option to override ignore private apis --- README.md | 9 +++++ .../plugins/check_parameter_documentation.rb | 5 ++- .../check_parameter_documentation_spec.rb | 33 ++++++++++++++++--- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 81cb66d..ee344b2 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,15 @@ rdoc style. class example($foo) { } ``` +### Private api + +The check will ignore missing documentation for private apis by default. +To disable this behaviour and check private apis, use the following configuration: + +```ruby +PuppetLint.configuration.docs_ignore_private_api = false +``` + ### Selective rake task The usual puppet-lint rake task checks all manifests, which isn't always diff --git a/lib/puppet-lint/plugins/check_parameter_documentation.rb b/lib/puppet-lint/plugins/check_parameter_documentation.rb index 052b353..5cc2965 100644 --- a/lib/puppet-lint/plugins/check_parameter_documentation.rb +++ b/lib/puppet-lint/plugins/check_parameter_documentation.rb @@ -1,5 +1,8 @@ PuppetLint.new_check(:parameter_documentation) do def check + + ignore_private = PuppetLint.configuration.docs_ignore_private_api.nil? ? true : PuppetLint.configuration.docs_ignore_private_api + class_indexes.concat(defined_type_indexes).each do |idx| doc_params = {} doc_params_duplicates = Hash.new { |hash, key| hash[key] = [doc_params[key]] } @@ -50,7 +53,7 @@ def check } end - unless is_private + unless ignore_private and is_private params.each do |p| next if doc_params.has_key? p.value notify :warning, { diff --git a/spec/puppet-lint/plugins/check_parameter_documentation_spec.rb b/spec/puppet-lint/plugins/check_parameter_documentation_spec.rb index 0d5eda2..c1d3f7d 100644 --- a/spec/puppet-lint/plugins/check_parameter_documentation_spec.rb +++ b/spec/puppet-lint/plugins/check_parameter_documentation_spec.rb @@ -173,13 +173,38 @@ class example($foo, $bar) { } EOS end - it 'should detect no single problems' do - expect(problems).to have(0).problems + context 'ignore private_api disabled (default)' do + it 'should detect no single problems' do + expect(problems).to have(0).problems + end + + it 'should not create a warning' do + expect(problems).not_to contain_info(class_msg % :foo) + end end - it 'should not create a warning' do - expect(problems).not_to contain_info(class_msg % :foo) + context 'ignore private_api disabled' do + before do + PuppetLint.configuration.docs_ignore_private_api = false + end + + after do + PuppetLint.configuration.docs_ignore_private_api = true + end + + it do + expect(PuppetLint.configuration.docs_ignore_private_api).to be(false) + end + + it 'should detect a single problems' do + expect(problems).to have(1).problem + end + + it 'should create a warning' do + expect(problems).to contain_warning(class_msg % :foo).on_line(6).in_column(15) + end end + end context 'define missing documentation (@param bar) for a parameter' do