Skip to content

Commit 5bbfb6c

Browse files
committed
Update and fix pre-commit hooks
Add language agonistic hooks for pre-commit - end-of-file-fixer - check-yaml Organize order of hooks by side of stack Add precommit script in package.json - This runs eslint without using --fix - https://stackoverflow.com/questions/51158815/running-eslint-in-precommit-does-not-stop-on-warnings#comment113030006_52896278 Add --max-warnings=0 flag to lint and precommit scripts Update flake8 hook to use remote repo Update flake8 and black to use local repository config files Run pre-commit check on all files and push fixes
1 parent 9429abf commit 5bbfb6c

File tree

24 files changed

+72
-48
lines changed

24 files changed

+72
-48
lines changed

.pre-commit-config.yaml

+21-20
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,41 @@ default_stages: [commit]
33
fail_fast: true
44

55
repos:
6-
# FRONTEND
7-
# ------------------------------------------------------------------------------
8-
- repo: local
9-
hooks:
10-
- id: eslint
11-
name: eslint
12-
language: system
13-
files: .+(js|jsx|ts|tsx|css|sass|less|json)
14-
entry: bash -c 'cd frontend && yarn lint'
15-
16-
# BACKEND
17-
# ------------------------------------------------------------------------------
186
- repo: https://github.com/pre-commit/pre-commit-hooks
197
rev: master
208
hooks:
219
- id: trailing-whitespace
22-
files: (^|/)a/.+\.(py|html|sh|css|js)$
10+
- id: end-of-file-fixer
11+
- id: check-yaml
2312

24-
- repo: local
13+
# Backend
14+
# ------------------------------------------------------------------------------
15+
- repo: https://gitlab.com/pycqa/flake8
16+
rev: 3.8.4
2517
hooks:
2618
- id: flake8
27-
name: flake8
28-
entry: flake8
29-
language: python
30-
types: [python]
3119
args: ["--config=backend/setup.cfg"]
20+
additional_dependencies: [flake8-isort]
3221

3322
- repo: https://github.com/psf/black
3423
rev: stable
3524
hooks:
3625
- id: black
37-
language_version: python3.8
26+
args: ["--config=backend/pyproject.toml"]
3827

3928
- repo: https://github.com/pre-commit/mirrors-mypy
40-
rev: v0.770
29+
rev: v0.790
4130
hooks:
4231
- id: mypy
32+
33+
# Frontend
34+
# ------------------------------------------------------------------------------
35+
# This hook runs the local eslint to avoid dependencies being out of sync with frontend/package.json
36+
# https://github.com/pre-commit/pre-commit/issues/945
37+
- repo: local
38+
hooks:
39+
- id: eslint
40+
name: eslint
41+
language: system
42+
files: .+(js|jsx|ts|tsx|json)$
43+
entry: bash -c 'cd frontend && yarn precommit'

LICENSE

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
77
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
88

99
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10-

backend/.envs/.local/.postgres

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ POSTGRES_HOST=postgres
22
POSTGRES_PORT=5432
33
POSTGRES_DB=postgres
44
POSTGRES_USER=postgres
5-
POSTGRES_PASSWORD=postgres
5+
POSTGRES_PASSWORD=postgres

backend/.envs/.production/.postgres.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ POSTGRES_HOST=postgres
22
POSTGRES_PORT=5432
33
POSTGRES_DB=postgres
44
POSTGRES_USER=postgres
5-
POSTGRES_PASSWORD=postgres
5+
POSTGRES_PASSWORD=postgres

backend/.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"python.pythonPath": "venv/bin/python"
3-
}
3+
}

backend/docker/local/keycloak/realm-export.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2128,4 +2128,4 @@
21282128
},
21292129
"keycloakVersion": "10.0.2",
21302130
"userManagedAccessAllowed": false
2131-
}
2131+
}

backend/metagrid/cart/tests/test_views.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ def setUp(self):
2626
"email": self.user.email,
2727
"password": raw_password,
2828
}
29-
response = self.client.post(rest_login_url, payload, format="json",)
29+
response = self.client.post(
30+
rest_login_url,
31+
payload,
32+
format="json",
33+
)
3034
assert response.status_code == status.HTTP_200_OK
3135

3236
# Add access token to authorization header
@@ -43,7 +47,11 @@ def test_get_request_returns_user_cart(self):
4347
def test_patch_request_updates_user_cart(self):
4448
# Add item to the user's cart
4549
payload = {"items": [{"title": "dataset"}]}
46-
response = self.client.patch(self.url, payload, format="json",)
50+
response = self.client.patch(
51+
self.url,
52+
payload,
53+
format="json",
54+
)
4755
assert response.status_code == status.HTTP_200_OK
4856

4957
user_cart = Cart.objects.get(user=self.user)
@@ -64,7 +72,11 @@ def setUp(self):
6472
"email": self.user.email,
6573
"password": raw_password,
6674
}
67-
response = self.client.post(rest_login_url, payload, format="json",)
75+
response = self.client.post(
76+
rest_login_url,
77+
payload,
78+
format="json",
79+
)
6880
assert response.status_code == status.HTTP_200_OK
6981

7082
# Add access token to authorization header
@@ -105,7 +117,11 @@ def test_put_request_updates_object(self):
105117
)
106118
payload["project_id"] = project.pk
107119

