mirror of
https://github.com/flutter/flutter.git
synced 2026-01-09 07:51:35 +08:00
- Initial config files for [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). These config files are modified versions of the one already added to the flutter/packages repo: https://github.com/flutter/packages/pull/9632 based on [the official docs](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). - Style guide has links to various contributing docs and style guides. - Ignore paths associated with version pins and third_party to avoid reviews on rolls and code that doesn't need modification. See https://github.com/flutter/packages/pull/9647. - Add a note to the PR template to provide some notice/guidance to contributors about how to use automated feedback, to clarify the role of the automated reviews and hopefully minimize potential issues in case the bot leaves incorrect feedback. This is a direct copy of the comment introduced in https://github.com/flutter/packages/pull/9632. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
4.5 KiB
4.5 KiB
Flutter Style Guide
This style guide outlines the coding conventions for contributions to the flutter/flutter repository. It is based on the more comprehensive official style guide for the Flutter repository.
Best Practices
- Code should follow the guidance and principles described in the Flutter contribution guide.
- Code should be tested and follow the guidance described in the writing effective tests guide and the running and writing tests guide.
- Changes to the engine/ directory should additionally have appropriate tests as described in the engine test guidance.
- PR descriptions should include the Pre-launch Checklist from the PR template, with all of the steps completed.
General Philosophy
- Optimize for readability: Code is read more often than it is written.
- Avoid duplicating state: Keep only one source of truth.
- Write what you need and no more, but when you write it, do it right.
- Error messages should be useful: Every error message is an opportunity to make someone love our product.
Dart Formatting
- All Dart code is formatted using
dart format. This is enforced by CI. - Constructors come first in a class definition, with the default constructor preceding named constructors.
- Other class members should be ordered logically (e.g., by lifecycle, or grouping related fields and methods).
Miscellaneous Languages
- Python code is formatted using
yapf, linted withpylint, and should follow the Google Python Style Guide. - C++ code is formatted using
clang-format, linted withclang-tidy, and should follow the Google C++ Style Guide. - Shaders are formatted using
clang-format. - Kotlin code is formatted using
ktformat, linted withktlint, and should follow the Android Kotlin Style Guide. - Java code is formatted using
google-java-formatand should follow the Google Java Style Guide. - Objective-C is formatted using
clang-format, linted withclang-tidy, and should follow the Google Objective-C Style Guide. - Swift is formatted and linted using
swift-formatand should follow the Google Swift Style Guide. - GN code is formatted using
gn formatand should follow the GN Style Guide.
Documentation
- All public members should have documentation.
- Answer your own questions: If you have a question, find the answer, and then document it where you first looked.
- Avoid useless documentation: If the documentation just repeats the member's name, it's useless. Explain the why and the how.
- Introduce terms: Don't assume the reader knows everything. Link to definitions.
- Provide sample code: Use
{@tool dartpad}for runnable examples. - Provide illustrations or screenshots for widgets.
- Use
///for public-quality documentation, even on private members.
Further Reading
For more detailed guidance, refer to the following documents: