Skip to content

Commit

Permalink
Transform all enum-like classes to dart enums (#1777)
Browse files Browse the repository at this point in the history
* 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]"
  • Loading branch information
Goodwine authored Aug 17, 2022
1 parent a987352 commit 0b8a0f6
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 97 deletions.
35 changes: 16 additions & 19 deletions lib/src/ast/sass/expression/binary_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,51 +88,48 @@ class BinaryOperationExpression implements Expression {
/// A binary operator constant.
///
/// {@category AST}
@sealed
class BinaryOperator {
enum BinaryOperator {
/// The Microsoft equals operator, `=`.
static const singleEquals = BinaryOperator._("single equals", "=", 0);
singleEquals('single equals', '=', 0),

/// The disjunction operator, `or`.
static const or = BinaryOperator._("or", "or", 1);
or('or', 'or', 1),

/// The conjunction operator, `and`.
static const and = BinaryOperator._("and", "and", 2);
and('and', 'and', 2),

/// The equality operator, `==`.
static const equals = BinaryOperator._("equals", "==", 3);
equals('equals', '==', 3),

/// The inequality operator, `!=`.
static const notEquals = BinaryOperator._("not equals", "!=", 3);
notEquals('not equals', '!=', 3),

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

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

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

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

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

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

/// The multiplication operator, `*`.
static const times = BinaryOperator._("times", "*", 6);
times('times', '*', 6),

/// The division operator, `/`.
static const dividedBy = BinaryOperator._("divided by", "/", 6);
dividedBy('divided by', '/', 6),

/// The modulo operator, `%`.
static const modulo = BinaryOperator._("modulo", "%", 6);
modulo('modulo', '%', 6);

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

const BinaryOperator._(this.name, this.operator, this.precedence);
const BinaryOperator(this.name, this.operator, this.precedence);

String toString() => name;
}
13 changes: 6 additions & 7 deletions lib/src/ast/sass/expression/unary_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,28 @@ class UnaryOperationExpression implements Expression {
/// A unary operator constant.
///
/// {@category AST}
@sealed
class UnaryOperator {
enum UnaryOperator {
/// The numeric identity operator, `+`.
static const plus = UnaryOperator._("plus", "+");
plus('plus', '+'),

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

/// The leading slash operator, `/`.
///
/// This is a historical artifact.
static const divide = UnaryOperator._("divide", "/");
divide('divide', '/'),

/// The boolean negation operator, `not`.
static const not = UnaryOperator._("not", "not");
not('not', 'not');

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

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

const UnaryOperator._(this.name, this.operator);
const UnaryOperator(this.name, this.operator);

String toString() => name;
}
16 changes: 8 additions & 8 deletions lib/src/ast/selector/attribute.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,31 @@ class AttributeSelector extends SimpleSelector {
}

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

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

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

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

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

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

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

const AttributeOperator._(this._text);
const AttributeOperator(this._text);

String toString() => _text;
}
13 changes: 5 additions & 8 deletions lib/src/ast/selector/combinator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import 'package:meta/meta.dart';

/// A combinator that defines the relationship between selectors in a
/// [ComplexSelector].
///
/// {@category AST}
@sealed
class Combinator {
enum Combinator {
/// Matches the right-hand selector if it's immediately adjacent to the
/// left-hand selector in the DOM tree.
static const nextSibling = Combinator._("+");
nextSibling('+'),

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

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

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

const Combinator._(this._text);
const Combinator(this._text);

String toString() => _text;
}
2 changes: 1 addition & 1 deletion lib/src/callable/async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class AsyncCallable {
/// The argument declaration is parsed from [arguments], which should not
/// include parentheses. Throws a [SassFormatException] if parsing fails.
///
/// See [new Callable] for more details.
/// See [Callable.new] for more details.
factory AsyncCallable.function(String name, String arguments,
FutureOr<Value> callback(List<Value> arguments)) =>
AsyncBuiltInCallable.function(name, arguments, callback);
Expand Down
10 changes: 5 additions & 5 deletions lib/src/extend/mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
// https://opensource.org/licenses/MIT.

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

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

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

/// The name of the mode.
final String name;

const ExtendMode._(this.name);
const ExtendMode(this.name);

String toString() => name;
}
2 changes: 1 addition & 1 deletion lib/src/functions/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ SassColor _transparentize(List<Value> arguments) {
.clamp(0, 1));
}

/// Like [new BuiltInCallable.function], but always sets the URL to
/// Like [BuiltInCallable.function], but always sets the URL to
/// `sass:color`.
BuiltInCallable _function(
String name, String arguments, Value callback(List<Value> arguments)) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/src/functions/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ final _slash = _function("slash", r"$elements...", (arguments) {
return SassList(list, ListSeparator.slash);
});

/// Like [new BuiltInCallable.function], but always sets the URL to `sass:list`.
/// Like [BuiltInCallable.function], but always sets the URL to `sass:list`.
BuiltInCallable _function(
String name, String arguments, Value callback(List<Value> arguments)) =>
BuiltInCallable.function(name, arguments, callback, url: "sass:list");
2 changes: 1 addition & 1 deletion lib/src/functions/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ SassMap _deepMergeImpl(SassMap map1, SassMap map2) {
return SassMap(result);
}

/// Like [new BuiltInCallable.function], but always sets the URL to `sass:map`.
/// Like [BuiltInCallable.function], but always sets the URL to `sass:map`.
BuiltInCallable _function(
String name, String arguments, Value callback(List<Value> arguments)) =>
BuiltInCallable.function(name, arguments, callback, url: "sass:map");
2 changes: 1 addition & 1 deletion lib/src/functions/math.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ BuiltInCallable _numberFunction(String name, num transform(num value)) {
});
}

/// Like [new _function.function], but always sets the URL to `sass:math`.
/// Like [_function.function], but always sets the URL to `sass:math`.
BuiltInCallable _function(
String name, String arguments, Value callback(List<Value> arguments)) =>
BuiltInCallable.function(name, arguments, callback, url: "sass:math");
2 changes: 1 addition & 1 deletion lib/src/functions/meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final local = UnmodifiableListView([
})
]);

