Skip to content

Commit 3931595

Browse files
authored
enable additional lints (#3336)
1 parent a52639e commit 3931595

17 files changed

+53
-33
lines changed

analysis_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ linter:
1919
- always_declare_return_types
2020
- always_put_required_named_parameters_first
2121
- avoid_bool_literals_in_conditional_expressions
22+
- avoid_catching_errors
2223
- avoid_dynamic_calls
2324
- avoid_slow_async_io
2425
- avoid_unused_constructor_parameters
2526
- directives_ordering
2627
- no_adjacent_strings_in_list
2728
- omit_local_variable_types
29+
- only_throw_errors
2830
- package_api_docs
2931
- prefer_asserts_in_initializer_lists
3032
- prefer_null_aware_method_calls
@@ -35,4 +37,5 @@ linter:
3537
- unawaited_futures
3638
- unnecessary_lambdas
3739
- unnecessary_parenthesis
40+
- unnecessary_statements
3841
- use_super_parameters

lib/src/failure.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
///
77
/// An instance of this is returned if dartdoc fails in an expected way (for
88
/// instance, if there is an analysis error in the library).
9-
class DartdocFailure {
9+
class DartdocFailure implements Exception {
1010
final String message;
1111

1212
DartdocFailure(this.message);

lib/src/model/extendable.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import 'package:dartdoc/src/model/model.dart';
88
/// extension methods.
99
mixin Extendable on ContainerMember {
1010
/// Returns this Extendable from the [Extension] in which it was declared.
11-
Extendable get definingExtension => throw UnimplementedError;
11+
Extendable get definingExtension =>
12+
throw UnimplementedError('definingExtension');
1213

1314
@override
14-
Container get canonicalEnclosingContainer => throw UnimplementedError;
15+
Container get canonicalEnclosingContainer =>
16+
throw UnimplementedError('canonicalEnclosingContainer');
1517
}

lib/src/model/package_builder.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ class PubPackageBuilder implements PackageBuilder {
444444
.difference(Set.of(knownLibraryNames))
445445
.difference(config.exclude);
446446
if (notFound.isNotEmpty) {
447-
throw 'Did not find: [${notFound.join(', ')}] in '
448-
'known libraries: [${knownLibraryNames.join(', ')}]';
447+
throw StateError('Did not find: [${notFound.join(', ')}] in '
448+
'known libraries: [${knownLibraryNames.join(', ')}]');
449449
}
450450
}
451451
// Include directive does not apply to special libraries.

lib/src/model/package_graph.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,19 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
215215
///
216216
/// This mapping must be complete before [initializePackageGraph] is called.
217217
@visibleForTesting
218-
final allLibraries = <String, Library>{};
218+
final Map<String, Library> allLibraries = {};
219219

220220
/// All [ModelElement]s constructed for this package; a superset of
221221
/// [_allModelElements].
222-
final HashMap<Tuple3<Element, Library, Container?>, ModelElement?>
223-
allConstructedModelElements =
224-
HashMap<Tuple3<Element, Library, Container?>, ModelElement?>();
222+
final Map<Tuple3<Element, Library, Container?>, ModelElement?>
223+
allConstructedModelElements = {};
225224

226225
/// Anything that might be inheritable, place here for later lookup.
227-
final allInheritableElements =
228-
HashMap<Tuple2<Element, Library>, Set<ModelElement>>();
226+
final Map<Tuple2<Element, Library>, Set<ModelElement>>
227+
allInheritableElements = {};
229228

230229
/// A mapping of the list of classes which implement each class.
231-
final _implementors =
230+
final Map<InheritingContainer, List<InheritingContainer>> _implementors =
232231
LinkedHashMap<InheritingContainer, List<InheritingContainer>>(
233232
equals: (InheritingContainer a, InheritingContainer b) =>
234233
a.definingContainer == b.definingContainer,
@@ -857,7 +856,8 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
857856
// might not be where the element was defined, which is what's important
858857
// for nodoc's semantics. Looking up the defining element just to pull
859858
// a context is again, slow.
860-
var globs = config.optionSet['nodoc'].valueAt(file.parent);
859+
var globs = (config.optionSet['nodoc'].valueAt(file.parent) as List)
860+
.cast<String>();
861861
return utils.matchGlobs(globs, fullName);
862862
});
863863
}

lib/src/mustachio/renderer_base.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ abstract class RendererBase<T extends Object?> {
189189
if (property != null) {
190190
try {
191191
return property.renderVariable(context, property, remainingNames);
192+
// ignore: avoid_catching_errors
192193
} on PartialMustachioResolutionError catch (e) {
193194
// The error thrown by [Property.renderVariable] does not have all of
194195
// the names required for a decent error. We throw a new error here.
@@ -199,6 +200,7 @@ abstract class RendererBase<T extends Object?> {
199200
"'$firstName' to a property on $T"));
200201
}
201202
}
203+
// ignore: avoid_catching_errors
202204
} on _MustachioResolutionErrorWithoutSpan catch (e) {
203205
throw MustachioResolutionError(node.keySpan.message(e.message));
204206
}

