|
| 1 | +--- |
| 2 | +title: lnt-naming-convention |
| 3 | +description: "Reference for Visual Studio C++ IntelliSense Linter check lnt-naming-convention." |
| 4 | +ms.date: 09/28/2023 |
| 5 | +f1_keywords: ["lnt-naming-convention"] |
| 6 | +helpviewer_keywords: ["lnt-naming-convention"] |
| 7 | +monikerRange: ">=msvc-170" |
| 8 | +--- |
| 9 | +# `lnt-naming-convention` |
| 10 | + |
| 11 | +Ensure that the naming convention for symbols aligns with your coding style, as specified in the project's `.editorconfig` file. |
| 12 | + |
| 13 | +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](https://raw.githubusercontent.com/microsoft/vc-ue-extensions/main/Source/.editorconfig). |
| 14 | + |
| 15 | +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](cpp-linter-overview.md#configure-the-linter). |
| 16 | + |
| 17 | +## Example |
| 18 | + |
| 19 | +Suppose that you have an `.editorconfig` file that contains: |
| 20 | + |
| 21 | +``` |
| 22 | +cpp_naming_style.boolean_style.capitalization = pascal_case |
| 23 | +cpp_naming_style.boolean_style.required_prefix = b |
| 24 | +``` |
| 25 | + |
| 26 | +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: |
| 27 | + |
| 28 | +```cpp |
| 29 | +void example() |
| 30 | +{ |
| 31 | + bool myFlag = true; // flagged because it doesn't follow the naming convention specified in the .editorconfig |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +## How to fix the issue |
| 36 | + |
| 37 | +Change the naming to match the style specified in the `.editorconfig`: |
| 38 | + |
| 39 | +```cpp |
| 40 | +void example() |
| 41 | +{ |
| 42 | + bool bMyFlag = true; // fixed to follow the code style specified in the .editorconfig |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +The editor can make the change for you. Place the cursor on the flagged symbol. Choose **Show potential fixes** and then **Apply naming convention**: |
| 47 | + |
| 48 | +:::image type="complex" source="media/lnt-apply-naming-convention.png" alt-text="Screenshot of the IDE suggesting applying naming convention."::: |
| 49 | +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. |
| 50 | +:::image-end::: |
| 51 | + |
| 52 | +## Remarks |
| 53 | + |
| 54 | +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. |
| 55 | + |
| 56 | +## See also |
| 57 | + |
| 58 | +[Create portable, custom editor settings with EditorConfig](/visualstudio/ide/create-portable-custom-editor-options)\ |
| 59 | +[IntelliSense code linter for C++ overview](cpp-linter-overview.md) |
0 commit comments