Skip to content

Commit ec3d0dd

Browse files
committed
Fix new pedantic lints
1 parent 08d0b8d commit ec3d0dd

File tree

17 files changed

+57
-48
lines changed

17 files changed

+57
-48
lines changed

analysis/lib/analysis_options.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,13 @@ analyzer:
1414
# This has tons of false positives for StreamSubscription.close().
1515
unawaited_futures: ignore
1616

17+
# These are style preferences rather than potential semantic issues. While
18+
# we're not intrinsically opposed to adopting them for consistency with the
19+
# Dart ecosystem, there aren't currently any automated tools to help us
20+
# migrate to and remain consistent with these style rules, so achieving
21+
# consistency isn't worth the engineering time we'd spend getting there.
22+
annotate_overrides: ignore
23+
prefer_single_quotes: ignore
24+
use_function_type_syntax_for_parameters: ignore
25+
1726
include: package:pedantic/analysis_options.yaml

lib/src/ast/css/media_query.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CssMediaQuery {
8181
} else {
8282
return MediaQueryMergeResult.unrepresentable;
8383
}
84-
} else if (this.matchesAllTypes || other.matchesAllTypes) {
84+
} else if (matchesAllTypes || other.matchesAllTypes) {
8585
return MediaQueryMergeResult.unrepresentable;
8686
}
8787

