Visual Studio checking naming convention for C++

480 views Asked by At

I'm trying to configure my Visual Studio 022 to check and put warning when my compagny C++ code rules et naming conventions are not respected. The simple example is to prefix boolean with a "b".

bool bFoo = true

I tried to configure Visual Studio with the .editorconfig. I found this in the Microsoft Documentation. And I created this :

[*.{cpp,h}]
cpp_naming_rule.booleans_prefixed.symbols                 = boolean_vars
cpp_naming_rule.booleans_prefixed.style                   = boolean_style

cpp_naming_symbols.boolean_vars.applicable_kinds          = local,parameter,field
cpp_naming_symbols.boolean_vars.applicable_type           = bool

cpp_naming_style.boolean_style.capitalization              = pascal_case
cpp_naming_style.boolean_style.required_prefix             = b
cpp_naming_style.boolean_style.required_suffix             =
cpp_naming_style.boolean_style.word_separator              =

But it does not work. (The file is taken into account, I checked by modifying the indent_size).

Have any ideas to fix the editorconfig or to solve my base problem ?

1

There are 1 answers

0
Minxin Yu - MSFT On

Introduced in Visual Studio 2022 17.7

  1. Check your Visual Studio version. Try resetting Visual Studio Settings.

  2. Place .editorconfig in the same folder as the project. Then add .editorconfig into project. Add -> Existing item.

  3. Check the settings: Naming Convention setting in the C/C++ Code Style options and Configure the linter. It is recommended to change it to Warning or Error. But this doesn't affect the compiler, just the editor. White is not obvious

enter image description here

  1. Wait for Visual Studio to load .editorconfig. It may take a long time until the font changes from white to green.

enter image description here