6

Use case

I want to configure readability-identifier-naming checker for clang-tidy running on my codebase.

Background

The checker in clang-tidy can be provided with CheckOptions, such like:

    clang-tidy -checks='-*,readability-identifier-naming' \ 
    -config="{CheckOptions: [ {key: readability-identifier-naming.ClassCase, value: CamelCase} ]}" main.cpp 

An option can also be specified in a .clang-tidy file.

Problem

Where do I find the list of available options (for a readability-identifier-naming check in this case) like e.g. the ClassCase from the line of code above?

The official documentation is not very specific, saying only "Many configuration options are available, in order to be able to create different rules for different kind of identifier."

Results of Googling

I have found this page on github, which explains it in a bit more detail (but still does not solve the problem).

I have also found a huge list in a file on a Microsoft's repository, but I have no idea where did they get that from.

Further investigation

I thought, that maybe clang-tidy would dump all the possible options if asked for. If you run

    clang-tidy -checks=* --dump-config

(or while specifying only readability-identifier-naming checker. It doesn't really matter, the output is the same)

    clang-tidy -checks='-*,readability-identifier-naming --dump-config

the dumped file includes only one option with respect to readability-identifier-naming, which is:

      - key:             readability-identifier-naming.IgnoreFailedSplit   
        value:           '0'

I was also trying to go through clang-tidy source code, but did not succeed.

After all

I would be grateful if someone could point me to a place (if it exists) with the list of all the available CheckOptions.

Community
  • 1
  • 1
Bartek
  • 71
  • 1
  • 3
  • You could always just check the source code. It's Open Source after all. – Jesper Juhl Jan 15 '19 at 16:40
  • 3
    @JesperJuhl "I was also trying to go through clang-tidy source code, but did not succeed." Additionally, this does not feel right, since usage options should be presented in the documentation for users. Don't you agree? – Bartek Jan 16 '19 at 07:25

2 Answers2

1

Where do I find the list of available options (for a readability-identifier-naming check in this case) like e.g. the ClassCase from the line of code above?

The list has since appeared on the page you originally linked to which currently lives here.

I have found this page on github, which explains it in a bit more detail (but still does not solve the problem).

Now it does!

John McFarlane
  • 5,528
  • 4
  • 34
  • 38
  • 1
    New link: https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html#options – Chris Jan 01 '23 at 09:23
0

The easiest way is to look into the source code of tests for this check here:

// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
// RUN:   -config='{CheckOptions: [ \
// RUN:     {key: readability-identifier-naming.AbstractClassCase, value: CamelCase}, \
// RUN:     {key: readability-identifier-naming.AbstractClassPrefix, value: 'A'}, \
...etc.

This list is not guaranteed to be exhaustive since it's only a command used for testing. To really be sure you'll have to look into the source code of the check itself here and you'll find all the naming keys:

#define NAMING_KEYS(m) \
    m(Namespace) \
    m(InlineNamespace) \
    m(EnumConstant) \
    ...

These naming keys are then stringized to StylenaNames[]. Then look into the IdentifierNamingCheck::storeOptions() function:

  for (size_t i = 0; i < SK_Count; ++i) {
    Options.store(Opts, (StyleNames[i] + "Case").str(),
                  toString(NamingStyles[i].Case));
    Options.store(Opts, (StyleNames[i] + "Prefix").str(),
                  NamingStyles[i].Prefix);
    Options.store(Opts, (StyleNames[i] + "Suffix").str(),
                  NamingStyles[i].Suffix);
  }

and you'll see that each naming key concatenated with Case, Prefix or Suffix can be specified as an option. That gives you the definitive list of possible options for this check.

pablo285
  • 2,460
  • 4
  • 14
  • 38