Skip to content

Commit b44cb81

Browse files
authored
Notes on enforcing code formatting (#195)
1 parent 02c82d1 commit b44cb81

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

patterns/automate-everything.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ Regularly review *every* manual process that the team performs. Automate it, but
3535
* Automated [tests](../practices/testing.md).
3636
* Automated [security](../practices/security.md) verification.
3737
* Automated [governance](governance-side-effect.md).
38+
* Hooks to [enforce code formatting](enforce-code-formatting.md).
3839

3940
## Examples — how to automate
4041

4142
Some automation is highly managed and is purely declarative. e.g. VM or container auto scaling in cloud platforms can typically be achieved without the need to write any code: the platform implements scaling based on specified rules.
4243

43-
Programmatic automation by contrast typically involves writing code and involves the use of **orchestrators** such as CI tools (e.g. Jenkins, Circle CI), AWS Step Functions or Lambda triggers and **runners** which do the actual work (e.g. bash or Python scripts). The orchestration and runner logic should all be represented in code with everything that entails (see [everything as code](everything-as-code.md)).
44+
Programmatic automation by contrast typically involves writing code and involves the use of **orchestrators** such as CI tools (e.g. Jenkins, Circle CI), AWS Step Functions or Lambda triggers and **runners** which do the actual work (e.g. bash or Python scripts). The orchestration and runner logic should all be represented in code with everything that entails (see [everything as code](everything-as-code.md)).

patterns/enforce-code-formatting.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Enforce code formatting
2+
3+
## Context
4+
5+
* These notes are part of a broader set of [principles](../principles.md)
6+
7+
## The pattern
8+
9+
Being consistent with your code formatting improves readability, and maintainability of your code base. Where consistency is enforced prior to commits being pushed this ensures that commits are cleaner and easier to manage.
10+
11+
## Benefits
12+
13+
* Reduces the need for changes to include formatting updates across non impacted code.
14+
* Improves clarity of code.
15+
* Enables teams to agree on formatting that is important to them up-front.
16+
17+
## Details
18+
19+
* Teams should agree on linting tools for their code.
20+
* Teams should agree the rules around formatting for their code.
21+
* These tools should be used to ensure that commits are not merged where code does not meet the agreed ruleset.
22+
* Teams should implement pre-commit hooks to check developers commits and fail to push changes that do not adhere to the agreed format.
23+
* Tools should provide useful output on failures - ideally auto formatting the code for developers to accept.
24+
* Developers can then apply formatting changes as part of their development process.
25+
* Teams should also employ a specific step in their CI/CD pipeline to verify that code is formatted to the agreed standards.
26+
27+
## Examples
28+
29+
* Python code formatting could use Black to enforce formatting on a repo.

patterns/everything-as-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ While effective testing is the best way to detect bugs or non-functional problem
4747
* Does it handle edge cases?
4848
#### Of high quality
4949
* Is the code clear and simple?
50-
* Is the code layout and structure consistent with agreed style and other code?
50+
* Is the code layout and structure consistent with agreed style and other code? (please see [enforce code formatting](enforce-code-formatting.md))
5151
* Would it easily allow future modification to meet slightly different needs, e.g. ten times the required data size or throughput?
5252
* Have the non-functional requirements been considered (performance, scalability, robustness, etc)?
5353
* Are common security issues guarded against (e.g. [OWASP Top 10](https://owasp.org/www-project-top-ten/))? Including:

0 commit comments

Comments
 (0)