Skip to content

Commit 2cbd373

Browse files
committed
Add NamingSettings to StyleCopSettings
1 parent 5030435 commit 2cbd373

5 files changed

Lines changed: 70 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public void VerifySettingsDefaults()
2525

2626
Assert.Equal("PlaceholderCompany", styleCopSettings.DocumentationRules.CompanyName);
2727
Assert.Equal("Copyright (c) PlaceholderCompany. All rights reserved.", styleCopSettings.DocumentationRules.CopyrightText);
28+
Assert.True(styleCopSettings.NamingRules.AllowCommonHungarianPrefixes);
29+
Assert.Equal(0, styleCopSettings.NamingRules.AllowedHungarianPrefixes.Length);
2830
}
2931

3032
/// <summary>
@@ -40,6 +42,10 @@ public async Task VerifySettingsAreReadCorrectlyAsync()
4042
""documentationRules"": {
4143
""companyName"": ""TestCompany"",
4244
""copyrightText"": ""Custom copyright text.""
45+
},
46+
""namingRules"": {
47+
""allowCommonHungarianPrefixes"": false,
48+
""allowedHungarianPrefixes"": [""a"", ""ab""]
4349
}
4450
}
4551
}
@@ -50,6 +56,8 @@ public async Task VerifySettingsAreReadCorrectlyAsync()
5056

5157
Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName);
5258
Assert.Equal("Custom copyright text.", styleCopSettings.DocumentationRules.CopyrightText);
59+
Assert.False(styleCopSettings.NamingRules.AllowCommonHungarianPrefixes);
60+
Assert.Equal(new[] { "a", "ab" }, styleCopSettings.NamingRules.AllowedHungarianPrefixes);
5361
}
5462

5563
/// <summary>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Settings.ObjectModel
5+
{
6+
using System.Collections.Immutable;
7+
using Newtonsoft.Json;
8+
9+
[JsonObject(MemberSerialization.OptIn)]
10+
internal class NamingSettings
11+
{
12+
/// <summary>
13+
/// This is the backing field for the <see cref="AllowCommonHungarianPrefixes"/> property.
14+
/// </summary>
15+
[JsonProperty("allowCommonHungarianPrefixes", DefaultValueHandling = DefaultValueHandling.Include)]
16+
private bool allowCommonHungarianPrefixes;
17+
18+
/// <summary>
19+
/// This is the backing field for the <see cref="AllowedHungarianPrefixes"/> property.
20+
/// </summary>
21+
[JsonProperty("allowedHungarianPrefixes", DefaultValueHandling = DefaultValueHandling.Ignore)]
22+
private ImmutableArray<string>.Builder allowedHungarianPrefixes;
23+
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="NamingSettings"/> class during JSON deserialization.
26+
/// </summary>
27+
[JsonConstructor]
28+
protected internal NamingSettings()
29+
{
30+
this.allowCommonHungarianPrefixes = true;
31+
this.allowedHungarianPrefixes = ImmutableArray<string>.Empty.ToBuilder();
32+
}
33+
34+
public bool AllowCommonHungarianPrefixes =>
35+
this.allowCommonHungarianPrefixes;
36+
37+
public ImmutableArray<string> AllowedHungarianPrefixes
38+
{
39+
get
40+
{
41+
return this.allowedHungarianPrefixes.ToImmutable();
42+
}
43+
}
44+
}
45+
}

StyleCop.Analyzers/StyleCop.Analyzers/Settings/ObjectModel/StyleCopSettings.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ internal class StyleCopSettings
1414
[JsonProperty("documentationRules", DefaultValueHandling = DefaultValueHandling.Ignore)]
1515
private DocumentationSettings documentationRules;
1616

17+
/// <summary>
18+
/// This is the backing field for the <see cref="NamingRules"/> property.
19+
/// </summary>
20+
[JsonProperty("namingRules", DefaultValueHandling = DefaultValueHandling.Ignore)]
21+
private NamingSettings namingRules;
22+
1723
/// <summary>
1824
/// Initializes a new instance of the <see cref="StyleCopSettings"/> class during JSON deserialization.
1925
/// </summary>
2026
[JsonConstructor]
2127
protected internal StyleCopSettings()
2228
{
2329
this.documentationRules = new DocumentationSettings();
30+
this.namingRules = new NamingSettings();
2431
}
2532

2633
public DocumentationSettings DocumentationRules
@@ -30,5 +37,13 @@ public DocumentationSettings DocumentationRules
3037
return this.documentationRules;
3138
}
3239
}
40+
41+
public NamingSettings NamingRules
42+
{
43+
get
44+
{
45+
return this.namingRules;
46+
}
47+
}
3348
}
3449
}

StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"default": [ ],
8181
"items": {
8282
"type": "string",
83+
"pattern": "^[a-z]{1,2}$",
8384
"uniqueItems": true
8485
}
8586
}

StyleCop.Analyzers/StyleCop.Analyzers/StyleCop.Analyzers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@
330330
<Compile Include="ReadabilityRules\SA1133DoNotCombineAttributes.cs" />
331331
<Compile Include="ReadabilityRules\SA1134AttributesMustNotShareLine.cs" />
332332
<Compile Include="Settings\ObjectModel\DocumentationSettings.cs" />
333+
<Compile Include="Settings\ObjectModel\NamingSettings.cs" />
333334
<Compile Include="Settings\ObjectModel\SettingsFile.cs" />
334335
<Compile Include="Settings\ObjectModel\StyleCopSettings.cs" />
335336
<Compile Include="Settings\SettingsFileCodeFixProvider.cs" />

0 commit comments

Comments
 (0)