Jelajahi Sumber

Update and add linting config to better match Wagtail

Sage Abdullah 2 tahun lalu
induk
melakukan
b45934ce83
4 mengubah file dengan 79 tambahan dan 2 penghapusan
  1. 27 0
      .editorconfig
  2. 27 0
      .pre-commit-config.yaml
  3. 17 0
      Makefile
  4. 8 2
      setup.cfg

+ 27 - 0
.editorconfig

@@ -0,0 +1,27 @@
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+trim_trailing_whitespace = true
+indent_style = space
+
+[Makefile]
+indent_style = tab
+
+[*.py]
+charset = utf-8
+indent_size = 4
+max_line_length = 120
+
+[*.js]
+charset = utf-8
+
+[*.{html,rst,md}]
+indent_size = 4
+
+[*.{js,ts,tsx,json,yml,yaml,css,scss}]
+indent_size = 2
+
+[*.md]
+trim_trailing_whitespace = false

+ 27 - 0
.pre-commit-config.yaml

@@ -0,0 +1,27 @@
+default_language_version:
+  node: system
+  python: python3
+repos:
+  - repo: https://github.com/psf/black
+    rev: 22.3.0
+    hooks:
+      - id: black
+        language_version: python3
+        args: ["--target-version", "py37"]
+  - repo: https://github.com/timothycrosley/isort
+    # isort config is in setup.cfg
+    rev: 5.6.4
+    hooks:
+      - id: isort
+  - repo: https://gitlab.com/pycqa/flake8
+    # flake8 config is in setup.cfg
+    rev: 3.8.4
+    hooks:
+      - id: flake8
+        additional_dependencies:
+          - flake8-comprehensions
+          - flake8-assertive
+  - repo: https://github.com/rtts/djhtml
+    rev: v1.4.13
+    hooks:
+      - id: djhtml

+ 17 - 0
Makefile

@@ -0,0 +1,17 @@
+.PHONY: lint format
+
+help:
+	@echo "lint - check style with black, flake8, sort python with isort, and indent html"
+	@echo "format - enforce a consistent code style across the codebase and sort python files with isort"
+
+lint:
+	black --target-version py37 --check --diff .
+	flake8
+	isort --check-only --diff .
+	curlylint --parse-only bakerydemo
+	git ls-files '*.html' | xargs djhtml --check
+
+format:
+	black --target-version py37 .
+	isort .
+	git ls-files '*.html' | xargs djhtml -i

+ 8 - 2
setup.cfg

@@ -1,4 +1,10 @@
 [flake8]
 max-line-length=120
-exclude=migrations
-ignore=F405,W503
+exclude=venv,.venv,bakerydemo/settings/local.py
+ignore=E501,F405,W503
+
+[isort]
+profile=black
+skip=migrations,.git,__pycache__,LC_MESSAGES,venv,.venv
+blocked_extensions=rst,html,js,svg,txt,css,scss,png,snap,ts,tsx
+default_section=THIRDPARTY