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 // An update to this file must be followed by regenerating the corresponding | 5 // An update to this file must be followed by regenerating the corresponding |
6 // json file. Use `json_converter.dart` in the bin directory. | 6 // json, dart2js and analyzer file. Use `publish.dart` in the bin directory. |
7 // | 7 // |
8 // Every message in this file must have an id. Use `message_id.dart` in the | 8 // Every message in this file must have an id. Use `message_id.dart` in the |
9 // bin directory to generate a fresh one. | 9 // bin directory to generate a fresh one. |
10 | 10 |
11 // The messages in this file should meet the following guide lines: | 11 // The messages in this file should meet the following guide lines: |
12 // | 12 // |
13 // 1. The message should be a complete sentence starting with an uppercase | 13 // 1. The message should be a complete sentence starting with an uppercase |
14 // letter, and ending with a period. | 14 // letter, and ending with a period. |
15 // | 15 // |
16 // 2. Reserved words and embedded identifiers should be in single quotes, so | 16 // 2. Reserved words and embedded identifiers should be in single quotes, so |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 // 10. Prefer to not use imperative tone. That is, the message should not sound | 51 // 10. Prefer to not use imperative tone. That is, the message should not sound |
52 // accusing or like it is ordering the user around. The computer should | 52 // accusing or like it is ordering the user around. The computer should |
53 // describe the problem, not criticize for violating the specification. | 53 // describe the problem, not criticize for violating the specification. |
54 // | 54 // |
55 // Other things to keep in mind: | 55 // Other things to keep in mind: |
56 // | 56 // |
57 // Generally, we want to provide messages that consists of three sentences: | 57 // Generally, we want to provide messages that consists of three sentences: |
58 // 1. what is wrong, 2. why is it wrong, 3. how do I fix it. However, we | 58 // 1. what is wrong, 2. why is it wrong, 3. how do I fix it. However, we |
59 // combine the first two in [template] and the last in [howToFix]. | 59 // combine the first two in [template] and the last in [howToFix]. |
60 | 60 |
61 final Map<String, Map> MESSAGES = { | 61 import 'dart:convert'; |
62 | |
63 class Message { | |
64 final String id; | |
65 final String template; | |
66 // The analyzer fills holes positionally (and not named). The following field | |
67 // overrides the order of the holes. | |
68 // For example the template "The argument #field in #cls is bad", could have | |
69 // the order `["cls", "field"]', which means that the analyzer would first | |
70 // provide the class `cls` and then only `field`. | |
71 // This list is generally `null`, but when it is provided it must contain all | |
72 // holes. | |
73 final List templateHoleOrder; | |
74 final String howToFix; | |
75 final List<String> options; | |
76 final List examples; | |
77 | |
78 Message({this.id, this.template, this.templateHoleOrder, this.howToFix, | |
79 this.options, this.examples}); | |
80 } | |
81 | |
82 String get messagesAsJson { | |
83 var jsonified = {}; | |
84 MESSAGES.forEach((String name, Message message) { | |
85 jsonified[name] = { | |
86 'id': message.id, | |
87 'template': message.template, | |
88 'howToFix': message.howToFix | |
89 }; | |
90 }); | |
91 return JSON.encode(jsonified); | |
92 } | |
93 | |
94 final Map<String, Message> MESSAGES = { | |
95 'exampleMessage': new Message( | |
96 id: 'use an Id generated by bin/message_id.dart', | |
97 template: "#use #named #arguments", | |
98 templateHoleOrder: ["arguments", "named", "use"], | |
99 howToFix: "an explanation on how to fix things", | |
100 examples: [r''' | |
101 Some multiline example; | |
Siggi Cherem (dart-lang)
2016/01/14 17:57:40
consider indenting this if the extra space is not
floitsch
2016/01/15 17:20:39
Done.
| |
102 That generates the bug.''', | |
103 { | |
104 'fileA.dart': ''' | |
105 or a map from file to content. | |
106 again multiline''', | |
107 'fileB.dart': ''' | |
108 with possibly multiple files. | |
109 muliline too''' | |
110 } | |
111 ] | |
112 ), | |
62 }; | 113 }; |
OLD | NEW |