Skip to content

Enforce coding style using clang-tidy#3603

Draft
PremadeS wants to merge 6 commits intorizinorg:devfrom
PremadeS:clang-tidy
Draft

Enforce coding style using clang-tidy#3603
PremadeS wants to merge 6 commits intorizinorg:devfrom
PremadeS:clang-tidy

Conversation

@PremadeS
Copy link
Copy Markdown
Collaborator

@PremadeS PremadeS commented Apr 14, 2026

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository
  • I made sure to follow the project's coding style
  • I've updated the documentation with the relevant information (if needed)
  • I've used AI tools to generate fully or partially these code changes and I'm sure the changes are not copyrighted by somebody else.

Detailed description

Cutter has no concrete coding style, too many bad practices and magic numbers. This PR aims to enforce a coding style using clang-tidy to fix those issues

What this PR adds:
1- .clang-tidy config with the relevant checks
2- scripts/clang-tidy.py for running clang-tidy
3- ci workflow for clang-tidy
4- Header sorting fix in _clang-format
5- Coding style documentation update in docs/source/contributing/code/development-guidelines.rst

Detailed Explaination

  1. .clang-tidy config

Contains the following checks. All of them must pass in order for the CI to pass

  1. scripts/clang-tidy.py

Similar to scripts/clang-format.py - a python script for making it easier to run clang-tidy

usage: clang-tidy.py [-h] [-T RUN_CLANG_TIDY] [-p BUILD_PATH] [-f FILE] [-i]

clang-tidy wrapper

options:
  -h, --help            show this help message and exit
  -T, --run-clang-tidy RUN_CLANG_TIDY
                        Path of run-clang-tidy binary
  -p, --build-path BUILD_PATH
                        Path to the build directory
  -f, --file FILE       Check a specific file only
  -i, --fix             Apply fixes automatically

clang-tidy will only run on valid/necessary files (.h .hpp and .cpp) in the src directory. It will not run on files in the following directories:
SKIP_LIST = ["themes", "bindings", "fonts", "img", "translations", "build", "_autogen"]

  1. ci workflow for clang-tidy

Added in the linter.yml file as a separate job
Verifies all of the checks defined in .clang-tidy config are passing. clang-tidy requires compile_commands.json so we have to configure cmake before running it.
CI performs the following tasks:
1- Install build dependencies for cutter
2- Install llvm-16
3- Install clang-tidy-16
4- Configure Cmake
5- Run Qt autogen tools for cutter
6- run clang-tidy on all valid/necessary files in src using the provided run-clang-tidy-16 script

From some testing the CI job takes around 15 minutes which is much less than the full build jobs, hence total time shouldn't be affected.
The code changes line is commented out on purpose (just for now)

  1. Header sorting fix in`_clang-format

_clang-format file had weird sorting for headers before:

IncludeBlocks:   Preserve
IncludeCategories: 
  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
    Priority:        2
  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
    Priority:        3
  - Regex:           '.*'
    Priority:        1

I'm guessing these were either taken from somewhere or were the default options for the _clang-format generation script
These are updated to be:

IncludeBlocks: Regroup
IncludeCategories:
  - Regex:           '^"([^"]*)"' 
    Priority:        1
  - Regex:           '^<[Qq]'     
    Priority:        2
  - Regex:           '.*'         
    Priority:        3

This now aligns with what the Includes segment in Coding Style documentation which suggests:
1- Main header at the top
2- Followed by local includes. e.g: #include "Cutter.h"
3- Followed by Qt includes. e.g: <QLabel>, <qlobal.h>`
4- Lastly C++ standard headers or any other headers that don't fall into the above 3 groups
All of these 4 groups are separated by an empty line and entries in them are sorted in alphabetical order
Note that this will cause the clang-format check to fail

This new _clang-format file is generated via the modified scripts/_clang-format script using scripts/update_clang_format.sh running clang-format-8

Also in scripts/clang-format.py the description states "Clang format the rizin project" while I'm pretty sure it's for cutter not rizin :)

  1. Coding Style Documentation Update

See the changed doc file for updated coding conventions

Test plan (required)

Will add later, this PR is not done yet. Checks might be added/removed when doing the actual refactor of the codebase
Just need some opinions on this first

Closing issues

@PremadeS PremadeS marked this pull request as draft April 14, 2026 19:33
Comment thread .github/workflows/linter.yml Outdated
Comment thread docs/source/contributing/code/development-guidelines.rst Outdated
@notxvilka notxvilka added this to the 2.5 milestone Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants