lnt-naming-convention
Ensure that the naming convention for symbols aligns with your coding style, as specified in the project's .editorconfig
file.
To enable this feature, add an .editorconfig
file in the same directory as your project file. The .editorconfig
specifies the naming conventions for symbols in your project. As an example, the naming conventions for Unreal Engine projects are specified in an .editorconfig
on GitHub.
Once you have the .editorconfig
file in your project, turn on the lnt-naming-convention
check with the Naming Convention setting in the C/C++ Code Style options. For information about how to change this setting, see Configure the linter.
Example
Suppose that you have an .editorconfig
file that contains:
cpp_naming_style.boolean_style.capitalization = pascal_case
cpp_naming_style.boolean_style.required_prefix = b
The linter flags the following code because it isn't prefixed with 'b' and because it isn't Pascal case, as specified in the .editorconfig
file:
void example()
{
bool myFlag = true; // flagged because it doesn't follow the naming convention specified in the .editorconfig
}
How to fix the issue
Change the naming to match the style specified in the .editorconfig
:
void example()
{
bool bMyFlag = true; // fixed to follow the code style specified in the .editorconfig
}
The editor can make the change for you. Place the cursor on the flagged symbol. Choose Show potential fixes and then Apply naming convention:
The code editor shows bool myFlag = true. With the cursor on that line of code, **Show potential fixes** appeared and was chosen. Now **Apply naming convention** is visible and it shows bool my Flag = true in red and the suggested change, bool b My Flag, in green. You can now choose **Apply naming convention** to change the flagged code to bool b My Flag = true.
Remarks
Introduced in Visual Studio 2022 17.7, the lnt-naming-convention
linter check ensures that naming conventions align with those specified in the .editorconfig
file. You can apply this check to any project that has an .editorconfig
file. You can also customize your .editorconfig
file to suit your project's coding style.
See also
Create portable, custom editor settings with EditorConfig
IntelliSense code linter for C++ overview