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
문장단위로 분절된 나무위키 데이터셋. Releases에서 다운로드 받거나, tfds-korean을 통해 다운로드 받으세요.

Namuwiki corpus 문장단위로 미리 분절된 나무위키 코퍼스. 목적이 LM등에서 사용하기 위한 데이터셋이라, 링크/이미지/테이블 등등이 잘려있습니다. 문장 단위 분절은 kss를 활용하였습니다. 라이선스는 나무위키에 명시된 바와 같이 CC BY-NC-SA 2.0

Jeong Ukjae 16 Apr 02, 2022
2021 AI CUP Competition on Traditional Chinese Scene Text Recognition - Intermediate Contest

繁體中文場景文字辨識 程式碼說明 組別:這就是我 成員:蔣明憲 唐碩謙 黃玥菱 林冠霆 蕭靖騰 目錄 環境套件 安裝方式 資料夾布局 前處理-製作偵測訓練註解檔 前處理-製作分類訓練樣本 part.py : 從 json 裁切出分類訓練樣本 Class.py : 將切出來的樣本按照文字分類到各資料夾

HuanyueTW 3 Jan 14, 2022
AI and Machine Learning workflows on Anthos Bare Metal.

Hybrid and Sovereign AI on Anthos Bare Metal Table of Contents Overview Terraform as IaC Substrate ABM Cluster on GCE using Terraform TensorFlow ResNe

Google Cloud Platform 8 Nov 26, 2022
Retraining OpenAI's GPT-2 on Discord Chats

Train OpenAI's GPT-2 on Discord Chats Retraining a Text Generation Model on Discord Chats using gpt-2-simple that wraps existing model fine-tuning and

Ayush Mishra 4 Oct 27, 2022
BeautyNet is an AI powered model which can tell you whether you're beautiful or not.

BeautyNet BeautyNet is an AI powered model which can tell you whether you're beautiful or not. Download Dataset from here:https://www.kaggle.com/gpios

Ansh Gupta 0 May 06, 2022
A Pytorch implementation of "Splitter: Learning Node Representations that Capture Multiple Social Contexts" (WWW 2019).

Splitter ⠀⠀ A PyTorch implementation of Splitter: Learning Node Representations that Capture Multiple Social Contexts (WWW 2019). Abstract Recent inte

Benedek Rozemberczki 201 Nov 09, 2022
Code repository for "It's About Time: Analog clock Reading in the Wild"

it's about time Code repository for "It's About Time: Analog clock Reading in the Wild" Packages required: pytorch (used 1.9, any reasonable version s

52 Nov 10, 2022
Semantic search through a vectorized Wikipedia (SentenceBERT) with the Weaviate vector search engine

Semantic search through Wikipedia with the Weaviate vector search engine Weaviate is an open source vector search engine with build-in vectorization a

SeMI Technologies 191 Dec 26, 2022
Training code of Spatial Time Memory Network. Semi-supervised video object segmentation.

Training-code-of-STM This repository fully reproduces Space-Time Memory Networks Performance on Davis17 val set&Weights backbone training stage traini

haochen wang 128 Dec 11, 2022
PyTorch implementation of "data2vec: A General Framework for Self-supervised Learning in Speech, Vision and Language" from Meta AI

data2vec-pytorch PyTorch implementation of "data2vec: A General Framework for Self-supervised Learning in Speech, Vision and Language" from Meta AI (F

Aryan Shekarlaban 105 Jan 04, 2023
Grover is a model for Neural Fake News -- both generation and detectio

Grover is a model for Neural Fake News -- both generation and detection. However, it probably can also be used for other generation tasks.

Rowan Zellers 856 Dec 24, 2022
构建一个多源(公众号、RSS)、干净、个性化的阅读环境

2C 构建一个多源(公众号、RSS)、干净、个性化的阅读环境 作为一名微信公众号的重度用户,公众号一直被我设为汲取知识的地方。随着使用程度的增加,相信大家或多或少会有一个比较头疼的问题——广告问题。 假设你关注的公众号有十来个,若一个公众号两周接一次广告,理论上你会面临二十多次广告,实际上会更多,运

howie.hu 678 Dec 28, 2022
Tool which allow you to detect and translate text.

Text detection and recognition This repository contains tool which allow to detect region with text and translate it one by one. Description Two pretr

Damian Panek 176 Nov 28, 2022
A framework for implementing federated learning

This is partly the reproduction of the paper of [Privacy-Preserving Federated Learning in Fog Computing](DOI: 10.1109/JIOT.2020.2987958. 2020)

DavidChen 46 Sep 23, 2022
📔️ Generate a text-based journal from a template file.

JGen 📔️ Generate a text-based journal from a template file. Contents Getting Started Example Overview Usage Details Reserved Keywords Gotchas Getting

Harrison Broadbent 21 Sep 25, 2022
A collection of models for image - text generation in ACM MM 2021.

Bi-directional Image and Text Generation UMT-BITG (image & text generator) Unifying Multimodal Transformer for Bi-directional Image and Text Generatio

Multimedia Research 63 Oct 30, 2022
HAN2HAN : Hangul Font Generation

HAN2HAN : Hangul Font Generation

Changwoo Lee 36 Dec 28, 2022
Bpe algorithm can finetune tokenizer - Bpe algorithm can finetune tokenizer

"# bpe_algorithm_can_finetune_tokenizer" this is an implyment for https://github

张博 1 Feb 02, 2022
A python script that will use hydra to get user and password to login to ssh, ftp, and telnet

Hydra-Auto-Hack A python script that will use hydra to get user and password to login to ssh, ftp, and telnet Project Description This python script w

2 Jan 16, 2022
This is the source code of RPG (Reward-Randomized Policy Gradient)

RPG (Reward-Randomized Policy Gradient) Zhenggang Tang*, Chao Yu*, Boyuan Chen, Huazhe Xu, Xiaolong Wang, Fei Fang, Simon Shaolei Du, Yu Wang, Yi Wu (

40 Nov 25, 2022