Skip to content

Commit

Permalink
Merge pull request #804 from xraystyle/feature/list_checks
Browse files Browse the repository at this point in the history
Implement --list-checks feature, to list the names of all available checks from the cli.
  • Loading branch information
rodjek authored Mar 25, 2018
2 parents 1601d29 + 1a2339c commit 2607e54
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Metrics/LineLength:
# Offense count: 65
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 100
Max: 105

# Offense count: 18
Metrics/PerceivedComplexity:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ puppet-lint --fix /modules

Puppet Lint options allow you to modify which checks to run. You can disable any of the checks temporarily or permanently, or you can limit testing to specific checks.

#### List all available checks

To list all available checks along with basic usage documentation, use the `--list-checks` option.

#### Run specific checks

To run only specific checks, use the `--only-checks` option, with a comma-separated list of arguments specifying which checks to make:
Expand All @@ -65,7 +69,7 @@ You can disable specific Lint checks on the command line, disable them permanent

#### Disable checks on the command line

To disable any of the checks when running the `puppet-lint` command, add a `--no-<check name>-check` flag to the command. For example, to skip the 140-character check, run:
To disable any of the checks when running the `puppet-lint` command, add a `--no-<check_name>-check` flag to the command. For example, to skip the 140-character check, run:

```
puppet-lint --no-140chars-check modules/
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet-lint/bin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def run
return 0
end

if PuppetLint.configuration.list_checks
puts PuppetLint.configuration.checks
return 0
end

if @args[0].nil?
puts 'puppet-lint: no file specified'
puts "puppet-lint: try 'puppet-lint --help' for more information"
Expand Down
4 changes: 4 additions & 0 deletions lib/puppet-lint/optparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def self.build(args)
PuppetLint.configuration.json = true
end

opts.on('--list-checks', 'List available check names.') do
PuppetLint.configuration.list_checks = true
end

opts.separator('')
opts.separator(' Checks:')

Expand Down
13 changes: 13 additions & 0 deletions spec/puppet-lint/bin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ def initialize(args)
its(:stdout) { is_expected.to eq("puppet-lint #{PuppetLint::VERSION}") }
end

context 'when asked to display available checks' do
let(:args) { '--list-checks' }
all_checks = PuppetLint.configuration.checks.map(&:to_s)

its(:exitstatus) { is_expected.to eq(0) }

all_checks.each do |c|
it "includes check #{c} in its output" do
expect(subject.stdout).to include c
end
end
end

context 'when passed a backslash separated path on Windows', :if => Gem.win_platform? do
let(:args) do
[
Expand Down

0 comments on commit 2607e54

Please sign in to comment.