mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
[pkg/vm_service] turn on a few more lints for this package
Change-Id: I8eef00c606e713e252db8834f730f1655cdd57a5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259509 Commit-Queue: Devon Carew <devoncarew@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com>
This commit is contained in:
parent
a3764263d8
commit
8e0f4f4191
|
@ -4,3 +4,6 @@ linter:
|
|||
rules:
|
||||
- directives_ordering
|
||||
- prefer_generic_function_type_aliases
|
||||
- prefer_initializing_formals
|
||||
- prefer_single_quotes
|
||||
- unnecessary_this
|
||||
|
|
|
@ -7,7 +7,7 @@ import 'dart:developer' as developer;
|
|||
void main(List<String> args) {
|
||||
String local1 = 'abcd';
|
||||
int local2 = 2;
|
||||
var longList = [1, "hello", 3, 5, 7, 11, 13, 14, 15, 16, 17, 18, 19, 20];
|
||||
var longList = [1, 'hello', 3, 5, 7, 11, 13, 14, 15, 16, 17, 18, 19, 20];
|
||||
var deepList = [
|
||||
Bar(),
|
||||
[
|
||||
|
@ -17,7 +17,7 @@ void main(List<String> args) {
|
|||
[7]
|
||||
]
|
||||
],
|
||||
"end"
|
||||
'end'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
@ -42,7 +42,7 @@ void foo(int val) {
|
|||
}
|
||||
|
||||
class Bar extends FooBar {
|
||||
String field1 = "my string";
|
||||
String field1 = 'my string';
|
||||
}
|
||||
|
||||
class FooBar {
|
||||
|
|
|
@ -8,7 +8,7 @@ void main(List<String> args) {
|
|||
if (true) local1 = 'abcd';
|
||||
|
||||
int local2 = 2;
|
||||
var longList = [1, "hello", 3, 5, 7, 11, 13, 14, 15, 16, 17, 18, 19, 20];
|
||||
var longList = [1, 'hello', 3, 5, 7, 11, 13, 14, 15, 16, 17, 18, 19, 20];
|
||||
var deepList = [
|
||||
Bar(),
|
||||
[
|
||||
|
@ -18,7 +18,7 @@ void main(List<String> args) {
|
|||
[7]
|
||||
]
|
||||
],
|
||||
"end"
|
||||
'end'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
@ -45,7 +45,7 @@ void foo(int val) {
|
|||
}
|
||||
|
||||
class Bar extends FooBar {
|
||||
String field1 = "my string";
|
||||
String field1 = 'my string';
|
||||
}
|
||||
|
||||
class FooBar {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
void main(List<String> args) {
|
||||
String local1 = 'abcd';
|
||||
int local2 = 2;
|
||||
var longList = [1, "hello", 3, 5, 7, 11, 13, 14, 15, 16, 17, 18, 19, 20];
|
||||
var longList = [1, 'hello', 3, 5, 7, 11, 13, 14, 15, 16, 17, 18, 19, 20];
|
||||
var deepList = [
|
||||
Bar(),
|
||||
[
|
||||
|
@ -15,7 +15,7 @@ void main(List<String> args) {
|
|||
[7]
|
||||
]
|
||||
],
|
||||
"end"
|
||||
'end'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
@ -38,7 +38,7 @@ void foo(int val) {
|
|||
}
|
||||
|
||||
class Bar extends FooBar {
|
||||
String field1 = "my string";
|
||||
String field1 = 'my string';
|
||||
}
|
||||
|
||||
class FooBar {
|
||||
|
|
|
@ -726,9 +726,9 @@ abstract class VmServiceInterface {
|
|||
return result;
|
||||
};
|
||||
if (m.deprecated) {
|
||||
gen.writeln("// ignore: deprecated_member_use_from_same_package");
|
||||
gen.writeln('// ignore: deprecated_member_use_from_same_package');
|
||||
}
|
||||
gen.write("response = await _serviceImplementation.${m.name}(");
|
||||
gen.write('response = await _serviceImplementation.${m.name}(');
|
||||
// Positional args
|
||||
m.args.where((arg) => !arg.optional).forEach((MethodArg arg) {
|
||||
if (arg.type.isArray) {
|
||||
|
@ -751,7 +751,7 @@ abstract class VmServiceInterface {
|
|||
}
|
||||
});
|
||||
}
|
||||
gen.writeln(");");
|
||||
gen.writeln(');');
|
||||
}
|
||||
gen.writeln('break;');
|
||||
}
|
||||
|
@ -1009,9 +1009,9 @@ class Method extends Member {
|
|||
// Special case for `getAllocationProfile`. We do not want to add these
|
||||
// params if they are false.
|
||||
if (name == 'getAllocationProfile') {
|
||||
gen.writeln("if (${arg.name} != null && ${arg.name})");
|
||||
gen.writeln('if (${arg.name} != null && ${arg.name})');
|
||||
} else {
|
||||
gen.writeln("if (${arg.name} != null)");
|
||||
gen.writeln('if (${arg.name} != null)');
|
||||
}
|
||||
gen.writeln("'${arg.name}': $valueRef,");
|
||||
});
|
||||
|
@ -1374,7 +1374,7 @@ class Type extends Member {
|
|||
|
||||
// Build from JSON.
|
||||
gen.writeln();
|
||||
String superCall = superName == null ? '' : ": super._fromJson(json) ";
|
||||
String superCall = superName == null ? '' : ': super._fromJson(json) ';
|
||||
if (name == 'Response' || name == 'TimelineEvent') {
|
||||
gen.write('${name}._fromJson(this.json)');
|
||||
} else {
|
||||
|
@ -1414,39 +1414,39 @@ class Type extends Member {
|
|||
} else if (name == 'Instance' && field.name == 'associations') {
|
||||
// Special case `Instance.associations`.
|
||||
gen.writeln("associations = json['associations'] == null "
|
||||
"? null : List<MapAssociation>.from("
|
||||
'? null : List<MapAssociation>.from('
|
||||
"_createSpecificObject(json['associations'], MapAssociation.parse));");
|
||||
} else if (name == 'Instance' && field.name == 'classRef') {
|
||||
// This is populated by `Obj`
|
||||
} else if (name == '_CpuProfile' && field.name == 'codes') {
|
||||
// Special case `_CpuProfile.codes`.
|
||||
gen.writeln("codes = List<CodeRegion>.from("
|
||||
gen.writeln('codes = List<CodeRegion>.from('
|
||||
"_createSpecificObject(json['codes']!, CodeRegion.parse));");
|
||||
} else if (name == '_CpuProfile' && field.name == 'functions') {
|
||||
// Special case `_CpuProfile.functions`.
|
||||
gen.writeln("functions = List<ProfileFunction>.from("
|
||||
gen.writeln('functions = List<ProfileFunction>.from('
|
||||
"_createSpecificObject(json['functions']!, ProfileFunction.parse));");
|
||||
} else if (name == 'SourceReport' && field.name == 'ranges') {
|
||||
// Special case `SourceReport.ranges`.
|
||||
gen.writeln("ranges = List<SourceReportRange>.from("
|
||||
gen.writeln('ranges = List<SourceReportRange>.from('
|
||||
"_createSpecificObject(json['ranges']!, SourceReportRange.parse));");
|
||||
} else if (name == 'SourceReportRange' && field.name == 'coverage') {
|
||||
// Special case `SourceReportRange.coverage`.
|
||||
gen.writeln("coverage = _createSpecificObject("
|
||||
gen.writeln('coverage = _createSpecificObject('
|
||||
"json['coverage'], SourceReportCoverage.parse);");
|
||||
} else if (name == 'Library' && field.name == 'dependencies') {
|
||||
// Special case `Library.dependencies`.
|
||||
gen.writeln("dependencies = List<LibraryDependency>.from("
|
||||
gen.writeln('dependencies = List<LibraryDependency>.from('
|
||||
"_createSpecificObject(json['dependencies']!, "
|
||||
"LibraryDependency.parse));");
|
||||
'LibraryDependency.parse));');
|
||||
} else if (name == 'Script' && field.name == 'tokenPosTable') {
|
||||
// Special case `Script.tokenPosTable`.
|
||||
gen.write("tokenPosTable = ");
|
||||
gen.write('tokenPosTable = ');
|
||||
if (field.optional) {
|
||||
gen.write("json['tokenPosTable'] == null ? null : ");
|
||||
}
|
||||
gen.writeln("List<List<int>>.from(json['tokenPosTable']!.map"
|
||||
"((dynamic list) => List<int>.from(list)));");
|
||||
'((dynamic list) => List<int>.from(list)));');
|
||||
gen.writeln('_parseTokenPosTable();');
|
||||
} else if (field.type.isArray) {
|
||||
TypeRef fieldType = field.type.types.first;
|
||||
|
@ -1454,41 +1454,43 @@ class Type extends Member {
|
|||
String ref = "json['${field.name}']";
|
||||
if (field.optional) {
|
||||
if (fieldType.isListTypeSimple) {
|
||||
gen.writeln("${field.generatableName} = $ref == null ? null : "
|
||||
"List<${fieldType.listTypeArg}>.from($ref);");
|
||||
gen.writeln('${field.generatableName} = $ref == null ? null : '
|
||||
'List<${fieldType.listTypeArg}>.from($ref);');
|
||||
} else {
|
||||
gen.writeln("${field.generatableName} = $ref == null ? null : "
|
||||
"List<${fieldType.listTypeArg}>.from(createServiceObject($ref, $typesList)! as List);");
|
||||
gen.writeln('${field.generatableName} = $ref == null ? null : '
|
||||
'List<${fieldType.listTypeArg}>.from(createServiceObject($ref, $typesList)! as List);');
|
||||
}
|
||||
} else {
|
||||
if (fieldType.isListTypeSimple) {
|
||||
// Special case `ClassHeapStats`. Pre 3.18, responses included keys
|
||||
// `new` and `old`. Post 3.18, these will be null.
|
||||
if (name == 'ClassHeapStats') {
|
||||
gen.writeln("${field.generatableName} = $ref == null ? null : "
|
||||
"List<${fieldType.listTypeArg}>.from($ref);");
|
||||
gen.writeln('${field.generatableName} = $ref == null ? null : '
|
||||
'List<${fieldType.listTypeArg}>.from($ref);');
|
||||
} else {
|
||||
gen.writeln("${field.generatableName} = "
|
||||
"List<${fieldType.listTypeArg}>.from($ref);");
|
||||
gen.writeln('${field.generatableName} = '
|
||||
'List<${fieldType.listTypeArg}>.from($ref);');
|
||||
}
|
||||
} else {
|
||||
// Special case `InstanceSet`. Pre 3.20, instances were sent in a
|
||||
// field named 'samples' instead of 'instances'.
|
||||
if (name == 'InstanceSet') {
|
||||
gen.writeln("${field.generatableName} = "
|
||||
gen.writeln('${field.generatableName} = '
|
||||
"List<${fieldType.listTypeArg}>.from(createServiceObject(($ref ?? json['samples']!) as List, $typesList)! as List);");
|
||||
} else {
|
||||
gen.writeln("${field.generatableName} = "
|
||||
"List<${fieldType.listTypeArg}>.from(createServiceObject($ref, $typesList) as List? ?? []);");
|
||||
gen.writeln('${field.generatableName} = '
|
||||
'List<${fieldType.listTypeArg}>.from(createServiceObject($ref, $typesList) as List? ?? []);');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String typesList = _typeRefListToString(field.type.types);
|
||||
String nullable = field.type.name != 'dynamic' ? '?' : '';
|
||||
gen.writeln("${field.generatableName} = "
|
||||
"createServiceObject(json['${field.name}'], "
|
||||
"$typesList) as ${field.type.name}$nullable;");
|
||||
gen.writeln(
|
||||
'${field.generatableName} = '
|
||||
"createServiceObject(json['${field.name}'], "
|
||||
'$typesList) as ${field.type.name}$nullable;',
|
||||
);
|
||||
}
|
||||
});
|
||||
if (fields.isNotEmpty) {
|
||||
|
@ -1585,7 +1587,7 @@ Map<String, dynamic> toJson() {
|
|||
if (toStringFields.length <= maxFieldsShownInToString) {
|
||||
String properties = toStringFields
|
||||
.map(
|
||||
(TypeField f) => "${f.generatableName}: \${${f.generatableName}}")
|
||||
(TypeField f) => '${f.generatableName}: \${${f.generatableName}}')
|
||||
.join(', ');
|
||||
if (properties.length > 60) {
|
||||
int index = properties.indexOf(', ', 55);
|
||||
|
@ -1801,7 +1803,7 @@ class TypeField extends Member {
|
|||
case 'String':
|
||||
return "''";
|
||||
case 'ByteData':
|
||||
return "ByteData(0)";
|
||||
return 'ByteData(0)';
|
||||
}
|
||||
if (type.isEnum) {
|
||||
// TODO(bkonyi): Figure out if there's a more correct way to determine a
|
||||
|
|
|
@ -15,7 +15,7 @@ class DartGenerator {
|
|||
|
||||
final int colBoundary;
|
||||
|
||||
String _indent = "";
|
||||
String _indent = '';
|
||||
final StringBuffer _buf = StringBuffer();
|
||||
|
||||
bool _previousWasEol = false;
|
||||
|
@ -56,27 +56,27 @@ class DartGenerator {
|
|||
writeln(str);
|
||||
} else {
|
||||
writeln(str.substring(0, index + 1));
|
||||
writeln(" ${str.substring(index + 1)}");
|
||||
writeln(' ${str.substring(index + 1)}');
|
||||
}
|
||||
} else {
|
||||
writeln(str);
|
||||
}
|
||||
}
|
||||
|
||||
void writeln([String str = ""]) => _write("${str}\n");
|
||||
void writeln([String str = '']) => _write('${str}\n');
|
||||
|
||||
void write(String str) => _write(str);
|
||||
|
||||
void out(String str) => _buf.write(str);
|
||||
|
||||
void _writeln([String str = "", bool ignoreCurlies = false]) =>
|
||||
_write("${str}\n", ignoreCurlies);
|
||||
void _writeln([String str = '', bool ignoreCurlies = false]) =>
|
||||
_write('${str}\n', ignoreCurlies);
|
||||
|
||||
void _write(String str, [bool ignoreCurlies = false]) {
|
||||
for (final int rune in str.runes) {
|
||||
if (!ignoreCurlies) {
|
||||
if (rune == RUNE_LEFT_CURLY) {
|
||||
_indent = "${_indent} ";
|
||||
_indent = '${_indent} ';
|
||||
} else if (rune == RUNE_RIGHT_CURLY && _indent.length >= 2) {
|
||||
_indent = _indent.substring(2);
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ class Api extends Member with ApiParseUtil {
|
|||
writer.addLine('logUnknownResponse(consumer, json);');
|
||||
}, modifiers: null, isOverride: true);
|
||||
|
||||
writer.addMethod("convertMapToJsonObject", [
|
||||
writer.addMethod('convertMapToJsonObject', [
|
||||
JavaMethodArg('map', 'Map<String, String>')
|
||||
], (StatementWriter writer) {
|
||||
writer.addLine('JsonObject obj = new JsonObject();');
|
||||
|
@ -221,17 +221,17 @@ class Api extends Member with ApiParseUtil {
|
|||
writer.addLine(' obj.addProperty(key, map.get(key));');
|
||||
writer.addLine('}');
|
||||
writer.addLine('return obj;');
|
||||
}, modifiers: "private", returnType: "JsonObject");
|
||||
}, modifiers: 'private', returnType: 'JsonObject');
|
||||
|
||||
writer.addMethod(
|
||||
"convertIterableToJsonArray", [JavaMethodArg('list', 'Iterable')],
|
||||
'convertIterableToJsonArray', [JavaMethodArg('list', 'Iterable')],
|
||||
(StatementWriter writer) {
|
||||
writer.addLine('JsonArray arr = new JsonArray();');
|
||||
writer.addLine('for (Object element : list) {');
|
||||
writer.addLine(' arr.add(new JsonPrimitive(element.toString()));');
|
||||
writer.addLine('}');
|
||||
writer.addLine('return arr;');
|
||||
}, modifiers: "private", returnType: "JsonArray");
|
||||
}, modifiers: 'private', returnType: 'JsonArray');
|
||||
});
|
||||
|
||||
for (var m in methods) {
|
||||
|
@ -534,7 +534,7 @@ class Method extends Member {
|
|||
for (var t in returnType.types) {
|
||||
writer.addImport(t.elementTypeName);
|
||||
writer.addMethod(
|
||||
"received", [JavaMethodArg('response', t.elementTypeName)], null);
|
||||
'received', [JavaMethodArg('response', t.elementTypeName)], null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -925,7 +925,7 @@ class TypeField extends Member {
|
|||
for (TypeRef t in type.types) {
|
||||
String refName = t.name!;
|
||||
if (refName.endsWith('Ref')) {
|
||||
refName = "@" + refName.substring(0, refName.length - 3);
|
||||
refName = '@' + refName.substring(0, refName.length - 3);
|
||||
}
|
||||
w.addLine('if (elem.get("type").getAsString().equals("${refName}")) '
|
||||
'return new ${t.name}(elem);');
|
||||
|
|
|
@ -125,10 +125,9 @@ class TypeWriter {
|
|||
final Map<String, String> _methods = Map<String, String>();
|
||||
final String scriptLocation;
|
||||
|
||||
TypeWriter(String typeName, scriptLocation)
|
||||
: this.pkgName = pkgNameFor(typeName),
|
||||
this.className = classNameFor(typeName),
|
||||
this.scriptLocation = scriptLocation;
|
||||
TypeWriter(String typeName, this.scriptLocation)
|
||||
: pkgName = pkgNameFor(typeName),
|
||||
className = classNameFor(typeName);
|
||||
|
||||
String get kind {
|
||||
if (isInterface) return 'interface';
|
||||
|
|
Loading…
Reference in a new issue