Skip to content

Commit 39992df

Browse files
felangelgrouma
authored andcommitted
Update analyzer and clean up warnings
1 parent 8fd103c commit 39992df

15 files changed

+156
-153
lines changed

pkgs/web_socket_channel/.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dart: dev
55
dart_task:
66
- test: --platform vm
77
- test: --platform firefox -j 1
8-
- dartanalyzer
8+
- dartanalyzer --fatal-infos --fatal-warnings
99

1010
matrix:
1111
include:
@@ -17,5 +17,5 @@ branches:
1717
only: [master]
1818

1919
cache:
20-
directories:
21-
- $HOME/.pub-cache
20+
directories:
21+
- $HOME/.pub-cache

pkgs/web_socket_channel/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ All submissions, including submissions by project members, require review.
2323
### File headers
2424
All files in the project must start with the following header.
2525

26-
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
26+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2727
// for details. All rights reserved. Use of this source code is governed by a
2828
// BSD-style license that can be found in the LICENSE file.
2929

pkgs/web_socket_channel/README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ other socket exactly why they're closing the connection.
5656

5757
`WebSocketChannel` also works as a cross-platform implementation of the
5858
WebSocket protocol. Because it can't initiate or handle HTTP requests in a
59-
cross-platform way, the [`new WebSocketChannel()` constructor][new] takes an
59+
cross-platform way, the [`WebSocketChannel()` constructor][new] takes an
6060
underlying [`StreamChannel`][stream_channel] over which it communicates using
6161
the WebSocket protocol. It also provides the static [`signKey()`][signKey]
6262
method to make it easier to implement the [initial WebSocket handshake][]. These
@@ -78,18 +78,18 @@ has its own library, `package:web_socket_channel/io.dart`. This allows the main
7878
[io.WebSocket]: https://api.dartlang.org/latest/dart-io/WebSocket-class.html
7979

8080
An `IOWebSocketChannel` can be created by passing a `dart:io` WebSocket to
81-
[its constructor][new IOWebSocketChannel]. It's more common to want to connect
81+
[its constructor][IOWebSocketChannel]. It's more common to want to connect
8282
directly to a `ws://` or `wss://` URL, in which case
83-
[`new IOWebSocketChannel.connect()`][IOWebSocketChannel.connect] should be used.
83+
[`IOWebSocketChannel.connect()`][IOWebSocketChannel.connect] should be used.
8484

85-
[new IOWebSocketChannel]: https://www.dartdocs.org/documentation/web_socket_channel/latest/io/IOWebSocketChannel/IOWebSocketChannel.html
85+
[IOWebSocketChannel]: https://www.dartdocs.org/documentation/web_socket_channel/latest/io/IOWebSocketChannel/IOWebSocketChannel.html
8686
[IOWebSocketChannel.connect]: https://www.dartdocs.org/documentation/web_socket_channel/latest/io/IOWebSocketChannel/IOWebSocketChannel.connect.html
8787

8888
```dart
8989
import 'package:web_socket_channel/io.dart';
9090
9191
main() async {
92-
var channel = new IOWebSocketChannel.connect("ws://localhost:8181");
92+
var channel = IOWebSocketChannel.connect("ws://localhost:8181");
9393
channel.sink.add("connected!");
9494
channel.stream.listen((message) {
9595
// ...
@@ -107,18 +107,18 @@ This allows the main `WebSocketChannel` class to be available on all platforms.
107107
[html.WebSocket]: https://api.dartlang.org/latest/dart-html/WebSocket-class.html
108108

109109
An `HtmlWebSocketChannel` can be created by passing a `dart:html` WebSocket to
110-
[its constructor][new HtmlWebSocketChannel]. It's more common to want to connect
110+
[its constructor][HtmlWebSocketChannel]. It's more common to want to connect
111111
directly to a `ws://` or `wss://` URL, in which case
112-
[`new HtmlWebSocketChannel.connect()`][HtmlWebSocketChannel.connect] should be used.
112+
[`HtmlWebSocketChannel.connect()`][HtmlWebSocketChannel.connect] should be used.
113113

