-
Notifications
You must be signed in to change notification settings - Fork 18
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
avoid_using_api: Lint Default Constructor Only #126
Comments
I also want to explore linting constructor parameters |
Maybe something like that? custom_lint:
rules:
- avoid_using_api:
entries:
# Add parentheses to lint only default constructor, use `identifier` for named constructors
- class_name: Border
method: ()
source: package:flutter
reason: Use `BorderDirectional` instead. and then custom_lint:
rules:
- avoid_using_api:
entries:
# Add parentheses to lint only default constructor, use `identifier` for named constructors
- class_name: Border
method: all()
source: package:flutter
reason: Use `BorderDirectional` instead. |
In your example, is I think that would work better. for linting method parameters, I was thinking we could do something like this: custom_lint:
rules:
- avoid_using_api:
entries:
- class_name: Border
identifier: (left)
source: package:flutter
reason: Use `BorderDirectional(start)` instead. |
Yes - that should be it. Not sure what |
The intent for my second comment was to only lint usage of a specific parameter in a constructor (or method) final border = const Border(left: 4.0); // LINT
final border2 = const Border(top: 4.0); // Okay custom_lint:
rules:
- avoid_using_api:
entries:
- class_name: Border
identifier: ()
parameter: left
source: package:flutter
reason: Use `BorderDirectional(start)` instead. |
Oh that's interesting! What if multiple parameters? It could be named |
I'm not sure how much benefit having multiple named parameters in a lint entry would provide. In my opinion, it's best if the lint reason is as specific as possible and should say what to use as a replacement. Linting multiple named parameters (while convenient) would require a more general lint reason, it wouldn't be able to say exactly what should be changed. I'm in favor of it being named |
I think it's settled then, we can return to multiple named parameters if the need arises. |
Instead of empty parentheses, I think it would be better to use the custom_lint:
rules:
- avoid_using_api:
entries:
- class_name: Border
identifier: new
named_parameter: left
source: package:flutter
reason: Use `BorderDirectional()` instead. |
Since |
While using the lint I noticed I missed an edge case, it is not possible to lint only the default constructor. it will always lint all usages of the class
Potential usage:
Not sure if this is the best way to implement it, and I could see it being confusing if named constructors (ie
class_name: Border.all()
) didn't also work. Thoughts?I can implement this.
The text was updated successfully, but these errors were encountered: