handle raw strings in prefer_interpolation_to_compose_strings (#2492)
diff --git a/lib/src/rules/prefer_interpolation_to_compose_strings.dart b/lib/src/rules/prefer_interpolation_to_compose_strings.dart
index 6198dc6..c835508 100644
--- a/lib/src/rules/prefer_interpolation_to_compose_strings.dart
+++ b/lib/src/rules/prefer_interpolation_to_compose_strings.dart
@@ -60,20 +60,23 @@
return;
}
if (node.operator.type == TokenType.PLUS) {
+ var leftOperand = node.leftOperand;
+ var rightOperand = node.rightOperand;
//OK(#735): str1 + str2
- if (node.leftOperand is! StringLiteral &&
- node.rightOperand is! StringLiteral) {
+ if (leftOperand is! StringLiteral && rightOperand is! StringLiteral) {
+ return;
+ }
+ //OK(#2490): str1 + r''
+ if (leftOperand is SimpleStringLiteral && leftOperand.isRaw ||
+ rightOperand is SimpleStringLiteral && rightOperand.isRaw) {
return;
}
//OK: 'foo' + 'bar'
- if (node.leftOperand is StringLiteral &&
- node.rightOperand is StringLiteral) {
+ if (leftOperand is StringLiteral && rightOperand is StringLiteral) {
return;
}
- if (DartTypeUtilities.isClass(
- node.leftOperand.staticType, 'String', 'dart.core') ||
- DartTypeUtilities.isClass(
- node.rightOperand.staticType, 'String', 'dart.core')) {
+ if ((leftOperand.staticType?.isDartCoreString ?? false) ||
+ (rightOperand.staticType?.isDartCoreString ?? false)) {
DartTypeUtilities.traverseNodesInDFS(node).forEach(skippedNodes.add);
rule.reportLint(node);
}
diff --git a/test/rules/prefer_interpolation_to_compose_strings.dart b/test/rules/prefer_interpolation_to_compose_strings.dart
index e5c3f8d..e906224 100644
--- a/test/rules/prefer_interpolation_to_compose_strings.dart
+++ b/test/rules/prefer_interpolation_to_compose_strings.dart
@@ -26,3 +26,8 @@
var str2 = 'World';
var str3 = str1 + str2; // OK (#735)
}
+
+issue2490() {
+ final String foo = 'Hello';
+ final String bar = foo + r' /world\'; // OK
+}