cookstyle icon indicating copy to clipboard operation
cookstyle copied to clipboard

using the `--display-cop-names` flag changes the exit status from 1 to 0

Open moutons opened this issue 5 years ago • 1 comments

Version:

cookstyle 5.9.3

Environment:

ubuntu 18, zsh, chefdk 4.5.0

Scenario:

It looks like the cookstyle 5.9.3 command that comes with ChefDK 4.5.0 will erroneously return success (exit status zero on Linux) if the --display-cop-names flag is specified. But if the cookstyle command is run alone, without the --display-cop-names flag, it exits nonzero on the same underlying cookbook code.

Steps to Reproduce:

where $foldername is a cookbook to be checked using cookstyle

user@host (master) foldername
$ cookstyle --version
Cookstyle 5.9.3
* RuboCop 0.72.0

user@host (master) foldername
$ cookstyle; echo "Exit status: $?"
Inspecting 8 files
.RRRCRR.

Offenses:

metadata.rb:7:1: R: ChefDeprecations/LongDescriptionMetadata: The long_description metadata.rb method is not used and is unnecessary in cookbooks
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
attributes/default.rb:2:1: R: ChefStyle/CommentFormat: Properly format header comments
# Cookbook Name:: foldername
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
. . .
8 files inspected, 13 offenses detected
Exit status: 1

contrast that exit status with the following:

user@host (master) foldername
$ cookstyle --display-cop-names; echo "Exit status: $?"
Inspecting 8 files
.RRRRRR.

Offenses:

metadata.rb:7:1: R: ChefDeprecations/LongDescriptionMetadata: The long_description metadata.rb method is not used and is unnecessary in cookbooks
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
attributes/default.rb:2:1: R: ChefStyle/CommentFormat: Properly format header comments
# Cookbook Name:: foldername
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
. . .
8 files inspected, 11 offenses detected
Exit status: 0

Expected Result:

Using the --display-cop-names flag shouldn't change the exit status

Actual Result:

Using the --display-cop-names flag changes the exit code

moutons avatar Nov 08 '19 15:11 moutons

I also came across this and noticed this was not the behaviour at some point in time, making our CI system not fail linting tests when it should.

After a look through the help command @Lasering pointed out you can pass the --fail-level [A,R,C,W,E,F] parameter to cookstyle, which solves this.

t0rrant avatar Feb 20 '20 14:02 t0rrant