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

Side by Side Diff: pkg/analyzer/lib/src/lint/io.dart

Issue 2559773002: Reapply "Move the linter core to the analyzer package" (Closed)
Patch Set: Created 4 years 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 | « pkg/analyzer/lib/src/lint/config.dart ('k') | pkg/analyzer/lib/src/lint/linter.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:io';
6
7 import 'package:analyzer/src/lint/util.dart';
8 import 'package:glob/glob.dart';
9 import 'package:path/path.dart' as p;
10
11 final dartMatcher = new Glob('**.dart');
12
13 /// Shared IO sink for standard error reporting.
14 /// Visible for testing
15 IOSink errorSink = stderr;
16
17 /// Shared IO sink for standard out reporting.
18 /// Visible for testing
19 IOSink outSink = stdout;
20
21 /// Cached project package.
22 String _projectPackageName;
23
24 /// Cached project root.
25 String _projectRoot;
26
27 /// Collect all lintable files, recursively, under this [path] root, ignoring
28 /// links.
29 Iterable<File> collectFiles(String path) {
30 List<File> files = [];
31
32 var file = new File(path);
33 if (file.existsSync()) {
34 files.add(file);
35 } else {
36 var directory = new Directory(path);
37 if (directory.existsSync()) {
38 for (var entry
39 in directory.listSync(recursive: true, followLinks: false)) {
40 var relative = p.relative(entry.path, from: directory.path);
41
42 if (isLintable(entry) && !isInHiddenDir(relative)) {
43 files.add(entry);
44 }
45 }
46 }
47 }
48
49 return files;
50 }
51
52 /// Returns `true` if this [entry] is a Dart file.
53 bool isDartFile(FileSystemEntity entry) => isDartFileName(entry.path);
54
55 /// Returns `true` if this relative path is a hidden directory.
56 bool isInHiddenDir(String relative) =>
57 p.split(relative).any((part) => part.startsWith("."));
58
59 /// Returns `true` if this relative path is a hidden directory.
60 bool isLintable(FileSystemEntity file) =>
61 file is File && (isDartFile(file) || isPubspecFile(file));
62
63 /// Returns `true` if this [entry] is a pubspec file.
64 bool isPubspecFile(FileSystemEntity entry) =>
65 isPubspecFileName(p.basename(entry.path));
66
67 /// Synchronously read the contents of the file at the given [path] as a string.
68 String readFile(String path) => new File(path).readAsStringSync();
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/lint/config.dart ('k') | pkg/analyzer/lib/src/lint/linter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698