visitPrefixedIdentifier method

  1. @override
R? visitPrefixedIdentifier(
  1. PrefixedIdentifier node
)
override

Implementation

@override
R? visitPrefixedIdentifier(PrefixedIdentifier node) {
  if (_shouldIgnore(node)) {
    return null;
  }

  final prefix = node.prefix.name;
  if ('Alignment' == prefix) {
    bool shouldFix = false;
    String fixResult = node.toString().replaceFirst(prefix, "${prefix}Directional");
    if (node.identifier.name.contains('Left')) {
      fixResult = fixResult.replaceFirst('Left', 'Start');
      shouldFix = true;
    }

    if (node.identifier.name.contains('Right')) {
      fixResult = fixResult.replaceFirst('Right', 'End');
      shouldFix = true;
    }

    if (!shouldFix) return null;

    final lineInfo = unit.lineInfo!;
    final begin = node.beginToken.charOffset;
    final end = node.endToken.charEnd;
    final loc = lineInfo.getLocation(begin);
    final locEnd = lineInfo.getLocation(end);

    foundRtlWidget(FoundRtlWidget(
        filePath: filePath,
        offset: node.offset,
        length: node.length,
        startLine: loc.lineNumber,
        startColumn: loc.columnNumber,
        endLine: locEnd.lineNumber,
        endColumn: locEnd.columnNumber,
        msg: 'RTL:Use ${prefix}Directional instead',
        fix: fixResult,
        error: '$prefix is not RTL campatiable'));
  }

  return super.visitPrefixedIdentifier(node);
}