DirectXMath icon indicating copy to clipboard operation
DirectXMath copied to clipboard

Consider adding a Clang-Tidy configuration to enforce some coding conventions

Open danielozyurt opened this issue 4 months ago • 0 comments

Take your project DirectXTK as an example, in which you have set these conventions:

PascalCase for class names, methods, functions, and enums.
camelCase for class member variables, struct members
UPPERCASE for preprocessor defines (and nameless enums)

To enforce these naming conventions, you can add readability-* to the checks as shown below:

Checks: >
  -*,
  readability-*

Then add some of these check options:

CheckOptions:
  readability-identifier-naming.ClassCase: 'CamelCase'
  readability-identifier-naming.ClassMethodCase: 'CamelCase'
  readability-identifier-naming.FunctionCase: 'CamelCase'
  readability-identifier-naming.EnumCase: 'CamelCase'
  readability-identifier-naming.ClassMemberCase: 'camelBack'
  readability-identifier-naming.MemberCase: 'camelBack'
  readability-identifier-naming.MacroDefinitionCase: 'UPPER_CASE'
  readability-identifier-naming.EnumConstantCase: 'UPPER_CASE'

Microsoft Visual Studio supports Clang-Tidy and Clang-Format out of the box.

P.S.: while EditorConfig is fine, I think you can enforce more specific code-style conventions, such as east const and west const with Clang-Format.

Using Clang-Tidy (and perhaps also Clang-Format) could help maintain greater code consistency.

Reference:

  • https://github.com/googleapis/google-cloud-cpp/blob/main/.clang-tidy
  • https://clang.llvm.org/extra/clang-tidy/
  • https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html

danielozyurt avatar Nov 07 '25 17:11 danielozyurt