Skip to content

Commit

Permalink
feat: report parser error locations in formatted file (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold committed Jun 12, 2022
1 parent 714fe12 commit e76ccf9
Show file tree
Hide file tree
Showing 11 changed files with 1,214 additions and 495 deletions.
2 changes: 1 addition & 1 deletion all_lint_rules.yaml
Expand Up @@ -106,7 +106,7 @@ linter:
- parameter_assignments
- prefer_adjacent_string_concatenation
- prefer_asserts_in_initializer_lists
- prefer_asserts_with_message
# - prefer_asserts_with_message
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_const_constructors
Expand Down
2 changes: 1 addition & 1 deletion melos.yaml
Expand Up @@ -30,7 +30,7 @@ scripts:

analyze:
description: Analyzes Dart packages in the repository.
exec: dart analyze --fata-infos --fata-warnings
exec: dart analyze --fatal-infos --fatal-warnings

test:
description: Runs tests.
Expand Down
2 changes: 2 additions & 0 deletions packages/daco/lib/src/char_codes.dart
@@ -0,0 +1,2 @@
/// Character code for a space character.
const int $SPACE = 32;
30 changes: 3 additions & 27 deletions packages/daco/lib/src/commands/format.dart
Expand Up @@ -2,7 +2,6 @@

import 'dart:io';

import 'package:analyzer/source/line_info.dart';
import 'package:ansi_styles/ansi_styles.dart';
import 'package:dart_style/dart_style.dart';
import 'package:path/path.dart' as p;
Expand Down Expand Up @@ -136,33 +135,10 @@ Future<_FormattingResult> _formatFile(
String formattedSource;
try {
formattedSource = await formatter.format(source, path: file.path);
// ignore: avoid_catches_without_on_clauses
} catch (exception) {
FormatterException? formatterException;
CharacterLocation? fencedCodeBlockLocation;

if (exception is FormatterException) {
formatterException = exception;
} else if (exception is FencedCodeBlockFormatterException) {
formatterException = exception.exception;
final lineInfo = LineInfo.fromContent(source);
fencedCodeBlockLocation = lineInfo.getLocation(exception.offset);
}

if (formatterException == null) {
rethrow;
}

logger.stderr('${AnsiStyles.red('FAILED')} $relativePath');
if (fencedCodeBlockLocation != null) {
logger.stderr(
'in ${AnsiStyles.bold.underline('fenced code block')} at '
'line ${fencedCodeBlockLocation.lineNumber}, '
'column ${fencedCodeBlockLocation.columnNumber}:',
);
}
} on FormatterException catch (exception) {
logger
.stderr(formatterException.message(color: stdout.supportsAnsiEscapes));
..stderr('${AnsiStyles.red('FAILED')} $relativePath')
..stderr(exception.message(color: stdout.supportsAnsiEscapes));

return _FormattingResult.failed;
}
Expand Down
140 changes: 0 additions & 140 deletions packages/daco/lib/src/dart_comments.dart

This file was deleted.

0 comments on commit e76ccf9

Please sign in to comment.