DEV Community

Xianpeng Shen
Xianpeng Shen

Posted on • Edited on

C/C++ Lint Action | clang-format & clang-tidy

My Workflow

A Github Action for linting C/C++ code integrating clang-tidy and clang-format to collect feedback provided in the form of thread comments and/or annotations.

Submission Category:

Maintainer Must-Haves

Yaml File or Link to Code

GitHub logo cpp-linter / cpp-linter-action

A Github Action for linting C/C++ code integrating clang-tidy and clang-format to collect feedback provided in the form of file-annotations, thread-comments, workflow step-summary, and Pull Request reviews.

C/C++ Linter Action | clang-format & clang-tidy

GitHub release (latest SemVer) GitHub marketplace cpp-linter MkDocs Deploy GitHub

A Github Action for linting C/C++ code integrating clang-tidy and clang-format to collect feedback provided in the form of file-annotations, thread-comments workflow step-summary, and Pull Request reviews (with tidy-review or format-review).

Usage

Create a new GitHub Actions workflow in your project, e.g. at .github/workflows/cpp-linter.yml

The content of the file should be in the following format.

    steps:
      - uses: actions/checkout@v5
      - uses: cpp-linter/cpp-linter-action@v2
        id: linter
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          style: 'file'  # Use .clang-format config file
          tidy-checks: '' # Use .clang-tidy config file
          # only 'update' a single comment in a pull request thread.
          thread-comments: ${{ github.event_name == 'pull_request' && 'update' }}
      - name: Fail fast?!
        if: steps.linter.outputs.checks-failed > 0
        run: exit 1
Enter fullscreen mode Exit fullscreen mode

For all explanations of our available input parameters and…

cpp-linter.yml

name: cpp-linter

on:
  pull_request:
    types: [opened, reopened]  # let PR-synchronize events be handled by push events
  push:

jobs:
  cpp-linter:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: cpp-linter/cpp-linter-action@v2
        id: linter
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          style: file

      - name: Fail fast?!
        if: steps.linter.outputs.checks-failed > 0
        run: |
          echo "Some files failed the linting checks!"
        # for actual deployment
        # run: exit 1
Enter fullscreen mode Exit fullscreen mode

Additional Resources / Info

https://cpp-linter.github.io/cpp-linter-action/

Example

Annotations

annotations-clang-format

annotations-clang-tidy

Thread Comment

Thread Comment

Top comments (0)