-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add combinators_ordering * address review comments
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2022, 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. | ||
|
||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:analyzer/dart/ast/visitor.dart'; | ||
import 'package:collection/collection.dart'; | ||
|
||
import '../analyzer.dart'; | ||
|
||
const _desc = r'Sort combinator names alphabetically.'; | ||
|
||
const _details = r''' | ||
**DO** sort combinator names alphabetically. | ||
**BAD:** | ||
```dart | ||
import 'a.dart' show B, A hide D, C; | ||
export 'a.dart' show B, A hide D, C; | ||
``` | ||
**GOOD:** | ||
```dart | ||
import 'a.dart' show A, B hide C, D; | ||
export 'a.dart' show A, B hide C, D; | ||
``` | ||
'''; | ||
|
||
class CombinatorsOrdering extends LintRule { | ||
CombinatorsOrdering() | ||
: super( | ||
name: 'combinators_ordering', | ||
description: _desc, | ||
details: _details, | ||
group: Group.style, | ||
); | ||
|
||
@override | ||
void registerNodeProcessors( | ||
NodeLintRegistry registry, | ||
LinterContext context, | ||
) { | ||
var visitor = _Visitor(this); | ||
registry.addHideCombinator(this, visitor); | ||
registry.addShowCombinator(this, visitor); | ||
} | ||
} | ||
|
||
class _Visitor extends SimpleAstVisitor<void> { | ||
_Visitor(this.rule); | ||
|
||
final LintRule rule; | ||
|
||
@override | ||
void visitHideCombinator(HideCombinator node) { | ||
if (!node.hiddenNames.map((e) => e.name).isSorted()) { | ||
rule.reportLint(node); | ||
} | ||
} | ||
|
||
@override | ||
void visitShowCombinator(ShowCombinator node) { | ||
if (!node.shownNames.map((e) => e.name).isSorted()) { | ||
rule.reportLint(node); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2022, 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/ `dart test -N combinators_ordering` | ||
|
||
import 'dart:math' as m1 show max, min; // OK | ||
import 'dart:math' as m2 show min, max; // LINT | ||
|
||
export 'dart:math' show max, min; // OK | ||
export 'dart:math' show min, max; // LINT | ||
|
||
import 'dart:math' as m3 hide max, min; // OK | ||
import 'dart:math' as m4 hide min, max; // LINT | ||
|
||
export 'dart:math' hide max, min; // OK | ||
export 'dart:math' hide min, max; // LINT |