Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 } |
| OLD | NEW |