-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[native_assets_cli] Syntax validation #2115
Conversation
PR HealthBreaking changes ✔️
Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
License Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
|
List<Object?> list, | ||
String key, | ||
) { | ||
var index = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd either use a normal C-style for loop and do final value = list[i]
or use for (final (index, value) in list.indexed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did I not know about .indexed
!
throwFormatException(value, T, [key]); | ||
} | ||
|
||
List<String> validate<T extends Object?>(String key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: T extends Object?
is the same as just T
but it's fine if you want to be more descriptive.
Not as important in generated code but a name like validateIsA
better describes the type checking here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah Object? == dynamic
I thought it excludes dynamic, but it doesn't.
validate
I wanted to keep it analogous to get
. We could do getA
, but I feel it makes it less readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think T extends Object?
is different to T
regarding the avoid_dynamic_calls
lint. I might be wrong on this though.
throwFormatException(value, T, [key]); | ||
} | ||
|
||
List<String> validate<T extends Object?>(String key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to have a full Dart class in a string? This feels like it should live somewhere the analyzer can look at it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to do that initially, but that means that invoking the code generator as a library needs to know where the code generator is so that it can find the file and read it as a String.
If we were to change the code generator to have a bin/
script we would know from the entry point. But we invoke it with a Dart API (and pass in a bunch of objects).
We could change the API to have to pass in URI of the package, but that also seems messy.
I'm open to suggestions.
(Orthogonal to this PR, so we should probably do that in a separate PR.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the entry point in hook/tool/generate_syntax.dart
, where you could hardcode the path to the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think passing the path to the file is not messy, but your choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes the Dart API have an extra param and less encapsulated. More ugly in the implementation but less ugly on call sites.
If this package ever gets published on pub, then the user would have to know the path of the package in the pub-cache and pass it in. That feels too messy.
(And publishing a full blown helper package package:json_syntax_runtime_lib
like we have with package:jni
, seems way too much overkill here.)
Let's keep the ugly inside instead of on the API.
@@ -28,6 +28,11 @@ class AndroidCodeConfig { | |||
json.setOrRemove('target_ndk_api', value); | |||
} | |||
|
|||
List<String> _validateTargetNdkApi() => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a header to the file detailing
- where it was generated/what generates it
- how to regenerate this, and when
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Orthogonal to this PR, let me do that in a separate PR
@@ -76,6 +91,26 @@ void _validateDataAsset( | |||
errors.addAll(_validateFile('Data asset ${dataAsset.name} file', file)); | |||
} | |||
|
|||
List<String> _validateDataAssetSyntax(EncodedAsset encodedAsset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation would be much appreciated ;) List<String>
is not a very expressive return type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, we actually have typedef ValidationErrors
. Good catch!
Thanks @HosseinYousefi & @mosuem ! |
Bug: #1826
This PR adds generated
validate
functions on the syntax classes that check the type and nullability of the required fields.This PR does not separate syntax and semantic validation in the
ProtocolExtension
as proposed in #2088. The inputs/outputs classes expose the underlying JSON and are lazy. So, they don't fail on syntax errors unless traversed.This PR does not yet address:
input.config.code.android.target_ndk_api
should be required in JSON #2039 (follow up PR)file
is required iflink_mode
is x).To prevent crashes in the semantic validation, the semantic validation is not run when when syntactic errors are found. To prevent confusion for users, an extra error message is added that semantic validation is not run if syntactic errors are found.
We should consider also skipping extension validation if any errors occur in the base protocol, the validation code of extensions should be able to rely on that base protocol doesn't contain any errors.