Skip to content

Commit

Permalink
Add more pre-commit hooks
Browse files Browse the repository at this point in the history
Hooks added:

* check-merge-conflict - checks for files with merge conflict strings
* check-toml - attempts to load all toml files to verify syntax
* check-yaml - attempts to load all yaml files to verify syntax
* end-of-file-fixer - ensures files end in a newline and only a newline
* mixed-line-ending - replaces mixed line endings with LF
* trailing-whitespace - trims trailing whitespace
* python-check-blanket-noqa - enforces that noqa annotations always
  occur with specific codes

Changes made to comply with new hooks:

* Remove trailing whitespaces
* Remove some useless noqa annotations
* Specify errors for noqa annotations
* Add missing newlines at end of files

See: python-discord/organisation#138
  • Loading branch information
MarkKoz committed Mar 5, 2020
1 parent 489b3d7 commit 5ed6e71
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 35 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@
# See e.g. https://stackoverflow.com/a/38588882/4464570
*.png binary
*.whl binary

23 changes: 19 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
repos:
- repo: local
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
- id: flake8
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.5.1
hooks:
- id: python-check-blanket-noqa
- repo: local
hooks:
- id: flake8
name: Flake8
description: This hook runs flake8 within our project's pipenv environment.
entry: pipenv run lint
entry: pipenv run flake8
language: python
types: [python]
require_serial: true
require_serial: true
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Instructions for setting up environments for both the site and the bot can be fo
When pulling down changes from GitHub, remember to sync your environment using `pipenv sync --dev` to ensure you're using the most up-to-date versions the project's dependencies.

