check method
void
check(
- DcqRegistry registry
)
Implementation
@override
void check(
DcqRegistry registry,
) {
registry.addIfElement((node) {
if (node.caseClause != null) return;
if (node.elseElement != null) return;
final condition = node.expression;
final thenElement = node.thenElement;
if (condition is! BinaryExpression) return;
if (condition.operator.lexeme != '!=') return;
final String? checkedName;
if (condition.rightOperand is NullLiteral) {
checkedName = _expressionSource(condition.leftOperand);
} else if (condition.leftOperand is NullLiteral) {
checkedName = _expressionSource(condition.rightOperand);
} else {
return;
}
if (checkedName == null) return;
if ((configBool(ruleConfig, 'ignore-nullable-chains') ?? true) &&
checkedName.contains('?.')) {
return;
}
if (thenElement is Expression) {
if (thenElement.toSource() == checkedName) {
reportAtNode(node);
}
}
});
}