Skip to content

Commit

Permalink
Update StyleCop, add editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
dfederm committed Aug 8, 2024
1 parent f0f9ba4 commit 4939c76
Show file tree
Hide file tree
Showing 21 changed files with 477 additions and 77 deletions.
402 changes: 402 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

31 changes: 27 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
<Project>
<PropertyGroup>
<DefaultItemExcludes>*log</DefaultItemExcludes>
<Deterministic>true</Deterministic>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
<!-- Use the latest version of C# available -->
<LangVersion>Latest</LangVersion>

<!-- Don't allow warnings -->
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
<NoWarn>$(NoWarn);SA0001</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<!-- Enabled the built-in analyzers -->
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisMode>All</AnalysisMode>

<!-- Use Directory.Packages.props to manage versions -->
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>

<DefaultItemExcludes>*log</DefaultItemExcludes>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>

<!-- Required for IDE0005 -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<!--<NoWarn>$(NoWarn);SA0001</NoWarn>-->
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation>
<UseArtifactsOutput>true</UseArtifactsOutput>
<Deterministic>true</Deterministic>
</PropertyGroup>

<!-- StyleCop-->
<ItemGroup>
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Visible="false" />
</ItemGroup>
</Project>
9 changes: 1 addition & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="Microsoft.Build" Version="17.10.4" />
Expand All @@ -19,10 +16,6 @@
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
</ItemGroup>
<ItemGroup Condition="'$(EnableStyleCopAnalyzers)' != 'false'">
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<Compile Include="$(MSBuildThisFileDirectory)src\GlobalSuppressions.cs" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Visible="false" />
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions PackagesConfigConverter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackagesConfigConverter.Uni
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{724AF5A0-8E73-4CE7-A613-2C0FE768AB6A}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
Directory.Build.props = Directory.Build.props
Directory.Build.rsp = Directory.Build.rsp
Expand Down
14 changes: 0 additions & 14 deletions src/GlobalSuppressions.cs

This file was deleted.

3 changes: 1 addition & 2 deletions src/PackagesConfigConverter.UnitTests/E2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -120,4 +119,4 @@ public void E2ETest(string testCase)
Assert.Equal(expectedProjectContent, actualProjectContent);
}
}
}
}
4 changes: 2 additions & 2 deletions src/PackagesConfigConverter.UnitTests/XUnitLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// Licensed under the MIT license.

using Microsoft.Extensions.Logging;
using System;
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace PackagesConfigConverter.UnitTests
Expand All @@ -25,4 +25,4 @@ public IDisposable BeginScope<TState>(TState state)
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
=> _testOutputHelper.WriteLine(formatter(state, exception));
}
}
}
2 changes: 1 addition & 1 deletion src/PackagesConfigConverter/AnalyzerRegularExpressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// Licensed under the MIT license.

using NuGet.Packaging.Core;
using System.Text.RegularExpressions;
using NuGet.Packaging.Core;

namespace PackagesConfigConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// Licensed under the MIT license.

using NuGet.Packaging.Core;
using System.Text.RegularExpressions;
using NuGet.Packaging.Core;

namespace PackagesConfigConverter
{
Expand Down
2 changes: 1 addition & 1 deletion src/PackagesConfigConverter/ElementPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// Licensed under the MIT license.

using Microsoft.Build.Construction;
using System;
using Microsoft.Build.Construction;

namespace PackagesConfigConverter
{
Expand Down
2 changes: 1 addition & 1 deletion src/PackagesConfigConverter/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//
// Licensed under the MIT license.

using Microsoft.Build.Construction;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Xml;
using Microsoft.Build.Construction;

namespace PackagesConfigConverter
{
Expand Down
2 changes: 1 addition & 1 deletion src/PackagesConfigConverter/ImportRegularExpressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// Licensed under the MIT license.

using NuGet.Packaging.Core;
using System.Text.RegularExpressions;
using NuGet.Packaging.Core;

namespace PackagesConfigConverter
{
Expand Down
6 changes: 3 additions & 3 deletions src/PackagesConfigConverter/PackageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
//
// Licensed under the MIT license.

using NuGet.Packaging;
using NuGet.Packaging.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NuGet.Packaging;
using NuGet.Packaging.Core;

namespace PackagesConfigConverter
{
Expand Down Expand Up @@ -75,4 +75,4 @@ static bool HasAnyRealFiles(string dir)
}
}
}
}
}
6 changes: 3 additions & 3 deletions src/PackagesConfigConverter/PackageInfoFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
//
// Licensed under the MIT license.

