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

149-new-lint-avoid_final_with_getter #161

Merged
merged 9 commits into from
Apr 19, 2024

Conversation

4akloon
Copy link
Contributor

@4akloon 4akloon commented Apr 17, 2024

added new avoid_final_with_getter rule

@4akloon 4akloon linked an issue Apr 17, 2024 that may be closed by this pull request
Copy link
Collaborator

@solid-vovabeloded solid-vovabeloded left a comment

Choose a reason for hiding this comment

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

Great work so far, @4akloon! I've added a couple of suggestions here - please, take a look.

Comment on lines 20 to 22
final int _myField = 0;

int get myFieldInt => _myField; // it is not a getter for the field too
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think in this case it should report the lint since it is a getter for the field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, but I think it is necessary to additionally check whether there is another getter or variable with the same name.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it make sense to search for a getter with exactly the same name as a variable. If we have a private variable and a public getter(with any name) that returns this variable we should show lint. Also, I think it makes sense to highlight the getter, but not the variable, so the user can see why we are saying that this field should be just public.

Copy link
Collaborator

@solid-vovabeloded solid-vovabeloded left a comment

Choose a reason for hiding this comment

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

Almost there, @4akloon! I've added one more suggestion and wanted to ask you to update the changelog with all the changes you've made so far.

isGetter: true,
declaredElement: ExecutableElement(
isAbstract: false,
isStatic: false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we actually need to skip static getters? I think we may have the same situation when a static getter returns the static final private variable that either does not make any sense. I would remove this restriction.

Copy link
Collaborator

@solid-vovabeloded solid-vovabeloded left a comment

Choose a reason for hiding this comment

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

Please, update the changelog file as well as I mentioned before

Comment on lines 13 to 18
class Fail2 {
final int _myField = 0;

// expect_lint: avoid_final_with_getter
int get myFieldInt => _myField;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to add a test for the static field and getter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it does

Copy link
Collaborator

@solid-vovabeloded solid-vovabeloded left a comment

Choose a reason for hiding this comment

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

LGTM! Great job, @4akloon.

@solid-vovabeloded solid-vovabeloded merged commit 8dc2cd5 into master Apr 19, 2024
2 checks passed
@solid-vovabeloded solid-vovabeloded deleted the 149-new-lint-avoid_final_with_getter branch April 19, 2024 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New lint: avoid_final_with_getter
2 participants