This repository was archived by the owner on Nov 20, 2024. It is now read-only.
File tree 3 files changed +84
-5
lines changed 3 files changed +84
-5
lines changed Original file line number Diff line number Diff line change @@ -62,13 +62,19 @@ class _Visitor extends SimpleAstVisitor<void> {
62
62
var exp = expression.expression;
63
63
if (exp is SimpleIdentifier ) {
64
64
var identifier = exp;
65
- var bracket = expression.rightBracket;
66
- if (bracket != null &&
67
- ! isIdentifierPart (bracket.next) &&
68
- ! identifier.name.contains ('\$ ' )) {
69
- rule.reportLint (expression);
65
+ if (! identifier.name.contains ('\$ ' )) {
66
+ _check (expression);
70
67
}
68
+ } else if (exp is ThisExpression ) {
69
+ _check (expression);
71
70
}
72
71
}
73
72
}
73
+
74
+ void _check (InterpolationExpression expression) {
75
+ var bracket = expression.rightBracket;
76
+ if (bracket != null && ! isIdentifierPart (bracket.next)) {
77
+ rule.reportLint (expression);
78
+ }
79
+ }
74
80
}
Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ import 'tighten_type_of_initializing_formals_test.dart'
70
70
as tighten_type_of_initializing_formals;
71
71
import 'type_init_formals_test.dart' as type_init_formals;
72
72
import 'unawaited_futures_test.dart' as unawaited_futures;
73
+ import 'unnecessary_brace_in_string_interps_test.dart'
74
+ as unnecessary_brace_in_string_interps;
73
75
import 'unnecessary_const_test.dart' as unnecessary_const;
74
76
import 'unnecessary_null_checks_test.dart' as unnecessary_null_checks;
75
77
import 'unnecessary_overrides_test.dart' as unnecessary_overrides;
@@ -129,6 +131,7 @@ void main() {
129
131
tighten_type_of_initializing_formals.main ();
130
132
type_init_formals.main ();
131
133
unawaited_futures.main ();
134
+ unnecessary_brace_in_string_interps.main ();
132
135
unnecessary_const.main ();
133
136
unnecessary_null_checks.main ();
134
137
unnecessary_overrides.main ();
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2
+ // for details. All rights reserved. Use of this source code is governed by a
3
+ // BSD-style license that can be found in the LICENSE file.
4
+
5
+ import 'package:test_reflective_loader/test_reflective_loader.dart' ;
6
+
7
+ import '../rule_test_support.dart' ;
8
+
9
+ main () {
10
+ defineReflectiveSuite (() {
11
+ defineReflectiveTests (UnnecessaryBraceInStringInterpsTest );
12
+ });
13
+ }
14
+
15
+ @reflectiveTest
16
+ class UnnecessaryBraceInStringInterpsTest extends LintRuleTest {
17
+ @override
18
+ String get lintRule => 'unnecessary_brace_in_string_interps' ;
19
+
20
+ test_simpleIdentifier () async {
21
+ await assertDiagnostics (r'''
22
+ void hi(String name) {
23
+ print('hi: ${name}');
24
+ }
25
+ ''' , [
26
+ lint (36 , 7 ),
27
+ ]);
28
+ }
29
+
30
+ test_simpleIdentifier_suffixed () async {
31
+ await assertNoDiagnostics (r'''
32
+ void hi(String name) {
33
+ print('hi: ${name}s');
34
+ }
35
+ ''' );
36
+ }
37
+
38
+ test_this_methodInvocation () async {
39
+ await assertNoDiagnostics (r'''
40
+ class A {
41
+ void hi() {
42
+ print('hi: ${this.toString()}');
43
+ }
44
+ }
45
+ ''' );
46
+ }
47
+
48
+ /// https://github.com/dart-lang/linter/issues/3691
49
+ test_thisExpression () async {
50
+ await assertDiagnostics (r'''
51
+ class A {
52
+ void hi() {
53
+ print('hi: ${this}');
54
+ }
55
+ }
56
+ ''' , [
57
+ lint (39 , 7 ),
58
+ ]);
59
+ }
60
+
61
+ test_thisExpression_suffixed () async {
62
+ await assertNoDiagnostics (r'''
63
+ class A {
64
+ void hi() {
65
+ print('${this}s');
66
+ }
67
+ }
68
+ ''' );
69
+ }
70
+ }
You can’t perform that action at this time.
0 commit comments