Skip to content

Commit

Permalink
Fix dart analyzing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jumperchen committed Aug 1, 2023
1 parent 9962da7 commit 68ee31b
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 95 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.3+1

Fix dart analyzing issues

## 2.0.3

**New Feature:**
Expand Down
6 changes: 4 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml

analyzer:
# exclude:
Expand All @@ -15,4 +15,6 @@ linter:
list_remove_unrelated_type: true
test_types_in_equals: true
unrelated_type_equality_checks: true
valid_regexps: true
valid_regexps: true
implementation_imports: false
overridden_fields: false
2 changes: 1 addition & 1 deletion lib/src/engine/parseqs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ String encode(Map obj) {

for (var i in obj.keys) {
if (str.isNotEmpty) str += '&';
str += Uri.encodeComponent('$i') + '=' + Uri.encodeComponent('${obj[i]}');
str += '${Uri.encodeComponent('$i')}=${Uri.encodeComponent('${obj[i]}')}';
}

return str;
Expand Down
47 changes: 23 additions & 24 deletions lib/src/engine/socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class Socket extends EventEmitter {
bool? forceBase64;
bool? enablesXDR;
String? timestampParam;
var timestampRequests;
dynamic timestampRequests;
late List<String> transports;
late Map transportOptions;
String readyState = '';
List writeBuffer = [];
int prevBufferLen = 0;
int? policyPort;
bool? rememberUpgrade;
var binaryType;
dynamic binaryType;
bool? onlyBinaryUpgrades;
late Map perMessageDeflate;
String? id;
Expand Down Expand Up @@ -103,10 +103,9 @@ class Socket extends EventEmitter {
}

upgrade = opts['upgrade'] != false;
path = (opts['path'] ?? '/engine.io')
path = '${(opts['path'] ?? '/engine.io')
.toString()
.replaceFirst(RegExp(r'\/$'), '') +
'/';
.replaceFirst(RegExp(r'\/$'), '')}/';
forceJSONP = opts['forceJSONP'] == true;
jsonp = opts['jsonp'] != false;
forceBase64 = opts['forceBase64'] == true;
Expand Down Expand Up @@ -239,7 +238,7 @@ class Socket extends EventEmitter {
///
/// @api private
void open() {
var transport;
dynamic transport;
if (rememberUpgrade != null &&
priorWebsocketSuccess &&
transports.contains('websocket')) {
Expand Down Expand Up @@ -298,10 +297,10 @@ class Socket extends EventEmitter {
_logger.fine('probing transport "$name"');
Transport? transport = createTransport(name, {'probe': true});
var failed = false;
var cleanup;
dynamic cleanup;
priorWebsocketSuccess = false;

var onTransportOpen = (_) {
onTransportOpen(_) {
if (onlyBinaryUpgrades == true) {
var upgradeLosesBinary =
supportsBinary == false && transport!.supportsBinary == false;
Expand Down Expand Up @@ -347,9 +346,9 @@ class Socket extends EventEmitter {
{'error': 'probe error', 'transport': transport!.name});
}
});
};
}

var freezeTransport = () {
freezeTransport() {
if (failed) return;

// Any callback called by transport should be ignored since now
Expand All @@ -359,31 +358,31 @@ class Socket extends EventEmitter {

transport!.close();
transport = null;
};
}

// Handle any error that happens while probing
var onerror = (err) {
onerror(err) {
final oldTransport = transport;
freezeTransport();

_logger.fine('probe transport "$name" failed because of error: $err');

emit('upgradeError',
{'error': 'probe error: $err', 'transport': oldTransport!.name});
};
}

var onTransportClose = (_) => onerror('transport closed');
onTransportClose(_) => onerror('transport closed');

// When the socket is closed while we're probing
var onclose = (_) => onerror('socket closed');
onclose(_) => onerror('socket closed');

// When the socket is upgraded while we're probing
var onupgrade = (to) {
onupgrade(to) {
if (transport != null && to.name != transport!.name) {
_logger.fine('"${to?.name}" works - aborting "${transport?.name}"');
freezeTransport();
}
};
}

// Remove all listeners on the transport and on self
cleanup = () {
Expand Down Expand Up @@ -604,27 +603,27 @@ class Socket extends EventEmitter {
///
/// @api private
Socket close() {
var close = () {
close() {
onClose('forced close');
_logger.fine('socket closing - telling transport to close');
transport!.close();
};
}

var temp;
var cleanupAndClose = (_) {
dynamic temp;
cleanupAndClose(_) {
off('upgrade', temp);
off('upgradeError', temp);
close();
};
}

// a workaround for dart to access the local variable;
temp = cleanupAndClose;

var waitForUpgrade = () {
waitForUpgrade() {
// wait for upgrade to finish since we can't send packets while pausing a transport
once('upgrade', cleanupAndClose);
once('upgradeError', cleanupAndClose);
};
}

if ('opening' == readyState || 'open' == readyState) {
readyState = 'closing';
Expand Down
17 changes: 6 additions & 11 deletions lib/src/engine/transport/io_websocket_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class IOWebSocketTransport extends Transport {

@override
String? name = 'websocket';
var protocols;
dynamic protocols;

@override
bool? supportsBinary;
Expand Down Expand Up @@ -76,7 +76,7 @@ class IOWebSocketTransport extends Transport {
void write(List packets) {
writable = false;

var done = () {
done() {
emit('flush');

// fake drain
Expand All @@ -85,12 +85,12 @@ class IOWebSocketTransport extends Transport {
writable = true;
emit('drain');
});
};
}

var total = packets.length;
// encodePacket efficient as it uses WS framing
// no need for encodePayload
packets.forEach((packet) {
for (var packet in packets) {
PacketParser.encodePacket(packet,
supportsBinary: supportsBinary, fromClient: true, callback: (data) {
// Sometimes the websocket has already been closed but the browser didn't
Expand All @@ -109,7 +109,7 @@ class IOWebSocketTransport extends Transport {

if (--total == 0) done();
});
});
}
}

///
Expand Down Expand Up @@ -156,12 +156,7 @@ class IOWebSocketTransport extends Transport {
}

var ipv6 = hostname.contains(':');
return schema +
'://' +
(ipv6 ? '[' + hostname + ']' : hostname) +
port +
path +
queryString;
return '$schema://${ipv6 ? '[$hostname]' : hostname}$port$path$queryString';
}
//
/////
Expand Down
6 changes: 3 additions & 3 deletions lib/src/engine/transport/jsonp_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final RegExp rEscapedNewline = RegExp(r'\\n');

///
/// Global JSONP callbacks.
var callbacks;
dynamic callbacks;

class JSONPTransport extends PollingTransport {
// static var empty = (_) => '';
Expand Down Expand Up @@ -164,7 +164,7 @@ class JSONPTransport extends PollingTransport {

form!.action = uri();

var initIframe = () {
initIframe() {
if (iframe != null) {
try {
iframe!.remove();
Expand All @@ -181,7 +181,7 @@ class JSONPTransport extends PollingTransport {

form!.append(iframe!);
iframe = iframe;
};
}

initIframe();

Expand Down
23 changes: 9 additions & 14 deletions lib/src/engine/transport/polling_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ abstract class PollingTransport extends Transport {

readyState = 'pausing';

var pause = () {
pause() {
_logger.fine('paused');
self.readyState = 'paused';
onPause();
};
}

if (polling == true || writable != true) {
var total = 0;
Expand Down Expand Up @@ -109,7 +109,7 @@ abstract class PollingTransport extends Transport {
void onData(data) {
var self = this;
_logger.fine('polling got data $data');
var callback = (packet, [index, total]) {
callback(packet, [index, total]) {
// if its the first message we consider the transport open
if ('opening' == self.readyState) {
self.onOpen();
Expand All @@ -124,7 +124,7 @@ abstract class PollingTransport extends Transport {
// otherwise bypass onData and handle the message
self.onPacket(packet);
return null;
};
}

// decode payload
PacketParser.decodePayload(data, socket!.binaryType).forEach(callback);
Expand All @@ -151,12 +151,12 @@ abstract class PollingTransport extends Transport {
void doClose() {
var self = this;

var close = ([_]) {
close([_]) {
_logger.fine('writing close packet');
self.write([
{'type': 'close'}
]);
};
}

if ('open' == readyState) {
_logger.fine('transport open - closing');
Expand All @@ -179,10 +179,10 @@ abstract class PollingTransport extends Transport {
void write(List packets) {
var self = this;
writable = false;
var callbackfn = (_) {
callbackfn(_) {
self.writable = true;
self.emit('drain');
};
}

PacketParser.encodePayload(packets, callback: (data) {
self.doWrite(data, callbackfn);
Expand Down Expand Up @@ -223,12 +223,7 @@ abstract class PollingTransport extends Transport {
}

var ipv6 = hostname.contains(':');
return schema +
'://' +
(ipv6 ? '[' + hostname + ']' : hostname) +
port +
path +
queryString;
return '$schema://${ipv6 ? '[$hostname]' : hostname}$port$path$queryString';
}

void doWrite(data, callback);
Expand Down
17 changes: 6 additions & 11 deletions lib/src/engine/transport/websocket_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WebSocketTransport extends Transport {

@override
String? name = 'websocket';
late var protocols;
late dynamic protocols;

@override
bool? supportsBinary;
Expand Down Expand Up @@ -70,7 +70,7 @@ class WebSocketTransport extends Transport {
void write(List packets) {
writable = false;

var done = () {
done() {
emit('flush');

// fake drain
Expand All @@ -79,12 +79,12 @@ class WebSocketTransport extends Transport {
writable = true;
emit('drain');
});
};
}

var total = packets.length;
// encodePacket efficient as it uses WS framing
// no need for encodePayload
packets.forEach((packet) {
for (var packet in packets) {
PacketParser.encodePacket(packet,
supportsBinary: supportsBinary, fromClient: true, callback: (data) {
// Sometimes the websocket has already been closed but the browser didn't
Expand All @@ -99,7 +99,7 @@ class WebSocketTransport extends Transport {

if (--total == 0) done();
});
});
}
}

/// Closes socket.
Expand Down Expand Up @@ -144,12 +144,7 @@ class WebSocketTransport extends Transport {
}

var ipv6 = hostname.contains(':');
return schema +
'://' +
(ipv6 ? '[' + hostname + ']' : hostname) +
port +
path +
queryString;
return '$schema://${ipv6 ? '[$hostname]' : hostname}$port$path$queryString';
}
/////
///// Feature detection for WebSocket.
Expand Down
Loading

0 comments on commit 68ee31b

Please sign in to comment.