From 7d8b1b6fe1c80e4713e07841b8ca740a9759a0d4 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 17 Aug 2023 17:02:19 +0800 Subject: [PATCH] Release flint 2.8.0 --- flint/CHANGELOG.md | 11 ++++ flint/README.md | 2 +- flint/lib/analysis_options.dart.yaml | 13 ++-- flint/pubspec.yaml | 4 +- flint/tool/environment.dart | 2 +- flint/tool/update.dart | 92 +++++++++++++++++++--------- 6 files changed, 85 insertions(+), 39 deletions(-) diff --git a/flint/CHANGELOG.md b/flint/CHANGELOG.md index 169beb0e..91099515 100644 --- a/flint/CHANGELOG.md +++ b/flint/CHANGELOG.md @@ -1,3 +1,14 @@ +# 2.8.0 (17/08/2023) +This update focuses on lint rules introduce in Dart 3.1.0. + +- Add `matching_super_parameters` +- Add `no_literal_bool_comparisons` +- Add `no_self_assignments` +- Add `no_wildcard_variable_uses` +- Add `unreachable_from_main` +- Remove deprecated `iterable_contains_unrelated_type` +- Remove deprecated `list_remove_unrelated_type` + # 2.7.0 (13/05/2023) This update focuses on lint rules introduce in Dart 3. diff --git a/flint/README.md b/flint/README.md index 10a3ef49..1c11f068 100644 --- a/flint/README.md +++ b/flint/README.md @@ -11,7 +11,7 @@ Lint rules used by Forus Labs. To use a ruleset, add `flint` as a dev dependency in your `pubspec.yaml`. ```yaml dev_dependencies: - flint: ^2.7.0 + flint: ^2.8.0 ``` Then, add a ruleset to your `analysis_options.yaml`. Flint contains a Dart ruleset & a Flutter ruleset. diff --git a/flint/lib/analysis_options.dart.yaml b/flint/lib/analysis_options.dart.yaml index dd28e37c..cba7b50f 100644 --- a/flint/lib/analysis_options.dart.yaml +++ b/flint/lib/analysis_options.dart.yaml @@ -65,21 +65,23 @@ linter: - hash_and_equals - implementation_imports - implicit_call_tearoffs - - iterable_contains_unrelated_type - join_return_with_assignment - leading_newlines_in_multiline_strings - library_annotations - library_names - library_prefixes - library_private_types_in_public_api - - list_remove_unrelated_type - literal_only_boolean_expressions + - matching_super_parameters - missing_whitespace_between_adjacent_strings - no_adjacent_strings_in_list - no_duplicate_case_values - no_leading_underscores_for_library_prefixes - no_leading_underscores_for_local_identifiers + - no_literal_bool_comparisons - no_runtimeType_toString + - no_self_assignments + - no_wildcard_variable_uses - non_constant_identifier_names - noop_primitive_operations - null_check_on_nullable_type_parameter @@ -160,6 +162,7 @@ linter: - unnecessary_string_interpolations - unnecessary_this - unnecessary_to_list_in_spreads + - unreachable_from_main - unrelated_type_equality_checks - unsafe_html - use_enums @@ -180,15 +183,12 @@ linter: ignore: - always_declare_return_types - always_put_required_named_parameters - - always_require_non_null_named_parameters - always_specify_types - avoid_annotating_with_dynamic - avoid_as - avoid_classes_with_only_static_members - avoid_equals_and_hash_code_on_mutable_classes - avoid_renaming_method_parameters - - avoid_returning_null - - avoid_returning_null_for_future - avoid_type_to_string - avoid_web_libraries_in_flutter - diagnostic_describe_all_properties @@ -208,9 +208,12 @@ ignore: - prefer_relative_imports - public_member_api_docs - require_trailing_commas + - sized_box_for_whitespace + - sized_box_shrink_expand - sort_constructors_first - sort_unnamed_constructors_first - unnecessary_final - use_colored_box - use_decorated_box + - use_full_hex_values_for_flutter_colors - use_key_in_widget_constructors \ No newline at end of file diff --git a/flint/pubspec.yaml b/flint/pubspec.yaml index 3beac075..b9bc409a 100644 --- a/flint/pubspec.yaml +++ b/flint/pubspec.yaml @@ -1,11 +1,11 @@ name: flint description: Analyzer lints used internally in Forus Labs' Dart & Flutter projects. -version: 2.7.0 +version: 2.8.0 homepage: https://github.com/forus-labs/cauldron repository: https://github.com/forus-labs/cauldron environment: - sdk: '>=3.0.0 <4.0.0' + sdk: '>=3.1.0 <4.0.0' dev_dependencies: html: ^0.15.0 diff --git a/flint/tool/environment.dart b/flint/tool/environment.dart index 8deffac1..f9dfd565 100644 --- a/flint/tool/environment.dart +++ b/flint/tool/environment.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:yaml/yaml.dart'; -final Uri remote = Uri.parse('https://raw.githubusercontent.com/dart-lang/linter/master/example/all.yaml'); +final Uri remote = Uri.parse('https://dart.dev/tools/linter-rules/all'); final String projectDirectory = (Platform.script.path.split('/')..removeLast()..removeLast()).join('/'); diff --git a/flint/tool/update.dart b/flint/tool/update.dart index 04dfdd9b..b59773a8 100644 --- a/flint/tool/update.dart +++ b/flint/tool/update.dart @@ -2,54 +2,86 @@ import 'dart:io'; import 'package:html/parser.dart' show parse; import 'package:http/http.dart'; -import 'package:yaml/yaml.dart'; import 'environment.dart'; -Future main() async => write(await mature(changes(await fetch())).toSet()); +Future main() async => write(await process(await fetch())); Future> fetch() async { - if (!temp.existsSync() || DateTime.now().difference(temp.lastModifiedSync()) > const Duration(days: 1)) { - print('"all_rules.yaml" could not be found/is outdated, downloading from $remote'); + print('Fetching lint rules from $remote.'); - final response = await get(remote); - temp..createSync(recursive: true)..writeAsStringSync(response.body); - } - - return Set.from(loadFile(temp)['linter']['rules'] as YamlList); + final response = parse((await get(remote)).body); + return response.getElementsByClassName('code-excerpt__code').single.innerHtml + .split(RegExp('[ ]+-[ ]+')) + .skip(1) + .map((e) => e.trim()) + .toSet(); } -Set changes(Set remote) => remote.difference( { - ...rules['linter']['rules'], - ...rules['ignore'], -}); - -Stream mature(Set changes) async* { - for (final change in changes) { - final response = await get(Uri.parse('https://dart-lang.github.io/linter/lints/$change.html')); +Future<(Set released, Set removed)> process(Set remote) async { + final existing = { ...rules['linter']['rules'], ...rules['ignore'] }; + final released = {}; + final experimental = {}; + final removed = {}; + + for (final rule in remote) { + final response = await get(Uri.parse('https://dart.dev/tools/linter-rules/$rule')); if (response.statusCode == 404) { - print('Warning: https://dart-lang.github.io/linter/lints/$change.html does not exist (the rule might still be experimental)'); - return; + print('Warning: https://dart.dev/tools/linter-rules/$rule does not exist.'); + continue; + } + + final content = parse(response.body) + .getElementsByClassName('content')[0] + .getElementsByTagName('p')[1] + .getElementsByTagName('em')[0] + .text; + + if (existing.contains(rule) && (content.contains('deprecated') || content.contains('removed'))) { + removed.add(rule); + } else if (!existing.contains(rule) && !content.contains('experimental') && !content.contains('deprecated') && !content.contains('removed')) { + released.add(rule); + } if (!existing.contains(rule) && content.contains('experimental')) { + experimental.add(rule); } + } - final header = parse(response.body).body?.getElementsByClassName('wrapper').first.getElementsByTagName('header').first; - final released = !header!.getElementsByClassName('tooltip').first.getElementsByTagName('p').first.innerHtml.contains('unreleased'); - if (released) { - yield change; + if (experimental.isNotEmpty) { + print('The following rules are experimental:'); + for (final rule in experimental) { + print('https://dart.dev/tools/linter-rules/$rule'); } } + + return (released, removed); } -void write(Set changes) { - if (changes.isNotEmpty) { - print('See https://dart-lang.github.io/linter/lints/ for more information on lints'); +void write((Set released, Set removed) rules) { + final (Set released, Set removed) = rules; + + if (released.isNotEmpty) { + print('The following rules are stable:'); + options.writeAsStringSync('\nreleased:\n', mode: FileMode.append); + + for (final rule in released) { + print('https://dart.dev/tools/linter-rules/$rule'); + options.writeAsStringSync(' - $rule\n', mode: FileMode.append); + } + + } else { + print('No new stable lint rules released.'); + } + + if (removed.isNotEmpty) { + print('The following rules have been removed:'); + options.writeAsStringSync('\nremoved:\n', mode: FileMode.append); - options.writeAsStringSync('\nchanges:\n', mode: FileMode.append); - for (final change in changes) { - options.writeAsStringSync(' - $change\n', mode: FileMode.append); + for (final rule in removed) { + print('https://dart.dev/tools/linter-rules/$rule'); + options.writeAsStringSync(' - $rule\n', mode: FileMode.append); } } else { - print('No changes to lints'); + print('No new lint rules removed.'); } }