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

Side by Side Diff: pkg/analyzer_experimental/bin/formatter.dart

Issue 23461044: Fix to NOT traverse linked directories when formatting (dartbug.com/13187). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 2
3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
4 // for details. All rights reserved. Use of this source code is governed by a 4 // for details. All rights reserved. Use of this source code is governed by a
5 // BSD-style license that can be found in the LICENSE file. 5 // BSD-style license that can be found in the LICENSE file.
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:args/args.dart'; 9 import 'package:args/args.dart';
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
11 11
12 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; 12 import 'package:analyzer_experimental/src/services/formatter_impl.dart';
13 13
14 14
15 const BINARY_NAME = 'dartfmt'; 15 const BINARY_NAME = 'dartfmt';
16 final dartFileRegExp = new RegExp(r'^[^.].*\.dart$', caseSensitive: false); 16 final dartFileRegExp = new RegExp(r'^[^.].*\.dart$', caseSensitive: false);
17 final argParser = _initArgParser(); 17 final argParser = _initArgParser();
18 18
19 bool overwriteFileContents; 19 bool overwriteFileContents;
20 const followLinks = false;
20 21
21 main() { 22 main() {
22 var options = argParser.parse(new Options().arguments); 23 var options = argParser.parse(new Options().arguments);
23 if (options['help']) { 24 if (options['help']) {
24 _printUsage(); 25 _printUsage();
25 return; 26 return;
26 } 27 }
27 overwriteFileContents = options['write']; 28 overwriteFileContents = options['write'];
28 29
29 if (options.rest.isEmpty) { 30 if (options.rest.isEmpty) {
(...skipping 14 matching lines...) Expand all
44 } 45 }
45 46
46 _formatResource(resource) { 47 _formatResource(resource) {
47 if (resource is Directory) { 48 if (resource is Directory) {
48 _formatDirectory(resource); 49 _formatDirectory(resource);
49 } else if (resource is File) { 50 } else if (resource is File) {
50 _formatFile(resource); 51 _formatFile(resource);
51 } 52 }
52 } 53 }
53 54
54 _formatDirectory(dir) => 55 _formatDirectory(dir) => dir.listSync(followLinks: followLinks)
55 dir.listSync().forEach((resource) => _formatResource(resource)); 56 .forEach((resource) => _formatResource(resource));
56 57
57 _formatFile(file) { 58 _formatFile(file) {
58 if (_isDartFile(file)) { 59 if (_isDartFile(file)) {
59 try { 60 try {
60 var buffer = new StringBuffer(); 61 var buffer = new StringBuffer();
61 var rawSource = file.readAsStringSync(); 62 var rawSource = file.readAsStringSync();
62 var formatted = _formatCU(rawSource); 63 var formatted = _formatCU(rawSource);
63 if (overwriteFileContents) { 64 if (overwriteFileContents) {
64 file.writeAsStringSync(formatted); 65 file.writeAsStringSync(formatted);
65 } else { 66 } else {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 115
115 /// Format the given [src] as a compilation unit. 116 /// Format the given [src] as a compilation unit.
116 String _formatCU(src, {options: const FormatterOptions()}) => 117 String _formatCU(src, {options: const FormatterOptions()}) =>
117 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); 118 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src);
118 119
119 /// Log the given [msg]. 120 /// Log the given [msg].
120 _log(String msg) { 121 _log(String msg) {
121 //TODO(pquitslund): add proper log support 122 //TODO(pquitslund): add proper log support
122 print(msg); 123 print(msg);
123 } 124 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698