Skip to content

Commit 2d76622

Browse files
committed
modernize, add license headers
1 parent b6933b0 commit 2d76622

17 files changed

+149
-101
lines changed

.editorconfig

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
root = true
22

33
[*]
4+
charset = utf-8
5+
end_of_line = crlf
46
indent_style = tab
57
indent_size = 4
68

9+
[*.yml]
10+
indent_style = space
11+
indent_size = 2
12+
713
[*.cs]
8-
# CA1031: Do not catch general exception types
9-
dotnet_diagnostic.CA1031.severity = silent
14+
file_header_template = Copyright © Clinton Ingram and Contributors. Licensed under the MIT License.
15+
16+
csharp_style_namespace_declarations = file_scoped:suggestion
17+
18+
dotnet_diagnostic.CA1031.severity = silent ; do not catch general exception types
19+
20+
dotnet_naming_rule.private_non_field_members_should_be_camel_case.severity = suggestion
21+
dotnet_naming_rule.private_non_field_members_should_be_camel_case.symbols = private_non_field_members
22+
dotnet_naming_rule.private_non_field_members_should_be_camel_case.style = camel_case
23+
24+
dotnet_naming_symbols.private_non_field_members.applicable_kinds = property, event, method
25+
dotnet_naming_symbols.private_non_field_members.applicable_accessibilities = private
26+
27+
dotnet_naming_style.camel_case.capitalization = camel_case

azure-pipelines.yml

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,58 @@
1+
name: $(Year:yy)$(DayOfYear)$(Rev:r)
12
trigger:
2-
- master
3+
branches:
4+
include:
5+
- master
6+
paths:
7+
exclude:
8+
- readme.md
39

410
pool:
5-
vmImage: windows-latest
11+
vmImage: ubuntu-latest
612

713
variables:
14+
azureNuGet: https://pkgs.dev.azure.com/saucecontrol/InheritDoc/_packaging/inheritdoc_ci/nuget/v3/index.json
815
disable.coverage.autogenerate: true
916

10-
name: $(Year:yy)$(DayOfYear)$(Rev:r)
1117
steps:
1218
- task: UseDotNet@2
13-
displayName: Ensure 5.0 SDK
19+
displayName: Ensure 8.0 SDK
20+
inputs:
21+
version: 8.0.x
22+
includePreviewVersions: true
23+
24+
- task: UseDotNet@2
25+
displayName: Ensure 6.0 Runtime
1426
inputs:
15-
version: 5.0.x
27+
packageType: runtime
28+
version: 6.0.x
1629
performMultiLevelLookup: true
1730

18-
- script: dotnet build src\InheritDoc -c Dist --version-suffix ci$(Build.BuildNumber)
31+
- script: dotnet build src/InheritDoc -c Dist --version-suffix ci$(Build.BuildNumber)
1932
displayName: Build
2033

21-
- script: dotnet test tests\InheritDoc.Test -c Coverage -s tests\runsettings --logger trx --collect "XPlat Code Coverage"
34+
- script: dotnet test tests/InheritDoc.Test -c Coverage
2235
displayName: Test
2336

24-
- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@4
37+
- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@5
2538
displayName: Coverage Reports
2639
inputs:
27-
reports: out\coverage\opencover*.xml
28-
targetdir: out\coverage\reports
40+
reports: out/coverage/opencover*.xml
41+
targetdir: out/coverage/reports
2942
reporttypes: HtmlInline_AzurePipelines;Cobertura;Badges
3043

3144
- task: NuGetAuthenticate@0
3245
condition: ne(variables['Build.Reason'], 'PullRequest')
3346

