Skip to content

Commit 36d2485

Browse files
committed
Merge remote-tracking branch 'DotNetAnalyzers/stabilization'
2 parents 90e043e + 834c2db commit 36d2485

38 files changed

Lines changed: 3392 additions & 172 deletions

LICENSE

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) Tunnel Vision Laboratories, LLC. All rights reserved.
1+
Copyright (c) Tunnel Vision Laboratories, LLC. All rights reserved.
22

33
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
44
these files except in compliance with the License. You may obtain a copy of the
@@ -45,3 +45,25 @@ Code Cracker
4545
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
4646
CONDITIONS OF ANY KIND, either express or implied. See the License for the
4747
specific language governing permissions and limitations under the License.
48+
49+
LightJson
50+
51+
Copyright (c) 2017 Marcos López C.
52+
53+
Permission is hereby granted, free of charge, to any person obtaining a copy
54+
of this software and associated documentation files (the "Software"), to deal
55+
in the Software without restriction, including without limitation the rights
56+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
57+
copies of the Software, and to permit persons to whom the Software is
58+
furnished to do so, subject to the following conditions:
59+
60+
The above copyright notice and this permission notice shall be included in
61+
all copies or substantial portions of the Software.
62+
63+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
64+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
65+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
66+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
67+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
68+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
69+
THE SOFTWARE.

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@
192192
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.2.1\lib\portable-net45+win8\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
193193
<Private>True</Private>
194194
</Reference>
195-
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
196-
<HintPath>..\..\packages\Newtonsoft.Json.7.0.1\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
197-
<Private>True</Private>
198-
</Reference>
199195
<Reference Include="System.Collections.Immutable, Version=1.1.37.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
200196
<HintPath>..\..\packages\System.Collections.Immutable.1.1.37\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
201197
<Private>True</Private>

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/StyleCop.Analyzers.nuspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<file src="bin\$Configuration$\StyleCop.Analyzers.CodeFixes.dll" target="analyzers\dotnet\cs" />
2525
<file src="bin\$Configuration$\**\StyleCop.Analyzers.CodeFixes.resources.dll" target="analyzers\dotnet\cs" />
2626
<file src="bin\$Configuration$\StyleCop.Analyzers.CodeFixes.pdb" target="analyzers\dotnet\cs" />
27-
<file src="..\..\packages\Newtonsoft.Json.7.0.1\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll" target="analyzers\dotnet\cs" />
2827

2928
<!-- Scripts -->
3029
<file src="tools\install.ps1" target="tools\" />

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="1.2.1" targetFramework="portable45-net45+win8" />
88
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="1.2.1" targetFramework="portable45-net45+win8" />
99
<package id="Microsoft.Composition" version="1.0.27" targetFramework="portable-net45+win8" />
10-
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="portable45-net45+win8" />
1110
<package id="NuGet.CommandLine" version="2.8.3" targetFramework="portable45-net45+win8" />
1211
<package id="StyleCop.Analyzers" version="1.1.0-beta001" targetFramework="portable45-net45+win8" developmentDependency="true" />
1312
<package id="System.Collections.Immutable" version="1.1.37" targetFramework="portable45-net45+win8" />

StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace TestHelper
99
using System.Linq;
1010
using System.Threading;
1111
using System.Threading.Tasks;
12+
using LightJson;
13+
using LightJson.Serialization;
1214
using Microsoft.CodeAnalysis;
1315
using Microsoft.CodeAnalysis.CSharp;
1416
using Microsoft.CodeAnalysis.Diagnostics;
1517
using Microsoft.CodeAnalysis.Formatting;
1618
using Microsoft.CodeAnalysis.Text;
17-
using Newtonsoft.Json;
18-
using Newtonsoft.Json.Linq;
1919
using StyleCop.Analyzers;
2020
using StyleCop.Analyzers.Settings.ObjectModel;
2121
using StyleCop.Analyzers.Test.Helpers;
@@ -156,9 +156,13 @@ protected virtual Solution CreateSolution(ProjectId projectId, string language)
156156
}
157157
else
158158
{
159-
JObject mergedSettings = JsonConvert.DeserializeObject<JObject>(settings);
160-
mergedSettings.Merge(JsonConvert.DeserializeObject<JObject>(indentationSettings));
161-
settings = JsonConvert.SerializeObject(mergedSettings);
159+
JsonObject indentationObject = JsonReader.Parse(indentationSettings);
160+
JsonObject settingsObject = JsonReader.Parse(settings);
161+
JsonObject mergedSettings = MergeJsonObjects(settingsObject, indentationObject);
162+
using (var writer = new JsonWriter(pretty: true))
163+
{
164+
settings = writer.Serialize(mergedSettings);
165+
}
162166
}
163167
}
164168

