Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 535a689

Browse files
author
David Robertson
authored
Reintroduce the lint targets in the linter script (#12455)
1 parent 6b3e0ea commit 535a689

File tree

3 files changed

+30
-41
lines changed

3 files changed

+30
-41
lines changed

changelog.d/12455.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reintroduce the list of targets to the linter script, to avoid linting unwanted local-only directories during development.

docs/code_style.md

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,36 @@ The Synapse codebase uses a number of code formatting tools in order to
66
quickly and automatically check for formatting (and sometimes logical)
77
errors in code.
88

9-
The necessary tools are detailed below.
9+
The necessary tools are:
1010

11-
First install them with:
11+
- [black](https://black.readthedocs.io/en/stable/), a source code formatter;
12+
- [isort](https://pycqa.github.io/isort/), which organises each file's imports;
13+
- [flake8](https://flake8.pycqa.org/en/latest/), which can spot common errors; and
14+
- [mypy](https://mypy.readthedocs.io/en/stable/), a type checker.
15+
16+
Install them with:
1217

1318
```sh
1419
pip install -e ".[lint,mypy]"
1520
```
1621

17-
- **black**
18-
19-
The Synapse codebase uses [black](https://pypi.org/project/black/)
20-
as an opinionated code formatter, ensuring all comitted code is
21-
properly formatted.
22-
23-
Have `black` auto-format your code (it shouldn't change any
24-
functionality) with:
25-
26-
```sh
27-
black .
28-
```
29-
30-
- **flake8**
31-
32-
`flake8` is a code checking tool. We require code to pass `flake8`
33-
before being merged into the codebase.
34-
35-
Check all application and test code with:
22+
The easiest way to run the lints is to invoke the linter script as follows.
3623

37-
```sh
38-
flake8 .
39-
```
40-
41-
- **isort**
42-
43-
`isort` ensures imports are nicely formatted, and can suggest and
44-
auto-fix issues such as double-importing.
45-
46-
Auto-fix imports with:
47-
48-
```sh
49-
isort .
50-
```
24+
```sh
25+
scripts-dev/lint.sh
26+
```
5127

5228
It's worth noting that modern IDEs and text editors can run these tools
5329
automatically on save. It may be worth looking into whether this
5430
functionality is supported in your editor for a more convenient
55-
development workflow. It is not, however, recommended to run `flake8` on
56-
save as it takes a while and is very resource intensive.
31+
development workflow. It is not, however, recommended to run `flake8` or `mypy`
32+
on save as they take a while and can be very resource intensive.
5733

5834
## General rules
5935

6036
- **Naming**:
61-
- Use camel case for class and type names
62-
- Use underscores for functions and variables.
37+
- Use `CamelCase` for class and type names
38+
- Use underscores for `function_names` and `variable_names`.
6339
- **Docstrings**: should follow the [google code
6440
style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings).
6541
See the

scripts-dev/lint.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,20 @@ else
7979
# If we were not asked to lint changed files, and no paths were found as a result,
8080
# then lint everything!
8181
if [[ -z ${files+x} ]]; then
82-
# Lint all source code files and directories
83-
files=( "." )
82+
# CI runs each linter on the entire checkout, e.g. `black .`. So don't
83+
# rely on this list to *find* lint targets if that misses a file; instead;
84+
# use it to exclude files from linters when this can't be done by config.
85+
#
86+
# To check which files the linters examine, use:
87+
# black --verbose . 2>&1 | \grep -v ignored
88+
# isort --show-files .
89+
# flake8 --verbose . # This isn't a great option
90+
# mypy has explicit config in mypy.ini; there is also mypy --verbose
91+
files=(
92+
"synapse" "docker" "tests"
93+
"scripts-dev"
94+
"contrib" "setup.py" "synmark" "stubs" ".ci"
95+
)
8496
fi
8597
fi
8698

0 commit comments

Comments
 (0)