Skip to content

use the package:pedantic analysis options #1951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include: package:pedantic/analysis_options.yaml

analyzer:
exclude:
- 'doc/**'
Expand Down
12 changes: 6 additions & 6 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ abstract class DartdocOption<T> {
}

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

/// Traverse skips this node, because it doesn't represent a real configuration object.
@override
void traverse(void visitor(DartdocOption)) {
void traverse(void visitor(DartdocOption option)) {
_children.values.forEach((d) => d.traverse(visitor));
}
}
Expand Down Expand Up @@ -884,12 +884,12 @@ class DartdocOptionArgFile<T> extends DartdocOption<T>
DartdocOptionArgFile(String name, T defaultsTo,
{String abbr,
bool mustExist = false,
String help: '',
String help = '',
bool hide = false,
bool isDir = false,
bool isFile = false,
bool negatable = false,
bool parentDirOverridesChild: false,
bool parentDirOverridesChild = false,
bool splitCommas})
: super(name, defaultsTo, help, isDir, isFile, mustExist, null) {
_abbr = abbr;
Expand Down Expand Up @@ -936,10 +936,10 @@ class DartdocOptionFileOnly<T> extends DartdocOption<T>
bool _parentDirOverridesChild;
DartdocOptionFileOnly(String name, T defaultsTo,
{bool mustExist = false,
String help: '',
String help = '',
bool isDir = false,
bool isFile = false,
bool parentDirOverridesChild: false,
bool parentDirOverridesChild = false,
T Function(YamlMap, pathLib.Context) convertYamlToType})
: super(name, defaultsTo, help, isDir, isFile, mustExist,
convertYamlToType) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class GenericTypeAliasElementType extends TypeParameterElementType
with GenericTypeAliasElementTypeMixin {
GenericTypeAliasElementType(TypeParameterType t, PackageGraph packageGraph,
ModelElement element, ElementType returnedFrom)
: super(t, packageGraph, element, returnedFrom) {}
: super(t, packageGraph, element, returnedFrom);
}

/// A Callable generic type alias that may or may not have a name.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/html/html_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class HtmlGeneratorOptions implements HtmlOptions {
this.relCanonicalPrefix,
this.faviconPath,
String toolVersion,
this.prettyIndexJson: false})
this.prettyIndexJson = false})
: this.toolVersion = toolVersion ?? 'unknown';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/io_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ String resolveTildePath(String originalPath) {
///
/// The returned paths are guaranteed to begin with [dir].
Iterable<String> listDir(String dir,
{bool recursive: false,
{bool recursive = false,
Iterable<FileSystemEntity> listDir(Directory dir)}) {
if (listDir == null) listDir = (Directory dir) => dir.listSync();

Expand Down
4 changes: 2 additions & 2 deletions lib/src/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ final RegExp _hide_schemes = new RegExp('^(http|https)://');
class MatchingLinkResult {
final ModelElement element;
final bool warn;
MatchingLinkResult(this.element, {this.warn: true});
MatchingLinkResult(this.element, {this.warn = true});
}

class IterableBlockParser extends md.BlockParser {
Expand Down Expand Up @@ -933,7 +933,7 @@ class MarkdownDocument extends md.Document {

class Documentation {
final Canonicalization _element;
Documentation.forElement(this._element) {}
Documentation.forElement(this._element);

bool _hasExtendedDocs;
bool get hasExtendedDocs {
Expand Down
31 changes: 17 additions & 14 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import 'package:analyzer/src/dart/sdk/sdk.dart';
import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult;
import 'package:analyzer/src/generated/java_io.dart';
import 'package:analyzer/src/generated/resolver.dart'
show Namespace, NamespaceBuilder, InheritanceManager;
show Namespace, NamespaceBuilder, InheritanceManager; // ignore: deprecated_member_use
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/source_io.dart';
Expand Down Expand Up @@ -1043,9 +1043,9 @@ class Class extends ModelElement
List<ExecutableElement> get _inheritedElements {
if (__inheritedElements == null) {
Map<String, ExecutableElement> cmap = definingLibrary.inheritanceManager
.getMembersInheritedFromClasses(element);
.getMembersInheritedFromClasses(element); // ignore: deprecated_member_use
Map<String, ExecutableElement> imap = definingLibrary.inheritanceManager
.getMembersInheritedFromInterfaces(element);
.getMembersInheritedFromInterfaces(element); // ignore: deprecated_member_use
__inheritedElements = new List.from(cmap.values)
..addAll(imap.values.where((e) => !cmap.containsKey(e.name)));
}
Expand Down Expand Up @@ -1515,15 +1515,15 @@ abstract class Canonicalization implements Locatable, Documentable {
// Penalty for deprecated libraries.
if (lib.isDeprecated) scoredCandidate.alterScore(-1.0, 'is deprecated');
// Give a big boost if the library has the package name embedded in it.
if (lib.package.namePieces.intersection(lib.namePieces).length > 0) {
if (lib.package.namePieces.intersection(lib.namePieces).isEmpty) {
scoredCandidate.alterScore(1.0, 'embeds package name');
}
// Give a tiny boost for libraries with long names, assuming they're
// more specific (and therefore more likely to be the owner of this symbol).
scoredCandidate.alterScore(.01 * lib.namePieces.length, 'name is long');
// If we don't know the location of this element, return our best guess.
// TODO(jcollins-g): is that even possible?
assert(!locationPieces.isEmpty);
assert(locationPieces.isNotEmpty);
if (locationPieces.isEmpty) return scoredCandidate;
// The more pieces we have of the location in our library name, the more we should boost our score.
scoredCandidate.alterScore(
Expand Down Expand Up @@ -1928,7 +1928,7 @@ abstract class GetterSetterCombo implements ModelElement {
} else if (hasPublicSetter) {
_documentationFrom.addAll(setter.documentationFrom);
}
if (_documentationFrom.length == 0 ||
if (_documentationFrom.isEmpty||
_documentationFrom.every((e) => e.documentationComment == ''))
_documentationFrom = computeDocumentationFrom;
}
Expand Down Expand Up @@ -2376,9 +2376,12 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
return '${package.baseHref}${library.dirName}/$fileName';
}

// ignore: deprecated_member_use
InheritanceManager _inheritanceManager;
// ignore: deprecated_member_use
InheritanceManager get inheritanceManager {
if (_inheritanceManager == null) {
// ignore: deprecated_member_use
_inheritanceManager = new InheritanceManager(element);
}
return _inheritanceManager;
Expand Down Expand Up @@ -3363,7 +3366,7 @@ abstract class ModelElement extends Canonicalization
// Avoid claiming canonicalization for elements outside of this element's
// defining package.
// TODO(jcollins-g): Make the else block unconditional.
if (!candidateLibraries.isEmpty &&
if (candidateLibraries.isNotEmpty &&
!candidateLibraries
.any((l) => l.package == definingLibrary.package)) {
warn(PackageWarning.reexportedPrivateApiAcrossPackages,
Expand Down Expand Up @@ -3814,7 +3817,7 @@ abstract class ModelElement extends Canonicalization
}

String linkedParams(
{bool showMetadata: true, bool showNames: true, String separator: ', '}) {
{bool showMetadata = true, bool showNames = true, String separator = ', '}) {
List<Parameter> requiredParams =
parameters.where((Parameter p) => !p.isOptional).toList();
List<Parameter> positionalParams =
Expand Down Expand Up @@ -3886,7 +3889,7 @@ abstract class ModelElement extends Canonicalization
String _calculateLinkedName() {
// If we're calling this with an empty name, we probably have the wrong
// element associated with a ModelElement or there's an analysis bug.
assert(!name.isEmpty ||
assert(name.isNotEmpty ||
(this.element is TypeDefiningElement &&
(this.element as TypeDefiningElement).type.name == "dynamic") ||
this is ModelFunction);
Expand Down Expand Up @@ -3935,7 +3938,7 @@ abstract class ModelElement extends Canonicalization
var fragmentFile = new File(pathLib.join(dirPath, args['file']));
if (fragmentFile.existsSync()) {
replacement = fragmentFile.readAsStringSync();
if (!lang.isEmpty) {
if (lang.isNotEmpty) {
replacement = replacement.replaceFirst('```', '```$lang');
}
} else {
Expand Down Expand Up @@ -4517,7 +4520,7 @@ abstract class ModelElement extends Canonicalization
final fragExtension = '.md';
var file = src + fragExtension;
var region = args['region'] ?? '';
if (!region.isEmpty) {
if (region.isNotEmpty) {
var dir = pathLib.dirname(src);
var basename = pathLib.basenameWithoutExtension(src);
var ext = pathLib.extension(src);
Expand Down Expand Up @@ -5241,15 +5244,15 @@ class PackageGraph {
}
}

if (!c._mixins.isEmpty) {
if (c._mixins.isNotEmpty) {
c._mixins.forEach((t) {
_checkAndAddClass(t.element, c);
});
}
if (c.supertype != null) {
_checkAndAddClass(c.supertype.element, c);
}
if (!c.interfaces.isEmpty) {
if (c.interfaces.isNotEmpty) {
c.interfaces.forEach((t) {
_checkAndAddClass(t.element, c);
});
Expand Down Expand Up @@ -6551,7 +6554,7 @@ class PackageBuilder {
final UriResolver packageResolver = new PackageMapUriResolver(
PhysicalResourceProvider.INSTANCE, packageMap);
UriResolver sdkResolver;
if (embedderSdk == null || embedderSdk.urlMappings.length == 0) {
if (embedderSdk == null || embedderSdk.urlMappings.isEmpty) {
// The embedder uri resolver has no mappings. Use the default Dart SDK
// uri resolver.
sdkResolver = new DartUriResolver(sdk);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/special_elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Set<String> specialLibraryFiles(DartSdk sdk) => _specialClassDefinitions.values
class SpecialClasses {
final Map<SpecialClass, Class> _specialClass = {};

SpecialClasses() {}
SpecialClasses();

/// Add a class object that could be special.
void addSpecial(Class aClass) {
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dev_dependencies:
io: ^0.3.0
http: ^0.12.0
meta: ^1.0.0
pedantic: ^1.5.0
test: ^1.3.0

executables:
Expand Down
4 changes: 2 additions & 2 deletions test/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class SubprocessLauncher {

// from flutter:dev/tools/dartdoc.dart, modified
static Future<void> _printStream(Stream<List<int>> stream, Stdout output,
{String prefix: '', Iterable<String> Function(String line) filter}) {
{String prefix = '', Iterable<String> Function(String line) filter}) {
assert(prefix != null);
if (filter == null) filter = (line) => [line];
return stream
Expand Down Expand Up @@ -273,7 +273,7 @@ class SubprocessLauncher {
Future<Iterable<Map>> runStreamed(String executable, List<String> arguments,
{String workingDirectory,
Map<String, String> environment,
bool includeParentEnvironment: true,
bool includeParentEnvironment = true,
void Function(String) perLine}) async {
environment ??= {};
environment.addAll(environmentDefaults);
Expand Down
6 changes: 3 additions & 3 deletions tool/doc_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ArgParser _createArgsParser() {
}

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

Future _exec(String command, List<String> args,
{String cwd,
bool quiet: false,
Duration timeout: const Duration(seconds: 60)}) {
bool quiet = false,
Duration timeout = const Duration(seconds: 60)}) {
return Process.start(command, args, workingDirectory: cwd)
.then((Process process) {
if (!quiet) {
Expand Down
4 changes: 2 additions & 2 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class WarningsCollection {
final String branch;
final String pubCachePath;
WarningsCollection(this.tempDir, this.pubCachePath, this.branch)
: this.warningKeyCounts = new Map() {}
: this.warningKeyCounts = new Map();

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