-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Proposal to enhance the deprecated annotation #32726
Comments
Honestly I'd rather see named constructors be used for this versus lots of optional arguments: // Renamed/moved to another library.
const factory Deprecated.movedTo(String name, {String sourceLibrary});
// Being removed entirely without an explicit replacement.
const factory Deprecated.willBeRemoved(); |
An annotation like this is really a small language. The "replacedBy" string is interpreted by tools, in the static context of the declaration. It's like DartDoc references in that way, and restricted in the same ways. On top of that, it only allows you to specify renamings - a tool that applies the change can only change one reference to another, it can't change, say, a value to a function returning that value (like the change I'm not sure it's really worth it as long as we are using strings as "change descriptors". We don't plan to make that many more renamings, and it can't handle complex changes anyway, so the value is limited. (And yes, named constructors are probably better, as proven by all the examples in the proposal being invalid because they omit the positional "expires" argument. 😄) |
I think we should aim for a very simple language here, but the main thing might well be the ability to name a transformation which is supported by some tool. That tool would then be able to traverse the source code, find each AST node where some deprecated feature is used, and use the name of the transformation to select and run a fix-up procedure on that node. It could do anything, including transforming the code to some extent and then putting up a dialog box saying "Please complete the following code such that ...[something]...". |
Here are some examples of recent deprecations (and, ~toolable deprecation transformations we'd like to support): https://gist.github.com/zanderso/d554e6159f486e8f96759a4f9774a01a |
I suspect that data-driven fixes satisfy most of the need for this proposed enhancement, so I'm closing this as not intended. |
Enhance the Deprecated annotation with additional information to support automated migration tooling.
The constructor for the class
Deprecated
should be enhanced to take named parameters whose values can be used by tools to automate the migration of use sites from the deprecated API to a newer API when one exists.Some migrations will not be amenable to automated tooling and/or will be infrequent enough to not justify the time required to support them, but I believe that we can and should support the most common migrations.
One of the simplest, and probably the most common, use cases for this support is to rename a member. I propose that we begin with a single named parameter containing the new name. Below is sample text for the Dartdoc describing this parameter.
The second most common use case is probably moving a member from one library to another. I believe that we can support this use case (in the future) by adding a second named parameter containing the URI of the library containing the replacing member.
Some additional use cases that we might consider supporting are changes to the number or types of function parameters or the number of type parameters. I believe that these could be supported by extending the interpretation of the
replacedBy
parameter's content, but have not done the design work related to them because I don't think we ought to try to support these cases at this time.The text was updated successfully, but these errors were encountered: