From 82819aa99bd77c9f58b3dc7c039f88befffc7da2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20Loipf=C3=BChrer?= <michael.loipfuehrer@stusta.de>
Date: Sat, 30 Oct 2021 17:45:22 +0200
Subject: [PATCH] fix pylint and bandit

---
 .pylintrc                   |  0
 management/forms.py         |  6 ++--
 management/urls.py          |  1 -
 pyproject.toml              | 63 ++++++++++++++++++++-----------------
 requirements_dev.txt        |  2 +-
 setup.py                    |  4 +--
 vote/models.py              |  4 +--
 wahlfang_api/admin.py       |  3 --
 wahlfang_api/serializers.py |  2 +-
 wahlfang_api/tests.py       |  3 --
 wahlfang_api/views.py       |  1 -
 11 files changed, 45 insertions(+), 44 deletions(-)
 delete mode 100644 .pylintrc

diff --git a/.pylintrc b/.pylintrc
deleted file mode 100644
index e69de29..0000000
diff --git a/management/forms.py b/management/forms.py
index 5b4ffad..bd2ff7d 100644
--- a/management/forms.py
+++ b/management/forms.py
@@ -62,13 +62,15 @@ class TemplateStringForm:
         checks if the cleaned_text fails when formatted on the test_data.
         """
         test_data_dict = {i: "" for i in test_data}
-        cleaned_text = self.cleaned_data[field]
+        cleaned_text = self.cleaned_data[field]  # pylint: disable=no-member
         try:
             cleaned_text.format(**test_data_dict)
         except (KeyError, ValueError, IndexError):
             x = re.findall(r"\{\w*\}", cleaned_text)
             test_data = set(x) - {f"{{{i}}}" for i in test_data}
-            self.add_error(field, "The following variables are not allowed: " + ", ".join(test_data))
+            self.add_error(  # pylint: disable=no-member
+                field, "The following variables are not allowed: " + ", ".join(test_data)
+            )
         return cleaned_text
 
 
diff --git a/management/urls.py b/management/urls.py
index 1a5779b..37ea99b 100644
--- a/management/urls.py
+++ b/management/urls.py
@@ -2,7 +2,6 @@ from django.contrib.auth import views as auth_views
 from django.urls import path
 from prometheus_client import Gauge
 
-import vote.views
 from management import views
 from management.models import ElectionManager
 from vote.models import Election, Session
diff --git a/pyproject.toml b/pyproject.toml
index 5305c43..4a99030 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -7,49 +7,56 @@ build-backend = 'setuptools.build_meta'
 
 [tool.pylint]
 [tool.pylint.master]
-ignore = ['migrations', 'settings.py']
-jobs = 1
+ignore = ['migrations', 'settings.py', 'docs']
+jobs = 4
 load-plugins = 'pylint_django'
 django-settings-module = 'wahlfang.settings.development'
 
 [tool.pylint.'MESSAGES CONTROL']
 disable = [
-    'print-statement',
-    'missing-function-docstring',
-    'missing-module-docstring',
-    'missing-class-docstring',
-    'line-too-long',
-    'invalid-name',
+    'R',
+    'C',
     'unused-argument',
-    'too-many-locals',
-    'too-many-statements',
-    'too-many-instance-arguments',
-    'too-few-public-methods',
-    'too-many-arguments',
-    'too-many-instance-attributes',
-    'too-many-branches',
-    'too-many-lines',
-    'too-many-public-methods',
-    'bad-indentation',
-    'bad-continuation',
-    'import-error',
-    'wildcard-import',
-    'no-self-use',
-    'duplicate-code',
-    'wrong-import-position',
-    'no-member',
-    'unused-import'
+    'fixme'
+    #'print-statement',
+    #'missing-function-docstring',
+    #'missing-module-docstring',
+    #'missing-class-docstring',
+    #'line-too-long',
+    #'invalid-name',
+    #'too-many-locals',
+    #'too-many-statements',
+    #'too-many-instance-arguments',
+    #'too-few-public-methods',
+    #'too-many-arguments',
+    #'too-many-instance-attributes',
+    #'too-many-branches',
+    #'too-many-lines',
+    #'too-many-public-methods',
+    #'bad-indentation',
+    #'bad-continuation',
+    #'import-error',
+    #'wildcard-import',
+    #'no-self-use',
+    #'duplicate-code',
+    #'wrong-import-position',
+    #'no-member',
+    #'unused-import',
+    #'missing-module-docstring',
+    #'missing-class-docstring',
+    #'missing-function-docstring'
 ]
 
 [tool.mypy]
 plugins = [
     'mypy_django_plugin.main'
 ]
+exclude = 'docs'
 ignore_missing_imports = true
 pretty = true
 
-#[tool.mypy.plugins.'django-stubs']  # FIXME: this does not work with toml apparently
-#django_settings_module = 'wahlfang.settings.development'
+[tool.django-stubs]
+django_settings_module = 'wahlfang.settings.development'
 
 [tool.'mypy-*'.'migrations.*']
 ignore_errors = true
diff --git a/requirements_dev.txt b/requirements_dev.txt
index 9e9bc72..ba090f0 100644
--- a/requirements_dev.txt
+++ b/requirements_dev.txt
@@ -1,5 +1,5 @@
 bandit==1.6.2
-pylint==2.8
+pylint==2.11.1
 pylint-django~=2.4
 django-cors-headers~=3.7.0
 django-stubs
diff --git a/setup.py b/setup.py
index f9eaf86..0cf9fb7 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 import os
 import shutil
-from subprocess import run
+from subprocess import run  # nosec
 
 from setuptools import setup
 
@@ -13,7 +13,7 @@ os.chdir(ui_dir)
 static_dir = os.path.join(ui_dir, 'static')
 if os.path.exists(static_dir):
     shutil.rmtree(static_dir)
-run(['yarn', 'build'], check=True)
+run(['yarn', 'build'], check=True)  # nosec
 os.chdir(curr_dir)
 
 setup()
diff --git a/vote/models.py b/vote/models.py
index 22c5811..d139ef5 100644
--- a/vote/models.py
+++ b/vote/models.py
@@ -487,9 +487,9 @@ class Application(models.Model):
              update_fields=None):
         if self.avatar and self._old_avatar != self.avatar:
             # remove old file
-            if self._old_avatar and os.path.isfile(self._old_avatar.path):
+            if self._old_avatar and os.path.isfile(self._old_avatar.path):  # pylint: disable=E1101
                 # let's not play russian roulette
-                path = os.path.normpath(self._old_avatar.path)
+                path = os.path.normpath(self._old_avatar.path)  # pylint: disable=E1101
                 if path.startswith(os.path.join(settings.MEDIA_ROOT, 'avatars')):
                     os.remove(path)
 
diff --git a/wahlfang_api/admin.py b/wahlfang_api/admin.py
index 8c38f3f..e69de29 100644
--- a/wahlfang_api/admin.py
+++ b/wahlfang_api/admin.py
@@ -1,3 +0,0 @@
-from django.contrib import admin
-
-# Register your models here.
diff --git a/wahlfang_api/serializers.py b/wahlfang_api/serializers.py
index 562c35e..fb18556 100644
--- a/wahlfang_api/serializers.py
+++ b/wahlfang_api/serializers.py
@@ -1,6 +1,6 @@
 from django.conf import settings
 from django.contrib.auth import authenticate
-from rest_framework import serializers, fields
+from rest_framework import serializers
 from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
 from rest_framework_simplejwt.tokens import RefreshToken
 
diff --git a/wahlfang_api/tests.py b/wahlfang_api/tests.py
index 7ce503c..e69de29 100644
--- a/wahlfang_api/tests.py
+++ b/wahlfang_api/tests.py
@@ -1,3 +0,0 @@
-from django.test import TestCase
-
-# Create your tests here.
diff --git a/wahlfang_api/views.py b/wahlfang_api/views.py
index 7eb09fc..3cc7b23 100644
--- a/wahlfang_api/views.py
+++ b/wahlfang_api/views.py
@@ -8,7 +8,6 @@ from rest_framework.throttling import AnonRateThrottle
 from rest_framework_simplejwt.views import TokenViewBase
 
 from vote.forms import VoteForm
-from management.forms import AddSessionForm
 from vote.models import Election, Voter, Application, Session
 from wahlfang_api.authentication import IsVoter, IsElectionManager, ElectionManagerJWTAuthentication, \
     VoterJWTAuthentication
-- 
GitLab