flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.33k stars 27.53k forks source link

[flutter analyze] add --set-exit-if-error option to fail if gets an error from the linter #86883

Open danielgomezrico opened 3 years ago

danielgomezrico commented 3 years ago

Use case

I would like to use the tool flutter analyze on our CI workflow, so, if we get a failure (fatal) from the linter the CI fails.

Currently, I can list all the outputs, fatal, warnings, and infos, but I don't have an out-of-the-box way to make it run an exit so the bash scripts on CI fails.

Proposal

This out of the box way already exists on flutter format tool and is --set-exit-if-changed, it fails if something needs to be changed, it would be awesome to have an option like this one but for flutter analyze, maybe:

One way to do it is with a bash script but is not out of the box using Flutter 2 (https://github.com/flutter/flutter/issues/20855):

RESULT=$(flutter analyze --no-pub --no-fatal-infos --no-fatal-warnings)

if [[ $RESULT == *"error •"* ]]; then
    echo "----> :O Some files have linter fatal errors, check Dart Analysis"
    exit 1
else
    echo "----> All things are good :)"
fi
justyntemme commented 2 years ago

This would be awesome , i am starting to look into this

justyntemme commented 2 years ago

I have added the code below, however i am looking how best to check for errors when the function is called, as it's a void and does not return any errors. Perhaps we could change this to be more like format?


    argParser.addFlag(
      'set-exit-if-error',
      negatable: true,
      hide: !verboseHelp,
      help: 'The path to write the request and response protocol. This is '
          'only intended to be used for debugging the tooling.',
    );
justyntemme commented 2 years ago

@TahaTesser Can you look over my question and give your thoughts on implementation? we may need to convert the void function to return a status code for errors.

aap01 commented 1 year ago

Is there any follow-up on this?