Skip to content

Commit a87bb84

Browse files
authored
Merge pull request #2092 from Hosch250/Issue1681
Whitelisted identifiers
2 parents 5082a03 + 2219fc8 commit a87bb84

17 files changed

+584
-96
lines changed

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public Inspector(IGeneralConfigService configService, IEnumerable<IInspection> i
2525
_inspections = inspections;
2626

2727
_configService = configService;
28-
configService.SettingsChanged += ConfigServiceLanguageChanged;
28+
configService.SettingsChanged += ConfigServiceSettingsChanged;
2929
}
3030

31-
private void ConfigServiceLanguageChanged(object sender, EventArgs e)
31+
private void ConfigServiceSettingsChanged(object sender, EventArgs e)
3232
{
3333
UpdateInspectionSeverity();
3434
}
@@ -125,7 +125,7 @@ public void Dispose()
125125
{
126126
if (_configService != null)
127127
{
128-
_configService.SettingsChanged -= ConfigServiceLanguageChanged;
128+
_configService.SettingsChanged -= ConfigServiceSettingsChanged;
129129
}
130130
}
131131
}

RetailCoder.VBE/Inspections/UseMeaningfulNameInspection.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using Rubberduck.Parsing.Symbols;
56
using Rubberduck.Parsing.VBA;
7+
using Rubberduck.Settings;
8+
using Rubberduck.SettingsProvider;
69
using Rubberduck.UI;
710

811
namespace Rubberduck.Inspections
912
{
1013
public sealed class UseMeaningfulNameInspection : InspectionBase
1114
{
1215
private readonly IMessageBox _messageBox;
16+
private readonly IPersistanceService<CodeInspectionSettings> _settings;
1317

14-
public UseMeaningfulNameInspection(IMessageBox messageBox, RubberduckParserState state)
18+
public UseMeaningfulNameInspection(IMessageBox messageBox, RubberduckParserState state, IPersistanceService<CodeInspectionSettings> settings)
1519
: base(state, CodeInspectionSeverity.Suggestion)
1620
{
1721
_messageBox = messageBox;
22+
_settings = settings;
1823
}
1924

2025
public override string Description { get { return InspectionsUI.UseMeaningfulNameInspectionName; } }
2126
public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } }
2227

