Skip to content

Commit

Permalink
Add tests for avoid-unrelated-type-assertions rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Bogatirov committed Sep 13, 2023
1 parent 322df23 commit 2ea9d5c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions lint_test/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ custom_lint:
- double-literal-format
- avoid-unnecessary-type-assertions
- avoid-unnecessary-type-casts
- avoid-unrelated-type-assertions
33 changes: 33 additions & 0 deletions lint_test/avoid_unrelated_type_assertions_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ignore_for_file: prefer_const_declarations
// ignore_for_file: unnecessary_nullable_for_final_variable_declarations
// ignore_for_file: unused_local_variable

/// Check the `avoid-unrelated-type-assertions` rule
class Foo {}

class Bar {}

class ChildFoo extends Foo {}

void fun() {
final testString = '';
final testList = [1, 2, 3];
final testMap = {'A': 'B'};
final Foo foo = Foo();
final childFoo = ChildFoo();

// expect_lint: avoid-unrelated-type-assertions
final result = testString is int;

// expect_lint: avoid-unrelated-type-assertions
final result2 = testList is List<String>;

// expect_lint: avoid-unrelated-type-assertions
final result3 = foo is Bar;

// expect_lint: avoid-unrelated-type-assertions
final result4 = childFoo is Bar;

// expect_lint: avoid-unrelated-type-assertions
final result5 = testMap['A'] is double;
}

0 comments on commit 2ea9d5c

Please sign in to comment.