Skip to content

danny-sg/internals-viewer / .claude/skills/unused-code

unused-code

Verified

Finds unused types and members in Internals Viewer projects by Roslyn reachability from production code, where code reached only from tests or from other unused code counts as unused, then removes them without losing test coverage. Use whenever the user asks whether a type or member is used, asks to find, review or remove unused, dead, leftover or test-only code in a project, or says unused types keep being missed, even when they name only one type.

scripts/MemberRemover/LeadingBlankLineRemover.cs

View on GitHub
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace MemberRemover;

internal sealed class LeadingBlankLineRemover : CSharpSyntaxRewriter
{
    public static SyntaxAnnotation FirstMemberRemoved { get; } = new(nameof(FirstMemberRemoved));

    public override SyntaxNode? VisitClassDeclaration(ClassDeclarationSyntax node)
        => Fix((TypeDeclarationSyntax)base.VisitClassDeclaration(node)!);

    public override SyntaxNode? VisitStructDeclaration(StructDeclarationSyntax node)
        => Fix((TypeDeclarationSyntax)base.VisitStructDeclaration(node)!);

    public override SyntaxNode? VisitRecordDeclaration(RecordDeclarationSyntax node)
        => Fix((TypeDeclarationSyntax)base.VisitRecordDeclaration(node)!);

    public override SyntaxNode? VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)
        => Fix((TypeDeclarationSyntax)base.VisitInterfaceDeclaration(node)!);

    private static SyntaxNode Fix(TypeDeclarationSyntax type)
    {
        if (type.Members.Count == 0 || !type.HasAnnotation(FirstMemberRemoved))
        {
            return type;
        }

        var first = type.Members[0];

        var trivia = first.GetLeadingTrivia();

        var index = 0;

        while (index < trivia.Count && trivia[index].IsKind(SyntaxKind.WhitespaceTrivia))
        {
            index++;
        }

        if (index >= trivia.Count || !trivia[index].IsKind(SyntaxKind.EndOfLineTrivia))
        {
            return type;
        }

        return type.ReplaceNode(first, first.WithLeadingTrivia(SyntaxFactory.TriviaList(trivia.Skip(index + 1))));
    }
}
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 197kUpdated Claude CodeCodexVerifiedInstall