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

prefer_mixin support for nonfunction-type-aliases #2523

Merged
merged 1 commit into from
Mar 18, 2021
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
5 changes: 4 additions & 1 deletion lib/src/rules/prefer_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class _Visitor extends SimpleAstVisitor<void> {
@override
void visitWithClause(WithClause node) {
for (var type in node.mixinTypes) {
final element = type.name.staticElement;
var element = type.name.staticElement;
if (element is TypeAliasElement) {
element = element.aliasedType.element;
}
if (element is ClassElement && !element.isMixin && !isAllowed(element)) {
rule.reportLint(type);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository: https://github.com/dart-lang/linter
documentation: https://dart-lang.github.io/linter/lints

environment:
sdk: '>=2.12.0-0 <3.0.0'
sdk: '>=2.13.0-0 <3.0.0'

dependencies:
analyzer: ^1.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
analyzer:
enable-experiment:
- nonfunction-type-aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// 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.

// test w/ `pub run test -N prefer_mixin`

import 'dart:collection';

import 'dart:convert';

class A {}

class B extends Object with A {} // LINT

mixin M {}

class C with M {} // OK

abstract class I with IterableMixin {} //OK

abstract class L with ListMixin {} //OK

abstract class MM with MapMixin {} //OK

abstract class S with SetMixin {} //OK

abstract class SCS with StringConversionSinkMixin {} //OK

// nonfunction-type-aliases

typedef AA = A;

abstract class CC with AA { } // LINT

typedef AAA = M;

abstract class CCC with AAA { } //OK