Skip to content

Commit

Permalink
Allow non-literal strings in prefer_interpolation_to_compose_strings (
Browse files Browse the repository at this point in the history
#735) (#832)

Allow concatentation of two non-literal strings in `prefer_interpolation_to_compose_strings`.

Fixes: #735
  • Loading branch information
pq committed Nov 2, 2017
1 parent caf2e34 commit 7867eef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/src/rules/prefer_interpolation_to_compose_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class _Visitor extends SimpleAstVisitor {
return;
}
if (node.operator.type == TokenType.PLUS) {
//OK(#735): str1 + str2
if (node.leftOperand is! StringLiteral &&
node.rightOperand is! StringLiteral) {
return;
}
//OK: 'foo' + 'bar'
if (node.leftOperand is StringLiteral &&
node.rightOperand is StringLiteral) {
return;
Expand Down
3 changes: 3 additions & 0 deletions test/rules/prefer_interpolation_to_compose_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ void main() {
pad = pad + ' '; // LINT
}

var str1 = 'Hello';
var str2 = 'World';
var str3 = str1 + str2; // OK (#735)
}

0 comments on commit 7867eef

Please sign in to comment.