Skip to content

Commit 71fc203

Browse files
TylerMSFTTylerMSFT
authored andcommitted
draft
1 parent b2b8cd5 commit 71fc203

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

docs/ide/include-cleanup-config.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: "Config the C++ #include cleanup tool"
3-
description: "Learn how to configure the C++ include cleanup tool for individual users and for your team."
2+
title: "Config C/C++ #include cleanup in Visual Studio"
3+
description: "Learn how to configure C/C++ include cleanup."
44
ms.date: 10/10/2023
55
ms.topic: "how-to"
66
ms.custom: intro-overview
77
---
8-
# Config the C++ #include tool in Visual Studio
8+
# Config C/C++ #include cleanup in Visual Studio
99

10-
Starting with Visual Studio 17.7 preview 3, Visual Studio provides the `#include` cleanup tool to improve the quality of your code in the following ways:
10+
Starting with Visual Studio 17.7 preview 3, Visual Studio provides the `#include` cleanup tool to improve the quality of your C and C++ code in the following ways:
1111
- Offers to remove unused header files--improving build times.
1212
- Offers to add header files for code that is only working because another header file includes the necessary header file.
1313

@@ -49,10 +49,21 @@ The `#include` cleanup tool indicates unused headers by dimming the line of the
4949
The line for #include < iostream > is dimmed becasue the line of code that uses iostream is commented out. That line of code is // std::cout << "charSize = " << charSize; The quick action menu is also visible for this line. It says the #include < iostream > is not used in this file, and has a link to Show potential fixes.
5050
:::image-end:::
5151

52-
For the exercise in this article, **Remove unused includes suggestion level** is set to **Dimmed** and **Add missing includes suggestion level** is set to **Suggestion**.
52+
## Configure the include cleanup tool with `.editorconfig`
5353

54-
There are more options for configuring the `#include` cleanup tool such as excluding specified includes from cleanup suggestions, indicating that some header files are required so that the tool doesn't mark them as unused, and so on. For more information, see [Configure code cleanup](/visualstudio/ide/code-cleanup#configure-code-cleanup-JTW_TO_WRITE).
54+
There are more options for configuring the `#include` cleanup tool, such as excluding specified includes from cleanup suggestions, indicating that some header files are required so that the tool doesn't mark them as unused, and so on. These options are defined in an `.editorconfig` file which, among other things, can be added to your project to enforce consistent coding styles for everyone that works in the codebase. For more information about adding an `.editorconfig` file to your project, see [Create portable, custom editor settings with EditorConfig](/visualstudio/ide/create-portable-custom-editor-options).
55+
56+
The `.editorconfig` settings that you can use with include cleanup are:
57+
58+
| Setting | Description | Values | Example |
59+
|--|--|--|--|
60+
| `cpp_include_cleanup_add_missing_error_tag_type` | Sets the error level of add transitive include suggestions. | `none`</br>`suggestion`</br>`warning`</br>`error` | `cpp_include_cleanup_add_missing_error_tag_type = suggestion` |
61+
| `cpp_include_cleanup_remove_unused_error_tag_type` | Sets the error level of remove unused include suggestions. | `none`</br>`suggestion`</br>`warning`</br>`error`</br>`dimmed` | `cpp_include_cleanup_remove_unused_error_tag_type = dimmed` |
62+
| `cpp_include_cleanup_excluded_files` | Excludes the specified files from include tool cleanup suggestions. | filename | `cpp_include_cleanup_excluded_files = vcruntime.h,vcruntime_string.h` |
63+
| `cpp_include_cleanup_required_files` | Ensures that required files won’t be marked as unused. | indirect header file:filename | `cpp_include_cleanup_required_files = atlwin.h:altbase.h,atlcom.h:altbase.h` |
64+
| `cpp_include_cleanup_replacement_files` | Redirect the usage of the first file to using the second file. | file to replace:replacing file | `cpp_include_cleanup_replacement_files = stdio.h:cstdio,stdint.h:cstdint` |
65+
| `cpp_include_cleanup_alternate_files` | Prevent #include cleanup from generating suggestions for alternate matches. | file to exclude:alternate file | `cpp_include_cleanup_alternate_files = windows.h:minwindef.h,windows.h:winerror.h` |
5566

5667
## See also
5768

58-
[Clean up C++ #includes in Visual Studio](/visualstudio/ide/include-cleanup-overview)
69+
[Clean up C and C++ #includes in Visual Studio](/visualstudio/ide/include-cleanup-overview)

docs/ide/include-cleanup-overview.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ms.date: 10/03/2023
55
ms.topic: "overview"
66
ms.custom: intro-overview
77
---
8-
# Clean up C++ #includes in Visual Studio
8+
# Clean up C and C++ #includes in Visual Studio
99

1010
Starting with Visual Studio 17.7 preview 3, Visual Studio provides an `#include` cleanup tool that improves the quality of your code in the following ways:
1111
- Offers to remove unused header files--improving build times and code cleanliness.
@@ -82,6 +82,7 @@ In the following screenshot, `#include "myHeader.h"` is dimmed (a setting descri
8282
We could choose to remove the unused header file, but that results in the code breaking since we will no longer be indirectly including `<string>` and `<iostream>`.
8383

8484
Instead, we can choose **Add all transitvely used and remove all unused #includes**. This removes the now unused header `myHeader.h`, but also adds any headers that are being used that were indirectly included by the removed header file. In this case, `#include <string>` and `#include <iostream>` are added because they are indirectly included by `myHeader.h`, which is then removed. You can think of the order of operations as:
85+
8586
- first determine which indirect header files are being used and are included by the unused header file that is about to be removed
8687
- add `#include`s for the indirect header files
8788
- remove the unused header file
@@ -105,10 +106,6 @@ The tool doesn't update the comments, but you can see that the code is now using
105106

106107
In this brief overview, you've seen how the #include cleanup tool can help you remove unused headers, and add headers that were indirectly included by other headers. This helps you keep your code clean, potentially build faster, and reduces the brittleness of your code.
107108

108-
For a practical introduction to improving code quality and build times, see [Cleanup tool walkthrough - TBD naming](link-somewhere).\
109-
For more information about customizing how the #include cleanup generates suggestions for your project and across your team, see [Cleanup tool configuration reference](include-cleanup-config.md).
110-
111109
## See also
112110

113-
[Cleanup tool walkthrough - TBD naming](link-somewhere)\
114111
[Cleanup tool configuration reference](link-somewhere)

0 commit comments

Comments
 (0)