check method

  1. @override
void check(
  1. DcqRegistry registry
)

Implementation

@override
void check(
  DcqRegistry registry,
) {
  final ignoreNonStringTypes =
      configBool(ruleConfig, 'ignore-non-string-types') ?? true;
  final ignoredInstances =
      configStringList(ruleConfig, 'ignored-instances') ?? const [];

  registry.addBinaryExpression((node) {
    if (node.operator.lexeme != '+') return;

    final leftIsString = node.leftOperand is StringLiteral;
    final rightIsString = node.rightOperand is StringLiteral;

    if (!leftIsString && !rightIsString) return;
    if (leftIsString && rightIsString) return;

    final nonLiteral = leftIsString ? node.rightOperand : node.leftOperand;

    if (ignoreNonStringTypes) {
      final type = nonLiteral.staticType;
      if (type != null && !type.isDartCoreString) return;
    }

    if (ignoredInstances.isNotEmpty) {
      final type = nonLiteral.staticType;
      if (type is InterfaceType &&
          ignoredInstances.contains(type.element.name)) {
        return;
      }
    }

    reportAtNode(node);
  });
}