Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 98 additions & 15 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,46 +1,129 @@
# clang-tidy configuration for nifti_clib.
#
# This is a C11 codebase that ships a stable ABI. Two consequences shape
# the list below:
#
# * Checks written for C++ idioms are noise here and are turned off
# rather than left to accumulate.
# * Any check that wants to change linkage or a declaration in an
# installed header is off, and must stay off. See the ABI section.
#
# Run it with:
# cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
# run-clang-tidy -p build -j "$(nproc)" -quiet
#
Checks: '-*,
android-*,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Google Carbon] Non-blocking note: when configuring with -DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON -DFSLSTYLE=ON (worth mentioning in the cmake -B build example on line 12!), doPigz (PIGZ) calls popen(command, "w"), which triggers android-cloexec-popen (demanding non-standard glibc/Bionic "we" mode in an ISO C11 build) and cert-env33-c. Dropping android-* altogether is likely cleaner for a cross-platform C11 library than disabling android-cloexec-* checks one by one.

-android-cloexec-fopen,

bugprone-*,
-bugprone-narrowing-conversions,
-bugprone-signed-char-misuse,
-bugprone-assignment-in-if-condition,
-bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
-bugprone-not-null-terminated-result,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-assignment-in-if-condition,
-bugprone-macro-parentheses,
-bugprone-narrowing-conversions,
-bugprone-not-null-terminated-result,
-bugprone-signed-char-misuse,

cert-*,
-cert-str34-c,
-cert-err34-c,
-cert-err33-c,
-cert-err34-c,
-cert-flp30-c,
-cert-str34-c,

clang-analyzer-*,
-clang-analyzer-alpha.clone.CloneChecker,
-clang-analyzer-alpha.deadcode.UnreachableCode,
-clang-analyzer-security.insecureAPI.strcpy,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
-clang-analyzer-security.FloatLoopCounter,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
-clang-analyzer-security.insecureAPI.strcpy,

google-*,
-google-readability-casting,
-google-readability-braces-around-statements,
-google-readability-casting,
-google-readability-function-size,

misc-*,
-misc-confusable-identifiers,
-misc-include-cleaner,
-misc-no-recursion,
-misc-use-internal-linkage,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Google Carbon] Heads-up for future CI setup: -misc-use-internal-linkage (here), -readability-avoid-nested-conditional-operator (line 54), and -readability-math-missing-parentheses (line 62) were introduced in LLVM 19. Regular clang-tidy runs ignore unknown negative patterns, but clang-tidy --verify-config will exit non-zero on Ubuntu 24.04's default clang-tidy-18 (18.1.3), so pin clang-tidy-19+ if --verify-config is added to CI. (Also, lines 54–55 aren't listed in the # Turned off as noise rationale block below.)


performance-*,
-performance-type-promotion-in-math-fn,

readability-*,
-readability-magic-numbers,
-readability-avoid-nested-conditional-operator,
-readability-avoid-unconditional-preprocessor-if,
-readability-braces-around-statements,
-readability-else-after-return,
-readability-identifier-length,
-readability-inconsistent-ifelse-braces,
-readability-isolate-declaration,
-readability-braces-around-statements,
-readability-magic-numbers,
-readability-math-missing-parentheses,
-readability-misleading-indentation,
-readability-named-parameter,
-readability-non-const-parameter,
-readability-misleading-indentation'
-readability-redundant-parentheses'

# ---------------------------------------------------------------------------
# ABI: checks that must never be enabled
#
# misc-use-internal-linkage Wants `static` on every function without a
# visible external use. It flags 29 distinct functions here, and 13 of
# them are symbols currently exported by libniftiio, libfslio or
# libcifti -- FslFileType, FslGetHdrImgNames, fsl_fileexists,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Google Carbon] Minor comment sync nit with PRs #90 and #89: both #90 and #89 actually mark FslFileType and fsl_fileexists static (removing them from exported_symbols_linux.txt) while keeping FslGetHdrImgNames, nifti_fileexists, etc. exported. Updating the example names here avoids contradicting #90/#89.

# axml_recur_find_xml and the rest. Applying the fix-it deletes them
# from the shared libraries, silently breaking anyone linking against
# them. Most are also the functions -Wmissing-prototypes complains
# about; the fix for those is a file-local prototype, not `static`.
# Never enable this check without an ABI review.
#
# readability-non-const-parameter Wants `const` added to pointer
# parameters. Harmless inside a .c file, but its fix-it does not know
# which functions are declared in an installed header, and adding const
# there changes the published prototype.
#
# ---------------------------------------------------------------------------
# Turned off as noise, with counts from the run that introduced this file
#
# readability-math-missing-parentheses 623. Wants parentheses around
# every * inside a +. This is a house-style opinion, not a defect
# class, and the arithmetic here is conventional.
# misc-include-cleaner 620. An include-what-you-use
# tool. It flags every transitively-included declaration, including
# ones from nifti1_io.h that exist precisely so callers need one header.
# readability-inconsistent-ifelse-braces 246. clang-format owns brace
# placement here and is configured with InsertBraces: false.
# readability-named-parameter 14. Omitting parameter names in
# a prototype is idiomatic C.
# readability-redundant-parentheses 29. Directly at odds with
# bugprone-macro-parentheses, which is enabled and is the one that
# catches real defects.
#
# ---------------------------------------------------------------------------
# Notable checks that ARE enabled
#
# bugprone-macro-parentheses was disabled; re-enabled here.
# The macros in nifti_tool.h and the QSTR/NT_FILL families expand their
# arguments without parentheses, so any caller passing an expression
# gets silent precedence bugs.
# bugprone-unchecked-string-to-number-conversion
# bugprone-suspicious-realloc-usage leaks the original block when
# realloc returns NULL.
# bugprone-misplaced-widening-cast cast applied after the overflow
# rather than before it.
# bugprone-multi-level-implicit-pointer-conversion
#
# cert-err33-c stays off for now: it flags every unchecked printf and fseek
# as well as the allocations that matter, which buries the signal. The
# allocation cases are covered by clang-analyzer-unix.Malloc instead.
#
CheckOptions:
- key: readability-function-cognitive-complexity.IgnoreMacros
value: 1
# A ratchet, not a target. Several functions here (nifti_image_read,
# nifti_tool's act_* dispatchers) are large by design. This value is set
# just above today's worst so that nothing may get worse; lower it as
# functions are split, never raise it.
- key: readability-function-cognitive-complexity.Threshold
value: 428
Loading