visitExpression method

void visitExpression(
  1. Expression? node
)

Implementation

void visitExpression(Expression? node) {
  // if (isAncestorDesignSystem(node)) return;
  final expressions = getExpressionsThatMatch(node, hasAnnotatedProperty);
  for (final expression in expressions) {
    // get the int value of the color code
    if (expression is InstanceCreationExpression) {
      final value = expression.argumentList.arguments.first;
      if (value is IntegerLiteral) {
        final colorValueAsHex = value.value?.toRadixString(16).toUpperCase();
        reportLint(
          value,
          message: 'IntegerLiteral Color value is $colorValueAsHex',
        );
        continue;
      }
    } else if (expression is PrefixedIdentifier) {
      final colorElement = expression.staticElement!;
      if (colorElement is PropertyAccessorElement) {
        final colorValue = colorElement.variable.computeConstantValue();
        final constantReader = ConstantReader(colorValue);
        final colorIntValue = constantReader.read('value').intValue;
        final colorValueAsHex = colorIntValue.toRadixString(16).toUpperCase();
        reportLint(
          expression,
          message:
              'PropertyAccessorElement Color value is 0x$colorValueAsHex',
        );
        continue;
      }

      reportLint(expression, message: 'Unknown color value');
    }
  }
}