JuceTidy - JUCE-specific Clang-Tidy checks

The checks cover every aspect of developing apps and plugins with JUCE from DSP to GUI. They’re mostly inspired by the JUCE Coding Standards, this forum post from @sudara, and other general best practices.


Some notable checks include:

JUCE Coding Standards checks

  • Check for == nullptr for pointer and std::function comparisons
  • Check for explicit unsigned int, not just unsigned
  • Check everything has a leak detector that should
  • Check order of public, protected, and private in classes
  • Check for passing small JUCE types by value (juce::Colour, juce::Point, etc.)
  • Check for pre-increment

juce-realtime-safety

Check for things like locks, allocations, and system calls in your audio playbacks. Use [[clang::nonblocking]] to allow Clang-Tidy to follow function calls to ensure the entire callstack is realtime safe.

juce::ValueTree checks

  • Check for adding listeners to temporaries
  • Check for unbound juce::CachedValues
  • Check for use of an unchecked child tree which could be invalid
  • Check for missing undo managers
  • Check for == comparisons on new/temporary trees (which would always return false)

Accessibility checks

  • Check all widgets have titles
  • Check custom widgets have custom accessibility handlers

JUCE vs STL checks

Configurable checks to always prefer JUCE equivalents to STL, or vice versa.

  • std::vector vs juce::Array
  • std::unordered_map vs juce::HashMap
  • std::set vs juce::SortedSet
  • std::span vs juce::Span
  • std::vector<std::byte> or std::span<std::byte> over juce::MemoryBlock
  • … and many more

Webview checks

  • Check for pageAboutToLoad() not properly implemented
  • Check for dev servers being used in Release builds
  • Check for hardcoded resource provider URLs (which aren’t cross-platform)
  • Check for missing MIME types
  • Check for incompatible Windows options

Other common mistakes

  • Not calling removeListener() in a listener’s destructor
  • Not stopping juce::Thread or juce::HighResolutionTimer in the destructor
  • Not resetting a component’s look-and-feel in its destructor
  • Calling repaint() from paint(), causing infinite repainting
  • Using a juce::Timer to call repaint() instead of a juce::VBlankAttachment
  • Capturing this in async and callback lambdas
  • Declaring widget attachments before their widgets in a class so the widget is destroyed before the attachment
  • Doing expensive things like loading images in paint()
  • Using #ifdef instead of #if with JUCE macros
  • … and many many more!

There are over 80 checks in total, with some checks covering multiple different patterns so well over 100 unique warnings JuceTidy can produce.

5 Likes

I’m a bit disappointed that tooling like this doesn’t ship with JUCE itself.

1 Like

It was surprisingly straightforward to make a custom ClangTidy plugin. It got me wondering why there aren’t more frameworks and libraries that ship their own plugins to encourage best practices!

With you there! Picking up JUCE with all of the safety nets baked in would, hopefully, reduce forum discussions especially around unwanted bugs, present best practices quietly, etc

The same for any other place.

The “common mistakes” areas you brought up are hard to guard against for example. Any of those can happen at any point, even when just cobbling together POCs or when juniors pick things up; hence why I think there’s a case to be made to bring this to JUCE itself.

1 Like

A lot of the checks in there just renforce a lot of the common JUCE assertions, things like not stopping threads, or creating files from relative paths. Making them Clang Tidy checks though means they can be enforced at compile time rather than runtime.