Quellcode durchsuchen

update pre-commit

gaotingquan vor 1 Jahr
Ursprung
Commit
dca46ea548
2 geänderte Dateien mit 52 neuen und 16 gelöschten Zeilen
  1. 20 0
      .clang_format.hook
  2. 32 16
      .pre-commit-config.yaml

+ 20 - 0
.clang_format.hook

@@ -0,0 +1,20 @@
+#!/bin/bash
+set -e
+
+readonly VERSION="13.0.0"
+
+version=$(clang-format -version)
+
+if ! [[ $(python -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1$2}') -ge 36 ]]; then
+    echo "clang-format installation by pip need python version great equal 3.6,
+          please change the default python to higher version."
+    exit 1
+fi
+
+if ! [[ $version == *"$VERSION"* ]]; then
+    # low version of pip may not have the source of clang-format whl
+    pip install --upgrade pip
+    pip install clang-format==13.0.0
+fi
+
+clang-format $@

+ 32 - 16
.pre-commit-config.yaml

@@ -1,28 +1,44 @@
 repos:
--   repo: https://github.com/cuicheng01/mirrors-yapf.git
-    rev: 0d79c0c469bab64f7229c9aca2b1186ef47f0e37
-    hooks:
-    -   id: yapf
-        files: \.py$
 -   repo: https://github.com/pre-commit/pre-commit-hooks
-    rev: a11d9314b22d8f8c7556443875b731ef05965464
+    rev: v4.6.0
     hooks:
+    -   id: check-added-large-files
+        args: ['--maxkb=512']
+    -   id: check-case-conflict
     -   id: check-merge-conflict
     -   id: check-symlinks
     -   id: detect-private-key
-        files: (?!.*paddle)^.*$
     -   id: end-of-file-fixer
-        files: \.md$
     -   id: trailing-whitespace
-        files: \.md$
+        files: \.(md|c|cc|cxx|cpp|cu|h|hpp|hxx|py)$
 -   repo: https://github.com/Lucas-C/pre-commit-hooks
-    rev: v1.0.1
+    rev: v1.5.1
     hooks:
-    -   id: forbid-crlf
-        files: \.md$
     -   id: remove-crlf
-        files: \.md$
-    -   id: forbid-tabs
-        files: \.md$
     -   id: remove-tabs
-        files: \.md$
+        files: \.(md|c|cc|cxx|cpp|cu|h|hpp|hxx|py)$
+-   repo: local
+    hooks:
+    -   id: clang-format
+        name: clang-format
+        description: Format files with ClangFormat
+        entry: bash .clang_format.hook -i
+        language: system
+        files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|cuh|proto)$
+# For Python files
+-   repo: https://github.com/psf/black.git
+    rev: 24.4.2
+    hooks:
+    -   id: black
+        files: (.*\.(py|pyi|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
+
+# Flake8
+-   repo: https://github.com/pycqa/flake8
+    rev: 7.0.0
+    hooks:
+    -   id: flake8
+        args:
+            - --count
+            - --select=E9,F63,F7,F82,E721
+            - --show-source
+            - --statistics