Skip to content

Commit 84e1f6d

Browse files
committed
Essentially close #1681
1 parent a6dde40 commit 84e1f6d

13 files changed

+522
-81
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()).WhitelistedNames.Select(s => s.Name).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\WhitelistedNameSetting.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 WhitelistedNameSetting[] {});
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 WhitelistedNameSetting[] {})
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+
WhitelistedNameSetting[] WhitelistedNames { 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("WhitelistedName", IsNullable = false)]
23+
public WhitelistedNameSetting[] WhitelistedNames { get; set; }
24+
25+
public CodeInspectionSettings() : this(new HashSet<CodeInspectionSetting>(), new WhitelistedNameSetting[] {})
2226
{
23-
CodeInspections =new HashSet<CodeInspectionSetting>();
2427
}
2528

26-
public CodeInspectionSettings(HashSet<CodeInspectionSetting> inspections)
29+
public CodeInspectionSettings(HashSet<CodeInspectionSetting> inspections, WhitelistedNameSetting[] whitelistedNames)
2730
{
2831
CodeInspections = inspections;
32+
WhitelistedNames = 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 WhitelistedNameSetting
7+
{
8+
[XmlAttribute]
9+
public string Name { get; set; }
10+
11+
public WhitelistedNameSetting(string name)
12+
{
13+
Name = name;
14+
}
15+
16+
public WhitelistedNameSetting() : this("*") { }
17+
}
18+
}

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 9 additions & 0 deletions
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,4 +1763,7 @@ 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_WhitelistedNamesLabel" xml:space="preserve">
1767+
<value>Whitelisted Names</value>
1768+
</data>
17661769
</root>

0 commit comments

Comments
 (0)