Skip to content

Commit b065b01

Browse files
committed
Fix analyzer warnings in code samples
- Add ignore directives to suppress warnings/info messages - Fix #region in async_objects_28d751fd.dart to exclude outer main - Suppress info-level rules in analysis_options.yaml: - unnecessary_import, deprecated_member_use (analyzer diagnostics) - use_key_in_widget_constructors, prefer_final_fields, etc. (linter rules) - All code samples now analyze cleanly
1 parent a3eb0a3 commit b065b01

15 files changed

+41
-24
lines changed

code_samples/analysis_options.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,23 @@ analyzer:
1616
undefined_identifier: error
1717
undefined_class: error
1818
invalid_assignment: error
19+
# Suppress info messages that don't matter for example code
20+
unused_local_variable: ignore
21+
unnecessary_import: ignore
22+
deprecated_member_use: ignore
1923

2024
linter:
2125
rules:
2226
# Disable rules that don't make sense for example code
2327
public_member_api_docs: false
2428
prefer_const_constructors: false
29+
prefer_const_constructors_in_immutables: false
2530
avoid_print: false
31+
use_key_in_widget_constructors: false
32+
unnecessary_string_interpolations: false
33+
annotate_overrides: false
34+
use_build_context_synchronously: false
35+
prefer_final_fields: false
2636
# Enable important rules
2737
avoid_relative_lib_imports: true
28-
prefer_final_fields: true
2938
unnecessary_null_checks: true

code_samples/lib/get_it/accessing_services_example.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: unused_local_variable
2+
13
import 'package:get_it/get_it.dart';
24
import '_shared/stubs.dart';
35

code_samples/lib/get_it/async_objects_174d24d3.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:get_it/get_it.dart';
2-
import '_shared/stubs.dart';
32

43
final getIt = GetIt.instance;
54

code_samples/lib/get_it/async_objects_21920847.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: unused_local_variable
2+
13
import 'package:get_it/get_it.dart';
24
import '_shared/stubs.dart';
35

code_samples/lib/get_it/async_objects_2642b731.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: unused_local_variable
2+
13
import 'package:get_it/get_it.dart';
24
import '_shared/stubs.dart';
35

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
1+
// ignore_for_file: unused_element
12
import 'package:flutter/material.dart';
23
import 'package:get_it/get_it.dart';
34
import '_shared/stubs.dart';
45

56
final getIt = GetIt.instance;
67

7-
// #region example
88
void main() async {
9-
Future<void> main() async {
10-
// Register first batch of services
11-
getIt.registerSingletonAsync<ConfigService>(
12-
() async => ConfigService.load());
13-
getIt.registerSingletonAsync<Logger>(() async => Logger.initialize());
9+
// #region example
10+
// Register first batch of services
11+
getIt.registerSingletonAsync<ConfigService>(() async => ConfigService.load());
12+
getIt.registerSingletonAsync<Logger>(() async => Logger.initialize());
1413

15-
// Wait for first batch
16-
await getIt.allReady();
17-
print('Core services ready');
14+
// Wait for first batch
15+
await getIt.allReady();
16+
print('Core services ready');
1817

19-
// Register second batch based on config
20-
final config = getIt<ConfigService>();
21-
if (config.enableFeatureX) {
22-
getIt.registerSingletonAsync<FeatureX>(() async => FeatureX.initialize());
23-
}
18+
// Register second batch based on config
19+
final config = getIt<ConfigService>();
20+
if (config.enableFeatureX) {
21+
getIt.registerSingletonAsync<FeatureX>(() async => FeatureX.initialize());
22+
}
2423

25-
// Wait for second batch
26-
await getIt.allReady();
27-
print('All services ready');
24+
// Wait for second batch
25+
await getIt.allReady();
26+
print('All services ready');
2827

29-
runApp(MyApp());
30-
}
28+
runApp(MyApp());
29+
// #endregion example
3130
}
32-
// #endregion example

code_samples/lib/get_it/async_objects_4ef84c96.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:get_it/get_it.dart';
2-
import '_shared/stubs.dart';
32

43
final getIt = GetIt.instance;
54

code_samples/lib/get_it/async_objects_f2965023.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:get_it/get_it.dart';
2-
import '_shared/stubs.dart';
32

43
final getIt = GetIt.instance;
54

code_samples/lib/get_it/checkout_service_example.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore_for_file: dead_code
12
import 'package:get_it/get_it.dart';
23
import '_shared/stubs.dart';
34

code_samples/lib/get_it/code_sample_14c31d5c.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore_for_file: unused_import
12
import 'package:get_it/get_it.dart';
23
import '_shared/stubs.dart';
34

0 commit comments

Comments
 (0)