This repository was archived by the owner on May 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathno_condition_parens.dart
49 lines (44 loc) · 1.67 KB
/
no_condition_parens.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2018 Google Inc. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
// The sass package's API is not necessarily stable. It is being imported with
// the Sass team's explicit knowledge and approval. See
// https://github.com/sass/dart-sass/issues/236.
import 'package:sass/src/ast/sass.dart';
import '../lint.dart';
import '../rule.dart';
/// A lint rule that reports unnecessary parentheses in conditionals.
///
/// Sometimes users who are familiar with other languages forget that Sass
/// doesn't need parentheses around its conditionals (as in, `@if (...) {`, or
/// `@else if (...) {`, or `@while (...) {`). This rule suggests removing these
/// parentheses.
class NoConditionParensRule extends Rule {
NoConditionParensRule() : super('no_condition_parens_rule');
@override
List<Lint> visitIfRule(IfRule node) {
var lint = <Lint>[];
for (var clause in node.clauses) {
if (clause.expression is ParenthesizedExpression) {
lint.add(Lint(
rule: this,
span: clause.expression.span,
message:
'Parentheses around ${clause.expression.span.text} are unnecessary'));
}
}
return lint..addAll(super.visitIfRule(node));
}
@override
List<Lint> visitWhileRule(WhileRule node) {
var lint = <Lint>[];
if (node.condition is ParenthesizedExpression) {
lint.add(Lint(
rule: this,
span: node.condition.span,
message:
'Parentheses around ${node.condition.span.text} are unnecessary'));
}
return lint..addAll(super.visitWhileRule(node));
}
}