Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all linting issues #27

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions backend/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
[DISABLED RULES]
disable = missing-module-docstring,
missing-function-docstring,
missing-class-docstring
missing-class-docstring,
misplaced-bare-raise

[MESSAGES CONTROL]
# Enable some checkers that are not activated by default:
enable = bad-inline-option, deprecated-pragma, file-ignored, use-symbolic-message-instead, useless-suppression

# Include some helpful details on errors messages for naming rules:
include-naming-hint = yes

[MASTER]
# Informational messages ("I") should make Pylint execution fail (non-0 program return code):
fail-on = I
# Enable many optional extensions:
load-plugins = pylint.extensions.bad_builtin,
pylint.extensions.code_style,
pylint.extensions.comparison_placement,
pylint.extensions.consider_refactoring_into_while_condition,
pylint.extensions.docparams,
pylint.extensions.dunder,
pylint.extensions.eq_without_hash,
pylint.extensions.for_any_all,
pylint.extensions.magic_value,
pylint.extensions.mccabe,
pylint.extensions.no_self_use,
pylint.extensions.overlapping_exceptions,
pylint.extensions.private_import,
pylint.extensions.redefined_loop_name,
pylint.extensions.redefined_variable_type,
pylint.extensions.set_membership,
pylint.extensions.typing,
pylint.extensions.while_used,

[STRING_CONSTANT]
# Doc: https://pylint.pycqa.org/en/latest/user_guide/messages/warning/implicit-str-concat.html
check-quote-consistency = yes

[VARIABLES]
allow-global-unused-variables = no
allow-global-unused-variables = yes
3 changes: 2 additions & 1 deletion backend/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
},
"isort.check": true
"isort.check": true,
"pylint.importStrategy": "fromEnvironment"
}
3 changes: 1 addition & 2 deletions backend/api/dependencies/oauth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime, timedelta
from typing import Annotated

from fastapi import APIRouter, Depends, HTTPException, status
from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
from joserfc import errors, jwt
from sqlalchemy.orm import Session
Expand Down
1 change: 0 additions & 1 deletion backend/api/routes/project/project.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import builtins
from typing import Annotated

from fastapi import APIRouter, Depends, Response
Expand Down
1 change: 0 additions & 1 deletion backend/api/routes/tag/tag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from email.policy import default
from typing import Annotated

from fastapi import APIRouter, Depends, Path, Query, Response
Expand Down
3 changes: 1 addition & 2 deletions backend/api/routes/user/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Annotated

from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from api.dependencies.db import get_db
Expand All @@ -26,6 +26,5 @@ def signup(user: UserCreate, db: Session = Depends(get_db)):
@router.get("/me", response_model=User)
def info(
current_user: Annotated[User, Depends(get_current_user)],
db: Session = Depends(get_db),
):
return current_user
3 changes: 2 additions & 1 deletion backend/db/db.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging
from typing import Any, TypedDict
from typing import TypedDict

from sqlalchemy import Engine, create_engine, event
from sqlalchemy.orm import Session, sessionmaker

# pylint: disable=unsubscriptable-object
DbPrams = TypedDict("DbPrams", {"session": sessionmaker[Session], "engine": Engine})


Expand Down
3 changes: 1 addition & 2 deletions backend/db/models/base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import datetime

from sqlalchemy import BigInteger, DateTime
from sqlalchemy import DateTime
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column


class Base(DeclarativeBase):
__abstract__ = True
__table_args__ = {"sqlite_autoincrement": True}
pass


class BasesWithCreatedDate(Base):
Expand Down
4 changes: 2 additions & 2 deletions backend/db/models/todo_category_order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING

from sqlalchemy import CheckConstraint, Connection, ForeignKey, UniqueConstraint, event
from sqlalchemy.orm import Mapped, Mapper, Session, mapped_column, relationship
from sqlalchemy import CheckConstraint, ForeignKey, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship

from db.models.base import BaseOrderedItem, BasesWithCreatedDate

Expand Down
1 change: 0 additions & 1 deletion backend/db/utils/oatuh.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime
from datetime import timedelta

from click import DateTime
from joserfc import jwt
from sqlalchemy.orm import Session