lib/src/package_meta.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class _FilePackageMeta extends PubPackageMeta {
310310
late final Map<dynamic, dynamic> _pubspec = () {
311311
var pubspec = dir.getChildAssumingFile('pubspec.yaml');
312312
assert(pubspec.exists);
313-
return loadYaml(pubspec.readAsStringSync());
313+
return loadYaml(pubspec.readAsStringSync()) as YamlMap;
314314
}();
315315

316316
_FilePackageMeta(super.dir, super.resourceProvider);

lib/src/tool_runner.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ToolRunner {
108108
'Stderr output was:\n${result.stderr}\n');
109109
return '';
110110
} else {
111-
return result.stdout;
111+
return result.stdout as String;
112112
}
113113
} on ProcessException catch (exception) {
114114
toolErrorCallback('Failed to run tool "$name" as '

lib/src/validator.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ class Validator {
153153
// The package index isn't supposed to be in the search, so suppress the
154154
// warning.
155155
found.add(indexPath);
156-
for (Map<String, dynamic> entry in jsonData) {
156+
for (var entry in jsonData.cast<Map<String, dynamic>>()) {
157157
if (entry.containsKey('href')) {
158-
final entryPath = p.joinAll([_origin, ...p.posix.split(entry['href'])]);
158+
final entryPath =
159+
p.joinAll([_origin, ...p.posix.split(entry['href'] as String)]);
159160
if (!_visited.contains(entryPath)) {
160161
_warn(PackageWarning.brokenLink, entryPath, _origin,
161162
referredFrom: fullPath);

test/mustachio/renderers_output_test.dart

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
library dartdoc.dartdoc_test;
66

77
import 'dart:async';
8+
import 'dart:io';
89

910
import 'package:analyzer/file_system/file_system.dart';
1011
import 'package:analyzer/file_system/memory_file_system.dart';
@@ -25,26 +26,35 @@ import 'package:test/test.dart';
2526
Future<DartdocGeneratorOptionContext> _generatorContextFromArgv(
2627
List<String> argv) async {
2728
var optionSet = DartdocOptionRoot.fromOptionGenerators(
28-
'dartdoc',
29-
[
30-
createDartdocOptions,
31-
createGeneratorOptions,
32-
],
33-
pubPackageMetaProvider);
29+
'dartdoc',
30+
[
31+
createDartdocOptions,
32+
createGeneratorOptions,
33+
],
34+
pubPackageMetaProvider,
35+
);
3436
optionSet.parseArguments(argv);
3537
return DartdocGeneratorOptionContext.fromDefaultContextLocation(
3638
optionSet, pubPackageMetaProvider.resourceProvider);
3739
}
3840

3941
void main() {
42+
late Directory tempDir;
43+
44+
setUp(() {
45+
tempDir = Directory.systemTemp.createTempSync('render_test');
46+
});
47+
48+
tearDown(() => tempDir.deleteSync(recursive: true));
49+
4050
test('source code links are visible', () async {
4151
var resourceProvider = pubPackageMetaProvider.resourceProvider;
4252
var pathContext = resourceProvider.pathContext;
4353
var testPackageDir = resourceProvider.getFolder(
4454
pathContext.absolute(pathContext.canonicalize('testing/test_package')));
4555

4656
var context = await _generatorContextFromArgv(
47-
['--input', testPackageDir.path, '--output', 'UNUSED']);
57+
['--input', testPackageDir.path, '--output', tempDir.path]);
4858
var dartdoc = await Dartdoc.fromContext(
4959
context,
5060
PubPackageBuilder(

0 commit comments

Comments
 (0)