Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/DotnetDocument.Tools/Handlers/ApplyDocumentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ public Result Apply(string? path, bool isDryRun)
var undocumentedMembers = memberDocStatusList.Where(m => m.IsDocumented is not true).ToList();

foreach (var member in undocumentedMembers)
{
_logger.LogInformation(" {File} (ln {Line}): {MemberType} '{MemberName}' has no document",
member.FilePath, member.StartLine, member.Kind.ToString().Humanize(), member.Identifier);
}

// If is dry run
if (isDryRun)
Expand Down Expand Up @@ -158,9 +160,11 @@ private IEnumerable<MemberDocumentationStatus> GetFileDocumentationStatus(string
_walker.Visit(root);

foreach (var node in _walker.NodesWithXmlDoc)
{
yield return new MemberDocumentationStatus(filePath, SyntaxUtils.FindMemberIdentifier(node),
node.Kind(), true, null, node,
node.GetLocation().GetLineSpan().StartLinePosition.ToString());
}

foreach (var node in _walker.NodesWithoutXmlDoc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ public AttributeServiceResolver(IServiceProvider provider) =>
.Any(a => a.Key == key));

if (service is null)
{
logger.LogWarning("No {ServiceType} implementation resolved matching {KeyType} key: '{Key}'",
typeof(TService).Name, key.GetType().Name, key);
}
else
{
logger.LogTrace("Resolved implementation of {ServiceType} with key '{Key}': {ImplementationType}",
typeof(TService).Name, key, service.GetType().Name);
}

return service;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override IEnumerable<SyntaxKind> GetSupportedKinds() => new[]
public override ConstructorDeclarationSyntax Apply(ConstructorDeclarationSyntax node)
{
// Retrieve constructor name
var ctorName = node.Identifier.Text;
var ctorName = SyntaxUtils.ExtractClassName(node);

// Declare the summary by using the template from configuration
var summary = new List<string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public override MethodDeclarationSyntax Apply(MethodDeclarationSyntax node)
var returns = string.Empty;

if (node.Body is not null)
{
// Extract the last return statement which returns a variable
// and humanize the name of the variable which will be used as
// returns descriptions. Empty otherwise.
Expand All @@ -83,6 +84,7 @@ public override MethodDeclarationSyntax Apply(MethodDeclarationSyntax node)
.Select(r => _formatter
.FormatName(_options.Returns.Template, (TemplateKeys.Name, r)))
.LastOrDefault();
}

// TODO: Handle case where node.ExpressionBody is not null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ public override PropertyDeclarationSyntax Apply(PropertyDeclarationSyntax node)
.ToList();

if (accessors is not null && accessors.Any())
{
accessorsDescription = string.Join(" or ", accessors)
.ToLower()
.Humanize();
}
else
{
accessorsDescription = _formatter.ConjugateThirdPersonSingular("Get");
}

var summary = new List<string>
{
Expand Down
28 changes: 28 additions & 0 deletions src/DotnetDocument/Syntax/SyntaxUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ public static string FindMemberIdentifier(SyntaxNode node)
public static IEnumerable<string> ExtractBaseTypes(ClassDeclarationSyntax classDeclarationSyntax)
{
if (classDeclarationSyntax.BaseList is not null)
{
return classDeclarationSyntax.BaseList.Types
.Select(t => t.Type.ToString().Replace("<", "{").Replace(">", "}").Trim());
}

return new List<string>();
}
Expand All @@ -118,8 +120,10 @@ public static IEnumerable<string> ExtractBaseTypes(ClassDeclarationSyntax classD
public static IEnumerable<string> ExtractBaseTypes(InterfaceDeclarationSyntax interfaceDeclarationSyntax)
{
if (interfaceDeclarationSyntax.BaseList is not null)
{
return interfaceDeclarationSyntax.BaseList.Types
.Select(t => t.Type.ToString().Replace("<", "{").Replace(">", "}").Trim());
}

return new List<string>();
}
Expand Down Expand Up @@ -257,8 +261,32 @@ public static IEnumerable<string> ExtractReturnStatements(BlockSyntax body)
if (body is null) yield break;

foreach (var returnStatement in body.Statements.OfType<ReturnStatementSyntax>())
{
if (returnStatement.Expression is IdentifierNameSyntax identifierName)
yield return identifierName.Identifier.Text;
}
}

/// <summary>
/// Extracts the class name using the specified constructor declaration syntax
/// </summary>
/// <param name="constructorDeclarationSyntax">The constructor declaration syntax</param>
/// <returns>The class name</returns>
public static string ExtractClassName(ConstructorDeclarationSyntax constructorDeclarationSyntax)
{
// Check if parent of this syntax is a class declaration with type params
if (constructorDeclarationSyntax.Parent is ClassDeclarationSyntax { TypeParameterList: { } } classDeclarationSyntax)
{
// Try to extract type params from the class declaration rather than from ctor
// Added the ! operator to make sure no warnings are thrown during CI
var typeParams = string
.Join(",", classDeclarationSyntax.TypeParameterList.Parameters!
.Select(x => x.Identifier.Text));

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

return constructorDeclarationSyntax.Identifier.Text;
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/DotnetDocument/Utils/EnglishUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ 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"))
{
return $"{verb}es";
}

// Check if verb is at least 3 chars long, ends with a consonant then y
if (verb.Length > 2 && verb.Last() == 'y' && verb[^2].IsConsonant()) return $"{verb.RemoveEnd("y")}ies";
Expand Down