diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..c6cb1f564f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,184 @@ +# editorconfig.org + +# top-most EditorConfig file +root = true + +# Default settings: +# A newline ending every file +# Use 4 spaces as indentation +[*] +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +# Generated code +[*{_AssemblyInfo.cs,.notsupported.cs,AsmOffsets.cs}] +generated_code = true + +# C# files +[*.cs] +# New line preferences +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_switch_labels = true +csharp_indent_labels = one_less_than_current + +# Modifier preferences +csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async:suggestion + +# avoid this. unless absolutely necessary +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_event = false:suggestion + +# Types: use keywords instead of BCL types, and permit var only when the type is clear +csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_when_type_is_apparent = false:none +csharp_style_var_elsewhere = false:suggestion +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion + +# name all constant fields using PascalCase +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.required_modifiers = const +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# static fields should have s_ prefix +dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion +dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields +dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style +dotnet_naming_symbols.static_fields.applicable_kinds = field +dotnet_naming_symbols.static_fields.required_modifiers = static +dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected +dotnet_naming_style.static_prefix_style.required_prefix = s_ +dotnet_naming_style.static_prefix_style.capitalization = camel_case + +# internal and private fields should be _camelCase +dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion +dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_symbols.private_internal_fields.applicable_kinds = field +dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal +dotnet_naming_style.camel_case_underscore_style.required_prefix = _ +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case + +# Code style defaults +csharp_using_directive_placement = outside_namespace:suggestion +dotnet_sort_system_directives_first = true +csharp_prefer_braces = true:silent +csharp_preserve_single_line_blocks = true:none +csharp_preserve_single_line_statements = false:none +csharp_prefer_static_local_function = true:suggestion +csharp_prefer_simple_using_statement = false:none +csharp_style_prefer_switch_expression = true:suggestion +dotnet_style_readonly_field = true:suggestion + +# Expression-level preferences +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +csharp_prefer_simple_default_expression = true:suggestion + +# Expression-bodied members +csharp_style_expression_bodied_methods = true:silent +csharp_style_expression_bodied_constructors = true:silent +csharp_style_expression_bodied_operators = true:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = true:silent + +# Pattern matching +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion + +# Null checking preferences +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion + +# Other features +csharp_style_prefer_index_operator = false:none +csharp_style_prefer_range_operator = false:none +csharp_style_pattern_local_over_anonymous_function = false:none + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = do_not_ignore +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# License header +file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license. + +# Xml project files +[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] +indent_size = 2 + +[*.{csproj,vbproj,proj,nativeproj,locproj}] +charset = utf-8 + +# Xml build files +[*.builds] +indent_size = 2 + +# Xml files +[*.{xml,stylecop,resx,ruleset}] +indent_size = 2 + +# Xml config files +[*.{props,targets,config,nuspec}] +indent_size = 2 + +# YAML config files +[*.{yml,yaml}] +indent_size = 2 + +# Shell scripts +[*.sh] +end_of_line = lf +[*.{cmd,bat}] +end_of_line = crlf diff --git a/src/packageSourceGenerator/PackageSourceGeneratorTask/GenerateProject.cs b/src/packageSourceGenerator/PackageSourceGeneratorTask/GenerateProject.cs index d4b1de7034..e6155a772b 100644 --- a/src/packageSourceGenerator/PackageSourceGeneratorTask/GenerateProject.cs +++ b/src/packageSourceGenerator/PackageSourceGeneratorTask/GenerateProject.cs @@ -41,7 +41,7 @@ public class GenerateProject : Task [Required] public required string ProjectRoot { get; set; } - /// + /// /// The package's compile items, including target framework metadata. /// public ITaskItem[] CompileItems { get; set; } = Array.Empty(); @@ -72,16 +72,16 @@ public override bool Execute() if (targetFrameworks.Length == 0) targetFrameworks = PackageDependencies.Select(packageDependency => packageDependency.GetMetadata(SharedMetadata.TargetFrameworkMetadataName)).ToArray(); - + if (targetFrameworks.Length == 0) targetFrameworks = FrameworkReferences.Select(frameworkReference => frameworkReference.GetMetadata(SharedMetadata.TargetFrameworkMetadataName)).ToArray(); - + targetFrameworks = targetFrameworks.Distinct() .Order() .ToArray(); // If no target framework is supplied, fallback to netstandard2.0. - projectContent = projectContent.Replace("$$TargetFrameworks$$", + projectContent = projectContent.Replace("$$TargetFrameworks$$", targetFrameworks.Length > 0 ? string.Join(';', targetFrameworks) : "netstandard2.0"); projectContent = projectContent.Replace("$$PackageVersion$$", PackageVersion); @@ -95,7 +95,7 @@ public override bool Execute() foreach (ITaskItem packageDependency in PackageDependencies.Where(packageDependency => packageDependency.GetMetadata(SharedMetadata.TargetFrameworkMetadataName) == targetFramework)) { string dependencyVersion = packageDependency.GetMetadata("Version"); - string dependencyProjectRelativePath = Path.Combine(packageDependency.ItemSpec.ToLowerInvariant(), dependencyVersion, $"{packageDependency.ItemSpec}.{dependencyVersion}.csproj"); + string dependencyProjectRelativePath = Path.Combine(packageDependency.ItemSpec.ToLowerInvariant(), dependencyVersion, $"{packageDependency.ItemSpec}.{dependencyVersion}.csproj"); // If the dependency is on the package reference allowed list (i.e. for source-build-externals packages like Newtonsoft.Json), emit a package reference. Otherwise, emit a project reference. if (AllowedPackageReference is not null && AllowedPackageReference.Contains(packageDependency.ItemSpec)) diff --git a/src/packageSourceGenerator/PackageSourceGeneratorTask/GetPackageItems.cs b/src/packageSourceGenerator/PackageSourceGeneratorTask/GetPackageItems.cs index 52ce87da29..41bab70422 100644 --- a/src/packageSourceGenerator/PackageSourceGeneratorTask/GetPackageItems.cs +++ b/src/packageSourceGenerator/PackageSourceGeneratorTask/GetPackageItems.cs @@ -3,16 +3,16 @@ using System; using System.Collections.Generic; -using System.Linq; using System.IO; +using System.Linq; using System.Reflection; using System.Text.RegularExpressions; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using NuGet.Client; using NuGet.ContentModel; -using NuGet.Packaging; using NuGet.Frameworks; +using NuGet.Packaging; using NuGet.Packaging.Core; namespace Microsoft.DotNet.SourceBuild.Tasks diff --git a/tests/SbrpTests/DummyAttributeTypeProvider.cs b/tests/SbrpTests/DummyAttributeTypeProvider.cs index f902b4320a..dc31aea972 100644 --- a/tests/SbrpTests/DummyAttributeTypeProvider.cs +++ b/tests/SbrpTests/DummyAttributeTypeProvider.cs @@ -25,6 +25,6 @@ internal class DummyAttributeTypeProvider : ICustomAttributeTypeProvider public Type? GetTypeFromSerializedName(string name) => default(Type); public PrimitiveTypeCode GetUnderlyingEnumType(Type? type) => default(PrimitiveTypeCode); - + public bool IsSystemType(Type? type) => default(bool); } diff --git a/tests/SbrpTests/ExecuteHelper.cs b/tests/SbrpTests/ExecuteHelper.cs index 8645963150..4c856dc0ce 100755 --- a/tests/SbrpTests/ExecuteHelper.cs +++ b/tests/SbrpTests/ExecuteHelper.cs @@ -18,7 +18,7 @@ public static (Process Process, string StdOut, string StdErr) ExecuteProcess( bool logOutput = false, Action? configure = null, int millisecondTimeout = -1) - { + { outputHelper.WriteLine($"Executing: {fileName} {args}"); Process process = new() @@ -116,4 +116,4 @@ public static void ValidateExitCode((Process Process, string StdOut, string StdE throw new InvalidOperationException(msg); } } -} \ No newline at end of file +} diff --git a/tests/SbrpTests/GenerateScriptTests.cs b/tests/SbrpTests/GenerateScriptTests.cs index a0ab048521..41f044a03b 100755 --- a/tests/SbrpTests/GenerateScriptTests.cs +++ b/tests/SbrpTests/GenerateScriptTests.cs @@ -27,7 +27,7 @@ public enum PackageType new object[] { "System.Buffers", "4.6.0", PackageType.Reference }, new object[] { "System.Security.Cryptography.ProtectedData", "8.0.0", PackageType.Reference }, }; - + public string SandboxDirectory { get; set; } public ITestOutputHelper Output { get; set; } @@ -38,7 +38,7 @@ public GenerateScriptTests(ITestOutputHelper output) Directory.CreateDirectory(SandboxDirectory); } - [Theory] + [Theory] [MemberData(nameof(GenerateScriptTests.Data), MemberType = typeof(GenerateScriptTests))] public void VerifyGenerateScript(string package, string version, PackageType type) { @@ -77,7 +77,7 @@ public void VerifyGenerateScript(string package, string version, PackageType typ } } - (Process Process, string StdOut, string StdErr) result = + (Process Process, string StdOut, string StdErr) result = ExecuteHelper.ExecuteProcess("git", $"diff --no-index {pkgSrcDirectory} {pkgSandboxDirectory}", Output, true); string diff = result.StdOut; diff --git a/tests/SbrpTests/PathUtilities.cs b/tests/SbrpTests/PathUtilities.cs index 8392af4cbe..61e5f8578e 100644 --- a/tests/SbrpTests/PathUtilities.cs +++ b/tests/SbrpTests/PathUtilities.cs @@ -9,18 +9,18 @@ namespace SbrpTests; internal static class PathUtilities { - public static string GetRepoRoot () => + public static string GetRepoRoot() => (string)AppContext.GetData("SbrpTests.RepoRoot")!; - public static string GetSourceBuildRepoRoot () + public static string GetSourceBuildRepoRoot() { - var artifactsDir = (string)AppContext.GetData ("SbrpTests.ArtifactsDir")!; + var artifactsDir = (string)AppContext.GetData("SbrpTests.ArtifactsDir")!; return Path.Combine(artifactsDir, "sb", "src"); } - - public static string GetSourceBuildPackagesShippingDir () + + public static string GetSourceBuildPackagesShippingDir() { - var configuration = (string)AppContext.GetData ("SbrpTests.Configuration")!; + var configuration = (string)AppContext.GetData("SbrpTests.Configuration")!; return Path.Combine(GetSourceBuildRepoRoot(), "artifacts", "packages", configuration, "Shipping"); } } diff --git a/tests/SbrpTests/ValidationTests.cs b/tests/SbrpTests/ValidationTests.cs index a8213fc097..049b1f2b18 100644 --- a/tests/SbrpTests/ValidationTests.cs +++ b/tests/SbrpTests/ValidationTests.cs @@ -35,10 +35,10 @@ public ValidationTests(ITestOutputHelper output) [SkippableFact] public void ValidateSbrpAttribute() - { + { string[] packages = GetPackages(); - HashSet targetAndTextOnlyPacks = new ( + HashSet targetAndTextOnlyPacks = new( Directory.GetDirectories(Path.Combine(PathUtilities.GetSourceBuildRepoRoot(), "src/targetPacks/ILsrc")) .Union(Directory.GetDirectories(Path.Combine(PathUtilities.GetSourceBuildRepoRoot(), "src/textOnlyPackages/src"))) .Select(x => Path.GetFileName(x).ToLower()) @@ -66,8 +66,8 @@ public void ValidateSbrpAttribute() foreach (var dll in dlls) { - using FileStream stream = new (dll, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - using PEReader peReader = new (stream); + using FileStream stream = new(dll, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + using PEReader peReader = new(stream); MetadataReader reader = peReader.GetMetadataReader(); Assert.True(HasSbrpAttribute(reader), $"{package}/{Path.GetRelativePath(tempDirectory, dll)} does not contain the {SbrpAttributeType} attribute with key='source' and value='{SbrpRepoIdentifier}'."); @@ -86,7 +86,7 @@ public async Task ValidateSignatures() string[] packages = GetPackages(); ISignatureVerificationProvider[] trustProviders = [new SignatureTrustAndValidityVerificationProvider()]; - PackageSignatureVerifier verifier = new (trustProviders); + PackageSignatureVerifier verifier = new(trustProviders); var settings = SignedPackageVerifierSettings.GetDefault(); Output.WriteLine($"Checking {packages.Count()} packages for signatures."); @@ -159,7 +159,7 @@ private static bool IsAttributeSbrp(MetadataReader reader, CustomAttribute attr) private static async Task IsPackageSignedAsync(string packagePath, PackageSignatureVerifier verifier, SignedPackageVerifierSettings settings) { - using PackageArchiveReader packageReader = new (packagePath); + using PackageArchiveReader packageReader = new(packagePath); var result = await verifier.VerifySignaturesAsync(packageReader, settings, CancellationToken.None); return result.IsSigned; }