Skip to content

Commit 3756f59

Browse files
carlescufikartben
authored andcommitted
doc: contribution guidelines: Clarify and extend
Clarify and extend some of the PR and contribution guidelines so that they cover practices that have been effectively enforced by maintainers, but were never properly documented. Signed-off-by: Carles Cufi <[email protected]> Signed-off-by: Anas Nashif <[email protected]>
1 parent 8a305df commit 3756f59

File tree

5 files changed

+121
-28
lines changed

5 files changed

+121
-28
lines changed

doc/build/kconfig/tips.rst

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -876,31 +876,10 @@ For a Kconfig symbol that enables a driver/subsystem FOO, consider having just
876876
usually be clear in the context of an option that can be toggled on/off, and
877877
makes things consistent.
878878

879+
Style
880+
=====
879881

880-
Header comments and other nits
881-
==============================
882-
883-
A few formatting nits, to help keep things consistent:
884-
885-
- Use this format for any header comments at the top of ``Kconfig`` files:
886-
887-
.. code-block:: none
888-
889-
# <Overview of symbols defined in the file, preferably in plain English>
890-
(Blank line)
891-
# Copyright (c) 2019 ...
892-
# SPDX-License-Identifier: <License>
893-
(Blank line)
894-
(Kconfig definitions)
895-
896-
- Format comments as ``# Comment`` rather than ``#Comment``
897-
898-
- Put a blank line before/after each top-level ``if`` and ``endif``
899-
900-
- Use a single tab for each indentation
901-
902-
- Indent help text with two extra spaces
903-
882+
See :ref:`coding_style` for style guidelines.
904883

905884
Lesser-known/used Kconfig features
906885
**********************************

doc/contribute/contributor_expectations.rst

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,83 @@ Changes which require an RFC proposal include:
8787
Maintainers have the discretion to request that contributors create an RFC for
8888
PRs that are too large or complicated.
8989

90+
.. _pr_requirements:
91+
9092
PR Requirements
9193
***************
9294

9395
- Each commit in the PR must provide a commit message following the
9496
:ref:`commit-guidelines`.
9597

98+
- No fixup or merge commits are allowed, see :ref:`Contribution workflow` for
99+
more information.
100+
96101
- The PR description must include a summary of the changes and their rationales.
97102

98103
- All files in the PR must comply with :ref:`Licensing
99104
Requirements<licensing_requirements>`.
100105

101-
- Follow the Zephyr :ref:`coding_style` and :ref:`coding_guidelines`.
106+
- The code must follow the Zephyr :ref:`coding_style` and :ref:`coding_guidelines`.
102107

103-
- PRs must pass all CI checks. This is a requirement to merge the PR.
108+
- The PR must pass all CI checks, as described in :ref:`merge_criteria`.
104109
Contributors may mark a PR as draft and explicitly request reviewers to
105110
provide early feedback, even with failing CI checks.
106111

107-
- When breaking a PR into multiple commits, each commit must build cleanly. The
112+
- When breaking up a PR into multiple commits, each commit must build cleanly. The
108113
CI system does not enforce this policy, so it is the PR author's
109114
responsibility to verify.
110115

116+
- Commits in a pull request should represent clear, logical units of change that are easy to review
117+
and maintain bisectability. The following guidelines expand on this principle:
118+
119+
1. Distinct, Logical Units of Change
120+
121+
Each commit should correspond to a self-contained, meaningful change. For example, adding a
122+
feature, fixing a bug, or refactoring existing code should be separate commits. Avoid mixing
123+
different types of changes (e.g., feature implementation and unrelated refactoring) in the same
124+
commit.
125+
126+
2. Retain Bisectability
127+
128+
Every commit in the pull request must build successfully and pass all relevant tests. This
129+
ensures that git bisect can be used effectively to identify the specific commit that introduced
130+
a bug or issue.
131+
132+
3. Squash Intermediary or Non-Final Development History
133+
134+
During development, commits may include intermediary changes (e.g., partial implementations,
135+
temporary files, or debugging code). These should be squashed or rewritten before submitting the
136+
pull request. Remove non-final artifacts, such as:
137+
138+
* Temporary renaming of files that are later renamed again.
139+
* Code that was rewritten or significantly changed in later commits.
140+
141+
4. Ensure Clean History Before Submission
142+
143+
Use interactive rebasing (git rebase -i) to clean up the commit history before submitting the
144+
pull request. This helps in:
145+
146+
* Squashing small, incomplete commits into a single cohesive commit.
147+
* Ensuring that each commit remains bisectable.
148+
* Maintaining proper attribution of authorship while improving clarity.
149+
150+
5. Renaming and Code Rewrites
151+
152+
If files or code are renamed or rewritten in later commits during development, squash or rewrite
153+
earlier commits to reflect the final structure. This ensures that:
154+
155+
* The history remains clean and easy to follow.
156+
* Bisectability is preserved by eliminating redundant renaming or partial rewrites.
157+
158+
6. Attribution of Authorship
159+
160+
While cleaning up the commit history, ensure that authorship attribution remains accurate.
161+
162+
7. Readable and Reviewable History
163+
164+
The final commit history should be easy to understand for future maintainers. Logical units of
165+
change should be grouped into commits that tell a clear, coherent story of the work done.
166+
111167
- When major new functionality is added, tests for the new functionality shall
112168
be added to the automated test suite. All API functions should have test cases
113169
and there should be tests for the behavior contracts of the API. Maintainers
@@ -133,6 +189,13 @@ PR Requirements
133189
- Changes to APIs must increment the API version number according to the API
134190
version rules.
135191

