瀏覽代碼

Add ESLint, Prettier, and Stylelint config files

Sage Abdullah 2 年之前
父節點
當前提交
41918f6a2c
共有 8 個文件被更改,包括 104 次插入3 次删除
  1. 3 0
      .eslintignore
  2. 24 0
      .eslintrc
  3. 24 1
      .pre-commit-config.yaml
  4. 9 0
      .prettierignore
  5. 14 0
      .prettierrc
  6. 4 0
      .stylelintignore
  7. 11 0
      .stylelintrc
  8. 15 2
      Makefile

+ 3 - 0
.eslintignore

@@ -0,0 +1,3 @@
+node_modules
+venv
+.venv

+ 24 - 0
.eslintrc

@@ -0,0 +1,24 @@
+{
+  "extends": [
+    "eslint:recommended"
+  ],
+  "parserOptions": {
+    "ecmaVersion": 9
+  },
+  "env": {
+    "browser": true
+  },
+  "rules": {
+    // allow no lines between single line members (e.g. static declarations)
+    "lines-between-class-members": [
+      "error",
+      "always",
+      {
+        "exceptAfterSingleLine": true
+      }
+    ],
+    // note you must disable the base rule as it can report incorrect errors
+    "no-use-before-define": "off",
+    "no-underscore-dangle": "error"
+  }
+}

+ 24 - 1
.pre-commit-config.yaml

@@ -7,7 +7,7 @@ repos:
     hooks:
       - id: black
         language_version: python3
-        args: ["--target-version", "py37"]
+        args: ['--target-version', 'py37']
   - repo: https://github.com/timothycrosley/isort
     # isort config is in setup.cfg
     rev: 5.6.4
@@ -25,3 +25,26 @@ repos:
     rev: v1.4.13
     hooks:
       - id: djhtml
+  - repo: https://github.com/pre-commit/mirrors-prettier
+    rev: v2.5.1
+    hooks:
+      - id: prettier
+        types_or: [css, javascript, json, yaml]
+  - repo: https://github.com/pre-commit/mirrors-eslint
+    rev: v8.8.0
+    hooks:
+      - id: eslint
+        types: [file]
+        files: \.(js)$
+        args: [--report-unused-disable-directives]
+        additional_dependencies:
+          - eslint@8.8.0
+  - repo: https://github.com/thibaudcolas/pre-commit-stylelint
+    rev: v14.2.0
+    hooks:
+      - id: stylelint
+        files: \.css$
+        additional_dependencies:
+          - stylelint@14.9.1
+          - stylelint-config-standard@26.0.0
+          - stylelint-config-prettier@9.0.3

+ 9 - 0
.prettierignore

@@ -0,0 +1,9 @@
+# Irrelevant files ignored for performance reasons.
+node_modules
+venv
+.venv
+*.min.css
+# File types which Prettier supports but we don’t want auto-formatting.
+*.md
+# Files which contain incompatible syntax.
+*.html

+ 14 - 0
.prettierrc

@@ -0,0 +1,14 @@
+{
+  "arrowParens": "always",
+  "bracketSameLine": false,
+  "bracketSpacing": true,
+  "embeddedLanguageFormatting": "auto",
+  "endOfLine": "lf",
+  "htmlWhitespaceSensitivity": "css",
+  "printWidth": 80,
+  "proseWrap": "preserve",
+  "quoteProps": "consistent",
+  "semi": true,
+  "singleQuote": true,
+  "trailingComma": "all"
+}

+ 4 - 0
.stylelintignore

@@ -0,0 +1,4 @@
+node_modules
+venv
+.venv
+*.min.css

+ 11 - 0
.stylelintrc

@@ -0,0 +1,11 @@
+{
+  "extends": ["stylelint-config-standard", "stylelint-config-prettier"],
+  "rules": {
+    "no-descending-specificity": null,
+    "custom-property-pattern": "^([a-z][a-z0-9]*)(-{1,2}[a-z0-9]+)*$",
+    "selector-class-pattern": [
+      "^[a-z]+[0-9]{0,2}(-[a-z0-9]+)*(__[a-z0-9]+(-[a-z0-9]+)*)?(--[a-z0-9]+(-[a-z0-9]+)*)?$",
+      { "resolveNestedSelectors": true }
+    ]
+  }
+}

+ 15 - 2
Makefile

@@ -4,14 +4,27 @@ 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:
+lint-server:
 	black --target-version py37 --check --diff .
 	flake8
 	isort --check-only --diff .
 	curlylint --parse-only bakerydemo
 	git ls-files '*.html' | xargs djhtml --check
 
-format:
+lint-client:
+	npm run lint:css --silent
+	npm run lint:js --silent
+	npm run lint:format --silent
+
+lint: lint-server lint-client
+
+format-server:
 	black --target-version py37 .
 	isort .
 	git ls-files '*.html' | xargs djhtml -i
+
+format-client:
+	npm run format
+	npm run fix:js
+
+format: format-server format-client