108-
response = self.client.put(self.detail_url, payload, format="json",)
120+
response = self.client.put(
121+
self.detail_url,
122+
payload,
123+
format="json",
124+
)
109125
assert response.status_code == status.HTTP_200_OK
110126

111127
user_search = Search.objects.get(pk=self.search_obj.pk)
@@ -114,7 +130,11 @@ def test_put_request_updates_object(self):
114130
def test_patch_request_partially_updates_object(self):
115131
# Add item to the user's cart
116132
payload = {"text_inputs": ["new_text"]}
117-
response = self.client.patch(self.detail_url, payload, format="json",)
133+
response = self.client.patch(
134+
self.detail_url,
135+
payload,
136+
format="json",
137+
)
118138
assert response.status_code == status.HTTP_200_OK
119139

120140
user_search = Search.objects.get(pk=self.search_obj.pk)

backend/metagrid/users/tests/test_views.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ def setUp(self):
5050
"email": self.user.email,
5151
"password": raw_password,
5252
}
53-
response = self.client.post(rest_login_url, payload, format="json",)
53+
response = self.client.post(
54+
rest_login_url,
55+
payload,
56+
format="json",
57+
)
5458
assert response.status_code == status.HTTP_200_OK
5559

5660
# Add access token to authorization header

backend/requirements/base.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ pre-commit==2.9.2 # https://github.com/pre-commit/pre-commit
3131
# Model Tools
3232
# ------------------------------------------------------------------------------
3333
django-model-utils==4.1.0 # https://github.com/jazzband/django-model-utils
34-
django_unique_upload==0.2.1 # https://github.com/agconti/django-unique-upload
34+
django_unique_upload==0.2.1 # https://github.com/agconti/django-unique-upload

backend/requirements/local.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ factory-boy==3.1.0 # https://github.com/FactoryBoy/factory_boy
2121
# ------------------------------------------------------------------------------
2222
ipdb==0.13.4 # https://github.com/gotcha/ipdb
2323
ipython==7.19.0 # https://github.com/ipython/ipython
24-
mkdocs==1.1.2 # https://www.mkdocs.org/
24+
mkdocs==1.1.2 # https://www.mkdocs.org/

frontend/.dockerignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ node_modules
22
build
33
.dockerignore
44
docker-compose.prod.yml
5-
docker-compose.yml
5+
docker-compose.yml

frontend/.envs/.local/.cors-proxy

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ PROXY_PORT=3001
88

99
# If set (array of strings), requests whose origin is not listed are blocked.
1010
# If this list is empty, all origins are allowed.
11-
PROXY_ORIGIN_WHITELIST=http://localhost:3000
11+
PROXY_ORIGIN_WHITELIST=http://localhost:3000

frontend/.envs/.production/.cors-proxy.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ PROXY_PORT=3001
77

88
# If set (array of strings), requests whose origin is not listed are blocked.
99
# If this list is empty, all origins are allowed.
10-
PROXY_ORIGIN_WHITELIST=
10+
PROXY_ORIGIN_WHITELIST=

frontend/.envs/.production/.react.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ REACT_APP_HOTJAR_SV=
4343
# react-ga
4444
# ------------------------------------------------------------------------------
4545
# https://github.com/react-ga/react-ga
46-
REACT_APP_GOOGLE_ANALYTICS_TRACKING_ID=
46+
REACT_APP_GOOGLE_ANALYTICS_TRACKING_ID=

frontend/.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dist
22
node_modules
33
coverage
4-
build
4+
build

frontend/docker/local/cors-proxy/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ RUN yarn install
1515
COPY . ./
1616

1717
# Start cors-proxy
18-
CMD ["node", "index.js"]
18+
CMD ["node", "index.js"]

frontend/docker/local/react/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ RUN yarn install
1616
COPY . ./
1717

1818
# Start app
19-
CMD ["yarn", "start:local"]
19+
CMD ["yarn", "start:local"]

frontend/docker/production/cors-proxy/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ RUN yarn install
1515
COPY . ./
1616

1717
# Start cors-proxy
18-
CMD ["node", "index.js"]
18+
CMD ["node", "index.js"]

frontend/docker/production/nginx/nginx.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ server {
1414
root /usr/share/nginx/html;
1515
}
1616

17-
}
17+
}

frontend/docker/production/nginx/nginx.subdir.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ server {
1414
root /usr/share/nginx/html;
1515
}
1616

17-
}
17+
}

frontend/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"test": "CI=1 env-cmd -f .envs/.local/.react react-scripts test --env=jest-environment-jsdom-sixteen",
4343
"test:watch": "env-cmd -f .envs/.local/.react react-scripts test --env=jest-environment-jsdom-sixteen",
4444
"test:coverage": "CI=1 env-cmd -f .envs/.local/.react react-scripts test --coverage --env=jest-environment-jsdom-sixteen",
45-
"lint": "eslint './src/**/*.{js,jsx,ts,tsx,json}' --fix --no-error-on-unmatched-pattern",
46-
"precommit": "lint-staged"
45+
"lint": "eslint './src/**/*.{js,jsx,ts,tsx,json}' --fix --max-warnings=0 --no-error-on-unmatched-pattern",
46+
"precommit": "eslint './src/**/*.{js,jsx,ts,tsx,json}' --max-warnings=0 --no-error-on-unmatched-pattern"
4747
},
4848
"eslintConfig": {
4949
"extends": "react-app"

frontend/src/assets/img/nodes.svg

+1-1
Loading

0 commit comments

Comments
 (0)