Skip to content

Commit 244f06a

Browse files
committed
chore: enable Flake8 on VS Code and align with Black rules
1 parent 4426985 commit 244f06a

File tree

5 files changed

+59
-14
lines changed

5 files changed

+59
-14
lines changed

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"recommendations": [
33
"ms-python.python",
4-
"ms-python.vscode-pylance",
4+
"ms-python.flake8",
55
"ms-python.black-formatter",
66
"github.vscode-pull-request-github",
77
"github.vscode-github-actions",

.vscode/settings.json

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"python.testing.unittestEnabled": false,
3-
"python.testing.pytestEnabled": true,
4-
"python.testing.pytestArgs": ["tests"],
52
"files.exclude": {
63
"**/__pycache__": true,
74
"**/.git": true,
@@ -13,6 +10,44 @@
1310
"editor.defaultFormatter": "ms-python.black-formatter",
1411
"editor.formatOnSave": true
1512
},
13+
"python.testing.unittestEnabled": false,
14+
"python.testing.pytestEnabled": true,
15+
"python.testing.pytestArgs": ["tests"],
16+
"flake8.enabled": true,
17+
"flake8.importStrategy": "fromEnvironment",
18+
"flake8.path": ["${interpreter}", "-m", "flake8"],
19+
// Point flake8 to use your existing config file automatically
20+
"flake8.args": [
21+
"--max-line-length=88",
22+
"--max-complexity=10",
23+
"--select=E,F,W",
24+
"--extend-ignore=E203,W503",
25+
"--exclude=.venv",
26+
"--per-file-ignores=tests/test_main.py:E501"
27+
],
28+
// Exclude files/folders you don’t want to lint (matching Black’s exclude)
29+
"flake8.ignorePatterns": [
30+
"**/.git/**",
31+
"**/.github/**",
32+
"**/.pytest_cache/**",
33+
"**/.venv/**",
34+
"**/.vscode/**",
35+
"**/assets/**",
36+
"**/htmlcov/**",
37+
"**/postman_collections/**",
38+
"**/scripts/**",
39+
"**/storage/**",
40+
"**/__pycache__/**",
41+
"**/tests/test_main.py"
42+
],
43+
"flake8.severity": {
44+
"convention": "Information",
45+
"error": "Error",
46+
"fatal": "Error",
47+
"refactor": "Hint",
48+
"warning": "Warning",
49+
"info": "Information"
50+
},
1651
"sonarlint.connectedMode.project": {
1752
"connectionId": "nanotaboada",
1853
"projectKey": "nanotaboada_python-samples-fastapi-restful"

models/player_model.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class MainModel(BaseModel):
2323
model_config (ConfigDict): Configuration for Pydantic models, including:
2424
alias_generator (function): A function to generate field aliases.
2525
Here, it uses `to_camel` to convert field names to camelCase.
26-
populate_by_name (bool): Allows population of fields by name when using Pydantic models.
26+
populate_by_name (bool): Allows population of fields by name when using
27+
Pydantic models.
2728
"""
2829

2930
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
@@ -41,10 +42,12 @@ class PlayerModel(MainModel):
4142
date_of_birth (Optional[str]): The date of birth of the Player, if provided.
4243
squad_number (int): The unique squad number assigned to the Player.
4344
position (str): The playing position of the Player.
44-
abbr_position (Optional[str]): The abbreviated form of the Player's position, if any.
45+
abbr_position (Optional[str]): The abbreviated form of the Player's position,
46+
if any.
4547
team (Optional[str]): The team to which the Player belongs, if any.
4648
league (Optional[str]): The league where the team plays, if any.
47-
starting11 (Optional[bool]): Indicates if the Player is in the starting 11, if provided.
49+
starting11 (Optional[bool]): Indicates if the Player is in the starting 11,
50+
if provided.
4851
"""
4952

5053
id: int

routes/health_route.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@api_router.get("/health", tags=["Health"])
1414
async def health_check():
1515
"""
16-
Simple health check endpoint. Returns a JSON response with a single key "status" and value "ok".
16+
Simple health check endpoint.
17+
Returns a JSON response with a single key "status" and value "ok".
1718
"""
1819
return {"status": "ok"}

routes/player_route.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ async def post_async(
4949
Endpoint to create a new player.
5050
5151
Args:
52-
player_model (PlayerModel): The Pydantic model representing the Player to create.
52+
player_model (PlayerModel): The Pydantic model representing the Player to
53+
create.
5354
async_session (AsyncSession): The async version of a SQLAlchemy ORM session.
5455
5556
Raises:
@@ -115,7 +116,8 @@ async def get_by_id_async(
115116
PlayerModel: The Pydantic model representing the matching Player.
116117
117118
Raises:
118-
HTTPException: Not found error if the Player with the specified ID does not exist.
119+
HTTPException: Not found error if the Player with the specified ID does not
120+
exist.
119121
"""
120122
player = await player_service.retrieve_by_id_async(async_session, player_id)
121123
if not player:
@@ -145,7 +147,8 @@ async def get_by_squad_number_async(
145147
PlayerModel: The Pydantic model representing the matching Player.
146148
147149
Raises:
148-
HTTPException: HTTP 404 Not Found error if the Player with the specified Squad Number does not exist.
150+
HTTPException: HTTP 404 Not Found error if the Player with the specified
151+
Squad Number does not exist.
149152
"""
150153
player = await player_service.retrieve_by_squad_number_async(
151154
async_session, squad_number
@@ -174,11 +177,13 @@ async def put_async(
174177
175178
Args:
176179
player_id (int): The ID of the Player to update.
177-
player_model (PlayerModel): The Pydantic model representing the Player to update.
180+
player_model (PlayerModel): The Pydantic model representing the Player to
181+
update.
178182
async_session (AsyncSession): The async version of a SQLAlchemy ORM session.
179183
180184
Raises:
181-
HTTPException: HTTP 404 Not Found error if the Player with the specified ID does not exist.
185+
HTTPException: HTTP 404 Not Found error if the Player with the specified ID
186+
does not exist.
182187
"""
183188
player = await player_service.retrieve_by_id_async(async_session, player_id)
184189
if not player:
@@ -208,7 +213,8 @@ async def delete_async(
208213
async_session (AsyncSession): The async version of a SQLAlchemy ORM session.
209214
210215
Raises:
211-
HTTPException: HTTP 404 Not Found error if the Player with the specified ID does not exist.
216+
HTTPException: HTTP 404 Not Found error if the Player with the specified ID
217+
does not exist.
212218
"""
213219
player = await player_service.retrieve_by_id_async(async_session, player_id)
214220
if not player:

0 commit comments

Comments
 (0)