Skip to content

Commit 7bef2dd

Browse files
RohitSailyCommit Queue
authored andcommitted
Fix literal_only_boolean_expressions Adjacent-Strings False-Positives
Change-Id: Ia3798ed4ba7e6128ad4e86458b9240918d7bedef Bug: #61903 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461560 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Auto-Submit: Rohit Saily <hello@rohitsaily.com>
1 parent d4f2fec commit 7bef2dd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pkg/linter/lib/src/rules/literal_only_boolean_expressions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const _desc = r'Boolean expression composed only with literals.';
1717
bool _onlyLiterals(Expression? rawExpression) {
1818
var expression = rawExpression?.unParenthesized;
1919
if (expression is Literal) {
20-
return expression is! StringInterpolation ||
20+
return expression is! StringLiteral ||
2121
expression.computeConstantValue() != null;
2222
}
2323
if (expression is PrefixExpression) {

pkg/linter/test/rules/literal_only_boolean_expressions_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ class LiteralOnlyBooleanExpressionsTest extends LintRuleTest {
1717
@override
1818
String get lintRule => LintNames.literal_only_boolean_expressions;
1919

20+
test_adjacent_string_interpolation_constant() async {
21+
await assertDiagnostics(
22+
r'''
23+
void f() {
24+
const a = 20;
25+
if ('$a' '0' == 20) {}
26+
}
27+
''',
28+
[lint(29, 22)],
29+
);
30+
}
31+
32+
test_adjacent_string_interpolation_nonconstant() async {
33+
await assertNoDiagnostics(r'''
34+
void f(int a) {
35+
if ('$a' '0' == 20) {}
36+
}
37+
''');
38+
}
39+
2040
test_doWhile_false() async {
2141
await assertDiagnostics(
2242
r'''

0 commit comments

Comments
 (0)