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

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

Issue 1447123002: Failsafe for unavailable project info (sdk#24947). (Closed) Base URL: https://github.com/dart-lang/linter.git@master
Patch Set: log updates Created 5 years, 1 month 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 | « CHANGELOG.md ('k') | pubspec.yaml » ('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 linter.src.rules.package_prefixed_library_names; 5 library linter.src.rules.package_prefixed_library_names;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/source.dart'; 8 import 'package:analyzer/src/generated/source.dart';
9 import 'package:linter/src/linter.dart'; 9 import 'package:linter/src/linter.dart';
10 import 'package:linter/src/project.dart'; 10 import 'package:linter/src/project.dart';
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 class Visitor extends SimpleAstVisitor { 75 class Visitor extends SimpleAstVisitor {
76 PackagePrefixedLibraryNames rule; 76 PackagePrefixedLibraryNames rule;
77 Visitor(this.rule); 77 Visitor(this.rule);
78 78
79 DartProject get project => rule.project; 79 DartProject get project => rule.project;
80 80
81 @override 81 @override
82 visitLibraryDirective(LibraryDirective node) { 82 visitLibraryDirective(LibraryDirective node) {
83 // If no project info is set, bail early.
84 // https://github.com/dart-lang/linter/issues/154
85 if (project == null) {
86 return;
87 }
83 Source source = node.element.source; 88 Source source = node.element.source;
84 var prefix = createLibraryNamePrefix( 89 var prefix = createLibraryNamePrefix(
85 libraryPath: source.fullName, 90 libraryPath: source.fullName,
86 projectRoot: project.root.absolute.path, 91 projectRoot: project.root.absolute.path,
87 packageName: project.name); 92 packageName: project.name);
88 93
89 var libraryName = node.element.name; 94 var libraryName = node.element.name;
90 if (!matchesOrIsPrefixedBy(libraryName, prefix)) { 95 if (!matchesOrIsPrefixedBy(libraryName, prefix)) {
91 rule.reportLint(node.name); 96 rule.reportLint(node.name);
92 } 97 }
93 } 98 }
94 } 99 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698