Skip to content

Commit

Permalink
Merge remote-tracking branch 'DotNetAnalyzers/master' into SA1134NonD…
Browse files Browse the repository at this point in the history
…eterminism
  • Loading branch information
sharwell committed Dec 19, 2023
2 parents df70004 + 0fc865d commit 5431f37
Show file tree
Hide file tree
Showing 2,632 changed files with 71,703 additions and 10,989 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
root = true

[*.{csproj,props,targets}]
indent_style = space
indent_size = 2

[*.yml]
indent_style = space
indent_size = 2

[*.cs]
charset = utf-8-bom
insert_final_newline = true
Expand All @@ -8,6 +16,8 @@ indent_size = 4

# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false
csharp_using_directive_placement = inside_namespace:none

# Always use "this." and "Me." when applicable; let StyleCop Analyzers provide the warning and fix
dotnet_style_qualification_for_field = true:none
Expand Down
7 changes: 3 additions & 4 deletions .nuget/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Codecov" version="1.1.0" />
<package id="Microsoft.DiaSymReader.Pdb2Pdb" version="1.1.0-beta1-62624-01" />
<package id="CodecovUploader" version="0.7.1" />
<package id="OpenCover" version="4.6.519" />
<package id="ReportGenerator" version="2.3.5.0" targetFramework="net452" />
<package id="xunit.runner.console" version="2.1.0" targetFramework="net452" />
<package id="ReportGenerator" version="5.2.0" />
<package id="xunit.runner.console" version="2.4.1" />
</packages>
10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ for issues suitable if you are unfamiliar with roslyn.

You can also help by filing issues, participating in discussions and doing code review.

## Building prerequisites

