Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Enable and fix package:pedantic lints #62

Merged
merged 3 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
linter:
rules:
- prefer_equal_for_default_values
- prefer_generic_function_type_aliases
- slash_for_doc_comments
- unnecessary_const
- unnecessary_new
errors:
prefer_spread_collections: ignore
17 changes: 9 additions & 8 deletions lib/src/chain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'trace.dart';
import 'utils.dart';

/// A function that handles errors in the zone wrapped by [Chain.capture].
@Deprecated("Will be removed in stack_trace 2.0.0.")
@Deprecated('Will be removed in stack_trace 2.0.0.')
typedef ChainHandler = void Function(dynamic error, Chain chain);

/// An opaque key used to track the current [StackZoneSpecification].
Expand Down Expand Up @@ -72,13 +72,13 @@ class Chain implements StackTrace {
/// `false`, [onError] must be `null`.
///
/// If [callback] returns a value, it will be returned by [capture] as well.
static T capture<T>(T callback(),
{void onError(error, Chain chain),
static T capture<T>(T Function() callback,
{void Function(Object error, Chain) onError,
bool when = true,
bool errorZone = true}) {
if (!errorZone && onError != null) {
throw ArgumentError.value(
onError, "onError", "must be null if errorZone is false");
onError, 'onError', 'must be null if errorZone is false');
}

if (!when) {
Expand Down Expand Up @@ -114,7 +114,7 @@ class Chain implements StackTrace {
/// [callback] in a [Zone] in which chain capturing is disabled.
///
/// If [callback] returns a value, it will be returned by [disable] as well.
static T disable<T>(T callback(), {bool when = true}) {
static T disable<T>(T Function() callback, {bool when = true}) {
var zoneValues =
when ? {_specKey: null, StackZoneSpecification.disableKey: true} : null;

Expand All @@ -126,8 +126,8 @@ class Chain implements StackTrace {
/// Prior to Dart 1.7, this was necessary to ensure that stack traces for
/// exceptions reported with [Completer.completeError] and
/// [StreamController.addError] were tracked correctly.
@Deprecated("Chain.track is not necessary in Dart 1.7+.")
static track(futureOrStream) => futureOrStream;
@Deprecated('Chain.track is not necessary in Dart 1.7+.')
static dynamic track(futureOrStream) => futureOrStream;

/// Returns the current stack chain.
///
Expand Down Expand Up @@ -211,7 +211,7 @@ class Chain implements StackTrace {
/// If [terse] is true, this will also fold together frames from the core
/// library or from this package, and simplify core library frames as in
/// [Trace.terse].
Chain foldFrames(bool predicate(Frame frame), {bool terse = false}) {
Chain foldFrames(bool Function(Frame) predicate, {bool terse = false}) {
var foldedTraces =
traces.map((trace) => trace.foldFrames(predicate, terse: terse));
var nonEmptyTraces = foldedTraces.where((trace) {
Expand Down Expand Up @@ -241,6 +241,7 @@ class Chain implements StackTrace {
/// in the chain.
Trace toTrace() => Trace(traces.expand((trace) => trace.frames));

@override
String toString() {
// Figure out the longest path so we know how much to pad.
var longest = traces.map((trace) {
Expand Down
31 changes: 16 additions & 15 deletions lib/src/frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final _v8EvalLocation =
// anonymous/<@http://pub.dartlang.org/stuff.js line 693 > Function:3:40
// anonymous/<@http://pub.dartlang.org/stuff.js line 693 > eval:3:40
final _firefoxEvalLocation =
RegExp(r"(\S+)@(\S+) line (\d+) >.* (Function|eval):\d+:\d+");
RegExp(r'(\S+)@(\S+) line (\d+) >.* (Function|eval):\d+:\d+');

// .VW.call$0@http://pub.dartlang.org/stuff.dart.js:560
// .VW.call$0("arg")@http://pub.dartlang.org/stuff.dart.js:560
Expand Down Expand Up @@ -65,7 +65,7 @@ final _friendlyFrame = RegExp(r'^(\S+)(?: (\d+)(?::(\d+))?)?\s+([^\d].*)$');
/// VM.
final _asyncBody = RegExp(r'<(<anonymous closure>|[^>]+)_async_body>');

final _initialDot = RegExp(r"^\.");
final _initialDot = RegExp(r'^\.');

/// A single stack frame. Each frame points to a precise location in Dart code.
class Frame {
Expand Down Expand Up @@ -100,7 +100,7 @@ class Frame {
/// This will usually be the string form of [uri], but a relative URI will be
/// used if possible. Data URIs will be truncated.
String get library {
if (uri.scheme == 'data') return "data:...";
if (uri.scheme == 'data') return 'data:...';
return path.prettyUri(uri);
}

Expand All @@ -125,8 +125,8 @@ class Frame {
/// higher than `1`, it will return higher frames.
factory Frame.caller([int level = 1]) {
if (level < 0) {
throw ArgumentError("Argument [level] must be greater than or equal "
"to 0.");
throw ArgumentError('Argument [level] must be greater than or equal '
'to 0.');
}

return Trace.current(level + 1).frames.first;
Expand All @@ -146,8 +146,8 @@ class Frame {
// Get the pieces out of the regexp match. Function, URI and line should
// always be found. The column is optional.
var member = match[1]
.replaceAll(_asyncBody, "<async>")
.replaceAll("<anonymous closure>", "<fn>");
.replaceAll(_asyncBody, '<async>')
.replaceAll('<anonymous closure>', '<fn>');
var uri = Uri.parse(match[2]);

var lineAndColumn = match[3].split(':');
Expand Down Expand Up @@ -191,13 +191,13 @@ class Frame {
return parseLocation(
match[2],
match[1]
.replaceAll("<anonymous>", "<fn>")
.replaceAll("Anonymous function", "<fn>")
.replaceAll("(anonymous function)", "<fn>"));
.replaceAll('<anonymous>', '<fn>')
.replaceAll('Anonymous function', '<fn>')
.replaceAll('(anonymous function)', '<fn>'));
} else {
// The second form looks like " at LOCATION", and is used for
// anonymous functions.
return parseLocation(match[3], "<fn>");
return parseLocation(match[3], '<fn>');
}
});

Expand Down Expand Up @@ -244,7 +244,7 @@ class Frame {
if (match[1] != null) {
member = match[1];
member +=
List.filled('/'.allMatches(match[2]).length, ".<fn>").join();
List.filled('/'.allMatches(match[2]).length, '.<fn>').join();
if (member == '') member = '<fn>';

// Some Firefox members have initial dots. We remove them for
Expand All @@ -261,11 +261,11 @@ class Frame {
});

/// Parses a string representation of a Safari 6.0 stack frame.
@Deprecated("Use Frame.parseSafari instead.")
@Deprecated('Use Frame.parseSafari instead.')
factory Frame.parseSafari6_0(String frame) => Frame.parseFirefox(frame);

/// Parses a string representation of a Safari 6.1+ stack frame.
@Deprecated("Use Frame.parseSafari instead.")
@Deprecated('Use Frame.parseSafari instead.')
factory Frame.parseSafari6_1(String frame) => Frame.parseFirefox(frame);

/// Parses a string representation of a Safari stack frame.
Expand Down Expand Up @@ -323,7 +323,7 @@ class Frame {
///
/// If [body] throws a [FormatException], returns an [UnparsedFrame] with
/// [text] instead.
static Frame _catchFormatException(String text, Frame body()) {
static Frame _catchFormatException(String text, Frame Function() body) {
try {
return body();
} on FormatException catch (_) {
Expand All @@ -333,5 +333,6 @@ class Frame {

Frame(this.uri, this.line, this.column, this.member);

@override
String toString() => '$location in $member';
}
12 changes: 7 additions & 5 deletions lib/src/lazy_chain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ class LazyChain implements Chain {

LazyChain(this._thunk);

Chain get _chain {
if (_inner == null) _inner = _thunk();
return _inner;
}
Chain get _chain => _inner ??= _thunk();

@override
List<Trace> get traces => _chain.traces;
@override
Chain get terse => _chain.terse;
Chain foldFrames(bool predicate(Frame frame), {bool terse = false}) =>
@override
Chain foldFrames(bool Function(Frame) predicate, {bool terse = false}) =>
LazyChain(() => _chain.foldFrames(predicate, terse: terse));
@override
Trace toTrace() => LazyTrace(() => _chain.toTrace());
@override
String toString() => _chain.toString();
}
13 changes: 8 additions & 5 deletions lib/src/lazy_trace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ class LazyTrace implements Trace {

LazyTrace(this._thunk);

Trace get _trace {
if (_inner == null) _inner = _thunk();
return _inner;
}
Trace get _trace => _inner ??= _thunk();

@override
List<Frame> get frames => _trace.frames;
@override
StackTrace get original => _trace.original;
@override
StackTrace get vmTrace => _trace.vmTrace;
@override
Trace get terse => LazyTrace(() => _trace.terse);
Trace foldFrames(bool predicate(Frame frame), {bool terse = false}) =>
@override
Trace foldFrames(bool Function(Frame) predicate, {bool terse = false}) =>
LazyTrace(() => _trace.foldFrames(predicate, terse: terse));
@override
String toString() => _trace.toString();

// Work around issue 14075.
Expand Down
10 changes: 5 additions & 5 deletions lib/src/stack_zone_specification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class StackZoneSpecification {
///
/// The chain associated with a given stack trace doesn't contain a node for
/// that stack trace.
final _chains = Expando<_Node>("stack chains");
final _chains = Expando<_Node>('stack chains');

/// The error handler for the zone.
///
Expand Down Expand Up @@ -113,7 +113,7 @@ class StackZoneSpecification {
/// Tracks the current stack chain so it can be set to [_currentChain] when
/// [f] is run.
ZoneCallback<R> _registerCallback<R>(
Zone self, ZoneDelegate parent, Zone zone, R f()) {
Zone self, ZoneDelegate parent, Zone zone, R Function() f) {
if (f == null || _disabled) return parent.registerCallback(zone, f);
var node = _createNode(1);
return parent.registerCallback(zone, () => _run(f, node));
Expand All @@ -122,7 +122,7 @@ class StackZoneSpecification {
/// Tracks the current stack chain so it can be set to [_currentChain] when
/// [f] is run.
ZoneUnaryCallback<R, T> _registerUnaryCallback<R, T>(
Zone self, ZoneDelegate parent, Zone zone, R f(T arg)) {
Zone self, ZoneDelegate parent, Zone zone, R Function(T) f) {
if (f == null || _disabled) return parent.registerUnaryCallback(zone, f);
var node = _createNode(1);
return parent.registerUnaryCallback(zone, (arg) {
Expand Down Expand Up @@ -184,7 +184,7 @@ class StackZoneSpecification {
}

var asyncError = parent.errorCallback(zone, error, stackTrace);
return asyncError == null ? AsyncError(error, stackTrace) : asyncError;
return asyncError ?? AsyncError(error, stackTrace);
}

/// Creates a [_Node] with the current stack trace and linked to
Expand All @@ -202,7 +202,7 @@ class StackZoneSpecification {
///
/// If [f] throws an error, this associates [node] with that error's stack
/// trace.
T _run<T>(T f(), _Node node) {
T _run<T>(T Function() f, _Node node) {
var previousNode = _currentNode;
_currentNode = node;
try {
Expand Down
Loading