You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There might be alot of unused code samples that needs to be removed.
Is there an easy way to determine if a specific sample is used or not ?
The samples here are used by dotnet/docs and dotnet/dotnet-api-docs, are there any other repos ?
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.
voidMain(){// Get .vb files in my local fork of samples.// Replacing \ with (\\|\/) is used later for regex, so it matches both \ and /varvbSamples=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.vardocsMarkdown=Directory.GetFiles(@"D:\dotnet\docs\docs\","*.md",SearchOption.AllDirectories).ToArray();// Get .md files in my local fork of dotnet-api-docs.varapiDocsMarkdown=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.varapiDocsXml=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(vari=0;i<vbSamples.Length;i++){// Initially, mark it as unused.varisUsedSample=false;// If a reference to the sample is found in any file, mark sample as used and break loop.foreach(varmdFileindocsMarkdown){if(System.Text.RegularExpressions.Regex.IsMatch(File.ReadAllText(mdFile).ToLower(),vbSamples[i])){isUsedSample=true;gotoend_checking;}}foreach(varmdFileinapiDocsMarkdown){if(System.Text.RegularExpressions.Regex.IsMatch(File.ReadAllText(mdFile).ToLower(),vbSamples[i])){isUsedSample=true;gotoend_checking;}}foreach(varxmlFileinapiDocsXml){if(System.Text.RegularExpressions.Regex.IsMatch(File.ReadAllText(xmlFile).ToLower(),vbSamples[i])){isUsedSample=true;gotoend_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 ?
Activity
Youssef1313 commentedon Sep 7, 2019
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
.vbfiles.Can there be any scenario where a sample is used and this code report it as unused ?
mairaw commentedon Oct 1, 2019
I'll close this one as duplicate of dotnet/docs#14825. I think @rpetrusha was also working on a code to identify those.