-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
548 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/custom_lint/lib/src/output/default_output_format.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:analyzer_plugin/protocol/protocol_common.dart'; | ||
import 'package:cli_util/cli_logging.dart'; | ||
|
||
import 'output_format.dart'; | ||
import 'render_lints.dart'; | ||
|
||
/// The default output format. | ||
class DefaultOutputFormat implements OutputFormat { | ||
@override | ||
void render({ | ||
required Iterable<AnalysisError> errors, | ||
required Logger log, | ||
}) { | ||
if (errors.isEmpty) { | ||
log.stdout('No issues found!'); | ||
return; | ||
} | ||
|
||
for (final error in errors) { | ||
log.stdout( | ||
' ${error.location.relativePath}:${error.location.startLine}:${error.location.startColumn}' | ||
' • ${error.message} • ${error.code} • ${error.severity.name}', | ||
); | ||
} | ||
|
||
// Display a summary separated from the lints | ||
log.stdout(''); | ||
final errorCount = errors.length; | ||
log.stdout('$errorCount issue${errorCount > 1 ? 's' : ''} found.'); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
packages/custom_lint/lib/src/output/json_output_format.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:analyzer_plugin/protocol/protocol_common.dart'; | ||
import 'package:cli_util/cli_logging.dart'; | ||
|
||
import 'output_format.dart'; | ||
|
||
/// The JSON output format. | ||
/// | ||
/// Code is an adaption of the original Dart SDK JSON format. | ||
/// See: https://github.com/dart-lang/sdk/blob/main/pkg/dartdev/lib/src/commands/analyze.dart | ||
class JsonOutputFormat implements OutputFormat { | ||
@override | ||
void render({ | ||
required Iterable<AnalysisError> errors, | ||
required Logger log, | ||
}) { | ||
final diagnostics = <Map<String, Object?>>[]; | ||
for (final error in errors) { | ||
final contextMessages = <Map<String, Object?>>[]; | ||
if (error.contextMessages != null) { | ||
for (final contextMessage in error.contextMessages!) { | ||
final startOffset = contextMessage.location.offset; | ||
contextMessages.add({ | ||
'location': _location( | ||
file: contextMessage.location.file, | ||
range: _range( | ||
start: _position( | ||
offset: startOffset, | ||
line: contextMessage.location.startLine, | ||
column: contextMessage.location.startColumn, | ||
), | ||
end: _position( | ||
offset: startOffset + contextMessage.location.length, | ||
line: contextMessage.location.endLine, | ||
column: contextMessage.location.endColumn, | ||
), | ||
), | ||
), | ||
'message': contextMessage.message, | ||
}); | ||
} | ||
} | ||
final startOffset = error.location.offset; | ||
diagnostics.add({ | ||
'code': error.code, | ||
'severity': error.severity, | ||
'type': error.type, | ||
'location': _location( | ||
file: error.location.file, | ||
range: _range( | ||
start: _position( | ||
offset: startOffset, | ||
line: error.location.startLine, | ||
column: error.location.startColumn, | ||
), | ||
end: _position( | ||
offset: startOffset + error.location.length, | ||
line: error.location.endLine, | ||
column: error.location.endColumn, | ||
), | ||
), | ||
), | ||
'problemMessage': error.message, | ||
if (error.correction != null) 'correctionMessage': error.correction, | ||
if (contextMessages.isNotEmpty) 'contextMessages': contextMessages, | ||
if (error.url != null) 'documentation': error.url, | ||
}); | ||
} | ||
log.stdout( | ||
json.encode({ | ||
'version': 1, | ||
'diagnostics': diagnostics, | ||
}), | ||
); | ||
} | ||
|
||
Map<String, Object?> _location({ | ||
required String file, | ||
required Map<String, Object?> range, | ||
}) { | ||
return { | ||
'file': file, | ||
'range': range, | ||
}; | ||
} | ||
|
||
Map<String, Object?> _position({ | ||
int? offset, | ||
int? line, | ||
int? column, | ||
}) { | ||
return { | ||
'offset': offset, | ||
'line': line, | ||
'column': column, | ||
}; | ||
} | ||
|
||
Map<String, Object?> _range({ | ||
required Map<String, Object?> start, | ||
required Map<String, Object?> end, | ||
}) { | ||
return { | ||
'start': start, | ||
'end': end, | ||
}; | ||
} | ||
} |
Oops, something went wrong.
e3d97eb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
custom-lint-website – ./
custom-lint-website-git-main-invertase.vercel.app
custom-lint-website-invertase.vercel.app
custom-lint-website.vercel.app
custom-lint.dev
www.custom-lint.dev