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

Unified Diff: pkg/analyzer/lib/src/lint/io.dart

Issue 2553203002: Move the linter core to the analyzer package (Closed)
Patch Set: Add missed files 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/lint/io.dart
diff --git a/pkg/analyzer/lib/src/lint/io.dart b/pkg/analyzer/lib/src/lint/io.dart
new file mode 100644
index 0000000000000000000000000000000000000000..762ee93d0b38a12fa025af5fc81c1dfd2292f601
--- /dev/null
+++ b/pkg/analyzer/lib/src/lint/io.dart
@@ -0,0 +1,68 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:io';
+
+import 'package:analyzer/src/lint/util.dart';
+import 'package:glob/glob.dart';
+import 'package:path/path.dart' as p;
+
+final dartMatcher = new Glob('**.dart');
+
+/// Shared IO sink for standard error reporting.
+/// Visible for testing
+IOSink errorSink = stderr;
+
+/// Shared IO sink for standard out reporting.
+/// Visible for testing
+IOSink outSink = stdout;
+
+/// Cached project package.
+String _projectPackageName;
+
+/// Cached project root.
+String _projectRoot;
+
+/// Collect all lintable files, recursively, under this [path] root, ignoring
+/// links.
+Iterable<File> collectFiles(String path) {
+ List<File> files = [];
+
+ var file = new File(path);
+ if (file.existsSync()) {
+ files.add(file);
+ } else {
+ var directory = new Directory(path);
+ if (directory.existsSync()) {
+ for (var entry
+ in directory.listSync(recursive: true, followLinks: false)) {
+ var relative = p.relative(entry.path, from: directory.path);
+
+ if (isLintable(entry) && !isInHiddenDir(relative)) {
+ files.add(entry);
+ }
+ }
+ }
+ }
+
+ return files;
+}
+
+/// Returns `true` if this [entry] is a Dart file.
+bool isDartFile(FileSystemEntity entry) => isDartFileName(entry.path);
+
+/// Returns `true` if this relative path is a hidden directory.
+bool isInHiddenDir(String relative) =>
+ p.split(relative).any((part) => part.startsWith("."));
+
+/// Returns `true` if this relative path is a hidden directory.
+bool isLintable(FileSystemEntity file) =>
+ file is File && (isDartFile(file) || isPubspecFile(file));
+
+/// Returns `true` if this [entry] is a pubspec file.
+bool isPubspecFile(FileSystemEntity entry) =>
+ isPubspecFileName(p.basename(entry.path));
+
+/// Synchronously read the contents of the file at the given [path] as a string.
+String readFile(String path) => new File(path).readAsStringSync();
« 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