34-
- script: dotnet nuget push --api-key AzureArtifacts --source https://pkgs.dev.azure.com/saucecontrol/InheritDoc/_packaging/inheritdoc_ci/nuget/v3/index.json out\bin\InheritDoc\Dist\SauceControl.InheritDoc.*.nupkg
47+
- script: dotnet nuget push --source $(azureNuGet) --api-key AzureArtifacts out/nuget/*.nupkg
3548
displayName: Push
3649
condition: ne(variables['Build.Reason'], 'PullRequest')
3750

3851
- task: PublishTestResults@2
3952
inputs:
4053
testRunner: VSTest
41-
testResultsFiles: out\testresults\*.trx
54+
testResultsFiles: out/testresults/*.trx
4255

43-
- task: PublishCodeCoverageResults@1
56+
- task: PublishCodeCoverageResults@2
4457
inputs:
45-
codeCoverageTool: Cobertura
46-
summaryFileLocation: out\coverage\reports\cobertura.xml
47-
reportDirectory: out\coverage\reports
58+
summaryFileLocation: out/coverage/reports/Cobertura.xml

build/Common.props

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,37 @@
66
<RepositoryUrl>https://github.com/saucecontrol/InheritDoc</RepositoryUrl>
77
<Copyright>Copyright © 2019-$([System.DateTime]::Today.Year) $(Authors)</Copyright>
88
<Title>Automatic Documentation Inheritance Processing</Title>
9+
<Description>Automatically replace &lt;inheritdoc /&gt; tags with inherited documentation at build time. Integrates with MSBuild, so no command line tool or VS add-on is required.</Description>
910

1011
<RootNamespace>$(MSBuildProjectName)</RootNamespace>
1112
<AssemblyName>$(Owners).$(MSBuildProjectName)</AssemblyName>
1213
<AssemblyTitle>$(MSBuildProjectName)</AssemblyTitle>
1314
<Product>$(MSBuildProjectName)</Product>
1415

15-
<PackageIcon>package/$(Owners).png</PackageIcon>
16+
<PackageIcon>$(Owners).png</PackageIcon>
17+
<PackageReadmeFile>readme.md</PackageReadmeFile>
1618
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1719
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
1820
<PackageTags>Inherit, XML, Documentation, Comments, MSBuild</PackageTags>
1921
<PackageReleaseNotes>See $(RepositoryUrl)/releases for release-specific notes.</PackageReleaseNotes>
20-
<PackageDescription>Automatically replace &lt;inheritdoc /&gt; tags with inherited documentation at build time. Integrates with MSBuild, so no command line tool or VS add-on is required.</PackageDescription>
2122

22-
<LangVersion>9</LangVersion>
23+
<LangVersion>12</LangVersion>
24+
<WarningLevel>7</WarningLevel>
2325
<Features>strict</Features>
2426
<Nullable>annotations</Nullable>
2527
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2628

2729
<Configurations>Debug;Release;Dist</Configurations>
2830
<Configuration Condition="'$(Configuration)'==''">Release</Configuration>
2931

32+
<ProjectRoot>$(MSBuildProjectDirectory)\</ProjectRoot>
3033
<RepositoryRoot>$(MSBuildThisFileDirectory)..\</RepositoryRoot>
3134
<BaseIntermediateOutputPath>$(RepositoryRoot)out\obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
32-
<BaseOutputPath>$(RepositoryRoot)out\bin\$(MSBuildProjectName)\</BaseOutputPath>
35+
<BaseOutputBinPath>$(RepositoryRoot)out\bin\</BaseOutputBinPath>
36+
<BaseOutputPath>$(BaseOutputBinPath)$(MSBuildProjectName)\</BaseOutputPath>
3337
<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
3438
<OutputPath>$(BaseOutputPath)$(Configuration)\</OutputPath>
39+
<PackageOutputPath>$(RepositoryRoot)out\nuget\</PackageOutputPath>
3540
<IntDir>$(IntermediateOutputPath)$(TargetFramework)\</IntDir>
3641
<OutDir>$(OutputPath)$(TargetFramework)\</OutDir>
3742

@@ -52,8 +57,9 @@
5257
</PropertyGroup>
5358

5459
<ItemGroup Condition="'$(Configuration)'=='Dist' Or '$(Configuration)'=='Coverage'">
55-
<None Include="$(MSBuildThisFileDirectory)$(Owners).png" Pack="true" PackagePath="package" />
56-
<None Include="$(RepositoryRoot)license" Pack="true" PackagePath="package" />
60+
<None Include="$(MSBuildThisFileDirectory)$(Owners).png" Pack="true" PackagePath="/" />
61+
<None Include="$(ProjectRoot)readme.md" Pack="true" PackagePath="/" />
62+
<None Include="$(RepositoryRoot)license" Pack="true" PackagePath="/" />
5763
<SourceRoot Include="$(RepositoryRoot)" />
5864
</ItemGroup>
5965

license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2019-2021 Clinton Ingram and Contributors
3+
Copyright (c) 2019-2023 Clinton Ingram and Contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup Condition="'$(Configuration)'=='Dist' or '$(Configuration)'=='Coverage'">
19-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" />
19+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
2020
</ItemGroup>
2121

2222
<ItemGroup Condition="'$(Configuration)'!='Dist'">

src/Directory.Build.targets

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/InheritDoc/CecilExtensions.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
// Copyright © Clinton Ingram and Contributors. Licensed under the MIT License.
2+
3+
using System;
24
using System.Linq;
35
using System.Collections.Generic;
46

@@ -9,13 +11,13 @@ internal static class CecilExtensions
911
private const string compilerGeneratedAttribute = "System.Runtime.CompilerServices.CompilerGeneratedAttribute";
1012

1113
// These are ignored as the base for types, defaulting the doc inheritance target to an implemented interface instead.
12-
private static readonly string[] ignoredBaseTypes = new[] {
14+
private static readonly string[] ignoredBaseTypes = [
1315
"System.Object",
1416
"System.ValueType",
1517
"System.Enum",
1618
"System.Delegate",
1719
"System.MulticastDelegate"
18-
};
20+
];
1921

2022
private static readonly IEnumerable<string> emptyStringEnumerable = new[] { string.Empty };
2123

@@ -297,7 +299,7 @@ public static RefAssemblyResolver Create(string mainAssembly, string[] refAssemb
297299
var resolver = new RefAssemblyResolver();
298300
var rparams = new ReaderParameters { AssemblyResolver = resolver };
299301

300-
foreach (var assemblyFile in refAssemblies.Concat(new[] { mainAssembly }))
302+
foreach (string assemblyFile in refAssemblies.Concat(new[] { mainAssembly }))
301303
{
302304
var assembly = AssemblyDefinition.ReadAssembly(assemblyFile, rparams);
303305
resolver.cache[assembly.FullName] = assembly;
@@ -319,7 +321,7 @@ public AssemblyDefinition Resolve(AssemblyNameReference name)
319321
return match ?? throw new AssemblyResolutionException(name);
320322
}
321323

322-
public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) => Resolve(name);
324+
public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters _) => Resolve(name);
323325

324326
public void Dispose()
325327
{

src/InheritDoc/InheritDoc.csproj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>1.3.0</VersionPrefix>
5-
<TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
4+
<VersionPrefix>1.4.0</VersionPrefix>
5+
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
66
</PropertyGroup>
77

88
<PropertyGroup>
@@ -14,15 +14,18 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<None Include="package\build\*" Pack="true" PackagePath="build;buildCrossTargeting" />
17+
<None Include="package\build\*" Pack="true" PackagePath="build;buildMultiTargeting" />
1818
<None Include="$(OutputPath)\*\Mono.Cecil.dll" Pack="true" PackagePath="tools" />
1919
<None Include="$(OutputPath)\*\System.ValueTuple.dll" Pack="true" PackagePath="tools" />
2020
</ItemGroup>
2121

2222
<ItemGroup>
2323
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.9.20" PrivateAssets="all" />
24-
<PackageReference Include="Mono.Cecil" Version="0.11.3" PrivateAssets="all" />
25-
<PackageReference Condition="$(DefineConstants.Contains('NETFRAMEWORK'))" Include="System.ValueTuple" Version="4.5.0" PrivateAssets="all" />
24+
<PackageReference Include="Mono.Cecil" Version="0.11.5" PrivateAssets="all" />
25+
<PackageReference Condition="$(DefineConstants.Contains('NETFRAMEWORK'))" Include="System.ValueTuple" Version="4.5.0" />
26+
<!-- these are for use in the test project, downloaded here to avoid version conflicts when building tests -->
27+
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[7.0.0]" />
28+
<PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net48" Version="[1.0.0]" />
2629
</ItemGroup>
2730

2831
</Project>

src/InheritDoc/InheritDocProcessor.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
// Copyright © Clinton Ingram and Contributors. Licensed under the MIT License.
2+
3+
using System;
24
using System.IO;
35
using System.Text;
46
using System.Linq;
@@ -30,14 +32,14 @@ private static class DocElementNames
3032

3133
private static class DocAttributeNames
3234
{
33-
public static readonly XName _visited = XName.Get("_visited");
34-
public static readonly XName _trimmed = XName.Get("_trimmed");
35+
public static readonly XName _visited = XName.Get(nameof(_visited));
36+
public static readonly XName _trimmed = XName.Get(nameof(_trimmed));
3537
public static readonly XName Cref = XName.Get("cref");
3638
public static readonly XName Name = XName.Get("name");
3739
public static readonly XName Path = XName.Get("path");
3840
}
3941

40-
private static readonly XName[] inheritSkipIfExists = new[] {
42+
private static readonly XName[] inheritSkipIfExists = [
4143
XName.Get("example"),
4244
XName.Get("exclude"),
4345
XName.Get("filterpriority"),
@@ -47,15 +49,15 @@ private static class DocAttributeNames
4749
XName.Get("returns"),
4850
XName.Get("threadsafety"),
4951
XName.Get("value")
50-
};
52+
];
5153

52-
private static readonly XName[] inheritSkipIfMatch = new[] {
54+
private static readonly XName[] inheritSkipIfMatch = [
5355
XName.Get("cref"),
5456
XName.Get("href"),
5557
XName.Get("name"),
5658
XName.Get("vref"),
5759
XName.Get("xref")
58-
};
60+
];
5961

6062
private static readonly string refFolderToken = Path.DirectorySeparatorChar + "ref" + Path.DirectorySeparatorChar;
6163
private static readonly string libFolderToken = Path.DirectorySeparatorChar + "lib" + Path.DirectorySeparatorChar;
@@ -101,7 +103,7 @@ static XDocument loadDoc(string path)
101103
beforeCount = docMembers.Descendants(DocElementNames.InheritDoc).Count(dm => !dm.Ancestors(DocElementNames.Member).Any(m => m.HasAttribute(DocAttributeNames._trimmed)));
102104

103105
var mem = default(XElement);
104-
while ((mem = docMembers.Elements(DocElementNames.Member).FirstOrDefault(m => isInheritDocCandidate(m))) is not null)
106+
while ((mem = docMembers.Elements(DocElementNames.Member).FirstOrDefault(isInheritDocCandidate)) is not null)
105107
replaceInheritDoc(docPath, mem, docMap, docMembers, refDocs, logger);
106108

107109
foreach (var md in docMembers.Elements(DocElementNames.Member).Where(m => m.HasAttribute(DocAttributeNames._visited)))
@@ -251,7 +253,7 @@ private static void replaceInheritDoc(string file, XElement mem, IDictionary<str
251253

252254
foreach (var inh in mem.Descendants(DocElementNames.InheritDoc).ToArray())
253255
{
254-
string? cref = (string)inh.Attribute(DocAttributeNames.Cref) ?? dml?.First().Cref;
256+
string? cref = (string)inh.Attribute(DocAttributeNames.Cref) ?? dml?.FirstOrDefault()?.Cref;
255257
if (string.IsNullOrEmpty(cref))
256258
{
257259
if (!mem.HasAttribute(DocAttributeNames._trimmed))
@@ -374,7 +376,7 @@ static XDocument getRefDocs(IReadOnlyCollection<string> refAssemblies, IReadOnly
374376
return doc;
375377

376378
var docPaths = refAssemblies
377-
.Select(path => Path.Combine(Path.GetDirectoryName(path)!, Path.GetFileNameWithoutExtension(path) + ".xml"))
379+
.Select(path => Path.ChangeExtension(path, ".xml"))
378380
.Concat(refAssemblies.Select(p => Path.GetDirectoryName(p)).Distinct().Select(p => Path.Combine(p!, "namespaces.xml"))
379381
.Concat(refDocs));
380382

@@ -478,18 +480,16 @@ private static string getTypeIDFromDocID(string docID)
478480

479481
private static IEnumerable<XElement> findDocsByID(XElement container, string docID) => container.Elements(DocElementNames.Member).Where(m => (string)m.Attribute(DocAttributeNames.Name) == docID);
480482

481-
private class DocMatch
483+
private class DocMatch(string cref)
482484
{
483485
private static readonly IReadOnlyDictionary<string, string> emptyMap = new Dictionary<string, string>();
484486

485-
public string Cref;
487+
public string Cref = cref;
486488
public IReadOnlyDictionary<string, string> TypeParamMap = emptyMap;
487489
public IReadOnlyDictionary<string, string> ParamMap = emptyMap;
488490
public bool HasReturn = false;
489491
public bool HasValue = false;
490492

491-
public DocMatch(string cref) => Cref = cref;
492-
493493
public DocMatch(string cref, TypeReference t, TypeReference? bt = null) : this(cref)
494494
{
495495
if (t.HasGenericParameters && (bt?.IsGenericInstance ?? true))
@@ -501,7 +501,7 @@ public DocMatch(string cref, TypeReference t, TypeReference? bt = null) : this(c
501501
var ga = ((GenericInstanceType)bt).GenericArguments;
502502
var rbt = bt.Resolve();
503503

504-
foreach (var tp in t.GenericParameters.Where(p => ga.Contains(p)))
504+
foreach (var tp in t.GenericParameters.Where(ga.Contains))
505505
tpm.Add(rbt.GenericParameters[ga.IndexOf(tp)].Name, tp.Name);
506506
}
507507
else
@@ -548,7 +548,7 @@ public enum Severity { Diag, Info, Message, Warn, Error }
548548
void Warn(string code, string file, int line, int column, string msg);
549549
}
550550

551-
internal class ErrorCodes
551+
internal static class ErrorCodes
552552
{
553553
public const string BadXml = "IDT001";
554554
public const string NoDocs = "IDT002";

0 commit comments

Comments
 (0)