How to beautify/change style in a c++ project using clang/clang-tidy?

Viewed 677

Having a large c++ project I would like to change some styles.

I am currently wondering if changing the public class methods from camelCase to PascalCase is actually possible without having to write a full refactoring tool. eg:

class MyLovelyClassPlentyOfCamelCaseMethods
{
    public:
        void aCamelCaseMethodIWouldLoveToConvertToPascalCaseEverywhere();
    protected:
    private:
        void anotherCamelCaseMethodIWouldLoveToRemainAsIs();
};

I know that LLVM/clang tools are a high powerful tools that can be oriented to achieve this but I am completely new at clang and clang-tidy in every aspect so any step by step guiding through is greatly welcomed. I have found several resources and documentation about but still couldn't reach to any useful point and started being really confused on how to go along with this.

Thanks a lot to the community in advance!

1 Answers

There is a clang-tidy check designed for this purpose :

readability-identifier-naming

Using the fix option you can use this check to actually convert the case from pascal to camel.

readability-identifier-naming can be used to convert case individually for different categories of identifiers.

To change case of public member methods to pascal* and private member methods to camel* your .clang-tidy file should look like this:

Checks: '-*,readability-identifier-naming'
CheckOptions:
  - { key: readability-identifier-naming.PublicMethodCase, value: CamelCase}
  - { key: readability-identifier-naming.PrivateMethodCase, value: camelBack}

*note: what you refer to as pascal case is called CamelCase and your camel case is camelBack in clang-tidy

Related