192+
- Documentation must be added and/or updated to reflect the changes in the code
193+
introduced by the PR. The documentation changes must use the proper
194+
terminology as present in the existing pages, and must be written in American
195+
English. If you include images as part of the documentation, those must follow
196+
the rules in :ref:`doc_images`. Please refer to :ref:`doc_guidelines` for
197+
additional information.
198+
136199
- PRs must also satisfy all :ref:`merge_criteria` before a member of the release
137200
engineering team merges the PR into the zephyr tree.
138201

doc/contribute/documentation/guidelines.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ Cross-referencing C documentation
700700
Visual Elements
701701
***************
702702

703+
.. _doc_images:
704+
703705
Images
704706
======
705707

doc/contribute/guidelines.rst

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,28 @@ reference manuals, etc.
536536
Coding Style
537537
============
538538

539+
.. note::
540+
Coding style is enforced on any new or modified code, but contributors are
541+
not expected to correct the style on existing code that they are not
542+
modifying.
543+
544+
.. note::
545+
For style aspects where the guidelines don't offer explicit guidance or
546+
permit multiple valid ways to express something, contributors should follow
547+
the style of existing code in the tree, with higher importance given to
548+
"nearby" code (first look at the function, then the same file, then
549+
subsystem, etc).
550+
539551
.. _Linux kernel coding style:
540552
https://kernel.org/doc/html/latest/process/coding-style.html
541553

554+
.. _snake case:
555+
https://en.wikipedia.org/wiki/Snake_case
556+
542557
In general, follow the `Linux kernel coding style`_, with the following
543-
exceptions:
558+
exceptions and clarifications:
544559

560+
* Use `snake case`_ for code and variables.
545561
* The line length is 100 columns or fewer. In the documentation, longer lines
546562
for URL references are an allowed exception.
547563
* Add braces to every ``if``, ``else``, ``do``, ``while``, ``for`` and
@@ -553,6 +569,38 @@ exceptions:
553569
* Avoid using binary literals (constants starting with ``0b``).
554570
* Avoid using non-ASCII symbols in code, unless it significantly improves
555571
clarity, avoid emojis in any case.
572+
* Use proper capitalization of nouns in code comments (e.g. ``UART`` and not
573+
``uart``, ``CMake`` and not ``cmake``).
574+
575+
Beyond C code, the following coding style rules apply to other types of files:
576+
577+
* CMake
578+
579+
* Indent with spaces, indentation is two spaces.
580+
* Don't use space between commands (e.g. ``if``) and the corresponding opening
581+
bracket (e.g. ``(``).
582+
583+
* Devicetree
584+
585+
* Indent with tabs.
586+
* Follow the Devicetree specification conventions and rules.
587+
* Use dashes (``-``) as word separators for node and property names.
588+
* Use underscores (``_``) as word separators in node labels.
589+
* Leave a single space on each side of the equal sign (``=``) in property
590+
definitions.
591+
* Don't insert empty lines before a dedenting ``};``.
592+
* Insert a single empty line to separate nodes at the same hierarchy level.
593+
594+
* Kconfig
595+
596+
* Line length of 100 columns or fewer.
597+
* Indent with tabs, except for ``help`` entry text which should be placed at
598+
one tab plus two extra spaces.
599+
* Leave a single empty line between option declarations.
600+
* Use Statements like ``select`` carefully, see
601+
:ref:`kconfig_tips_and_tricks` for more information.
602+
* Format comments as ``# Comment`` rather than ``#Comment``
603+
* Insert an empty line before/after each top-level ``if`` and ``endif``
556604

557605
Use these coding guidelines to ensure that your development complies with the
558606
project's style and naming conventions.

doc/project/project_roles.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ Release Activity
350350
Merge Criteria
351351
++++++++++++++
352352

353+
* All :ref:`pr_requirements` must be met.
353354
* Minimal of 2 approvals, including an approval by the designated assignee.
354355
* Pull requests should be reviewed by at least a maintainer or collaborator of
355356
each affected area; Unless the changes to a given area are considered trivial

0 commit comments

Comments
 (0)