Skip to content

Commit 0b8a0f6

Browse files
authored
Transform all enum-like classes to dart enums (#1777)
* Transform all enum-like classes to dart enums Fixes #1746 * fix new linter warnings upon upgrading to 2.17 regarding "[new MyClass]" to "[MyClass.new]"
1 parent a987352 commit 0b8a0f6

File tree

20 files changed

+77
-97
lines changed

20 files changed

+77
-97
lines changed

lib/src/ast/sass/expression/binary_operation.dart

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,51 +88,48 @@ class BinaryOperationExpression implements Expression {
8888
/// A binary operator constant.
8989
///
9090
/// {@category AST}
91-
@sealed
92-
class BinaryOperator {
91+
enum BinaryOperator {
9392
/// The Microsoft equals operator, `=`.
94-
static const singleEquals = BinaryOperator._("single equals", "=", 0);
93+
singleEquals('single equals', '=', 0),
9594

9695
/// The disjunction operator, `or`.
97-
static const or = BinaryOperator._("or", "or", 1);
96+
or('or', 'or', 1),
9897

9998
/// The conjunction operator, `and`.
100-
static const and = BinaryOperator._("and", "and", 2);
99+
and('and', 'and', 2),
101100

102101
/// The equality operator, `==`.
103-
static const equals = BinaryOperator._("equals", "==", 3);
102+
equals('equals', '==', 3),
104103

105104
/// The inequality operator, `!=`.
106-
static const notEquals = BinaryOperator._("not equals", "!=", 3);
105+
notEquals('not equals', '!=', 3),
107106

108107
/// The greater-than operator, `>`.
109-
static const greaterThan = BinaryOperator._("greater than", ">", 4);
108+
greaterThan('greater than', '>', 4),
110109

111110
/// The greater-than-or-equal-to operator, `>=`.
112-
static const greaterThanOrEquals =
113-
BinaryOperator._("greater than or equals", ">=", 4);
111+
greaterThanOrEquals('greater than or equals', '>=', 4),
114112

115113
/// The less-than operator, `<`.
116-
static const lessThan = BinaryOperator._("less than", "<", 4);
114+
lessThan('less than', '<', 4),
117115

118116
/// The less-than-or-equal-to operator, `<=`.
119-
static const lessThanOrEquals =
120-
BinaryOperator._("less than or equals", "<=", 4);
117+
lessThanOrEquals('less than or equals', '<=', 4),
121118

122119
/// The addition operator, `+`.
123-
static const plus = BinaryOperator._("plus", "+", 5);
120+
plus('plus', '+', 5),
124121

125122
/// The subtraction operator, `-`.
126-
static const minus = BinaryOperator._("minus", "-", 5);
123+
minus('minus', '-', 5),
127124

128125
/// The multiplication operator, `*`.
129-
static const times = BinaryOperator._("times", "*", 6);
126+
times('times', '*', 6),
130127

131128
/// The division operator, `/`.
132-
static const dividedBy = BinaryOperator._("divided by", "/", 6);
129+
dividedBy('divided by', '/', 6),
133130

134131
/// The modulo operator, `%`.
135-
static const modulo = BinaryOperator._("modulo", "%", 6);
132+
modulo('modulo', '%', 6);
136133

137134
/// The English name of [this].
138135
final String name;
@@ -145,7 +142,7 @@ class BinaryOperator {
145142
/// An operator with higher precedence binds tighter.
146143
final int precedence;
147144

148-
const BinaryOperator._(this.name, this.operator, this.precedence);
145+
const BinaryOperator(this.name, this.operator, this.precedence);
149146

150147
String toString() => name;
151148
}

lib/src/ast/sass/expression/unary_operation.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,28 @@ class UnaryOperationExpression implements Expression {
3838
/// A unary operator constant.
3939
///
4040
/// {@category AST}
41-
@sealed
42-
class UnaryOperator {
41+
enum UnaryOperator {
4342
/// The numeric identity operator, `+`.
44-
static const plus = UnaryOperator._("plus", "+");
43+
plus('plus', '+'),
4544

4645
/// The numeric negation operator, `-`.
47-
static const minus = UnaryOperator._("minus", "-");
46+
minus('minus', '-'),
4847

4948
/// The leading slash operator, `/`.
5049
///
5150
/// This is a historical artifact.
52-
static const divide = UnaryOperator._("divide", "/");
51+
divide('divide', '/'),
5352

5453
/// The boolean negation operator, `not`.
55-
static const not = UnaryOperator._("not", "not");
54+
not('not', 'not');
5655

5756
/// The English name of [this].
5857
final String name;
5958

6059
/// The Sass syntax for [this].
6160
final String operator;
6261

63-
const UnaryOperator._(this.name, this.operator);
62+
const UnaryOperator(this.name, this.operator);
6463

6564
String toString() => name;
6665
}

lib/src/ast/selector/attribute.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,31 @@ class AttributeSelector extends SimpleSelector {
6969
}
7070

7171
/// An operator that defines the semantics of an [AttributeSelector].
72-
class AttributeOperator {
72+
enum AttributeOperator {
7373
/// The attribute value exactly equals the given value.
74-
static const equal = AttributeOperator._("=");
74+
equal('='),
7575

7676
/// The attribute value is a whitespace-separated list of words, one of which
7777
/// is the given value.
78-
static const include = AttributeOperator._("~=");
78+
include('~='),
7979

8080
/// The attribute value is either exactly the given value, or starts with the
8181
/// given value followed by a dash.
82-
static const dash = AttributeOperator._("|=");
82+
dash('|='),
8383

8484
/// The attribute value begins with the given value.
85-
static const prefix = AttributeOperator._("^=");
85+
prefix('^='),
8686

8787
/// The attribute value ends with the given value.
88-
static const suffix = AttributeOperator._("\$=");
88+
suffix('\$='),
8989

9090
/// The attribute value contains the given value.
91-
static const substring = AttributeOperator._("*=");
91+
substring('*=');
9292

9393
/// The operator's token text.
9494
final String _text;
9595

96-
const AttributeOperator._(this._text);
96+
const AttributeOperator(this._text);
9797

9898
String toString() => _text;
9999
}

lib/src/ast/selector/combinator.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,27 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import 'package:meta/meta.dart';
6-
75
/// A combinator that defines the relationship between selectors in a
86
/// [ComplexSelector].
97
///
108
/// {@category AST}
11-
@sealed
12-
class Combinator {
9+
enum Combinator {
1310
/// Matches the right-hand selector if it's immediately adjacent to the
1411
/// left-hand selector in the DOM tree.
15-
static const nextSibling = Combinator._("+");
12+
nextSibling('+'),
1613

1714
/// Matches the right-hand selector if it's a direct child of the left-hand
1815
/// selector in the DOM tree.
19-
static const child = Combinator._(">");
16+
child('>'),
2017

2118
/// Matches the right-hand selector if it comes after the left-hand selector
2219
/// in the DOM tree.
23-
static const followingSibling = Combinator._("~");
20+
followingSibling('~');
2421

2522
/// The combinator's token text.
2623
final String _text;
2724

28-
const Combinator._(this._text);
25+
const Combinator(this._text);
2926

3027
String toString() => _text;
3128
}

lib/src/callable/async.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract class AsyncCallable {
3636
/// The argument declaration is parsed from [arguments], which should not
3737
/// include parentheses. Throws a [SassFormatException] if parsing fails.
3838
///
39-
/// See [new Callable] for more details.
39+
/// See [Callable.new] for more details.
4040
factory AsyncCallable.function(String name, String arguments,
4141
FutureOr<Value> callback(List<Value> arguments)) =>
4242
AsyncBuiltInCallable.function(name, arguments, callback);

lib/src/extend/mode.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
// https://opensource.org/licenses/MIT.
44

55
/// Different modes in which extension can run.
6-
class ExtendMode {
6+
enum ExtendMode {
77
/// Normal mode, used with the `@extend` rule.
88
///
99
/// This preserves existing selectors and extends each target individually.
10-
static const normal = ExtendMode._("normal");
10+
normal('normal'),
1111

1212
/// Replace mode, used by the `selector-replace()` function.
1313
///
1414
/// This replaces existing selectors and requires every target to match to
1515
/// extend a given compound selector.
16-
static const replace = ExtendMode._("replace");
16+
replace('replace'),
1717

1818
/// All-targets mode, used by the `selector-extend()` function.
1919
///
2020
/// This preserves existing selectors but requires every target to match to
2121
/// extend a given compound selector.
22-
static const allTargets = ExtendMode._("allTargets");
22+
allTargets('allTargets');
2323

2424
/// The name of the mode.
2525
final String name;
2626

27-
const ExtendMode._(this.name);
27+
const ExtendMode(this.name);
2828

2929
String toString() => name;
3030
}

lib/src/functions/color.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ SassColor _transparentize(List<Value> arguments) {
863863
.clamp(0, 1));
864864
}
865865

866-
/// Like [new BuiltInCallable.function], but always sets the URL to
866+
/// Like [BuiltInCallable.function], but always sets the URL to
867867
/// `sass:color`.
868868
BuiltInCallable _function(
869869
String name, String arguments, Value callback(List<Value> arguments)) =>

lib/src/functions/list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ final _slash = _function("slash", r"$elements...", (arguments) {
148148
return SassList(list, ListSeparator.slash);
149149
});
150150

151-
/// Like [new BuiltInCallable.function], but always sets the URL to `sass:list`.
151+
/// Like [BuiltInCallable.function], but always sets the URL to `sass:list`.
152152
BuiltInCallable _function(
153153
String name, String arguments, Value callback(List<Value> arguments)) =>
154154
BuiltInCallable.function(name, arguments, callback, url: "sass:list");

lib/src/functions/map.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ SassMap _deepMergeImpl(SassMap map1, SassMap map2) {
218218
return SassMap(result);
219219
}
220220

221-
/// Like [new BuiltInCallable.function], but always sets the URL to `sass:map`.
221+
/// Like [BuiltInCallable.function], but always sets the URL to `sass:map`.
222222
BuiltInCallable _function(
223223
String name, String arguments, Value callback(List<Value> arguments)) =>
224224
BuiltInCallable.function(name, arguments, callback, url: "sass:map");

lib/src/functions/math.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ BuiltInCallable _numberFunction(String name, num transform(num value)) {
328328
});
329329
}
330330

331-
/// Like [new _function.function], but always sets the URL to `sass:math`.
331+
/// Like [_function.function], but always sets the URL to `sass:math`.
332332
BuiltInCallable _function(
333333
String name, String arguments, Value callback(List<Value> arguments)) =>
334334
BuiltInCallable.function(name, arguments, callback, url: "sass:math");

0 commit comments

Comments
 (0)