зеркало из https://github.com/mozilla/pontoon.git
Add a Make target to run all linters. (#2011)
* Add a Make target to run all linters * Unify order of commands in PHONY, help and definitions * More meaningful order of commands * Simpler ci command definition * Document pyupgrade * Fix b0rken link in the docs Co-authored-by: Matjaž Horvat <matjaz.horvat@gmail.com>
This commit is contained in:
Родитель
02e5faaf2d
Коммит
4883395701
|
@ -96,6 +96,12 @@ To format the Python and the JavaScript code at once you can use:
|
|||
|
||||
Code formatting is explained in more detail in the following sections.
|
||||
|
||||
To run the required linters on the Python and the Javascript code at once you can use:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
$ make lint
|
||||
|
||||
|
||||
Python code conventions
|
||||
=======================
|
||||
|
@ -113,6 +119,12 @@ Alternatively, you can format your code using:
|
|||
|
||||
$ make black
|
||||
|
||||
We also require Python code to use newer syntax of Python. You can upgrade automatically by running:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
$ make pyupgrade
|
||||
|
||||
Additionally, we use a linter to verify that imports are correct. You can run it with:
|
||||
|
||||
.. code-block:: shell
|
||||
|
@ -126,7 +138,7 @@ ignore that error. Note that in most cases, it is better to fix the issues than
|
|||
Javascript code conventions
|
||||
===========================
|
||||
|
||||
Our Javascript code is automatically formatted using `Prettier <https://prettier.io/docs/en/index.html>_`.
|
||||
Our Javascript code is automatically formatted using `Prettier <https://prettier.io/docs/en/index.html>`_.
|
||||
We enforce that in our Continuous Integration, so you will need to run
|
||||
prettier on your code before sending it for review.
|
||||
|
||||
|
@ -137,7 +149,7 @@ Alternatively, you can format your code using:
|
|||
|
||||
.. code-block:: shell
|
||||
|
||||
$ make prettier
|
||||
$ make prettier
|
||||
|
||||
Additionally, there are linting rules that are defined in our
|
||||
``.eslintrc.js`` file. To run the linter, do:
|
||||
|
@ -208,7 +220,7 @@ Code reviews should review the changes in the context of the rest of the system.
|
|||
Dependencies
|
||||
============
|
||||
|
||||
Direct dependencies for Pontoon are distributed across three files:
|
||||
Direct dependencies for Pontoon are distributed across four files:
|
||||
|
||||
1. ``requirements/default.in``: Running Pontoon in production
|
||||
2. ``requirements/dev.in``: Development
|
||||
|
|
59
Makefile
59
Makefile
|
@ -10,7 +10,7 @@ SITE_URL ?= http://localhost:8000
|
|||
USER_ID?=1000
|
||||
GROUP_ID?=1000
|
||||
|
||||
.PHONY: build build-frontend build-server server-env setup run clean shell ci test test-server test-frontend jest pytest flake8 black prettier check-prettier format types eslint dumpdb loaddb build-tagadmin build-tagadmin-w sync-projects requirements
|
||||
.PHONY: build build-frontend build-server server-env setup run clean shell ci test test-frontend test-server jest pytest format lint types eslint prettier check-prettier flake8 pyupgrade check-pyupgrade black check-black dropdb dumpdb loaddb build-tagadmin build-tagadmin-w sync-projects requirements
|
||||
|
||||
help:
|
||||
@echo "Welcome to Pontoon!\n"
|
||||
|
@ -27,13 +27,17 @@ help:
|
|||
@echo " test Runs both frontend and server test suites"
|
||||
@echo " test-frontend Runs the translate frontend test suite (Jest)"
|
||||
@echo " test-server Runs the server test suite (Pytest)"
|
||||
@echo " flake8 Runs the flake8 style guides on all Python code"
|
||||
@echo " black Runs the black formatter on all Python code"
|
||||
@echo " prettier Runs the prettier formatter on the frontend code"
|
||||
@echo " check-prettier Runs a check for format issues with the prettier formatter"
|
||||
@echo " format Runs formatters for both the frontend and Python code"
|
||||
@echo " lint Runs linters for both the frontend and Python code"
|
||||
@echo " types Runs the tsc compiler to check TypeScript on all frontend code"
|
||||
@echo " eslint Runs a code linter on the JavaScript code"
|
||||
@echo " prettier Runs the prettier formatter on the frontend code"
|
||||
@echo " check-prettier Runs a check for format issues with the prettier formatter"
|
||||
@echo " flake8 Runs the flake8 style guides on all Python code"
|
||||
@echo " pyupgrade Upgrades all Python code to newer syntax of Python"
|
||||
@echo " check-pyupgrade Runs a check for outdated syntax of Python with the pyupgrade formatter"
|
||||
@echo " black Runs the black formatter on all Python code"
|
||||
@echo " check-black Runs a check for format issues with the black formatter"
|
||||
@echo " dropdb Completely remove the postgres container and its data"
|
||||
@echo " dumpdb Create a postgres database dump with timestamp used as file name"
|
||||
@echo " loaddb Load a database dump into postgres, file name in DB_DUMP_FILE"
|
||||
|
@ -68,11 +72,12 @@ run: .frontend-build .server-build
|
|||
clean:
|
||||
rm -f .docker-build .frontend-build .server-build
|
||||
|
||||
test: test-server test-frontend
|
||||
shell:
|
||||
"${DC}" run --rm server //bin/bash
|
||||
|
||||
ci: test-frontend
|
||||
"${DC}" run --rm server //app/docker/server_tests.sh
|
||||
"${DC}" run --rm frontend npm run check-prettier
|
||||
ci: test lint
|
||||
|
||||
test: test-server test-frontend
|
||||
|
||||
test-frontend: jest
|
||||
jest:
|
||||
|
@ -82,18 +87,17 @@ test-server: pytest
|
|||
pytest:
|
||||
"${DC}" run ${run_opts} --rm server pytest --cov-report=xml:pontoon/coverage.xml --cov=. $(opts)
|
||||
|
||||
flake8:
|
||||
"${DC}" run --rm server flake8 pontoon/
|
||||
format: prettier pyupgrade black
|
||||
|
||||
black:
|
||||
"${DC}" run --rm server black pontoon/
|
||||
|
||||
pyupgrade:
|
||||
"${DC}" run --rm server pyupgrade --exit-zero-even-if-changed --py38-plus *.py `find pontoon -name \*.py`
|
||||
lint: types eslint check-prettier flake8 check-pyupgrade check-black
|
||||
|
||||
types:
|
||||
"${DC}" run --rm -w //frontend frontend yarn types
|
||||
|
||||
eslint:
|
||||
"${DC}" run --rm frontend npm run lint
|
||||
"${DC}" run --rm server npm run eslint
|
||||
|
||||
prettier:
|
||||
"${DC}" run --rm frontend npm run prettier
|
||||
"${DC}" run --rm server npm run prettier
|
||||
|
@ -102,20 +106,23 @@ check-prettier:
|
|||
"${DC}" run --rm frontend npm run check-prettier
|
||||
"${DC}" run --rm server npm run check-prettier
|
||||
|
||||
format:
|
||||
make prettier
|
||||
make pyupgrade
|
||||
make black
|
||||
flake8:
|
||||
"${DC}" run --rm server flake8 pontoon/
|
||||
|
||||
eslint:
|
||||
"${DC}" run --rm frontend npm run lint
|
||||
"${DC}" run --rm server npm run eslint
|
||||
pyupgrade:
|
||||
"${DC}" run --rm server pyupgrade --exit-zero-even-if-changed --py38-plus *.py `find pontoon -name \*.py`
|
||||
|
||||
shell:
|
||||
"${DC}" run --rm server //bin/bash
|
||||
check-pyupgrade:
|
||||
"${DC}" run --rm webapp pyupgrade --py38-plus *.py `find pontoon -name \*.py`
|
||||
|
||||
black:
|
||||
"${DC}" run --rm server black pontoon/
|
||||
|
||||
check-black:
|
||||
"${DC}" run --rm webapp black --check pontoon
|
||||
|
||||
dropdb:
|
||||
"${DC}" down --volumes postgresql
|
||||
"${DC}" down --volumes postgresql
|
||||
|
||||
dumpdb:
|
||||
"${DOCKER}" exec -t `"${DC}" ps -q postgresql` pg_dumpall -c -U pontoon > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Run all linting, testing and coverage steps for Pontoon.
|
||||
|
||||
# Failures should cause setup to fail.
|
||||
set -e
|
||||
|
||||
# Make sure we use correct binaries.
|
||||
PYTHON="$(which python)"
|
||||
BLACK="$(which black)"
|
||||
FLAKE8="$(which flake8)"
|
||||
NPM="$(which npm)"
|
||||
PYTEST="$(which pytest)"
|
||||
|
||||
|
||||
echo ""
|
||||
echo "--------------------------------------------------------------------------------------------"
|
||||
echo "Formatting Python code"
|
||||
$BLACK pontoon/ --check
|
||||
|
||||
|
||||
echo ""
|
||||
echo "--------------------------------------------------------------------------------------------"
|
||||
echo "Linting Python code"
|
||||
$FLAKE8 pontoon/
|
||||
|
||||
|
||||
echo ""
|
||||
echo "--------------------------------------------------------------------------------------------"
|
||||
echo "Formatting Javascript code"
|
||||
npm run check-prettier
|
||||
|
||||
|
||||
echo ""
|
||||
echo "Linting JavaScript code"
|
||||
npm run eslint
|
||||
|
||||
|
||||
echo ""
|
||||
echo "--------------------------------------------------------------------------------------------"
|
||||
echo "Collecting static files and bundles"
|
||||
$WEBPACK_BINARY
|
||||
$PYTHON manage.py collectstatic -v0 --noinput
|
||||
|
||||
|
||||
echo ""
|
||||
echo "--------------------------------------------------------------------------------------------"
|
||||
echo "Running Python tests"
|
||||
$PYTEST --cov-append --cov-report=term --cov=.
|
Загрузка…
Ссылка в новой задаче