-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce documentation for new strict modes (#3823)
* Introduce documentation for new strict modes * Include all modes in the options file excerpt * Try out different examples * Adjust analyzer results * Fix code excerpts * Fix accidental change by test script * Add back missing code excerpt * Regenerate excerpts * Clarify strict inference extra examples
- Loading branch information
Showing
8 changed files
with
140 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
Analyzing analysis... | ||
|
||
error - lib/assignment.dart:11:14 - A value of type 'dynamic' can't be assigned to a variable of type 'String'. Try changing the type of the variable, or casting the right-hand type to 'String'. - invalid_assignment | ||
error - lib/strict_modes.dart:13:7 - The argument type 'dynamic' can't be assigned to the parameter type 'List<String>'. - argument_type_not_assignable | ||
info - lib/lint.dart:9:19 - Avoid empty statements. - empty_statements | ||
info - lib/lint.dart:17:7 - Close instances of `dart.core.Sink`. - close_sinks | ||
info - lib/strict_modes.dart:22:27 - The type argument(s) of 'Map' can't be inferred. Use explicit type argument(s) for 'Map'. - inference_failure_on_collection_literal | ||
info - lib/strict_modes.dart:33:3 - The generic type 'List<dynamic>' should have explicit type arguments but doesn't. Use explicit type arguments for 'List<dynamic>'. - strict_raw_type | ||
|
||
3 issues found. | ||
5 issues found. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
Analyzing analysis... | ||
|
||
error - lib/assignment.dart:11:14 - A value of type 'dynamic' can't be assigned to a variable of type 'String'. Try changing the type of the variable, or casting the right-hand type to 'String'. - invalid_assignment | ||
error - lib/strict_modes.dart:13:7 - The argument type 'dynamic' can't be assigned to the parameter type 'List<String>'. - argument_type_not_assignable | ||
info - lib/lint.dart:9:19 - Avoid empty statements. - empty_statements | ||
info - lib/lint.dart:17:7 - Close instances of `dart.core.Sink`. - close_sinks | ||
info - lib/strict_modes.dart:22:17 - The type argument(s) of 'Map' can't be inferred. Use explicit type argument(s) for 'Map'. - inference_failure_on_collection_literal | ||
info - lib/strict_modes.dart:33:3 - The generic type 'List<dynamic>' should have explicit type arguments but doesn't. Use explicit type arguments for 'List<dynamic>'. - strict_raw_type | ||
|
||
3 issues found. | ||
5 issues found. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
Analyzing analysis... | ||
|
||
error - lib/assignment.dart:11:14 - A value of type 'dynamic' can't be assigned to a variable of type 'String'. Try changing the type of the variable, or casting the right-hand type to 'String'. - invalid_assignment | ||
error - lib/strict_modes.dart:13:7 - The argument type 'dynamic' can't be assigned to the parameter type 'List<String>'. - argument_type_not_assignable | ||
info - lib/lint.dart:9:19 - Avoid empty statements. - empty_statements | ||
info - lib/lint.dart:17:7 - Close instances of `dart.core.Sink`. - close_sinks | ||
info - lib/strict_modes.dart:22:17 - The type argument(s) of 'Map' can't be inferred. Use explicit type argument(s) for 'Map'. - inference_failure_on_collection_literal | ||
info - lib/strict_modes.dart:33:3 - The generic type 'List<dynamic>' should have explicit type arguments but doesn't. Use explicit type arguments for 'List<dynamic>'. - strict_raw_type | ||
|
||
3 issues found. | ||
5 issues found. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ignore_for_file: dead_code, prefer_typing_uninitialized_variables, | ||
// ignore_for_file: unused_local_variable | ||
|
||
import 'dart:convert'; | ||
|
||
import 'package:examples_util/ellipsis.dart'; | ||
|
||
// #docregion strict-casts | ||
void foo(List<String> lines) { | ||
ellipsis<String>(); | ||
} | ||
|
||
void bar(String jsonText) { | ||
// ignore: stable, beta, dev, argument_type_not_assignable | ||
foo(jsonDecode(jsonText)); // Implicit cast | ||
} | ||
// #enddocregion strict-casts | ||
|
||
void strictInference() { | ||
// #docregion strict-inference | ||
// ignore: stable, beta, dev, inference_failure_on_collection_literal | ||
final lines = {}; // Inference failure | ||
lines['Dart'] = 10000; | ||
lines['C++'] = 'one thousand'; | ||
lines['Go'] = 2000; | ||
print('Lines: ${lines.values.reduce((a, b) => a + b)}'); // Runtime error | ||
// #enddocregion strict-inference | ||
} | ||
|
||
void strictRawTypes() { | ||
// #docregion strict-raw-types | ||
// ignore: stable, beta, dev, strict_raw_type | ||
List numbers = [1, 2, 3]; // List with raw type | ||
for (final n in numbers) { | ||
print(n.length); // Runtime error | ||
} | ||
// #enddocregion strict-raw-types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters