-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: add rule for final_defined_class
#278
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @ostk0069, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request introduces a new lint rule, final_defined_class
, to encourage developers to mark classes as final
if they are not intended to be extended. This enhances code clarity and prevents unintended inheritance. The PR includes the implementation of the lint rule, a quick fix to automatically add the final
keyword, and updates to the documentation.
Highlights
- New Lint Rule:
final_defined_class
: The pull request adds a new lint rule that suggests marking classes asfinal
when they are not designed for inheritance. This promotes better code design and prevents unintended extensions. - Quick Fix Implementation: A quick fix is included to automatically add the
final
keyword to class declarations, making it easy for developers to apply the suggestion. - Documentation Update: The
README.md
file is updated to include documentation for the newfinal_defined_class
rule, providing usage examples and configuration details.
Changelog
Click here to see the changelog
- packages/nilts/README.md
- Added documentation for the
final_defined_class
lint rule, including target SDK, rule type, maturity level, and quick fix availability. - Included 'bad' and 'good' code examples to illustrate the rule's purpose.
- Added documentation for the
- packages/nilts/lib/nilts.dart
- Imported the
final_defined_class.dart
file. - Registered the
FinalDefinedClass
lint rule, making it available for analysis.
- Imported the
- packages/nilts/lib/src/lints/final_defined_class.dart
- Implemented the
FinalDefinedClass
lint rule, which checks for classes that are not marked asfinal
but could be. - Implemented the
_AddFinalKeyword
fix, which automatically adds thefinal
keyword to a class declaration. - The rule skips classes that are already
sealed
,abstract
,final
,base
,interface
, ormixin
.
- Implemented the
- packages/nilts_test/test/lints/final_defined_class.dart
- Added a test case to verify that the
final_defined_class
lint rule correctly identifies classes that should be marked asfinal
.
- Added a test case to verify that the
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Trivia time!
What keyword, introduced in Dart 3.0, restricts class inheritance?
Click here for the answer
The `final` keyword, when applied to a class, prevents it from being extended or implemented.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new lint rule final_defined_class
to encourage marking classes as final when they are not intended to be extended. The rule includes a quick fix to automatically add the final
keyword. The changes seem well-structured and include necessary documentation and tests.
Merge Readiness
The pull request introduces a new lint rule and associated quick fix, along with documentation and tests. Given the review settings, I have focused on identifying medium, high, and critical severity issues. I did not find any issues at those levels. Therefore, I believe the pull request is in good shape to be merged, pending any further reviews and approvals. I am unable to directly approve the pull request, and other reviewers should examine the code before merging.
final_defined_class
a25f3af
to
a1233aa
Compare
@@ -725,6 +725,36 @@ See also: | |||
|
|||
</details> | |||
|
|||
### final_defined_class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the rule in the rule list table.
<details> | ||
|
||
<!-- prettier-ignore-start --> | ||
- Target SDK : >= Flutter 3.10.0 (Dart 3.0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Target SDK : >= Flutter 3.10.0 (Dart 3.0.0) | |
- Target SDK : Any versions nilts supports |
ErrorReporter reporter, | ||
CustomLintContext context, | ||
) { | ||
context.registry.addClassDeclaration((node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (node.sealedKeyword != null || | ||
node.abstractKeyword != null || | ||
node.finalKeyword != null || | ||
node.baseKeyword != null || | ||
node.interfaceKeyword != null || | ||
node.mixinKeyword != null) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overview
add rule
final_defined_class
Feature type
Checklist
melos test
to run tests.