You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Organise imports places @Timeout in the wrong position #3598
If you are using the test package you are able to add an @timeout annotation to the top of a library to indicate a longer than default timeout for the tests.
The @timeout annotation MUST be at the top of the file.
If you have the @timeout annotation and run 'Organise Imports' the @timeout annotation often gets moved down in amongst the imports and in some cases is completely deleted.
This causes an error an you have to manually move the annotation back to the top of the file or worse still removes it all together and if it is deleted you may not even realise it has been deleted.
Delete Example
In this example 'dart:io' is an unused package. Running organise imports removes dart:io and also @timeout
@bwilkerson the Timeout class is decorated with @Target(TargetKind.library) which is documented as:
/// Indicates that an annotation is valid on the first directive in a library,
/// whether that's a `library`, `import`, `export` or `part` directive. This
/// doesn't include the `part of` directive in a part file.
library,
Would this be the best way to determine whether the annotation should be anchored to the top?
I'm assuming it's not possible to have a single unused import (that would leave nowhere for the annotation to go), as you'd need to always either by importing the file containing the annotation, or if the annotation is in the current file, importing the meta package to be able to decorate it with Target?
Would this be the best way to determine whether the annotation should be anchored to the top?
I can't think of any better way.
I'm assuming it's not possible to have a single unused import ...
Not a single unused import that's annotated with something from meta. You could certainly have an unused import that's annotated with an annotation that's defined locally:
@local
import 'dart:math';
const local = '';
In that case the annotation won't have a Target associated with it. Not sure whether it's better to remove the annotation along with the last directive or whether it's better to leave it attached to the first declaration (assuming there is one). I doubt it will come up often, though.
Activity
DanTup commentedon Oct 7, 2021
@bwilkerson the
Timeoutclass is decorated with@Target(TargetKind.library)which is documented as:Would this be the best way to determine whether the annotation should be anchored to the top?
I'm assuming it's not possible to have a single unused import (that would leave nowhere for the annotation to go), as you'd need to always either by importing the file containing the annotation, or if the annotation is in the current file, importing the
metapackage to be able to decorate it withTarget?bwilkerson commentedon Oct 7, 2021
I can't think of any better way.
Not a single unused import that's annotated with something from meta. You could certainly have an unused import that's annotated with an annotation that's defined locally:
In that case the annotation won't have a
Targetassociated with it. Not sure whether it's better to remove the annotation along with the last directive or whether it's better to leave it attached to the first declaration (assuming there is one). I doubt it will come up often, though.[analysis_server] Preserve library-level annotations when removing/so…
[analysis_server] Improve handling of library-target annotations when…
DanTup commentedon Nov 9, 2021
This should be fixed with dart-lang/sdk@445ac5d. It's a change in the SDK rather than Dart-Code so will show up with an SDK release.