Where to put editorconfig?

JW 81 Reputation points
2023-02-22T15:45:03.3566667+00:00

I'm trying to customize spell checking. As explained in the release notes (https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes) the "behavior can be modified with an .editorconfig file."

But where am I supposed to put this file? I used File Explorer to create a new text file called ".editorconfig" in my project folder and copied the example from the release notes. I then opened my project with Visual Studio and added the new file with "Project->Add existing Item". I tried restarting Visual Studio, but still doesn't work.

For example, as you can see in this screenshot, I removed "comments" from checkable types, but the editor is still checking comments. The file "tinyxml2.cpp" is in the project folder (same folder as ".editorconfig")
User's image

What am I doing wrong?

Developer technologies | Visual Studio | Other
{count} votes

Accepted answer
  1. Michael Taylor 60,326 Reputation points
    2023-02-22T19:37:11.08+00:00

    .editorconfig is a standard file that contains lots of different things related to a solution/project. For example almost all the styling rules and analyzer settings can be stored here. The purpose of this file, as discussed here, is to allow you to standardize your editor configuration (related to styles, naming, formatting, etc) and share it with a team. By putting the configuration into a file, the file can be placed into your source control repository and anyone who pulls down the code will automatically use the configured settings instead of whatever defaults they have set up or VS is using. Basically it forces compliance with company-defined rules.

    The file itself can be anywhere in the directory structure up to your project file. For example if your code is at c:\projects\company\myproduct then the file can reside in any directory up to myproduct. If you have different settings for different projects then it makes sense to put it at the project(solution) level. However many companies have standard settings so it is often put into the higher level company directory and all solutions/projects created under that will follow the guidance. So in your specific case put the file anywhere in the directory structure but no deeper than where your project file is. I would recommend with the solution file myself. Restart VS and it'll find it.

    Alternatively you can go into the VS options where you configure the formatting rules. It has a button to auto-generate a file based upon your current VS settings. This is generally a faster way of generating the file if you're not comfortable with the format.

    The file is hierarchical. By default the IDE will load up every .editorconfig file from the project directory back to the root. This allows you to override settings on a per-project/solution basis. But this can be time consuming so you can optionally add the attribute that marks the config file as root. When the IDE finds a config marked as root it stops walking the directories backwards. If you're using Github repos and plan to share your code then I would recommend you put your config file in the root of your repo and mark it as root so it takes precedence over any other config files.

    Note you should not add this file to your project. It is just an extra file (like .gitignore) and doesn't need to be added. It doesn't hurt if you do but it doesn't change anything.

    Now, why isn't it working for you. Firstly you should confirm that you're running VS 2022 17.5 Preview 3. This is the first version that supports this feature for C++. If you have a version of VS earlier than that then it won't work for C++ yet. If you are running at least that version then the problem lies elsewhere.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.