Git Product home page Git Product logo

Comments (2)

Youssef1313 avatar Youssef1313 commented on May 11, 2024

I've written a small C# program to determine the unused snippets but want to make sure if it's correct ?
For now, it only checks for .vb files.

void Main()
{
    // Get .vb files in my local fork of samples.
    // Replacing \ with (\\|\/) is used later for regex, so it matches both \ and /
    var vbSamples = Directory.GetFiles(@"D:\dotnet\samples\samples\", "*.vb", SearchOption.AllDirectories)
                    .Select(s => s.Replace(@"D:\dotnet\samples\samples\", "").Replace(@"\", @"(\\|\/)").ToLower()).ToArray();

    // Get .md files in my local fork of docs.
    var docsMarkdown = Directory.GetFiles(@"D:\dotnet\docs\docs\", "*.md", SearchOption.AllDirectories).ToArray();

    // Get .md files in my local fork of dotnet-api-docs.
    var apiDocsMarkdown = Directory.GetFiles(@"D:\dotnet\dotnet-api-docs\dotnet-api-docs\", "*.md", SearchOption.AllDirectories).ToArray();

    // Get .xml files in my local fork of dotnet-api-docs.
    var apiDocsXml = Directory.GetFiles(@"D:\dotnet\dotnet-api-docs\dotnet-api-docs\", "*.xml", SearchOption.AllDirectories).ToArray();
    
    // Iterate on each vbSample to check if it is used or not.
    for (var i = 0; i < vbSamples.Length; i++)
    {
        // Initially, mark it as unused.
        var isUsedSample = false;

         // If a reference to the sample is found in any file, mark sample as used and break loop.
        foreach (var mdFile in docsMarkdown)
        {
            if (System.Text.RegularExpressions.Regex.IsMatch(File.ReadAllText(mdFile).ToLower(), vbSamples[i]))
            {
                isUsedSample = true;
                goto end_checking;
            }
        }
        
        foreach (var mdFile    in apiDocsMarkdown)
        {
            if (System.Text.RegularExpressions.Regex.IsMatch(File.ReadAllText(mdFile).ToLower(), vbSamples[i]))
            {
                isUsedSample = true;
                goto end_checking;
            }
        }
        
        foreach (var xmlFile in apiDocsXml)
        {
            if (System.Text.RegularExpressions.Regex.IsMatch(File.ReadAllText(xmlFile).ToLower(), vbSamples[i]))
            {
                isUsedSample = true;
                goto end_checking;
            }
        }
        
        
end_checking:
        
        if (!isUsedSample) Console.WriteLine(vbSamples[i]);
        // Write the unused samples to the console.
        Console.WriteLine($"{i + 1} / {vbSamples.Length}");
    }
}

Can there be any scenario where a sample is used and this code report it as unused ?

from samples.

mairaw avatar mairaw commented on May 11, 2024

I'll close this one as duplicate of dotnet/docs#14825. I think @rpetrusha was also working on a code to identify those.

from samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.