Skip to content

Commit

Permalink
Update and fix pre-commit hooks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tomvothecoder committed Dec 24, 2020
1 parent 9429abf commit 5bbfb6c
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 48 deletions.
41 changes: 21 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,41 @@ default_stages: [commit]
fail_fast: true

repos:
# FRONTEND
# ------------------------------------------------------------------------------
- repo: local
hooks:
- id: eslint
name: eslint
language: system
files: .+(js|jsx|ts|tsx|css|sass|less|json)
entry: bash -c 'cd frontend && yarn lint'

# BACKEND
# ------------------------------------------------------------------------------
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: master
hooks:
- id: trailing-whitespace
files: (^|/)a/.+\.(py|html|sh|css|js)$
- id: end-of-file-fixer
- id: check-yaml

- repo: local
# Backend
# ------------------------------------------------------------------------------
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
name: flake8
entry: flake8
language: python
types: [python]
args: ["--config=backend/setup.cfg"]
additional_dependencies: [flake8-isort]

- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3.8
args: ["--config=backend/pyproject.toml"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.770
rev: v0.790
hooks:
- id: mypy

# Frontend
# ------------------------------------------------------------------------------
# This hook runs the local eslint to avoid dependencies being out of sync with frontend/package.json
# https://github.com/pre-commit/pre-commit/issues/945
- repo: local
hooks:
- id: eslint
name: eslint
language: system
files: .+(js|jsx|ts|tsx|json)$
entry: bash -c 'cd frontend && yarn precommit'
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.

2 changes: 1 addition & 1 deletion backend/.envs/.local/.postgres
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_PASSWORD=postgres
2 changes: 1 addition & 1 deletion backend/.envs/.production/.postgres.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_PASSWORD=postgres
2 changes: 1 addition & 1 deletion backend/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"python.pythonPath": "venv/bin/python"
}
}
2 changes: 1 addition & 1 deletion backend/docker/local/keycloak/realm-export.json
Original file line number Diff line number Diff line change
Expand Up @@ -2128,4 +2128,4 @@
},
"keycloakVersion": "10.0.2",
"userManagedAccessAllowed": false
}
}
30 changes: 25 additions & 5 deletions backend/metagrid/cart/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def setUp(self):
"email": self.user.email,
"password": raw_password,
}
response = self.client.post(rest_login_url, payload, format="json",)
response = self.client.post(
rest_login_url,
payload,
format="json",
)
assert response.status_code == status.HTTP_200_OK

# Add access token to authorization header
Expand All @@ -43,7 +47,11 @@ def test_get_request_returns_user_cart(self):
def test_patch_request_updates_user_cart(self):
# Add item to the user's cart
payload = {"items": [{"title": "dataset"}]}
response = self.client.patch(self.url, payload, format="json",)
response = self.client.patch(
self.url,
payload,
format="json",
)
assert response.status_code == status.HTTP_200_OK

user_cart = Cart.objects.get(user=self.user)
Expand All @@ -64,7 +72,11 @@ def setUp(self):
"email": self.user.email,
"password": raw_password,
}
response = self.client.post(rest_login_url, payload, format="json",)
response = self.client.post(
rest_login_url,
payload,
format="json",
)
assert response.status_code == status.HTTP_200_OK

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

response = self.client.put(self.detail_url, payload, format="json",)
response = self.client.put(
self.detail_url,
payload,
format="json",
)
assert response.status_code == status.HTTP_200_OK

user_search = Search.objects.get(pk=self.search_obj.pk)
Expand All @@ -114,7 +130,11 @@ def test_put_request_updates_object(self):
def test_patch_request_partially_updates_object(self):
# Add item to the user's cart
payload = {"text_inputs": ["new_text"]}
response = self.client.patch(self.detail_url, payload, format="json",)
response = self.client.patch(
self.detail_url,
payload,
format="json",
)
assert response.status_code == status.HTTP_200_OK

user_search = Search.objects.get(pk=self.search_obj.pk)
Expand Down
6 changes: 5 additions & 1 deletion backend/metagrid/users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def setUp(self):
"email": self.user.email,
"password": raw_password,
}
response = self.client.post(rest_login_url, payload, format="json",)
response = self.client.post(
rest_login_url,
payload,
format="json",
)
assert response.status_code == status.HTTP_200_OK