@@ -116,7 +116,7 @@ class CssMediaQuery {
116116
// Otherwise, there's no way to represent the intersection.
117117
return MediaQueryMergeResult.unrepresentable;
118118
}
119-
} else if (this.matchesAllTypes) {
119+
} else if (matchesAllTypes) {
120120
modifier = theirModifier;
121121
// Omit the type if either input query did, since that indicates that they
122122
// aren't targeting a browser that requires "all and".

lib/src/ast/selector/list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class SelectorList extends Selector {
169169
return null;
170170
}
171171

172-
Iterable<SimpleSelector> resolvedMembers = containsSelectorPseudo
172+
var resolvedMembers = containsSelectorPseudo
173173
? compound.components.map((simple) {
174174
if (simple is PseudoSelector) {
175175
if (simple.selector == null) return simple;

lib/src/ast/selector/pseudo.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class PseudoSelector extends SimpleSelector {
135135
if (simple is PseudoSelector && simple.isElement) {
136136
// A given compound selector may only contain one pseudo element. If
137137
// [compound] has a different one than [this], unification fails.
138-
if (this.isElement) return null;
138+
if (isElement) return null;
139139

140140
// Otherwise, this is a pseudo selector and should come before pseduo
141141
// elements.

lib/src/callable/built_in.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ class BuiltInCallable implements Callable, AsyncBuiltInCallable {
8686

8787
/// Returns a copy of this callable with the given [name].
8888
BuiltInCallable withName(String name) =>
89-
BuiltInCallable._(name, this._overloads);
89+
BuiltInCallable._(name, _overloads);
9090
}

lib/src/executable/options.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class ExecutableOptions {
243243
var stdin = _options['stdin'] as bool;
244244
if (_options.rest.isEmpty && !stdin) _fail("Compile Sass to CSS.");
245245

246-
var directories = Set<String>();
246+
var directories = <String>{};
247247
var colonArgs = false;
248248
var positionalArgs = false;
249249
for (var argument in _options.rest) {
@@ -314,7 +314,7 @@ class ExecutableOptions {
314314
// Track [seen] separately from `sourcesToDestinations.keys` because we want
315315
// to report errors for sources as users entered them, rather than after
316316
// directories have been resolved.
317-
var seen = Set<String>();
317+
var seen = <String>{};
318318
var sourcesToDestinations = p.PathMap<String>();
319319
var sourceDirectoriesToDestinations = p.PathMap<String>();
320320
for (var argument in _options.rest) {

lib/src/executable/watch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class _Watcher {
224224
///
225225
/// Returns whether all recompilations succeeded.
226226
Future<bool> _recompileDownstream(Iterable<StylesheetNode> nodes) async {
227-
var seen = Set<StylesheetNode>();
227+
var seen = <StylesheetNode>{};
228228
var toRecompile = Queue.of(nodes);
229229

230230
var allSucceeded = true;

lib/src/extend/extender.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class Extender {
199199
for (var component in complex.components) {
200200
if (component is CompoundSelector) {
201201
for (var simple in component.components) {
202-
_selectors.putIfAbsent(simple, () => Set()).add(selector);
202+
_selectors.putIfAbsent(simple, () => {}).add(selector);
203203

204204
if (simple is PseudoSelector && simple.selector != null) {
205205
_registerSelector(simple.selector, selector);
@@ -415,7 +415,7 @@ class Extender {
415415
// Find existing selectors to extend.
416416
var selectorsForTarget = _selectors[target];
417417
if (selectorsForTarget != null) {
418-
selectorsToExtend ??= Set();
418+
selectorsToExtend ??= {};
419419
selectorsToExtend.addAll(selectorsForTarget);
420420
}
421421

@@ -568,7 +568,7 @@ class Extender {
568568
// which targets are actually extended.
569569
var targetsUsed = _mode == ExtendMode.normal || extensions.length < 2
570570
? null
571-
: Set<SimpleSelector>();
571+
: <SimpleSelector>{};
572572

573573
// The complex selectors produced from each component of [compound].
574574
List<List<Extension>> options;
@@ -904,12 +904,12 @@ class Extender {
904904
var newSelectors =
905905
<SimpleSelector, Set<ModifiableCssValue<SelectorList>>>{};
906906
var newMediaContexts =
907-
Map<ModifiableCssValue<SelectorList>, List<CssMediaQuery>>();
907+
<ModifiableCssValue<SelectorList>, List<CssMediaQuery>>{};
908908
var oldToNewSelectors =
909909
<CssValue<SelectorList>, ModifiableCssValue<SelectorList>>{};
910910

911911
_selectors.forEach((simple, selectors) {
912-
var newSelectorSet = Set<ModifiableCssValue<SelectorList>>();
912+
var newSelectorSet = <ModifiableCssValue<SelectorList>>{};
913913
newSelectors[simple] = newSelectorSet;
914914

915915
for (var selector in selectors) {

lib/src/functions/color.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ final _adjust = BuiltInCallable("adjust", r"$color, $kwargs...", (arguments) {
379379
}
380380

381381
var keywords = Map.of(argumentList.keywords);
382-
getInRange(String name, num min, num max) =>
382+
num getInRange(String name, num min, num max) =>
383383
keywords.remove(name)?.assertNumber(name)?.valueInRange(min, max, name);
384384

385385
var red = _fuzzyRoundOrNull(getInRange("red", -255, 255));
@@ -432,15 +432,15 @@ final _scale = BuiltInCallable("scale", r"$color, $kwargs...", (arguments) {
432432
}
433433

434434
var keywords = Map.of(argumentList.keywords);
435-
getScale(String name) {
435+
num getScale(String name) {
436436
var value = keywords.remove(name);
437437
if (value == null) return null;
438438
var number = value.assertNumber(name);
439439
number.assertUnit("%", name);
440440
return number.valueInRange(-100, 100, name) / 100;
441441
}
442442

443-
scaleValue(num current, num scale, num max) {
443+
num scaleValue(num current, num scale, num max) {
444444
if (scale == null) return current;
445445
return current + (scale > 0 ? max - current : current) * scale;
446446
}
@@ -493,7 +493,7 @@ final _change = BuiltInCallable("change", r"$color, $kwargs...", (arguments) {
493493
}
494494

495495
var keywords = Map.of(argumentList.keywords);
496-
getInRange(String name, num min, num max) =>
496+
num getInRange(String name, num min, num max) =>
497497
keywords.remove(name)?.assertNumber(name)?.valueInRange(min, max, name);
498498

499499
var red = _fuzzyRoundOrNull(getInRange("red", 0, 255));
@@ -531,7 +531,7 @@ final _change = BuiltInCallable("change", r"$color, $kwargs...", (arguments) {
531531

532532
final _ieHexStr = BuiltInCallable("ie-hex-str", r"$color", (arguments) {
533533
var color = arguments[0].assertColor("color");
534-
hexString(int component) =>
534+
String hexString(int component) =>
535535
component.toRadixString(16).padLeft(2, '0').toUpperCase();
536536
return SassString(
537537
"#${hexString(fuzzyRound(color.alpha * 255))}${hexString(color.red)}"

lib/src/parse/at_root_query.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AtRootQueryParser extends Parser {
2323
scanner.expectChar($colon);
2424
whitespace();
2525

26-
var atRules = Set<String>();
26+
var atRules = <String>{};
2727
do {
2828
atRules.add(identifier().toLowerCase());
2929
whitespace();

lib/src/parse/stylesheet.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,8 @@ abstract class StylesheetParser extends Parser {
987987
/// The plain identifiers are returned in the first set, and the variable
988988
/// names in the second.
989989
Tuple2<Set<String>, Set<String>> _memberList() {
990-
var identifiers = Set<String>();
991-
var variables = Set<String>();
990+
var identifiers = <String>{};
991+
var variables = <String>{};
992992
do {
993993
whitespace();
994994
withErrorMessage("Expected variable, mixin, or function name", () {
@@ -1625,7 +1625,7 @@ relase. For details, see http://bit.ly/moz-document.
16251625

16261626
// Resets the scanner state to the state it was at at the beginning of the
16271627
// expression, except for [_inParentheses].
1628-
resetState() {
1628+
void resetState() {
16291629
commaExpressions = null;
16301630
spaceExpressions = null;
16311631
operators = null;
@@ -1635,7 +1635,7 @@ relase. For details, see http://bit.ly/moz-document.
16351635
singleExpression = _singleExpression();
16361636
}
16371637

1638-
resolveOneOperation() {
1638+
void resolveOneOperation() {
16391639
var operator = operators.removeLast();
16401640
if (operator != BinaryOperator.dividedBy) allowSlash = false;
16411641
if (allowSlash && !_inParentheses) {
@@ -1647,14 +1647,14 @@ relase. For details, see http://bit.ly/moz-document.
16471647
}
16481648
}
16491649

1650-
resolveOperations() {
1650+
void resolveOperations() {
16511651
if (operators == null) return;
16521652
while (operators.isNotEmpty) {
16531653
resolveOneOperation();
16541654
}
16551655
}
16561656

1657-
addSingleExpression(Expression expression, {bool number = false}) {
1657+
void addSingleExpression(Expression expression, {bool number = false}) {
16581658
if (singleExpression != null) {
16591659
// If we discover we're parsing a list whose first element is a division
16601660
// operation, and we're in parentheses, reparse outside of a paren
@@ -1679,7 +1679,7 @@ relase. For details, see http://bit.ly/moz-document.
16791679
singleExpression = expression;
16801680
}
16811681

1682-
addOperator(BinaryOperator operator) {
1682+
void addOperator(BinaryOperator operator) {
16831683
if (plainCss && operator != BinaryOperator.dividedBy) {
16841684
scanner.error("Operators aren't allowed in plain CSS.",
16851685
position: scanner.position - operator.operator.length,
@@ -1704,7 +1704,7 @@ relase. For details, see http://bit.ly/moz-document.
17041704
allowSlash = allowSlash && singleExpression is NumberExpression;
17051705
}
17061706

1707-
resolveSpaceExpressions() {
1707+
void resolveSpaceExpressions() {
17081708
resolveOperations();
17091709

17101710
if (spaceExpressions != null) {

lib/src/stylesheet_graph.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class StylesheetNode {
242242

243243
/// The stylesheets that import [stylesheet].
244244
Set<StylesheetNode> get downstream => UnmodifiableSetView(_downstream);
245-
final _downstream = Set<StylesheetNode>();
245+
final _downstream = <StylesheetNode>{};
246246

247247
StylesheetNode._(
248248
this._stylesheet, this.importer, this.canonicalUrl, this._upstream) {

lib/src/value.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ abstract class Value implements ext.Value {
222222
SassList changeListContents(Iterable<Value> contents,
223223
{ListSeparator separator, bool brackets}) {
224224
return SassList(contents, separator ?? this.separator,
225-
brackets: brackets ?? this.hasBrackets);
225+
brackets: brackets ?? hasBrackets);
226226
}
227227

228228
/// The SassScript `=` operation.

lib/src/value/number.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class SassNumber extends Value implements ext.SassNumber {
250250
return true;
251251
}, orElse: () {
252252
throw SassScriptException("Incompatible units "
253-
"${_unitString(this.numeratorUnits, this.denominatorUnits)} and "
253+
"${_unitString(numeratorUnits, denominatorUnits)} and "
254254
"${_unitString(newNumerators, newDenominators)}.");
255255
});
256256
}
@@ -264,14 +264,14 @@ class SassNumber extends Value implements ext.SassNumber {
264264
return true;
265265
}, orElse: () {
266266
throw SassScriptException("Incompatible units "
267-
"${_unitString(this.numeratorUnits, this.denominatorUnits)} and "
267+
"${_unitString(numeratorUnits, denominatorUnits)} and "
268268
"${_unitString(newNumerators, newDenominators)}.");
269269
});
270270
}
271271

272272
if (oldNumerators.isNotEmpty || oldDenominators.isNotEmpty) {
273273
throw SassScriptException("Incompatible units "
274-
"${_unitString(this.numeratorUnits, this.denominatorUnits)} and "
274+
"${_unitString(numeratorUnits, denominatorUnits)} and "
275275
"${_unitString(newNumerators, newDenominators)}.");
276276
}
277277

@@ -353,16 +353,16 @@ class SassNumber extends Value implements ext.SassNumber {
353353

354354
Value times(Value other) {
355355
if (other is SassNumber) {
356-
return _multiplyUnits(this.value * other.value, this.numeratorUnits,
357-
this.denominatorUnits, other.numeratorUnits, other.denominatorUnits);
356+
return _multiplyUnits(value * other.value, numeratorUnits,
357+
denominatorUnits, other.numeratorUnits, other.denominatorUnits);
358358
}
359359
throw SassScriptException('Undefined operation "$this * $other".');
360360
}
361361

362362
Value dividedBy(Value other) {
363363
if (other is SassNumber) {
364-
return _multiplyUnits(this.value / other.value, this.numeratorUnits,
365-
this.denominatorUnits, other.denominatorUnits, other.numeratorUnits);
364+
return _multiplyUnits(value / other.value, numeratorUnits,
365+
denominatorUnits, other.denominatorUnits, other.numeratorUnits);
366366
}
367367
return super.dividedBy(other);
368368
}
@@ -381,9 +381,9 @@ class SassNumber extends Value implements ext.SassNumber {
381381
SassNumber other, num operation(num num1, num num2)) {
382382
var result = _coerceUnits(other, operation);
383383
return SassNumber.withUnits(result,
384-
numeratorUnits: hasUnits ? this.numeratorUnits : other.numeratorUnits,
384+
numeratorUnits: hasUnits ? numeratorUnits : other.numeratorUnits,
385385
denominatorUnits:
386-
hasUnits ? this.denominatorUnits : other.denominatorUnits);
386+
hasUnits ? denominatorUnits : other.denominatorUnits);
387387
}
388388

389389
/// Converts [other]'s value to be compatible with this number's, and calls
@@ -394,10 +394,10 @@ class SassNumber extends Value implements ext.SassNumber {
394394
num num1;
395395
num num2;
396396
if (hasUnits) {
397-
num1 = this.value;
398-
num2 = other.valueInUnits(this.numeratorUnits, this.denominatorUnits);
397+
num1 = value;
398+
num2 = other.valueInUnits(numeratorUnits, denominatorUnits);
399399
} else {
400-
num1 = this.valueInUnits(other.numeratorUnits, other.denominatorUnits);
400+
num1 = valueInUnits(other.numeratorUnits, other.denominatorUnits);
401401
num2 = other.value;
402402
}
403403

lib/src/visitor/async_evaluate.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ class _EvaluateVisitor
198198
///
199199
/// For filesystem imports, this contains the import path. For all other
200200
/// imports, it contains the URL passed to the `@import`.
201-
final _includedFiles = Set<String>();
201+
final _includedFiles = <String>{};
202202

203203
/// The set of canonical URLs for modules (or imported files) that are
204204
/// currently being evaluated.
205205
///
206206
/// This is used to ensure that we don't get into an infinite load loop.
207-
final _activeModules = Set<Uri>();
207+
final _activeModules = <Uri>{};
208208

209209
/// The dynamic call stack representing function invocations, mixin
210210
/// invocations, and imports surrounding the current context.
@@ -786,7 +786,7 @@ class _EvaluateVisitor
786786
List<Module> _topologicalModules(Module root) {
787787
// Construct a topological ordering using depth-first traversal, as in
788788
// https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search.
789-
var seen = Set<Module>();
789+
var seen = <Module>{};
790790
var sorted = QueueList<Module>();
791791

792792
void visitModule(Module module) {

lib/src/visitor/evaluate.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ class _EvaluateVisitor
206206
///
207207
/// For filesystem imports, this contains the import path. For all other
208208
/// imports, it contains the URL passed to the `@import`.
209-
final _includedFiles = Set<String>();
209+
final _includedFiles = <String>{};
210210

211211
/// The set of canonical URLs for modules (or imported files) that are
212212
/// currently being evaluated.
213213
///
214214
/// This is used to ensure that we don't get into an infinite load loop.
215-
final _activeModules = Set<Uri>();
215+
final _activeModules = <Uri>{};
216216

217217
/// The dynamic call stack representing function invocations, mixin
218218
/// invocations, and imports surrounding the current context.
@@ -790,7 +790,7 @@ class _EvaluateVisitor
790790
List<Module<Callable>> _topologicalModules(Module<Callable> root) {
791791
// Construct a topological ordering using depth-first traversal, as in
792792
// https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search.
793-
var seen = Set<Module<Callable>>();
793+
var seen = <Module<Callable>>{};
794794
var sorted = QueueList<Module<Callable>>();
795795

796796
void visitModule(Module<Callable> module) {

tool/grind/benchmark.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ String _compare(Duration duration1, Duration duration2) {
267267
? duration2.inMilliseconds / duration1.inMilliseconds
268268
: duration1.inMilliseconds / duration2.inMilliseconds;
269269
var rounded = (ratio * 10).round().toString();
270-
var humanRatio = '${rounded.substring(0, rounded.length - 1)}.' +
270+
var humanRatio = '${rounded.substring(0, rounded.length - 1)}.'
271271
'${rounded.substring(rounded.length - 1)}x';
272272
if (humanRatio == '1.0x') return 'identical to';
273273

0 commit comments

Comments
 (0)