check method
void
check(
- DcqRegistry registry
)
Implementation
@override
void check(DcqRegistry registry) {
registry.addIndexExpression((node) {
final index = node.index;
if (index is! BinaryExpression) return;
if (index.operator.lexeme != '-') return;
final right = index.rightOperand;
if (right is! IntegerLiteral || right.value != 1) return;
final left = index.leftOperand;
String? propertyName;
if (left is PrefixedIdentifier) {
propertyName = left.identifier.name;
} else if (left is PropertyAccess) {
propertyName = left.propertyName.name;
}
if (propertyName != 'length') return;
final target = node.target;
if (target == null) return;
final targetType = target.staticType;
if (targetType is! InterfaceType || targetType.element.name != 'List') {
return;
}
if (left is PrefixedIdentifier) {
if (left.prefix.toSource() != target.toSource()) return;
} else if (left is PropertyAccess) {
final leftTarget = left.target;
if (leftTarget == null) return;
if (leftTarget.toSource() != target.toSource()) return;
}
reportAtNode(node);
});
}