DEV Community

Peter Shen
Peter Shen

Posted 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 shenxianpeng / cpp-linter-action

Improved C/C++ Lint Action: Automatically checks push & pull request changes with clang-format & clang-tidy, then posts a comment with faulty results.

icon

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

GitHub release (latest SemVer) cpp-linter GitHub Dev Docs Status open repo in gitpod

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.

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.

# Workflow syntax:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
name: cpp-linter

on:
  push:
    paths-ignore: "docs/**"
  pull_request:
    paths-ignore: "docs/**"

jobs:
  cpp-linter:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: shenxianpeng/cpp-linter-action@master
        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

Optional Inputs

style

  • Description: The style rules to use. Set this…

cpp-linter.yml

name: cpp-linter

on:
  push:
    paths-ignore: "docs/**"
  pull_request:
    paths-ignore: "docs/**"

jobs:
  cpp-linter:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: shenxianpeng/cpp-linter-action@master
        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

Example

Thread Comment

Thread Comment

Annotations
Annotations

Discussion (0)