Skip to content

Commit 640d9a7

Browse files
parloughCommit Queue
authored andcommitted
[linter] Update lint changelog for 3.8 and 3.9
Also mark recently published lint docs as published. Change-Id: If2fba38b6c6cae5764691803d9359dffca8ddf33 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429281 Reviewed-by: Samuel Rawlins <[email protected]> Auto-Submit: Parker Lougheed <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 40323df commit 640d9a7

File tree

5 files changed

+57
-10
lines changed

5 files changed

+57
-10
lines changed

CHANGELOG.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 3.9.0
22

3+
**Released on:** Unreleased
4+
35
### Language
46

57
Dart 3.9 assumes null safety when computing type promotion, reachability, and
@@ -12,6 +14,14 @@ constraint][language version] lower bound to 3.9 or greater (`sdk: '^3.9.0'`).
1214

1315
### Tools
1416

17+
#### Analyzer
18+
19+
- Add the [`switch_on_type`][] lint rule.
20+
- Add the [`unnecessary_unawaited`][] lint rule.
21+
22+
[`switch_on_type`]: http://dart.dev/lints/switch_on_type
23+
[`unnecessary_unawaited`]: http://dart.dev/lints/unnecessary_unawaited
24+
1525
#### Dart Development Compiler (dartdevc)
1626

