Turn clang-tidy warnings and fixes to comments in your pull request

Overview

clang-tidy pull request comments

clang-tidy-8 support clang-tidy-9 support clang-tidy-10 support clang-tidy-11 support clang-tidy-12 support

A GitHub Action to post clang-tidy warnings and suggestions as review comments on your pull request.

action preview

What

platisd/clang-tidy-pr-comments is a GitHub Action that utilizes the exported fixes of clang-tidy for your C++ project and posts them as code review comments in the related pull request.

If clang-tidy has a concrete recommendation on how you should modify your code to fix the issue that's detected, then it will be presented as a suggested change that can be committed directly. Alternatively, the offending line will be highlighted along with a description of the warning.

The GitHub Action can be configured to request changes if clang-tidy warnings are found or merely leave a comment without blocking the pull request from being merged. It should fail only if it has been misconfigured by you, due to a bug (please contact me if that's the case) or the GitHub API acting up.

Please note the following:

  • It will not run clang-tidy for you. You are responsible for doing that and then supply the Action with the path to your generated report (see examples below).
    Specifically, the YAML report that includes the fixes is generated via the -export-fixes argument to the run-clang-tidy utility script. Alternatively, you may use --export-fixes with clang-tidy itself and then, in both cases, specify the path where you would like the report to be exported.
    The very same path should be supplied to the GitHub Action.
  • It will only comment on files and lines changed in the pull request. This is due to GitHub not allowing comments on other files outside the pull request diff. This means that there may be more warnings in your project. Make sure you fix them before starting to use this Action to ensure new warnings will not be introduced in the future.
  • Having the Action leave comments on every update of the pull request may result in spam. Specifically, existing comments are not taken into consideration and will be repeated every time the Action is triggered, as long as the violation has not been amended. If you see this becoming an issue, consider triggering it manually with a comment instead (see example below).

Supported clang-tidy versions

YAML files containing generated fixes by the following clang-tidy versions are currently supported:

  • clang-tidy-8
  • clang-tidy-9
  • clang-tidy-10
  • clang-tidy-11
  • clang-tidy-12

How

Since this action comments on files changed in pull requests, naturally, it can be only run on pull_request events. That being said, if it happens to be triggered in a different context, e.g. a push event, it will not run and fail softly by returning a success code.

A basic configuration for the platisd/clang-tidy-pr-comments action can be seen below:

name: Static analysis

on: pull_request

jobs:
  clang-tidy:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/[email protected]
      - name: Build project and/or unit tests
        run: ./your-build-script.sh
      - name: Run clang-tidy
        run: ./your-clang-tidy-script.sh --fixes-path fixes.yaml
      - name: Run clang-tidy-pr-comments action
        uses: platisd/[email protected]
        with:
          # The GitHub token (or a personal access token)
          github_token: ${{ secrets.GITHUB_TOKEN }}
          # The path to the clang-tidy fixes generated previously
          clang_tidy_fixes: fixes.yaml
          # Optionally set to true if you want the Action to request
          # changes in case warnings are found
          request_changes: true
          # Optionally set the number of comments per review
          # to avoid GitHub API timeouts for heavily loaded
          # pull requests
          suggestions_per_comment: 10

If you want to trigger the Action manually, i.e. by leaving a comment with a particular keyword in the pull request, then you can try the following:

name: Static analysis

# Don't trigger it on pull_request events but issue_comment instead
on: issue_comment

jobs:
  clang-tidy:
    # Trigger the job only when someone comments: run_clang_tidy
    if: github.event.issue.pull_request && contains(github.event.comment.body, 'run_clang_tidy')
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/[email protected]
      - name: Build project and/or unit tests
        run: ./your-build-script.sh
      - name: Run clang-tidy
        run: ./your-clang-tidy-script.sh --fixes-path fixes.yaml
      - name: Run clang-tidy-pr-comments action
        uses: platisd/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          clang_tidy_fixes: fixes.yaml
Comments
  • How to contribute to this project?

    How to contribute to this project?

    Hello, thank you for developing this project! Although I just started to take a look at this, it looks so nice. :smile:

    So I'd like to contribute to this project and I believe I can contribute mainly 3 points. How should I contribute? Could I send PRs for these?

    1. Release Management

    By adding CI scripts like this, if I push a tag, image

    this CI will run, https://github.com/kenji-miyake/clang-tidy-pr-comments/runs/5168564498?check_suite_focus=true

    and a new release is prepared, image

    and after I publish it, the major version tag is created as well. https://github.com/kenji-miyake/clang-tidy-pr-comments/runs/5168578795?check_suite_focus=true image

    Why doing so is here: https://github.com/actions/toolkit/blob/2f164000dcd42fb08287824a3bc3030dbed33687/docs/action-versioning.md

    2. Other CI scripts

    It seems some files are not properly formatted. image

    By installing pre-commit.ci and other tools, this can be improved and it will reduce your maintenance cost.

    Please see this project for more details: https://github.com/autowarefoundation/autoware-github-actions/

    3. Bug investigations/fixes

    While I'm testing this action, it seems I caught a bug. I can investigate the cause and fix it. https://github.com/kenji-miyake/autoware.universe/runs/5168447074?check_suite_focus=true image

    -> clang_tidy_fixes should be under the checked-out workspace?

    opened by kenji-miyake 16
  • Error appending replacements in multi-line comments

    Error appending replacements in multi-line comments

    With #38, suggestions including multiple replacements where tried to be tackled. However, right now, replacements text is only concatenated and the length is being summed, which is a bit too simple, resulting in potentially unusable comments.

    Consider the following example: Screenshot 2022-12-12 at 16 50 26

    Diagnostics:
    - BuildDirectory: /home/runner/work/orbitprofiler/orbitprofiler/build/src/DataViews
      DiagnosticMessage:
        FileOffset: 1269
        FilePath: /home/runner/work/orbitprofiler/orbitprofiler/src/DataViews/CallstackDataView.cpp
        Message: invalid case style for local variable 'resultingColumns_'
        Replacements:
        - FilePath: /home/runner/work/orbitprofiler/orbitprofiler/src/DataViews/CallstackDataView.cpp
          Length: 17
          Offset: 1269
          ReplacementText: resulting_columns
        - FilePath: /home/runner/work/orbitprofiler/orbitprofiler/src/DataViews/CallstackDataView.cpp
          Length: 17
          Offset: 1292
          ReplacementText: resulting_columns
        - FilePath: /home/runner/work/orbitprofiler/orbitprofiler/src/DataViews/CallstackDataView.cpp
          Length: 17
          Offset: 1335
          ReplacementText: resulting_columns
        - FilePath: /home/runner/work/orbitprofiler/orbitprofiler/src/DataViews/CallstackDataView.cpp
          Length: 17
          Offset: 1420
          ReplacementText: resulting_columns
        - FilePath: /home/runner/work/orbitprofiler/orbitprofiler/src/DataViews/CallstackDataView.cpp
          Length: 17
          Offset: 1503
          ReplacementText: resulting_columns
        - FilePath: /home/runner/work/orbitprofiler/orbitprofiler/src/DataViews/CallstackDataView.cpp
          Length: 17
          Offset: 1581
          ReplacementText: resulting_columns
        - FilePath: /home/runner/work/orbitprofiler/orbitprofiler/src/DataViews/CallstackDataView.cpp
          Length: 17
          Offset: 1663
          ReplacementText: resulting_columns
        - FilePath: /home/runner/work/orbitprofiler/orbitprofiler/src/DataViews/CallstackDataView.cpp
          Length: 17
          Offset: 1762
          ReplacementText: resulting_columns
      DiagnosticName: readability-identifier-naming
      Level: Warning
    MainSourceFile: ''
    
    opened by florian-kuebler 13
  • multiline code-suggestions

    multiline code-suggestions

    Hi,

    Might be that this request is not relevant or that the problem lies somewhere else. We (UltiMaker Cura) recently start using your GitHub action, for our custom-made linting tool. We wrote a small Python module which performs linting on a json file which contains definition for 3D printers used in Cura. Since we have a lot of community contributions we want provide the community contributors with some automatic feedback on their PR's

    The output of this linting tool follows the same scheme as clang-tidy. See the example below:

    Diagnostics:
    -   DiagnosticMessage:
            FileOffset: 238
            FilePath: /home/jspijker/cura_wp/Cura/resources/extruders/koonovo_kn5_extruder_1.def.json
            Message: 'Overriding machine_nozzle_offset_x with the same value (0.0) as defined in parent definition: fdmextruder'
            Replacements:
            -   FilePath: /home/jspijker/cura_wp/Cura/resources/extruders/koonovo_kn5_extruder_1.def.json
                Length: 52
                Offset: 246
                ReplacementText: ''
        DiagnosticName: diagnostic-definition-redundant-override
        Level: Warning
    -   DiagnosticMessage:
            FileOffset: 299
            FilePath: /home/jspijker/cura_wp/Cura/resources/extruders/koonovo_kn5_extruder_1.def.json
            Message: 'Overriding machine_nozzle_offset_y with the same value (0.0) as defined in parent definition: fdmextruder'
            Replacements:
            -   FilePath: /home/jspijker/cura_wp/Cura/resources/extruders/koonovo_kn5_extruder_1.def.json
                Length: 52
                Offset: 307
                ReplacementText: ''
        DiagnosticName: diagnostic-definition-redundant-override
        Level: Warning
    -   DiagnosticMessage:
            FileOffset: 360
            FilePath: /home/jspijker/cura_wp/Cura/resources/extruders/koonovo_kn5_extruder_1.def.json
            Message: 'Overriding machine_nozzle_size with the same value (0.4) as defined in parent definition: fdmextruder'
            Replacements:
            -   FilePath: /home/jspijker/cura_wp/Cura/resources/extruders/koonovo_kn5_extruder_1.def.json
                Length: 48
                Offset: 368
                ReplacementText: ''
    

    However some of our suggested fixes are fixes over multiple lines, which this Action seems to have some trouble with, at least when we use it in conjunction with our custom printer-linter. It could be that the fixes suggested by clang-tidy are always confined to a single line so it isn't an issue for normal usage. But it would really help us if this action handles multi line suggestion comments

    image The suggestion in the image would result in an ill-formed json

    opened by jellespijker 10
  • Wrong suggestions

    Wrong suggestions

    Sometimes I get incorrect suggestions. For example, for this PR the suggestion is:

    -	auto findIteratorFor = [](const InterfaceState* state, const Interface& interface) {
    +	auto findItfind_iterator_forconst InterfaceState* state, const Interface& interface) {
    

    instead of the following one, which is correctly produced by clang-apply-replacements from the provided fixes file:

    -	auto findIteratorFor = [](const InterfaceState* state, const Interface& interface) {
    +	auto find_iterator_for = [](const InterfaceState* state, const Interface& interface) {
    

    Looks like the replacement is shifted by 6 characters in the suggestion.

    opened by rhaschke 5
  • Add release CI workflows

    Add release CI workflows

    As explained in #17,

    • github-release.yaml will prepare the release when a tag is published.
    • actions-tagger.yaml will generate a v1/v2/v3 tag when a release is published.
    opened by kenji-miyake 5
  • Example projects using clang-tidy-pr-comments

    Example projects using clang-tidy-pr-comments

    Great project! Are there any real life example project on github which are using this github action? If yes please add them to the readme it would help developers to decide if they want to use it and promote this tool more. Thanks in advance!

    opened by vkresch 3
  • 1.3.0 Seems to break warning without suggested replacement

    1.3.0 Seems to break warning without suggested replacement

    Just noticed my actions are failing with the following message, my guess is that it breaks when there are no suggested replacements. I will try to make a minimal example if you need it.

    Traceback (most recent call last):
      File "/action/run_action.py", line 4[12], in <module>
        sys.exit(main())
      File "/action/run_action.py", line 268, in main
        suggestion_end = suggestion_begin + diagnostic["ReplacementLength"]
    KeyError: 'ReplacementLength'
    
    opened by Summon528 3
  • Bug: warnings not correctly recognized

    Bug: warnings not correctly recognized

    In this build, clang-tidy found some warnings (and fixes):

    Run cat /home/runner/work/industrial_ci/industrial_ci/.work/clang-tidy-fixes.yml
    Diagnostics:
    - DiagnosticName: readability-identifier-naming
      FileOffset: 26
      FilePath: /home/runner/work/industrial_ci/industrial_ci/.work/target_ws/src/test_clang_tidy/src/test_clang_tidy.cpp
      Message: invalid case style for variable 'a'
      Replacements:
      - {FilePath: /home/runner/work/industrial_ci/industrial_ci/.work/target_ws/src/test_clang_tidy/src/test_clang_tidy.cpp,
        Length: 1, Offset: 26, ReplacementText: A}
    MainSourceFile: ''
    

    but the action reports: No warnings found in files changed in this pull request

    opened by rhaschke 3
  • Configuration examples not workng

    Configuration examples not workng

    To start using clang-tidy-pr-comments in a project, I copied the example code in "Using this Action to safely perform analysis of pull requests from forks". I kept getting fatal git errors in git diff -U0 HEAD^.

    I found a solution that I hope will be added to the examples to help others. action/[email protected] (and v3) can use fetch-depth: 2 to enable enough context for git diff to work.

    opened by skrobinson 3
  • A more strict regex extracting diff info is required

    A more strict regex extracting diff info is required

    One of my test failed with an index out of range error (see logs here). The patches include changes on something like this:

    +    // @@@@@@@
    +    // test
    +    // @@@@@@@
    +    /*
    

    And the regex at https://github.com/platisd/clang-tidy-pr-comments/blob/6f016d02636cd7122e972a64220efd8769f9568a/run_action.py#L135-L137 matches this pattern, not giving out diff info, resulting in error. I suggest replacing it with a more strict regex match, maybe like @@ -\d+,\d+ \+\d+,\d+ @@.

    opened by caic99 3
  • Failed to match codes between repo and `fixes.yml`.

    Failed to match codes between repo and `fixes.yml`.

    In my action, the running log shows that "No warnings found in files changed in this pull request". This error also happened in #17 .

    @kenji-miyake All file paths in your fixes.yaml begin with /__w/... (probably because clang-tidy is running self-hosted) while this action expects the GitHub directory layout (/home/runner/...), so it can't normalize paths and is not able to find all these files from your PR. Originally posted by @oleg-derevenetz in https://github.com/platisd/clang-tidy-pr-comments/issues/17#issuecomment-1038393661

    Thanks @oleg-derevenetz points out that there is another file system in a custom actions container.

    I wonder is there a proper way to avoid modifications on fixes.yaml? Maybe GitHub environment variable GITHUB_WORKSPACE helps, creating a symlink from from /home/runner/... to /__w/... .

    opened by caic99 3
  • Ambiguous expression in example workflow config

    Ambiguous expression in example workflow config

    https://github.com/platisd/clang-tidy-pr-comments/blob/10dea67599cd21bff5391960fe080aa6fd3a164b/README.md?plain=1#L114-L117

    Here, the comment says this is "the number of comments per review", but the variable name gives us "suggestions per comment". I suppose the latter one is actually what you mean.

    opened by caic99 1
  • Support Checks API

    Support Checks API

    It would be cool if instead of regular comments, the fixes could be suggested as part of the Checks API.

    There's a more informative picture here: https://docs.github.com/en/developers/apps/guides/creating-ci-tests-with-the-checks-api#step-25-updating-the-check-run-with-ci-test-results

    opened by pqn 2
Releases(1.3.2)
Owner
Dimitris Platis
Software Engineer & Maker. Currently with a special interest in the fields of Embedded Systems, Internet of things and Robotics.
Dimitris Platis
PyABSA - Open & Efficient for Framework for Aspect-based Sentiment Analysis

PyABSA - Open & Efficient for Framework for Aspect-based Sentiment Analysis

YangHeng 567 Jan 07, 2023
Crowd sourced training data for Rasa NLU models

NLU Training Data Crowd-sourced training data for the development and testing of Rasa NLU models. If you're interested in grabbing some data feel free

Rasa 169 Dec 26, 2022
Plugin repository for Macast

Macast-plugins Plugin repository for Macast. How to use third-party player plugin Download Macast from GitHub Release. Download the plugin you want fr

109 Jan 04, 2023
A simple word search made in python

Word Search Puzzle A simple word search made in python Usage $ python3 main.py -h usage: main.py [-h] [-c] [-f FILE] Generates a word s

Magoninho 16 Mar 10, 2022
Precision Medicine Knowledge Graph (PrimeKG)

PrimeKG Website | bioRxiv Paper | Harvard Dataverse Precision Medicine Knowledge Graph (PrimeKG) presents a holistic view of diseases. PrimeKG integra

Machine Learning for Medicine and Science @ Harvard 103 Dec 10, 2022
Tensorflow implementation of paper: Learning to Diagnose with LSTM Recurrent Neural Networks.

Multilabel time series classification with LSTM Tensorflow implementation of model discussed in the following paper: Learning to Diagnose with LSTM Re

Aaqib 552 Nov 28, 2022
Unsupervised text tokenizer focused on computational efficiency

YouTokenToMe YouTokenToMe is an unsupervised text tokenizer focused on computational efficiency. It currently implements fast Byte Pair Encoding (BPE)

VK.com 847 Dec 19, 2022
🦆 Contextually-keyed word vectors

sense2vec: Contextually-keyed word vectors sense2vec (Trask et. al, 2015) is a nice twist on word2vec that lets you learn more interesting and detaile

Explosion 1.5k Dec 25, 2022
Addon for adding subtitle files to blender VSE as Text sequences. Using pysub2 python module.

Import Subtitles for Blender VSE Addon for adding subtitle files to blender VSE as Text sequences. Using pysub2 python module. Supported formats by py

4 Feb 27, 2022
Learning General Purpose Distributed Sentence Representations via Large Scale Multi-task Learning

GenSen Learning General Purpose Distributed Sentence Representations via Large Scale Multi-task Learning Sandeep Subramanian, Adam Trischler, Yoshua B

Maluuba Inc. 309 Oct 19, 2022
This is the offline-training-pipeline for our project.

offline-training-pipeline This is the offline-training-pipeline for our project. We adopt the offline training and online prediction Machine Learning

0 Apr 22, 2022
:P Some basic stuff I'm gonna use for my upcoming Agile Software Development and Devops

reverse-image-search-py bash script.sh img_name.jpg Requirements pip install requests pip install pyshorteners Dry run [ Sudhanva M 3 Dec 18, 2021

A PyTorch implementation of paper "Learning Shared Semantic Space for Speech-to-Text Translation", ACL (Findings) 2021

Chimera: Learning Shared Semantic Space for Speech-to-Text Translation This is a Pytorch implementation for the "Chimera" paper Learning Shared Semant

Chi Han 43 Dec 28, 2022
Edge-Augmented Graph Transformer

Edge-augmented Graph Transformer Introduction This is the official implementation of the Edge-augmented Graph Transformer (EGT) as described in https:

Md Shamim Hussain 21 Dec 14, 2022
PyTorch Implementation of "Bridging Pre-trained Language Models and Hand-crafted Features for Unsupervised POS Tagging" (Findings of ACL 2022)

Feature_CRF_AE Feature_CRF_AE provides a implementation of Bridging Pre-trained Language Models and Hand-crafted Features for Unsupervised POS Tagging

Jacob Zhou 6 Apr 29, 2022
A Fast Sequence Transducer Implementation with PyTorch Bindings

transducer A Fast Sequence Transducer Implementation with PyTorch Bindings. The corresponding publication is Sequence Transduction with Recurrent Neur

Awni Hannun 184 Dec 18, 2022
Generate product descriptions, blogs, ads and more using GPT architecture with a single request to TextCortex API a.k.a Hemingwai

TextCortex - HemingwAI Generate product descriptions, blogs, ads and more using GPT architecture with a single request to TextCortex API a.k.a Hemingw

TextCortex AI 27 Nov 28, 2022
Pangu-Alpha for Transformers

Pangu-Alpha for Transformers Usage Download MindSpore FP32 weights for GPU from here to data/Pangu-alpha_2.6B.ckpt Activate MindSpore environment and

One 5 Oct 01, 2022
A Flask Sentiment Analysis API, with visual implementation

The Sentiment Analysis Api was created using python flask module,it allows users to parse a text or sentence throught the (?text) arguement, then view the sentiment analysis of that sentence. It can

Ifechukwudeni Oweh 10 Jul 17, 2022
Knowledge Oriented Programming Language

KoPL: 面向知识的推理问答编程语言 安装 | 快速开始 | 文档 KoPL全称 Knowledge oriented Programing Language, 是一个为复杂推理问答而设计的编程语言。我们可以将自然语言问题表示为由基本函数组合而成的KoPL程序,程序运行的结果就是问题的答案。目前,

THU-KEG 62 Dec 12, 2022