diff --git a/.github/workflows/lints.yaml b/.github/workflows/lints.yaml index 9135065db..a91586b22 100644 --- a/.github/workflows/lints.yaml +++ b/.github/workflows/lints.yaml @@ -26,7 +26,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [beta] # todo: re-add stable + sdk: [dev, beta, stable] steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 @@ -36,6 +36,7 @@ jobs: - run: dart pub get - run: dart format --output=none --set-exit-if-changed . + if: ${{ matrix.sdk == 'stable' }} - run: dart analyze --fatal-infos - run: dart tool/validate_lib.dart - run: dart tool/gen_docs.dart --verify diff --git a/pkgs/lints/CHANGELOG.md b/pkgs/lints/CHANGELOG.md index de9f93b6b..dbd4504bd 100644 --- a/pkgs/lints/CHANGELOG.md +++ b/pkgs/lints/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.0.0-wip + +- `recommended`: + - added [unnecessary_underscores] (https://github.com/dart-lang/core/issues/856) +- Require Dart 3.7. + ## 5.1.1 - Updated the SDK lower bound to 3.6. diff --git a/pkgs/lints/lib/recommended.yaml b/pkgs/lints/lib/recommended.yaml index 5b762ff7b..bb7c1a435 100644 --- a/pkgs/lints/lib/recommended.yaml +++ b/pkgs/lints/lib/recommended.yaml @@ -63,6 +63,7 @@ linter: - unnecessary_string_interpolations - unnecessary_this - unnecessary_to_list_in_spreads + - unnecessary_underscores - use_function_type_syntax_for_parameters - use_rethrow_when_possible - use_super_parameters diff --git a/pkgs/lints/pubspec.yaml b/pkgs/lints/pubspec.yaml index ccb21f2e7..171efe948 100644 --- a/pkgs/lints/pubspec.yaml +++ b/pkgs/lints/pubspec.yaml @@ -1,5 +1,5 @@ name: lints -version: 5.1.1 +version: 6.0.0-wip description: > Official Dart lint rules. Defines the 'core' and 'recommended' set of lints suggested by the Dart team. @@ -11,7 +11,7 @@ topics: - lints environment: - sdk: ^3.6.0 + sdk: ^3.7.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 e4dd15e40..d073af84e 100644 --- a/pkgs/lints/rules.md +++ b/pkgs/lints/rules.md @@ -98,6 +98,7 @@ | [`unnecessary_string_interpolations`](https://dart.dev/lints/unnecessary_string_interpolations) | Unnecessary string interpolation. | ✅ | | [`unnecessary_this`](https://dart.dev/lints/unnecessary_this) | Don't access members with `this` unless avoiding shadowing. | ✅ | | [`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_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. | ✅ | diff --git a/pkgs/lints/tool/gen_docs.dart b/pkgs/lints/tool/gen_docs.dart index 2ecea3860..e0818931c 100644 --- a/pkgs/lints/tool/gen_docs.dart +++ b/pkgs/lints/tool/gen_docs.dart @@ -48,8 +48,10 @@ void main(List args) async { } // Generate new documentation. - var newRulesMarkdownContent = - _updateMarkdown(rulesMarkdownContent, rulesJson); + var newRulesMarkdownContent = _updateMarkdown( + rulesMarkdownContent, + rulesJson, + ); // If no documentation change, all is up-to-date. if (newRulesMarkdownContent == rulesMarkdownContent) { @@ -59,8 +61,10 @@ void main(List args) async { /// Documentation has changed. if (verifyOnly) { - print('${rulesMarkdownFile.path} is not up-to-date (lint tables need to be ' - 'regenerated).'); + print( + '${rulesMarkdownFile.path} is not up-to-date (lint tables need to be ' + 'regenerated).', + ); print(''); print("Run 'dart tool/gen_docs.dart' to re-generate."); exit(1); @@ -79,8 +83,9 @@ void main(List args) async { /// /// If [verifyOnly] is `true`, only reads the cached data back from /// [rulesCacheFilePath]. -Future>> _fetchRulesJson( - {required bool verifyOnly}) async { +Future>> _fetchRulesJson({ + required bool verifyOnly, +}) async { final rulesJsonFile = _packageRelativeFile(rulesCacheFilePath); if (verifyOnly) { final rulesJsonText = rulesJsonFile.readAsStringSync(); @@ -91,8 +96,9 @@ Future>> _fetchRulesJson( // Re-save [rulesJsonFile] file. var newRulesJson = [...rulesJson.values]; - rulesJsonFile - .writeAsStringSync(JsonEncoder.withIndent(' ').convert(newRulesJson)); + rulesJsonFile.writeAsStringSync( + JsonEncoder.withIndent(' ').convert(newRulesJson), + ); return rulesJson; } @@ -108,8 +114,8 @@ Map> _readJson(String rulesJsonText) { return { for (Map rule in rulesJson) rule['name'] as String: { - for (var key in relevantKeys) key: rule[key] as String - } + for (var key in relevantKeys) key: rule[key] as String, + }, }; } @@ -121,7 +127,9 @@ Map> _readJson(String rulesJsonText) { /// [rulesJson], based on the list of rules in `lib/core.yaml` and /// `lib/recommended.yaml`. String _updateMarkdown( - String content, Map> rulesJson) { + String content, + Map> rulesJson, +) { for (var ruleSetName in ['core', 'recommended']) { var ruleFile = _packageRelativeFile(p.join('lib', '$ruleSetName.yaml')); var ruleSet = _parseRules(ruleFile); @@ -134,7 +142,10 @@ String _updateMarkdown( continue; } content = content.replaceRange( - rangeStart, rangeEnd, _createRuleTable(ruleSet, rulesJson)); + rangeStart, + rangeEnd, + _createRuleTable(ruleSet, rulesJson), + ); } return content; } @@ -148,7 +159,9 @@ List _parseRules(File yamlFile) { /// Creates markdown source for a table of lint rules. String _createRuleTable( - List rules, Map> lintMeta) { + List rules, + Map> lintMeta, +) { rules.sort(); final lines = [ @@ -166,15 +179,18 @@ String _createRuleTable( /// The row should have the same number of entires as the table format, /// and should be on a single line with no newline at the end. String _createRuleTableRow( - String rule, Map> lintMeta) { + String rule, + Map> lintMeta, +) { final ruleMeta = lintMeta[rule]; if (ruleMeta == null) { stderr.writeln("WARNING: Missing rule information for rule: $rule"); } - final description = (ruleMeta?['description'] ?? '') - .replaceAll('\n', ' ') - .replaceAll(RegExp(r'\s+'), ' ') - .trim(); + final description = + (ruleMeta?['description'] ?? '') + .replaceAll('\n', ' ') + .replaceAll(RegExp(r'\s+'), ' ') + .trim(); final hasFix = ruleMeta?['fixStatus'] == 'hasFix'; final fixDesc = hasFix ? '✅' : ''; diff --git a/pkgs/lints/tool/rules.json b/pkgs/lints/tool/rules.json index 5dff4a90f..cce22959e 100644 --- a/pkgs/lints/tool/rules.json +++ b/pkgs/lints/tool/rules.json @@ -904,6 +904,11 @@ "description": "Specify non-obvious type annotations for top-level and static variables.", "fixStatus": "hasFix" }, + { + "name": "strict_top_level_inference", + "description": "Specify type annotations.", + "fixStatus": "hasFix" + }, { "name": "super_goes_last", "description": "Place the `super` call last in a constructor initialization list.", @@ -949,6 +954,11 @@ "description": "Use of angle brackets in a doc comment is treated as HTML by Markdown.", "fixStatus": "needsFix" }, + { + "name": "unnecessary_async", + "description": "No await no async.", + "fixStatus": "needsFix" + }, { "name": "unnecessary_await_in_return", "description": "Unnecessary `await` keyword in return.", @@ -984,6 +994,11 @@ "description": "Avoid wrapping fields in getters and setters just to be \"safe\".", "fixStatus": "hasFix" }, + { + "name": "unnecessary_ignore", + "description": "Don't ignore a diagnostic code that is not produced.", + "fixStatus": "hasFix" + }, { "name": "unnecessary_lambdas", "description": "Don't create a lambda when a tear-off will do.", @@ -1074,6 +1089,11 @@ "description": "Unnecessary `toList()` in spreads.", "fixStatus": "hasFix" }, + { + "name": "unnecessary_underscores", + "description": "Unnecessary underscores can be removed.", + "fixStatus": "hasFix" + }, { "name": "unreachable_from_main", "description": "Unreachable top-level members in executable libraries.", diff --git a/pkgs/lints/tool/validate_lib.dart b/pkgs/lints/tool/validate_lib.dart index 38b1ce80c..388a7f86c 100644 --- a/pkgs/lints/tool/validate_lib.dart +++ b/pkgs/lints/tool/validate_lib.dart @@ -9,11 +9,12 @@ import 'package:path/path.dart' as p; void main(List args) { print('Validating that there are no .dart source files in lib/ ...'); - final dartSourceFiles = Directory('lib') - .listSync(recursive: true) - .whereType() - .where((file) => p.extension(file.path) == '.dart') - .toList(); + final dartSourceFiles = + Directory('lib') + .listSync(recursive: true) + .whereType() + .where((file) => p.extension(file.path) == '.dart') + .toList(); if (dartSourceFiles.isEmpty) { print('No Dart files found.');