Skip to content

Commit

Permalink
Fix new pedantic lints
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Dec 18, 2019
1 parent 08d0b8d commit ec3d0dd
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 48 deletions.
9 changes: 9 additions & 0 deletions analysis/lib/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ analyzer:
# This has tons of false positives for StreamSubscription.close().
unawaited_futures: ignore

# These are style preferences rather than potential semantic issues. While
# we're not intrinsically opposed to adopting them for consistency with the
# Dart ecosystem, there aren't currently any automated tools to help us
# migrate to and remain consistent with these style rules, so achieving
# consistency isn't worth the engineering time we'd spend getting there.
annotate_overrides: ignore
prefer_single_quotes: ignore
use_function_type_syntax_for_parameters: ignore

include: package:pedantic/analysis_options.yaml
4 changes: 2 additions & 2 deletions lib/src/ast/css/media_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CssMediaQuery {
} else {
return MediaQueryMergeResult.unrepresentable;
}
} else if (this.matchesAllTypes || other.matchesAllTypes) {
} else if (matchesAllTypes || other.matchesAllTypes) {
return MediaQueryMergeResult.unrepresentable;
}

Expand Down Expand Up @@ -116,7 +116,7 @@ class CssMediaQuery {
// Otherwise, there's no way to represent the intersection.
return MediaQueryMergeResult.unrepresentable;
}
} else if (this.matchesAllTypes) {
} else if (matchesAllTypes) {
modifier = theirModifier;
// Omit the type if either input query did, since that indicates that they
// aren't targeting a browser that requires "all and".
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/selector/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class SelectorList extends Selector {
return null;
}

Iterable<SimpleSelector> resolvedMembers = containsSelectorPseudo
var resolvedMembers = containsSelectorPseudo
? compound.components.map((simple) {
if (simple is PseudoSelector) {
if (simple.selector == null) return simple;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ast/selector/pseudo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class PseudoSelector extends SimpleSelector {
if (simple is PseudoSelector && simple.isElement) {
// A given compound selector may only contain one pseudo element. If
// [compound] has a different one than [this], unification fails.
if (this.isElement) return null;
if (isElement) return null;

// Otherwise, this is a pseudo selector and should come before pseduo
// elements.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/callable/built_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ class BuiltInCallable implements Callable, AsyncBuiltInCallable {

/// Returns a copy of this callable with the given [name].
BuiltInCallable withName(String name) =>
BuiltInCallable._(name, this._overloads);
BuiltInCallable._(name, _overloads);
}
4 changes: 2 additions & 2 deletions lib/src/executable/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class ExecutableOptions {
var stdin = _options['stdin'] as bool;
if (_options.rest.isEmpty && !stdin) _fail("Compile Sass to CSS.");

var directories = Set<String>();
var directories = <String>{};
var colonArgs = false;
var positionalArgs = false;
for (var argument in _options.rest) {
Expand Down Expand Up @@ -314,7 +314,7 @@ class ExecutableOptions {
// Track [seen] separately from `sourcesToDestinations.keys` because we want
// to report errors for sources as users entered them, rather than after
// directories have been resolved.
var seen = Set<String>();
var seen = <String>{};
var sourcesToDestinations = p.PathMap<String>();
var sourceDirectoriesToDestinations = p.PathMap<String>();
for (var argument in _options.rest) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/executable/watch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class _Watcher {
///
/// Returns whether all recompilations succeeded.
Future<bool> _recompileDownstream(Iterable<StylesheetNode> nodes) async {
var seen = Set<StylesheetNode>();
var seen = <StylesheetNode>{};
var toRecompile = Queue.of(nodes);

var allSucceeded = true;
Expand Down
10 changes: 5 additions & 5 deletions lib/src/extend/extender.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class Extender {
for (var component in complex.components) {
if (component is CompoundSelector) {
for (var simple in component.components) {
_selectors.putIfAbsent(simple, () => Set()).add(selector);
_selectors.putIfAbsent(simple, () => {}).add(selector);

if (simple is PseudoSelector && simple.selector != null) {
_registerSelector(simple.selector, selector);
Expand Down Expand Up @@ -415,7 +415,7 @@ class Extender {
// Find existing selectors to extend.
var selectorsForTarget = _selectors[target];
if (selectorsForTarget != null) {
selectorsToExtend ??= Set();
selectorsToExtend ??= {};
selectorsToExtend.addAll(selectorsForTarget);
}

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

// The complex selectors produced from each component of [compound].
List<List<Extension>> options;
Expand Down Expand Up @@ -904,12 +904,12 @@ class Extender {
var newSelectors =
<SimpleSelector, Set<ModifiableCssValue<SelectorList>>>{};
var newMediaContexts =
Map<ModifiableCssValue<SelectorList>, List<CssMediaQuery>>();
<ModifiableCssValue<SelectorList>, List<CssMediaQuery>>{};
var oldToNewSelectors =
<CssValue<SelectorList>, ModifiableCssValue<SelectorList>>{};

_selectors.forEach((simple, selectors) {
var newSelectorSet = Set<ModifiableCssValue<SelectorList>>();
var newSelectorSet = <ModifiableCssValue<SelectorList>>{};
newSelectors[simple] = newSelectorSet;

for (var selector in selectors) {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/functions/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ final _adjust = BuiltInCallable("adjust", r"$color, $kwargs...", (arguments) {
}

var keywords = Map.of(argumentList.keywords);
getInRange(String name, num min, num max) =>
num getInRange(String name, num min, num max) =>
keywords.remove(name)?.assertNumber(name)?.valueInRange(min, max, name);

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

var keywords = Map.of(argumentList.keywords);
getScale(String name) {
num getScale(String name) {
var value = keywords.remove(name);
if (value == null) return null;
var number = value.assertNumber(name);
number.assertUnit("%", name);
return number.valueInRange(-100, 100, name) / 100;
}

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

var keywords = Map.of(argumentList.keywords);
getInRange(String name, num min, num max) =>
num getInRange(String name, num min, num max) =>
keywords.remove(name)?.assertNumber(name)?.valueInRange(min, max, name);

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

final _ieHexStr = BuiltInCallable("ie-hex-str", r"$color", (arguments) {
var color = arguments[0].assertColor("color");
hexString(int component) =>
String hexString(int component) =>
component.toRadixString(16).padLeft(2, '0').toUpperCase();
return SassString(
"#${hexString(fuzzyRound(color.alpha * 255))}${hexString(color.red)}"
Expand Down
2 changes: 1 addition & 1 deletion lib/src/parse/at_root_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AtRootQueryParser extends Parser {
scanner.expectChar($colon);
whitespace();

var atRules = Set<String>();
var atRules = <String>{};
do {
atRules.add(identifier().toLowerCase());
whitespace();
Expand Down
16 changes: 8 additions & 8 deletions lib/src/parse/stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,8 @@ abstract class StylesheetParser extends Parser {
/// The plain identifiers are returned in the first set, and the variable
/// names in the second.
Tuple2<Set<String>, Set<String>> _memberList() {
var identifiers = Set<String>();
var variables = Set<String>();
var identifiers = <String>{};
var variables = <String>{};
do {
whitespace();
withErrorMessage("Expected variable, mixin, or function name", () {
Expand Down Expand Up @@ -1625,7 +1625,7 @@ relase. For details, see http://bit.ly/moz-document.

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

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

resolveOperations() {
void resolveOperations() {
if (operators == null) return;
while (operators.isNotEmpty) {
resolveOneOperation();
}
}

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

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

resolveSpaceExpressions() {
void resolveSpaceExpressions() {
resolveOperations();

if (spaceExpressions != null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/stylesheet_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class StylesheetNode {

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

StylesheetNode._(
this._stylesheet, this.importer, this.canonicalUrl, this._upstream) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ abstract class Value implements ext.Value {
SassList changeListContents(Iterable<Value> contents,
{ListSeparator separator, bool brackets}) {
return SassList(contents, separator ?? this.separator,
brackets: brackets ?? this.hasBrackets);
brackets: brackets ?? hasBrackets);
}

/// The SassScript `=` operation.
Expand Down
24 changes: 12 additions & 12 deletions lib/src/value/number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class SassNumber extends Value implements ext.SassNumber {
return true;
}, orElse: () {
throw SassScriptException("Incompatible units "
"${_unitString(this.numeratorUnits, this.denominatorUnits)} and "
"${_unitString(numeratorUnits, denominatorUnits)} and "
"${_unitString(newNumerators, newDenominators)}.");
});
}
Expand All @@ -264,14 +264,14 @@ class SassNumber extends Value implements ext.SassNumber {
return true;
}, orElse: () {
throw SassScriptException("Incompatible units "
"${_unitString(this.numeratorUnits, this.denominatorUnits)} and "
"${_unitString(numeratorUnits, denominatorUnits)} and "
"${_unitString(newNumerators, newDenominators)}.");
});
}

if (oldNumerators.isNotEmpty || oldDenominators.isNotEmpty) {
throw SassScriptException("Incompatible units "
"${_unitString(this.numeratorUnits, this.denominatorUnits)} and "
"${_unitString(numeratorUnits, denominatorUnits)} and "
"${_unitString(newNumerators, newDenominators)}.");
}

Expand Down Expand Up @@ -353,16 +353,16 @@ class SassNumber extends Value implements ext.SassNumber {

Value times(Value other) {
if (other is SassNumber) {
return _multiplyUnits(this.value * other.value, this.numeratorUnits,
this.denominatorUnits, other.numeratorUnits, other.denominatorUnits);
return _multiplyUnits(value * other.value, numeratorUnits,
denominatorUnits, other.numeratorUnits, other.denominatorUnits);
}
throw SassScriptException('Undefined operation "$this * $other".');
}

Value dividedBy(Value other) {
if (other is SassNumber) {
return _multiplyUnits(this.value / other.value, this.numeratorUnits,
this.denominatorUnits, other.denominatorUnits, other.numeratorUnits);
return _multiplyUnits(value / other.value, numeratorUnits,
denominatorUnits, other.denominatorUnits, other.numeratorUnits);
}
return super.dividedBy(other);
}
Expand All @@ -381,9 +381,9 @@ class SassNumber extends Value implements ext.SassNumber {
SassNumber other, num operation(num num1, num num2)) {
var result = _coerceUnits(other, operation);
return SassNumber.withUnits(result,
numeratorUnits: hasUnits ? this.numeratorUnits : other.numeratorUnits,
numeratorUnits: hasUnits ? numeratorUnits : other.numeratorUnits,
denominatorUnits:
hasUnits ? this.denominatorUnits : other.denominatorUnits);
hasUnits ? denominatorUnits : other.denominatorUnits);
}

/// Converts [other]'s value to be compatible with this number's, and calls
Expand All @@ -394,10 +394,10 @@ class SassNumber extends Value implements ext.SassNumber {
num num1;
num num2;
if (hasUnits) {
num1 = this.value;
num2 = other.valueInUnits(this.numeratorUnits, this.denominatorUnits);
num1 = value;
num2 = other.valueInUnits(numeratorUnits, denominatorUnits);
} else {
num1 = this.valueInUnits(other.numeratorUnits, other.denominatorUnits);
num1 = valueInUnits(other.numeratorUnits, other.denominatorUnits);
num2 = other.value;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/visitor/async_evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ class _EvaluateVisitor
///
/// For filesystem imports, this contains the import path. For all other
/// imports, it contains the URL passed to the `@import`.
final _includedFiles = Set<String>();
final _includedFiles = <String>{};

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

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

void visitModule(Module module) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/visitor/evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ class _EvaluateVisitor
///
/// For filesystem imports, this contains the import path. For all other
/// imports, it contains the URL passed to the `@import`.
final _includedFiles = Set<String>();
final _includedFiles = <String>{};

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

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

void visitModule(Module<Callable> module) {
Expand Down
2 changes: 1 addition & 1 deletion tool/grind/benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ String _compare(Duration duration1, Duration duration2) {
? duration2.inMilliseconds / duration1.inMilliseconds
: duration1.inMilliseconds / duration2.inMilliseconds;
var rounded = (ratio * 10).round().toString();
var humanRatio = '${rounded.substring(0, rounded.length - 1)}.' +
var humanRatio = '${rounded.substring(0, rounded.length - 1)}.'
'${rounded.substring(rounded.length - 1)}x';
if (humanRatio == '1.0x') return 'identical to';

Expand Down

0 comments on commit ec3d0dd

Please sign in to comment.