Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default/json output formats #86

Closed
wants to merge 5 commits into from

Conversation

kuhnroyal
Copy link
Contributor

@kuhnroyal kuhnroyal commented Feb 21, 2023

This is an initial start in order to eventually support invertase/github-action-dart-analyzer#199

It works pretty much, most of the output code comes from the Dart SDK. Wonder if there is a way to use it directly?

Fixes #22
Fixes #101

Bildschirm­foto 2023-02-27 um 20 02 25

Bildschirm­foto 2023-02-27 um 20 08 17

@vercel
Copy link

vercel bot commented Feb 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
custom-lint-website ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 27, 2023 at 8:31PM (UTC)

@rrousselGit
Copy link
Collaborator

Wonder if there is. a way to use it directly?

I don't know honestly.

Problem is currently the print overrides which don't work well together with cli_util package and the output expectations in the tests.

What's the issue exactly?

@kuhnroyal
Copy link
Contributor Author

What's the issue exactly?

The cli_util package which the Dart analyzer also uses, has a Logger which uses print internally: https://github.com/dart-lang/cli_util/blame/master/lib/cli_logging.dart#L140
But there is a Zone override to write the log file, maybe the log file should only be generated for the server and not for the client?

@rrousselGit
Copy link
Collaborator

No it is crutial that logs in the client are reported. That's probably the most important bit.

But I do not understand why you need to disable log reporting in the client for this

@rrousselGit
Copy link
Collaborator

Maybe you're looking at modifying the CommandCustomLintDelegate?

@kuhnroyal
Copy link
Contributor Author

Well cli_util uses print and in the current setup print goes into the log file and not to stdout as far as I can tell :)
Can we use some dedicated logging for the log file instead of the zone override?

@kuhnroyal
Copy link
Contributor Author

Maybe I am also just stupid. I fixed the tests and added screenshots of the sample outputs.

@rrousselGit
Copy link
Collaborator

Using zone overrides is expected. It's the most user-friendly experience, as they can just use "print". That's natural
Your implementation should support it.

As I said, you should be able to change CommandCustomLintDelegate to your liking.

@kuhnroyal
Copy link
Contributor Author

I think this is good now, I added a test for the json format and extended the sorting test to take the severity into account.

@kuhnroyal kuhnroyal marked this pull request as ready for review February 27, 2023 20:41
@praxder
Copy link
Contributor

praxder commented Mar 3, 2023

I'm looking forward to this being merged. :)

@@ -70,58 +75,26 @@ Future<void> _runPlugins(
CustomLintRunner runner, {
required bool reload,
}) async {
final log = Logger.standard();

log.progress('Analyzing');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The progress is never stopped

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cli_util automatically stops progress if any other output is performed.

@@ -33,6 +33,7 @@ q: Quit
/// Watch mode cannot be enabled if in release mode.
Future<void> customLint({
bool watchMode = true,
String format = 'default',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use Strings here. Use an enum

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, will do.

import 'package:path/path.dart' as p;

/// The maximum length of any of the existing severity labels.
const int _severityWidth = 7;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird to have this hardcoded I think. We should be able to easily compute this dymically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea maybe, but I wanted to keep the whole output code as close to the original Dart analyzer code as possible. This way custom_lint has the same consistent output formatting and it is easier to keep up with changes in the Dart analyzer.

Comment on lines +20 to +22
/// is used as the usageLineLength.
int? get _dartdevUsageLineLength =>
stdout.hasTerminal ? stdout.terminalColumns : null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how the function name and its implementation are related

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just taken from the Dart analyzer - it is the max line length in a terminal before a line break happens, but only if stdout is connected a terminal.

for (final contextMessage in error.contextMessages!) {
final startOffset = contextMessage.location.offset;
contextMessages.add({
'location': location(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this serialization logic sounds redundant with the AnalyzerConverter class. Which allows converting an AnalysisError from analyzer into one from analyzer_plugin. And the latter has a toJson

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this is just taken from Dart analyzer and is different from the toJson output I believe.


/// Emits a list of lints in the Dart analyzer style default format.
@internal
void emitDefaultFormat(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change the output of the default mode in this PR.
That makes reviewing this PR a bit difficult

If we want to improve the rendering, this should be a separate issue/PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is apparently taken from the analyzer, it'd be great to document that too. Maybe have all the analyzer code in a separate file with a link to their original source

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that is basically most of the output file, I will try to split the custom_lint parts out and add a license-info/documentation at the top.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But splitting up the json/default format into 2 PRs is kinda hard because they are pretty interwoven until the last print step.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good then. I'm fine with having one PR if you move analyzer-stuff in its own file :)
Otherwise it's a bit hard to know what you wrote vs what's forked

@kuhnroyal
Copy link
Contributor Author

Are the 2 output examples in the screenshots something that we generally agree on?

@@ -21,6 +22,8 @@ final helloWordPluginSource = createPluginSource([
)
]);

final ansi = Ansi(Ansi.terminalSupportsAnsi);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests shouldn't rely on terminalSupportsAnsi
Instead they should use a consistent on/off status.

We'd want to test the output both with and without terminalSupportsAnsi then.
Which also means a test which doesn't strip ansi codes to make sure they are present if you don't mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will see if we can simulate this somehow but Github runner terminals don't support ansi.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need github runners for this.

@rrousselGit
Copy link
Collaborator

If you don't mind, I'll wait until I can fix the funky platform crash before merging this.

@kuhnroyal
Copy link
Contributor Author

I am gonna split this up in smaller parts.

@kuhnroyal kuhnroyal closed this Mar 17, 2023
ghost pushed a commit to solid-software/dart_custom_lint that referenced this pull request Dec 5, 2023
)

* Fix false-positives for cyclomatic complexity metric lints

* fmt

---------

Co-authored-by: Yurii Prykhodko <yurii.prykhodko@solid.software>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: improve output formatting when running run custom_lint Update CLI to output severity
3 participants