From 7f63386418db949ef0363fb621434b92c4a2cf7c Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 20 Dec 2018 12:00:30 -0800 Subject: [PATCH] [License] Enable prefer_equal_for_default_values lint --- .../tools/licenses/analysis_options.yaml | 1 + .../flutter/tools/licenses/lib/licenses.dart | 48 ++++++++++++++----- .../src/flutter/tools/licenses/lib/main.dart | 6 +-- .../flutter/tools/licenses/lib/patterns.dart | 20 +++++++- 4 files changed, 57 insertions(+), 18 deletions(-) diff --git a/engine/src/flutter/tools/licenses/analysis_options.yaml b/engine/src/flutter/tools/licenses/analysis_options.yaml index 281e646ce2..5bfc674a9e 100644 --- a/engine/src/flutter/tools/licenses/analysis_options.yaml +++ b/engine/src/flutter/tools/licenses/analysis_options.yaml @@ -45,6 +45,7 @@ linter: - one_member_abstracts - overridden_fields - package_prefixed_library_names + - prefer_equal_for_default_values - prefer_final_locals - prefer_is_not_empty - prefer_single_quotes diff --git a/engine/src/flutter/tools/licenses/lib/licenses.dart b/engine/src/flutter/tools/licenses/lib/licenses.dart index 05ce3a3172..a02c48b2e7 100644 --- a/engine/src/flutter/tools/licenses/lib/licenses.dart +++ b/engine/src/flutter/tools/licenses/lib/licenses.dart @@ -106,7 +106,11 @@ abstract class LicenseSource { } abstract class License implements Comparable { - factory License.unique(String body, LicenseType type, { bool reformatted: false, String origin, bool yesWeKnowWhatItLooksLikeButItIsNot: false }) { + factory License.unique(String body, LicenseType type, { + bool reformatted = false, + String origin, + bool yesWeKnowWhatItLooksLikeButItIsNot = false + }) { if (!reformatted) body = _reformat(body); final License result = _registry.putIfAbsent(body, () => UniqueLicense._(body, type, origin: origin, yesWeKnowWhatItLooksLikeButItIsNot: yesWeKnowWhatItLooksLikeButItIsNot)); @@ -118,7 +122,10 @@ abstract class License implements Comparable { return result; } - factory License.template(String body, LicenseType type, { bool reformatted: false, String origin }) { + factory License.template(String body, LicenseType type, { + bool reformatted = false, + String origin + }) { if (!reformatted) body = _reformat(body); final License result = _registry.putIfAbsent(body, () => TemplateLicense._(body, type, origin: origin)); @@ -130,7 +137,10 @@ abstract class License implements Comparable { return result; } - factory License.message(String body, LicenseType type, { bool reformatted: false, String origin }) { + factory License.message(String body, LicenseType type, { + bool reformatted = false, + String origin + }) { if (!reformatted) body = _reformat(body); final License result = _registry.putIfAbsent(body, () => MessageLicense._(body, type, origin: origin)); @@ -157,7 +167,10 @@ abstract class License implements Comparable { return _registry.putIfAbsent(body, () => UniqueLicense._(body, type)); } - factory License.fromBodyAndType(String body, LicenseType type, { bool reformatted: false, String origin }) { + factory License.fromBodyAndType(String body, LicenseType type, { + bool reformatted = false, + String origin + }) { if (!reformatted) body = _reformat(body); final License result = _registry.putIfAbsent(body, () { @@ -271,7 +284,10 @@ abstract class License implements Comparable { return _registry.putIfAbsent(body, () => License.fromBodyAndType(body, type, origin: origin)); } - License._(String body, this.type, { this.origin, bool yesWeKnowWhatItLooksLikeButItIsNot: false }) : body = body, authors = _readAuthors(body) { + License._(String body, this.type, { + this.origin, + bool yesWeKnowWhatItLooksLikeButItIsNot = false + }) : body = body, authors = _readAuthors(body) { assert(_reformat(body) == body); assert(() { try { @@ -500,7 +516,7 @@ Iterable<_LineRange> _walkLinesBackwards(String body, int start) sync* { yield _LineRange(start, end, body); } -Iterable<_LineRange> _walkLinesForwards(String body, { int start: 0, int end }) sync* { +Iterable<_LineRange> _walkLinesForwards(String body, { int start = 0, int end }) sync* { int startIndex = start == 0 || body[start-1] == '\n' ? start : null; int endIndex = startIndex ?? start; end ??= body.length; @@ -526,7 +542,7 @@ class _SplitLicense { String getConditions() => _split >= _body.length ? '' : _body.substring(_split == 0 ? 0 : _split + 1); } -_SplitLicense _splitLicense(String body, { bool verifyResults: true }) { +_SplitLicense _splitLicense(String body, { bool verifyResults = true }) { final Iterator<_LineRange> lines = _walkLinesForwards(body).iterator; if (!lines.moveNext()) throw 'tried to split empty license'; @@ -613,7 +629,7 @@ class _PartialLicenseMatch { final bool hasCopyrights; } -Iterable<_PartialLicenseMatch> _findLicenseBlocks(String body, RegExp pattern, int firstPrefixIndex, int indentPrefixIndex, { bool needsCopyright: true }) sync* { +Iterable<_PartialLicenseMatch> _findLicenseBlocks(String body, RegExp pattern, int firstPrefixIndex, int indentPrefixIndex, { bool needsCopyright = true }) sync* { // I tried doing this with one big RegExp initially, but that way lay madness. for (Match match in pattern.allMatches(body)) { assert(match.groupCount >= firstPrefixIndex); @@ -709,7 +725,11 @@ Iterable<_PartialLicenseMatch> _findLicenseBlocks(String body, RegExp pattern, i } class _LicenseMatch { - _LicenseMatch(this.license, this.start, this.end, { this.debug: '', this.isDuplicate: false, this.missingCopyrights: false }); + _LicenseMatch(this.license, this.start, this.end, { + this.debug = '', + this.isDuplicate = false, + this.missingCopyrights = false + }); final License license; final int start; final int end; @@ -718,7 +738,7 @@ class _LicenseMatch { final bool missingCopyrights; } -Iterable<_LicenseMatch> _expand(License template, String copyright, String body, int start, int end, { String debug: '', String origin }) sync* { +Iterable<_LicenseMatch> _expand(License template, String copyright, String body, int start, int end, { String debug = '', String origin }) sync* { final List results = template.expandTemplate(_reformat(copyright), body, origin: origin).toList(); if (results.isEmpty) throw 'license could not be expanded'; @@ -780,7 +800,7 @@ Iterable<_LicenseMatch> _tryReferenceByFilename(String body, LicenseFileReferenc } } -Iterable<_LicenseMatch> _tryReferenceByType(String body, RegExp pattern, LicenseSource parentDirectory, { String origin, bool needsCopyright: true }) sync* { +Iterable<_LicenseMatch> _tryReferenceByType(String body, RegExp pattern, LicenseSource parentDirectory, { String origin, bool needsCopyright = true }) sync* { for (_PartialLicenseMatch match in _findLicenseBlocks(body, pattern, 1, 2, needsCopyright: needsCopyright)) { final LicenseType type = convertLicenseNameToType(match.group(3)); final License template = parentDirectory.nearestLicenseOfType(type); @@ -965,8 +985,10 @@ class MultiLicense extends License { // the kind of license that should not be combined with separate copyright notices class UniqueLicense extends License { - UniqueLicense._(String body, LicenseType type, { String origin, bool yesWeKnowWhatItLooksLikeButItIsNot: false }) - : super._(body, type, origin: origin, yesWeKnowWhatItLooksLikeButItIsNot: yesWeKnowWhatItLooksLikeButItIsNot); + UniqueLicense._(String body, LicenseType type, { + String origin, + bool yesWeKnowWhatItLooksLikeButItIsNot = false + }) : super._(body, type, origin: origin, yesWeKnowWhatItLooksLikeButItIsNot: yesWeKnowWhatItLooksLikeButItIsNot); @override Iterable expandTemplate(String copyright, String licenseBody, { String origin }) sync* { throw 'attempted to expand non-template license with "$copyright"\ntemplate was: $this'; diff --git a/engine/src/flutter/tools/licenses/lib/main.dart b/engine/src/flutter/tools/licenses/lib/main.dart index d355ae85c1..f3d025aa01 100644 --- a/engine/src/flutter/tools/licenses/lib/main.dart +++ b/engine/src/flutter/tools/licenses/lib/main.dart @@ -1097,13 +1097,13 @@ class _RepositoryDirectory extends _RepositoryEntry implements LicenseSource { return null; } - License _fullWalkUpForLicenseWithName(String name, { String authors, bool ignoreCase: false }) { + License _fullWalkUpForLicenseWithName(String name, { String authors, bool ignoreCase = false }) { return _canGoUp(authors) ? parent._fullWalkUpForLicenseWithName(name, authors: authors, ignoreCase: ignoreCase) : _fullWalkDownForLicenseWithName(name, authors: authors, ignoreCase: ignoreCase); } - License _fullWalkDownForLicenseWithName(String name, { String authors, bool ignoreCase: false }) { + License _fullWalkDownForLicenseWithName(String name, { String authors, bool ignoreCase = false }) { License result = _localLicenseWithName(name, authors: authors, ignoreCase: ignoreCase); if (result == null) { for (_RepositoryDirectory directory in _subdirectories) { @@ -1140,7 +1140,7 @@ class _RepositoryDirectory extends _RepositoryEntry implements LicenseSource { /// to the LICENSE in the root of the repo. bool get isLicenseRootException => false; - License _localLicenseWithName(String name, { String authors, bool ignoreCase: false }) { + License _localLicenseWithName(String name, { String authors, bool ignoreCase = false }) { Map map; if (ignoreCase) { // we get here if we're trying a last-ditch effort at finding a file. diff --git a/engine/src/flutter/tools/licenses/lib/patterns.dart b/engine/src/flutter/tools/licenses/lib/patterns.dart index 7d61406144..4740081f1d 100644 --- a/engine/src/flutter/tools/licenses/lib/patterns.dart +++ b/engine/src/flutter/tools/licenses/lib/patterns.dart @@ -262,7 +262,15 @@ final List csAttribution = [ // REFERENCES TO OTHER FILES class LicenseFileReferencePattern { - LicenseFileReferencePattern({ this.firstPrefixIndex, this.indentPrefixIndex, this.copyrightIndex, this.authorIndex, this.fileIndex, this.pattern, this.needsCopyright: true }); + LicenseFileReferencePattern({ + this.firstPrefixIndex, + this.indentPrefixIndex, + this.copyrightIndex, + this.authorIndex, + this.fileIndex, + this.pattern, + this.needsCopyright = true + }); final int firstPrefixIndex; final int indentPrefixIndex; final int copyrightIndex; @@ -571,7 +579,15 @@ final List csReferencesByTypeNoCopyright = [ ]; class MultipleVersionedLicenseReferencePattern { - MultipleVersionedLicenseReferencePattern({ this.firstPrefixIndex, this.indentPrefixIndex, this.licenseIndices, this.versionIndicies, this.checkLocalFirst: true, this.pattern }); + MultipleVersionedLicenseReferencePattern({ + this.firstPrefixIndex, + this.indentPrefixIndex, + this.licenseIndices, + this.versionIndicies, + this.checkLocalFirst = true, + this.pattern + }); + final int firstPrefixIndex; final int indentPrefixIndex; final List licenseIndices;