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

Side by Side Diff: pkg/analyzer/lib/source/analysis_options_provider.dart

Issue 1369573003: Fix handling of empty .analysis_options files and test this case (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | pkg/analyzer/test/source/analysis_options_provider_test.dart » ('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 source.analysis_options_provider; 5 library source.analysis_options_provider;
6 6
7 import 'package:analyzer/file_system/file_system.dart'; 7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:yaml/yaml.dart'; 8 import 'package:yaml/yaml.dart';
9 9
10 /// Provide the options found in the `.analysis_options` file. 10 /// Provide the options found in the `.analysis_options` file.
(...skipping 17 matching lines...) Expand all
28 } 28 }
29 29
30 /// Provide the options found in [optionsSource]. 30 /// Provide the options found in [optionsSource].
31 /// Return an empty options map if the source is null. 31 /// Return an empty options map if the source is null.
32 Map<String, YamlNode> getOptionsFromString(String optionsSource) { 32 Map<String, YamlNode> getOptionsFromString(String optionsSource) {
33 var options = <String, YamlNode>{}; 33 var options = <String, YamlNode>{};
34 if (optionsSource == null) { 34 if (optionsSource == null) {
35 return options; 35 return options;
36 } 36 }
37 var doc = loadYaml(optionsSource); 37 var doc = loadYaml(optionsSource);
38 if (doc is! YamlMap) {
pquitslund 2015/09/24 19:26:17 I would prefer: if (doc != null && doc is! Yaml
Cutch 2015/09/24 19:37:22 Done and I've added a test for the invalid yaml ca
39 throw new Exception(
40 'Bad options file format (expected map, got ${doc.runtimeType})');
41 }
42 if (doc is YamlMap) { 38 if (doc is YamlMap) {
43 doc.forEach((k, v) { 39 doc.forEach((k, v) {
44 if (k is! String) { 40 if (k is! String) {
45 throw new Exception( 41 throw new Exception(
46 'Bad options file format (expected String scope key, ' 42 'Bad options file format (expected String scope key, '
47 'got ${k.runtimeType})'); 43 'got ${k.runtimeType})');
48 } 44 }
49 options[k] = v; 45 options[k] = v;
50 }); 46 });
51 } 47 }
52 return options; 48 return options;
53 } 49 }
54 50
55 /// Read the contents of [file] as a string. 51 /// Read the contents of [file] as a string.
56 /// Returns null if file does not exist. 52 /// Returns null if file does not exist.
57 String _readAnalysisOptionsFile(File file) { 53 String _readAnalysisOptionsFile(File file) {
58 try { 54 try {
59 return file.readAsStringSync(); 55 return file.readAsStringSync();
60 } on FileSystemException { 56 } on FileSystemException {
61 // File can't be read. 57 // File can't be read.
62 return null; 58 return null;
63 } 59 }
64 } 60 }
65 } 61 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/source/analysis_options_provider_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698