@@ -308,6 +312,35 @@ protected virtual Project ApplyCompilationOptions(Project project)
308312
return solution.GetProject(project.Id);
309313
}
310314

315+
private static JsonObject MergeJsonObjects(JsonObject priority, JsonObject fallback)
316+
{
317+
foreach (var pair in priority)
318+
{
319+
if (pair.Value.IsJsonObject)
320+
{
321+
switch (fallback[pair.Key].Type)
322+
{
323+
case JsonValueType.Null:
324+
fallback[pair.Key] = pair.Value;
325+
break;
326+
327+
case JsonValueType.Object:
328+
fallback[pair.Key] = MergeJsonObjects(pair.Value.AsJsonObject, fallback[pair.Key].AsJsonObject);
329+
break;
330+
331+
default:
332+
throw new InvalidOperationException($"Cannot merge objects of type '{pair.Value.Type}' and '{fallback[pair.Key].Type}'.");
333+
}
334+
}
335+
else
336+
{
337+
fallback[pair.Key] = pair.Value;
338+
}
339+
}
340+
341+
return fallback;
342+
}
343+
311344
/// <summary>
312345
/// Sort <see cref="Diagnostic"/>s by location in source document.
313346
/// </summary>

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,88 @@ public async Task VerifyInvalidReferenceBehaviorAsync()
148148
Assert.Equal("[InvalidReference]", styleCopSettings.DocumentationRules.GetCopyrightText("unused"));
149149
}
150150

151+
/// <summary>
152+
/// Verifies that the settings successfully parse line comments.
153+
/// </summary>
154+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
155+
[Fact]
156+
public async Task VerifySettingsSupportsLineCommentsAsync()
157+
{
158+
var settings = @"
159+
{
160+
// Set value for company name
161+
""settings"": {
162+
""documentationRules"": {
163+
""companyName"": ""TestCompany""
164+
}
165+
}
166+
}
167+
";
168+
var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false);
169+
170+
var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None);
171+
172+
Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName);
173+
Assert.Equal("Copyright (c) TestCompany. All rights reserved.", styleCopSettings.DocumentationRules.GetCopyrightText("unused"));
174+
}
175+
176+
/// <summary>
177+
/// Verifies that the settings successfully parse block comments.
178+
/// </summary>
179+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
180+
[Fact]
181+
public async Task VerifySettingsSupportsBlockCommentsAsync()
182+
{
183+
var settings = @"
184+
{
185+
/*
186+
* Set value for company name
187+
*/
188+
""settings"": {
189+
""documentationRules"": {
190+
""companyName"": ""TestCompany""
191+
}
192+
}
193+
}
194+
";
195+
var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false);
196+
197+
var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None);
198+
199+
Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName);
200+
Assert.Equal("Copyright (c) TestCompany. All rights reserved.", styleCopSettings.DocumentationRules.GetCopyrightText("unused"));
201+
}
202+
203+
/// <summary>
204+
/// Verifies that the settings successfully parse trailing commas.
205+
/// </summary>
206+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
207+
[Fact]
208+
public async Task VerifySettingsSupportsTrailingCommasAsync()
209+
{
210+
var settings = @"
211+
{
212+
""settings"": {
213+
""documentationRules"": {
214+
""companyName"": ""TestCompany"",
215+
},
216+
""namingRules"": {
217+
""allowedHungarianPrefixes"": [ ""a"", ],
218+
},
219+
}
220+
}
221+
";
222+
var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false);
223+
224+
var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None);
225+
226+
Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName);
227+
Assert.Equal("Copyright (c) TestCompany. All rights reserved.", styleCopSettings.DocumentationRules.GetCopyrightText("unused"));
228+
229+
Assert.Equal(1, styleCopSettings.NamingRules.AllowedHungarianPrefixes.Length);
230+
Assert.Equal("a", styleCopSettings.NamingRules.AllowedHungarianPrefixes[0]);
231+
}
232+
151233
[Fact]
152234
public async Task VerifyInvalidJsonBehaviorAsync()
153235
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpecialRules/SA0002UnitTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public async Task TestValidSettingsAsync()
4040
[Fact]
4141
public async Task TestInvalidSettingsAsync()
4242
{
43+
// The settings file is missing a comma after the $schema property
4344
this.settings = @"
4445
{
4546
""$schema"": ""https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json""
@@ -58,6 +59,25 @@ public async Task TestInvalidSettingsAsync()
5859
await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false);
5960
}
6061