1727
- Outstanding async code now checks and cancels itself after a hot restart if
@@ -166,13 +176,12 @@ Full details are in the [feature specification][null-aware elements].
166176
- Add LSP document links for dependency packages in pubspec files.
167177
- Fix various issues around patterns, like highlighting, navigation, and
168178
autocompletion.
179+
- Add the [`use_null_aware_elements`][] lint rule.
169180
- Add the experimental [`unnecessary_ignore`][] lint rule.
170-
- Add the [`switch_on_runtimetype`][] lint rule that reports when a switch
171-
statement or switch expression uses an expression's `runtimeType` as its
172-
switch variable.
173181
- (Thanks [@FMorschel](https://github.com/FMorschel) for many of the above
174182
enhancements!)
175183

184+
[`use_null_aware_elements`]: http://dart.dev/lints/use_null_aware_elements
176185
[`unnecessary_ignore`]: http://dart.dev/lints/unnecessary_ignore
177186

178187
#### Dart Development Compiler (dartdevc)

pkg/linter/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# 3.8.0-wip
1+
# 3.9.0-wip
2+
3+
- new lint: `switch_on_type`
4+
- new lint: `unnecessary_unawaited`
5+
6+
# 3.8.0
27

38
- new lint: `use_null_aware_elements`
49
- new _(experimental)_ lint: `unnecessary_ignore`

pkg/linter/lib/src/lint_codes.g.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,7 @@ class LinterLintCode extends LintCode {
15461546
LintNames.switch_on_type,
15471547
"Avoid switch statements on a 'Type'.",
15481548
correctionMessage: "Try using pattern matching on a variable instead.",
1549+
hasPublishedDocs: true,
15491550
);
15501551

15511552
static const LintCode test_types_in_equals = LinterLintCode(
@@ -1840,6 +1841,7 @@ class LinterLintCode extends LintCode {
18401841
correctionMessage:
18411842
"Try removing the use of 'unawaited', as the unawaited element is "
18421843
"annotated with '@awaitNotRequired'.",
1844+
hasPublishedDocs: true,
18431845
);
18441846

18451847
static const LintCode unnecessary_underscores = LinterLintCode(

pkg/linter/messages.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11348,9 +11348,9 @@ LintCode:
1134811348
problemMessage: "Avoid switch statements on a 'Type'."
1134911349
correctionMessage: "Try using pattern matching on a variable instead."
1135011350
state:
11351-
stable: "3.0"
11351+
stable: "3.9"
1135211352
categories: [unintentional, style, languageFeatureUsage, errorProne]
11353-
hasPublishedDocs: false
11353+
hasPublishedDocs: true
1135411354
documentation: |-
1135511355
#### Description
1135611356
@@ -13668,7 +13668,7 @@ LintCode:
1366813668
state:
1366913669
stable: "3.9"
1367013670
categories: [brevity, unintentional, unusedCode]
13671-
hasPublishedDocs: false
13671+
hasPublishedDocs: true
1367213672
documentation: |-
1367313673
#### Description
1367413674

pkg/linter/tool/machine/rules.json

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@
599599
"state": "stable",
600600
"incompatible": [],
601601
"sets": [],
602-
"fixStatus": "hasFix",
602+
"fixStatus": "noFix",
603603
"details": "**AVOID** using a parameter name that is the same as an existing type.\n\n**BAD:**\n```dart\nm(f(int));\n```\n\n**GOOD:**\n```dart\nm(f(int v));\n```",
604604
"sinceDartSdk": "2.0"
605605
},
@@ -1954,7 +1954,7 @@
19541954
"state": "stable",
19551955
"incompatible": [],
19561956
"sets": [],
1957-
"fixStatus": "needsFix",
1957+
"fixStatus": "hasFix",
19581958
"details": "**DO** use `forEach` if you are only going to apply a function or a method\nto all the elements of an iterable.\n\nUsing `forEach` when you are only going to apply a function or method to all\nelements of an iterable is a good practice because it makes your code more\nterse.\n\n**BAD:**\n```dart\nfor (final key in map.keys.toList()) {\n map.remove(key);\n}\n```\n\n**GOOD:**\n```dart\nmap.keys.toList().forEach(map.remove);\n```\n\n**NOTE:** Replacing a for each statement with a forEach call may change the\nbehavior in the case where there are side-effects on the iterable itself.\n```dart\nfor (final v in myList) {\n foo().f(v); // This code invokes foo() many times.\n}\n\nmyList.forEach(foo().f); // But this one invokes foo() just once.\n```",
19591959
"sinceDartSdk": "2.0"
19601960
},
@@ -2447,6 +2447,22 @@
24472447
"details": "NOTE: This rule is removed in Dart 3.0.0; it is no longer functional.\n\n**DO** place the `super` call last in a constructor initialization list.\n\nField initializers are evaluated in the order that they appear in the\nconstructor initialization list. If you place a `super()` call in the middle of\nan initializer list, the superclass's initializers will be evaluated right then\nbefore evaluating the rest of the subclass's initializers.\n\nWhat it doesn't mean is that the superclass's constructor body will be executed\nthen. That always happens after all initializers are run regardless of where\n`super` appears. It's vanishingly rare that the order of initializers matters,\nso the placement of `super` in the list almost never matters either.\n\nGetting in the habit of placing it last improves consistency, visually\nreinforces when the superclass's constructor body is run, and may help\nperformance.\n\n**BAD:**\n```dart\nView(Style style, List children)\n : super(style),\n _children = children {\n```\n\n**GOOD:**\n```dart\nView(Style style, List children)\n : _children = children,\n super(style) {\n```",
24482448
"sinceDartSdk": "2.0"
24492449
},
2450+
{
2451+
"name": "switch_on_type",
2452+
"description": "Avoid switch statements on a 'Type'.",
2453+
"categories": [
2454+
"unintentional",
2455+
"style",
2456+
"languageFeatureUsage",
2457+
"errorProne"
2458+
],
2459+
"state": "stable",
2460+
"incompatible": [],
2461+
"sets": [],
2462+
"fixStatus": "noFix",
2463+
"details": "**AVOID** using switch on `Type`.\n\nSwitching on `Type` is not type-safe and can lead to bugs if the\nclass hierarchy changes. Prefer to use pattern matching on the variable\ninstead.\n\n**BAD:**\n```dart\nvoid f(Object o) {\n switch (o.runtimeType) {\n case int:\n print('int');\n case String:\n print('String');\n }\n}\n```\n\n**GOOD:**\n```dart\nvoid f(Object o) {\n switch(o) {\n case int():\n print('int');\n case String _:\n print('String');\n default:\n print('other');\n }\n}\n```",
2464+
"sinceDartSdk": "3.9"
2465+
},
24502466
{
24512467
"name": "test_types_in_equals",
24522468
"description": "Test type of argument in `operator ==(Object other)`.",
@@ -2928,6 +2944,21 @@
29282944
"details": "Unnecessary `toList()` in spreads.\n\n**BAD:**\n```dart\nchildren: <Widget>[\n ...['foo', 'bar', 'baz'].map((String s) => Text(s)).toList(),\n]\n```\n\n**GOOD:**\n```dart\nchildren: <Widget>[\n ...['foo', 'bar', 'baz'].map((String s) => Text(s)),\n]\n```",
29292945
"sinceDartSdk": "2.18"
29302946
},
2947+
{
2948+
"name": "unnecessary_unawaited",
2949+
"description": "Unnecessary use of 'unawaited'.",
2950+
"categories": [
2951+
"brevity",
2952+
"unintentional",
2953+
"unusedCode"
2954+
],
2955+
"state": "stable",
2956+
"incompatible": [],
2957+
"sets": [],
2958+
"fixStatus": "hasFix",
2959+
"details": "A call to a function, method, or operator, or a reference to a field,\ngetter, or top-level variable which is annotated with `@awaitNotRequired`\ndoes not need to be wrapped in a call to `unawaited()`.\n\n**BAD:**\n```dart\n@awaitNotRequired\nFuture<LogMessage> log(String message) { ... }\n\nvoid f() {\n unawaited(log('Message.'));\n}\n```\n\n**GOOD:**\n```dart\n@awaitNotRequired\nFuture<LogMessage> log(String message) { ... }\n\nvoid f() {\n log('Message.');\n}\n```",
2960+
"sinceDartSdk": "3.9"
2961+
},
29312962
{
29322963
"name": "unnecessary_underscores",
29332964
"description": "Unnecessary underscores can be removed.",
@@ -3086,7 +3117,7 @@
30863117
"state": "stable",
30873118
"incompatible": [],
30883119
"sets": [],
3089-
"fixStatus": "needsFix",
3120+
"fixStatus": "hasFix",
30903121
"details": "From [Effective Dart](https://dart.dev/effective-dart/usage#prefer-using--to-convert-null-to-a-boolean-value):\n\nUse `??` operators to convert `null`s to `bool`s.\n\n**BAD:**\n```dart\nif (nullableBool == true) {\n}\nif (nullableBool != false) {\n}\n```\n\n**GOOD:**\n```dart\nif (nullableBool ?? false) {\n}\nif (nullableBool ?? true) {\n}\n```",
30913122
"sinceDartSdk": "2.13"
30923123
},

0 commit comments

Comments
 (0)