Giter Club home page Giter Club logo

clang-format-lint-action's Introduction

clang-format lint action

This action checks if the source code matches the .clang-format file.

Inputs

source

Where the source files are located.
Default: '.' (current folder)
Example: './src' or 'src test examples' for multiple.

exclude

What folder should be excluded from format checking.
Default: 'none'
Example: './third_party' or 'third_party exclude' for multiple.

Multiple exclude rules can also be put in a .clang-format-ignore file, which also supports comments.
Example:

# ignore third_party code from clang-format checks
src/third_party/*
src/ignored/*

extensions

What filename extensions should be used for format checking.
Default: 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx'
Example: 'cpp,h'

clangFormatVersion

What clang-format version should be used.
Available version are from 5 to 11.
Default: 9
Example: 11

style

Style to use.
Results in the appropriate --style parameter.
Default: file
Example: chromium

inplace

Whether to change the files on the disk instead of writing to disk.
This is the same as clang-format -i
Default: False\

You probably want to pair this with a GitHub action (such as EndBug/add-and-commit) to commit the changed files. For example:

name: Run clang-format Linter

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - uses: DoozyX/[email protected]
      with:
        source: '.'
        exclude: './lib'
        extensions: 'h,cpp,c'
        clangFormatVersion: 11
        inplace: True
    - uses: EndBug/add-and-commit@v4
      with:
        author_name: Clang Robot
        author_email: [email protected]
        message: 'Committing clang-format changes'
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Example usage

name: test-clang-format

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - uses: DoozyX/[email protected]
      with:
        source: '.'
        exclude: './third_party ./external'
        extensions: 'h,cpp'
        clangFormatVersion: 11
        style: chromium

Run locally

Install Docker and then run:

docker build -t clang-format-lint github.com/DoozyX/clang-format-lint-action

When the image is built, run the linting:

docker run -it --rm --workdir /src -v $(pwd):/src clang-format-lint \
    --clang-format-executable /clang-format/clang-format9 -r --exclude .git .

clang-format-lint-action's People

Contributors

doozyx avatar flamefire avatar hatstand avatar johnboiles avatar jsharpe avatar sbeyer avatar schra avatar wenzeslaus avatar wmmc88 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.