Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit caea8d4

Browse files
authored
Require Dart 3.1, bump and fix lints, use switch expressions (#55)
1 parent 7f523c3 commit caea8d4

12 files changed

+41
-51
lines changed

.github/workflows/test-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
matrix:
4545
# Add macos-latest and/or windows-latest if relevant for this package.
4646
os: [ubuntu-latest]
47-
sdk: [2.17.0, dev]
47+
sdk: [3.1, dev]
4848
steps:
4949
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
5050
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.1.2-wip
2+
3+
* Increase the SDK minimum to `3.1.0`.
4+
15
## 2.1.1
26

37
* Increase the SDK minimum to `2.17.0`.

analysis_options.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
include: package:lints/recommended.yaml
1+
include: package:dart_flutter_team_lints/analysis_options.yaml
22

33
linter:
44
rules:
5-
- always_declare_return_types
6-
- avoid_dynamic_calls
75
- avoid_unused_constructor_parameters
86
- cancel_subscriptions
9-
- directives_ordering
10-
- omit_local_variable_types
117
- package_api_docs
12-
- prefer_single_quotes
13-
- test_types_in_equals
14-
- throw_in_finally
15-
- unawaited_futures

lib/boolean_selector.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ abstract class BooleanSelector {
4141
bool evaluate(bool Function(String variable) semantics);
4242

4343
/// Returns a new [BooleanSelector] that matches only inputs matched by both
44-
/// [this] and [other].
44+
/// `this` and [other].
4545
BooleanSelector intersection(BooleanSelector other);
4646

4747
/// Returns a new [BooleanSelector] that matches all inputs matched by either
48-
/// [this] or [other].
48+
/// `this` or [other].
4949
BooleanSelector union(BooleanSelector other);
5050

5151
/// Throws a [FormatException] if any variables are undefined.

lib/src/ast.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class Node {
2020
/// All the variables in this node, in the order they appear.
2121
Iterable<String> get variables;
2222

23-
/// Calls the appropriate [Visitor] method on [this] and returns the result.
23+
/// Calls the appropriate [Visitor] method on `this` and returns the result.
2424
T accept<T>(Visitor<T> visitor);
2525
}
2626

@@ -44,7 +44,7 @@ class VariableNode implements Node {
4444
String toString() => name;
4545

4646
@override
47-
bool operator ==(other) => other is VariableNode && name == other.name;
47+
bool operator ==(Object other) => other is VariableNode && name == other.name;
4848

4949
@override
5050
int get hashCode => name.hashCode;
@@ -71,7 +71,7 @@ class NotNode implements Node {
7171
child is VariableNode || child is NotNode ? '!$child' : '!($child)';
7272

7373
@override
74-
bool operator ==(other) => other is NotNode && child == other.child;
74+
bool operator ==(Object other) => other is NotNode && child == other.child;
7575

7676
@override
7777
int get hashCode => ~child.hashCode;
@@ -109,7 +109,7 @@ class OrNode implements Node {
109109
}
110110

111111
@override
112-
bool operator ==(other) =>
112+
bool operator ==(Object other) =>
113113
other is OrNode && left == other.left && right == other.right;
114114

115115
@override
@@ -148,7 +148,7 @@ class AndNode implements Node {
148148
}
149149

150150
@override
151-
bool operator ==(other) =>
151+
bool operator ==(Object other) =>
152152
other is AndNode && left == other.left && right == other.right;
153153

154154
@override
@@ -190,7 +190,7 @@ class ConditionalNode implements Node {
190190
}
191191

192192
@override
193-
bool operator ==(other) =>
193+
bool operator ==(Object other) =>
194194
other is ConditionalNode &&
195195
condition == other.condition &&
196196
whenTrue == other.whenTrue &&

lib/src/impl.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:source_span/source_span.dart';
6+
57
import '../boolean_selector.dart';
68
import 'ast.dart';
79
import 'evaluator.dart';
@@ -12,9 +14,9 @@ import 'validator.dart';
1214

1315
/// The concrete implementation of a [BooleanSelector] parsed from a string.
1416
///
15-
/// This is separate from [BooleanSelector] so that [intersect] and [union] can
16-
/// check to see whether they're passed a [BooleanSelectorImpl] or a different
17-
/// class that implements [BooleanSelector].
17+
/// This is separate from [BooleanSelector] so that [intersection] and [union]
18+
/// can check to see whether they're passed a [BooleanSelectorImpl] or a
19+
/// different class that implements [BooleanSelector].
1820
class BooleanSelectorImpl implements BooleanSelector {
1921
/// The parsed AST.
2022
final Node _selector;
@@ -62,7 +64,7 @@ class BooleanSelectorImpl implements BooleanSelector {
6264
String toString() => _selector.toString();
6365

6466
@override
65-
bool operator ==(other) =>
67+
bool operator ==(Object other) =>
6668
other is BooleanSelectorImpl && _selector == other._selector;
6769

6870
@override

lib/src/intersection_selector.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class IntersectionSelector implements BooleanSelector {
1919
IntersectionSelector(this._selector1, this._selector2);
2020

2121
@override
22-
bool evaluate(semantics) =>
22+
bool evaluate(bool Function(String variable) semantics) =>
2323
_selector1.evaluate(semantics) && _selector2.evaluate(semantics);
2424

2525
@override
@@ -39,7 +39,7 @@ class IntersectionSelector implements BooleanSelector {
3939
String toString() => '($_selector1) && ($_selector2)';
4040

4141
@override
42-
bool operator ==(other) =>
42+
bool operator ==(Object other) =>
4343
other is IntersectionSelector &&
4444
_selector1 == other._selector1 &&
4545
_selector2 == other._selector2;

lib/src/scanner.dart

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,16 @@ class Scanner {
7373
return Token(TokenType.endOfFile, _scanner.spanFrom(_scanner.state));
7474
}
7575

76-
switch (_scanner.peekChar()) {
77-
case 0x28 /* ( */ :
78-
return _scanOperator(TokenType.leftParen);
79-
case 0x29 /* ) */ :
80-
return _scanOperator(TokenType.rightParen);
81-
case 0x3F /* ? */ :
82-
return _scanOperator(TokenType.questionMark);
83-
case 0x3A /* : */ :
84-
return _scanOperator(TokenType.colon);
85-
case 0x21 /* ! */ :
86-
return _scanOperator(TokenType.not);
87-
case 0x7C /* | */ :
88-
return _scanOr();
89-
case 0x26 /* & */ :
90-
return _scanAnd();
91-
default:
92-
return _scanIdentifier();
93-
}
76+
return switch (_scanner.peekChar()) {
77+
0x28 /* ( */ => _scanOperator(TokenType.leftParen),
78+
0x29 /* ) */ => _scanOperator(TokenType.rightParen),
79+
0x3F /* ? */ => _scanOperator(TokenType.questionMark),
80+
0x3A /* : */ => _scanOperator(TokenType.colon),
81+
0x21 /* ! */ => _scanOperator(TokenType.not),
82+
0x7C /* | */ => _scanOr(),
83+
0x26 /* & */ => _scanAnd(),
84+
_ => _scanIdentifier()
85+
};
9486
}
9587

9688
/// Scans a single-character operator and returns a token of type [type].

lib/src/union_selector.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class UnionSelector implements BooleanSelector {
3737
String toString() => '($_selector1) && ($_selector2)';
3838

3939
@override
40-
bool operator ==(other) =>
40+
bool operator ==(Object other) =>
4141
other is UnionSelector &&
4242
_selector1 == other._selector1 &&
4343
_selector2 == other._selector2;

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
name: boolean_selector
2-
version: 2.1.1
2+
version: 2.1.2-wip
33
description: >-
44
A flexible syntax for boolean expressions, based on a simplified version of
55
Dart's expression syntax.
66
repository: https://github.com/dart-lang/boolean_selector
77

88
environment:
9-
sdk: '>=2.17.0 <3.0.0'
9+
sdk: ^3.1.0
1010

1111
dependencies:
1212
source_span: ^1.8.0
1313
string_scanner: ^1.1.0
1414

1515
dev_dependencies:
16-
lints: ^2.0.0
16+
dart_flutter_team_lints: ^2.0.0
1717
test: ^1.16.0

test/parser_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import 'package:boolean_selector/src/parser.dart';
77
import 'package:test/test.dart';
88

99
/// A matcher that asserts that a value is a [ConditionalNode].
10-
final _isConditionalNode = TypeMatcher<ConditionalNode>();
10+
const _isConditionalNode = TypeMatcher<ConditionalNode>();
1111

1212
/// A matcher that asserts that a value is an [OrNode].
13-
final _isOrNode = TypeMatcher<OrNode>();
13+
const _isOrNode = TypeMatcher<OrNode>();
1414

1515
/// A matcher that asserts that a value is an [AndNode].
16-
final _isAndNode = TypeMatcher<AndNode>();
16+
const _isAndNode = TypeMatcher<AndNode>();
1717

1818
/// A matcher that asserts that a value is a [NotNode].
19-
final _isNotNode = TypeMatcher<NotNode>();
19+
const _isNotNode = TypeMatcher<NotNode>();
2020

2121
void main() {
2222
group('parses a conditional expression', () {

test/scanner_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:boolean_selector/src/token.dart';
77
import 'package:test/test.dart';
88

99
/// A matcher that asserts that a value is a [IdentifierToken].
10-
final _isIdentifierToken = TypeMatcher<IdentifierToken>();
10+
const _isIdentifierToken = TypeMatcher<IdentifierToken>();
1111

1212
void main() {
1313
group('peek()', () {

0 commit comments

Comments
 (0)