* Visual Studio 2017 (Community Edition or higher) is required for building this repository.
* The version of the [.NET Core SDK](https://dotnet.microsoft.com/download/dotnet-core) as specified in the global.json file at the root of this repo.
Use the init script at the root of the repo to conveniently acquire and install the right version.

## Implementing a diagnostic

1. To start working on a diagnostic, add a comment to the issue indicating you are working on implementing it.
Expand All @@ -23,7 +29,3 @@ You can also help by filing issues, participating in discussions and doing code
2. A new issue was created for implementing tests for the item (e.g. #176).
3. Evidence was given that the feature is currently operational, and the code appears to be a solid starting point
for other contributors to continue the implementation effort.

## Building

Visual Studio 2017 (Community Edition or higher) is required for building this repository.
90 changes: 21 additions & 69 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,69 +1,21 @@
Copyright (c) Tunnel Vision Laboratories, LLC. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
these files except in compliance with the License. You may obtain a copy of the
License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

---

This project uses other open source projects, which are used under the terms
of the following license(s).

.NET Compiler Platform ("Roslyn")

Copyright Microsoft.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
these files except in compliance with the License. You may obtain a copy of the
License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

Code Cracker

Copyright 2014 Giovanni Bassi and Elemar Jr.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
these files except in compliance with the License. You may obtain a copy of the
License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

LightJson

Copyright (c) 2017 Marcos López C.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
MIT License

Copyright (c) Tunnel Vision Laboratories, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 6 additions & 4 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="roslyn" value="https://dotnet.myget.org/F/roslyn/api/v3/index.json" />
<add key="roslyn-analyzers" value="https://dotnet.myget.org/F/roslyn-analyzers/api/v3/index.json" />
<add key="symreader-converter" value="https://dotnet.myget.org/F/symreader-converter/api/v3/index.json" />
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />

<!-- Uncomment this to test unpublished builds from the AppVeyor feed. -->
<!--<add key="appveyor-stylecop" value="https://ci.appveyor.com/nuget/stylecopanalyzers-jqg4a6mt0hgj" />-->
<!--<add key="appveyor-stylecop" value="https://ci.appveyor.com/nuget/stylecopanalyzers" />-->
</packageSources>
</configuration>
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ Not all versions of StyleCop.Analyzers support all features of each C# language

| C# version | StyleCop.Analyzers version | Visual Studio version |
|------------|----------------------------|-----------------------|
| 1.0 - 6.0 | v1.0.2 or higher | VS2015+ |
| 7.0 - 7.3 | v1.1.0-beta or higher | VS2017 |
| 1.0 - 6.0 | v1.0.2 or higher | VS2015+ |
| 7.0 - 7.3 | v1.1.0-beta or higher | VS2017+ |
| 8.0 | v1.2.0-beta or higher | VS2019 |

## Installation

Expand Down
36 changes: 32 additions & 4 deletions StyleCop.Analyzers/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
</PropertyGroup>

<PropertyGroup>
<LangVersion>7.2</LangVersion>
<Features>strict</Features>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<WarningLevel>99</WarningLevel>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
Expand All @@ -20,7 +22,8 @@
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugType Condition="'$(Configuration)' == 'Debug'">full</DebugType>
<DebugType Condition="'$(Configuration)' != 'Debug'">portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

Expand All @@ -37,14 +40,39 @@
<NoWarn>$(NoWarn),1573,1591,1712</NoWarn>
</PropertyGroup>

<PropertyGroup>
<SharedMicrosoftCodeAnalysisAnalyzersVersion>3.11.0-beta1.23472.1</SharedMicrosoftCodeAnalysisAnalyzersVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="2.2.13" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AsyncUsageAnalyzers" Version="1.0.0-alpha003" PrivateAssets="all" />
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.46" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta.47" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(SharedMicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.0.1" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator" Version="$(SharedMicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
</ItemGroup>

<!-- C# Compiler -->
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.0.1" PrivateAssets="all" />
</ItemGroup>

<!-- Public API -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(SharedMicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="PublicAPI.Shipped.txt" Condition="Exists('PublicAPI.Shipped.txt')" />
<AdditionalFiles Include="PublicAPI.Unshipped.txt" Condition="Exists('PublicAPI.Unshipped.txt')" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 0 additions & 15 deletions StyleCop.Analyzers/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<ItemGroup>
<!-- Enable code generation for resource files -->
<CodeGenerationEmbeddedResource Include="@(EmbeddedResource)" Exclude="**\*.??-??.resx" />
<EmbeddedResource Update="@(CodeGenerationEmbeddedResource)" Generator="ResXFileCodeGenerator" />
</ItemGroup>

<!-- Special handling for embedded resources and generated files to show as nested in Solution Explorer -->
<ItemGroup>
<!-- Update designer files for *.resx files -->
<Compile Update="@(CodeGenerationEmbeddedResource->'%(RecursiveDir)%(Filename).Designer.cs')" DependentUpon="$([System.IO.Path]::ChangeExtension($([System.IO.Path]::GetFileNameWithoutExtension(%(Identity))), '.resx'))" />

<!-- Localized embedded resources are just dependent on the parent RESX -->
<EmbeddedResource Update="**\*.??-??.resx" DependentUpon="$([System.IO.Path]::ChangeExtension($([System.IO.Path]::GetFileNameWithoutExtension(%(Identity))), '.resx'))" />
</ItemGroup>

<ItemGroup>
<None Include="$(MSBuildProjectFileDirectory)$(AssemblyOriginatorKeyFile)" Link="%(Filename)%(Extension)" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.DocumentationRules
{
Expand Down Expand Up @@ -66,6 +68,9 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
return SpecializedTasks.CompletedTask;
}

private static string GetFileName(Document document)
=> Path.GetFileName(document.FilePath ?? document.Name);

private static async Task<Document> GetTransformedDocumentAsync(Document document, CancellationToken cancellationToken)
{
return document.WithSyntaxRoot(await GetTransformedSyntaxRootAsync(document, cancellationToken).ConfigureAwait(false));
Expand All @@ -74,13 +79,13 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen
private static async Task<SyntaxNode> GetTransformedSyntaxRootAsync(Document document, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(cancellationToken);
var settings = document.Project.AnalyzerOptions.GetStyleCopSettings(root.SyntaxTree, cancellationToken);

var fileHeader = FileHeaderHelpers.ParseFileHeader(root);
SyntaxNode newSyntaxRoot;
if (fileHeader.IsMissing)
{
newSyntaxRoot = AddHeader(document, root, document.Name, settings);
newSyntaxRoot = AddHeader(document, root, GetFileName(document), settings);
}
else
{
Expand Down Expand Up @@ -144,9 +149,9 @@ private static SyntaxNode ReplaceWellFormedMultiLineCommentHeader(Document docum
// Pad line that used to be next to a /*
triviaStringParts[0] = commentIndentation + interlinePadding + " " + triviaStringParts[0];
StringBuilder sb = StringBuilderPool.Allocate();
string fileName = Path.GetFileName(document.FilePath);
string fileName = GetFileName(document);
var copyrightText = GetCopyrightText(commentIndentation + interlinePadding, settings.DocumentationRules.GetCopyrightText(fileName), newLineText);
var newHeader = WrapInXmlComment(commentIndentation + interlinePadding, copyrightText, document.Name, settings, newLineText);
var newHeader = WrapInXmlComment(commentIndentation + interlinePadding, copyrightText, fileName, settings, newLineText);

sb.Append(commentIndentation);
sb.Append("/*");
Expand Down Expand Up @@ -310,13 +315,13 @@ private static SyntaxNode ReplaceHeader(Document document, SyntaxNode root, Styl
string newLineText = document.Project.Solution.Workspace.Options.GetOption(FormattingOptions.NewLine, LanguageNames.CSharp);
var newLineTrivia = SyntaxFactory.EndOfLine(newLineText);

var newHeaderTrivia = CreateNewHeader(leadingSpaces + "//", document.Name, settings, newLineText);
var newHeaderTrivia = CreateNewHeader(leadingSpaces + "//", GetFileName(document), settings, newLineText);
if (!isMalformedHeader && copyrightTriviaIndex.HasValue)
{
// Does the copyright element have leading whitespace? If so remove it.
if ((copyrightTriviaIndex.Value > 0) && trivia[copyrightTriviaIndex.Value - 1].IsKind(SyntaxKind.WhitespaceTrivia))
{
copyrightTriviaIndex = copyrightTriviaIndex - 1;
copyrightTriviaIndex--;
trivia = trivia.RemoveAt(copyrightTriviaIndex.Value);
}

Expand Down Expand Up @@ -444,12 +449,12 @@ private static SyntaxTriviaList RemoveHeaderDecorationLines(SyntaxTriviaList tri
for (int i = 0; i < trivia.Count; i++)
{
var triviaLine = trivia[i];
if (triviaLine.Kind() == SyntaxKind.SingleLineCommentTrivia && triviaLine.ToFullString().Contains(settings.DocumentationRules.HeaderDecoration))
if (triviaLine.IsKind(SyntaxKind.SingleLineCommentTrivia) && triviaLine.ToFullString().Contains(settings.DocumentationRules.HeaderDecoration))
{
decorationRemovalList.Add(i);

// also remove the line break
if (i + 1 < trivia.Count && trivia[i + 1].Kind() == SyntaxKind.EndOfLineTrivia)
if (i + 1 < trivia.Count && trivia[i + 1].IsKind(SyntaxKind.EndOfLineTrivia))
{
decorationRemovalList.Add(i + 1);
}
Expand Down
Loading

0 comments on commit 5431f37

Please sign in to comment.