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
Module for automatic summarization of text documents and HTML pages.

Automatic text summarizer Simple library and command line utility for extracting summary from HTML pages or plain texts. The package also contains sim

Mišo Belica 3k Jan 08, 2023
Text Normalization(文本正则化)

Text Normalization(文本正则化) 任务描述:通过机器学习算法将英文文本的“手写”形式转换成“口语“形式,例如“6ft”转换成“six feet”等 实验结果 XGBoost + bag-of-words: 0.99159 XGBoost+Weights+rules:0.99002

Jason_Zhang 0 Feb 26, 2022
🤗Transformers: State-of-the-art Natural Language Processing for Pytorch and TensorFlow 2.0.

State-of-the-art Natural Language Processing for PyTorch and TensorFlow 2.0 🤗 Transformers provides thousands of pretrained models to perform tasks o

Hugging Face 77.3k Jan 03, 2023
A Python package implementing a new model for text classification with visualization tools for Explainable AI :octocat:

A Python package implementing a new model for text classification with visualization tools for Explainable AI 🍣 Online live demos: http://tworld.io/s

Sergio Burdisso 285 Jan 02, 2023
Augmenty is an augmentation library based on spaCy for augmenting texts.

Augmenty: The cherry on top of your NLP pipeline Augmenty is an augmentation library based on spaCy for augmenting texts. Besides a wide array of high

Kenneth Enevoldsen 124 Dec 29, 2022
Implementation / replication of DALL-E, OpenAI's Text to Image Transformer, in Pytorch

Implementation / replication of DALL-E, OpenAI's Text to Image Transformer, in Pytorch

Phil Wang 5k Jan 02, 2023
2021 2학기 데이터크롤링 기말프로젝트

공지 주제 웹 크롤링을 이용한 취업 공고 스케줄러 스케줄 주제 정하기 코딩하기 핵심 코드 설명 + 피피티 구조 구상 // 12/4 토 피피티 + 스크립트(대본) 제작 + 녹화 // ~ 12/10 ~ 12/11 금~토 영상 편집 // ~12/11 토 웹크롤러 사람인_평균

Choi Eun Jeong 2 Aug 16, 2022
Research Code for NeurIPS 2020 Spotlight paper "Large-Scale Adversarial Training for Vision-and-Language Representation Learning": UNITER adversarial training part

VILLA: Vision-and-Language Adversarial Training This is the official repository of VILLA (NeurIPS 2020 Spotlight). This repository currently supports

Zhe Gan 109 Dec 31, 2022
中文空间语义理解评测

中文空间语义理解评测 最新消息 2021-04-10 🚩 排行榜发布: Leaderboard 2021-04-05 基线系统发布: SpaCE2021-Baseline 2021-04-05 开放数据提交: 提交结果 2021-04-01 开放报名: 我要报名 2021-04-01 数据集 pa

40 Jan 04, 2023
Multilingual Emotion classification using BERT (fine-tuning). Published at the WASSA workshop (ACL2022).

XLM-EMO: Multilingual Emotion Prediction in Social Media Text Abstract Detecting emotion in text allows social and computational scientists to study h

MilaNLP 35 Sep 17, 2022
Dé op-de-vlucht Pieton vertaler. Wereldwijd gebruikt door meer dan 1.000+ succesvolle bedrijven!

Dé op-de-vlucht Pieton vertaler. Wereldwijd gebruikt door meer dan 1.000+ succesvolle bedrijven!

Lau 1 Dec 17, 2021
Python Implementation of ``Modeling the Influence of Verb Aspect on the Activation of Typical Event Locations with BERT'' (Findings of ACL: ACL 2021)

BERT-for-Surprisal Python Implementation of ``Modeling the Influence of Verb Aspect on the Activation of Typical Event Locations with BERT'' (Findings

7 Dec 05, 2022
Label data using HuggingFace's transformers and automatically get a prediction service

Label Studio for Hugging Face's Transformers Website • Docs • Twitter • Join Slack Community Transfer learning for NLP models by annotating your textu

Heartex 135 Dec 29, 2022
source code for paper: WhiteningBERT: An Easy Unsupervised Sentence Embedding Approach.

WhiteningBERT Source code and data for paper WhiteningBERT: An Easy Unsupervised Sentence Embedding Approach. Preparation git clone https://github.com

49 Dec 17, 2022
Beyond Accuracy: Behavioral Testing of NLP models with CheckList

CheckList This repository contains code for testing NLP Models as described in the following paper: Beyond Accuracy: Behavioral Testing of NLP models

Marco Tulio Correia Ribeiro 1.8k Dec 28, 2022
A simple Streamlit App to classify swahili news into different categories.

Swahili News Classifier Streamlit App A simple app to classify swahili news into different categories. Installation Install all streamlit requirements

Davis David 4 May 01, 2022
2021 AI CUP Competition on Traditional Chinese Scene Text Recognition - Intermediate Contest

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

HuanyueTW 3 Jan 14, 2022
使用Mask LM预训练任务来预训练Bert模型。训练垂直领域语料的模型表征,提升下游任务的表现。

Pretrain_Bert_with_MaskLM Info 使用Mask LM预训练任务来预训练Bert模型。 基于pytorch框架,训练关于垂直领域语料的预训练语言模型,目的是提升下游任务的表现。 Pretraining Task Mask Language Model,简称Mask LM,即

Desmond Ng 24 Dec 10, 2022
Mycroft Core, the Mycroft Artificial Intelligence platform.

Mycroft Mycroft is a hackable open source voice assistant. Table of Contents Getting Started Running Mycroft Using Mycroft Home Device and Account Man

Mycroft 6.1k Jan 09, 2023
Code for Editing Factual Knowledge in Language Models

KnowledgeEditor Code for Editing Factual Knowledge in Language Models (https://arxiv.org/abs/2104.08164). @inproceedings{decao2021editing, title={Ed

Nicola De Cao 86 Nov 28, 2022