diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 000000000..5c65ced4b --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,22 @@ +name: pre-commit + +on: + pull_request: + branches: [ master ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v5 + with: + # requites to grab the history of the PR + fetch-depth: 0 + - uses: actions/setup-python@v6 + with: + python-version: '3.11' + - uses: pre-commit/action@v3.0.1 + with: + extra_args: --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }} diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml deleted file mode 100644 index 4c8724f60..000000000 --- a/.github/workflows/style.yml +++ /dev/null @@ -1,38 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: check style - -# Controls when the action will run. -on: - # Triggers the workflow on push or pull request events but only for the master branch - push: - pull_request: - branches: [ master ] - - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-22.04 - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v5 - with: - fetch-depth: 0 # fetch all history so multiple commits can be scanned - - name: install deps - run: | - sudo apt-get update - sudo apt-get install -y clang-format-14 - sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-14 1000 - - uses: BSFishy/pip-action@v1 - with: - packages: cpplint - - name: run the style script - env: - GITHUB_PUSH_BASE_SHA: ${{ github.event.base }} - GITHUB_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }} - run: | - export PATH="$HOME/.local/bin:$PATH" - ./keyvi/check-style.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..5407721e6 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,36 @@ +exclude: | + (?x)^( + keyvi/3rdparty/.* + )$ +repos: + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v21.1.2 + hooks: + - id: clang-format + exclude: '^(.*/3rdparty/.*)' + - repo: https://github.com/cpplint/cpplint + rev: 2.0.2 + hooks: + - id: cpplint + exclude: '^(.*/3rdparty/.*)' + - repo: local + hooks: + - id: cargo-fmt + name: cargo-fmt + entry: cargo fmt --manifest-path rust/Cargo.toml -- --check + language: system + pass_filenames: false + types: + - rust + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-toml + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: "v0.14.0" + hooks: + - id: ruff-check + - id: ruff-format diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cb9360a56..3a7e77e4e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ You will need to fork the repository and clone it to your local machine. See [gi ### Submitting your changes -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. +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. #### Submit a pull request @@ -30,6 +30,6 @@ Please be as reviewer friendly as possible: By contributing to the project: -- You agree to publish your work under the licence of the project: Apache 2.0 +- You agree to publish your work under the licence of the project: Apache 2.0 - You represent and warrant that you are the exclusive owner of the Copyright in the Contribution - If your contribution contains 3rdparty code you provide details about licence and restriction diff --git a/keyvi/README.md b/keyvi/README.md index 6a480ab13..07ece409d 100644 --- a/keyvi/README.md +++ b/keyvi/README.md @@ -66,13 +66,3 @@ to build on the commandline (in addition cmake creates Visual Studio configs): ``` cmake --build . --config Release ``` - -## Coding Rules - -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). - -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). - -Formatting is not done automatically for you but code neads to be cleanly pushed. - -The check must pass for all changed, including new, files. diff --git a/keyvi/check-style.sh b/keyvi/check-style.sh deleted file mode 100755 index 13ae3a6cb..000000000 --- a/keyvi/check-style.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -clang-format -version - -if [ -n "${GITHUB_PULL_REQUEST_BASE_SHA}" ]; then -commit_range="${GITHUB_PULL_REQUEST_BASE_SHA}...${GITHUB_SHA}" -elif [ -n "${GITHUB_PUSH_BASE_SHA}" ]; then -commit_range="${GITHUB_PUSH_BASE_SHA}...${GITHUB_SHA}" -else -commit_range="upstream/master...HEAD" -fi - -infiles=`git diff --name-only --diff-filter=ACMRT $(echo ${commit_range} | sed 's/\.//') | grep -v "3rdparty" | grep -E "\.(cpp|h)$"` - -clang_format_files=() -cpplint_files=() - -for file in ${infiles}; do - fqfile=`git rev-parse --show-toplevel`/${file} - echo "Checking: ${file}" - if ! cmp -s ${fqfile} <(clang-format ${fqfile}); then - clang_format_files+=("${file}") - fi - if ! cpplint --quiet ${fqfile}; then - cpplint_files+=("${file}") - fi -done - -rc=0 - -if [ -n "${clang_format_files}" ]; then -echo "Format error (clang-format) within the following files:" -printf "%s\n" "${clang_format_files[@]}" -rc=1 -fi - - -if [ -n "${cpplint_files}" ]; then -echo "Cpplint error within the following files:" -printf "%s\n" "${cpplint_files[@]}" -rc=1 -fi - -exit ${rc} diff --git a/keyvi/include/keyvi/dictionary/match.h b/keyvi/include/keyvi/dictionary/match.h index f31b38e4a..db9516e99 100644 --- a/keyvi/include/keyvi/dictionary/match.h +++ b/keyvi/include/keyvi/dictionary/match.h @@ -1,4 +1,4 @@ -/* * keyvi - A key value store. +/* keyvi - A key value store. * * Copyright 2015 Hendrik Muhs * @@ -234,9 +234,7 @@ struct Match { * * @param value */ - void SetRawValue(const std::string& value) { - raw_value_ = value; - } + void SetRawValue(const std::string& value) { raw_value_ = value; } private: size_t start_ = 0; @@ -254,9 +252,7 @@ struct Match { template friend match_t index::internal::FirstFilteredMatch(const MatcherT&, const DeletedT&); - fsa::automata_t& GetFsa() { - return fsa_; - } + fsa::automata_t& GetFsa() { return fsa_; } }; } /* namespace dictionary */