Skip to content
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

Added rule avoid_final_parameters #3045

Merged
merged 2 commits into from
Oct 28, 2021

Conversation

mat100payette
Copy link
Contributor

@mat100payette mat100payette commented Oct 27, 2021

Added rule avoid_final_parameters

Description

This is a new lint rule to be used with parameter_assignments. It is a style rule.
Tests passed on my end (ran on Windows 10).

02:01 +565: All tests passed!

Fixes #3036

Added rule avoid_final_parameters
@google-cla google-cla bot added the cla: yes label Oct 27, 2021
@kevmoo kevmoo requested a review from pq October 27, 2021 00:47
@coveralls
Copy link

coveralls commented Oct 27, 2021

Coverage Status

Coverage increased (+0.02%) to 94.158% when pulling 1105500 on mat100payette:avoid_final_parameters_rule into f31a8f7 on dart-lang:master.

@pq
Copy link
Member

pq commented Oct 27, 2021

This looks great. Could you add yourself to AUTHORS while you're at it?

Copy link
Member

@pq pq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Nicely done. Thanks!

It'd be great to get an attribution in AUTHORS and then let's land this.

Copy link
Member

@bwilkerson bwilkerson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the one comment, lgtm.

var visitor = _Visitor(this);
registry.addConstructorDeclaration(this, visitor);
registry.addFunctionExpression(this, visitor);
registry.addMethodDeclaration(this, visitor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although there are a couple of places where FormalParameterList can appear in the AST that aren't covered here, I believe that final is invalid in those places. As a result, it might be easier today, and require less maintenance in the future, to register to visit FormalParameterList directly than to register to visit the parents.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bwilkerson Just to be on the same page, can you provide 1 or 2 small examples of these other places ? To stay as consistent as possible, I made this rule reflect the opposite of prefer_final_parameters. That being said, I wouldn't mind doing slight changes to this PR if I understand them lol.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the course of replying I decided that it's better to leave the code the way you have it. Sorry for the noise.

Nodes of type FormalParameterList appear as a child of the following node types: ConstructorDeclaration, FieldFormalParameter, FunctionExpression, FunctionTypeAlias, FunctionTypedFormalParameter, GenericFunctionType, and MethodDeclaration. The ones that are currently missing are in typedefs, both the old and new syntactic form, and in formal parameters whose type is a function. I believe that in all those locations any use of final is an error. Which means that if you did what I suggested we'd be double reporting in those places, which is something we strive to avoid.

@pq pq merged commit 7058a80 into dart-lang:master Oct 28, 2021
@mat100payette mat100payette deleted the avoid_final_parameters_rule branch October 28, 2021 16:25
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Aug 23, 2023
* Added rule avoid_final_parameters

Added rule avoid_final_parameters

* Update AUTHORS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

proposal: avoid_final_parameters
4 participants