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

Commit ec86ee5

Browse files
authored
Require Dart 3.0, update and fix lints (#194)
1 parent 1ad2d1e commit ec86ee5

13 files changed

+202
-310
lines changed

.github/workflows/test-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
matrix:
4848
# Add macos-latest and/or windows-latest if relevant for this package.
4949
os: [ubuntu-latest, windows-latest]
50-
sdk: [2.19.0, dev]
50+
sdk: [3.0, dev]
5151
steps:
5252
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
5353
- 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+
## 1.0.1-wip
2+
3+
- Require Dart 3.0
4+
15
## 1.0.0
26

37
- Rev to `1.0.0` (note however that there are no API changes from `0.17.x`).

analysis_options.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ analyzer:
55
strict-casts: true
66
strict-inference: true
77
strict-raw-types: true
8+
errors:
9+
comment_references: ignore #too many false positives
10+
11+
linter:
12+
rules:
13+
- prefer_expression_function_bodies

example/main.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ StyleSheet parseCss(
8484
String cssInput, {
8585
List<css.Message>? errors,
8686
css.PreprocessorOptions? opts,
87-
}) {
88-
return css.parse(cssInput, errors: errors, options: opts ?? _default);
89-
}
87+
}) =>
88+
css.parse(cssInput, errors: errors, options: opts ?? _default);
9089

9190
/// Pretty printer for CSS.
9291
String prettyPrint(StyleSheet ss) =>