114-
[new HtmlWebSocketChannel]: https://www.dartdocs.org/documentation/web_socket_channel/latest/html/HtmlWebSocketChannel/HtmlWebSocketChannel.html
114+
[HtmlWebSocketChannel]: https://www.dartdocs.org/documentation/web_socket_channel/latest/html/HtmlWebSocketChannel/HtmlWebSocketChannel.html
115115
[HtmlWebSocketChannel.connect]: https://www.dartdocs.org/documentation/web_socket_channel/latest/html/HtmlWebSocketChannel/HtmlWebSocketChannel.connect.html
116116

117117
```dart
118118
import 'package:web_socket_channel/html.dart';
119119
120120
main() async {
121-
var channel = new HtmlWebSocketChannel.connect("ws://localhost:8181");
121+
var channel = HtmlWebSocketChannel.connect("ws://localhost:8181");
122122
channel.sink.add("connected!");
123123
channel.stream.listen((message) {
124124
// ...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2018, 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+
import 'package:web_socket_channel/io.dart';
6+
import 'package:web_socket_channel/status.dart' as status;
7+
8+
void main() async {
9+
final channel = await IOWebSocketChannel.connect("ws://localhost:1234");
10+
11+
channel.stream.listen((message) {
12+
channel.sink.add("received!");
13+
channel.sink.close(status.goingAway);
14+
});
15+
}

pkgs/web_socket_channel/lib/html.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class HtmlWebSocketChannel extends StreamChannelMixin
4646

4747
Stream get stream => _controller.foreign.stream;
4848
final _controller =
49-
new StreamChannelController(sync: true, allowForeignErrors: false);
49+
StreamChannelController(sync: true, allowForeignErrors: false);
5050

5151
WebSocketSink get sink => _sink;
5252
WebSocketSink _sink;
@@ -64,12 +64,12 @@ class HtmlWebSocketChannel extends StreamChannelMixin
6464
/// [BinaryType.blob], they're delivered as [Blob]s instead.
6565
HtmlWebSocketChannel.connect(url,
6666
{Iterable<String> protocols, BinaryType binaryType})
67-
: this(new WebSocket(url.toString(), protocols)
67+
: this(WebSocket(url.toString(), protocols)
6868
..binaryType = (binaryType ?? BinaryType.list).value);
6969

7070
/// Creates a channel wrapping [webSocket].
7171
HtmlWebSocketChannel(this._webSocket) {
72-
_sink = new _HtmlWebSocketSink(this);
72+
_sink = _HtmlWebSocketSink(this);
7373

7474
if (_webSocket.readyState == WebSocket.OPEN) {
7575
_listen();
@@ -84,8 +84,8 @@ class HtmlWebSocketChannel extends StreamChannelMixin
8484
// The socket API guarantees that only a single error event will be emitted,
8585
// and that once it is no open or message events will be emitted.
8686
_webSocket.onError.first.then((_) {
87-
_controller.local.sink.addError(
88-
new WebSocketChannelException("WebSocket connection failed."));
87+
_controller.local.sink
88+
.addError(WebSocketChannelException("WebSocket connection failed."));
8989
_controller.local.sink.close();
9090
});
9191

pkgs/web_socket_channel/lib/io.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,25 @@ class IOWebSocketChannel extends StreamChannelMixin
5353
Map<String, dynamic> headers,
5454
Duration pingInterval}) {
5555
var channel;
56-
var sinkCompleter = new WebSocketSinkCompleter();
56+
var sinkCompleter = WebSocketSinkCompleter();
5757
var stream = StreamCompleter.fromFuture(
5858
WebSocket.connect(url.toString(), headers: headers).then((webSocket) {
5959
webSocket.pingInterval = pingInterval;
6060
channel._webSocket = webSocket;
61-
sinkCompleter.setDestinationSink(new _IOWebSocketSink(webSocket));
61+
sinkCompleter.setDestinationSink(_IOWebSocketSink(webSocket));
6262
return webSocket;
63-
}).catchError((error) => throw new WebSocketChannelException.from(error)));
63+
}).catchError((error) => throw WebSocketChannelException.from(error)));
6464

65-
channel = new IOWebSocketChannel._withoutSocket(stream, sinkCompleter.sink);
65+
channel = IOWebSocketChannel._withoutSocket(stream, sinkCompleter.sink);
6666
return channel;
6767
}
6868

6969
/// Creates a channel wrapping [socket].
7070
IOWebSocketChannel(WebSocket socket)
7171
: _webSocket = socket,
7272
stream = socket.handleError(
73-
(error) => throw new WebSocketChannelException.from(error)),
74-
sink = new _IOWebSocketSink(socket);
73+
(error) => throw WebSocketChannelException.from(error)),
74+
sink = _IOWebSocketSink(socket);
7575

7676
/// Creates a channel without a socket.
7777
///
@@ -80,7 +80,7 @@ class IOWebSocketChannel extends StreamChannelMixin
8080
IOWebSocketChannel._withoutSocket(Stream stream, this.sink)
8181
: _webSocket = null,
8282
stream = stream.handleError(
83-
(error) => throw new WebSocketChannelException.from(error));
83+
(error) => throw WebSocketChannelException.from(error));
8484
}
8585

8686
/// A [WebSocketSink] that forwards [close] calls to a `dart:io` [WebSocket].

pkgs/web_socket_channel/lib/src/channel.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class WebSocketChannel extends StreamChannelMixin {
4747
/// Before the connection has been closed, this will be `null`.
4848
String get closeReason => _webSocket.closeReason;
4949

50-
Stream get stream => new StreamView(_webSocket);
50+
Stream get stream => StreamView(_webSocket);
5151

5252
/// The sink for sending values to the other endpoint.
5353
///
5454
/// This supports additional arguments to [WebSocketSink.close] that provide
5555
/// the remote endpoint reasons for closing the connection.
56-
WebSocketSink get sink => new WebSocketSink._(_webSocket);
56+
WebSocketSink get sink => WebSocketSink._(_webSocket);
5757

5858
/// Signs a `Sec-WebSocket-Key` header sent by a WebSocket client as part of
5959
/// the [initial handshake][].
@@ -91,7 +91,7 @@ class WebSocketChannel extends StreamChannelMixin {
9191
/// [WebSocket handshake]: https://tools.ietf.org/html/rfc6455#section-4
9292
WebSocketChannel(StreamChannel<List<int>> channel,
9393
{String protocol, Duration pingInterval, bool serverSide: true})
94-
: _webSocket = new WebSocketImpl.fromSocket(
94+
: _webSocket = WebSocketImpl.fromSocket(
9595
channel.stream, channel.sink, protocol, serverSide)
9696
..pingInterval = pingInterval;
9797
}

pkgs/web_socket_channel/lib/src/copy/bytes_builder.dart

+11-12
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ abstract class BytesBuilder {
2626
/// output. Default is `true`.
2727
factory BytesBuilder({bool copy: true}) {
2828
if (copy) {
29-
return new _CopyingBytesBuilder();
29+
return _CopyingBytesBuilder();
3030
} else {
31-
return new _BytesBuilder();
31+
return _BytesBuilder();
3232
}
3333
}
3434

@@ -71,15 +71,15 @@ class _CopyingBytesBuilder implements BytesBuilder {
7171
// Start with 1024 bytes.
7272
static const int _INIT_SIZE = 1024;
7373

74-
static final _emptyList = new Uint8List(0);
74+
static final _emptyList = Uint8List(0);
7575

7676
int _length = 0;
7777
Uint8List _buffer;
7878

7979
_CopyingBytesBuilder([int initialCapacity = 0])
8080
: _buffer = (initialCapacity <= 0)
8181
? _emptyList
82-
: new Uint8List(_pow2roundup(initialCapacity));
82+
: Uint8List(_pow2roundup(initialCapacity));
8383

8484
void add(List<int> bytes) {
8585
int bytesLength = bytes.length;
@@ -119,22 +119,21 @@ class _CopyingBytesBuilder implements BytesBuilder {
119119
} else {
120120
newSize = _pow2roundup(newSize);
121121
}
122-
var newBuffer = new Uint8List(newSize);
122+
var newBuffer = Uint8List(newSize);
123123
newBuffer.setRange(0, _buffer.length, _buffer);
124124
_buffer = newBuffer;
125125
}
126126

127127
List<int> takeBytes() {
128128
if (_length == 0) return _emptyList;
129-
var buffer = new Uint8List.view(_buffer.buffer, 0, _length);
129+
var buffer = Uint8List.view(_buffer.buffer, 0, _length);
130130
clear();
131131
return buffer;
132132
}
133133

134134
List<int> toBytes() {
135135
if (_length == 0) return _emptyList;
136-
return new Uint8List.fromList(
137-
new Uint8List.view(_buffer.buffer, 0, _length));
136+
return Uint8List.fromList(Uint8List.view(_buffer.buffer, 0, _length));
138137
}
139138

140139
int get length => _length;
@@ -169,14 +168,14 @@ class _BytesBuilder implements BytesBuilder {
169168
if (bytes is Uint8List) {
170169
typedBytes = bytes;
171170
} else {
172-
typedBytes = new Uint8List.fromList(bytes);
171+
typedBytes = Uint8List.fromList(bytes);
173172
}
174173
_chunks.add(typedBytes);
175174
_length += typedBytes.length;
176175
}
177176

178177
void addByte(int byte) {
179-
_chunks.add(new Uint8List(1)..[0] = byte);
178+
_chunks.add(Uint8List(1)..[0] = byte);
180179
_length++;
181180
}
182181

@@ -187,7 +186,7 @@ class _BytesBuilder implements BytesBuilder {
187186
clear();
188187
return buffer;
189188
}
190-
var buffer = new Uint8List(_length);
189+
var buffer = Uint8List(_length);
191190
int offset = 0;
192191
for (var chunk in _chunks) {
193192
buffer.setRange(offset, offset + chunk.length, chunk);
@@ -199,7 +198,7 @@ class _BytesBuilder implements BytesBuilder {
199198

200199
List<int> toBytes() {
201200
if (_length == 0) return _CopyingBytesBuilder._emptyList;
202-
var buffer = new Uint8List(_length);
201+
var buffer = Uint8List(_length);
203202
int offset = 0;
204203
for (var chunk in _chunks) {
205204
buffer.setRange(offset, offset + chunk.length, chunk);

pkgs/web_socket_channel/lib/src/copy/io_sink.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'dart:async';
1515

1616
class StreamSinkImpl<T> implements StreamSink<T> {
1717
final StreamConsumer<T> _target;
18-
final Completer _doneCompleter = new Completer();
18+
final Completer _doneCompleter = Completer();
1919
StreamController<T> _controllerInstance;
2020
Completer _controllerCompleter;
2121
bool _isClosed = false;
@@ -43,7 +43,7 @@ class StreamSinkImpl<T> implements StreamSink<T> {
4343

4444
Future addStream(Stream<T> stream) {
4545
if (_isBound) {
46-
throw new StateError("StreamSink is already bound to a stream");
46+
throw StateError("StreamSink is already bound to a stream");
4747
}
4848
if (_hasError) return done;
4949

@@ -62,9 +62,9 @@ class StreamSinkImpl<T> implements StreamSink<T> {
6262

6363
Future flush() {
6464
if (_isBound) {
65-
throw new StateError("StreamSink is bound to a stream");
65+
throw StateError("StreamSink is bound to a stream");
6666
}
67-
if (_controllerInstance == null) return new Future.value(this);
67+
if (_controllerInstance == null) return Future.value(this);
6868
// Adding an empty stream-controller will return a future that will complete
6969
// when all data is done.
7070
_isBound = true;
@@ -77,7 +77,7 @@ class StreamSinkImpl<T> implements StreamSink<T> {
7777

7878
Future close() {
7979
if (_isBound) {
80-
throw new StateError("StreamSink is bound to a stream");
80+
throw StateError("StreamSink is bound to a stream");
8181
}
8282
if (!_isClosed) {
8383
_isClosed = true;
@@ -111,14 +111,14 @@ class StreamSinkImpl<T> implements StreamSink<T> {
111111

112112
StreamController<T> get _controller {
113113
if (_isBound) {
114-
throw new StateError("StreamSink is bound to a stream");
114+
throw StateError("StreamSink is bound to a stream");
115115
}
116116
if (_isClosed) {
117-
throw new StateError("StreamSink is closed");
117+
throw StateError("StreamSink is closed");
118118
}
119119
if (_controllerInstance == null) {
120-
_controllerInstance = new StreamController<T>(sync: true);
121-
_controllerCompleter = new Completer();
120+
_controllerInstance = StreamController<T>(sync: true);
121+
_controllerCompleter = Completer();
122122
_target.addStream(_controller.stream).then((_) {
123123
if (_isBound) {
124124
// A new stream takes over - forward values to that stream.

0 commit comments

Comments
 (0)