Skip to content

Commit

Permalink
Configure linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtanko committed Mar 31, 2024
1 parent cd47752 commit 58c5b90
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
28 changes: 20 additions & 8 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.
analyzer:
strong-mode:
implicit-casts: false
exclude: [build/**]
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
errors:
todo: ignore
missing_return: error
dead_code: info

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**
linter:
rules:
- camel_case_types
- always_declare_return_types
- comment_references
- await_only_futures
- avoid_slow_async_io
- discarded_futures

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
Expand Down
8 changes: 4 additions & 4 deletions lib/dart_isolates/echo_isolates_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Future<String> echoIsolate(String message) async {
sendPort.send([message, answer.sendPort]);

// Wait for the response.
final response = await answer.first;
final response = await answer.first as Future<String>;

return response;
}
Expand All @@ -26,7 +26,7 @@ Future<SendPort> createIsolate() async {
await Isolate.spawn(echo, receivePort.sendPort);

// The 'echo' isolate sends its SendPort as the first message.
final sendPort = await receivePort.first;
final sendPort = await receivePort.first as Future<SendPort>;

return sendPort;
}
Expand All @@ -41,8 +41,8 @@ void echo(SendPort sendPort) {

port.listen((message) {
// Parse the message.
final String data = message[0];
final SendPort replyTo = message[1];
final String data = message[0] as String;
final SendPort replyTo = message[1] as SendPort;

// Send a message back.
replyTo.send('Echo: $data');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ Future<List<int>> calculateSquaresParallel(List<int> data) async {
return squares;
}

/// The function executed by each isolate to calculate the squares of the numbers in the given [chunk].
/// The calculated squares are sent back to the main isolate using the [sendPort].
/// Function to be executed in an isolate.
/// It receives a message containing a chunk of data and a send port.
/// It squares each number in the chunk and sends the squared chunk back through the send port.
void isolateFunction(Map<String, dynamic> message) {
final List<int> chunk = message['data'];
final SendPort sendPort = message['sendPort'];
final List<int> chunk = message['data'] as List<int>;
final SendPort sendPort = message['sendPort'] as SendPort;
final List<int> squaredChunk =
chunk.map((number) => number * number).toList();
sendPort.send(squaredChunk);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dart_concurrency
description: A sample command-line application.
description: A is a sample command-line application that demonstrates the use of concurrency in Dart.
version: 1.0.0
# repository: https://github.com/my_org/my_repo

Expand Down

0 comments on commit 58c5b90

Please sign in to comment.