Enforce and fix prefer_typing_uninitialized_variables (#100)
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 9d14291..a20ed49 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -4,6 +4,7 @@
rules:
- prefer_equal_for_default_values
- prefer_generic_function_type_aliases
+ - prefer_typing_uninitialized_variables
- slash_for_doc_comments
- unnecessary_const
- unnecessary_new
diff --git a/lib/parser.dart b/lib/parser.dart
index 1f3d185..ca1f465 100644
--- a/lib/parser.dart
+++ b/lib/parser.dart
@@ -549,7 +549,7 @@
_next();
// Page name
- var name;
+ Identifier name;
if (_peekIdentifier()) {
name = identifier();
}
@@ -666,7 +666,7 @@
// '}'
_next();
- var name;
+ dynamic name;
if (_peekIdentifier()) {
name = identifier();
}
@@ -897,7 +897,7 @@
}
} else if (mixinParameter && _peekToken.kind == TokenKind.VAR_DEFINITION) {
_next();
- var definedName;
+ Identifier definedName;
if (_peekIdentifier()) definedName = identifier();
Expressions exprs;
@@ -917,7 +917,7 @@
// @include IDENT [(args,...)];
_next();
- var name;
+ Identifier name;
if (_peekIdentifier()) {
name = identifier();
}
@@ -931,7 +931,7 @@
// the first has 3 terms and the second has 1 term.
if (_maybeEat(TokenKind.LPAREN)) {
var terms = <Expression>[];
- var expr;
+ dynamic expr;
var keepGoing = true;
while (keepGoing && (expr = processTerm()) != null) {
// VarUsage is returns as a list
@@ -960,7 +960,7 @@
_next(); // '@-moz-document'
var functions = <LiteralTerm>[];
do {
- var function;
+ LiteralTerm function;
// Consume function token: IDENT '('
var ident = identifier();
@@ -1431,7 +1431,7 @@
// than the error message for element. Should consolidate the
// code.
// TODO(terry): Need to handle attribute namespace too.
- var first;
+ dynamic first;
var start = _peekToken.span;
switch (_peek()) {
case TokenKind.ASTERISK:
@@ -1632,7 +1632,7 @@
var expressions = <Expression>[];
Token termToken;
- var value;
+ dynamic value;
var keepParsing = true;
while (keepParsing) {
@@ -1719,7 +1719,7 @@
op = TokenKind.NO_MATCH;
}
- var value;
+ dynamic value;
if (op != TokenKind.NO_MATCH) {
// Operator hit so we require a value too.
if (_peekIdentifier()) {
@@ -2158,7 +2158,7 @@
var expressions = Expressions(_makeSpan(start));
var keepGoing = true;
- var expr;
+ dynamic expr;
while (keepGoing && (expr = processTerm(ieFilter)) != null) {
Expression op;
@@ -2242,7 +2242,7 @@
[bool ieFilter = false]) {
var start = _peekToken.span;
Token t; // token for term's value
- var value; // value of term (numeric values)
+ dynamic value; // value of term (numeric values)
var unary = '';
switch (_peek()) {
diff --git a/lib/src/analyzer.dart b/lib/src/analyzer.dart
index e9fd7c9..2f6d449 100644
--- a/lib/src/analyzer.dart
+++ b/lib/src/analyzer.dart
@@ -547,7 +547,7 @@
/// Utility function to match an include to a list of either Declarations or
/// RuleSets, depending on type of mixin (ruleset or declaration). The include
/// can be an include in a declaration or an include directive (top-level).
-int _findInclude(List list, var node) {
+int _findInclude(List list, TreeNode node) {
IncludeDirective matchNode =
(node is IncludeMixinAtDeclaration) ? node.include : node;
@@ -844,13 +844,13 @@
/// @include as a top-level with ruleset(s).
class _IncludeReplacer extends Visitor {
- final _include;
+ final TreeNode _include;
final List<TreeNode> _newDeclarations;
/// Look for the [ruleSet] inside of a @media directive; if found then replace
/// with the [newRules].
static void replace(
- StyleSheet ss, var include, List<TreeNode> newDeclarations) {
+ StyleSheet ss, TreeNode include, List<TreeNode> newDeclarations) {
var visitor = _IncludeReplacer(include, newDeclarations);
visitor.visitStyleSheet(ss);
}
diff --git a/lib/src/polyfill.dart b/lib/src/polyfill.dart
index 2582bae..0c2ef04 100644
--- a/lib/src/polyfill.dart
+++ b/lib/src/polyfill.dart
@@ -174,7 +174,7 @@
var result = <Expression>[];
var varDef = _knownVarDefs[usage.name];
- var expressions;
+ List<Expression> expressions;
if (varDef == null) {
// VarDefinition not found try the defaultValues.
expressions = usage.defaultValues;
diff --git a/lib/src/token.dart b/lib/src/token.dart
index 7c5ef65..444b8ee 100644
--- a/lib/src/token.dart
+++ b/lib/src/token.dart
@@ -41,7 +41,7 @@
/// A token containing a parsed literal value.
class LiteralToken extends Token {
- var value;
+ dynamic value;
LiteralToken(int kind, FileSpan span, this.value) : super(kind, span);
}
diff --git a/lib/src/tokenizer_base.dart b/lib/src/tokenizer_base.dart
index a648e62..5f22112 100644
--- a/lib/src/tokenizer_base.dart
+++ b/lib/src/tokenizer_base.dart
@@ -261,7 +261,7 @@
}
Token _makeRawStringToken(bool isMultiline) {
- var s;
+ String s;
if (isMultiline) {
// Skip initial newline in multiline strings
var start = _startIndex + 4;
diff --git a/lib/src/tree.dart b/lib/src/tree.dart
index b050442..8a17b53 100644
--- a/lib/src/tree.dart
+++ b/lib/src/tree.dart
@@ -171,7 +171,7 @@
// All other selectors (element, #id, .class, attribute, pseudo, negation,
// namespace, *) are derived from this selector.
abstract class SimpleSelector extends TreeNode {
- final _name; // Wildcard, ThisOperator, Identifier, Negation, others?
+ final dynamic _name; // Wildcard, ThisOperator, Identifier, Negation, others?
SimpleSelector(this._name, SourceSpan span) : super(span);
@@ -200,7 +200,7 @@
// namespace|element
class NamespaceSelector extends SimpleSelector {
- final _namespace; // null, Wildcard or Identifier
+ final dynamic _namespace; // null, Wildcard or Identifier
NamespaceSelector(this._namespace, var name, SourceSpan span)
: super(name, span);
@@ -1689,7 +1689,7 @@
}
class HeightExpression extends DartStyleExpression {
- final height;
+ final dynamic height;
HeightExpression(SourceSpan span, this.height)
: super(DartStyleExpression.heightStyle, span);
@@ -1712,7 +1712,7 @@
}
class WidthExpression extends DartStyleExpression {
- final width;
+ final dynamic width;
WidthExpression(SourceSpan span, this.width)
: super(DartStyleExpression.widthStyle, span);