Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: lib/src/rules/unnecessary_brace_in_string_interp.dart

Issue 900093002: Fix for alphanumerics following braces. (Closed) Base URL: https://github.com/dart-lang/dart_lint.git@master
Patch Set: Review nits Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/rules/unnecessary_brace_in_string_interp.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library unnecessary_brace_in_string_interp; 5 library unnecessary_brace_in_string_interp;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/scanner.dart';
9 import 'package:analyzer/src/services/lint.dart'; 10 import 'package:analyzer/src/services/lint.dart';
10 11
11 const msg = ''' 12 final RegExp alphaNumeric = new RegExp(r'^[a-zA-Z0-9]');
12 Interpolated simple identifiers (not followed by an alphanumeric string) do 13
13 not need braces. 14 const msg =
14 '''; 15 '''Interpolated simple identifiers (not followed by an alphanumeric string) do
16 not need braces.''';
15 17
16 const name = 'UnnecessaryBraceInStringInterp'; 18 const name = 'UnnecessaryBraceInStringInterp';
17 19
20 bool isAlphaNumeric(Token token) =>
21 token is StringToken && token.lexeme.startsWith(alphaNumeric);
22
18 class UnnecessaryBraceInStringInterp extends Linter { 23 class UnnecessaryBraceInStringInterp extends Linter {
19 @override 24 @override
20 AstVisitor getVisitor() => new Visitor(reporter); 25 AstVisitor getVisitor() => new Visitor(reporter);
21 } 26 }
22 27
23 class Visitor extends SimpleAstVisitor<Object> { 28 class Visitor extends SimpleAstVisitor {
24 ErrorReporter reporter; 29 ErrorReporter reporter;
25 Visitor(this.reporter); 30 Visitor(this.reporter);
26 31
27 @override 32 @override
28 visitStringInterpolation(StringInterpolation node) { 33 visitStringInterpolation(StringInterpolation node) {
29 var expressions = node.elements.where((e) => e is InterpolationExpression); 34 var expressions = node.elements.where((e) => e is InterpolationExpression);
30 for (InterpolationExpression expression in expressions) { 35 for (InterpolationExpression expression in expressions) {
31 if (expression.expression is SimpleIdentifier && 36 if (expression.expression is SimpleIdentifier) {
32 expression.rightBracket != null) { 37 Token bracket = expression.rightBracket;
33 reporter.reportErrorForNode(new LintCode(name, msg), expression, []); 38 if (bracket != null && !isAlphaNumeric(bracket.next)) {
39 reporter.reportErrorForNode(new LintCode(name, msg), expression, []);
40 }
34 } 41 }
35 } 42 }
36 } 43 }
37 } 44 }
OLDNEW
« no previous file with comments | « no previous file | test/rules/unnecessary_brace_in_string_interp.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698