# Add access token to authorization header
Expand Down
2 changes: 1 addition & 1 deletion backend/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ pre-commit==2.9.2 # https://github.com/pre-commit/pre-commit
# Model Tools
# ------------------------------------------------------------------------------
django-model-utils==4.1.0 # https://github.com/jazzband/django-model-utils
django_unique_upload==0.2.1 # https://github.com/agconti/django-unique-upload
django_unique_upload==0.2.1 # https://github.com/agconti/django-unique-upload
2 changes: 1 addition & 1 deletion backend/requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ factory-boy==3.1.0 # https://github.com/FactoryBoy/factory_boy
# ------------------------------------------------------------------------------
ipdb==0.13.4 # https://github.com/gotcha/ipdb
ipython==7.19.0 # https://github.com/ipython/ipython
mkdocs==1.1.2 # https://www.mkdocs.org/
mkdocs==1.1.2 # https://www.mkdocs.org/
2 changes: 1 addition & 1 deletion frontend/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules
build
.dockerignore
docker-compose.prod.yml
docker-compose.yml
docker-compose.yml
2 changes: 1 addition & 1 deletion frontend/.envs/.local/.cors-proxy
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ PROXY_PORT=3001

# If set (array of strings), requests whose origin is not listed are blocked.
# If this list is empty, all origins are allowed.
PROXY_ORIGIN_WHITELIST=http://localhost:3000
PROXY_ORIGIN_WHITELIST=http://localhost:3000
2 changes: 1 addition & 1 deletion frontend/.envs/.production/.cors-proxy.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ PROXY_PORT=3001

# If set (array of strings), requests whose origin is not listed are blocked.
# If this list is empty, all origins are allowed.
PROXY_ORIGIN_WHITELIST=
PROXY_ORIGIN_WHITELIST=
2 changes: 1 addition & 1 deletion frontend/.envs/.production/.react.template
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ REACT_APP_HOTJAR_SV=
# react-ga
# ------------------------------------------------------------------------------
# https://github.com/react-ga/react-ga
REACT_APP_GOOGLE_ANALYTICS_TRACKING_ID=
REACT_APP_GOOGLE_ANALYTICS_TRACKING_ID=
2 changes: 1 addition & 1 deletion frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist
node_modules
coverage
build
build
2 changes: 1 addition & 1 deletion frontend/docker/local/cors-proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ RUN yarn install
COPY . ./

# Start cors-proxy
CMD ["node", "index.js"]
CMD ["node", "index.js"]
2 changes: 1 addition & 1 deletion frontend/docker/local/react/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ RUN yarn install
COPY . ./

# Start app
CMD ["yarn", "start:local"]
CMD ["yarn", "start:local"]
2 changes: 1 addition & 1 deletion frontend/docker/production/cors-proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ RUN yarn install
COPY . ./

# Start cors-proxy
CMD ["node", "index.js"]
CMD ["node", "index.js"]
2 changes: 1 addition & 1 deletion frontend/docker/production/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ server {
root /usr/share/nginx/html;
}

}
}
2 changes: 1 addition & 1 deletion frontend/docker/production/nginx/nginx.subdir.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ server {
root /usr/share/nginx/html;
}

}
}
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"test": "CI=1 env-cmd -f .envs/.local/.react react-scripts test --env=jest-environment-jsdom-sixteen",
"test:watch": "env-cmd -f .envs/.local/.react react-scripts test --env=jest-environment-jsdom-sixteen",
"test:coverage": "CI=1 env-cmd -f .envs/.local/.react react-scripts test --coverage --env=jest-environment-jsdom-sixteen",
"lint": "eslint './src/**/*.{js,jsx,ts,tsx,json}' --fix --no-error-on-unmatched-pattern",
"precommit": "lint-staged"
"lint": "eslint './src/**/*.{js,jsx,ts,tsx,json}' --fix --max-warnings=0 --no-error-on-unmatched-pattern",
"precommit": "eslint './src/**/*.{js,jsx,ts,tsx,json}' --max-warnings=0 --no-error-on-unmatched-pattern"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/assets/img/nodes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5bbfb6c

Please sign in to comment.