### Type Hinting
[PEP 484](https://www.python.org/dev/peps/pep-0484/) formally specifies type hints for Python functions, added to the Python Standard Library in version 3.5. Type hints are recognized by most modern code editing tools and provide useful insight into both the input and output types of a function, preventing the user from having to go through the codebase to determine these types.
[PEP 484](https://www.python.org/dev/peps/pep-0484/) formally specifies type hints for Python functions, added to the Python Standard Library in version 3.5. Type hints are recognized by most modern code editing tools and provide useful insight into both the input and output types of a function, preventing the user from having to go through the codebase to determine these types.

For example:

Expand Down Expand Up @@ -106,4 +106,4 @@ As stated earlier, **ensure that "Allow edits from maintainers" is checked**. Th

## Footnotes

This document was inspired by the [Glowstone contribution guidelines](https://github.com/GlowstoneMC/Glowstone/blob/dev/docs/CONTRIBUTING.md).
This document was inspired by the [Glowstone contribution guidelines](https://github.com/GlowstoneMC/Glowstone/blob/dev/docs/CONTRIBUTING.md).
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ makemigrations = "python manage.py makemigrations"
django_shell = "python manage.py shell"
test = "coverage run manage.py test"
report = "coverage report -m"
lint = "flake8"
lint = "pre-commit run --all-files"
precommit = "pre-commit install"
2 changes: 1 addition & 1 deletion pydis_site/apps/api/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
test_user, _created = User.objects.get_or_create(
username='test',
email='[email protected]',
password='testpass', # noqa
password='testpass',
is_superuser=True,
is_staff=True
)
Expand Down
4 changes: 2 additions & 2 deletions pydis_site/apps/api/tests/test_deleted_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DeletedMessagesWithoutActorTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.author = User.objects.create(
id=55,
name='Robbie Rotten',
Expand Down Expand Up @@ -49,7 +49,7 @@ def test_accepts_valid_data(self):

class DeletedMessagesWithActorTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.author = cls.actor = User.objects.create(
id=12904,
name='Joe Armstrong',
Expand Down
4 changes: 2 additions & 2 deletions pydis_site/apps/api/tests/test_documentation_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_delete_returns_404(self):

class DetailLookupDocumentationLinkAPITests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.doc_link = DocumentationLink.objects.create(
package='testpackage',
base_url='https://example.com',
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_detail_lookup_works_with_package(self):

class DocumentationLinkDeletionTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.doc_link = DocumentationLink.objects.create(
package='example',
base_url='https://example.com',
Expand Down
6 changes: 3 additions & 3 deletions pydis_site/apps/api/tests/test_infractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_partial_update_returns_401(self):

class InfractionTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.user = User.objects.create(
id=5,
name='james',
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_partial_update_returns_400_for_frozen_field(self):

class CreationTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.user = User.objects.create(
id=5,
name='james',
Expand Down Expand Up @@ -517,7 +517,7 @@ def test_integrity_error_if_missing_active_field(self):

class ExpandedTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.user = User.objects.create(
id=5,
name='james',
Expand Down
4 changes: 2 additions & 2 deletions pydis_site/apps/api/tests/test_nominations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class CreationTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.user = User.objects.create(
id=1234,
name='joe dart',
Expand Down Expand Up @@ -185,7 +185,7 @@ def test_returns_400_for_active_at_creation(self):

class NominationTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.user = User.objects.create(
id=1234,
name='joe dart',
Expand Down
4 changes: 2 additions & 2 deletions pydis_site/apps/api/tests/test_off_topic_channel_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_returns_400_for_negative_random_items_param(self):

class ListTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.test_name = OffTopicChannelName.objects.create(name='lemons-lemonade-stand')
cls.test_name_2 = OffTopicChannelName.objects.create(name='bbq-with-bisk')

Expand Down Expand Up @@ -129,7 +129,7 @@ def test_returns_400_for_bad_name_param(self):

class DeletionTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.test_name = OffTopicChannelName.objects.create(name='lemons-lemonade-stand')
cls.test_name_2 = OffTopicChannelName.objects.create(name='bbq-with-bisk')

Expand Down
6 changes: 3 additions & 3 deletions pydis_site/apps/api/tests/test_offensive_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_returns_400_on_negative_id_or_channel_id(self):

class ListTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
delete_at = datetime.datetime.now() + datetime.timedelta(days=1)
aware_delete_at = delete_at.replace(tzinfo=datetime.timezone.utc)

Expand Down Expand Up @@ -110,7 +110,7 @@ def test_get_data(self):

class DeletionTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
delete_at = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(days=1)

cls.valid_offensive_message = OffensiveMessage.objects.create(
Expand All @@ -134,7 +134,7 @@ def test_delete_data(self):

class NotAllowedMethodsTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
delete_at = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(days=1)

cls.valid_offensive_message = OffensiveMessage.objects.create(
Expand Down
2 changes: 1 addition & 1 deletion pydis_site/apps/api/tests/test_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class CreationTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.admins_role = Role.objects.create(
id=1,
name="Admins",
Expand Down
4 changes: 2 additions & 2 deletions pydis_site/apps/api/tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_delete_returns_401(self):

class CreationTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.role = Role.objects.create(
id=5,
name="Test role pls ignore",
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_returns_400_for_bad_data(self):

class UserModelTests(APISubdomainTestCase):
@classmethod
def setUpTestData(cls): # noqa
def setUpTestData(cls):
cls.role_top = Role.objects.create(
id=777,
name="High test role",
Expand Down
4 changes: 2 additions & 2 deletions pydis_site/apps/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HealthcheckView(APIView):
authentication_classes = ()
permission_classes = ()

def get(self, request, format=None): # noqa
def get(self, request, format=None): # noqa: D102,ANN001,ANN201
return Response({'status': 'ok'})


Expand Down Expand Up @@ -96,7 +96,7 @@ def _format_link(description: str, link: str, target: str) -> str:
)

# `format` here is the result format, we have a link format here instead.
def get(self, request, format=None): # noqa
def get(self, request, format=None): # noqa: D102,ANN001,ANN201
link_format = request.query_params.get('link_format', 'md')
if link_format not in ('html', 'md'):
raise ParseError(
Expand Down
2 changes: 1 addition & 1 deletion pydis_site/apps/home/tests/test_repodata_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pydis_site.apps.home.views import HomeView


def mocked_requests_get(*args, **kwargs) -> "MockResponse": # noqa
def mocked_requests_get(*args, **kwargs) -> "MockResponse": # noqa: F821
"""A mock version of requests.get, so we don't need to call the API every time we run a test."""
class MockResponse:
def __init__(self, json_data, status_code):
Expand Down
1 change: 0 additions & 1 deletion pydis_site/static/css/home/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,3 @@ span.repo-language-dot.javascript {
max-width: none;
}
}

2 changes: 1 addition & 1 deletion pydis_site/static/favicons/safari-pinned-tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion pydis_site/templates/home/account/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,3 @@ <h3 class="title">Connections</h3>
</div>
</div>
</div>

1 change: 0 additions & 1 deletion pydis_site/templates/home/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,3 @@ <h1 class="title is-6 has-text-grey">
</section>

{% endblock %}

2 changes: 0 additions & 2 deletions pydis_site/templates/wiki/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,3 @@
<script src="{% static "js/wiki/modal.js" %}" type="text/javascript"></script>
<script src="{% static "js/wiki/history.js" %}" type="text/javascript"></script>
{% endblock %}


0 comments on commit 5ed6e71

Please sign in to comment.