/// Like [new BuiltInCallable.function], but always sets the URL to `sass:meta`.
/// Like [BuiltInCallable.function], but always sets the URL to `sass:meta`.
BuiltInCallable _function(
String name, String arguments, Value callback(List<Value> arguments)) =>
BuiltInCallable.function(name, arguments, callback, url: "sass:meta");
2 changes: 1 addition & 1 deletion lib/src/functions/selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ CompoundSelector? _prependParent(CompoundSelector compound) {
}
}

/// Like [new BuiltInCallable.function], but always sets the URL to
/// Like [BuiltInCallable.function], but always sets the URL to
/// `sass:selector`.
BuiltInCallable _function(
String name, String arguments, Value callback(List<Value> arguments)) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/src/functions/string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int _codepointForIndex(int index, int lengthInCodepoints,
return result;
}

/// Like [new BuiltInCallable.function], but always sets the URL to
/// Like [BuiltInCallable.function], but always sets the URL to
/// `sass:string`.
BuiltInCallable _function(
String name, String arguments, Value callback(List<Value> arguments)) =>
Expand Down
12 changes: 5 additions & 7 deletions lib/src/syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;

/// An enum of syntaxes that Sass can parse.
///
/// {@category Compile}
@sealed
class Syntax {
enum Syntax {
/// The CSS-superset SCSS syntax.
static const scss = Syntax._("SCSS");
scss('SCSS'),

/// The whitespace-sensitive indented syntax.
static const sass = Syntax._("Sass");
sass('Sass'),

/// The plain CSS syntax, which disallows special Sass features.
static const css = Syntax._("CSS");
css('CSS');

/// Returns the default syntax to use for a file loaded from [path].
static Syntax forPath(String path) {
Expand All @@ -34,7 +32,7 @@ class Syntax {
/// The name of the syntax.
final String _name;

const Syntax._(this._name);
const Syntax(this._name);

String toString() => _name;
}
2 changes: 1 addition & 1 deletion lib/src/value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export 'value/string.dart';
/// A SassScript value.
///
/// All SassScript values are unmodifiable. New values can be constructed using
/// subclass constructors like [new SassString]. Untyped values can be cast to
/// subclass constructors like [SassString.new]. Untyped values can be cast to
/// particular types using `assert*()` functions like [assertString], which
/// throw user-friendly error messages if they fail.
///
Expand Down
13 changes: 6 additions & 7 deletions lib/src/value/calculation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -365,19 +365,18 @@ class CalculationOperation {
/// An enumeration of possible operators for [CalculationOperation].
///
/// {@category Value}
@sealed
class CalculationOperator {
enum CalculationOperator {
/// The addition operator.
static const plus = CalculationOperator._("plus", "+", 1);
plus('plus', '+', 1),

/// The subtraction operator.
static const minus = CalculationOperator._("minus", "-", 1);
minus('minus', '-', 1),

/// The multiplication operator.
static const times = CalculationOperator._("times", "*", 2);
times('times', '*', 2),

/// The division operator.
static const dividedBy = CalculationOperator._("divided by", "/", 2);
dividedBy('divided by', '/', 2);

/// The English name of [this].
final String name;
Expand All @@ -393,7 +392,7 @@ class CalculationOperator {
@internal
final int precedence;

const CalculationOperator._(this.name, this.operator, this.precedence);
const CalculationOperator(this.name, this.operator, this.precedence);

String toString() => name;
}
Expand Down
Loading

0 comments on commit 0b8a0f6

Please sign in to comment.