Skip to content

Commit 3b27ea7

Browse files
committed
style: update lints and code
1 parent 7ff1d16 commit 3b27ea7

13 files changed

Lines changed: 74 additions & 52 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.3.1
2+
3+
- Fix lint errors.
4+
- Use `package:zekfad_lints/lib.yaml` which aligns with core lints.
5+
16
## 2.3.0
27

38
> Requires Dart 3.6

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ This package provides WASM-ready Dart bindings to JavaScript
2222
## Some notes about `fetch` and `Request`
2323

2424
`fetch` and `Request` have same options but different semantics, e.g. `fetch`'s
25-
default mode is `no-cors` while `Request`'s `cors`. Therefore options objects
26-
for `fetch` function and `Request` constructor made as different extension
25+
default mode is `no-cors` while `Request`'s `cors`. Therefore, options objects
26+
of `fetch` function and `Request` constructor made as different extension
2727
types, although they are interchangeable and both inherited from `RequestInit`.
2828

29-
For more info about that read [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
29+
For more info about that, read [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).

analysis_options.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
include: package:zekfad_lints/recommended.yaml
2-
3-
linter:
4-
rules:
5-
public_member_api_docs: true
1+
include: package:zekfad_lints/lib.yaml

lib/src/iterator/extensions.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ extension CoreIteratorToJSIterator<T extends JSAny> on core.Iterator<T> {
2020
js.Iterator get toJS =>
2121
js.Iterator<T>(
2222
next: ([value]) {
23-
if (!moveNext())
23+
if (!moveNext()) {
2424
return js.IteratorResult(done: true);
25+
}
2526
return js.IteratorResult(value: current);
2627
},
2728
);

lib/src/iterator/iterator.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ extension type Iterator<T extends JSAny>._(JSObject _) implements JSObject {
2020
IteratorResult<T> Function([JSAny? error])? throwValue,
2121
}) {
2222
final object = Iterator._new$1(next: IteratorMethod(next));
23-
if (returnValue != null)
23+
if (returnValue != null) {
2424
object._return = IteratorMethod(returnValue);
25-
if (throwValue != null)
25+
}
26+
if (throwValue != null) {
2627
object._throw = IteratorMethod(throwValue);
28+
}
2729
object._.setProperty(
2830
_symbolIterator,
2931
IteratorSymbolMethod(() => object),
@@ -61,10 +63,11 @@ extension type Iterator<T extends JSAny>._(JSObject _) implements JSObject {
6163
/// and can perform any cleanup actions.
6264
IteratorResult<T> Function([T? value])? get returnValue => _return?.bind(_).call;
6365
set returnValue(IteratorResult<T> Function([T? value])? fn) {
64-
if (fn == null)
66+
if (fn == null) {
6567
_.delete('return'.toJS);
66-
else
68+
} else {
6769
_return = IteratorMethod<T, T>(fn);
70+
}
6871
}
6972

7073
/// A function that accepts zero or one argument and returns an object
@@ -74,10 +77,11 @@ extension type Iterator<T extends JSAny>._(JSObject _) implements JSObject {
7477
/// condition, and exception is typically an `Error` instance.
7578
IteratorResult<T> Function([JSAny? value])? get throwValue => _throw?.bind(_).call;
7679
set throwValue(IteratorResult<T> Function([JSAny? value])? fn) {
77-
if (fn == null)
80+
if (fn == null) {
7881
_.delete('throw'.toJS);
79-
else
82+
} else {
8083
_throw = IteratorMethod<T, JSAny>(fn);
84+
}
8185
}
8286

8387
@JS('next')

lib/src/js_define_property/js_accessor_descriptor.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ extension type JSAccessorDescriptor<T extends JSObject, R extends JSAny?>._(JSPr
1919
configurable: configurable,
2020
enumerable: enumerable,
2121
);
22-
if (get != null)
22+
if (get != null) {
2323
descriptor.get = JSAccessorDescriptorGetterMethod<T, R>(get);
24-
if (set != null)
24+
}
25+
if (set != null) {
2526
descriptor.set = JSAccessorDescriptorSetterMethod<T>(set);
27+
}
2628
return descriptor;
2729
}
2830

lib/src/readable_stream/readable_stream.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ extension type ReadableStream<T extends JSAny, AbortType extends JSAny>._(JSObje
1717
JSObject? queuingStrategy,
1818
]) {
1919
if (underlyingSource != null) {
20-
if (queuingStrategy != null)
20+
if (queuingStrategy != null) {
2121
return ReadableStream._new$2(underlyingSource, queuingStrategy);
22-
else
22+
} else {
2323
return ReadableStream._new$1(underlyingSource);
24-
} else
24+
}
25+
} else {
2526
return ReadableStream._new$0();
27+
}
2628
}
2729

2830
/// Creates and returns a readable stream object.

lib/src/readable_stream/readable_stream_default_reader.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ extension type ReadableStreamDefaultReader<T extends JSAny, AbortType extends JS
5858
ReadableStreamDefaultReaderChunk<T> chunk;
5959
do {
6060
chunk = await read();
61-
if (chunk.value case final value?)
61+
if (chunk.value case final value?) {
6262
yield value;
63+
}
6364
} while (!chunk.done);
6465
return;
6566
} catch(_) {
@@ -69,8 +70,9 @@ extension type ReadableStreamDefaultReader<T extends JSAny, AbortType extends JS
6970
// Cancel stream after full read or early break.
7071
// If used with fetch response, this will cancel further response body
7172
// download on subscription cancellation and save bandwidth.
72-
if (!error)
73+
if (!error) {
7374
await cancel();
75+
}
7476
}
7577
}
7678
}

