OLD | NEW |
(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(); |
OLD | NEW |