using System.Collections.Concurrent;
using NuGet.Packaging;
using NuGet.Packaging.Core;
using System.Collections.Concurrent;

namespace PackagesConfigConverter
{
internal sealed class PackageInfoFactory
{
private readonly PackagePathResolver _packagePathResolver;
private readonly VersionFolderPathResolver _versionFolderPathResolver;
private readonly ConcurrentDictionary<PackageIdentity, PackageInfo> _packages = new ();
private readonly ConcurrentDictionary<PackageIdentity, PackageInfo> _packages = new();

public PackageInfoFactory(PackagePathResolver packagePathResolver, VersionFolderPathResolver versionFolderPathResolver)
{
Expand All @@ -22,4 +22,4 @@ public PackageInfoFactory(PackagePathResolver packagePathResolver, VersionFolder

public PackageInfo GetPackageInfo(PackageIdentity identity) => _packages.GetOrAdd(identity, id => new PackageInfo(id, _packagePathResolver, _versionFolderPathResolver));
}
}
}
15 changes: 7 additions & 8 deletions src/PackagesConfigConverter/PackageUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
//
// Licensed under the MIT license.

using System.Collections.Generic;
using System.Linq;
using CommandLine;
using Microsoft.Build.Construction;
using NuGet.Packaging.Core;
using NuGet.Versioning;
using System.Collections.Generic;
using System.Linq;

namespace PackagesConfigConverter
{
internal sealed class PackageUsage
{
public PackageUsage(PackageIdentity identity, PackageInfo packageInfo, bool isDevelopmentDependency)
public PackageUsage(PackageInfo packageInfo, bool isDevelopmentDependency)
{
PackageInfo = packageInfo;
IsDevelopmentDependency = isDevelopmentDependency;
Expand All @@ -25,11 +24,11 @@ public PackageUsage(PackageIdentity identity, PackageInfo packageInfo, bool isDe

public IEnumerable<ProjectElement> AllElements => AnalyzerItems.Cast<ProjectElement>().Concat(AssemblyReferences).Concat(Imports);

public List<ProjectItemElement> AnalyzerItems { get; } = new ();
public List<ProjectItemElement> AnalyzerItems { get; } = new();

public List<ProjectItemElement> AssemblyReferences { get; } = new ();
public List<ProjectItemElement> AssemblyReferences { get; } = new();

public List<ProjectImportElement> Imports { get; } = new ();
public List<ProjectImportElement> Imports { get; } = new();

public bool GeneratePathProperty { get; set; }

Expand All @@ -39,4 +38,4 @@ public PackageUsage(PackageIdentity identity, PackageInfo packageInfo, bool isDe

public NuGetVersion PackageVersion => PackageInfo.Identity.Version;
}
}
}
11 changes: 5 additions & 6 deletions src/PackagesConfigConverter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
//
// Licensed under the MIT license.

using CommandLine;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;

using CommandLine;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using ILogger = Microsoft.Extensions.Logging.ILogger;

namespace PackagesConfigConverter
Expand Down Expand Up @@ -79,7 +78,7 @@ public static void Run(ProgramArguments arguments)
if (!arguments.Yes)
{
Console.Write("Ensure there are no files checked out in git before continuing! Continue? (Y/N) ");
if (!Console.In.ReadLine() !.StartsWith("Y", StringComparison.OrdinalIgnoreCase))
if (!Console.In.ReadLine()!.StartsWith("Y", StringComparison.OrdinalIgnoreCase))
{
throw new OperationCanceledException();
}
Expand Down
27 changes: 13 additions & 14 deletions src/PackagesConfigConverter/ProjectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
//
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Xml.Linq;
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using Microsoft.Extensions.Logging;
Expand All @@ -17,28 +24,20 @@
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using NuGet.Versioning;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Xml.Linq;

using ILogger = Microsoft.Extensions.Logging.ILogger;

// ReSharper disable CollectionNeverUpdated.Local
namespace PackagesConfigConverter
{
internal sealed class ProjectConverter : IProjectConverter
{
private static readonly HashSet<string> ItemsToRemove = new (StringComparer.OrdinalIgnoreCase) { "packages.config" };
private static readonly HashSet<string> PropertiesToRemove = new (StringComparer.OrdinalIgnoreCase) { "NuGetPackageImportStamp" };
private static readonly HashSet<string> TargetsToRemove = new (StringComparer.OrdinalIgnoreCase) { "EnsureNuGetPackageBuildImports" };
private static readonly HashSet<string> ItemsToRemove = new(StringComparer.OrdinalIgnoreCase) { "packages.config" };
private static readonly HashSet<string> PropertiesToRemove = new(StringComparer.OrdinalIgnoreCase) { "NuGetPackageImportStamp" };
private static readonly HashSet<string> TargetsToRemove = new(StringComparer.OrdinalIgnoreCase) { "EnsureNuGetPackageBuildImports" };
private readonly ProjectConverterSettings _converterSettings;
private readonly string _globalPackagesFolder;
private readonly ISettings _nugetSettings;
private readonly ProjectCollection _projectCollection = new ();
private readonly ProjectCollection _projectCollection = new();
private readonly string _repositoryPath;
private readonly PackageInfoFactory _packageInfoFactory;
private readonly RestoreCommandProvidersCache _restoreCommandProvidersCache;
Expand Down Expand Up @@ -218,7 +217,7 @@ private bool ConvertProject(string projectPath, string packagesConfigPath)
.Select(i =>
{
PackageInfo packageInfo = _packageInfoFactory.GetPackageInfo(i.PackageIdentity);
return new PackageUsage(i.PackageIdentity, packageInfo, i.IsDevelopmentDependency);
return new PackageUsage(packageInfo, i.IsDevelopmentDependency);
})
.ToList();

Expand Down Expand Up @@ -311,7 +310,7 @@ private void DetectMissingTransitiveDependencies(List<PackageUsage> packages, st

PackageIdentity packageIdentity = new PackageIdentity(library.Name, library.Version);
PackageInfo packageInfo = _packageInfoFactory.GetPackageInfo(packageIdentity);
PackageUsage missingTransitiveDependency = new PackageUsage(packageIdentity, packageInfo, isDevelopmentDependency: false);
PackageUsage missingTransitiveDependency = new PackageUsage(packageInfo, isDevelopmentDependency: false);
missingTransitiveDependency.IsMissingTransitiveDependency = true;
packages.Add(missingTransitiveDependency);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PackagesConfigConverter/ProjectConverterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// Licensed under the MIT license.

using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging;

namespace PackagesConfigConverter
{
Expand Down
6 changes: 3 additions & 3 deletions src/PackagesConfigConverter/RegularExpressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace PackagesConfigConverter
{
internal static class RegularExpressions
{
public static AnalyzerRegularExpressions Analyzers { get; } = new ();
public static AnalyzerRegularExpressions Analyzers { get; } = new();

public static AssemblyReferenceRegularExpressions AssemblyReferences { get; } = new ();
public static AssemblyReferenceRegularExpressions AssemblyReferences { get; } = new();

public static ImportRegularExpressions Imports { get; } = new ();
public static ImportRegularExpressions Imports { get; } = new();
}
}
Loading

0 comments on commit 4939c76

Please sign in to comment.