Skip to content

Commit 915f5bd

Browse files
Card 152: Support folder level cleanup exclusions.
1 parent cabce50 commit 915f5bd

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

CodeMaid/Logic/Cleaning/CodeCleanupAvailabilityLogic.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ internal bool CanCleanup(Document document, bool allowUserPrompts = false)
106106
document != null &&
107107
IsDocumentLanguageIncludedByOptions(document) &&
108108
!IsDocumentExcludedBecauseExternal(document, allowUserPrompts) &&
109-
!IsFileNameExcludedByOptions(document.Name) &&
109+
!IsFileNameExcludedByOptions(document.FullName) &&
110110
!IsParentCodeGeneratorExcludedByOptions(document);
111111
}
112112

@@ -121,7 +121,7 @@ internal bool CanCleanup(ProjectItem projectItem)
121121
projectItem != null &&
122122
projectItem.Kind == Constants.vsProjectItemKindPhysicalFile &&
123123
IsProjectItemLanguageIncludedByOptions(projectItem) &&
124-
!IsFileNameExcludedByOptions(projectItem.Name) &&
124+
!IsFileNameExcludedByOptions(projectItem) &&
125125
!IsParentCodeGeneratorExcludedByOptions(projectItem);
126126
}
127127

@@ -218,6 +218,24 @@ private bool IsDocumentLanguageIncludedByOptions(Document document)
218218
}
219219
}
220220

221+
/// <summary>
222+
/// Determines whether the specified project item has a filename which is excluded by configuration.
223+
/// </summary>
224+
/// <param name="projectItem">The project item.</param>
225+
/// <returns>True if the project item has a filename which is excluded, otherwise false.</returns>
226+
private bool IsFileNameExcludedByOptions(ProjectItem projectItem)
227+
{
228+
try
229+
{
230+
return IsFileNameExcludedByOptions(projectItem.FileNames[1]);
231+
}
232+
catch (Exception)
233+
{
234+
// Guard in case FileNames is ever invalid as there isn't a way to test the collection.
235+
return false;
236+
}
237+
}
238+
221239
/// <summary>
222240
/// Determines whether the specified filename is excluded by configuration.
223241
/// </summary>

CodeMaid/Properties/Settings.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodeMaid/Properties/Settings.settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<Value Profile="(Default)">True</Value>
4343
</Setting>
4444
<Setting Name="Cleaning_ExclusionExpression" Type="System.String" Scope="User">
45-
<Value Profile="(Default)">.*\.Designer\.cs||.*\.Designer\.vb||.*\.resx</Value>
45+
<Value Profile="(Default)">\.Designer\.cs$||\.Designer\.vb$||\.resx$</Value>
4646
</Setting>
4747
<Setting Name="Cleaning_IncludeCPlusPlus" Type="System.Boolean" Scope="User">
4848
<Value Profile="(Default)">True</Value>

CodeMaid/UI/Dialogs/Options/Cleaning/CleaningFileTypesDataTemplate.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<StackPanel>
4747
<CheckBox Content="T4 generated code" IsChecked="{Binding ExcludeT4GeneratedCode}" />
4848

49-
<TextBlock Text="Regular expressions that match file names to exclude (ex: .*\.resx )" Margin="5,5,5,0" />
49+
<TextBlock Text="Regular expressions that match path names to exclude (ex: \.resx$ or \\lib\\ )" Margin="5,5,5,0" />
5050
<TextBox Style="{DynamicResource TextBoxMultiLine}"
5151
Text="{Binding ExclusionExpression, Converter={x:Static cnv:StringReplaceConverter.DoublePipeToNewLine}, UpdateSourceTrigger=PropertyChanged}" />
5252
<TextBlock FontStyle="Italic" Text="Place each regular expression on a separate line" />

CodeMaid/app.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<value>True</value>
4949
</setting>
5050
<setting name="Cleaning_ExclusionExpression" serializeAs="String">
51-
<value>.*\.Designer\.cs||.*\.Designer\.vb||.*\.resx</value>
51+
<value>\.Designer\.cs$||\.Designer\.vb$||\.resx$</value>
5252
</setting>
5353
<setting name="Cleaning_IncludeCPlusPlus" serializeAs="String">
5454
<value>True</value>

0 commit comments

Comments
 (0)