Skip to content

Commit

Permalink
Apply 193 (invertase#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit authored and oskar-zeinomahmalat-sonarsource committed Dec 3, 2024
1 parent 27931ae commit d7bca62
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
3 changes: 3 additions & 0 deletions packages/custom_lint/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Optimized logic for finding an unused VM_service port.
- Sort lints by severity in the command line (thanks to @kuhnroyal)
- Fix watch mode not quitting with `q` (thanks to @kuhnroyal)
- Improve the command line's output (thanks to @kuhnroyal)
- Update uuid to 4.0.0
- Fixed a port leak
- Fix connection issues on Docker/windows (thanks to @hamsbrar)

## 0.5.3 - 2023-08-29

Expand Down
39 changes: 24 additions & 15 deletions packages/custom_lint/lib/src/v2/server_to_client_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,27 @@ class SocketCustomLintServerToClientChannel {
_tempDirectory = await _workspace.createPluginHostDirectory();
_writeEntrypoint(_workspace.uniquePluginNames, tempDirectory);

return _asyncRetry(retryCount: 5, () async {
// Using "late" to fetch the port only if needed (in watch mode)
late final port = _findPossiblyUnusedPort();
final process = await Process.start(
Platform.resolvedExecutable,
[
if (_server.watchMode) '--enable-vm-service=${await port}',
join('lib', 'custom_lint_client.dart'),
_serverSocket.port.toString(),
],
workingDirectory: tempDirectory.path,
);
return process;
});
try {
return _asyncRetry(retryCount: 5, () async {
// Using "late" to fetch the port only if needed (in watch mode)
late final port = _findPossiblyUnusedPort();
final process = await Process.start(
Platform.resolvedExecutable,
[
if (_server.watchMode) '--enable-vm-service=${await port}',
join('lib', 'custom_lint_client.dart'),
_serverSocket.address.host,
_serverSocket.port.toString(),
],
workingDirectory: tempDirectory.path,
);
return process;
});
} catch (_) {
// If the process failed to start, we can delete the temp directory
await _tempDirectory?.delete(recursive: true);
rethrow;
}
}

void _writeEntrypoint(
Expand All @@ -201,10 +208,12 @@ import 'package:custom_lint_builder/src/channel.dart';
$imports
void main(List<String> args) async {
final port = int.parse(args.single);
final host = args[0];
final port = int.parse(args[1]);
runSocket(
port: port,
host: host,
includeBuiltInLints: ${_server.includeBuiltInLints},
{$plugins},
);
Expand Down
4 changes: 2 additions & 2 deletions packages/custom_lint/test/cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ invalid;
^^^^^^^
'''),
matchIgnoringAnsi(contains, '''
lib/custom_lint_client.dart:13:29: Error: Undefined name 'createPlugin'.
lib/custom_lint_client.dart:15:29: Error: Undefined name 'createPlugin'.
{'test_lint': test_lint.createPlugin,
^^^^^^^^^^^^
'''),
Expand Down Expand Up @@ -362,7 +362,7 @@ int x = 'oy';
^
'''),
matchIgnoringAnsi(contains, '''
lib/custom_lint_client.dart:15:26: Error: Undefined name 'createPlugin'.
lib/custom_lint_client.dart:17:26: Error: Undefined name 'createPlugin'.
'test_lint2': test_lint2.createPlugin,
^^^^^^^^^^^^
'''),
Expand Down
3 changes: 2 additions & 1 deletion packages/custom_lint_builder/lib/src/channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ typedef CreatePluginMain = PluginBase Function();
Future<void> runSocket(
Map<String, CreatePluginMain> pluginMains, {
required int port,
required String host,
required bool includeBuiltInLints,
}) async {
late Future<CustomLintPluginClient> client;

await asyncRunZonedGuarded(
() => client = Future(() async {
// ignore: close_sinks, connection stays open until the plugin is killed
final socket = await Socket.connect('localhost', port);
final socket = await Socket.connect(host, port);
final socketChannel = JsonSocketChannel(Future.value(socket));
final registeredPlugins = <String, PluginBase>{};

Expand Down

0 comments on commit d7bca62

Please sign in to comment.