CFLint icon indicating copy to clipboard operation
CFLint copied to clipboard

Suggestion: exit code

Open jaredbeck opened this issue 6 years ago • 9 comments

Given input that produces no warnings, cflint would exit with code 0.

Given input that produces warnings, cflint would exit with a non-zero code, perhaps 1.

This would allow cflint to be used as a required step in a build or deploy script.

I don't write much Java, but I would be willing to try building this if it is wanted.

jaredbeck avatar Dec 19 '18 20:12 jaredbeck

@jaredbeck I'd love something like this.

bosonau avatar Jan 30 '19 20:01 bosonau

system.exit(1) should do just that. Use with care though - it will bring down the entire JVM. A bad thing if you run cflint embedded.

On Wed, Jan 30, 2019 at 3:54 PM Boson Au [email protected] wrote:

@jaredbeck https://github.com/jaredbeck I'd love something like this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cflint/CFLint/issues/609#issuecomment-459105018, or mute the thread https://github.com/notifications/unsubscribe-auth/AFtZu_NEYsiIPvuvk-sGpVJWyubtRhlMks5vIgaTgaJpZM4Za81R .

ryaneberly avatar Jan 31 '19 01:01 ryaneberly

I don't write much Java, but I would be willing to try building this if it is wanted.

system.exit(1) should do just that.

Are you saying you want me to try building this, and that's how you want me to do it?

Use with care though - it will bring down the entire JVM. A bad thing if you run cflint embedded.

What does "embedded" mean?

Thanks.

jaredbeck avatar Jan 31 '19 03:01 jaredbeck

If you did try to implement system.exit(1), it's have to be made sure that it only does that if it's run as an executable jar.

What Ryan means with embedded is that for people who use cflint as a java library inside of something else, system.exit(1) would kill their whole JVM instance running the "something else".

As a side note:

You could achieve your original requirement by simply creating findbugs output and check in your CI server if the number of cflint results is 0 or has increased and then fail the build.

On Thu, 31 Jan 2019 at 2:54 PM, ryaneberly [email protected] wrote:

system.exit(1) should do just that. Use with care though - it will bring down the entire JVM. A bad thing if you run cflint embedded.

On Wed, Jan 30, 2019 at 3:54 PM Boson Au [email protected] wrote:

@jaredbeck https://github.com/jaredbeck I'd love something like this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cflint/CFLint/issues/609#issuecomment-459105018, or mute the thread < https://github.com/notifications/unsubscribe-auth/AFtZu_NEYsiIPvuvk-sGpVJWyubtRhlMks5vIgaTgaJpZM4Za81R

.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cflint/CFLint/issues/609#issuecomment-459184256, or mute the thread https://github.com/notifications/unsubscribe-auth/AATrRCZigvVqlGI9qaZV6NCLD47l7P8Xks5vIkzWgaJpZM4Za81R .

TheRealAgentK avatar Jan 31 '19 08:01 TheRealAgentK

so my current situation is this: I have a node app (that uses cfcs for data calls) that already has eslint configured to run on a precommit hook via husky and lint-staged. I'd like to incorporate cflint in this workflow.

there's a npm cflint wrapper but it doesn't generate an exit code. what I'd like is for a way to run cflint w/ an exitcode AND generate an html file

my hack for this is probably this (haven't actually built it but this is the logic)

  • run cflint's jar using child_process,
  • then parse or scrape the resulting xml/json/html file (maybe using cheerio or something) and look for "total errors" the if there is an error to set the exit code to 1 else leave it at 0...

its... a messy solution but would probably work... thats why I'd love for cflint to spit out an exit code.

bosonau avatar Feb 01 '19 03:02 bosonau

It's an easy non-impact to the community if you make the exit code dependent on a command line flag and not utilized by default.

On Thu, Jan 31, 2019 at 10:06 PM Boson Au [email protected] wrote:

so my current situation is this: I have a node app (that uses cfcs for data calls) that already has eslint configured to run on a precommit hook via husky and lint-staged. I'd like to incorporate cflint in this workflow.

there's a npm cflint wrapper but it doesn't generate an exit code. what I'd like is for a way to run cflint w/ an exitcode AND generate an html file

my hack for this is probably this (haven't actually built it but this is the logic)

  • run cflint's jar using child_process,
  • then parse or scrape the resulting xml/json/html file (maybe using cheerio or something) and look for "total errors" the if there is an error to set the exit code to 1 else leave it at 0...

its... a messy solution but would probably work... thats why I'd love for cflint to spit out an exit code.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cflint/CFLint/issues/609#issuecomment-459589383, or mute the thread https://github.com/notifications/unsubscribe-auth/AFtZu8KZ184BaoatFN_ihwtrPjoRc8Ccks5vI68mgaJpZM4Za81R .

ryaneberly avatar Feb 01 '19 03:02 ryaneberly

This would be handy for git hooks as well.

jimpriest avatar Nov 10 '19 21:11 jimpriest

I needed this feature so I implemented it in my fork: https://github.com/NewLunarFire/CFLint/releases/tag/CFLint-1.5.0-SNAPSHOT

I supports no configuration whatsoever. It just returns a -1 exit code if there are any bugs, whatever their severity may be.

I could add a flag to enable / disable this feature, but I don't know what to call it. I could also add a flag to change which severity triggers a non-zero exit code. For example, setting this flag to warning returns zero if there are only info bugs. I am open to suggestions.

NewLunarFire avatar Mar 12 '20 17:03 NewLunarFire

I worked on this feature today. Here is the result on my fork: https://github.com/NewLunarFire/CFLint/releases/tag/CFLint-1.5.1-SNAPSHOT

I added the -failurelevel command-line flag to define the minimum severity level to fail the lint job. If any issue arise that are of this level or higher, the program returns a non-zero exit code. For exemple, -failurelevel warning fails if any issue with severity warning, error, critical and fatal occur.

NewLunarFire avatar Apr 21 '20 21:04 NewLunarFire