Expand Down
2 changes: 1 addition & 1 deletion backend/db/utils/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def update_user_permissions(
# check if the user we are changing has access to this project
try:
validate_project_belongs_to_user(db, project_id, permissions.user_id, None)
except UserFriendlyError as ex:
except UserFriendlyError:
raise UserFriendlyError(
ErrorCode.USER_DOESNT_HAVE_ACCESS_TO_PROJECT,
"The user that you are trying to update their permissions doesn't have access to this project or doesn't exist",
Expand Down
5 changes: 3 additions & 2 deletions backend/db/utils/shared/ordered_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Callable, Type, TypedDict
from collections.abc import Callable
from typing import Type, TypedDict

from sqlalchemy.orm import Mapped, Query, Session

Expand Down Expand Up @@ -100,7 +101,7 @@ def _remove_item_from_sorted_items_in_position[
TOrderedItemClass: BaseOrderedItem
](
db: Session,
order_class: Type[TOrderedItemClass],
order_class: type[TOrderedItemClass],
order_query: Query[TOrderedItemClass],
item_id_column: Mapped[int],
removing_item_id: int,
Expand Down
6 changes: 1 addition & 5 deletions backend/db/utils/tag_crud.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import typing

from sqlalchemy import and_
from sqlalchemy.orm import Session

from db.models.project import Project
from db.models.project_user_association import ProjectUserAssociation
from db.models.tag import Tag
from db.models.todo_category import TodoCategory
from db.models.todo_item import TodoItem
from db.models.todo_item_tag_association import TodoItemTagAssociation
from db.models.user import User
from db.models.user_project_permission import Permission, UserProjectPermission
from db.models.user_project_permission import Permission
from db.schemas.tag import TagAttachToTodo, TagCreate, TagDelete, TagUpdate
from db.utils.project_crud import validate_project_belongs_to_user
from db.utils.shared.permission_query import (
Expand Down
8 changes: 5 additions & 3 deletions backend/db/utils/todo_category_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def create_order(id: int, left_id: int | None, right_id: int | None):
db.commit()

item = db.query(TodoCategory).filter(TodoCategory.id == category_id).first()

if item is None:
raise

Expand Down Expand Up @@ -288,19 +289,20 @@ def validate_todo_category_belongs_to_user(
def _update_actions(
db: Session, todo_category: TodoCategory, toggle_actions: list[Action]
):

def has_action(actions: list[TodoCategoryAction], action: Action):
return len(list(filter(lambda x: x.action == action, actions))) >= 1
return len([_action for _action in actions if _action == action]) >= 1

def validate_can_add_action(action: Action, todo_category: TodoCategory):
match action:
case Action.AUTO_MARK_AS_DONE:
if len(list(filter(lambda x: not x.is_done, todo_category.items))) >= 1:
if len([item for item in todo_category.items if not item.is_done]) >= 1:
raise UserFriendlyError(
ErrorCode.CANT_CHANGE_ACTION,
"Cannot add this rule at the moment, because this category contains items that are not done yet",
)
case Action.AUTO_MARK_AS_UNDONE:
if len(list(filter(lambda x: x.is_done, todo_category.items))) >= 1:
if len([item for item in todo_category.items if item.is_done]) >= 1:
raise UserFriendlyError(
ErrorCode.CANT_CHANGE_ACTION,
"Cannot add this rule at the moment, because this category contains items that are already marked as done",
Expand Down
8 changes: 4 additions & 4 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
annotated-types==0.5.0
anyio==4.1.0
astroid==3.2.4
astroid==3.3.4
bcrypt==4.1.3
black==24.4.2
black==24.8.0
certifi==2024.7.4
cffi==1.16.0
click==8.1.6
cryptography==42.0.4
cryptography==43.0.1
dill==0.3.8
ecdsa==0.18.0
exceptiongroup==1.1.2
Expand Down Expand Up @@ -35,7 +35,7 @@ pycparser==2.21
pydantic==2.6.1
pydantic-settings==2.0.2
pydantic_core==2.16.2
pylint==3.2.6
pylint==3.3.1
pytest==7.4.3
python-dotenv==1.0.0
python-multipart==0.0.6
Expand Down
5 changes: 3 additions & 2 deletions backend/tests/api/fixtures/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Callable, List, TypedDict
from collections.abc import Callable
from typing import TypedDict

import pytest
from fastapi import FastAPI
Expand All @@ -8,7 +9,7 @@

TestUserType = TypedDict("TestUserType", {"id": int, "username": str, "password": str})

_TEST_USERS: List[TestUserType] = [
_TEST_USERS: list[TestUserType] = [
{"id": -1, "username": "test_username1", "password": "test_password1"},
{"id": -1, "username": "test_username2", "password": "test_password2"},
{"id": -1, "username": "test_username3", "password": "test_password3"},
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/api/fixtures/permissions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable
from collections.abc import Callable

import pytest
from fastapi.testclient import TestClient
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/api/fixtures/projects.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable
from collections.abc import Callable

import pytest
from fastapi.testclient import TestClient
Expand Down
6 changes: 3 additions & 3 deletions backend/tests/api/fixtures/tags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Dict
from collections.abc import Callable

import pytest
from fastapi.testclient import TestClient
Expand All @@ -9,7 +9,7 @@
@pytest.fixture(scope="function")
def attach_tag_to_todo(
test_client: TestClient,
auth_header_factory: Callable[[TestUserType], Dict[str, str]],
auth_header_factory: Callable[[TestUserType], dict[str, str]],
):
def _create_tag(user: TestUserType, project_id: int, todo_id: int, tag_name: str):
response = test_client.post(
Expand All @@ -29,7 +29,7 @@ def _create_tag(user: TestUserType, project_id: int, todo_id: int, tag_name: str
@pytest.fixture(scope="function")
def detach_tag_from_todo(
test_client: TestClient,
auth_header_factory: Callable[[TestUserType], Dict[str, str]],
auth_header_factory: Callable[[TestUserType], dict[str, str]],
):

def _remove_tag(
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/api/fixtures/todo_categories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable
from collections.abc import Callable

import pytest
from fastapi.testclient import TestClient
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/api/fixtures/todo_comments.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable
from collections.abc import Callable

import pytest
from fastapi.testclient import TestClient
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/api/fixtures/todo_items.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable
from collections.abc import Callable

import pytest
from fastapi.testclient import TestClient
Expand Down
4 changes: 1 addition & 3 deletions backend/tests/api/routes/permissions/test_permission.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from encodings import search_function
from typing import Callable
from collections.abc import Callable

from httpx import Response

Expand All @@ -8,7 +7,6 @@
from db.schemas.project import PartialUserWithPermission, Project
from error.exceptions import ErrorCode
from tests.api.conftest import TestUserType
from tests.api.routes.user import test_user


def test_permissions_dont_leak(
Expand Down
3 changes: 2 additions & 1 deletion backend/tests/api/routes/project/test_project.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Callable, cast
from collections.abc import Callable
from typing import cast

import pytest
from httpx import Response
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/api/routes/tag/test_tag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable
from collections.abc import Callable

from httpx import Response

Expand Down
4 changes: 1 addition & 3 deletions backend/tests/api/routes/todo_category/test_todo_category.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Callable, Dict
from collections.abc import Callable

import pytest
from fastapi.testclient import TestClient
from httpx import Response

from db.models.user_project_permission import Permission
Expand Down
3 changes: 1 addition & 2 deletions backend/tests/api/routes/todo_item/test_todo_item.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Callable, Dict
from collections.abc import Callable

import pytest
from fastapi.testclient import TestClient
from httpx import Response

from api.routes.error import UserFriendlyErrorSchema
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable
from collections.abc import Callable

from httpx import Response

Expand Down
5 changes: 4 additions & 1 deletion todos.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"cSpell.words": [
"addoption",
"autouse",
"httpx",
"ondropped",
"onsubmitclienterror",
"onsubmitended",
Expand All @@ -25,6 +27,7 @@
"starlette",
"testid"
],
"svelte.enable-ts-plugin": true
"svelte.enable-ts-plugin": true,
"pylint.importStrategy": "fromEnvironment"
}
}