--The backend (Flask) code of the project you are participating in has had a hard time (still ongoing) because Linter and formatter have not been introduced.
――Do you want to lint & format with Githook? ?? ?? ?? ?? ??
--The code written at the beginning of the project ignores pep8 gun and introduces lint, an error occurs. ――I want to apply autofix at once, but the difference is too large to review. ――I want to refactor the whole amount, but there is no man-hours, and the test code does not seem to be enough
--Lint & format is applied to the newly created code.
--The existing code remains as it is
--Review the test code of the existing code and implement it additionally so that it can be refactored at any time.
--Lint is applied with hook. The format is decided by the human being (a measure of bitterness).
--Existing is forced to commit with git commit --no-verify
black hogehoge.py
flake8 hogehoge.py
by specifying the file)black hogehoge.py --diff
and fix it by hand. (Lintflake8 hogehoge.py
by file specification)git commit --no-verify
linter uses flake8.
pip install flake8
.flake8
in the project root).flake8
[flake8]
ignore = E203, E266, E501, W503, F403, F401
max-line-length = 79
max-complexity = 18
select = B,C,E,F,W,T4,B9
--Honestly, max-line-length <80 is too few in modern times ――E203, W503, W504 are required for igonore because of the relationship with black. Other than that, as appropriate -Look here
formatter uses black
pip install black
pyproject.toml
in the project root)pyproject.toml
[tool.black]
line-length = 79
include = '\.pyi?$'
exclude = '''
/(
\.git
)
'''
――I'm surprised when I sometimes get an error even though I use formatr.
Use pre-commit to set the hook.
pip install pre-commit
.pre-commit-config.yaml
in the project root)repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: flake8
――Because of the introduction period of the tool, manual work is included. Change little by little --Lint and formater should be entered first. The minimum rules (pep8) should be included ――Change the rules when you find it difficult to write --If the test code is correct, there is no problem with the existing ones.
Recommended Posts