Skip to content

Commit 8aa847c

Browse files
authored
Enable and fix standard lints, test on oldest supported Dart sdk (flutter#14)
1 parent 6010304 commit 8aa847c

19 files changed

+131
-94
lines changed

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
language: dart
2-
sudo: false
2+
33
dart:
4-
#- stable
4+
- 2.0.0
55
- dev
6+
67
dart_task:
78
- test: -p vm
89
xvfb: false

analysis_options.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
include: package:pedantic/analysis_options.yaml
2+
linter:
3+
rules:
4+
- avoid_empty_else
5+
- avoid_init_to_null
6+
- avoid_null_checks_in_equality_operators
7+
- avoid_unused_constructor_parameters
8+
- await_only_futures
9+
- camel_case_types
10+
- cancel_subscriptions
11+
- constant_identifier_names
12+
- control_flow_in_finally
13+
- directives_ordering
14+
- empty_catches
15+
- empty_constructor_bodies
16+
- empty_statements
17+
- hash_and_equals
18+
- implementation_imports
19+
- iterable_contains_unrelated_type
20+
- library_names
21+
- library_prefixes
22+
- list_remove_unrelated_type
23+
- non_constant_identifier_names
24+
- overridden_fields
25+
- package_api_docs
26+
- package_names
27+
- package_prefixed_library_names
28+
- prefer_equal_for_default_values
29+
- prefer_final_fields
30+
- prefer_generic_function_type_aliases
31+
- prefer_is_not_empty
32+
- slash_for_doc_comments
33+
- test_types_in_equals
34+
- throw_in_finally
35+
- type_init_formals
36+
- unnecessary_brace_in_string_interps
37+
- unnecessary_const
38+
- unnecessary_new
39+
- unrelated_type_equality_checks
40+
- valid_regexps

lib/boolean_selector.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import 'src/none.dart';
2020
/// same parsed structure are considered equal.
2121
abstract class BooleanSelector {
2222
/// A selector that accepts all inputs.
23-
static const all = const All();
23+
static const all = All();
2424

2525
/// A selector that accepts no inputs.
26-
static const none = const None();
26+
static const none = None();
2727

2828
/// All the variables in this selector, in the order they appear.
2929
Iterable<String> get variables;

lib/src/evaluator.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'ast.dart';
66
import 'visitor.dart';
77

8-
typedef bool _Semantics(String variable);
8+
typedef _Semantics = bool Function(String variable);
99

1010
/// A visitor for evaluating boolean selectors against a specific set of
1111
/// semantics.

lib/src/impl.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,32 @@ class BooleanSelectorImpl implements BooleanSelector {
2424
/// This will throw a [SourceSpanFormatException] if the selector is
2525
/// malformed or if it uses an undefined variable.
2626
BooleanSelectorImpl.parse(String selector)
27-
: _selector = new Parser(selector).parse();
27+
: _selector = Parser(selector).parse();
2828

2929
BooleanSelectorImpl._(this._selector);
3030

3131
Iterable<String> get variables => _selector.variables;
3232

33-
bool evaluate(semantics) => _selector.accept(new Evaluator(semantics));
33+
bool evaluate(semantics) => _selector.accept(Evaluator(semantics));
3434

3535
BooleanSelector intersection(BooleanSelector other) {
3636
if (other == BooleanSelector.all) return this;
3737
if (other == BooleanSelector.none) return other;
3838
return other is BooleanSelectorImpl
39-
? new BooleanSelectorImpl._(new AndNode(_selector, other._selector))
40-
: new IntersectionSelector(this, other);
39+
? BooleanSelectorImpl._(AndNode(_selector, other._selector))
40+
: IntersectionSelector(this, other);
4141
}
4242

4343
BooleanSelector union(BooleanSelector other) {
4444
if (other == BooleanSelector.all) return other;
4545
if (other == BooleanSelector.none) return this;
4646
return other is BooleanSelectorImpl
47-
? new BooleanSelectorImpl._(new OrNode(_selector, other._selector))
48-
: new UnionSelector(this, other);
47+
? BooleanSelectorImpl._(OrNode(_selector, other._selector))
48+
: UnionSelector(this, other);
4949
}
5050

5151
void validate(bool isDefined(String variable)) {
52-
_selector.accept(new Validator(isDefined));
52+
_selector.accept(Validator(isDefined));
5353
}
5454

5555
String toString() => _selector.toString();

lib/src/intersection_selector.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ class IntersectionSelector implements BooleanSelector {
2121
_selector1.evaluate(semantics) && _selector2.evaluate(semantics);
2222

2323
BooleanSelector intersection(BooleanSelector other) =>
24-
new IntersectionSelector(this, other);
24+
IntersectionSelector(this, other);
2525

26-
BooleanSelector union(BooleanSelector other) =>
27-
new UnionSelector(this, other);
26+
BooleanSelector union(BooleanSelector other) => UnionSelector(this, other);
2827

2928
void validate(bool isDefined(String variable)) {
3029
_selector1.validate(isDefined);

lib/src/parser.dart

+10-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Parser {
1818
/// The scanner that tokenizes the selector.
1919
final Scanner _scanner;
2020

21-
Parser(String selector) : _scanner = new Scanner(selector);
21+
Parser(String selector) : _scanner = Scanner(selector);
2222

2323
/// Parses the selector.
2424
///
@@ -27,7 +27,7 @@ class Parser {
2727
var selector = _conditional();
2828

2929
if (_scanner.peek().type != TokenType.endOfFile) {
30-
throw new SourceSpanFormatException(
30+
throw SourceSpanFormatException(
3131
"Expected end of input.", _scanner.peek().span);
3232
}
3333

@@ -45,12 +45,11 @@ class Parser {
4545

4646
var whenTrue = _conditional();
4747
if (!_scanner.scan(TokenType.colon)) {
48-
throw new SourceSpanFormatException(
49-
'Expected ":".', _scanner.peek().span);
48+
throw SourceSpanFormatException('Expected ":".', _scanner.peek().span);
5049
}
5150

5251
var whenFalse = _conditional();
53-
return new ConditionalNode(condition, whenTrue, whenFalse);
52+
return ConditionalNode(condition, whenTrue, whenFalse);
5453
}
5554

5655
/// Parses a logical or:
@@ -60,7 +59,7 @@ class Parser {
6059
Node _or() {
6160
var left = _and();
6261
if (!_scanner.scan(TokenType.or)) return left;
63-
return new OrNode(left, _or());
62+
return OrNode(left, _or());
6463
}
6564

6665
/// Parses a logical and:
@@ -70,7 +69,7 @@ class Parser {
7069
Node _and() {
7170
var left = _simpleExpression();
7271
if (!_scanner.scan(TokenType.and)) return left;
73-
return new AndNode(left, _and());
72+
return AndNode(left, _and());
7473
}
7574

7675
/// Parses a simple expression:
@@ -84,21 +83,21 @@ class Parser {
8483
switch (token.type) {
8584
case TokenType.not:
8685
var child = _simpleExpression();
87-
return new NotNode(child, token.span.expand(child.span));
86+
return NotNode(child, token.span.expand(child.span));
8887

8988
case TokenType.leftParen:
9089
var child = _conditional();
9190
if (!_scanner.scan(TokenType.rightParen)) {
92-
throw new SourceSpanFormatException(
91+
throw SourceSpanFormatException(
9392
'Expected ")".', _scanner.peek().span);
9493
}
9594
return child;
9695

9796
case TokenType.identifier:
98-
return new VariableNode((token as IdentifierToken).name, token.span);
97+
return VariableNode((token as IdentifierToken).name, token.span);
9998

10099
default:
101-
throw new SourceSpanFormatException("Expected expression.", token.span);
100+
throw SourceSpanFormatException("Expected expression.", token.span);
102101
}
103102
}
104103
}

lib/src/scanner.dart

+10-11
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ import 'token.dart';
99
/// A regular expression matching both whitespace and single-line comments.
1010
///
1111
/// This will only match if consumes at least one character.
12-
final _whitespaceAndSingleLineComments =
13-
new RegExp(r"([ \t\n]+|//[^\n]*(\n|$))+");
12+
final _whitespaceAndSingleLineComments = RegExp(r"([ \t\n]+|//[^\n]*(\n|$))+");
1413

1514
/// A regular expression matching the body of a multi-line comment, after `/*`
1615
/// but before `*/` or a nested `/*`.
1716
///
1817
/// This will only match if it consumes at least one character.
19-
final _multiLineCommentBody = new RegExp(r"([^/*]|/[^*]|\*[^/])+");
18+
final _multiLineCommentBody = RegExp(r"([^/*]|/[^*]|\*[^/])+");
2019

2120
/// A regular expression matching a hyphenated identifier.
2221
///
2322
/// This is like a standard Dart identifier, except that it can also contain
2423
/// hyphens.
25-
final _hyphenatedIdentifier = new RegExp(r"[a-zA-Z_-][a-zA-Z0-9_-]*");
24+
final _hyphenatedIdentifier = RegExp(r"[a-zA-Z_-][a-zA-Z0-9_-]*");
2625

2726
/// A scanner that converts a boolean selector string into a stream of tokens.
2827
class Scanner {
@@ -35,7 +34,7 @@ class Scanner {
3534
/// Whether the scanner has emitted a [TokenType.endOfFile] token.
3635
bool _endOfFileEmitted = false;
3736

38-
Scanner(String selector) : _scanner = new SpanScanner(selector);
37+
Scanner(String selector) : _scanner = SpanScanner(selector);
3938

4039
/// Returns the next token that will be returned by [next].
4140
///
@@ -70,11 +69,11 @@ class Scanner {
7069

7170
/// Scan and return the next token in the stream.
7271
Token _getNext() {
73-
if (_endOfFileEmitted) throw new StateError("No more tokens.");
72+
if (_endOfFileEmitted) throw StateError("No more tokens.");
7473

7574
_consumeWhitespace();
7675
if (_scanner.isDone) {
77-
return new Token(TokenType.endOfFile, _scanner.spanFrom(_scanner.state));
76+
return Token(TokenType.endOfFile, _scanner.spanFrom(_scanner.state));
7877
}
7978

8079
switch (_scanner.peekChar()) {
@@ -104,7 +103,7 @@ class Scanner {
104103
Token _scanOperator(TokenType type) {
105104
var start = _scanner.state;
106105
_scanner.readChar();
107-
return new Token(type, _scanner.spanFrom(start));
106+
return Token(type, _scanner.spanFrom(start));
108107
}
109108

110109
/// Scans a `||` operator and returns the appropriate token.
@@ -113,7 +112,7 @@ class Scanner {
113112
Token _scanOr() {
114113
var start = _scanner.state;
115114
_scanner.expect("||");
116-
return new Token(TokenType.or, _scanner.spanFrom(start));
115+
return Token(TokenType.or, _scanner.spanFrom(start));
117116
}
118117

119118
/// Scans a `&&` operator and returns the appropriate token.
@@ -122,13 +121,13 @@ class Scanner {
122121
Token _scanAnd() {
123122
var start = _scanner.state;
124123
_scanner.expect("&&");
125-
return new Token(TokenType.and, _scanner.spanFrom(start));
124+
return Token(TokenType.and, _scanner.spanFrom(start));
126125
}
127126

128127
/// Scans and returns an identifier token.
129128
Token _scanIdentifier() {
130129
_scanner.expect(_hyphenatedIdentifier, name: "expression");
131-
return new IdentifierToken(_scanner.lastMatch[0], _scanner.lastSpan);
130+
return IdentifierToken(_scanner.lastMatch[0], _scanner.lastSpan);
132131
}
133132

134133
/// Consumes all whitespace and comments immediately following the cursor's

lib/src/token.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,31 @@ class IdentifierToken implements Token {
3535
/// An enumeration of types of tokens.
3636
class TokenType {
3737
/// A `(` character.
38-
static const leftParen = const TokenType._("left paren");
38+
static const leftParen = TokenType._("left paren");
3939

4040
/// A `)` character.
41-
static const rightParen = const TokenType._("right paren");
41+
static const rightParen = TokenType._("right paren");
4242

4343
/// A `||` sequence.
44-
static const or = const TokenType._("or");
44+
static const or = TokenType._("or");
4545

4646
/// A `&&` sequence.
47-
static const and = const TokenType._("and");
47+
static const and = TokenType._("and");
4848

4949
/// A `!` character.
50-
static const not = const TokenType._("not");
50+
static const not = TokenType._("not");
5151

5252
/// A `?` character.
53-
static const questionMark = const TokenType._("question mark");
53+
static const questionMark = TokenType._("question mark");
5454

5555
/// A `:` character.
56-
static const colon = const TokenType._("colon");
56+
static const colon = TokenType._("colon");
5757

5858
/// A named identifier.
59-
static const identifier = const TokenType._("identifier");
59+
static const identifier = TokenType._("identifier");
6060

6161
/// The end of the selector.
62-
static const endOfFile = const TokenType._("end of file");
62+
static const endOfFile = TokenType._("end of file");
6363

6464
/// The name of the token type.
6565
final String name;

lib/src/union_selector.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ class UnionSelector implements BooleanSelector {
1919
_selector1.evaluate(semantics) || _selector2.evaluate(semantics);
2020

2121
BooleanSelector intersection(BooleanSelector other) =>
22-
new IntersectionSelector(this, other);
22+
IntersectionSelector(this, other);
2323

24-
BooleanSelector union(BooleanSelector other) =>
25-
new UnionSelector(this, other);
24+
BooleanSelector union(BooleanSelector other) => UnionSelector(this, other);
2625

2726
void validate(bool isDefined(String variable)) {
2827
_selector1.validate(isDefined);

lib/src/validator.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:source_span/source_span.dart';
77
import 'ast.dart';
88
import 'visitor.dart';
99

10-
typedef bool _IsDefined(String variable);
10+
typedef _IsDefined = bool Function(String variable);
1111

1212
/// An AST visitor that ensures that all variables are valid.
1313
class Validator extends RecursiveVisitor {
@@ -17,6 +17,6 @@ class Validator extends RecursiveVisitor {
1717

1818
void visitVariable(VariableNode node) {
1919
if (_isDefined(node.name)) return;
20-
throw new SourceSpanFormatException("Undefined variable.", node.span);
20+
throw SourceSpanFormatException("Undefined variable.", node.span);
2121
}
2222
}

pubspec.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
name: boolean_selector
2-
version: 1.0.4
2+
version: 1.0.5-dev
33
description: A flexible syntax for boolean expressions.
44
author: Dart Team <[email protected]>
55
homepage: https://github.com/dart-lang/boolean_selector
66

77
environment:
8-
sdk: '>=2.0.0-dev.58 <3.0.0'
8+
sdk: '>=2.0.0 <3.0.0'
99

1010
dependencies:
11-
source_span: '^1.0.0'
11+
source_span: ^1.0.0
1212
string_scanner: '>=0.1.1 <2.0.0'
1313

1414
dev_dependencies:
15+
pedantic: ^1.0.0
1516
test: ^1.2.0

0 commit comments

Comments
 (0)