Add use_null_aware_elements to recommended (#923)
Closes #899
Bump to a feature release.
Drop an unnecessary `-0` suffix on the SDK constraint.
Update URL for reading rules from the dart site source.
diff --git a/pkgs/lints/CHANGELOG.md b/pkgs/lints/CHANGELOG.md
index ff99d82..1680b2a 100644
--- a/pkgs/lints/CHANGELOG.md
+++ b/pkgs/lints/CHANGELOG.md
@@ -1,7 +1,11 @@
-## 6.0.1-wip
+## 6.1.0-wip
+- `recommended`:
+ - added [use_null_aware_elements] (https://github.com/dart-lang/core/issues/899)
- Run `dart format` with the new style.
+[use_null_aware_elements]: https://dart.dev/lints/use_null_aware_elements
+
## 6.0.0
- `core`:
diff --git a/pkgs/lints/lib/recommended.yaml b/pkgs/lints/lib/recommended.yaml
index bb7c1a4..7fe341b 100644
--- a/pkgs/lints/lib/recommended.yaml
+++ b/pkgs/lints/lib/recommended.yaml
@@ -65,5 +65,6 @@
- unnecessary_to_list_in_spreads
- unnecessary_underscores
- use_function_type_syntax_for_parameters
+ - use_null_aware_elements
- use_rethrow_when_possible
- use_super_parameters
diff --git a/pkgs/lints/pubspec.yaml b/pkgs/lints/pubspec.yaml
index 8059666..99cae1e 100644
--- a/pkgs/lints/pubspec.yaml
+++ b/pkgs/lints/pubspec.yaml
@@ -1,5 +1,5 @@
name: lints
-version: 6.0.1-wip
+version: 6.1.0-wip
description: >
Official Dart lint rules. Defines the 'core' and 'recommended' set of lints
suggested by the Dart team.
@@ -11,7 +11,7 @@
- lints
environment:
- sdk: ^3.8.0-0
+ sdk: ^3.8.0
# NOTE: Code is not allowed in this package - do not add dependencies.
# dependencies:
diff --git a/pkgs/lints/rules.md b/pkgs/lints/rules.md
index 076f4ce..097fec2 100644
--- a/pkgs/lints/rules.md
+++ b/pkgs/lints/rules.md
@@ -8,7 +8,7 @@
| [`avoid_empty_else`](https://dart.dev/lints/avoid_empty_else) | Avoid empty statements in else clauses. | ✅ |
| [`avoid_relative_lib_imports`](https://dart.dev/lints/avoid_relative_lib_imports) | Avoid relative imports for files in `lib/`. | ✅ |
| [`avoid_shadowing_type_parameters`](https://dart.dev/lints/avoid_shadowing_type_parameters) | Avoid shadowing type parameters. | |
-| [`avoid_types_as_parameter_names`](https://dart.dev/lints/avoid_types_as_parameter_names) | Avoid types as parameter names. | ✅ |
+| [`avoid_types_as_parameter_names`](https://dart.dev/lints/avoid_types_as_parameter_names) | Avoid types as parameter names. | |
| [`await_only_futures`](https://dart.dev/lints/await_only_futures) | Await only futures. | ✅ |
| [`camel_case_extensions`](https://dart.dev/lints/camel_case_extensions) | Name extensions using UpperCamelCase. | |
| [`camel_case_types`](https://dart.dev/lints/camel_case_types) | Name types using UpperCamelCase. | |
@@ -101,6 +101,7 @@
| [`unnecessary_to_list_in_spreads`](https://dart.dev/lints/unnecessary_to_list_in_spreads) | Unnecessary `toList()` in spreads. | ✅ |
| [`unnecessary_underscores`](https://dart.dev/lints/unnecessary_underscores) | Unnecessary underscores can be removed. | ✅ |
| [`use_function_type_syntax_for_parameters`](https://dart.dev/lints/use_function_type_syntax_for_parameters) | Use generic function type syntax for parameters. | ✅ |
+| [`use_null_aware_elements`](https://dart.dev/lints/use_null_aware_elements) | If-elements testing for null can be replaced with null-aware elements. | ✅ |
| [`use_rethrow_when_possible`](https://dart.dev/lints/use_rethrow_when_possible) | Use rethrow to rethrow a caught exception. | ✅ |
| [`use_super_parameters`](https://dart.dev/lints/use_super_parameters) | Use super-initializer parameters where possible. | ✅ |
<!-- recommended -->
diff --git a/pkgs/lints/tool/gen_docs.dart b/pkgs/lints/tool/gen_docs.dart
index 54a99ad..91aa2ab 100644
--- a/pkgs/lints/tool/gen_docs.dart
+++ b/pkgs/lints/tool/gen_docs.dart
@@ -10,8 +10,10 @@
import 'package:http/http.dart' as http;
/// Source of truth for linter rules.
-const rulesUrl =
- 'https://raw.githubusercontent.com/dart-lang/site-www/main/src/_data/linter_rules.json';
+final rulesUri = Uri.https(
+ 'raw.githubusercontent.com',
+ 'dart-lang/site-www/main/src/data/linter_rules.json',
+);
/// Local cache of linter rules from [rulesUrl].
///
@@ -25,7 +27,7 @@
/// Fetches the [rulesUrl] JSON description of all lints, saves a cached
/// summary of the relevant fields in [rulesCacheFilePath], and
-/// updates [rulesMarkdownFilePath] to
+/// updates [rulesMarkdownFilePath].
///
/// Passing any command line argument disables generating documentation,
/// and makes this tool just verify that the doc is up-to-date with the
@@ -91,7 +93,7 @@
final rulesJsonText = rulesJsonFile.readAsStringSync();
return _readJson(rulesJsonText);
}
- final rulesJsonText = (await http.get(Uri.parse(rulesUrl))).body;
+ final rulesJsonText = (await http.get(rulesUri)).body;
final rulesJson = _readJson(rulesJsonText);
// Re-save [rulesJsonFile] file.
diff --git a/pkgs/lints/tool/rules.json b/pkgs/lints/tool/rules.json
index cce2295..9a75264 100644
--- a/pkgs/lints/tool/rules.json
+++ b/pkgs/lints/tool/rules.json
@@ -52,7 +52,7 @@
{
"name": "avoid_bool_literals_in_conditional_expressions",
"description": "Avoid `bool` literals in conditional expressions.",
- "fixStatus": "needsFix"
+ "fixStatus": "hasFix"
},
{
"name": "avoid_catches_without_on_clauses",
@@ -222,7 +222,7 @@
{
"name": "avoid_types_as_parameter_names",
"description": "Avoid types as parameter names.",
- "fixStatus": "hasFix"
+ "fixStatus": "noFix"
},
{
"name": "avoid_types_on_closure_parameters",
@@ -356,7 +356,7 @@
},
{
"name": "discarded_futures",
- "description": "Don't invoke asynchronous functions in non-`async` blocks.",
+ "description": "There should be no `Future`-returning calls in synchronous functions unless they are assigned or returned.",
"fixStatus": "hasFix"
},
{
@@ -732,7 +732,7 @@
{
"name": "prefer_foreach",
"description": "Use `forEach` to only apply a function to all the elements.",
- "fixStatus": "needsFix"
+ "fixStatus": "hasFix"
},
{
"name": "prefer_function_declarations_over_variables",
@@ -850,6 +850,11 @@
"fixStatus": "noFix"
},
{
+ "name": "remove_deprecations_in_breaking_versions",
+ "description": "Deprecation in major version.",
+ "fixStatus": "needsFix"
+ },
+ {
"name": "require_trailing_commas",
"description": "Use trailing commas for all parameter lists and argument lists.",
"fixStatus": "hasFix"
@@ -915,6 +920,11 @@
"fixStatus": "noFix"
},
{
+ "name": "switch_on_type",
+ "description": "Avoid switch statements on a 'Type'.",
+ "fixStatus": "noFix"
+ },
+ {
"name": "test_types_in_equals",
"description": "Test type of argument in `operator ==(Object other)`.",
"fixStatus": "noFix"
@@ -957,7 +967,7 @@
{
"name": "unnecessary_async",
"description": "No await no async.",
- "fixStatus": "needsFix"
+ "fixStatus": "hasFix"
},
{
"name": "unnecessary_await_in_return",
@@ -1090,6 +1100,11 @@
"fixStatus": "hasFix"
},
{
+ "name": "unnecessary_unawaited",
+ "description": "Unnecessary use of 'unawaited'.",
+ "fixStatus": "hasFix"
+ },
+ {
"name": "unnecessary_underscores",
"description": "Unnecessary underscores can be removed.",
"fixStatus": "hasFix"
@@ -1147,7 +1162,7 @@
{
"name": "use_if_null_to_convert_nulls_to_bools",
"description": "Use `??` operators to convert `null`s to `bool`s.",
- "fixStatus": "needsFix"
+ "fixStatus": "hasFix"
},
{
"name": "use_is_even_rather_than_modulo",
@@ -1170,6 +1185,11 @@
"fixStatus": "hasFix"
},
{
+ "name": "use_null_aware_elements",
+ "description": "If-elements testing for null can be replaced with null-aware elements.",
+ "fixStatus": "hasFix"
+ },
+ {
"name": "use_raw_strings",
"description": "Use raw string to avoid escapes.",
"fixStatus": "hasFix"