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
Mapping a variable-length sentence to a fixed-length vector using BERT model

Are you looking for X-as-service? Try the Cloud-Native Neural Search Framework for Any Kind of Data bert-as-service Using BERT model as a sentence enc

Han Xiao 11.1k Jan 01, 2023
Fuzzy String Matching in Python

FuzzyWuzzy Fuzzy string matching like a boss. It uses Levenshtein Distance to calculate the differences between sequences in a simple-to-use package.

SeatGeek 8.8k Jan 01, 2023
apple's universal binaries BUT MUCH WORSE (PRACTICAL SHITPOST) (NOT PRODUCTION READY)

hyperuniversality investment opportunity: what if we could run multiple architectures in a single file, again apple universal binaries, but worse how

luna 2 Oct 19, 2021
Sequence-to-Sequence learning using PyTorch

Seq2Seq in PyTorch This is a complete suite for training sequence-to-sequence models in PyTorch. It consists of several models and code to both train

Elad Hoffer 514 Nov 17, 2022
Code for our paper "Mask-Align: Self-Supervised Neural Word Alignment" in ACL 2021

Mask-Align: Self-Supervised Neural Word Alignment This is the implementation of our work Mask-Align: Self-Supervised Neural Word Alignment. @inproceed

THUNLP-MT 46 Dec 15, 2022
用Resnet101+GPT搭建一个玩王者荣耀的AI

基于pytorch框架用resnet101加GPT搭建AI玩王者荣耀 本源码模型主要用了SamLynnEvans Transformer 的源码的解码部分。以及pytorch自带的预训练模型"resnet101-5d3b4d8f.pth"

冯泉荔 2.2k Jan 03, 2023
基于“Seq2Seq+前缀树”的知识图谱问答

KgCLUE-bert4keras 基于“Seq2Seq+前缀树”的知识图谱问答 简介 博客:https://kexue.fm/archives/8802 环境 软件:bert4keras=0.10.8 硬件:目前的结果是用一张Titan RTX(24G)跑出来的。 运行 第一次运行的时候,会给知

苏剑林(Jianlin Su) 65 Dec 12, 2022
Sploitus - Command line search tool for sploitus.com. Think searchsploit, but with more POCs

Sploitus Command line search tool for sploitus.com. Think searchsploit, but with

watchdog2000 5 Mar 07, 2022
Stuff related to Ben Eater's 8bit breadboard computer

8bit breadboard computer simulator This is an assembler + simulator/emulator of Ben Eater's 8bit breadboard computer. For a version with its RAM upgra

Marijn van Vliet 29 Dec 29, 2022
Shared, streaming Python dict

UltraDict Sychronized, streaming Python dictionary that uses shared memory as a backend Warning: This is an early hack. There are only few unit tests

Ronny Rentner 192 Dec 23, 2022
📜 GPT-2 Rhyming Limerick and Haiku models using data augmentation

Well-formed Limericks and Haikus with GPT2 📜 GPT-2 Rhyming Limerick and Haiku models using data augmentation In collaboration with Matthew Korahais &

Bardia Shahrestani 2 May 26, 2022
Implementation of Fast Transformer in Pytorch

Fast Transformer - Pytorch Implementation of Fast Transformer in Pytorch. This only work as an encoder. Yannic video AI Epiphany Install $ pip install

Phil Wang 167 Dec 27, 2022
DataCLUE: 国内首个以数据为中心的AI测评(含模型分析报告)

DataCLUE 以数据为中心的AI测评(DataCLUE) DataCLUE: A Chinese Data-centric Language Evaluation Benchmark 内容导引 章节 描述 简介 介绍以数据为中心的AI测评(DataCLUE)的背景 任务描述 任务描述 实验结果

CLUE benchmark 135 Dec 22, 2022
Text to speech for Vietnamese, ez to use, ez to update

Chào mọi người, đây là dự án mở nhằm giúp việc đọc được trở nên dễ dàng hơn. Rất cảm ơn đội ngũ Zalo đã cung cấp hạ tầng để mình có thể tạo ra app này

Trần Cao Minh Bách 32 Jul 29, 2022
A Chinese to English Neural Model Translation Project

ZH-EN NMT Chinese to English Neural Machine Translation This project is inspired by Stanford's CS224N NMT Project Dataset used in this project: News C

Zhenbang Feng 29 Nov 26, 2022
Pipeline for chemical image-to-text competition

BMS-Molecular-Translation Introduction This is a pipeline for Bristol-Myers Squibb – Molecular Translation by Vadim Timakin and Maksim Zhdanov. We got

Maksim Zhdanov 7 Sep 20, 2022
Simple, hackable offline speech to text - using the VOSK-API.

Simple, hackable offline speech to text - using the VOSK-API.

Campbell Barton 844 Jan 07, 2023
NLP Overview

NLP-Overview Introduction The field of NPL encompasses a variety of topics which involve the computational processing and understanding of human langu

PeterPham 1 Jan 13, 2022
Simple NLP based project without any use of AI

Simple NLP based project without any use of AI

Shripad Rao 1 Apr 26, 2022
Making text a first-class citizen in TensorFlow.

TensorFlow Text - Text processing in Tensorflow IMPORTANT: When installing TF Text with pip install, please note the version of TensorFlow you are run

1k Dec 26, 2022