-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[new lint]: avoid_types_as_type_parameter_names
#58093
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
Comments
(Looking at this now.) |
Looking at the related lint, I see this comment: and then a heuristic: @scheglov, @bwilkerson: thoughts on a better way? Can we "synthesize" a type object for the identifier and see if it resolves? (Not saying this right I'm sure...) |
We would need to build a It would be useful to have such an API. We could use it here, and we could also use it when suggesting names to ensure that the name we're suggesting would not hide an existing name. I don't really want to make |
@scheglov: do you have any preferences given Brian's proposals? |
Coincidentally I was thinking how to update clients that currently use Yes, I think we could add a new method to |
Perhaps We'll need to carefully define what scope is being used by each class of node. For example, if the node is a |
Sorry, I thought some more about this issue, and think that maybe we should go with more specific services in For extension E on A {
int get foo => 0;
}
int foo = 0;
class A {
void bar() {
this.foo;
}
} So, maybe something like this? /// If the given [element] is declared in a class, mixin, or extension,
/// return `true` if it can be referenced by its name without `this.` prefix
/// at the location of the [node].
bool canReferenceElementWithoutThisPrefix(Element element, AstNode node); And for this new lint, provide exactly what the linter needs. /// Return `true` if the [name] if the name of a type defining element
/// in the library scope, i.e. of a class, mixin, or a function type alias.
///
/// Return `false` for names of other declarations - local variables and
/// functions, top-level functions, extensions, import prefixes, etc; or when
/// the name is not a name of any element.
bool isTypeName(String name); |
https://dart-review.googlesource.com/c/sdk/+/129819 implements |
https://dart-review.googlesource.com/c/sdk/+/129819 added |
Fantastic. When @stereotype441 is back and can do an analyzer push, let's get this all updated to use the new APIs. 👍 |
See #32042 (comment).
Related to: http://dart-lang.github.io/linter/lints/avoid_types_as_parameter_names.html
The text was updated successfully, but these errors were encountered: