2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- import 'package:analyzer/dart/ast/ast.dart' ;
6
- import 'package:analyzer/dart/ast/visitor.dart' ;
7
- import 'package:analyzer/dart/element/type.dart' ;
8
-
9
5
import '../analyzer.dart' ;
10
6
11
7
const _desc = r'Prefer using a boolean as the assert condition.' ;
@@ -31,12 +27,6 @@ assert(() {
31
27
return true;
32
28
}());
33
29
```
34
-
35
- **DEPRECATED:** In Dart 2, `assert`s no longer accept non-`bool` values so this
36
- rule is made redundant by the Dart analyzer's basic checks and is no longer
37
- necessary.
38
-
39
- The rule will be removed in a future Linter release.
40
30
''' ;
41
31
42
32
class PreferBoolInAsserts extends LintRule {
@@ -50,45 +40,9 @@ class PreferBoolInAsserts extends LintRule {
50
40
name: 'prefer_bool_in_asserts' ,
51
41
description: _desc,
52
42
details: _details,
53
- state: State .deprecated ( ),
43
+ state: State .removed (since : dart3 ),
54
44
group: Group .style);
55
45
56
46
@override
57
47
LintCode get lintCode => code;
58
-
59
- @override
60
- void registerNodeProcessors (
61
- NodeLintRegistry registry, LinterContext context) {
62
- var visitor = _Visitor (this , context);
63
- registry.addAssertStatement (this , visitor);
64
- }
65
- }
66
-
67
- class _Visitor extends SimpleAstVisitor <void > {
68
- final LintRule rule;
69
-
70
- final TypeSystem typeSystem;
71
-
72
- final DartType boolType;
73
-
74
- _Visitor (this .rule, LinterContext context)
75
- : typeSystem = context.typeSystem,
76
- boolType = context.typeProvider.boolType;
77
-
78
- @override
79
- void visitAssertStatement (AssertStatement node) {
80
- var conditionType = _unbound (node.condition.staticType);
81
- if (conditionType != null &&
82
- ! typeSystem.isAssignableTo (conditionType, boolType)) {
83
- rule.reportLint (node.condition);
84
- }
85
- }
86
-
87
- DartType ? _unbound (DartType ? type) {
88
- var t = type;
89
- while (t is TypeParameterType ) {
90
- t = t.bound;
91
- }
92
- return t;
93
- }
94
48
}
0 commit comments