Skip to main content

ClangTidy.lua reference

This document lists all of the available functions for use in ClangTidy.lua files. You can also use the standard Lua functions as listed in the Lua reference manual.

enable_checks

enable_checks("check-name-or-wildcard-*")

Enables the checks that match the given name or wildcard. You can either use an exact name like my-check-name or a wildcard like unreal-*.

Checks are enabled or disabled in the order of enable_checks and disable_checks calls. Therefore you can do this to enable all checks that match a wildcard and then turn off a specific check:

enable_checks("unreal-*")
disable_checks("unreal-broken-array-call")

disable_checks

disable_checks("check-name-or-wildcard-*")

Disables the checks that match the given name or wildcard. You can either use an exact name like my-check-name or a wildcard like unreal-*.

Refer to enable_checks on how the ordering of these calls matters.

treat_as_errors

treat_as_errors("check-name-or-wildcard-*")

Treats the checks that match the given name or wildcard as errors instead of warnings. Therefore, the specified checks will fail the build.

check

check {
-- The name of the check, as it can be used with `enable_checks`, etc.
name = "my-check-name",
-- A description associated with this check. Just for your own documentation; not emitted from clang-tidy.
description = [[
A custom description you want to write.
]],
-- The matcher expression, as you wrote it in clang-query (minus the `m` command prefix).
matcher = [[
fieldDecl().bind("binding_example")
]],
-- The message to emit from clang-tidy when this check is hit.
message = "the message to emit from clang-tidy",
-- The main binding ID to emit the warning or error on.
callsite = "binding_example",
-- If specified, this check is enabled by default.
enabled = true,
-- A table of the binding IDs to hint messages to emit.
hints = {
binding_id = "hint message",
other_binding = "another hint message"
}
}

Defines a custom check. Refer to Writing custom checks for more information on how to define these.

enable_profiling

enable_profiling()

Enables clang-tidy profiling. After each file is processed, it'll emit how long it took to run each check so you can identify checks that are consuming a lot of time in the build.

enable_match_outside_of_headers

enable_match_outside_of_headers()

By default, clang-tidy for Unreal Engine does not run checks against header files that are outside of the module. This saves a lot of time because checks don't have to evaluate any of the Unreal Engine header files beyond parsing them for general C++ processing.

You can turn on running checks against the Unreal Engine header files and files outside the current module by calling this function. However, this will take the build much longer.

Note that you don't need to turn this on if you just want to traverse to AST nodes within Unreal Engine headers from matchers; it's just that the root AST matcher won't be run against AST nodes outside of the current module. You can still e.g. look up fields relative to the matched root AST node in parent classes where those parent classes are in Unreal Engine header files.

enable_file_tracing

enable_file_tracing()

When enabled, clang-tidy will emit what files it's running checks against. This can help identify if certain files are not having checks run on them due to the lack of a enable_match_outside_of_headers() call.