Debian Codegraph @

CONTRIBUTING.md

raw
1 # Contribution Guidelines
2
3 This document contains guidelines for contributing code to aerc. It has to be
4 followed in order for your patch to be approved and applied.
5
6 ## Contribution Channels
7
8 Anyone can contribute to aerc. First you need to clone the repository and build
9 the project:
10
11 $ git clone https://git.sr.ht/~rjarry/aerc
12 $ cd aerc
13 $ gmake
14
15 Patch the code. Write some tests. Ensure that your code is properly formatted
16 with `gofumpt`. Ensure that everything builds and works as expected. Ensure
17 that you did not break anything.
18
19 - If applicable, update unit tests.
20 - If adding a new feature, please consider adding new tests.
21 - Do not forget to update the docs.
22 - Run the linter using `gmake lint`.
23
24 Once you are happy with your work, you can create a commit (or several
25 commits). Follow these general rules:
26
27 - Limit the first line (title) of the commit message to 60 characters.
28 - Use a short prefix for the commit title for readability with `git log
29 --oneline`. Do not use the `fix:` nor `feature:` prefixes. See recent commits
30 for inspiration.
31 - Only use lower case letters for the commit title except when quoting symbols
32 or known acronyms.
33 - Use the body of the commit message to actually explain what your patch does
34 and why it is useful. Even if your patch is a one line fix, the description
35 is not limited in length and may span over multiple paragraphs. Use proper
36 English syntax, grammar and punctuation.
37 - Address only one issue/topic per commit.
38 - Describe your changes in imperative mood, e.g. *"make xyzzy do frotz"*
39 instead of *"[This patch] makes xyzzy do frotz"* or *"[I] changed xyzzy to do
40 frotz"*, as if you are giving orders to the codebase to change its behaviour.
41 - If you are fixing a ticket, use appropriate
42 [commit trailers](https://man.sr.ht/git.sr.ht/#referencing-tickets-in-git-commit-messages).
43 - If you are fixing a regression introduced by another commit, add a `Fixes:`
44 trailer with the commit id and its title.
45 - When in doubt, follow the format and layout of the recent existing commits.
46 - If your commit brings visible changes for end-users, add one of the following
47 trailers with a short and concise description of the change. The change
48 should be described in full sentences, starting with a capital letter and
49 ending in a period.
50
51 * `Changelog-added:` for new features.
52 * `Changelog-fixed:` for bug fixes.
53 * `Changelog-changed:` for behaviour or config format changes.
54 * `Changelog-deprecated:` for deprecation or removal of functionality.
55
56 If a complete trailer is longer than 72 characters, it can be continued by
57 indenting extra lines with a single space. The trailer text must be valid
58 markdown. You can take inspiration from existing entries in
59 [CHANGELOG.md](https://git.sr.ht/~rjarry/aerc/tree/master/item/CHANGELOG.md).
60 - The following trailers are accepted in commits. If you are using multiple
61 trailers in a commit, it's preferred to also order them according to this
62 list. Note, that the `commit-msg` hook (see below for installing) will
63 automatically sort them for you when committing.
64
65 * `Closes: <URL>` closes the ticket with the neutral `CLOSED` resolution.
66 * `Fixes: <URL>` closes the ticket with the `FIXED` resolution.
67 * `Fixes: <sha> ("<title>")` reference the commit that introduced a regression.
68 * `Implements: <URL>` closes the ticket with the `IMPLEMENTED` resolution.
69 * `References: <URL>` adds a comment to the ticket.
70 * `Link:`
71 * `Changelog-added:`
72 * `Changelog-fixed:`
73 * `Changelog-changed:`
74 * `Changelog-deprecated:`
75 * `Cc:`
76 * `Suggested-by:`
77 * `Requested-by:`
78 * `Reported-by:`
79 * `Co-authored-by:`
80 * `Signed-off-by:` compulsory!
81 * `Tested-by:` used in review _after_ submission to the mailing list. If
82 minimal changes occur between respins, feel free to include that into your
83 respin to keep track of previous reviews.
84 * `Reviewed-by:` used in review _after_ submission. If minimal changes occur
85 between respins, feel free to include that into your respin to keep track
86 of previous reviews.
87 * `Acked-by:` used in review _after_ submission.
88
89 There is a great reference for commit messages in the
90 [Linux kernel documentation](https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes).
91
92 IMPORTANT: you must sign-off your work using `git commit --signoff`. Follow the
93 [Linux kernel developer's certificate of origin][linux-signoff] for more
94 details. All contributions are made under the MIT license. If you do not want
95 to disclose your real name, you may sign-off using a pseudonym. Here is an
96 example:
97
98 Signed-off-by: Robin Jarry <[email protected]>
99
100 Before sending the patch, you should configure your local clone with sane
101 defaults:
102
103 $ gmake gitconfig
104 git config format.subjectPrefix "PATCH aerc"
105 git config sendemail.to "~rjarry/[email protected]"
106 git config format.notes true
107 git config notes.rewriteRef refs/notes/commits
108 git config notes.rewriteMode concatenate
109 ln -s ../../contrib/commit-msg .git/hooks/commit-msg
110 + ln -s ../../contrib/sendemail-validate .git/hooks/sendemail-validate
111 + git config sendemail.validate true
112
113 And send the patch to the mailing list ([step-by-step
114 instructions][git-send-email-tutorial]):
115
116 $ git send-email --annotate -1
117
118 If you are sending a patch against the `wiki` branch, make sure to change the
119 subject prefix to avoid triggering the automated builds that will inevitably
120 fail:
121
122 $ git send-email --annotate -1 --subject-prefix="PATCH aerc/wiki"
123
124 Before your patch can be applied, it needs to be reviewed and approved by
125 others. They will indicate their approval by replying to your patch with
126 a [Tested-by, Reviewed-by or Acked-by][linux-review] (see also: [the git
127 wiki][git-trailers]) trailer. For example:
128
129 Acked-by: Robin Jarry <[email protected]>
130
131 There is no "chain of command" in aerc. Anyone that feels comfortable enough to
132 "ack" or "review" a patch should express their opinion freely with an official
133 Acked-by or Reviewed-by trailer. If you only tested that a patch works as
134 expected but did not conduct a proper code review, you can indicate it with
135 a Tested-by trailer.
136
137 You can follow the review process via email and on the [web ui][web-ui].
138
139 Wait for feedback. Address comments and amend changes to your original commit.
140 Then you should send a v2 (and maybe a v3, v4, etc.):
141
142 $ git send-email --annotate -v2 -1
143
144 Be polite, patient and address *all* of the reviewers' remarks. If you disagree
145 with something, feel free to discuss it.
146
147 To help reviewers track what changed between respins of your patch, it is nice
148 to include a mini change log **after** the `---` line that separates your
149 commit message from the diff. You can either do that manually when reviewing
150 (`git send-email --annotate`) before sending your email, or you can use [git
151 notes][git-notes] to make this part of your git workflow:
152
153 $ git notes edit $ref
154
155 [git-notes]: https://git-scm.com/docs/git-notes
156
157 When `format.notes = true` is set in your git configuration, notes attached to
158 commits will automatically be included in the correct location by `git
159 format-patch` and `git send-email`.
160
161 If you have set `notes.rewriteMode = concatenate`, squashing commits together
162 with `git rebase -i` will also merge their respective notes by concatenating
163 them.
164
165 Once your patch has been reviewed and approved (and if the maintainer is OK
166 with it), it will be applied and pushed.
167
168 IMPORTANT: Do NOT use `--in-reply-to` when sending followup versions of a patch
169 set. It causes multiple versions of the same patch to be merged under v1 in the
170 [web ui][web-ui]
171
172 [web-ui]: https://lists.sr.ht/~rjarry/aerc-devel/patches
173
174 ## Use of generative AI
175
176 The use of generative AI or LLMs for writing code or documentation for aerc is
177 not permitted. These tools make copyright and license compliance complex and
178 difficult (making aerc's DCO policy impossible to comply with). They have an
179 enormous environmental cost, grossly misallocate the resources of a responsible
180 society, expand the power of the wealthy, and directly facilitate the
181 encroachment of fascism on global politics.
182
183 For more information about the social, ethical, and political problems posed by
184 LLMs, [consult this reference][llms].
185
186 [llms]: https://codeberg.org/small-hack/open-slopware#why-not-llms
187
188 ## Code Style
189
190 Please refer only to the quoted sections when guidelines are sourced from
191 outside documents as some rules of the source material may conflict with other
192 rules set out in this document.
193
194 When updating an existing file, respect the existing coding style unless there
195 is a good reason not to do so.
196
197 ### Indentation
198
199 Indentation rules follow the Linux kernel coding style:
200
201 > Tabs are 8 characters, and thus indentations are also 8 characters. […]
202 >
203 > Rationale: The whole idea behind indentation is to clearly define where
204 > a block of control starts and ends. Especially when you’ve been looking at
205 > your screen for 20 straight hours, you’ll find it a lot easier to see how the
206 > indentation works if you have large indentations.
207 > — [Linux kernel coding style][linux-coding-style]
208
209 ### Breaking long lines and strings
210
211 Wrapping rules follow the Linux kernel coding style:
212
213 > Coding style is all about readability and maintainability using commonly
214 > available tools.
215 >
216 > The preferred limit on the length of a single line is 80 columns.
217 >
218 > Statements longer than 80 columns should be broken into sensible chunks,
219 > unless exceeding 80 columns significantly increases readability and does not
220 > hide information.
221 > […]
222 > These same rules are applied to function headers with a long argument list.
223 >
224 > However, never break user-visible strings such as printk messages because
225 > that breaks the ability to grep for them.
226 > — [Linux kernel coding style][linux-coding-style]
227
228 Whether or not wrapping lines is acceptable can be discussed on IRC or the
229 mailing list, when in doubt.
230
231 ### Functions
232
233 Function rules follow the Linux kernel coding style:
234
235 > Functions should be short and sweet, and do just one thing. They should fit
236 > on one or two screenfuls of text (the ISO/ANSI screen size is 80x24, as we
237 > all know), and do one thing and do that well.
238 >
239 > The maximum length of a function is inversely proportional to the complexity
240 > and indentation level of that function. So, if you have a conceptually simple
241 > function that is just one long (but simple) case-statement, where you have to
242 > do lots of small things for a lot of different cases, it’s OK to have
243 > a longer function.
244 >
245 > However, if you have a complex function, and you suspect that
246 > a less-than-gifted first-year high-school student might not even understand
247 > what the function is all about, you should adhere to the maximum limits all
248 > the more closely. Use helper functions with descriptive names (you can ask
249 > the compiler to in-line them if you think it’s performance-critical, and it
250 > will probably do a better job of it than you would have done).
251 >
252 > Another measure of the function is the number of local variables. They
253 > shouldn’t exceed 5-10, or you’re doing something wrong. Re-think the
254 > function, and split it into smaller pieces. A human brain can generally
255 > easily keep track of about 7 different things, anything more and it gets
256 > confused. You know you’re brilliant, but maybe you’d like to understand what
257 > you did 2 weeks from now.
258 > — [Linux kernel coding style][linux-coding-style]
259
260 ### Commenting
261
262 Commenting rules follow the Linux kernel coding style:
263
264 > Comments are good, but there is also a danger of over-commenting. NEVER try
265 > to explain HOW your code works in a comment: it’s much better to write the
266 > code so that the working is obvious, and it’s a waste of time to explain
267 > badly written code.
268 >
269 > Generally, you want your comments to tell WHAT your code does, not HOW. Also,
270 > try to avoid putting comments inside a function body: if the function is so
271 > complex that you need to separately comment parts of it, you should probably
272 > go back to [the previous section regarding functions] for a while. You can
273 > make small comments to note or warn about something particularly clever (or
274 > ugly), but try to avoid excess. Instead, put the comments at the head of the
275 > function, telling people what it does, and possibly WHY it does it.
276 >
277 > When commenting […] API functions, please use the [GoDoc] format. See the
278 > [official documentation][godoc-comments] for details.
279 > — [Linux kernel coding style][linux-coding-style]
280
281 ### Editor modelines
282
283 > Some editors can interpret configuration information embedded in source
284 > files, indicated with special markers. For example, emacs interprets lines
285 > marked like this:
286 >
287 > -*- mode: c -*-
288 >
289 > Or like this:
290 >
291 > /*
292 > Local Variables:
293 > compile-command: "gcc -DMAGIC_DEBUG_FLAG foo.c"
294 > End:
295 > */
296 >
297 > Vim interprets markers that look like this:
298 >
299 > /* vim:set sw=8 noet */
300 >
301 > Do not include any of these in source files. People have their own personal
302 > editor configurations, and your source files should not override them. This
303 > includes markers for indentation and mode configuration. People may use
304 > their own custom mode, or may have some other magic method for making
305 > indentation work correctly.
306 > — [Linux kernel coding style][linux-coding-style]
307
308 In the same way, files specific to only your workflow (for example the `.idea`
309 or `.vscode` directory) are not desired. If a script might be useful to other
310 contributors, it can be sent as a separate patch that adds it to the `contrib`
311 directory. Since it is not editor-specific, an
312 [`.editorconfig`](https://git.sr.ht/~rjarry/aerc/tree/master/item/.editorconfig)
313 is available in the repository.
314
315 ### Go-code
316
317 The Go-code follows the rules of [gofumpt][gofumpt-repo] which is equivalent to
318 gofmt but adds a few additional rules. The code can be automatically formatted
319 by running `gmake fmt`.
320
321 If gofumpt accepts your code it's most likely properly formatted.
322
323 ### Logging
324
325 Aerc allows logging messages to a file. Either by redirecting the output to
326 a file (e.g. `aerc > log`), or by configuring `log-file` in `aerc.conf`.
327 Logging messages are associated with a severity level, from lowest to highest:
328 `trace`, `debug`, `info`, `warn`, `error`.
329
330 Messages can be sent to the log file by using the following functions:
331
332 - `log.Errorf()`: Use to report serious (but non-fatal) errors.
333 - `log.Warnf()`: Use to report issues that do not affect normal use.
334 - `log.Infof()`: Use to display important messages that may concern
335 non-developers.
336 - `log.Debugf()`: Use to display non-important messages, or debugging
337 details.
338 - `log.Tracef()`: Use to display only low level debugging traces.
339
340 ### Man pages
341
342 All `doc/*.scd` files are written in the [scdoc][scdoc] format and compiled to
343 man pages.
344
345 For consistent rendering, please respect the following guidelines:
346
347 - use `*:command*` to reference commands
348 - use `*-x*` for flags
349 - use `_<arg>_` argument placeholders that must be replaced by a suitable value
350 - use `_foobar.conf_` for file paths
351 - use `_true_`, `_0_`, `_constant_` for literal constants that must be typed as is
352 - use `[*-x*]` or `[_<arg>_]` for optional flags/arguments
353 - use `*-x*|*-y*` for mutually exclusive flags/arguments
354 - use `*[section]*` to reference sections in configuration files
355 - use `*foo*` or `*[section].foo*` to reference settings
356 - if an option does **not** have a default value, simply omit it
357 - use `*FOO*` and `*$FOO*` for environment variables
358 - only use `_"quoted values"_` when white space matters
359 - put command alternatives/aliases on separate lines with `++` suffixes
360 - use `*<c-x>*` or `*<enter>*` to reference key strokes
361 - use `# UPPER CASE` for man page sections
362 - use `*aerc-config*(5)` to reference other man pages
363 - use `aerc` (instead of `*aerc*` or `_aerc_`) to reference the aerc project or
364 the aerc program
365
366 [git-send-email-tutorial]: https://git-send-email.io/
367 [git-trailers]: https://git.wiki.kernel.org/index.php/CommitMessageConventions
368 [godoc-comments]: https://go.dev/blog/godoc
369 [gofumpt-repo]: https://github.com/mvdan/gofumpt
370 [linux-coding-style]: https://www.kernel.org/doc/html/v5.19-rc8/process/coding-style.html
371 [linux-review]: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#using-reported-by-tested-by-reviewed-by-suggested-by-and-fixes
372 [linux-signoff]: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin
373 [scdoc]: https://git.sr.ht/~sircmpwn/scdoc