62+
[Fact]
63+
public async Task TestInvalidSettingValueAsync()
64+
{
65+
this.settings = @"
66+
{
67+
""settings"": {
68+
""documentationRules"": {
69+
""companyName"": 3
70+
}
71+
}
72+
}
73+
";
74+
75+
// This diagnostic is reported without a location
76+
DiagnosticResult expected = this.CSharpDiagnostic();
77+
78+
await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false);
79+
}
80+
6181
[Fact]
6282
public async Task TestEmptySettingsAsync()
6383
{

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\..\packages\xunit.runner.visualstudio.2.2.0-beta4-build1194\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.2.0-beta4-build1194\build\net20\xunit.runner.visualstudio.props')" />
3+
<Import Project="..\..\packages\xunit.runner.visualstudio.2.3.0-beta1-build1309\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.3.0-beta1-build1309\build\net20\xunit.runner.visualstudio.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -64,10 +64,6 @@
6464
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.2.1\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
6565
<Private>True</Private>
6666
</Reference>
67-
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
68-
<HintPath>..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
69-
<Private>True</Private>
70-
</Reference>
7167
<Reference Include="System" />
7268
<Reference Include="System.Collections.Immutable, Version=1.1.37.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
7369
<HintPath>..\..\packages\System.Collections.Immutable.1.1.37\lib\dotnet\System.Collections.Immutable.dll</HintPath>
@@ -427,7 +423,7 @@
427423
<PropertyGroup>
428424
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
429425
</PropertyGroup>
430-
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.2.0-beta4-build1194\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.2.0-beta4-build1194\build\net20\xunit.runner.visualstudio.props'))" />
426+
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.3.0-beta1-build1309\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.3.0-beta1-build1309\build\net20\xunit.runner.visualstudio.props'))" />
431427
</Target>
432428
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
433429
Other similar extension points exist, see Microsoft.Common.targets.

StyleCop.Analyzers/StyleCop.Analyzers.Test/packages.config

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="1.2.1" targetFramework="net452" />
88
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="1.2.1" targetFramework="net452" />
99
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net452" />
10-
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
1110
<package id="StyleCop.Analyzers" version="1.1.0-beta001" targetFramework="net452" developmentDependency="true" />
1211
<package id="System.Collections" version="4.0.0" targetFramework="net452" />
1312
<package id="System.Collections.Immutable" version="1.1.37" targetFramework="net452" />
@@ -25,5 +24,5 @@
2524
<package id="xunit.core" version="2.2.0-beta4-build3444" targetFramework="net452" />
2625
<package id="xunit.extensibility.core" version="2.2.0-beta4-build3444" targetFramework="net452" />
2726
<package id="xunit.extensibility.execution" version="2.2.0-beta4-build3444" targetFramework="net452" />
28-
<package id="xunit.runner.visualstudio" version="2.2.0-beta4-build1194" targetFramework="net452" developmentDependency="true" />
27+
<package id="xunit.runner.visualstudio" version="2.3.0-beta1-build1309" targetFramework="net452" developmentDependency="true" />
2928
</packages>

0 commit comments

Comments
 (0)