This repository was archived by the owner on Nov 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +75
-17
lines changed Expand file tree Collapse file tree 3 files changed +75
-17
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,8 @@ import 'unnecessary_new_test.dart' as unnecessary_new;
146
146
import 'unnecessary_null_aware_assignments_test.dart'
147
147
as unnecessary_null_aware_assignments;
148
148
import 'unnecessary_null_checks_test.dart' as unnecessary_null_checks;
149
+ import 'unnecessary_null_in_if_null_operators_test.dart'
150
+ as unnecessary_null_in_if_null_operators;
149
151
import 'unnecessary_nullable_for_final_variable_declarations_test.dart'
150
152
as unnecessary_nullable_for_final_variable_declarations;
151
153
import 'unnecessary_overrides_test.dart' as unnecessary_overrides;
@@ -285,6 +287,7 @@ void main() {
285
287
unnecessary_new.main ();
286
288
unnecessary_null_aware_assignments.main ();
287
289
unnecessary_null_checks.main ();
290
+ unnecessary_null_in_if_null_operators.main ();
288
291
unnecessary_nullable_for_final_variable_declarations.main ();
289
292
unnecessary_overrides.main ();
290
293
unnecessary_parenthesis.main ();
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, 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 (UnnecessaryNullInIfNullOperatorsLanguage29Test );
12
+ });
13
+ }
14
+
15
+ @reflectiveTest
16
+ class UnnecessaryNullInIfNullOperatorsLanguage29Test extends LintRuleTest {
17
+ @override
18
+ String get lintRule => 'unnecessary_null_in_if_null_operators' ;
19
+
20
+ @override
21
+ String get testPackageLanguageVersion => '2.9' ;
22
+
23
+ test_localVariableDeclaration_noNull () async {
24
+ await assertNoDiagnostics (r'''
25
+ void f() {
26
+ var x = 1 ?? 1;
27
+ }
28
+ ''' );
29
+ }
30
+
31
+ test_localVariableDeclaration_nullOnLeft () async {
32
+ await assertDiagnostics (r'''
33
+ void f() {
34
+ var x = null ?? 1;
35
+ }
36
+ ''' , [
37
+ lint (21 , 9 ),
38
+ ]);
39
+ }
40
+
41
+ test_localVariableDeclaration_nullOnRight () async {
42
+ await assertDiagnostics (r'''
43
+ void f() {
44
+ var x = 1 ?? null;
45
+ }
46
+ ''' , [
47
+ lint (21 , 9 ),
48
+ ]);
49
+ }
50
+
51
+ test_topLevelVariableDeclaration_noNull () async {
52
+ await assertNoDiagnostics (r'''
53
+ var x = 1 ?? 1;
54
+ ''' );
55
+ }
56
+
57
+ test_topLevelVariableDeclaration_nullOnLeft () async {
58
+ await assertDiagnostics (r'''
59
+ var x = null ?? 1;
60
+ ''' , [
61
+ lint (8 , 9 ),
62
+ ]);
63
+ }
64
+
65
+ test_topLevelVariableDeclaration_nullOnRight () async {
66
+ await assertDiagnostics (r'''
67
+ var x = 1 ?? null;
68
+ ''' , [
69
+ lint (8 , 9 ),
70
+ ]);
71
+ }
72
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments