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;
if (left is! PrefixedIdentifier && left is! PropertyAccess) return;
String? propertyName;
String? targetSource;
if (left is PrefixedIdentifier) {
propertyName = left.identifier.name;
targetSource = left.prefix.toSource();
} else if (left is PropertyAccess) {
propertyName = left.propertyName.name;
targetSource = left.target?.toSource();
}
if (propertyName != 'length') return;
final target = node.target;
if (target == null) return;
if (target.toSource() != targetSource) return;
final targetType = target.staticType;
if (targetType is InterfaceType && targetType.element.name == 'List') {
reportAtNode(node);
}
});
}