Skip to content

Commit 293d5da

Browse files
Uno-Takashiclaude
andcommitted
chore: add pre-commit hooks and flake8-bandit ruff rules
Introduce a pre-commit configuration running ruff (lint + format) and the standard pre-commit-hooks. Expand the ruff rule set to cover flake8 (E/W/F), flake8-django (DJ) and flake8-bandit (S); ignore S101 in tests/conftest. Vendored static assets under web/static/ are excluded from the generic whitespace/EOF hooks. Hand-maintained files are normalised one-off. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 41ba974 commit 293d5da

9 files changed

Lines changed: 54 additions & 16 deletions

File tree

.dockleignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CIS-DI-0010
1+
CIS-DI-0010

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313

1414
## その他・備考
1515

16-
- (備考やレビュワーへの申し送り事項等があれば書いてください)
16+
- (備考やレビュワーへの申し送り事項等があれば書いてください)

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ migrations/
9696

9797
prof/*
9898

99-
.coverage*
99+
.coverage*

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# pre-commit hooks for the d-party Backend (Django).
2+
# Install: `pre-commit install` (run from this directory).
3+
# Run on everything: `pre-commit run --all-files`
4+
#
5+
# ruff の詳細ルール(flake8 / flake8-django / flake8-bandit 等)は pyproject.toml の
6+
# [tool.ruff] を参照する。
7+
minimum_pre_commit_version: "3.5.0"
8+
9+
# ベンダー製 / 配信用静的アセット(jQuery・Bootstrap・Flickity 等の minified ライブラリ)は
10+
# 整形対象から除外する。アプリのソースコードのみフックを適用する。
11+
exclude: '^web/static/'
12+
13+
repos:
14+
- repo: https://github.com/pre-commit/pre-commit-hooks
15+
rev: v6.0.0
16+
hooks:
17+
- id: trailing-whitespace
18+
- id: end-of-file-fixer
19+
- id: check-yaml
20+
args: [--allow-multiple-documents]
21+
- id: check-toml
22+
- id: check-json
23+
- id: check-merge-conflict
24+
- id: check-added-large-files
25+
26+
- repo: https://github.com/astral-sh/ruff-pre-commit
27+
rev: v0.15.18
28+
hooks:
29+
# Lint(flake8 / flake8-django / flake8-bandit 等を ruff で再現。設定は pyproject.toml)
30+
- id: ruff-check
31+
args: [--fix]
32+
# Format(black 互換)
33+
- id: ruff-format

pyproject.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ line-length = 88
5252
extend-exclude = ["**/migrations/*"]
5353

5454
[tool.ruff.lint]
55-
select = ["E", "F", "I", "UP", "B", "DJ", "C4"]
55+
# E,W,F = flake8 本体 (pycodestyle + pyflakes) / DJ = flake8-django /
56+
# S = flake8-bandit / I = isort / UP = pyupgrade / B = flake8-bugbear /
57+
# C4 = flake8-comprehensions
58+
select = ["E", "W", "F", "I", "UP", "B", "DJ", "C4", "S"]
5659
ignore = [
5760
"E501", # line length is handled by the formatter
5861
"B008", # function calls in argument defaults are idiomatic in Django/DRF
@@ -62,8 +65,10 @@ ignore = [
6265
[tool.ruff.lint.per-file-ignores]
6366
# The Channels ASGI entrypoint must initialise Django before importing routing.
6467
"d_party/asgi.py" = ["E402"]
65-
# Pre-existing test-only smells we intentionally leave untouched.
66-
"**/tests.py" = ["E711", "E721", "E722", "F811", "F841"]
68+
# Tests use bare asserts (flake8-bandit S101) plus pre-existing test-only smells.
69+
"**/tests.py" = ["S101", "E711", "E721", "E722", "F811", "F841"]
70+
"**/test_*.py" = ["S101"]
71+
"conftest.py" = ["S101"]
6772

6873
[tool.pytest.ini_options]
6974
DJANGO_SETTINGS_MODULE = "d_party.settings"

web/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
!static/
1+
!static/

web/templates/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% block stylesheet %}
33
{% load static %}
44
<link rel="stylesheet" href="{% static "web/css/lobby.css" %}" />
5-
{% endblock %}
5+
{% endblock %}
66
{% block content %}
77
<div class="redirect-shop update-shop">
88
<img src="{% static "web/img/lobby/hand.svg" %}" width="125" height="125"/>

web/templates/chart.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{% extends "layout.html" %} {% load static %}
2-
{%block stylesheet %} <script src="{% static "web/js/index.js" %}"></script>
2+
{%block stylesheet %} <script src="{% static "web/js/index.js" %}"></script>
33
<script src="{% static "web/js/echarts.min.js" %}"></script>
44
<script src="{% static "web/js/dark.js" %}"></script>
55
<link rel="stylesheet" href="{% static "web/css/chart.css" %}" />
6-
{% endblock %}
6+
{% endblock %}
77
{% block content %}
88
<div id="main" class="container center-block statistics-title">
99
<h1 class="text-white text-center statistics-title">ユーザーログ統計情報</h1>
@@ -60,4 +60,4 @@ <h6 class="card-title">ルーム : 接続中</h5>
6060
<div id="reaction_room" class="chart_content"></div>
6161
</div>
6262
<script src="{% static "web/js/chart.js" %}"></script>
63-
{% endblock %}
63+
{% endblock %}

web/templates/layout.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{%block head%}{% endblock %}
1010
{% load static %}
1111
<link rel="icon"
12-
type="image/png" sizes="32x32" href="{% static "web/favicon/favicon-32x32.png" %}">
12+
type="image/png" sizes="32x32" href="{% static "web/favicon/favicon-32x32.png" %}">
1313
<link rel="icon" type="image/png" sizes="16x16" href="{% static "web/favicon/favicon-16x16.png" %}">
1414
<meta name="theme-color" content="#ffffff" />
1515
<meta name="msapplication-TileColor" content="#da532c" />
@@ -24,11 +24,11 @@
2424
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
2525
<link rel="stylesheet" href="https://unpkg.com/simplebar@latest/dist/simplebar.css"/>
2626
<script src="https://unpkg.com/simplebar@latest/dist/simplebar.min.js"></script>
27-
<script src="{% static "web/js/bootstrap.min.js" %}"></script>
27+
<script src="{% static "web/js/bootstrap.min.js" %}"></script>
2828
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.0/font/bootstrap-icons.css">
29-
<script src="{% static "web/js/jquery-3.6.0.js" %}"></script>
30-
<script src="{% static "web/js/jquery-migrate.js" %}"></script>
31-
<script src="{% static "web/js/flickity.min.js" %}"></script>
29+
<script src="{% static "web/js/jquery-3.6.0.js" %}"></script>
30+
<script src="{% static "web/js/jquery-migrate.js" %}"></script>
31+
<script src="{% static "web/js/flickity.min.js" %}"></script>
3232
<script src="https://unpkg.com/axios@1.0.0/dist/axios.min.js"></script>
3333
{%block stylesheet%}{% endblock %}
3434
</head>

0 commit comments

Comments
 (0)