lib/parser.dart

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ParserState extends TokenizerState {
3838

3939
void _createMessages({List<Message>? errors, PreprocessorOptions? options}) {
4040
errors ??= [];
41-
options ??= PreprocessorOptions(useColors: false, inputFile: 'memory');
41+
options ??= const PreprocessorOptions(useColors: false, inputFile: 'memory');
4242

4343
messages = Messages(options: options, printHandler: errors.add);
4444
}
@@ -258,24 +258,18 @@ class _Parser {
258258
///////////////////////////////////////////////////////////////////
259259
// Basic support methods
260260
///////////////////////////////////////////////////////////////////
261-
int _peek() {
262-
return _peekToken.kind;
263-
}
261+
int _peek() => _peekToken.kind;
264262

265263
Token _next({bool unicodeRange = false}) {
266264
final next = _previousToken = _peekToken;
267265
_peekToken = tokenizer.next(unicodeRange: unicodeRange);
268266
return next;
269267
}
270268

271-
bool _peekKind(int kind) {
272-
return _peekToken.kind == kind;
273-
}
269+
bool _peekKind(int kind) => _peekToken.kind == kind;
274270

275271
// Is the next token a legal identifier? This includes pseudo-keywords.
276-
bool _peekIdentifier() {
277-
return TokenKind.isIdentifier(_peekToken.kind);
278-
}
272+
bool _peekIdentifier() => TokenKind.isIdentifier(_peekToken.kind);
279273

280274
/// Marks the parser/tokenizer look ahead to support Less nested selectors.
281275
ParserState get _mark => ParserState(_peekToken, _previousToken, tokenizer);
@@ -792,9 +786,8 @@ class _Parser {
792786
}
793787

794788
var declGroup = processDeclarations(checkBrace: false);
795-
if (declGroup.declarations.any((decl) {
796-
return decl is Declaration && decl is! IncludeMixinAtDeclaration;
797-
})) {
789+
if (declGroup.declarations.any((decl) =>
790+
decl is Declaration && decl is! IncludeMixinAtDeclaration)) {
798791
var newDecls = <Declaration>[];
799792
for (var include in productions) {
800793
// If declGroup has items that are declarations then we assume
@@ -2038,40 +2031,31 @@ class _Parser {
20382031
DartStyleExpression? processOneNumber(Expressions exprs, int part) {
20392032
var value = marginValue(exprs.expressions[0]);
20402033
if (value != null) {
2041-
switch (part) {
2042-
case _marginPartLeft:
2043-
return MarginExpression(exprs.span, left: value);
2044-
case _marginPartTop:
2045-
return MarginExpression(exprs.span, top: value);
2046-
case _marginPartRight:
2047-
return MarginExpression(exprs.span, right: value);
2048-
case _marginPartBottom:
2049-
return MarginExpression(exprs.span, bottom: value);
2050-
case _borderPartLeft:
2051-
case _borderPartLeftWidth:
2052-
return BorderExpression(exprs.span, left: value);
2053-
case _borderPartTop:
2054-
case _borderPartTopWidth:
2055-
return BorderExpression(exprs.span, top: value);
2056-
case _borderPartRight:
2057-
case _borderPartRightWidth:
2058-
return BorderExpression(exprs.span, right: value);
2059-
case _borderPartBottom:
2060-
case _borderPartBottomWidth:
2061-
return BorderExpression(exprs.span, bottom: value);
2062-
case _heightPart:
2063-
return HeightExpression(exprs.span, value);
2064-
case _widthPart:
2065-
return WidthExpression(exprs.span, value);
2066-
case _paddingPartLeft:
2067-
return PaddingExpression(exprs.span, left: value);
2068-
case _paddingPartTop:
2069-
return PaddingExpression(exprs.span, top: value);
2070-
case _paddingPartRight:
2071-
return PaddingExpression(exprs.span, right: value);
2072-
case _paddingPartBottom:
2073-
return PaddingExpression(exprs.span, bottom: value);
2074-
}
2034+
return switch (part) {
2035+
_marginPartLeft => MarginExpression(exprs.span, left: value),
2036+
_marginPartTop => MarginExpression(exprs.span, top: value),
2037+
_marginPartRight => MarginExpression(exprs.span, right: value),
2038+
_marginPartBottom => MarginExpression(exprs.span, bottom: value),
2039+
_borderPartLeft ||
2040+
_borderPartLeftWidth =>
2041+
BorderExpression(exprs.span, left: value),
2042+
_borderPartTop ||
2043+
_borderPartTopWidth =>
2044+
BorderExpression(exprs.span, top: value),
2045+
_borderPartRight ||
2046+
_borderPartRightWidth =>
2047+
BorderExpression(exprs.span, right: value),
2048+
_borderPartBottom ||
2049+
_borderPartBottomWidth =>
2050+
BorderExpression(exprs.span, bottom: value),
2051+
_heightPart => HeightExpression(exprs.span, value),
2052+
_widthPart => WidthExpression(exprs.span, value),
2053+
_paddingPartLeft => PaddingExpression(exprs.span, left: value),
2054+
_paddingPartTop => PaddingExpression(exprs.span, top: value),
2055+
_paddingPartRight => PaddingExpression(exprs.span, right: value),
2056+
_paddingPartBottom => PaddingExpression(exprs.span, bottom: value),
2057+
_ => null
2058+
};
20752059
}
20762060
return null;
20772061
}

lib/src/messages.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Messages {
8686
final List<Message> messages = <Message>[];
8787

8888
Messages({PreprocessorOptions? options, this.printHandler = print})
89-
: options = options ?? PreprocessorOptions();
89+
: options = options ?? const PreprocessorOptions();
9090

9191
/// Report a compile-time CSS error.
9292
void error(String message, SourceSpan? span) {

lib/src/property.dart

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,12 @@ class Rgba implements _StyleProperty, ColorBase {
504504

505505
factory Rgba.fromColor(Color color) => color.rgba;
506506

507-
factory Rgba.fromArgbValue(num value) {
508-
return Rgba(
509-
(value.toInt() & 0xff000000) >> 0x18, // a
510-
(value.toInt() & 0xff0000) >> 0x10, // r
511-
(value.toInt() & 0xff00) >> 8, // g
512-
value.toInt() & 0xff,
513-
); // b
514-
}
507+
factory Rgba.fromArgbValue(num value) => Rgba(
508+
(value.toInt() & 0xff000000) >> 0x18, // a
509+
(value.toInt() & 0xff0000) >> 0x10, // r
510+
(value.toInt() & 0xff00) >> 8, // g
511+
value.toInt() & 0xff,
512+
); // b
515513

516514
factory Rgba.fromHsla(Hsla hsla) {
517515
// Convert to Rgba.
@@ -752,10 +750,9 @@ class PointXY implements _StyleProperty {
752750
const PointXY(this.x, this.y);
753751

754752
@override
755-
String? get cssExpression {
756-
// TODO(terry): TBD
757-
return null;
758-
}
753+
String? get cssExpression =>
754+
// TODO(terry): TBD
755+
null;
759756
}
760757

761758
// TODO(terry): Implement style and color.
@@ -779,14 +776,12 @@ class Border implements _StyleProperty {
779776
int get height => top! + bottom!;
780777

781778
@override
782-
String get cssExpression {
783-
return (top == left && bottom == right && top == right)
784-
? '${left}px'
785-
: "${top != null ? '$top' : '0'}px "
786-
"${right != null ? '$right' : '0'}px "
787-
"${bottom != null ? '$bottom' : '0'}px "
788-
"${left != null ? '$left' : '0'}px";
789-
}
779+
String get cssExpression => (top == left && bottom == right && top == right)
780+
? '${left}px'
781+
: "${top != null ? '$top' : '0'}px "
782+
"${right != null ? '$right' : '0'}px "
783+
"${bottom != null ? '$bottom' : '0'}px "
784+
"${left != null ? '$left' : '0'}px";
790785
}
791786

792787
/// Font style constants.
@@ -1069,10 +1064,9 @@ class Font implements _StyleProperty {
10691064
}
10701065

10711066
@override
1072-
int get hashCode {
1073-
// TODO(jimhug): Lot's of potential collisions here. List of fonts, etc.
1074-
return size!.toInt() % family![0].hashCode;
1075-
}
1067+
int get hashCode =>
1068+
// TODO(jimhug): Lot's of potential collisions here. List of fonts, etc.
1069+
size!.toInt() % family![0].hashCode;
10761070

10771071
@override
10781072
bool operator ==(Object other) {

0 commit comments

Comments
 (0)