Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

remove prefer_bool_in_asserts #4015

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 1 addition & 47 deletions lib/src/rules/prefer_bool_in_asserts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/type.dart';

import '../analyzer.dart';

const _desc = r'Prefer using a boolean as the assert condition.';
Expand All @@ -31,12 +27,6 @@ assert(() {
return true;
}());
```

**DEPRECATED:** In Dart 2, `assert`s no longer accept non-`bool` values so this
rule is made redundant by the Dart analyzer's basic checks and is no longer
necessary.

The rule will be removed in a future Linter release.
''';

class PreferBoolInAsserts extends LintRule {
Expand All @@ -50,45 +40,9 @@ class PreferBoolInAsserts extends LintRule {
name: 'prefer_bool_in_asserts',
description: _desc,
details: _details,
state: State.deprecated(),
state: State.removed(since: dart3),
group: Group.style);

@override
LintCode get lintCode => code;

@override
void registerNodeProcessors(
NodeLintRegistry registry, LinterContext context) {
var visitor = _Visitor(this, context);
registry.addAssertStatement(this, visitor);
}
}

class _Visitor extends SimpleAstVisitor<void> {
final LintRule rule;

final TypeSystem typeSystem;

final DartType boolType;

_Visitor(this.rule, LinterContext context)
: typeSystem = context.typeSystem,
boolType = context.typeProvider.boolType;

@override
void visitAssertStatement(AssertStatement node) {
var conditionType = _unbound(node.condition.staticType);
if (conditionType != null &&
!typeSystem.isAssignableTo(conditionType, boolType)) {
rule.reportLint(node.condition);
}
}

DartType? _unbound(DartType? type) {
var t = type;
while (t is TypeParameterType) {
t = t.bound;
}
return t;
}
}
24 changes: 0 additions & 24 deletions test_data/rules/prefer_bool_in_asserts.dart

This file was deleted.