Skip to content

Commit 39affbf

Browse files
Swap out Flake8 for ruff in linting (#232)
## Ticket Resolves #107 ## Changes Change our linter from flake8 to ruff Python package updates ## Context for reviewers [ruff](https://docs.astral.sh/ruff/) is a linter built in Rust that is both better performing and contains much more options than flake8 (including many of the Flake8 rules). Ruff has a lot of [potential rules](https://docs.astral.sh/ruff/rules/) we could configure, but to keep things simple, I ported over the same rules that we already had configured. If we want to try out any of the other rules, we can follow up with that. For context, enabling all rules causes ~1300 errors, although many of the common ones I see are not issues I think we would want to actually consider (complaining about using `assert` in test functions) Ruff can also serve as a formatter of code, potentially replacing black + isort, but I'll explore using that later as the change is likely much bigger as it would cause a lot of little formatting differences ## Testing Was able to run ruff via `make lint-ruff` and only encountered a few small issues that I fixed. We also switched to using this approach a few months ago in the simpler grants codebase and haven't run into any issues. HHS/simpler-grants-gov#1626 --------- Co-authored-by: nava-platform-bot <platform-admins@navapbc.com>
1 parent e6093b3 commit 39affbf

File tree

10 files changed

+1092
-1040
lines changed

10 files changed

+1092
-1040
lines changed

app/Makefile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@ DECODE_LOG := 2>&1 | python3 -u src/logging/util/decodelog.py
1616
SHELL = /bin/bash -o pipefail
1717

1818
# The APP_DIR variable is the path from the root of the repository to this Makefile.
19-
# This variable is used to display errors from Flake8 and MyPy in the 'Files Changed'
19+
# This variable is used to display errors from MyPy in the 'Files Changed'
2020
# section of a pull request. If this is set to the incorrect value, you won't be able
2121
# to see the errors on the correct files in that section
2222
APP_DIR := app
2323
ifdef CI
2424
DOCKER_EXEC_ARGS := -T -e CI -e PYTEST_ADDOPTS="--color=yes"
25-
FLAKE8_FORMAT := '::warning file=$(APP_DIR)/%(path)s,line=%(row)d,col=%(col)d::%(path)s:%(row)d:%(col)d: %(code)s %(text)s'
2625
MYPY_FLAGS := --no-pretty
2726
MYPY_POSTPROC := | perl -pe "s/^(.+):(\d+):(\d+): error: (.*)/::warning file=$(APP_DIR)\/\1,line=\2,col=\3::\4/"
28-
else
29-
FLAKE8_FORMAT := default
3027
endif
3128

3229
# By default, all python/poetry commands will run inside of the docker container
@@ -199,10 +196,10 @@ format-check: ## Check file formatting
199196

200197
lint: lint-py ## Lint
201198

202-
lint-py: lint-flake lint-mypy
199+
lint-py: lint-ruff lint-mypy
203200

204-
lint-flake:
205-
$(PY_RUN_CMD) flake8 --format=$(FLAKE8_FORMAT) src tests
201+
lint-ruff:
202+
$(PY_RUN_CMD) ruff check src tests
206203

207204
lint-mypy:
208205
$(PY_RUN_CMD) mypy --show-error-codes $(MYPY_FLAGS) src $(MYPY_POSTPROC)

app/openapi.generated.yml

Lines changed: 220 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,28 @@ paths:
4545
content:
4646
application/json:
4747
schema:
48-
$ref: '#/components/schemas/HTTPError'
48+
type: object
49+
properties:
50+
message:
51+
type: string
52+
description: The message to return
53+
data:
54+
$ref: '#/components/schemas/HTTPError'
55+
status_code:
56+
type: integer
57+
description: The HTTP status code
58+
warnings:
59+
type: array
60+
items:
61+
$ref: '#/components/schemas/ValidationError'
62+
errors:
63+
type: array
64+
items:
65+
$ref: '#/components/schemas/ValidationError'
66+
pagination_info:
67+
description: The pagination information for paginated endpoints
68+
allOf:
69+
- $ref: '#/components/schemas/PaginationInfo'
4970
description: Service Unavailable
5071
tags:
5172
- Health
@@ -85,13 +106,55 @@ paths:
85106
content:
86107
application/json:
87108
schema:
88-
$ref: '#/components/schemas/ValidationError'
109+
type: object
110+
properties:
111+
message:
112+
type: string
113+
description: The message to return
114+
data:
115+
$ref: '#/components/schemas/ValidationError'
116+
status_code:
117+
type: integer
118+
description: The HTTP status code
119+
warnings:
120+
type: array
121+
items:
122+
$ref: '#/components/schemas/ValidationError'
123+
errors:
124+
type: array
125+
items:
126+
$ref: '#/components/schemas/ValidationError'
127+
pagination_info:
128+
description: The pagination information for paginated endpoints
129+
allOf:
130+
- $ref: '#/components/schemas/PaginationInfo'
89131
description: Validation error
90132
'401':
91133
content:
92134
application/json:
93135
schema:
94-
$ref: '#/components/schemas/HTTPError'
136+
type: object
137+
properties:
138+
message:
139+
type: string
140+
description: The message to return
141+
data:
142+
$ref: '#/components/schemas/HTTPError'
143+
status_code:
144+
type: integer
145+
description: The HTTP status code
146+
warnings:
147+
type: array
148+
items:
149+
$ref: '#/components/schemas/ValidationError'
150+
errors:
151+
type: array
152+
items:
153+
$ref: '#/components/schemas/ValidationError'
154+
pagination_info:
155+
description: The pagination information for paginated endpoints
156+
allOf:
157+
- $ref: '#/components/schemas/PaginationInfo'
95158
description: Authentication error
96159
tags:
97160
- User
@@ -140,13 +203,55 @@ paths:
140203
content:
141204
application/json:
142205
schema:
143-
$ref: '#/components/schemas/ValidationError'
206+
type: object
207+
properties:
208+
message:
209+
type: string
210+
description: The message to return
211+
data:
212+
$ref: '#/components/schemas/ValidationError'
213+
status_code:
214+
type: integer
215+
description: The HTTP status code
216+
warnings:
217+
type: array
218+
items:
219+
$ref: '#/components/schemas/ValidationError'
220+
errors:
221+
type: array
222+
items:
223+
$ref: '#/components/schemas/ValidationError'
224+
pagination_info:
225+
description: The pagination information for paginated endpoints
226+
allOf:
227+
- $ref: '#/components/schemas/PaginationInfo'
144228
description: Validation error
145229
'401':
146230
content:
147231
application/json:
148232
schema:
149-
$ref: '#/components/schemas/HTTPError'
233+
type: object
234+
properties:
235+
message:
236+
type: string
237+
description: The message to return
238+
data:
239+
$ref: '#/components/schemas/HTTPError'
240+
status_code:
241+
type: integer
242+
description: The HTTP status code
243+
warnings:
244+
type: array
245+
items:
246+
$ref: '#/components/schemas/ValidationError'
247+
errors:
248+
type: array
249+
items:
250+
$ref: '#/components/schemas/ValidationError'
251+
pagination_info:
252+
description: The pagination information for paginated endpoints
253+
allOf:
254+
- $ref: '#/components/schemas/PaginationInfo'
150255
description: Authentication error
151256
tags:
152257
- User
@@ -198,13 +303,55 @@ paths:
198303
content:
199304
application/json:
200305
schema:
201-
$ref: '#/components/schemas/HTTPError'
306+
type: object
307+
properties:
308+
message:
309+
type: string
310+
description: The message to return
311+
data:
312+
$ref: '#/components/schemas/HTTPError'
313+
status_code:
314+
type: integer
315+
description: The HTTP status code
316+
warnings:
317+
type: array
318+
items:
319+
$ref: '#/components/schemas/ValidationError'
320+
errors:
321+
type: array
322+
items:
323+
$ref: '#/components/schemas/ValidationError'
324+
pagination_info:
325+
description: The pagination information for paginated endpoints
326+
allOf:
327+
- $ref: '#/components/schemas/PaginationInfo'
202328
description: Authentication error
203329
'404':
204330
content:
205331
application/json:
206332
schema:
207-
$ref: '#/components/schemas/HTTPError'
333+
type: object
334+
properties:
335+
message:
336+
type: string
337+
description: The message to return
338+
data:
339+
$ref: '#/components/schemas/HTTPError'
340+
status_code:
341+
type: integer
342+
description: The HTTP status code
343+
warnings:
344+
type: array
345+
items:
346+
$ref: '#/components/schemas/ValidationError'
347+
errors:
348+
type: array
349+
items:
350+
$ref: '#/components/schemas/ValidationError'
351+
pagination_info:
352+
description: The pagination information for paginated endpoints
353+
allOf:
354+
- $ref: '#/components/schemas/PaginationInfo'
208355
description: Not found
209356
tags:
210357
- User
@@ -250,19 +397,82 @@ paths:
250397
content:
251398
application/json:
252399
schema:
253-
$ref: '#/components/schemas/ValidationError'
400+
type: object
401+
properties:
402+
message:
403+
type: string
404+
description: The message to return
405+
data:
406+
$ref: '#/components/schemas/ValidationError'
407+
status_code:
408+
type: integer
409+
description: The HTTP status code
410+
warnings:
411+
type: array
412+
items:
413+
$ref: '#/components/schemas/ValidationError'
414+
errors:
415+
type: array
416+
items:
417+
$ref: '#/components/schemas/ValidationError'
418+
pagination_info:
419+
description: The pagination information for paginated endpoints
420+
allOf:
421+
- $ref: '#/components/schemas/PaginationInfo'
254422
description: Validation error
255423
'401':
256424
content:
257425
application/json:
258426
schema:
259-
$ref: '#/components/schemas/HTTPError'
427+
type: object
428+
properties:
429+
message:
430+
type: string
431+
description: The message to return
432+
data:
433+
$ref: '#/components/schemas/HTTPError'
434+
status_code:
435+
type: integer
436+
description: The HTTP status code
437+
warnings:
438+
type: array
439+
items:
440+
$ref: '#/components/schemas/ValidationError'
441+
errors:
442+
type: array
443+
items:
444+
$ref: '#/components/schemas/ValidationError'
445+
pagination_info:
446+
description: The pagination information for paginated endpoints
447+
allOf:
448+
- $ref: '#/components/schemas/PaginationInfo'
260449
description: Authentication error
261450
'404':
262451
content:
263452
application/json:
264453
schema:
265-
$ref: '#/components/schemas/HTTPError'
454+
type: object
455+
properties:
456+
message:
457+
type: string
458+
description: The message to return
459+
data:
460+
$ref: '#/components/schemas/HTTPError'
461+
status_code:
462+
type: integer
463+
description: The HTTP status code
464+
warnings:
465+
type: array
466+
items:
467+
$ref: '#/components/schemas/ValidationError'
468+
errors:
469+
type: array
470+
items:
471+
$ref: '#/components/schemas/ValidationError'
472+
pagination_info:
473+
description: The pagination information for paginated endpoints
474+
allOf:
475+
- $ref: '#/components/schemas/PaginationInfo'
266476
description: Not found
267477
tags:
268478
- User

0 commit comments

Comments
 (0)