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

Commit 6af4349

Browse files
authored
Fix comment reference issues, among other new lints (#119)
1 parent 2194227 commit 6af4349

File tree

12 files changed

+97
-119
lines changed

12 files changed

+97
-119
lines changed

analysis_options.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://dart.dev/guides/language/analysis-options
12
include: package:lints/recommended.yaml
23

34
analyzer:
@@ -8,9 +9,14 @@ analyzer:
89
linter:
910
rules:
1011
- always_declare_return_types
12+
- avoid_catching_errors
13+
- avoid_dynamic_calls
1114
- avoid_private_typedef_functions
15+
- avoid_redundant_argument_values
1216
- avoid_unused_constructor_parameters
17+
- avoid_void_async
1318
- cancel_subscriptions
19+
- comment_references
1420
- directives_ordering
1521
- lines_longer_than_80_chars
1622
- literal_only_boolean_expressions
@@ -19,12 +25,20 @@ linter:
1925
- no_runtimeType_toString
2026
- omit_local_variable_types
2127
- package_api_docs
28+
- prefer_asserts_in_initializer_lists
29+
- prefer_const_constructors
30+
- prefer_const_declarations
2231
- prefer_relative_imports
2332
- prefer_single_quotes
33+
- sort_pub_dependencies
2434
- test_types_in_equals
2535
- throw_in_finally
2636
- type_annotate_public_apis
2737
- unawaited_futures
2838
- unnecessary_await_in_return
2939
- unnecessary_lambdas
40+
- unnecessary_parenthesis
41+
- unnecessary_statements
42+
- use_is_even_rather_than_modulo
43+
- use_string_buffers
3044
- use_super_parameters

example/example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void main() {
77
}
88

99
void _scheduleAsync() {
10-
Future.delayed(Duration(seconds: 1)).then((_) => _runAsync());
10+
Future.delayed(const Duration(seconds: 1)).then((_) => _runAsync());
1111
}
1212

1313
void _runAsync() {

lib/src/chain.dart

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final _specKey = Object();
2121
/// A chain of stack traces.
2222
///
2323
/// A stack chain is a collection of one or more stack traces that collectively
24-
/// represent the path from [main] through nested function calls to a particular
24+
/// represent the path from `main` through nested function calls to a particular
2525
/// code location, usually where an error was thrown. Multiple stack traces are
2626
/// necessary when using asynchronous functions, since the program's stack is
2727
/// reset before each asynchronous callback is run.
@@ -189,21 +189,19 @@ class Chain implements StackTrace {
189189
/// Returns a new [Chain] comprised of [traces].
190190
Chain(Iterable<Trace> traces) : traces = List<Trace>.unmodifiable(traces);
191191

192-
/// Returns a terser version of [this].
192+
/// Returns a terser version of this chain.
193193
///
194194
/// This calls [Trace.terse] on every trace in [traces], and discards any
195195
/// trace that contain only internal frames.
196196
///
197197
/// This won't do anything with a raw JavaScript trace, since there's no way
198198
/// to determine which frames come from which Dart libraries. However, the
199-
/// [`source_map_stack_trace`][source_map_stack_trace] package can be used to
200-
/// convert JavaScript traces into Dart-style traces.
201-
///
202-
/// [source_map_stack_trace]: https://pub.dev/packages/source_map_stack_trace
199+
/// [`source_map_stack_trace`](https://pub.dev/packages/source_map_stack_trace)
200+
/// package can be used to convert JavaScript traces into Dart-style traces.
203201
Chain get terse => foldFrames((_) => false, terse: true);
204202

205-
/// Returns a new [Chain] based on [this] where multiple stack frames matching
206-
/// [predicate] are folded together.
203+
/// Returns a new [Chain] based on this chain where multiple stack frames
204+
/// matching [predicate] are folded together.
207205
///
208206
/// This means that whenever there are multiple frames in a row that match
209207
/// [predicate], only the last one is kept. In addition, traces that are
@@ -239,7 +237,7 @@ class Chain implements StackTrace {
239237
return Chain(nonEmptyTraces);
240238
}
241239

242-
/// Converts [this] to a [Trace].
240+
/// Converts this chain to a [Trace].
243241
///
244242
/// The trace version of a chain is just the concatenation of all the traces
245243
/// in the chain.
@@ -248,18 +246,19 @@ class Chain implements StackTrace {
248246
@override
249247
String toString() {
250248
// Figure out the longest path so we know how much to pad.
251-
var longest = traces.map((trace) {
252-
return trace.frames
253-
.map((frame) => frame.location.length)
254-
.fold(0, math.max);
255-
}).fold(0, math.max);
249+
var longest = traces
250+
.map((trace) => trace.frames
251+
.map((frame) => frame.location.length)
252+
.fold(0, math.max))
253+
.fold(0, math.max);
256254

257255
// Don't call out to [Trace.toString] here because that doesn't ensure that
258256
// padding is consistent across all traces.
259-
return traces.map((trace) {
260-
return trace.frames.map((frame) {
261-
return '${frame.location.padRight(longest)} ${frame.member}\n';
262-
}).join();
263-
}).join(chainGap);
257+
return traces
258+
.map((trace) => trace.frames
259+
.map((frame) =>
260+
'${frame.location.padRight(longest)} ${frame.member}\n')
261+
.join())
262+
.join(chainGap);
264263
}
265264
}

lib/src/stack_zone_specification.dart

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,13 @@ class StackZoneSpecification {
6464
StackZoneSpecification(this._onError, {bool errorZone = true})
6565
: _errorZone = errorZone;
6666

67-
/// Converts [this] to a real [ZoneSpecification].
68-
ZoneSpecification toSpec() {
69-
return ZoneSpecification(
70-
handleUncaughtError: _errorZone ? _handleUncaughtError : null,
71-
registerCallback: _registerCallback,
72-
registerUnaryCallback: _registerUnaryCallback,
73-
registerBinaryCallback: _registerBinaryCallback,
74-
errorCallback: _errorCallback);
75-
}
67+
/// Converts this specification to a real [ZoneSpecification].
68+
ZoneSpecification toSpec() => ZoneSpecification(
69+
handleUncaughtError: _errorZone ? _handleUncaughtError : null,
70+
registerCallback: _registerCallback,
71+
registerUnaryCallback: _registerUnaryCallback,
72+
registerBinaryCallback: _registerBinaryCallback,
73+
errorCallback: _errorCallback);
7674

7775
/// Returns the current stack chain.
7876
///
@@ -107,7 +105,7 @@ class StackZoneSpecification {
107105
}
108106
}
109107

110-
/// Tracks the current stack chain so it can be set to [_currentChain] when
108+
/// Tracks the current stack chain so it can be set to [_currentNode] when
111109
/// [f] is run.
112110
ZoneCallback<R> _registerCallback<R>(
113111
Zone self, ZoneDelegate parent, Zone zone, R Function() f) {
@@ -116,27 +114,25 @@ class StackZoneSpecification {
116114
return parent.registerCallback(zone, () => _run(f, node));
117115
}
118116

119-
/// Tracks the current stack chain so it can be set to [_currentChain] when
117+
/// Tracks the current stack chain so it can be set to [_currentNode] when
120118
/// [f] is run.
121119
ZoneUnaryCallback<R, T> _registerUnaryCallback<R, T>(
122120
Zone self, ZoneDelegate parent, Zone zone, R Function(T) f) {
123121
if (_disabled) return parent.registerUnaryCallback(zone, f);
124122
var node = _createNode(1);
125-
return parent.registerUnaryCallback(zone, (arg) {
126-
return _run(() => f(arg), node);
127-
});
123+
return parent.registerUnaryCallback(
124+
zone, (arg) => _run(() => f(arg), node));
128125
}
129126

130-
/// Tracks the current stack chain so it can be set to [_currentChain] when
127+
/// Tracks the current stack chain so it can be set to [_currentNode] when
131128
/// [f] is run.
132129
ZoneBinaryCallback<R, T1, T2> _registerBinaryCallback<R, T1, T2>(
133130
Zone self, ZoneDelegate parent, Zone zone, R Function(T1, T2) f) {
134131
if (_disabled) return parent.registerBinaryCallback(zone, f);
135132

136133
var node = _createNode(1);
137-
return parent.registerBinaryCallback(zone, (arg1, arg2) {
138-
return _run(() => f(arg1, arg2), node);
139-
});
134+
return parent.registerBinaryCallback(
135+
zone, (arg1, arg2) => _run(() => f(arg1, arg2), node));
140136
}
141137

142138
/// Looks up the chain associated with [stackTrace] and passes it either to

lib/src/trace.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ class Trace implements StackTrace {
9494
}
9595

9696
var trace = Trace.from(StackTrace.current);
97-
return LazyTrace(() {
98-
// JS includes a frame for the call to StackTrace.current, but the VM
99-
// doesn't, so we skip an extra frame in a JS context.
100-
return Trace(trace.frames.skip(level + (inJS ? 2 : 1)),
101-
original: trace.original.toString());
102-
});
97+
return LazyTrace(
98+
() =>
99+
// JS includes a frame for the call to StackTrace.current, but the VM
100+
// doesn't, so we skip an extra frame in a JS context.
101+
Trace(trace.frames.skip(level + (inJS ? 2 : 1)),
102+
original: trace.original.toString()),
103+
);
103104
}
104105

105106
/// Returns a new stack trace containing the same data as [trace].
@@ -250,7 +251,7 @@ class Trace implements StackTrace {
250251
/// platform is being used.
251252
StackTrace get vmTrace => VMTrace(frames);
252253

253-
/// Returns a terser version of [this].
254+
/// Returns a terser version of this trace.
254255
///
255256
/// This is accomplished by folding together multiple stack frames from the
256257
/// core library or from this package, as in [foldFrames]. Remaining core
@@ -260,15 +261,13 @@ class Trace implements StackTrace {
260261
///
261262
/// This won't do anything with a raw JavaScript trace, since there's no way
262263
/// to determine which frames come from which Dart libraries. However, the
263-
/// [`source_map_stack_trace`][source_map_stack_trace] package can be used to
264-
/// convert JavaScript traces into Dart-style traces.
265-
///
266-
/// [source_map_stack_trace]: https://pub.dev/packages/source_map_stack_trace
264+
/// [`source_map_stack_trace`][https://pub.dev/packages/source_map_stack_trace]
265+
/// package can be used to convert JavaScript traces into Dart-style traces.
267266
///
268267
/// For custom folding, see [foldFrames].
269268
Trace get terse => foldFrames((_) => false, terse: true);
270269

271-
/// Returns a new [Trace] based on [this] where multiple stack frames matching
270+
/// Returns a new [Trace] based on `this` where multiple stack frames matching
272271
/// [predicate] are folded together.
273272
///
274273
/// This means that whenever there are multiple frames in a row that match

lib/src/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ final vmChainGap = RegExp(r'^<asynchronous suspension>\n?$', multiLine: true);
1212

1313
// TODO(nweiz): When cross-platform imports work, use them to set this.
1414
/// Whether we're running in a JS context.
15-
final bool inJS = 0.0 is int;
15+
const bool inJS = 0.0 is int;

test/chain/chain_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void main() {
103103
test("doesn't enable chain-tracking", () {
104104
return Chain.disable(() {
105105
return Chain.capture(() {
106-
var completer = Completer();
106+
var completer = Completer<Chain>();
107107
inMicrotask(() {
108108
completer.complete(Chain.current());
109109
});
@@ -126,7 +126,7 @@ void main() {
126126
group('Chain.disable()', () {
127127
test('disables chain-tracking', () {
128128
return Chain.disable(() {
129-
var completer = Completer();
129+
var completer = Completer<Chain>();
130130
inMicrotask(() => completer.complete(Chain.current()));
131131

132132
return completer.future.then((chain) {
@@ -138,7 +138,7 @@ void main() {
138138
test('Chain.capture() re-enables chain-tracking', () {
139139
return Chain.disable(() {
140140
return Chain.capture(() {
141-
var completer = Completer();
141+
var completer = Completer<Chain>();
142142
inMicrotask(() => completer.complete(Chain.current()));
143143

144144
return completer.future.then((chain) {
@@ -173,7 +173,7 @@ void main() {
173173
test("with when: false doesn't disable", () {
174174
return Chain.capture(() {
175175
return Chain.disable(() {
176-
var completer = Completer();
176+
var completer = Completer<Chain>();
177177
inMicrotask(() => completer.complete(Chain.current()));
178178

179179
return completer.future.then((chain) {

0 commit comments

Comments
 (0)