Statiq.Framework icon indicating copy to clipboard operation
Statiq.Framework copied to clipboard

Fix code analysis not correctly detecting base types when inline constructors are used

Open girlpunk opened this issue 6 months ago • 3 comments

At present, when a class uses an inline constructor (see examples below), the base class or interface would not be detected correctly, and incorrectly return object. This is due to an out of date library. This PR updates the library, and fixes a resultant error (there are now two overloads of GetAccessibleMembersInThisAndBaseTypes())

public class MyClass(String inputString) : OtherClass {}

public class CustomPipeline : Pipeline
{
    public CustomPipeline()
    {
        Dependencies.Add(nameof(Code));
        DependencyOf.Add(nameof(Statiq.Web.Pipelines.Content));

        using var cache = new CacheDocuments(new ExecuteConfig(Config.FromContext(AnalyseCSharp)));

        ProcessModules = new ModuleList(
            new ConcatDocuments(nameof(Code)),
            cache.WithoutSourceMapping()
        );
    }

    private static AnalyzeCSharp AnalyseCSharp(IExecutionContext ctx)
    {
        return new AnalyzeCSharp()
            .WhereNamespaces(ctx.Settings.GetBool(DocsKeys.IncludeGlobalNamespace))
            .WithCssClasses("code", "cs")
            .WithSolutions(Config.FromContext<IEnumerable<string>>(static ctx => ctx.GetList<string>(DocsKeys.SolutionFiles)))
            .WithAssemblySymbols()
            .WithImplicitInheritDoc(ctx.GetBool(DocsKeys.ImplicitInheritDoc))
            .WhereSymbol(
                static symbol =>
                {
                    if (symbol.Kind == SymbolKind.NamedType)
                    {
                        var typeSymbol = (INamedTypeSymbol) symbol;
                        return typeSymbol.BaseType?.GetQualifiedName() == "ExampleProject.OtherClass ";
                    }

                    return false;
                }
            );
    }
}

In the above, the CustomPipeline should only document classes the extend the OtherClass base type. At present, MyClass is not documented despite extending the correct base type. This PR fixes this issue.

girlpunk avatar May 07 '25 12:05 girlpunk

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Sam M seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar May 07 '25 12:05 CLAassistant

Thanks! I've got a fair amount of cleanup and catchup to do (including a big version bump courtesy of @devlead), but I'm still around and will get to everything eventually! I actually use this project in my regular job daily so it's far from dead. Just a heads up that I've seen this :)

daveaglick avatar May 07 '25 12:05 daveaglick

That's great to hear, Statiq has some great features and is significantly easier to use that other tools like docfx. If there's anything I can do to help with the cleanup or catch up I'm more than happy to help

girlpunk avatar May 08 '25 09:05 girlpunk