lib/src/readable_stream/readable_stream_source.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@ extension type ReadableStreamSource<T extends JSAny, AbortType extends JSAny>._(
2424
int? autoAllocateChunkSize,
2525
}) {
2626
final object = JSObject() as ReadableStreamSource<T, AbortType>;
27-
if (start != null)
27+
if (start != null) {
2828
object.start = ReadableStreamSourceControllerMethod(start);
29-
if (pull != null)
29+
}
30+
if (pull != null) {
3031
object.pull = ReadableStreamSourceControllerMethod(pull);
31-
if (cancel != null)
32+
}
33+
if (cancel != null) {
3234
object.cancel = ReadableStreamSourceCancelMethod<T, JSAny?, AbortType>(cancel);
33-
if (type != null)
35+
}
36+
if (type != null) {
3437
object.type = type;
35-
if (autoAllocateChunkSize != null)
38+
}
39+
if (autoAllocateChunkSize != null) {
3640
object.autoAllocateChunkSize = autoAllocateChunkSize;
41+
}
3742
return object;
3843
}
3944

@@ -48,8 +53,9 @@ extension type ReadableStreamSource<T extends JSAny, AbortType extends JSAny>._(
4853
subscription = stream.listen(
4954
(event) {
5055
controller.enqueue(event);
51-
if (controller.desiredSize <= 0)
56+
if (controller.desiredSize <= 0) {
5257
subscription.pause();
58+
}
5359
},
5460
onError: (Object error) {
5561
final object = switch (error) {
@@ -66,12 +72,15 @@ extension type ReadableStreamSource<T extends JSAny, AbortType extends JSAny>._(
6672
},
6773
cancelOnError: true,
6874
);
75+
return;
6976
},
7077
pull: (controller) {
7178
subscription.resume();
79+
return;
7280
},
7381
cancel: (reason, controller) async {
7482
await subscription.cancel();
83+
return;
7584
},
7685
);
7786
}

lib/src/request/request_body.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ extension type const RequestBody._(JSAny _) implements JSAny {
3939
const factory RequestBody.fromReadableStream(ReadableStream<JSUint8Array, JSAny> body) = _RequestBodyReadableStream;
4040

4141
/// Try to create [RequestBody] from JS value.
42-
factory RequestBody.fromJSAny(JSAny _body) => switch(_body) {
43-
final JSString body when _body.isA<JSString>() => RequestBody.fromJSString(body),
44-
final JSArrayBuffer body when _body.isA<JSArrayBuffer>() => RequestBody.fromJSArrayBuffer(body),
45-
final Blob body when _body.isA<Blob>() => RequestBody.fromBlob(body),
46-
final JSDataView body when _body.isA<JSDataView>() => RequestBody.fromJSDataView(body),
47-
final File body when _body.isA<File>() => RequestBody.fromFile(body),
48-
final FormData body when _body.isA<FormData>() => RequestBody.fromFormData(body),
49-
final JSTypedArray body when _body.isA<JSTypedArray>() => RequestBody.fromJSTypedArray(body),
50-
final URLSearchParams body when _body.isA<URLSearchParams>() => RequestBody.fromURLSearchParams(body),
51-
final ReadableStream<JSUint8Array, JSAny> body when _body.isA<ReadableStream<JSUint8Array, JSAny>>() => RequestBody.fromReadableStream(body),
52-
_ => throw JSTypeError('${_body.runtimeType} is not a valid RequestBody'),
42+
factory RequestBody.fromJSAny(JSAny body) => switch(body) {
43+
final JSString body when body.isA<JSString>() => RequestBody.fromJSString(body),
44+
final JSArrayBuffer body when body.isA<JSArrayBuffer>() => RequestBody.fromJSArrayBuffer(body),
45+
final Blob body when body.isA<Blob>() => RequestBody.fromBlob(body),
46+
final JSDataView body when body.isA<JSDataView>() => RequestBody.fromJSDataView(body),
47+
final File body when body.isA<File>() => RequestBody.fromFile(body),
48+
final FormData body when body.isA<FormData>() => RequestBody.fromFormData(body),
49+
final JSTypedArray body when body.isA<JSTypedArray>() => RequestBody.fromJSTypedArray(body),
50+
final URLSearchParams body when body.isA<URLSearchParams>() => RequestBody.fromURLSearchParams(body),
51+
final ReadableStream<JSUint8Array, JSAny> body when body.isA<ReadableStream<JSUint8Array, JSAny>>() => RequestBody.fromReadableStream(body),
52+
_ => throw JSTypeError('${body.runtimeType} is not a valid RequestBody'),
5353
};
5454

5555
/// Convert to target JS value.

0 commit comments

Comments
 (0)