Skip to content

Commit

Permalink
Upgrade to DotNet 8. Upgraded all nuget packages to latest. (#22)
Browse files Browse the repository at this point in the history
* Upgrade to DotNet 8. Upgraded all nuget packages to latest.

* Fixed class with file scoped namespace. Cleaned up SonarLint warnings and some general logic.

* More cleanup. Renamed the test to NoIdent to properly explain the meaning.

* Fix the build by updating the version and format check

* Change centralised version definition

* Fix linting

* Remove TargetFramework tags

* Correct version number for DotNet

* Upgrade setup-dotnet action to latest

* Fixing test build. Removed a missed TargetFramework tag.

* Fixed test names.

---------

Co-authored-by: Peter Knobloch <pknobloch@mobiquityinc.com>
  • Loading branch information
pknobloch and pknobloch-mobiquity authored Mar 21, 2024
1 parent 2b0a506 commit 9361210
Show file tree
Hide file tree
Showing 25 changed files with 213 additions and 166 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build
on: [push, pull_request]

env:
DOTNET_VERSION: 6.0.101
DOTNET_VERSION: 8.0.203
PACKAGE_ID: dotnet-document
NUPKG_PATH: ./src/DotnetDocument.Tools/nupkg/*.nupkg
PROJECT_PATH: src/DotnetDocument.Tools/DotnetDocument.Tools.csproj
Expand All @@ -18,11 +18,8 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v2

- name: Install dotnet-format
run: dotnet tool install -g dotnet-format

- name: Check format
run: dotnet format --check -v q
run: dotnet format --severity error --verify-no-changes -v q

# The test job
test-build-pack:
Expand All @@ -36,7 +33,7 @@ jobs:

# Setup .NET
- name: Setup .NET ${{ env.DOTNET_VERSION }}
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

Expand All @@ -58,7 +55,7 @@ jobs:
dotnet pack -v normal -c Release --no-restore \
--include-symbols --include-source \
-p:PackageID=${{ env.PACKAGE_ID }} \
-p:PackageVersion=${GITHUB_RUN_ID} \
-p:PackageVersion=0.0.1 \
${{ env.PROJECT_PATH }}
# Upload nupkg to build artifacts
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- '*'

env:
DOTNET_VERSION: 6.0.101
DOTNET_VERSION: 8.0.203
PACKAGE_ID: dotnet-document
NUPKG_PATH: ./src/DotnetDocument.Tools/nupkg/*.nupkg
PROJECT_PATH: src/DotnetDocument.Tools/DotnetDocument.Tools.csproj
Expand All @@ -29,9 +29,9 @@ jobs:
- name: Update build/Version.props with version from tag
run: dotnet TagToVersion -t ${{ github.ref }}

# Setup .NET 5.0
# Setup .NET
- name: Setup .NET ${{ env.DOTNET_VERSION }}
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
source-url: https://api.nuget.org/v3/index.json
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<!-- Enable nullable and treat their warnings as errors -->
<Nullable>enable</Nullable>
Expand Down
11 changes: 2 additions & 9 deletions dotnet-document.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3F70908C-71D
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{5C0CC22B-6A56-4BEE-BFCF-3EC1CF6DF1D4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotnetDocument.Tools.Tests", "test\DotnetDocument.Tools.Tests\DotnetDocument.Tools.Tests.csproj", "{E5201557-757B-4C6E-B88C-EF0E273F77FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotnetDocument", "src\DotnetDocument\DotnetDocument.csproj", "{120B347D-2DEB-4983-A0C3-AEC5201EB386}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotnetDocument.Tests", "test\DotnetDocument.Tests\DotnetDocument.Tests.csproj", "{53A03382-32D2-4B80-96B6-7FFDF3936368}"
Expand All @@ -24,14 +22,10 @@ Global
{29B9E303-643B-4DA8-A01C-B7D2F49322A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29B9E303-643B-4DA8-A01C-B7D2F49322A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29B9E303-643B-4DA8-A01C-B7D2F49322A1}.Release|Any CPU.Build.0 = Release|Any CPU
{E5201557-757B-4C6E-B88C-EF0E273F77FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5201557-757B-4C6E-B88C-EF0E273F77FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5201557-757B-4C6E-B88C-EF0E273F77FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5201557-757B-4C6E-B88C-EF0E273F77FA}.Release|Any CPU.Build.0 = Release|Any CPU
{120B347D-2DEB-4983-A0C3-AEC5201EB386}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{120B347D-2DEB-4983-A0C3-AEC5201EB386}.Debug|Any CPU.Build.0 = Debug|Any CPU
{120B347D-2DEB-4983-A0C3-AEC5201EB386}.Release|Any CPU.ActiveCfg = Release|Any CPU
{120B347D-2DEB-4983-A0C3-AEC5201EB386}.Release|Any CPU.Build.0 = Release|Any CPU
{120B347D-2DEB-4983-A0C3-AEC5201EB386}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{120B347D-2DEB-4983-A0C3-AEC5201EB386}.Debug|Any CPU.Build.0 = Release|Any CPU
{53A03382-32D2-4B80-96B6-7FFDF3936368}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53A03382-32D2-4B80-96B6-7FFDF3936368}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53A03382-32D2-4B80-96B6-7FFDF3936368}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -43,7 +37,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{29B9E303-643B-4DA8-A01C-B7D2F49322A1} = {3F70908C-71DC-48D1-A6A7-1D46A1481A97}
{E5201557-757B-4C6E-B88C-EF0E273F77FA} = {5C0CC22B-6A56-4BEE-BFCF-3EC1CF6DF1D4}
{120B347D-2DEB-4983-A0C3-AEC5201EB386} = {3F70908C-71DC-48D1-A6A7-1D46A1481A97}
{53A03382-32D2-4B80-96B6-7FFDF3936368} = {5C0CC22B-6A56-4BEE-BFCF-3EC1CF6DF1D4}
{87C75476-E094-4BB6-9F90-2A0B099686E4} = {5C0CC22B-6A56-4BEE-BFCF-3EC1CF6DF1D4}
Expand Down
24 changes: 12 additions & 12 deletions src/DotnetDocument.Tools/DotnetDocument.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@

<ItemGroup>
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="OneOf" Version="3.0.205" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="OneOf" Version="3.0.263" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
<PackageReference Include="YamlDotNet.NetCore" Version="1.0.0" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/DotnetDocument.Tools/Handlers/ApplyDocumentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Result Apply(string? path, bool isDryRun)
var memberDocStatusList = GetFilesDocumentationStatus(files);

// Get the list of undocumented members
var undocumentedMembers = memberDocStatusList.Where(m => m.IsDocumented is not true).ToList();
var undocumentedMembers = memberDocStatusList.Where(m => !m.IsDocumented).ToList();

foreach (var member in undocumentedMembers)
_logger.LogInformation(" {File} (ln {Line}): {MemberType} '{MemberName}' has no document",
Expand All @@ -87,7 +87,7 @@ public Result Apply(string? path, bool isDryRun)

// Don't go ahead with saving.
// If there are members without doc return `undocumented members`
return memberDocStatusList.Any(m => m.IsDocumented is not true)
return memberDocStatusList.Any(m => !m.IsDocumented)
? Result.UndocumentedMembers
: Result.Success;
}
Expand Down
3 changes: 1 addition & 2 deletions src/DotnetDocument.Tools/Workspace/FileWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ namespace DotnetDocument.Tools.Workspace
/// <summary>
/// The file workspace class
/// </summary>
/// <seealso cref="WorkspaceBase" />
/// <seealso cref="IWorkspace" />
public class FileWorkspace : WorkspaceBase, IWorkspace
public class FileWorkspace : IWorkspace
{
/// <summary>
/// The exclude paths
Expand Down
3 changes: 1 addition & 2 deletions src/DotnetDocument.Tools/Workspace/FolderWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ namespace DotnetDocument.Tools.Workspace
/// <summary>
/// The folder workspace class
/// </summary>
/// <seealso cref="WorkspaceBase" />
/// <seealso cref="IWorkspace" />
public class FolderWorkspace : WorkspaceBase, IWorkspace
public class FolderWorkspace : IWorkspace
{
/// <summary>
/// The exclude paths
Expand Down
9 changes: 0 additions & 9 deletions src/DotnetDocument.Tools/Workspace/WorkspaceBase.cs

This file was deleted.

8 changes: 4 additions & 4 deletions src/DotnetDocument/DotnetDocument.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<ItemGroup>
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
<PackageReference Include="Humanizer" Version="2.13.14" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/DotnetDocument/Format/HumanizeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public string FormatMethod(string methodName, string returnType, IEnumerable<str
var words = humanizedMethodName.Split(" ");

// Take the first word and format it as a verb
var verb = ConjugateThirdPersonSingular(words.First());
var verb = ConjugateThirdPersonSingular(words[0]);

// Check if method is test
var isTestMethod = attributes.Any(a => options.TestAttributes.Contains(a));
Expand All @@ -127,8 +127,8 @@ public string FormatMethod(string methodName, string returnType, IEnumerable<str
// Humanize the return type
var humanizedReturnType = FormatUtils.HumanizeReturnsType(returnType);

switch (returns: returnType, @static: isStaticMethod, test: isTestMethod, wordsCount: words.Length,
parametersCount: humanizedParameters.Count())
switch (returns: humanizedReturnType, @static: isStaticMethod, test: isTestMethod, wordsCount: words.Length,
parametersCount: humanizedParameters.Count)
{
// Method marked with tests attributes
case { test: true }:
Expand Down Expand Up @@ -164,15 +164,15 @@ public string FormatMethod(string methodName, string returnType, IEnumerable<str
case { wordsCount: 1, parametersCount: > 0 }:
return options.Method.Summary.ManyArgsOneWordMethod
.Replace(TemplateKeys.Verb, verb)
.Replace(TemplateKeys.FirstParam, humanizedParameters.First())
.Replace(TemplateKeys.FirstParam, humanizedParameters[0])
.FirstCharToUpper();

// Multiple words method with params
case { wordsCount: > 1, parametersCount: > 0 }:
return options.Method.Summary.ManyArgsManyWordMethod
.Replace(TemplateKeys.Verb, verb)
.Replace(TemplateKeys.Object, string.Join(" ", words.Skip(1)))
.Replace(TemplateKeys.FirstParam, humanizedParameters.First())
.Replace(TemplateKeys.FirstParam, humanizedParameters[0])
.FirstCharToUpper();

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override PropertyDeclarationSyntax Apply(PropertyDeclarationSyntax node)
.Replace(TemplateKeys.Name, humanizedPropertyName)
};

// Check if constructor has an expression body => {...}
//TODO Check if constructor has an expression body => {...}
if (node.ExpressionBody is not null)
{
}
Expand Down
11 changes: 7 additions & 4 deletions src/DotnetDocument/Syntax/DocumentationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ public T Build()
.GetIndentationTrivia(node);

// Declare a new line element using the method indentation
var xmlNewLine = DocumentationFactory
.XmlNewLineToken(indentationTrivia);
var xmlNewLine = DocumentationFactory.XmlNewLineToken(indentationTrivia);

// Declare a new line node
var newLineXmlNode = SyntaxFactory
Expand Down Expand Up @@ -285,10 +284,14 @@ public T Build()
// TODO: Research this
var endOfLineTrivia = SyntaxFactory.EndOfLine(Environment.NewLine);

var newLeadingTrivia = leadingTrivia
var newLeadingTrivia = indentationTrivia.HasValue
? leadingTrivia
.Add(documentationTrivia)
.Add(endOfLineTrivia)
.Add(indentationTrivia);
.Add(indentationTrivia.Value)
: leadingTrivia
.Add(documentationTrivia)
.Add(endOfLineTrivia);

var documentedNode = node
.WithLeadingTrivia(newLeadingTrivia);
Expand Down
15 changes: 11 additions & 4 deletions src/DotnetDocument/Syntax/DocumentationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ public static class DocumentationFactory
/// </summary>
/// <param name="indentationTrivia">The indentation trivia</param>
/// <returns>The syntax token</returns>
public static SyntaxToken XmlNewLineToken(SyntaxTrivia indentationTrivia) => SyntaxFactory
.XmlTextNewLine(Environment.NewLine, false)
.WithTrailingTrivia(SyntaxFactory.TriviaList(indentationTrivia, SyntaxFactory
.DocumentationCommentExterior("/// ")));
public static SyntaxToken XmlNewLineToken(SyntaxTrivia? indentationTrivia)
{
List<SyntaxTrivia> paramList =
indentationTrivia.HasValue
? [indentationTrivia.Value, SyntaxFactory.DocumentationCommentExterior("/// ")]
: [SyntaxFactory.DocumentationCommentExterior("/// ")];

return SyntaxFactory
.XmlTextNewLine(Environment.NewLine, false)
.WithTrailingTrivia(SyntaxFactory.TriviaList(paramList));
}

/// <summary>
/// Summaries the summary lines
Expand Down
62 changes: 35 additions & 27 deletions src/DotnetDocument/Syntax/SyntaxUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,32 @@ public static class SyntaxUtils
/// </summary>
/// <param name="node">The node</param>
/// <returns>The syntax trivia</returns>
public static SyntaxTrivia GetIndentationTrivia(SyntaxNode node)
public static SyntaxTrivia? GetIndentationTrivia(SyntaxNode node)
{
var leadingTrivia = node
.GetLeadingTrivia();
var leadingTrivia = node.GetLeadingTrivia();

try
{
var indentationTrivia = leadingTrivia
.Last();
if (leadingTrivia.Count <= 0) return null;

// Retrieve the last trivia item (usually indentation)
var lastTrivia = leadingTrivia.Last();

return indentationTrivia;
// Check if the last trivia is an end-of-line trivia
if (lastTrivia.IsKind(SyntaxKind.EndOfLineTrivia))
{
return null;
}

// If it's not an end-of-line trivia, return it directly
return lastTrivia;
}
catch (Exception e)
{
Console.WriteLine(node.ToFullString() + Environment.NewLine + e);

// TODO: Investigate this. It should be an empty trivia
return SyntaxFactory.Space;
// It should be an empty trivia, but I can't figure it out so I just ignore it later
return null;
}
}

Expand Down Expand Up @@ -96,6 +104,25 @@ public static string FindMemberIdentifier(SyntaxNode node)
return descendantIdentifier;
}

/// <summary>
/// Gets the type.
/// </summary>
/// <param name="constructorDeclarationSyntax">The constructor declaration syntax.</param>
/// <returns></returns>
public static string ExtractClassName(ConstructorDeclarationSyntax constructorDeclarationSyntax)
{
if (constructorDeclarationSyntax.Parent is ClassDeclarationSyntax classDeclarationSyntax
&& classDeclarationSyntax.TypeParameterList != null)
{
var typeParams = string.Join(",",
classDeclarationSyntax.TypeParameterList.Parameters.Select(x => x.Identifier.Text));

return $"{constructorDeclarationSyntax.Identifier.Text}{{{typeParams}}}";
}

return constructorDeclarationSyntax.Identifier.Text;
}

/// <summary>
/// Extracts the base types using the specified class declaration syntax
/// </summary>
Expand All @@ -110,25 +137,6 @@ public static IEnumerable<string> ExtractBaseTypes(ClassDeclarationSyntax classD
return new List<string>();
}

/// <summary>
/// Gets the type.
/// </summary>
/// <param name="constructorDeclarationSyntax">The constructor declaration syntax.</param>
/// <returns></returns>
public static string ExtractClassName(ConstructorDeclarationSyntax constructorDeclarationSyntax)
{
if (constructorDeclarationSyntax.Parent is ClassDeclarationSyntax classDeclarationSyntax)
{
if (classDeclarationSyntax.TypeParameterList != null)
{
var typeParams = string.Join(",", classDeclarationSyntax.TypeParameterList.Parameters.Select(x => x.Identifier.Text));
return $"{constructorDeclarationSyntax.Identifier.Text}{{{typeParams}}}";
}
}

return constructorDeclarationSyntax.Identifier.Text;
}

/// <summary>
/// Extracts the base types using the specified interface declaration syntax
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/DotnetDocument/Utils/EnglishUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static class EnglishUtils
public static string ConjugateToThirdPersonSingular(string verb)
{
// Check if verb ends with one of the following chars
if (verb.EndsWith("ch") || verb.EndsWith("s") || verb.EndsWith("sh") ||
verb.EndsWith("x") || verb.EndsWith("z") || verb.EndsWith("o"))
if (verb.EndsWith("ch") || verb.EndsWith('s') || verb.EndsWith("sh") ||
verb.EndsWith('x') || verb.EndsWith('z') || verb.EndsWith('o'))
return $"{verb}es";

// Check if verb is at least 3 chars long, ends with a consonant then y
Expand Down
Loading

0 comments on commit 9361210

Please sign in to comment.