-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new check: no trailing spaces in test source
Ensure test source files aren't created w/ trailing spaces. (These are just noise and distract in code reviews.) Change-Id: I34259521c27a652df085865ab91ee83349591de0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386826 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
- Loading branch information
Showing
9 changed files
with
76 additions
and
17 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
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
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,54 @@ | ||
// Copyright (c) 2024, 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:linter/src/analyzer.dart'; | ||
|
||
const _desc = r"Don't create string literals with trailing spaces in tests."; | ||
|
||
class NoTrailingSpaces extends LintRule { | ||
static const LintCode code = LintCode('no_trailing_spaces', _desc, | ||
correctionMessage: 'Try removing the trailing spaces.', | ||
hasPublishedDocs: true); | ||
|
||
NoTrailingSpaces() | ||
: super( | ||
name: 'no_trailing_spaces', | ||
description: _desc, | ||
); | ||
|
||
@override | ||
LintCode get lintCode => code; | ||
|
||
@override | ||
void registerNodeProcessors( | ||
NodeLintRegistry registry, LinterContext context) { | ||
if (context.definingUnit.unit.inTestDir) { | ||
var visitor = _Visitor(this); | ||
registry.addMethodInvocation(this, visitor); | ||
} | ||
} | ||
} | ||
|
||
class _Visitor extends SimpleAstVisitor<void> { | ||
final LintRule rule; | ||
|
||
_Visitor(this.rule); | ||
|
||
@override | ||
void visitMethodInvocation(MethodInvocation node) { | ||
var arguments = node.argumentList.arguments; | ||
for (var sourceString in arguments) { | ||
if (sourceString is! SimpleStringLiteral) return; | ||
|
||
var literal = sourceString.literal; | ||
if (literal is! StringToken) return; | ||
|
||
if (literal.lexeme.contains(' \n')) { | ||
rule.reportLintForToken(literal); | ||
} | ||
} | ||
} | ||
} |