Repository: flutter
Issue: --format=machine parameter for flutter analyze 
Labels: c: new feature,tool,c: proposal,P2,team-tool,triaged-tool

 @christopherfujino 
 
<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Use case

<!--
     Please tell us the problem you are running into that led to you wanting
     a new feature.

     Is your feature request related to a problem? Please give a clear and
     concise description of what the problem is.

     Describe the alternative solutions you've considered. Is there a package
     on pub.dev/flutter that already solves this?
-->

`dart analyze` has a parameter `--format`:

```
    --format=<value>         Specifies the format to display errors.

          [default]          The default output format. This format is intended to be user consumable.
                             The format is not specified and can change between releases.
          [json]             A machine readable output in a JSON format.
          [machine]          A machine readable output. The format is:

                             SEVERITY|TYPE|ERROR_CODE|FILE_PATH|LINE|COLUMN|LENGTH|ERROR_MESSAGE

                             Note that the pipe character is escaped with backslashes for the file path and error message fields.
```

The output from `dart analyze --format=machine` is supported by https://github.com/tomasbjerre/violation-comments-action so that it is possible to get analysis comments directly in PR diffs like this but with Dart code:
![image](https://user-images.githubusercontent.com/189982/145688461-866925bf-85fc-4d08-b13d-316aa8ac5385.png)


It might therefore be considered advantageous if `flutter analyze` also had this feature for consistency. Note: There may be other `dart analyze` parameters that are not available for `flutter analyze` but those are not part of this feature request.



## Proposal

<!--
     Briefly but precisely describe what you would like Flutter to be able to do.

     Consider attaching something showing what you are imagining:
      * images
      * videos
      * code samples

     Does this have to be provided by Flutter directly, or can it be provided
     by a package on pub.dev/flutter? If so, maybe consider implementing and
     publishing such a package rather than filing a bug.
-->

I propose the implementation of `flutter analyze --format=…`. The means would mean changing at least:

* https://github.com/flutter/flutter/blob/master/packages/packages/flutter_tools/lib/src/commands/analyze.dart to add `argParser.addOption('format', …`
* https://github.com/flutter/flutter/blob/master/packages/packages/flutter_tools/lib/src/commands/analyze_base.dart to pick up `argResults['format']` and write the specified output format

We need the same or almost the same code as  `emitMachineFormat` and `emitJsonFormat`  from https://github.com/dart-lang/sdk/blob/main/pkg/dartdev/lib/src/commands/analyze.dart and I suggest we just copy that code and modify as needed. In the name of reuse, it might be considered to introduce a pub.dev package but I personally believe that copying code is a better option in this case.