Skip to content

Commit 1269361

Browse files
authored
Migrate to pre-commit (#366)
replace the custom check style script with pre-commit. Fixes the long-existing problem of clang-format inconsistencies, by installing a fixed version of clang-format from pip and adds checks for python and rust. Only checks changed files for the start.
1 parent a94ea15 commit 1269361

File tree

7 files changed

+63
-101
lines changed

7 files changed

+63
-101
lines changed

.github/workflows/pre-commit.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
branches: [ master ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-22.04
11+
12+
steps:
13+
- uses: actions/checkout@v5
14+
with:
15+
# requites to grab the history of the PR
16+
fetch-depth: 0
17+
- uses: actions/setup-python@v6
18+
with:
19+
python-version: '3.11'
20+
- uses: pre-commit/action@v3.0.1
21+
with:
22+
extra_args: --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}

.github/workflows/style.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
exclude: |
2+
(?x)^(
3+
keyvi/3rdparty/.*
4+
)$
5+
repos:
6+
- repo: https://github.com/pre-commit/mirrors-clang-format
7+
rev: v21.1.2
8+
hooks:
9+
- id: clang-format
10+
exclude: '^(.*/3rdparty/.*)'
11+
- repo: https://github.com/cpplint/cpplint
12+
rev: 2.0.2
13+
hooks:
14+
- id: cpplint
15+
exclude: '^(.*/3rdparty/.*)'
16+
- repo: local
17+
hooks:
18+
- id: cargo-fmt
19+
name: cargo-fmt
20+
entry: cargo fmt --manifest-path rust/Cargo.toml -- --check
21+
language: system
22+
pass_filenames: false
23+
types:
24+
- rust
25+
- repo: https://github.com/pre-commit/pre-commit-hooks
26+
rev: v6.0.0
27+
hooks:
28+
- id: check-toml
29+
- id: check-yaml
30+
- id: end-of-file-fixer
31+
- id: trailing-whitespace
32+
- repo: https://github.com/charliermarsh/ruff-pre-commit
33+
rev: "v0.14.0"
34+
hooks:
35+
- id: ruff-check
36+
- id: ruff-format

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ You will need to fork the repository and clone it to your local machine. See [gi
1111

1212
### Submitting your changes
1313

14-
Once you successfully tested you are ready to submit for review. Note that some parts have to fulfill certain rules (e.g. formating), please have a look and do the changes accordingly. We will not do it for you.
14+
Once you successfully tested you are ready to submit for review. Note that some parts have to fulfill certain rules (e.g. formating), please have a look and do the changes accordingly. All checks must pass.
1515

1616
#### Submit a pull request
1717

@@ -30,6 +30,6 @@ Please be as reviewer friendly as possible:
3030

3131
By contributing to the project:
3232

33-
- You agree to publish your work under the licence of the project: Apache 2.0
33+
- You agree to publish your work under the licence of the project: Apache 2.0
3434
- You represent and warrant that you are the exclusive owner of the Copyright in the Contribution
3535
- If your contribution contains 3rdparty code you provide details about licence and restriction

keyvi/README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,3 @@ to build on the commandline (in addition cmake creates Visual Studio configs):
6666
```
6767
cmake --build . --config Release
6868
```
69-
70-
## Coding Rules
71-
72-
The cpp part of keyvi has to pass the [https://pypi.python.org/pypi/cpplint](cpplint) checks as well as [https://clang.llvm.org/docs/ClangFormat.html](clang-format) (5.0.0 at the moment, defined by our travis CI configuration).
73-
74-
The configuration of both tools is part of the project. You can check your changes against the config using the `check-style.sh` script. For your convenience consider using a plugin for your IDE of choice (e.g. CppStyle for Eclipse).
75-
76-
Formatting is not done automatically for you but code neads to be cleanly pushed.
77-
78-
The check must pass for all changed, including new, files.

keyvi/check-style.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

keyvi/include/keyvi/dictionary/match.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* * keyvi - A key value store.
1+
/* keyvi - A key value store.
22
*
33
* Copyright 2015 Hendrik Muhs<hendrik.muhs@gmail.com>
44
*
@@ -234,9 +234,7 @@ struct Match {
234234
*
235235
* @param value
236236
*/
237-
void SetRawValue(const std::string& value) {
238-
raw_value_ = value;
239-
}
237+
void SetRawValue(const std::string& value) { raw_value_ = value; }
240238

241239
private:
242240
size_t start_ = 0;
@@ -254,9 +252,7 @@ struct Match {
254252
template <class MatcherT, class DeletedT>
255253
friend match_t index::internal::FirstFilteredMatch(const MatcherT&, const DeletedT&);
256254

257-
fsa::automata_t& GetFsa() {
258-
return fsa_;
259-
}
255+
fsa::automata_t& GetFsa() { return fsa_; }
260256
};
261257

262258
} /* namespace dictionary */

0 commit comments

Comments
 (0)