Visual Studio 2022 now performs automatic code cleanup on file saves – Visual Studio Magazine
Visual Studio 2022 now performs automatic code cleanup on file saves
A nifty little feature of the brand new Visual Studio 2022 17.1 Preview 2 is automatic code cleanup on save.
Code Cleanup was actually introduced in 2018 with Visual Studio 2019 Preview 1. It allows developers to configure the code styles they want to apply by choosing one of two profiles in the Configure Code Cleanup dialog box. coded.
Microsoft Documentation August 2021 says: “For C# code files, Visual Studio 2019 has a Code cleanup button at the bottom of the editor (keyboard: CTRL+K, CTRL+E) to apply code styles from an EditorConfig file or from the code style options page. If a .editorconfig file exists for the project, the settings prevail.”
“Code Cleanup On Save” has also been available for a while, thanks to a Visual Studio Marketplace extension aptly called Code cleanup on save, authored by Microsoft extension guru Mads Kristensen. “Code Cleanup is a new feature in Visual Studio 2019 that will automatically clean up your code file to ensure it is properly formatted and your coding style preferences are applied,” the marketplace description reads. “This extension will automatically perform code cleanup when saving the file.” It sports over 30,000 installs and earned a perfect 5 rating from 12 developers who reviewed it.
Now, the feature is integrated into the company’s flagship IDE for the first time, although you’ll have to dive into the preview channel to use it right now.
“Starting with Visual Studio 2022 17.1 Preview 2, developers can now automatically perform code cleanup when a file is saved!” said Microsoft product manager Denizhan Yigitbas in a January 10 blog post. Publish. “Automatic Code Cleanup on Save is a new feature in Visual Studio 2022 that can clean up your code file to ensure it is formatted correctly and that your coding style preferences are applied. Some preferences Customizable features include: format document, sort usages, remove unnecessary usages, and more. This feature can help minimize stylistic violations in PR and more so developers can spend less time fixing unresponsive code. not to specific standards and more time doing what they do best.
Its instructions for using it are:
- Go to Analyze > Code Cleanup > Configure Code Cleanup to customize the desired customizations of your code cleanup profile(s).
- Go to Tools > Options > Text Editor > Code Cleanup. Check the box “Run code cleanup profile on save”. Be sure to select the appropriate profile that you want to run automatically every time you save!
In the comments to the article, it was revealed that cleaning up code on save does not yet work with C++, so a Developer Community Feedback item was just posted today ( January 11), appropriately called Code cleanup support for C++.
Another developer also replied: “Indeed, while waiting for c++ support here…. In fact, just including ‘Document Format’ support will get you almost there. Although that doesn’t tell me Also wouldn’t mind a few fixes (seems the msvc tooling api itself won’t happen, so stick to clang tools for now).”
Yet another comment said, “It’s a nice feature, but how Code Cleanup interacts with EditorConfig is unclear + confusing.”
Or you can just check out the existing documentation appropriately titled Code styles in EditorConfig files.