From 356dfa27c2bda4b973c3973f6e954e16512c7e6d Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sat, 28 May 2022 14:20:46 +0200 Subject: [PATCH] ci: add .pre-commit-config.yaml and .flake8 config --- .flake8 | 15 +++++++++ .pre-commit-config.yaml | 74 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 .flake8 create mode 100644 .pre-commit-config.yaml diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..8977cf827 --- /dev/null +++ b/.flake8 @@ -0,0 +1,15 @@ +# flake8 is a Python linting tool run by pre-commit as declared by our +# pre-commit-config.yaml file. +# +# This configuration is compatible with the autoformatter tool black, and +# further relaxed to not bug us with too small details. +# +# flake8 configuration reference: +# https://flake8.pycqa.org/en/latest/user/configuration.html +# +[flake8] +max-line-length = 88 +extend-ignore = C, E, W + +# Adjustments to linting +builtins = c diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..d2c68edb4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,74 @@ +# pre-commit is a tool to perform a predefined set of tasks manually and/or +# automatically before git commits are made. +# +# Config reference: https://pre-commit.com/#pre-commit-configyaml---top-level +# +# Common tasks +# +# - Run on all files: pre-commit run --all-files +# - Register git hooks: pre-commit install --install-hooks +# +repos: + # Autoformat: Python code, syntax patterns are modernized + - repo: https://github.com/asottile/pyupgrade + rev: v2.32.1 + hooks: + - id: pyupgrade + args: + - --py37-plus + + # Autoformat: Python code + - repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + args: + # --target-version should be all supported versions + - --target-version=py37 + - --target-version=py38 + - --target-version=py39 + - --target-version=py310 + + # Autoformat: Python code + - repo: https://github.com/pycqa/isort + rev: 5.10.1 + hooks: + - id: isort + args: + - --profile=black + + # Autoformat: js, html, markdown, yaml, json + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.6.2 + hooks: + - id: prettier + exclude_types: + # These are excluded initially as pre-commit was added but can + # absolutely be enabled later. If so, we should consider having a + # separate run of pre-commit where we configure a line spacing of 4 + # for these file formats. + - html + - javascript + - css + + # Misc autoformatting and linting + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 + hooks: + - id: end-of-file-fixer + exclude_types: [svg, css, json] + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: requirements-txt-fixer + # These files have requirements.in files associated with them, and are + # generated by pip-compile. + # + exclude: > + images/minesweeper/requirements.txt| + images/federation-redirect/requirements.txt + + # Lint: Python code + - repo: https://github.com/PyCQA/flake8 + rev: "4.0.1" + hooks: + - id: flake8