Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #1212

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions Fody.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=FE2F1D5B_002D5931_002D413B_002DB376_002DDD491BD63610/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeAccessorOwnerBody/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeMethodOrOperatorBody/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeRedundantParentheses/@EntryIndexedValue">ERROR</s:String>
Expand Down
2 changes: 0 additions & 2 deletions Fody/AssemblyPathValidator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.IO;

public partial class Processor
{
public virtual void ValidateAssemblyPath()
Expand Down
2 changes: 0 additions & 2 deletions Fody/BuildLogger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using Fody;
using Microsoft.Build.Framework;

public class BuildLogger :
Expand Down
19 changes: 6 additions & 13 deletions Fody/ConfigFileFinder/ConfigFileFinder.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;

public static class ConfigFileFinder
public static class ConfigFileFinder
{
const string FodyWeaversConfigFileName = "FodyWeavers.xml";
static readonly XNamespace schemaNamespace = XNamespace.Get("http://www.w3.org/2001/XMLSchema");
Expand Down Expand Up @@ -77,7 +70,7 @@ public static WeaverConfigFile GenerateDefault(string projectDirectory, List<Wea
var weaverConfig = new XDocument(root);

var elements = weaverEntries
.Select(entry => new XElement(entry.ElementName))
.Select(_ => new XElement(_.ElementName))
.ToArray();

root.Add(elements);
Expand Down Expand Up @@ -105,7 +98,7 @@ static void CreateSchemaForConfig(string projectConfigFilePath, IEnumerable<Weav
{
var schema = XDocument.Parse(Fody.Properties.Resources.FodyWeavers_SchemaTemplate);

var baseNode = schema.Descendants().First(item => item.Name == schemaNamespace.GetName("all"));
var baseNode = schema.Descendants().First(_ => _.Name == schemaNamespace.GetName("all"));

var fragments = weavers.Select(CreateItemFragment);

Expand Down Expand Up @@ -182,9 +175,9 @@ public static void EnsureSchemaIsUpToDate(string projectDirectory, IEnumerable<W
}

var hasNamespace = doc.Root.Attributes()
.Any(attr => !attr.IsNamespaceDeclaration &&
attr.Name.LocalName == "noNamespaceSchemaLocation" &&
string.Equals(attr.Value, "FodyWeavers.xsd", StringComparison.OrdinalIgnoreCase));
.Any(_ => !_.IsNamespaceDeclaration &&
_.Name.LocalName == "noNamespaceSchemaLocation" &&
string.Equals(_.Value, "FodyWeavers.xsd", StringComparison.OrdinalIgnoreCase));

if (!hasNamespace)
{
Expand Down
4 changes: 1 addition & 3 deletions Fody/ConfigFileFinder/WeaverConfigFile.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Xml.Linq;

public class WeaverConfigFile
public class WeaverConfigFile
{
public readonly bool AllowExtraEntries;
public readonly string? FilePath;
Expand Down
6 changes: 1 addition & 5 deletions Fody/DomainAssemblyResolver.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
using System.Linq;
using System.Reflection;

public static class DomainAssemblyResolver
{
public static void Connect() =>
AppDomain.CurrentDomain.AssemblyResolve += (_, args) => GetAssembly(args.Name);

public static Assembly? GetAssembly(string name) =>
AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => string.Equals(x.FullName, name, StringComparison.OrdinalIgnoreCase));
AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(_ => string.Equals(_.FullName, name, StringComparison.OrdinalIgnoreCase));
}
6 changes: 2 additions & 4 deletions Fody/ExceptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;

public static class ExceptionExtensions
{
public static void LogException(this ILogger logger, Exception exception)
{
var exceptionType = exception.GetType();
if (exceptionType.Name == "WeavingException")
var type = exception.GetType();
if (type.Name == "WeavingException")
{
logger.LogError(exception.Message);
}
Expand Down
6 changes: 2 additions & 4 deletions Fody/ExtractConstants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Collections.Generic;
using System.Linq;

static class ExtractConstants
{
internal static List<string> GetConstants(this string? input)
Expand All @@ -9,6 +6,7 @@ internal static List<string> GetConstants(this string? input)
{
return new();
}

return input.Split(';').ToList();
}
}
}
13 changes: 13 additions & 0 deletions Fody/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Global using directives

global using System;
global using System.Collections.Generic;
global using System.Diagnostics;
global using System.Diagnostics.CodeAnalysis;
global using System.Text.RegularExpressions;
global using System.IO;
global using System.Linq;
global using System.Reflection;
global using System.Xml;
global using System.Xml.Linq;
global using Fody;
12 changes: 4 additions & 8 deletions Fody/Processor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

public partial class Processor
{
public string AssemblyFilePath = null!;
Expand Down Expand Up @@ -81,7 +76,8 @@ void Inner()
ConfigEntries = ConfigFileFinder.ParseWeaverConfigEntries(ConfigFiles);

var extraEntries = ConfigEntries.Values
.Where(entry => !entry.ConfigFile.AllowExtraEntries && !Weavers.Any(weaver => string.Equals(weaver.ElementName, entry.ElementName)))
.Where(entry => !entry.ConfigFile.AllowExtraEntries &&
Weavers.All(weaver => weaver.ElementName != entry.ElementName))
.ToArray();

const string missingWeaversHelp = "Add the desired weavers via their nuget package.";
Expand Down Expand Up @@ -113,8 +109,8 @@ void Inner()
ConfigFileFinder.EnsureSchemaIsUpToDate(ProjectDirectory, Weavers, GenerateXsd);

Weavers = Weavers
.Where(weaver => weaver.Element != null)
.OrderBy(weaver => weaver.ExecutionOrder)
.Where(_ => _.Element != null)
.OrderBy(_ => _.ExecutionOrder)
.ToList();

lock (mutex)
Expand Down
2 changes: 0 additions & 2 deletions Fody/ProjectPathFinder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.IO;

public partial class Processor
{
public virtual void ValidateProjectPath()
Expand Down
2 changes: 0 additions & 2 deletions Fody/SolutionDirectoryFinder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.IO;

public class SolutionDirectoryFinder
{
public static string Find(string? solutionDir, string? nCrunchOriginalSolutionDir, string projectDirectory)
Expand Down
2 changes: 0 additions & 2 deletions Fody/SolutionPathValidator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.IO;

public partial class Processor
{
public virtual void ValidateSolutionPath()
Expand Down
10 changes: 3 additions & 7 deletions Fody/UpdateReferenceCopyLocalTask.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

Expand Down Expand Up @@ -38,11 +34,11 @@ void InnerExecute()
var referenceCopyLocalPaths = new HashSet<string>(CopyLocalFiles.Select(_ => _.ItemSpec), StringComparer.OrdinalIgnoreCase);

var existingReferenceCopyLocalFiles = CopyLocalFiles
.Where(item => updatedReferenceCopyLocalPaths.Contains(item.ItemSpec));
.Where(_ => updatedReferenceCopyLocalPaths.Contains(_.ItemSpec));

var newReferenceCopyLocalFiles = updatedReferenceCopyLocalPaths
.Where(item => !referenceCopyLocalPaths.Contains(item))
.Select(item => new TaskItem(item));
.Where(_ => !referenceCopyLocalPaths.Contains(_))
.Select(_ => new TaskItem(_));

UpdatedCopyLocalFiles = existingReferenceCopyLocalFiles.Concat(newReferenceCopyLocalFiles).ToArray();
}
Expand Down
18 changes: 8 additions & 10 deletions Fody/Verify/Verifier.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Fody;

public class Verifier
public class Verifier
{
public ILogger Logger = null!;
public string SolutionDirectory = null!;
Expand Down Expand Up @@ -94,6 +87,7 @@ public static bool ExtractVerifyAssemblyFromConfigs(IEnumerable<WeaverConfigFile
return value;
}
}

return false;
}

Expand All @@ -103,12 +97,16 @@ public static IEnumerable<string> ExtractVerifyIgnoreCodesConfigs(IEnumerable<We
{
var configXml = configFile.Document;
var element = configXml.Root;
var codesConfigs = (string)element.Attribute("VerifyIgnoreCodes");
var codesConfigs = (string) element.Attribute("VerifyIgnoreCodes");
if (string.IsNullOrWhiteSpace(codesConfigs))
{
continue;
}
foreach (var value in codesConfigs.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries))

foreach (var value in codesConfigs.Split(new[]
{
','
}, StringSplitOptions.RemoveEmptyEntries))
{
yield return value;
}
Expand Down
4 changes: 0 additions & 4 deletions Fody/WeaversHistory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;

public static class WeaversHistory
{
public static Dictionary<string, DateTime> TimeStamps = new(StringComparer.OrdinalIgnoreCase);
Expand Down
10 changes: 1 addition & 9 deletions Fody/WeavingException.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
using System;

class WeavingException : Exception
{
public WeavingException(string message)
: base(message)
{
}
}
class WeavingException(string message) : Exception(message);
18 changes: 7 additions & 11 deletions Fody/WeavingTask.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

Expand Down Expand Up @@ -141,11 +137,11 @@ public List<WeaverEntry> GetWeaversFromProps()

return WeaverFiles
.Select(
taskItem => new
_ => new
{
taskItem.ItemSpec,
ClassNames = GetConfiguredClassNames(taskItem),
PackageReference = GetPackageReference(taskItem)
_.ItemSpec,
ClassNames = GetConfiguredClassNames(_),
PackageReference = GetPackageReference(_)
})
.SelectMany(entry => entry.ClassNames.Select(
className =>
Expand All @@ -163,14 +159,14 @@ public List<WeaverEntry> GetWeaversFromProps()
static IEnumerable<string> GetConfiguredClassNames(ITaskItem taskItem) =>
taskItem.GetMetadata("WeaverClassNames")
.Split(';')
.Select(name => name.Trim())
.Where(name => !string.IsNullOrEmpty(name))
.Select(_ => _.Trim())
.Where(_ => !string.IsNullOrEmpty(_))
.DefaultIfEmpty();

ITaskItem? GetPackageReference(ITaskItem weaverFileItem)
{
var packageName = Path.GetFileNameWithoutExtension(weaverFileItem.ItemSpec);
return PackageReferences?.FirstOrDefault(p => string.Equals(p.ItemSpec, packageName, StringComparison.OrdinalIgnoreCase));
return PackageReferences?.FirstOrDefault(_ => string.Equals(_.ItemSpec, packageName, StringComparison.OrdinalIgnoreCase));
}

public void Cancel() =>
Expand Down
9 changes: 2 additions & 7 deletions Fody/XmlExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;

public static class XmlExtensions
{
public static void StripNamespace(this XDocument document)
Expand All @@ -20,8 +15,8 @@ public static void StripNamespace(this XDocument document)

static IEnumerable<XAttribute> GetAttributes(XElement xElement) =>
xElement.Attributes()
.Where(x => !x.IsNamespaceDeclaration)
.Select(x => new XAttribute(x.Name.LocalName, x.Value));
.Where(_ => !_.IsNamespaceDeclaration)
.Select(_ => new XAttribute(_.Name.LocalName, _.Value));

public static bool TryReadBool(this XElement config, string nodeName, out bool value)
{
Expand Down
2 changes: 0 additions & 2 deletions FodyCommon/AssemblyLocation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.IO;

public static class AssemblyLocation
{
static AssemblyLocation()
Expand Down