Skip to content

Commit d5ff8ed

Browse files
authored
[record_use] Use snake_case in JSON (dart-lang#2978)
1 parent c26f756 commit d5ff8ed

26 files changed

Lines changed: 108 additions & 106 deletions

‎pkgs/record_use/doc/schema/record_use.schema.json‎

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@
6565
"anyOf": [
6666
{
6767
"enum": [
68-
"Instance",
69-
"Null",
70-
"String",
7168
"bool",
69+
"instance",
7270
"int",
7371
"list",
74-
"map"
72+
"map",
73+
"null",
74+
"string"
7575
]
7676
},
7777
{
@@ -88,47 +88,50 @@
8888
"if": {
8989
"properties": {
9090
"type": {
91-
"const": "Instance"
91+
"const": "bool"
9292
}
9393
}
9494
},
9595
"then": {
9696
"properties": {
9797
"value": {
98-
"type": "object",
99-
"additionalProperties": true
98+
"type": "boolean"
10099
}
101-
}
100+
},
101+
"required": [
102+
"value"
103+
]
102104
}
103105
},
104106
{
105107
"if": {
106108
"properties": {
107109
"type": {
108-
"const": "Null"
110+
"const": "instance"
109111
}
110112
}
111113
},
112114
"then": {
113-
"not": {
114-
"required": [
115-
"value"
116-
]
115+
"properties": {
116+
"value": {
117+
"type": "object",
118+
"additionalProperties": true
119+
}
117120
}
118121
}
119122
},
120123
{
121124
"if": {
122125
"properties": {
123126
"type": {
124-
"const": "String"
127+
"const": "int"
125128
}
126129
}
127130
},
128131
"then": {
129132
"properties": {
130133
"value": {
131-
"type": "string"
134+
"type": "integer"
132135
}
133136
},
134137
"required": [
@@ -140,14 +143,14 @@
140143
"if": {
141144
"properties": {
142145
"type": {
143-
"const": "bool"
146+
"const": "list"
144147
}
145148
}
146149
},
147150
"then": {
148151
"properties": {
149152
"value": {
150-
"type": "boolean"
153+
"type": "array"
151154
}
152155
},
153156
"required": [
@@ -159,14 +162,15 @@
159162
"if": {
160163
"properties": {
161164
"type": {
162-
"const": "int"
165+
"const": "map"
163166
}
164167
}
165168
},
166169
"then": {
167170
"properties": {
168171
"value": {
169-
"type": "integer"
172+
"type": "object",
173+
"additionalProperties": true
170174
}
171175
},
172176
"required": [
@@ -178,34 +182,30 @@
178182
"if": {
179183
"properties": {
180184
"type": {
181-
"const": "list"
185+
"const": "null"
182186
}
183187
}
184188
},
185189
"then": {
186-
"properties": {
187-
"value": {
188-
"type": "array"
189-
}
190-
},
191-
"required": [
192-
"value"
193-
]
190+
"not": {
191+
"required": [
192+
"value"
193+
]
194+
}
194195
}
195196
},
196197
{
197198
"if": {
198199
"properties": {
199200
"type": {
200-
"const": "map"
201+
"const": "string"
201202
}
202203
}
203204
},
204205
"then": {
205206
"properties": {
206207
"value": {
207-
"type": "object",
208-
"additionalProperties": true
208+
"type": "string"
209209
}
210210
},
211211
"required": [

‎pkgs/record_use/lib/src/constant.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ sealed class Constant {
6868
(key, value) => MapEntry(key, constants[value as int]),
6969
),
7070
),
71-
_ => throw UnimplementedError('This type is not a supported constant'),
71+
_ => throw UnimplementedError(
72+
'"${syntax.type}" is not a supported constant type',
73+
),
7274
};
7375
}
7476

‎pkgs/record_use/lib/src/syntax.g.dart‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,12 @@ class ConstantSyntax extends JsonObjectSyntax {
125125
List<Object> path = const [],
126126
}) {
127127
final result = ConstantSyntax._fromJson(json, path: path);
128-
if (result.isInstanceConstant) {
129-
return result.asInstanceConstant;
130-
}
131-
if (result.isNullConstant) {
132-
return result.asNullConstant;
133-
}
134-
if (result.isStringConstant) {
135-
return result.asStringConstant;
136-
}
137128
if (result.isBoolConstant) {
138129
return result.asBoolConstant;
139130
}
131+
if (result.isInstanceConstant) {
132+
return result.asInstanceConstant;
133+
}
140134
if (result.isIntConstant) {
141135
return result.asIntConstant;
142136
}
@@ -146,6 +140,12 @@ class ConstantSyntax extends JsonObjectSyntax {
146140
if (result.isMapConstant) {
147141
return result.asMapConstant;
148142
}
143+
if (result.isNullConstant) {
144+
return result.asNullConstant;
145+
}
146+
if (result.isStringConstant) {
147+
return result.asStringConstant;
148+
}
149149
return result;
150150
}
151151

@@ -344,7 +344,7 @@ class InstanceConstantSyntax extends ConstantSyntax {
344344
}) : super._fromJson();
345345

346346
InstanceConstantSyntax({JsonObjectSyntax? value, super.path = const []})
347-
: super(type: 'Instance') {
347+
: super(type: 'instance') {
348348
_value = value;
349349
json.sortOnKey();
350350
}
@@ -382,7 +382,7 @@ class InstanceConstantSyntax extends ConstantSyntax {
382382
}
383383

384384
extension InstanceConstantSyntaxExtension on ConstantSyntax {
385-
bool get isInstanceConstant => type == 'Instance';
385+
bool get isInstanceConstant => type == 'instance';
386386

387387
InstanceConstantSyntax get asInstanceConstant =>
388388
InstanceConstantSyntax.fromJson(json, path: path);
@@ -624,7 +624,7 @@ class NullConstantSyntax extends ConstantSyntax {
624624
super.path,
625625
}) : super._fromJson();
626626

627-
NullConstantSyntax({super.path = const []}) : super(type: 'Null');
627+
NullConstantSyntax({super.path = const []}) : super(type: 'null');
628628

629629
@override
630630
List<String> validate() => [
@@ -636,7 +636,7 @@ class NullConstantSyntax extends ConstantSyntax {
636636
}
637637

638638
extension NullConstantSyntaxExtension on ConstantSyntax {
639-
bool get isNullConstant => type == 'Null';
639+
bool get isNullConstant => type == 'null';
640640

641641
NullConstantSyntax get asNullConstant =>
642642
NullConstantSyntax.fromJson(json, path: path);
@@ -916,7 +916,7 @@ class StringConstantSyntax extends ConstantSyntax {
916916
}) : super._fromJson();
917917

918918
StringConstantSyntax({required String value, super.path = const []})
919-
: super(type: 'String') {
919+
: super(type: 'string') {
920920
_value = value;
921921
json.sortOnKey();
922922
}
@@ -944,7 +944,7 @@ class StringConstantSyntax extends ConstantSyntax {
944944
}
945945

946946
extension StringConstantSyntaxExtension on ConstantSyntax {
947-
bool get isStringConstant => type == 'String';
947+
bool get isStringConstant => type == 'string';
948948

949949
StringConstantSyntax get asStringConstant =>
950950
StringConstantSyntax.fromJson(json, path: path);

‎pkgs/record_use/test/test_data.dart‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const recordedUsesJson = '''{
112112
},
113113
"constants": [
114114
{
115-
"type": "String",
115+
"type": "string",
116116
"value": "lib_SHA1"
117117
},
118118
{
@@ -124,11 +124,11 @@ const recordedUsesJson = '''{
124124
"value": 1
125125
},
126126
{
127-
"type": "String",
127+
"type": "string",
128128
"value": "mercury"
129129
},
130130
{
131-
"type": "String",
131+
"type": "string",
132132
"value": "jenkins"
133133
},
134134
{
@@ -142,15 +142,15 @@ const recordedUsesJson = '''{
142142
}
143143
},
144144
{
145-
"type": "String",
145+
"type": "string",
146146
"value": "camus"
147147
},
148148
{
149-
"type": "String",
149+
"type": "string",
150150
"value": "einstein"
151151
},
152152
{
153-
"type": "String",
153+
"type": "string",
154154
"value": "insert"
155155
},
156156
{
@@ -178,17 +178,17 @@ const recordedUsesJson = '''{
178178
"value": 42
179179
},
180180
{
181-
"type": "Null"
181+
"type": "null"
182182
},
183183
{
184-
"type": "Instance",
184+
"type": "instance",
185185
"value": {
186186
"a": 13,
187187
"b": 14
188188
}
189189
},
190190
{
191-
"type": "Instance"
191+
"type": "instance"
192192
}
193193
],
194194
"locations": [
@@ -283,7 +283,7 @@ const recordedUsesJson2 = '''{
283283
"value": 1
284284
},
285285
{
286-
"type": "String",
286+
"type": "string",
287287
"value": "mercury"
288288
},
289289
{

‎pkgs/record_use/test_data/json/extension.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "../../doc/schema/record_use.schema.json",
33
"constants": [
44
{
5-
"type": "String",
5+
"type": "string",
66
"value": "42"
77
}
88
],

‎pkgs/record_use/test_data/json/instance_class.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"value": 42
77
},
88
{
9-
"type": "Instance",
9+
"type": "instance",
1010
"value": {
1111
"i": 0
1212
}

‎pkgs/record_use/test_data/json/instance_complex.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"value": 15
77
},
88
{
9-
"type": "String",
9+
"type": "string",
1010
"value": "s"
1111
},
1212
{
@@ -40,10 +40,10 @@
4040
]
4141
},
4242
{
43-
"type": "Null"
43+
"type": "null"
4444
},
4545
{
46-
"type": "Instance",
46+
"type": "instance",
4747
"value": {
4848
"i": 0,
4949
"s": 1,

‎pkgs/record_use/test_data/json/instance_duplicates.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"value": 42
77
},
88
{
9-
"type": "Instance",
9+
"type": "instance",
1010
"value": {
1111
"i": 0
1212
}
@@ -16,7 +16,7 @@
1616
"value": 43
1717
},
1818
{
19-
"type": "Instance",
19+
"type": "instance",
2020
"value": {
2121
"i": 2
2222
}

‎pkgs/record_use/test_data/json/instance_method.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"value": 42
77
},
88
{
9-
"type": "Instance",
9+
"type": "instance",
1010
"value": {
1111
"i": 0
1212
}

0 commit comments

Comments
 (0)