2328
public override IEnumerable<InspectionResultBase> GetInspectionResults()
2429
{
30+
var whitelistedNames = new List<string>();
31+
32+
try
33+
{
34+
whitelistedNames = _settings.Load(new CodeInspectionSettings()).WhitelistedIdentifiers.Select(s => s.Identifier).ToList();
35+
}
36+
catch (IOException) { }
37+
2538
var issues = UserDeclarations
26-
.Where(declaration => declaration.DeclarationType != DeclarationType.ModuleOption &&
39+
.Where(declaration => declaration.DeclarationType != DeclarationType.ModuleOption &&
40+
!whitelistedNames.Contains(declaration.IdentifierName) &&
2741
(declaration.IdentifierName.Length < 3 ||
2842
char.IsDigit(declaration.IdentifierName.Last()) ||
2943
!declaration.IdentifierName.Any(c =>

RetailCoder.VBE/Root/RubberduckModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public override void Load()
8585

8686
BindCommandsToMenuItems();
8787

88-
Rebind<Rubberduck.Parsing.ISinks>().To<Sinks>().InSingletonScope();
88+
Rebind<ISinks>().To<Sinks>().InSingletonScope();
8989
Rebind<IIndenter>().To<Indenter>().InSingletonScope();
9090
Rebind<IIndenterSettings>().To<IndenterSettings>();
9191
Bind<Func<IIndenterSettings>>().ToMethod(t => () => Kernel.Get<IGeneralConfigService>().LoadConfiguration().UserSettings.IndenterSettings);

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@
404404
<Compile Include="Settings\RubberduckHotkey.cs" />
405405
<Compile Include="Settings\ToDoListConfigProvider.cs" />
406406
<Compile Include="Settings\UnitTestConfigProvider.cs" />
407+
<Compile Include="Settings\WhitelistedIdentifierSetting.cs" />
407408
<Compile Include="Sinks.cs" />
408409
<Compile Include="UI\About\AboutControl.xaml.cs">
409410
<DependentUpon>AboutControl.xaml</DependentUpon>

RetailCoder.VBE/Settings/CodeInspectionConfigProvider.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ public CodeInspectionSettings Create(IEnumerable<IInspection> inspections)
2727
if (inspections == null) return null;
2828

2929
_inspections = inspections;
30-
var prototype = new CodeInspectionSettings(GetDefaultCodeInspections());
30+
var prototype = new CodeInspectionSettings(GetDefaultCodeInspections(), new WhitelistedIdentifierSetting[] {});
3131
return _persister.Load(prototype) ?? prototype;
3232
}
3333

3434
public CodeInspectionSettings CreateDefaults()
3535
{
3636
//This sucks.
37-
return _inspections != null ? new CodeInspectionSettings(GetDefaultCodeInspections()) : null;
37+
return _inspections != null
38+
? new CodeInspectionSettings(GetDefaultCodeInspections(), new WhitelistedIdentifierSetting[] {})
39+
: null;
3840
}
3941

4042
public void Save(CodeInspectionSettings settings)

RetailCoder.VBE/Settings/CodeInspectionSettings.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Rubberduck.Settings
1010
public interface ICodeInspectionSettings
1111
{
1212
HashSet<CodeInspectionSetting> CodeInspections { get; set; }
13+
WhitelistedIdentifierSetting[] WhitelistedIdentifiers { get; set; }
1314
}
1415

1516
[XmlType(AnonymousType = true)]
@@ -18,14 +19,17 @@ public class CodeInspectionSettings : ICodeInspectionSettings
1819
[XmlArrayItem("CodeInspection", IsNullable = false)]
1920
public HashSet<CodeInspectionSetting> CodeInspections { get; set; }
2021

21-
public CodeInspectionSettings()
22+
[XmlArrayItem("WhitelistedIdentifier", IsNullable = false)]
23+
public WhitelistedIdentifierSetting[] WhitelistedIdentifiers { get; set; }
24+
25+
public CodeInspectionSettings() : this(new HashSet<CodeInspectionSetting>(), new WhitelistedIdentifierSetting[] {})
2226
{
23-
CodeInspections =new HashSet<CodeInspectionSetting>();
2427
}
2528

26-
public CodeInspectionSettings(HashSet<CodeInspectionSetting> inspections)
29+
public CodeInspectionSettings(HashSet<CodeInspectionSetting> inspections, WhitelistedIdentifierSetting[] whitelistedNames)
2730
{
2831
CodeInspections = inspections;
32+
WhitelistedIdentifiers = whitelistedNames;
2933
}
3034

3135
public CodeInspectionSetting GetSetting(Type inspection)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Xml.Serialization;
2+
3+
namespace Rubberduck.Settings
4+
{
5+
[XmlType(AnonymousType = true)]
6+
public class WhitelistedIdentifierSetting
7+
{
8+
[XmlAttribute]
9+
public string Identifier { get; set; }
10+
11+
public WhitelistedIdentifierSetting(string identifier)
12+
{
13+
Identifier = identifier;
14+
}
15+
16+
public WhitelistedIdentifierSetting() : this("*") { }
17+
}
18+
}

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

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

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
15751575
<value>Parser Errors</value>
15761576
</data>
15771577
<data name="GeneralSettings_MinimumLogLevelLabel" xml:space="preserve">
1578-
<value>Minimum Log Level</value>
1578+
<value>Minimum Log Level:</value>
15791579
</data>
15801580
<data name="GeneralSettings_DebugLogLevel" xml:space="preserve">
15811581
<value>Debug</value>
@@ -1763,4 +1763,13 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
17631763
<data name="RegexAssistant_Title" xml:space="preserve">
17641764
<value>Regular Expression Analyzer</value>
17651765
</data>
1766+
<data name="CodeInspectionSettings_WhitelistedIdentifiersLabel" xml:space="preserve">
1767+
<value>Whitelisted Identifiers</value>
1768+
</data>
1769+
<data name="CodeInspectionSettings_InspectionSeveritySettingsLabel" xml:space="preserve">
1770+
<value>Inspection Severities</value>
1771+
</data>
1772+
<data name="CodeInspectionSettings_WhitelistedIdentifiersDescription" xml:space="preserve">
1773+
<value>These identifiers will be ignored by the 'Use meaningful names' inspection</value>
1774+
</data>
17661775
</root>

0 commit comments

Comments
 (0)