OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library linter.src.rules.dont_compare_unrelated_types_for_equality; | 5 library linter.src.rules.unrelated_type_equality_checks; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
11 import 'package:analyzer/dart/element/type.dart'; | 11 import 'package:analyzer/dart/element/type.dart'; |
12 import 'package:linter/src/linter.dart'; | 12 import 'package:linter/src/linter.dart'; |
13 | 13 |
14 const String _desc = r'Equality operator (==) invocation with references of' | 14 const String _desc = r'Equality operator (==) invocation with references of' |
15 r' unrelated types.'; | 15 r' unrelated types.'; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } | 119 } |
120 | 120 |
121 class ClassBase {} | 121 class ClassBase {} |
122 | 122 |
123 abstract class Mixin {} | 123 abstract class Mixin {} |
124 | 124 |
125 class DerivedClass2 extends ClassBase with Mixin {} | 125 class DerivedClass2 extends ClassBase with Mixin {} |
126 ``` | 126 ``` |
127 '''; | 127 '''; |
128 | 128 |
129 class DontCompareUnrelatedTypesForEquality extends LintRule { | 129 class UnrelatedTypeEqualityChecks extends LintRule { |
130 _Visitor _visitor; | 130 _Visitor _visitor; |
131 | 131 |
132 DontCompareUnrelatedTypesForEquality() : super( | 132 UnrelatedTypeEqualityChecks() : super( |
133 name: 'dont_compare_unrelated_types_for_equality', | 133 name: 'unrelated_type_equality_checks', |
134 description: _desc, | 134 description: _desc, |
135 details: _details, | 135 details: _details, |
136 group: Group.errors, | 136 group: Group.errors, |
137 maturity: Maturity.experimental) { | 137 maturity: Maturity.experimental) { |
138 _visitor = new _Visitor(this); | 138 _visitor = new _Visitor(this); |
139 } | 139 } |
140 | 140 |
141 @override | 141 @override |
142 AstVisitor getVisitor() => _visitor; | 142 AstVisitor getVisitor() => _visitor; |
143 } | 143 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 177 } |
178 Element leftElement = leftType.element; | 178 Element leftElement = leftType.element; |
179 Element rightElement = rightType.element; | 179 Element rightElement = rightType.element; |
180 if (leftElement is ClassElement && rightElement is ClassElement) { | 180 if (leftElement is ClassElement && rightElement is ClassElement) { |
181 return leftElement.supertype.isObject || | 181 return leftElement.supertype.isObject || |
182 leftElement.supertype != rightElement.supertype; | 182 leftElement.supertype != rightElement.supertype; |
183 } | 183 } |
184 return false; | 184 return false; |
185 } | 185 } |
186 } | 186 } |
OLD | NEW |