Skip to content

Commit 15c7fe9

Browse files
authored
add unnecessary_underscores to recommended (#863)
1 parent 0b2bd3f commit 15c7fe9

File tree

8 files changed

+72
-26
lines changed

8 files changed

+72
-26
lines changed

.github/workflows/lints.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
fail-fast: false
2828
matrix:
29-
sdk: [beta] # todo: re-add stable
29+
sdk: [dev, beta, stable]
3030

3131
steps:
3232
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
@@ -36,6 +36,7 @@ jobs:
3636

3737
- run: dart pub get
3838
- run: dart format --output=none --set-exit-if-changed .
39+
if: ${{ matrix.sdk == 'stable' }}
3940
- run: dart analyze --fatal-infos
4041
- run: dart tool/validate_lib.dart
4142
- run: dart tool/gen_docs.dart --verify

pkgs/lints/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 6.0.0-wip
2+
3+
- `recommended`:
4+
- added [unnecessary_underscores] (https://github.com/dart-lang/core/issues/856)
5+
- Require Dart 3.7.
6+
17
## 5.1.1
28

39
- Updated the SDK lower bound to 3.6.

pkgs/lints/lib/recommended.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ linter:
6363
- unnecessary_string_interpolations
6464
- unnecessary_this
6565
- unnecessary_to_list_in_spreads
66+
- unnecessary_underscores
6667
- use_function_type_syntax_for_parameters
6768
- use_rethrow_when_possible
6869
- use_super_parameters

pkgs/lints/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: lints
2-
version: 5.1.1
2+
version: 6.0.0-wip
33
description: >
44
Official Dart lint rules. Defines the 'core' and 'recommended' set of lints
55
suggested by the Dart team.
@@ -11,7 +11,7 @@ topics:
1111
- lints
1212

1313
environment:
14-
sdk: ^3.6.0
14+
sdk: ^3.7.0
1515

1616
# NOTE: Code is not allowed in this package - do not add dependencies.
1717
# dependencies:

pkgs/lints/rules.md

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
| [`unnecessary_string_interpolations`](https://dart.dev/lints/unnecessary_string_interpolations) | Unnecessary string interpolation. ||
9999
| [`unnecessary_this`](https://dart.dev/lints/unnecessary_this) | Don't access members with `this` unless avoiding shadowing. ||
100100
| [`unnecessary_to_list_in_spreads`](https://dart.dev/lints/unnecessary_to_list_in_spreads) | Unnecessary `toList()` in spreads. ||
101+
| [`unnecessary_underscores`](https://dart.dev/lints/unnecessary_underscores) | Unnecessary underscores can be removed. ||
101102
| [`use_function_type_syntax_for_parameters`](https://dart.dev/lints/use_function_type_syntax_for_parameters) | Use generic function type syntax for parameters. ||
102103
| [`use_rethrow_when_possible`](https://dart.dev/lints/use_rethrow_when_possible) | Use rethrow to rethrow a caught exception. ||
103104
| [`use_super_parameters`](https://dart.dev/lints/use_super_parameters) | Use super-initializer parameters where possible. ||

pkgs/lints/tool/gen_docs.dart

+34-18
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ void main(List<String> args) async {
4848
}
4949

5050
// Generate new documentation.
51-
var newRulesMarkdownContent =
52-
_updateMarkdown(rulesMarkdownContent, rulesJson);
51+
var newRulesMarkdownContent = _updateMarkdown(
52+
rulesMarkdownContent,
53+
rulesJson,
54+
);
5355

5456
// If no documentation change, all is up-to-date.
5557
if (newRulesMarkdownContent == rulesMarkdownContent) {
@@ -59,8 +61,10 @@ void main(List<String> args) async {
5961

6062
/// Documentation has changed.
6163
if (verifyOnly) {
62-
print('${rulesMarkdownFile.path} is not up-to-date (lint tables need to be '
63-
'regenerated).');
64+
print(
65+
'${rulesMarkdownFile.path} is not up-to-date (lint tables need to be '
66+
'regenerated).',
67+
);
6468
print('');
6569
print("Run 'dart tool/gen_docs.dart' to re-generate.");
6670
exit(1);
@@ -79,8 +83,9 @@ void main(List<String> args) async {
7983
///
8084
/// If [verifyOnly] is `true`, only reads the cached data back from
8185
/// [rulesCacheFilePath].
82-
Future<Map<String, Map<String, String>>> _fetchRulesJson(
83-
{required bool verifyOnly}) async {
86+
Future<Map<String, Map<String, String>>> _fetchRulesJson({
87+
required bool verifyOnly,
88+
}) async {
8489
final rulesJsonFile = _packageRelativeFile(rulesCacheFilePath);
8590
if (verifyOnly) {
8691
final rulesJsonText = rulesJsonFile.readAsStringSync();
@@ -91,8 +96,9 @@ Future<Map<String, Map<String, String>>> _fetchRulesJson(
9196

9297
// Re-save [rulesJsonFile] file.
9398
var newRulesJson = [...rulesJson.values];
94-
rulesJsonFile
95-
.writeAsStringSync(JsonEncoder.withIndent(' ').convert(newRulesJson));
99+
rulesJsonFile.writeAsStringSync(
100+
JsonEncoder.withIndent(' ').convert(newRulesJson),
101+
);
96102

97103
return rulesJson;
98104
}
@@ -108,8 +114,8 @@ Map<String, Map<String, String>> _readJson(String rulesJsonText) {
108114
return {
109115
for (Map<String, Object?> rule in rulesJson)
110116
rule['name'] as String: {
111-
for (var key in relevantKeys) key: rule[key] as String
112-
}
117+
for (var key in relevantKeys) key: rule[key] as String,
118+
},
113119
};
114120
}
115121

@@ -121,7 +127,9 @@ Map<String, Map<String, String>> _readJson(String rulesJsonText) {
121127
/// [rulesJson], based on the list of rules in `lib/core.yaml` and
122128
/// `lib/recommended.yaml`.
123129
String _updateMarkdown(
124-
String content, Map<String, Map<String, String>> rulesJson) {
130+
String content,
131+
Map<String, Map<String, String>> rulesJson,
132+
) {
125133
for (var ruleSetName in ['core', 'recommended']) {
126134
var ruleFile = _packageRelativeFile(p.join('lib', '$ruleSetName.yaml'));
127135
var ruleSet = _parseRules(ruleFile);
@@ -134,7 +142,10 @@ String _updateMarkdown(
134142
continue;
135143
}
136144
content = content.replaceRange(
137-
rangeStart, rangeEnd, _createRuleTable(ruleSet, rulesJson));
145+
rangeStart,
146+
rangeEnd,
147+
_createRuleTable(ruleSet, rulesJson),
148+
);
138149
}
139150
return content;
140151
}
@@ -148,7 +159,9 @@ List<String> _parseRules(File yamlFile) {
148159

149160
/// Creates markdown source for a table of lint rules.
150161
String _createRuleTable(
151-
List<String> rules, Map<String, Map<String, String>> lintMeta) {
162+
List<String> rules,
163+
Map<String, Map<String, String>> lintMeta,
164+
) {
152165
rules.sort();
153166

154167
final lines = [
@@ -166,15 +179,18 @@ String _createRuleTable(
166179
/// The row should have the same number of entires as the table format,
167180
/// and should be on a single line with no newline at the end.
168181
String _createRuleTableRow(
169-
String rule, Map<String, Map<String, String>> lintMeta) {
182+
String rule,
183+
Map<String, Map<String, String>> lintMeta,
184+
) {
170185
final ruleMeta = lintMeta[rule];
171186
if (ruleMeta == null) {
172187
stderr.writeln("WARNING: Missing rule information for rule: $rule");
173188
}
174-
final description = (ruleMeta?['description'] ?? '')
175-
.replaceAll('\n', ' ')
176-
.replaceAll(RegExp(r'\s+'), ' ')
177-
.trim();
189+
final description =
190+
(ruleMeta?['description'] ?? '')
191+
.replaceAll('\n', ' ')
192+
.replaceAll(RegExp(r'\s+'), ' ')
193+
.trim();
178194
final hasFix = ruleMeta?['fixStatus'] == 'hasFix';
179195
final fixDesc = hasFix ? '✅' : '';
180196

pkgs/lints/tool/rules.json

+20
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,11 @@
904904
"description": "Specify non-obvious type annotations for top-level and static variables.",
905905
"fixStatus": "hasFix"
906906
},
907+
{
908+
"name": "strict_top_level_inference",
909+
"description": "Specify type annotations.",
910+
"fixStatus": "hasFix"
911+
},
907912
{
908913
"name": "super_goes_last",
909914
"description": "Place the `super` call last in a constructor initialization list.",
@@ -949,6 +954,11 @@
949954
"description": "Use of angle brackets in a doc comment is treated as HTML by Markdown.",
950955
"fixStatus": "needsFix"
951956
},
957+
{
958+
"name": "unnecessary_async",
959+
"description": "No await no async.",
960+
"fixStatus": "needsFix"
961+
},
952962
{
953963
"name": "unnecessary_await_in_return",
954964
"description": "Unnecessary `await` keyword in return.",
@@ -984,6 +994,11 @@
984994
"description": "Avoid wrapping fields in getters and setters just to be \"safe\".",
985995
"fixStatus": "hasFix"
986996
},
997+
{
998+
"name": "unnecessary_ignore",
999+
"description": "Don't ignore a diagnostic code that is not produced.",
1000+
"fixStatus": "hasFix"
1001+
},
9871002
{
9881003
"name": "unnecessary_lambdas",
9891004
"description": "Don't create a lambda when a tear-off will do.",
@@ -1074,6 +1089,11 @@
10741089
"description": "Unnecessary `toList()` in spreads.",
10751090
"fixStatus": "hasFix"
10761091
},
1092+
{
1093+
"name": "unnecessary_underscores",
1094+
"description": "Unnecessary underscores can be removed.",
1095+
"fixStatus": "hasFix"
1096+
},
10771097
{
10781098
"name": "unreachable_from_main",
10791099
"description": "Unreachable top-level members in executable libraries.",

pkgs/lints/tool/validate_lib.dart

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import 'package:path/path.dart' as p;
99
void main(List<String> args) {
1010
print('Validating that there are no .dart source files in lib/ ...');
1111

12-
final dartSourceFiles = Directory('lib')
13-
.listSync(recursive: true)
14-
.whereType<File>()
15-
.where((file) => p.extension(file.path) == '.dart')
16-
.toList();
12+
final dartSourceFiles =
13+
Directory('lib')
14+
.listSync(recursive: true)
15+
.whereType<File>()
16+
.where((file) => p.extension(file.path) == '.dart')
17+
.toList();
1718

1819
if (dartSourceFiles.isEmpty) {
1920
print('No Dart files found.');

0 commit comments

Comments
 (0)