Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit fe0b1cc

Browse files
authored
generate flutter lint badges (#1304)
1 parent bd705ff commit fe0b1cc

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

tool/doc.dart

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ These rules are under active development. Feedback is
5252

5353
const ruleLeadMatter = 'Rules are organized into familiar rule groups.';
5454

55+
final flutterRules = <String>[];
5556
final pedanticRules = <String>[];
5657

5758
/// Sorted list of contributed lint rules.
@@ -81,14 +82,23 @@ String get enumerateStyleRules => rules
8182
List<String> get sortedRules => rules.map((r) => r.name).toList()..sort();
8283

8384
Future<void> fetchBadgeInfo() async {
84-
var client = new http.Client();
85-
var req = await client.get(Uri.parse(
86-
'https://raw.githubusercontent.com/dart-lang/pedantic/master/lib/analysis_options.yaml'));
87-
88-
var config = processAnalysisOptionsFile(req.body);
89-
for (var ruleConfig in config.ruleConfigs) {
85+
var pedantic = await fetchConfig(
86+
'https://raw.githubusercontent.com/dart-lang/pedantic/master/lib/analysis_options.yaml');
87+
for (var ruleConfig in pedantic.ruleConfigs) {
9088
pedanticRules.add(ruleConfig.name);
9189
}
90+
91+
var flutter = await fetchConfig(
92+
'https://raw.githubusercontent.com/flutter/flutter/master/packages/flutter/lib/analysis_options_user.yaml');
93+
for (var ruleConfig in flutter.ruleConfigs) {
94+
flutterRules.add(ruleConfig.name);
95+
}
96+
}
97+
98+
Future<LintConfig> fetchConfig(String url) async {
99+
var client = new http.Client();
100+
var req = await client.get(url);
101+
return processAnalysisOptionsFile(req.body);
92102
}
93103

94104
Future<void> generateDocs(String dir) async {
@@ -125,11 +135,18 @@ Future<void> generateDocs(String dir) async {
125135
new OptionsSample(rules).generate(outDir);
126136
}
127137

128-
String getBadges(String rule) => isPedantic(rule)
129-
? '<a href="https://github.com/dart-lang/pedantic/#enabled-lints"><img alt="pedantic" src="style-pedantic.svg"></a>'
130-
: '';
131-
132-
bool isPedantic(String rule) => pedanticRules.contains(rule);
138+
String getBadges(String rule) {
139+
var sb = new StringBuffer();
140+
if (flutterRules.contains(rule)) {
141+
sb.write(
142+
'<a href="https://github.com/flutter/flutter/blob/master/packages/flutter/lib/analysis_options_user.yaml"><img alt="flutter" src="style-flutter.svg"></a> ');
143+
}
144+
if (pedanticRules.contains(rule)) {
145+
sb.write(
146+
'<a href="https://github.com/dart-lang/pedantic/#enabled-lints"><img alt="pedantic" src="style-pedantic.svg"></a>');
147+
}
148+
return sb.toString();
149+
}
133150

134151
void printUsage(ArgParser parser, [String error]) {
135152
var message = 'Generates lint docs.';

0 commit comments

Comments
 (0)