Skip to content

Commit af7fc0e

Browse files
authored
use the package:pedantic analysis options (#1951)
1 parent 2751ba5 commit af7fc0e

12 files changed

+39
-33
lines changed

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include: package:pedantic/analysis_options.yaml
2+
13
analyzer:
24
exclude:
35
- 'doc/**'

lib/src/dartdoc_options.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ abstract class DartdocOption<T> {
657657
}
658658

659659
/// Apply the function [visit] to [this] and all children.
660-
void traverse(void visit(DartdocOption)) {
660+
void traverse(void visit(DartdocOption option)) {
661661
visit(this);
662662
_children.values.forEach((d) => d.traverse(visit));
663663
}
@@ -832,7 +832,7 @@ class DartdocOptionSet extends DartdocOption<Null> {
832832

833833
/// Traverse skips this node, because it doesn't represent a real configuration object.
834834
@override
835-
void traverse(void visitor(DartdocOption)) {
835+
void traverse(void visitor(DartdocOption option)) {
836836
_children.values.forEach((d) => d.traverse(visitor));
837837
}
838838
}
@@ -884,12 +884,12 @@ class DartdocOptionArgFile<T> extends DartdocOption<T>
884884
DartdocOptionArgFile(String name, T defaultsTo,
885885
{String abbr,
886886
bool mustExist = false,
887-
String help: '',
887+
String help = '',
888888
bool hide = false,
889889
bool isDir = false,
890890
bool isFile = false,
891891
bool negatable = false,
892-
bool parentDirOverridesChild: false,
892+
bool parentDirOverridesChild = false,
893893
bool splitCommas})
894894
: super(name, defaultsTo, help, isDir, isFile, mustExist, null) {
895895
_abbr = abbr;
@@ -936,10 +936,10 @@ class DartdocOptionFileOnly<T> extends DartdocOption<T>
936936
bool _parentDirOverridesChild;
937937
DartdocOptionFileOnly(String name, T defaultsTo,
938938
{bool mustExist = false,
939-
String help: '',
939+
String help = '',
940940
bool isDir = false,
941941
bool isFile = false,
942-
bool parentDirOverridesChild: false,
942+
bool parentDirOverridesChild = false,
943943
T Function(YamlMap, pathLib.Context) convertYamlToType})
944944
: super(name, defaultsTo, help, isDir, isFile, mustExist,
945945
convertYamlToType) {

lib/src/element_type.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class GenericTypeAliasElementType extends TypeParameterElementType
318318
with GenericTypeAliasElementTypeMixin {
319319
GenericTypeAliasElementType(TypeParameterType t, PackageGraph packageGraph,
320320
ModelElement element, ElementType returnedFrom)
321-
: super(t, packageGraph, element, returnedFrom) {}
321+
: super(t, packageGraph, element, returnedFrom);
322322
}
323323

324324
/// A Callable generic type alias that may or may not have a name.

lib/src/html/html_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class HtmlGeneratorOptions implements HtmlOptions {
128128
this.relCanonicalPrefix,
129129
this.faviconPath,
130130
String toolVersion,
131-
this.prettyIndexJson: false})
131+
this.prettyIndexJson = false})
132132
: this.toolVersion = toolVersion ?? 'unknown';
133133
}
134134

lib/src/io_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ String resolveTildePath(String originalPath) {
3636
///
3737
/// The returned paths are guaranteed to begin with [dir].
3838
Iterable<String> listDir(String dir,
39-
{bool recursive: false,
39+
{bool recursive = false,
4040
Iterable<FileSystemEntity> listDir(Directory dir)}) {
4141
if (listDir == null) listDir = (Directory dir) => dir.listSync();
4242

lib/src/markdown_processor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ final RegExp _hide_schemes = new RegExp('^(http|https)://');
153153
class MatchingLinkResult {
154154
final ModelElement element;
155155
final bool warn;
156-
MatchingLinkResult(this.element, {this.warn: true});
156+
MatchingLinkResult(this.element, {this.warn = true});
157157
}
158158

159159
class IterableBlockParser extends md.BlockParser {
@@ -933,7 +933,7 @@ class MarkdownDocument extends md.Document {
933933

934934
class Documentation {
935935
final Canonicalization _element;
936-
Documentation.forElement(this._element) {}
936+
Documentation.forElement(this._element);
937937

938938
bool _hasExtendedDocs;
939939
bool get hasExtendedDocs {

lib/src/model.dart

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import 'package:analyzer/src/dart/sdk/sdk.dart';
3838
import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult;
3939
import 'package:analyzer/src/generated/java_io.dart';
4040
import 'package:analyzer/src/generated/resolver.dart'
41-
show Namespace, NamespaceBuilder, InheritanceManager;
41+
show Namespace, NamespaceBuilder, InheritanceManager; // ignore: deprecated_member_use
4242
import 'package:analyzer/src/generated/sdk.dart';
4343
import 'package:analyzer/src/generated/source.dart';
4444
import 'package:analyzer/src/generated/source_io.dart';
@@ -1043,9 +1043,9 @@ class Class extends ModelElement
10431043
List<ExecutableElement> get _inheritedElements {
10441044
if (__inheritedElements == null) {
10451045
Map<String, ExecutableElement> cmap = definingLibrary.inheritanceManager
1046-
.getMembersInheritedFromClasses(element);
1046+
.getMembersInheritedFromClasses(element); // ignore: deprecated_member_use
10471047
Map<String, ExecutableElement> imap = definingLibrary.inheritanceManager
1048-
.getMembersInheritedFromInterfaces(element);
1048+
.getMembersInheritedFromInterfaces(element); // ignore: deprecated_member_use
10491049
__inheritedElements = new List.from(cmap.values)
10501050
..addAll(imap.values.where((e) => !cmap.containsKey(e.name)));
10511051
}
@@ -1515,15 +1515,15 @@ abstract class Canonicalization implements Locatable, Documentable {
15151515
// Penalty for deprecated libraries.
15161516
if (lib.isDeprecated) scoredCandidate.alterScore(-1.0, 'is deprecated');
15171517
// Give a big boost if the library has the package name embedded in it.
1518-
if (lib.package.namePieces.intersection(lib.namePieces).length > 0) {
1518+
if (lib.package.namePieces.intersection(lib.namePieces).isEmpty) {
15191519
scoredCandidate.alterScore(1.0, 'embeds package name');
15201520
}
15211521
// Give a tiny boost for libraries with long names, assuming they're
15221522
// more specific (and therefore more likely to be the owner of this symbol).
15231523
scoredCandidate.alterScore(.01 * lib.namePieces.length, 'name is long');
15241524
// If we don't know the location of this element, return our best guess.
15251525
// TODO(jcollins-g): is that even possible?
1526-
assert(!locationPieces.isEmpty);
1526+
assert(locationPieces.isNotEmpty);
15271527
if (locationPieces.isEmpty) return scoredCandidate;
15281528
// The more pieces we have of the location in our library name, the more we should boost our score.
15291529
scoredCandidate.alterScore(
@@ -1928,7 +1928,7 @@ abstract class GetterSetterCombo implements ModelElement {
19281928
} else if (hasPublicSetter) {
19291929
_documentationFrom.addAll(setter.documentationFrom);
19301930
}
1931-
if (_documentationFrom.length == 0 ||
1931+
if (_documentationFrom.isEmpty||
19321932
_documentationFrom.every((e) => e.documentationComment == ''))
19331933
_documentationFrom = computeDocumentationFrom;
19341934
}
@@ -2376,9 +2376,12 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
23762376
return '${package.baseHref}${library.dirName}/$fileName';
23772377
}
23782378

2379+
// ignore: deprecated_member_use
23792380
InheritanceManager _inheritanceManager;
2381+
// ignore: deprecated_member_use
23802382
InheritanceManager get inheritanceManager {
23812383
if (_inheritanceManager == null) {
2384+
// ignore: deprecated_member_use
23822385
_inheritanceManager = new InheritanceManager(element);
23832386
}
23842387
return _inheritanceManager;
@@ -3363,7 +3366,7 @@ abstract class ModelElement extends Canonicalization
33633366
// Avoid claiming canonicalization for elements outside of this element's
33643367
// defining package.
33653368
// TODO(jcollins-g): Make the else block unconditional.
3366-
if (!candidateLibraries.isEmpty &&
3369+
if (candidateLibraries.isNotEmpty &&
33673370
!candidateLibraries
33683371
.any((l) => l.package == definingLibrary.package)) {
33693372
warn(PackageWarning.reexportedPrivateApiAcrossPackages,
@@ -3814,7 +3817,7 @@ abstract class ModelElement extends Canonicalization
38143817
}
38153818

38163819
String linkedParams(
3817-
{bool showMetadata: true, bool showNames: true, String separator: ', '}) {
3820+
{bool showMetadata = true, bool showNames = true, String separator = ', '}) {
38183821
List<Parameter> requiredParams =
38193822
parameters.where((Parameter p) => !p.isOptional).toList();
38203823
List<Parameter> positionalParams =
@@ -3886,7 +3889,7 @@ abstract class ModelElement extends Canonicalization
38863889
String _calculateLinkedName() {
38873890
// If we're calling this with an empty name, we probably have the wrong
38883891
// element associated with a ModelElement or there's an analysis bug.
3889-
assert(!name.isEmpty ||
3892+
assert(name.isNotEmpty ||
38903893
(this.element is TypeDefiningElement &&
38913894
(this.element as TypeDefiningElement).type.name == "dynamic") ||
38923895
this is ModelFunction);
@@ -3935,7 +3938,7 @@ abstract class ModelElement extends Canonicalization
39353938
var fragmentFile = new File(pathLib.join(dirPath, args['file']));
39363939
if (fragmentFile.existsSync()) {
39373940
replacement = fragmentFile.readAsStringSync();
3938-
if (!lang.isEmpty) {
3941+
if (lang.isNotEmpty) {
39393942
replacement = replacement.replaceFirst('```', '```$lang');
39403943
}
39413944
} else {
@@ -4517,7 +4520,7 @@ abstract class ModelElement extends Canonicalization
45174520
final fragExtension = '.md';
45184521
var file = src + fragExtension;
45194522
var region = args['region'] ?? '';
4520-
if (!region.isEmpty) {
4523+
if (region.isNotEmpty) {
45214524
var dir = pathLib.dirname(src);
45224525
var basename = pathLib.basenameWithoutExtension(src);
45234526
var ext = pathLib.extension(src);
@@ -5241,15 +5244,15 @@ class PackageGraph {
52415244
}
52425245
}
52435246

5244-
if (!c._mixins.isEmpty) {
5247+
if (c._mixins.isNotEmpty) {
52455248
c._mixins.forEach((t) {
52465249
_checkAndAddClass(t.element, c);
52475250
});
52485251
}
52495252
if (c.supertype != null) {
52505253
_checkAndAddClass(c.supertype.element, c);
52515254
}
5252-
if (!c.interfaces.isEmpty) {
5255+
if (c.interfaces.isNotEmpty) {
52535256
c.interfaces.forEach((t) {
52545257
_checkAndAddClass(t.element, c);
52555258
});
@@ -6551,7 +6554,7 @@ class PackageBuilder {
65516554
final UriResolver packageResolver = new PackageMapUriResolver(
65526555
PhysicalResourceProvider.INSTANCE, packageMap);
65536556
UriResolver sdkResolver;
6554-
if (embedderSdk == null || embedderSdk.urlMappings.length == 0) {
6557+
if (embedderSdk == null || embedderSdk.urlMappings.isEmpty) {
65556558
// The embedder uri resolver has no mappings. Use the default Dart SDK
65566559
// uri resolver.
65576560
sdkResolver = new DartUriResolver(sdk);

lib/src/special_elements.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Set<String> specialLibraryFiles(DartSdk sdk) => _specialClassDefinitions.values
8787
class SpecialClasses {
8888
final Map<SpecialClass, Class> _specialClass = {};
8989

90-
SpecialClasses() {}
90+
SpecialClasses();
9191

9292
/// Add a class object that could be special.
9393
void addSpecial(Class aClass) {

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dev_dependencies:
3939
io: ^0.3.0
4040
http: ^0.12.0
4141
meta: ^1.0.0
42+
pedantic: ^1.5.0
4243
test: ^1.3.0
4344

4445
executables:

test/src/utils.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class SubprocessLauncher {
242242

243243
// from flutter:dev/tools/dartdoc.dart, modified
244244
static Future<void> _printStream(Stream<List<int>> stream, Stdout output,
245-
{String prefix: '', Iterable<String> Function(String line) filter}) {
245+
{String prefix = '', Iterable<String> Function(String line) filter}) {
246246
assert(prefix != null);
247247
if (filter == null) filter = (line) => [line];
248248
return stream
@@ -273,7 +273,7 @@ class SubprocessLauncher {
273273
Future<Iterable<Map>> runStreamed(String executable, List<String> arguments,
274274
{String workingDirectory,
275275
Map<String, String> environment,
276-
bool includeParentEnvironment: true,
276+
bool includeParentEnvironment = true,
277277
void Function(String) perLine}) async {
278278
environment ??= {};
279279
environment.addAll(environmentDefaults);

tool/doc_packages.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ArgParser _createArgsParser() {
6060
}
6161

6262
/// Print help if we are passed the help option or invalid arguments.
63-
void _printUsageAndExit(ArgParser parser, {int exitCode: 0}) {
63+
void _printUsageAndExit(ArgParser parser, {int exitCode = 0}) {
6464
print('Generate documentation for published pub packages.\n');
6565
print('Usage: _doc_packages [OPTIONS] <package1> <package2>\n');
6666
print(parser.usage);
@@ -194,8 +194,8 @@ Future<bool> _generateFor(PackageInfo package) async {
194194

195195
Future _exec(String command, List<String> args,
196196
{String cwd,
197-
bool quiet: false,
198-
Duration timeout: const Duration(seconds: 60)}) {
197+
bool quiet = false,
198+
Duration timeout = const Duration(seconds: 60)}) {
199199
return Process.start(command, args, workingDirectory: cwd)
200200
.then((Process process) {
201201
if (!quiet) {

tool/grind.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class WarningsCollection {
237237
final String branch;
238238
final String pubCachePath;
239239
WarningsCollection(this.tempDir, this.pubCachePath, this.branch)
240-
: this.warningKeyCounts = new Map() {}
240+
: this.warningKeyCounts = new Map();
241241

242242
static const String kPubCachePathReplacement = '_xxxPubDirectoryxxx_';
243243
static const String kTempDirReplacement = '_xxxTempDirectoryxxx_';
@@ -943,7 +943,7 @@ Future<void> buildDartdocFlutterPluginDocs() async {
943943
@Task('Verify docs for a package that requires flutter with remote linking')
944944
Future<void> testDartdocFlutterPlugin() async {
945945
WarningsCollection warnings = await _buildDartdocFlutterPluginDocs();
946-
if (!warnings.warningKeyCounts.isEmpty) {
946+
if (warnings.warningKeyCounts.isNotEmpty) {
947947
fail('No warnings should exist in : ${warnings.warningKeyCounts}');
948948
}
949949
// Verify that links to Dart SDK and Flutter SDK go to the flutter site.

0 commit comments

Comments
 (0)