[clang] [clang-format] Add -r option for recursing into directories (PR #160299)

James Henderson via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 24 02:28:10 PDT 2025


jh7370 wrote:

> > The option recursively replaces any directories on the command-line with all entries within the specified directories, making it easier to reformat an entire directory tree.
> > Fixes #62108
> 
> See [#62108 (comment)](https://github.com/llvm/llvm-project/issues/62108#issuecomment-1507022141). I agreed with @mkurdej then and haven't changed my mind. Let's see what @mydeveloperday thinks.

The reason I put this up for review is because there is quite considerable demand for the feature, based on both the ticket and the linked Stack Overflow post. Writing a script or crafting a find command to walk the directory tree and gather the desired files is non-zero work, which most people don't want to do. Depending on a user's setup, it may not even be that simple. Given the clear demand and relatively stragihtforward implementation, it seems silly to tell people simply "no, we refuse to do this". That's hardly listening to what the community want, which, since clang-format is probably one of the best known tools within the wider llvm project after clang itself, we should be doing.

Anyway, the clang-format-ignore file allows ignoring files from a set passed in, I assume so that things like `*.cpp` can be used in the input list without formatting certain specific files, or so that directory-walking scripts don't have to do the filtering themselves. That's hardly a formatting-related feature and rather violates the "do one thing well" idea that seems to be the sole argument against this. `-r` works well with it in fact (and I could see an argument that without it, -r shouldn't exist either).

https://github.com/llvm/llvm-project/pull/160299


More information about the cfe-commits mailing list