@@ -173,6 +173,55 @@ The `legacy_foo` arg was removed
173173:::
174174```
175175
176+ ## Style and idioms
177+
178+ For the most part, we just accept whatever the code formatters do, so there
179+ isn't much style to enforce.
180+
181+ Some miscellanous style, idioms, and conventions we have are:
182+
183+ ### Markdown/Sphinx Style
184+
185+ * Use colons for prose sections of text, e.g. ` :::{note} ` , not backticks.
186+ * Use backticks for code blocks.
187+ * Max line length: 100.
188+
189+ ### BUILD/bzl Style
190+
191+ * When a macro generates public targets, use a dot (` . ` ) to separate the
192+ user-provided name from the generted name. e.g. ` foo(name="x") ` generates
193+ ` x.test ` . The ` . ` is our convention to communicate that it's a generated
194+ target, and thus one should look for ` name="x" ` when searching for the
195+ definition.
196+ * The different build phases shouldn't load code that defines objects that
197+ aren't valid for their phase. e.g.
198+ * The bzlmod phase shouldn't load code defining regular rules or providers.
199+ * The repository phase shouldn't load code defining module extensions, regular
200+ rules, or providers.
201+ * The loading phase shouldn't load code defining module extensions or
202+ repository rules.
203+ * Loading utility libraries or generic code is OK, but should strive to load
204+ code that is usable for its phase. e.g. loading-phase code shouldn't
205+ load utility code that is predominately only usable to the bzlmod phase.
206+ * Providers should be in their own files. This allows implementing a custom rule
207+ that implements the provider without loading a specific implementation.
208+ * One rule per file is preferred, but not required. The goal is that defining an
209+ e.g. library shouldn't incur loading all the code for binaries, tests,
210+ packaging, etc; things that may be niche or uncommonly used.
211+ * Separate files should be used to expose public APIs. This ensures our public
212+ API is well defined and prevents accidentally exposing a package-private
213+ symbol as a public symbol.
214+
215+ :::{note}
216+ The public API file's docstring becomes part of the user-facing docs. That
217+ file's docstring must be used for module-level API documentation.
218+ :::
219+ * Repository rules should have name ending in ` _repo ` . This helps distinguish
220+ them from regular rules.
221+ * Each bzlmod extension, the "X" of ` use_repo("//foo:foo.bzl", "X") ` should be
222+ in its own file. The path given in the ` use_repo() ` expression is the identity
223+ Bazel uses and cannot be changed.
224+
176225## Generated files
177226
178227Some checked-in files are generated and need to be updated when a new PR is
0 commit comments