Coverage report for lib/src/error_listener.dart

Line coverage: 6 / 6 (100.0%)

All files > lib/src/error_listener.dart

1
// Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file
2
// for details. All rights reserved. Use of this source code is governed by a
3
// BSD-style license that can be found in the LICENSE file.
4
5
library dart_style.src.error_listener;
6
7
import 'package:analyzer/error/error.dart';
8
import 'package:analyzer/error/listener.dart';
9
10
import 'exceptions.dart';
11
12
/// A simple [AnalysisErrorListener] that just collects the reported errors.
13
class ErrorListener implements AnalysisErrorListener {
14
  final _errors = <AnalysisError>[];
15
161
  void onError(AnalysisError error) {
17
    // Fasta produces some semantic errors, which we want to ignore so that
18
    // users can format code containing static errors.
193
    if (error.errorCode.type != ErrorType.SYNTACTIC_ERROR) return;
20
212
    _errors.add(error);
22
  }
23
24
  /// Throws a [FormatterException] if any errors have been reported.
253
  void throwIfErrors() {
266
    if (_errors.isEmpty) return;
27
282
    throw new FormatterException(_errors);
29
  }
30
}