Skip to content

Commit

Permalink
[format] Add pre-commit check (#438)
Browse files Browse the repository at this point in the history
* pre-commit check add

* update README and precommit check

* update README and precommit check and pre-commit install

* update README and precommit check and pre-commit install

---------

Co-authored-by: LiuQun <[email protected]>
  • Loading branch information
LIUQyou and LiuQun authored Jan 6, 2025
1 parent 61a4c5b commit 9e9ea47
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
59 changes: 59 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.3 # Use the version of clang-format you have installed
hooks:
- id: clang-format
name: clang-format C++ code
files: \.(cpp|hpp|cc|cxx|h|c|hxx)$
args: [--style=llvm] # You can set your preferred style here

# - repo: https://github.com/pocc/pre-commit-hooks
# rev: v1.3.5 # Use the latest stable version
# hooks:
# - id: clang-tidy
# name: clang-tidy C++ code
# files: \.(cpp|hpp|cc|cxx|h|c|hxx)$
# args:
# - --quiet
# - --checks=*,-clang-diagnostic-*,-clang-analyzer-*
# - --extra-arg=-x
# - --extra-arg=c++
# - --extra-arg=-std=c++17
# - --warnings-as-errors=*
# - --extra-arg=-I.

- repo: https://github.com/psf/black
rev: 24.10.0 # Use the latest stable version
hooks:
- id: black
language_version: python3.10

# a comprehensive tool for checking the style and quality of Python code.
# It combines three popular Python tools:
# PyFlakes: Checks for logical errors in the code.
# pycodestyle (formerly known as pep8): Checks for adherence to the PEP 8 style guide.
# McCabe Complexity Checker: Measures the complexity of your code.
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0 # Set the rev to match the desired flake8 version
hooks:
- id: flake8
args:
- --max-line-length=88 # Adjust as per your style guide
- --ignore=F821,F403,F405,F401,W503,E203,E402,E401,W605,E712,E711,F841
# W503: Line break before binary operator
# E203: Whitespace before colon
# E402: Module level import not at top of file
# E401: Multiple imports on one line
# W605: Invalid escape sequence
# E712: Comparison to True/False
# E711: Comparison to None
# F841: Unused variable

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0 # Updated to the latest version
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-merge-conflict
- id: check-yaml
- id: check-added-large-files
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ This program should be a drop-in replacement for `mlir-lsp-server`, supporting n

After modification, your editor should have correct completion and error prompts for new dialects such as `rvv` and `gemmini`.

### pre-commit checks

The .pre-commit-config.yaml file checks code format and style on each commit, using tools such as clang-format, black, and flake8. You can also run these checks without committing by using "pre-commit run --all-files". This ensures consistent coding standards and prevents common errors before pushing changes.

To get started, you should install pre-commit (e.g., pip install pre-commit) and verify that clang-format, black, and flake8 are available. On Linux, you can use your package manager for clang-format, and pip for Python tools. If you need to revert any unwanted formatting changes, you can use "git stash" or "git restore ." (for all files) or "git restore <file>" (for a specific file), or revert the commit through your Git history.

## Examples

The purpose of the examples is to give users a better understanding of how to use the passes and the interfaces in buddy-mlir. Currently, we provide three types of examples.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ PyYAML
certifi
idna
diffusers

pre-commit

0 comments on commit 9e9ea47

Please sign in to comment.