Skip to content

Commit f1808c9

Browse files
authored
Fix lints and warnings accumulated in dartdoc (#1635)
* Fix or disable miscellaneous lints in dartdoc * Clean up a few more lints. * Review comments * dartfmt
1 parent fd4047a commit f1808c9

11 files changed

+55
-61
lines changed

bin/dartdoc.dart

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ main(List<String> arguments) async {
144144
output['message'] = record.message;
145145
}
146146

147-
print(JSON.encode(output));
147+
print(json.encode(output));
148148
});
149149
} else {
150150
final stopwatch = new Stopwatch()..start();
@@ -311,29 +311,21 @@ ArgParser _createArgsParser() {
311311
help: 'Path to source directory.', defaultsTo: Directory.current.path);
312312
parser.addOption('output',
313313
help: 'Path to output directory.', defaultsTo: defaultOutDir);
314-
parser.addOption('header',
315-
allowMultiple: true,
316-
splitCommas: true,
317-
help: 'paths to header files containing HTML text.');
318-
parser.addOption('footer',
319-
allowMultiple: true,
320-
splitCommas: true,
321-
help: 'paths to footer files containing HTML text.');
322-
parser.addOption('footer-text',
323-
allowMultiple: true,
314+
parser.addMultiOption('header',
315+
splitCommas: true, help: 'paths to header files containing HTML text.');
316+
parser.addMultiOption('footer',
317+
splitCommas: true, help: 'paths to footer files containing HTML text.');
318+
parser.addMultiOption('footer-text',
324319
splitCommas: true,
325320
help: 'paths to footer-text files '
326321
'(optional text next to the package name and version).');
327-
parser.addOption('exclude',
328-
allowMultiple: true, splitCommas: true, help: 'Library names to ignore.');
329-
parser.addOption('exclude-packages',
330-
allowMultiple: true, splitCommas: true, help: 'Package names to ignore.');
331-
parser.addOption('include',
332-
allowMultiple: true,
333-
splitCommas: true,
334-
help: 'Library names to generate docs for.');
335-
parser.addOption('include-external',
336-
allowMultiple: true,
322+
parser.addMultiOption('exclude',
323+
splitCommas: true, help: 'Library names to ignore.');
324+
parser.addMultiOption('exclude-packages',
325+
splitCommas: true, help: 'Package names to ignore.');
326+
parser.addMultiOption('include',
327+
splitCommas: true, help: 'Library names to generate docs for.');
328+
parser.addMultiOption('include-external',
337329
help: 'Additional (external) dart files to include; use "dir/fileName", '
338330
'as in lib/material.dart.');
339331
parser.addOption('hosted-url',
@@ -353,10 +345,9 @@ ArgParser _createArgsParser() {
353345
help: 'Group libraries from the same package into categories.',
354346
negatable: false,
355347
defaultsTo: false);
356-
parser.addOption('category-order',
348+
parser.addMultiOption('category-order',
357349
help: 'A list of category names to place first when --use-categories is '
358350
'set. Unmentioned categories are sorted after these.',
359-
allowMultiple: true,
360351
splitCommas: true);
361352
parser.addFlag('auto-include-dependencies',
362353
help:

lib/src/html/resource_loader.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
library dartdoc.resource_loader;
1212

1313
import 'dart:async' show Future;
14-
import 'dart:convert' show UTF8;
14+
import 'dart:convert' show utf8;
1515

1616
import 'package:resource/resource.dart';
1717

1818
/// Loads a `package:` resource as a String.
1919
Future<String> loadAsString(String path) async {
2020
var bytes = await loadAsBytes(path);
2121

22-
return UTF8.decode(bytes);
22+
return utf8.decode(bytes);
2323
}
2424

2525
/// Loads a `package:` resource as an [List<int>].

lib/src/io_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class SubprocessLauncher {
7777
assert(prefix != null);
7878
if (filter == null) filter = (line) => [line];
7979
stream
80-
.transform(UTF8.decoder)
80+
.transform(utf8.decoder)
8181
.transform(const LineSplitter())
8282
.expand(filter)
8383
.listen((String line) {

lib/src/markdown_processor.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ final RegExp notARealDocReference = new RegExp(r'''(^[^\w]|^[\d]|[,"'/]|^$)''');
140140

141141
final RegExp operatorPrefix = new RegExp(r'^operator[ ]*');
142142

143-
final HtmlEscape htmlEscape = const HtmlEscape(HtmlEscapeMode.ELEMENT);
143+
final HtmlEscape htmlEscape = const HtmlEscape(HtmlEscapeMode.element);
144144

145145
final List<md.InlineSyntax> _markdown_syntaxes = [
146146
new _InlineCodeSyntax(),
147147
new _AutolinkWithoutScheme()
148-
]..addAll(md.ExtensionSet.gitHub.inlineSyntaxes);
148+
]..addAll(md.ExtensionSet.gitHubFlavored.inlineSyntaxes);
149149

150150
final List<md.BlockSyntax> _markdown_block_syntaxes = []
151-
..addAll(md.ExtensionSet.gitHub.blockSyntaxes);
151+
..addAll(md.ExtensionSet.gitHubFlavored.blockSyntaxes);
152152

153153
// Remove these schemas from the display text for hyperlinks.
154154
final RegExp _hide_schemes = new RegExp('^(http|https)://');
@@ -735,7 +735,7 @@ String _linkDocReference(
735735
// This would be linkedElement.linkedName, but link bodies are slightly
736736
// different for doc references.
737737
if (linkedElement.href == null) {
738-
return '<code>${HTML_ESCAPE.convert(label)}</code>';
738+
return '<code>${htmlEscape.convert(label)}</code>';
739739
} else {
740740
return '<a ${classContent}href="${linkedElement.href}">$label</a>';
741741
}
@@ -744,7 +744,7 @@ String _linkDocReference(
744744
warnable.warn(PackageWarning.unresolvedDocReference,
745745
message: codeRef, referredFrom: warnable.documentationFrom);
746746
}
747-
return '<code>${HTML_ESCAPE.convert(label)}</code>';
747+
return '<code>${htmlEscape.convert(label)}</code>';
748748
}
749749
}
750750

@@ -992,7 +992,7 @@ class _InlineCodeSyntax extends md.InlineSyntax {
992992

993993
@override
994994
bool onMatch(md.InlineParser parser, Match match) {
995-
var element = new md.Element.text('code', HTML_ESCAPE.convert(match[1]));
995+
var element = new md.Element.text('code', htmlEscape.convert(match[1]));
996996
parser.addNode(element);
997997
return true;
998998
}

lib/src/model.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Map<String, Map<String, List<Map<String, dynamic>>>> get _crossdartJson {
6161
var crossdartFile =
6262
new File(p.join(config.inputDir.path, "crossdart.json"));
6363
if (crossdartFile.existsSync()) {
64-
__crossdartJson = JSON.decode(crossdartFile.readAsStringSync())
64+
__crossdartJson = json.decode(crossdartFile.readAsStringSync())
6565
as Map<String, Map<String, List<Map<String, dynamic>>>>;
6666
} else {
6767
__crossdartJson = {};
@@ -1543,7 +1543,7 @@ abstract class GetterSetterCombo implements ModelElement {
15431543

15441544
String _buildConstantValueBase() {
15451545
String result = constantInitializer?.toString() ?? '';
1546-
return const HtmlEscape(HtmlEscapeMode.UNKNOWN).convert(result);
1546+
return const HtmlEscape(HtmlEscapeMode.unknown).convert(result);
15471547
}
15481548

15491549
String get constantValue => linkifyConstantValue(constantValueBase);
@@ -3413,7 +3413,7 @@ abstract class ModelElement extends Canonicalization
34133413
if (isPublicAndPackageDocumented) {
34143414
warn(PackageWarning.noCanonicalFound);
34153415
}
3416-
return HTML_ESCAPE.convert(name);
3416+
return htmlEscape.convert(name);
34173417
}
34183418

34193419
var classContent = isDeprecated ? ' class="deprecated"' : '';

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,4 @@ packages:
408408
source: hosted
409409
version: "2.1.13"
410410
sdks:
411-
dart: ">=2.0.0-dev.23.0 <=2.0.0-dev.36.0"
411+
dart: ">=2.0.0-dev.23.0 <=2.0.0-dev.38.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ homepage: https://github.com/dart-lang/dartdoc
77
# For development, recommend 1.25.0-dev.0.0 or higher to allow
88
# dartanalyzer to work on dartdoc itself.
99
environment:
10-
sdk: '>=1.23.0-dev.11.5 <2.0.0'
10+
sdk: '>=2.0.0-dev.9.0 <3.0.0'
1111
dependencies:
1212
analyzer: '0.31.2-alpha.0'
1313
args: '>=0.13.0 <2.0.0'

test/compare_output_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void main() {
174174

175175
var jsonValues = LineSplitter
176176
.split(result.stdout)
177-
.map((j) => JSON.decode(j) as Map<String, dynamic>)
177+
.map((j) => json.decode(j) as Map<String, dynamic>)
178178
.toList();
179179

180180
expect(jsonValues, isNotEmpty,

test/model_test.dart

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,20 +1172,15 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
11721172
});
11731173

11741174
test('typedef params have proper signature', () {
1175-
// typedef void VoidCallback();
1176-
// void addCallback(VoidCallback callback) { }
11771175
ModelFunction function =
11781176
fakeLibrary.functions.firstWhere((f) => f.name == 'addCallback');
1179-
ElementType t = function.parameters.first.modelType;
11801177
String params = function.linkedParams();
11811178
expect(
11821179
params,
11831180
'<span class="parameter" id="addCallback-param-callback">'
11841181
'<span class="type-annotation"><a href="fake/VoidCallback.html">VoidCallback</a></span> '
11851182
'<span class="parameter-name">callback</span></span>');
11861183

1187-
// typedef int Callback2(String);
1188-
// void addCallback2(Callback2 callback) { }
11891184
function =
11901185
fakeLibrary.functions.firstWhere((f) => f.name == 'addCallback2');
11911186
params = function.linkedParams();
@@ -1216,7 +1211,6 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
12161211
.singleWhere((f) => f.name == 'explicitSetter');
12171212
// TODO(jcollins-g): really, these shouldn't be called "parameters" in
12181213
// the span class.
1219-
ElementType t = explicitSetter.modelType;
12201214
expect(explicitSetter.linkedReturnType,
12211215
'<span class="parameter" id="explicitSetter=-param-f"><span class="type-annotation">dynamic</span> <span class="parameter-name">Function</span>(<span class="parameter" id="f-param-bar"><span class="type-annotation">int</span>, </span> <span class="parameter" id="f-param-baz"><span class="type-annotation"><a href="fake/Cool-class.html">Cool</a></span>, </span> <span class="parameter" id="f-param-macTruck"><span class="type-annotation">List<span class="signature">&lt;int&gt;</span></span></span>)</span>');
12221216
});
@@ -1293,7 +1287,6 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
12931287
Method aTypedefReturningMethodInterface = TemplatedInterface
12941288
.allInstanceMethods
12951289
.singleWhere((m) => m.name == 'aTypedefReturningMethodInterface');
1296-
ElementType mt = aTypedefReturningMethodInterface.modelType;
12971290
expect(aTypedefReturningMethodInterface.linkedReturnType,
12981291
'<a href=\"ex/ParameterizedTypedef.html\">ParameterizedTypedef</a><span class="signature">&lt;List<span class="signature">&lt;String&gt;</span>&gt;</span>');
12991292
});
@@ -2234,13 +2227,17 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
22342227
fakeLibrary.classes.firstWhere((t) => t.name == 'TypedefUsingClass');
22352228
});
22362229

2237-
test('Typedefs with bound type parameters indirectly referred in parameters are displayed', () {
2230+
test(
2231+
'Typedefs with bound type parameters indirectly referred in parameters are displayed',
2232+
() {
22382233
Constructor theConstructor = TypedefUsingClass.constructors.first;
2239-
expect(theConstructor.linkedParams(), equals('<span class="parameter" id="-param-x"><span class="type-annotation"><a href="ex/ParameterizedTypedef.html">ParameterizedTypedef</a><span class="signature">&lt;double&gt;</span></span> <span class="parameter-name">x</span></span>'));
2234+
expect(
2235+
theConstructor.linkedParams(),
2236+
equals(
2237+
'<span class="parameter" id="-param-x"><span class="type-annotation"><a href="ex/ParameterizedTypedef.html">ParameterizedTypedef</a><span class="signature">&lt;double&gt;</span></span> <span class="parameter-name">x</span></span>'));
22402238
});
22412239

22422240
test('anonymous nested functions inside typedefs are handled', () {
2243-
ElementType t = aComplexTypedef.modelType;
22442241
expect(aComplexTypedef, isNotNull);
22452242
expect(aComplexTypedef.linkedReturnType, startsWith('Function'));
22462243
expect(aComplexTypedef.nameWithGenerics,
@@ -2371,13 +2368,11 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
23712368
});
23722369

23732370
test('typedef param is linked and does not include types', () {
2374-
ElementType t = methodWithTypedefParam.parameters.first.modelType;
23752371
var params = methodWithTypedefParam.linkedParams();
23762372
expect(
23772373
params,
23782374
equals(
23792375
'<span class="parameter" id="methodWithTypedefParam-param-p"><span class="type-annotation"><a href="ex/processMessage.html">processMessage</a></span> <span class="parameter-name">p</span></span>'));
2380-
//expect(params, contains('<a href="ex/processMessage.html">'));
23812376
});
23822377
});
23832378

testing/test_package/lib/fake.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,10 @@
4747
library fake;
4848

4949
import 'dart:async';
50-
5150
import 'dart:collection';
5251

53-
import 'example.dart';
54-
5552
import 'css.dart' as css;
56-
53+
import 'example.dart';
5754
import 'two_exports.dart' show BaseClass;
5855

5956
abstract class ImplementingThingy implements BaseThingy {}
@@ -224,6 +221,7 @@ typedef int LotsAndLotsOfParameters(so, many, parameters, it, should, wrap,
224221

225222
/// This class is cool!
226223
class Cool {
224+
// ignore: missing_return
227225
Cool returnCool() {}
228226
}
229227

@@ -258,7 +256,9 @@ class SuperAwesomeClass {
258256
///
259257
/// Another comment line.
260258
void fly(int height, Cool superCool, {String msg}) {
259+
// ignore: unused_local_variable, avoid_init_to_null
261260
var x = null;
261+
// ignore: unused_local_variable
262262
int i, y;
263263
for (int z = 0; z < 100; z++) {
264264
print('hi');
@@ -400,6 +400,7 @@ class ClassWithUnusualProperties extends ImplicitProperties {
400400
///
401401
/// The rest of this is not in the first paragraph.
402402
@Annotation('value')
403+
// ignore: deprecated_member_use
403404
class LongFirstLine extends SuperAwesomeClass
404405
with MixMeIn
405406
implements Interface, AnotherInterface {
@@ -649,14 +650,18 @@ class HasGenericWithExtends<T extends Foo2> {}
649650

650651
/// Extends [ListBase]
651652
class SpecialList<E> extends ListBase<E> {
653+
// ignore: annotate_overrides
652654
E operator [](int index) {
653655
return null;
654656
}
655657

658+
// ignore: annotate_overrides
656659
int get length => 0;
657660

661+
// ignore: annotate_overrides
658662
void set length(int length) {}
659663

664+
// ignore: annotate_overrides
660665
void operator []=(int index, E value) {}
661666
}
662667

@@ -676,6 +681,7 @@ class BaseForDocComments {
676681
///
677682
/// Reference to another method in this class [anotherMethod] xx
678683
///
684+
// ignore: deprecated_member_use
679685
/// Reference to a top-level function in this library [topLevelFunction] xx
680686
///
681687
/// Reference to a top-level function in another library that is imported into this library (example lib) [function1] xx
@@ -771,6 +777,7 @@ class ReferringClass {
771777
abstract class MIEEMixinWithOverride<K, V> = MIEEBase<K, V> with _MIEEPrivateOverride<K, V>;
772778

773779
abstract class _MIEEPrivateOverride<K, V> implements MIEEThing<K, V> {
780+
// ignore: annotate_overrides
774781
void operator[]=(K key, V value) {
775782
throw new UnsupportedError("Never use this");
776783
}
@@ -779,6 +786,7 @@ abstract class _MIEEPrivateOverride<K, V> implements MIEEThing<K, V> {
779786
abstract class MIEEBase<K, V> extends MIEEMixin<K, V> {}
780787

781788
abstract class MIEEMixin<K, V> implements MIEEThing<K, V> {
789+
// ignore: annotate_overrides
782790
operator []=(K key, V value);
783791
}
784792

tool/doc_packages.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
library dartdoc.doc_packages;
77

88
import 'dart:async';
9-
import 'dart:convert' show JSON, UTF8;
9+
import 'dart:convert' show json, utf8;
1010
import 'dart:io';
1111

1212
import 'package:args/args.dart';
@@ -125,17 +125,17 @@ Future<List<String>> _packageUrls(int page) {
125125
return http
126126
.get('https://pub.dartlang.org/packages.json?page=${page}')
127127
.then((response) {
128-
return new List<String>.from(JSON.decode(response.body)['packages']);
128+
return new List<String>.from(json.decode(response.body)['packages']);
129129
});
130130
}
131131

132132
Future<List<PackageInfo>> _getPackageInfos(List<String> packageUrls) {
133133
var futures = packageUrls.map((String p) {
134134
return http.get(p).then((response) {
135-
var json = JSON.decode(response.body);
136-
String name = json['name'];
135+
var decodedJson = json.decode(response.body);
136+
String name = decodedJson['name'];
137137
List<Version> versions = new List<Version>.from(
138-
json['versions'].map((v) => new Version.parse(v)));
138+
decodedJson['versions'].map((v) => new Version.parse(v)));
139139
return new PackageInfo(name, Version.primary(versions));
140140
});
141141
}).toList();
@@ -200,8 +200,8 @@ Future _exec(String command, List<String> args,
200200
.start(command, args, workingDirectory: cwd)
201201
.then((Process process) {
202202
if (!quiet) {
203-
process.stdout.listen((bytes) => _log(UTF8.decode(bytes)));
204-
process.stderr.listen((bytes) => _log(UTF8.decode(bytes)));
203+
process.stdout.listen((bytes) => _log(utf8.decode(bytes)));
204+
process.stderr.listen((bytes) => _log(utf8.decode(bytes)));
205205
}
206206

207207
Future f = process.exitCode.then((code) {

0 commit comments

Comments
 (0)