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

Require Dart 3.1, bump and fix lints, use switch expressions #55

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [2.17.0, dev]
sdk: [3.1.0, dev]
kevmoo marked this conversation as resolved.
Show resolved Hide resolved
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.2-wip

* Increase the SDK minimum to `3.1.0`.

## 2.1.1

* Increase the SDK minimum to `2.17.0`.
Expand Down
10 changes: 1 addition & 9 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
include: package:lints/recommended.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

linter:
rules:
- always_declare_return_types
- avoid_dynamic_calls
- avoid_unused_constructor_parameters
- cancel_subscriptions
- directives_ordering
- omit_local_variable_types
- package_api_docs
- prefer_single_quotes
- test_types_in_equals
- throw_in_finally
- unawaited_futures
4 changes: 2 additions & 2 deletions lib/boolean_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ abstract class BooleanSelector {
bool evaluate(bool Function(String variable) semantics);

/// Returns a new [BooleanSelector] that matches only inputs matched by both
/// [this] and [other].
/// `this` and [other].
BooleanSelector intersection(BooleanSelector other);

/// Returns a new [BooleanSelector] that matches all inputs matched by either
/// [this] or [other].
/// `this` or [other].
BooleanSelector union(BooleanSelector other);

/// Throws a [FormatException] if any variables are undefined.
Expand Down
12 changes: 6 additions & 6 deletions lib/src/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class Node {
/// All the variables in this node, in the order they appear.
Iterable<String> get variables;

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

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

@override
bool operator ==(other) => other is VariableNode && name == other.name;
bool operator ==(Object other) => other is VariableNode && name == other.name;

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

@override
bool operator ==(other) => other is NotNode && child == other.child;
bool operator ==(Object other) => other is NotNode && child == other.child;

@override
int get hashCode => ~child.hashCode;
Expand Down Expand Up @@ -109,7 +109,7 @@ class OrNode implements Node {
}

@override
bool operator ==(other) =>
bool operator ==(Object other) =>
other is OrNode && left == other.left && right == other.right;

@override
Expand Down Expand Up @@ -148,7 +148,7 @@ class AndNode implements Node {
}

@override
bool operator ==(other) =>
bool operator ==(Object other) =>
other is AndNode && left == other.left && right == other.right;

@override
Expand Down Expand Up @@ -190,7 +190,7 @@ class ConditionalNode implements Node {
}

@override
bool operator ==(other) =>
bool operator ==(Object other) =>
other is ConditionalNode &&
condition == other.condition &&
whenTrue == other.whenTrue &&
Expand Down
10 changes: 6 additions & 4 deletions lib/src/impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:source_span/source_span.dart';

import '../boolean_selector.dart';
import 'ast.dart';
import 'evaluator.dart';
Expand All @@ -12,9 +14,9 @@ import 'validator.dart';

/// The concrete implementation of a [BooleanSelector] parsed from a string.
///
/// This is separate from [BooleanSelector] so that [intersect] and [union] can
/// check to see whether they're passed a [BooleanSelectorImpl] or a different
/// class that implements [BooleanSelector].
/// This is separate from [BooleanSelector] so that [intersection] and [union]
/// can check to see whether they're passed a [BooleanSelectorImpl] or a
/// different class that implements [BooleanSelector].
class BooleanSelectorImpl implements BooleanSelector {
/// The parsed AST.
final Node _selector;
Expand Down Expand Up @@ -62,7 +64,7 @@ class BooleanSelectorImpl implements BooleanSelector {
String toString() => _selector.toString();

@override
bool operator ==(other) =>
bool operator ==(Object other) =>
other is BooleanSelectorImpl && _selector == other._selector;

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/src/intersection_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IntersectionSelector implements BooleanSelector {
IntersectionSelector(this._selector1, this._selector2);

@override
bool evaluate(semantics) =>
bool evaluate(bool Function(String variable) semantics) =>
_selector1.evaluate(semantics) && _selector2.evaluate(semantics);

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

@override
bool operator ==(other) =>
bool operator ==(Object other) =>
other is IntersectionSelector &&
_selector1 == other._selector1 &&
_selector2 == other._selector2;
Expand Down
28 changes: 10 additions & 18 deletions lib/src/scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,16 @@ class Scanner {
return Token(TokenType.endOfFile, _scanner.spanFrom(_scanner.state));
}

switch (_scanner.peekChar()) {
case 0x28 /* ( */ :
return _scanOperator(TokenType.leftParen);
case 0x29 /* ) */ :
return _scanOperator(TokenType.rightParen);
case 0x3F /* ? */ :
return _scanOperator(TokenType.questionMark);
case 0x3A /* : */ :
return _scanOperator(TokenType.colon);
case 0x21 /* ! */ :
return _scanOperator(TokenType.not);
case 0x7C /* | */ :
return _scanOr();
case 0x26 /* & */ :
return _scanAnd();
default:
return _scanIdentifier();
}
return switch (_scanner.peekChar()) {
0x28 /* ( */ => _scanOperator(TokenType.leftParen),
0x29 /* ) */ => _scanOperator(TokenType.rightParen),
0x3F /* ? */ => _scanOperator(TokenType.questionMark),
0x3A /* : */ => _scanOperator(TokenType.colon),
0x21 /* ! */ => _scanOperator(TokenType.not),
0x7C /* | */ => _scanOr(),
0x26 /* & */ => _scanAnd(),
_ => _scanIdentifier()
};
}

/// Scans a single-character operator and returns a token of type [type].
Expand Down
2 changes: 1 addition & 1 deletion lib/src/union_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class UnionSelector implements BooleanSelector {
String toString() => '($_selector1) && ($_selector2)';

@override
bool operator ==(other) =>
bool operator ==(Object other) =>
other is UnionSelector &&
_selector1 == other._selector1 &&
_selector2 == other._selector2;
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: boolean_selector
version: 2.1.1
version: 2.1.2-wip
description: >-
A flexible syntax for boolean expressions, based on a simplified version of
Dart's expression syntax.
repository: https://github.com/dart-lang/boolean_selector

environment:
sdk: '>=2.17.0 <3.0.0'
sdk: ^3.1.0

dependencies:
source_span: ^1.8.0
string_scanner: ^1.1.0

dev_dependencies:
lints: ^2.0.0
dart_flutter_team_lints: ^2.0.0
test: ^1.16.0
8 changes: 4 additions & 4 deletions test/parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import 'package:boolean_selector/src/parser.dart';
import 'package:test/test.dart';

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

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

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

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

void main() {
group('parses a conditional expression', () {
Expand Down
2 changes: 1 addition & 1 deletion test/scanner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:boolean_selector/src/token.dart';
import 'package:test/test.dart';

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

void main() {
group('peek()', () {
Expand Down