Chromium Code Reviews| Index: lib/src/rules/unnecessary_brace_in_string_interp.dart |
| diff --git a/lib/src/rules/unnecessary_brace_in_string_interp.dart b/lib/src/rules/unnecessary_brace_in_string_interp.dart |
| index fa8e9ee9a86a4b6abc197a6953e852e741519355..13ef1d651637c1003764c44cd43eb537ff6436f3 100644 |
| --- a/lib/src/rules/unnecessary_brace_in_string_interp.dart |
| +++ b/lib/src/rules/unnecessary_brace_in_string_interp.dart |
| @@ -6,8 +6,11 @@ library unnecessary_brace_in_string_interp; |
| import 'package:analyzer/src/generated/ast.dart'; |
| import 'package:analyzer/src/generated/error.dart'; |
| +import 'package:analyzer/src/generated/scanner.dart'; |
| import 'package:analyzer/src/services/lint.dart'; |
| +final RegExp alphaNumeric = new RegExp(r'^[a-zA-Z0-9]'); |
| + |
| const msg = ''' |
| Interpolated simple identifiers (not followed by an alphanumeric string) do |
| not need braces. |
|
Brian Wilkerson
2015/02/05 01:38:42
Don't include end-of-line characters in the messag
pquitslund
2015/02/05 03:42:06
Done.
|
| @@ -15,6 +18,9 @@ not need braces. |
| const name = 'UnnecessaryBraceInStringInterp'; |
| +bool isAlphaNumeric(Token token) => |
| + token is StringToken && token.lexeme.startsWith(alphaNumeric); |
| + |
| class UnnecessaryBraceInStringInterp extends Linter { |
| @override |
| AstVisitor getVisitor() => new Visitor(reporter); |
| @@ -28,9 +34,11 @@ class Visitor extends SimpleAstVisitor<Object> { |
| visitStringInterpolation(StringInterpolation node) { |
| var expressions = node.elements.where((e) => e is InterpolationExpression); |
| for (InterpolationExpression expression in expressions) { |
| - if (expression.expression is SimpleIdentifier && |
| - expression.rightBracket != null) { |
| - reporter.reportErrorForNode(new LintCode(name, msg), expression, []); |
| + if (expression.expression is SimpleIdentifier) { |
| + Token bracket = expression.rightBracket; |
| + if (bracket != null && !isAlphaNumeric(bracket.next)) { |
| + reporter.reportErrorForNode(new LintCode(name, msg), expression, []); |
|
Brian Wilkerson
2015/02/05 01:38:42
I would recommend defining static constant fields
pquitslund
2015/02/05 03:42:06
Agreed! That said, if I understand you right, I'm
|
| + } |
| } |
| } |
| } |