Ejemplo n.º 1
0
        private static IEnumerable <Snippet> LoadSnippets(string dirPath)
        {
            foreach (string dirPath2 in Directory.EnumerateDirectories(dirPath, "*", SearchOption.TopDirectoryOnly))
            {
                if (Path.GetFileName(dirPath2).StartsWith("_"))
                {
                    continue;
                }

                foreach (SnippetFile snippetFile in SnippetSerializer.DeserializeFiles(dirPath2, SearchOption.AllDirectories))
                {
                    foreach (Snippet snippet in snippetFile.Snippets)
                    {
                        yield return(snippet);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var dirPaths = new List <string>();

            if (args?.Length > 0)
            {
                dirPaths.AddRange(args);
            }
            else
            {
                dirPaths.Add(Environment.CurrentDirectory);
            }

            Console.WriteLine();
            Console.WriteLine("directories:");

            for (int i = 0; i < dirPaths.Count; i++)
            {
                Console.WriteLine($"  {dirPaths[i]}");

                if (!Assert(Directory.Exists(dirPaths[i]), "directory not found"))
                {
                    return;
                }
            }

            var snippets = new List <Snippet>(SnippetSerializer.DeserializeFiles(dirPaths[0], SearchOption.AllDirectories).SelectMany(f => f.Snippets));

            Console.WriteLine();
            Console.WriteLine($"number of snippets: {snippets.Count}");

            foreach (SnippetValidationResult result in SnippetChecker.Validate(snippets))
            {
                Console.WriteLine();
                Console.WriteLine($"{result.Importance}: \"{result.Description}\" in \"{result.Snippet.FilePath}\"");
            }

            foreach (IGrouping <string, Snippet> snippet in snippets
                     .Where(f => f.Keywords.Contains(NonUniqueShortcutKeyword))
                     .GroupBy(f => f.Shortcut)
                     .Where(f => f.Count() == 1))
            {
                Console.WriteLine();
                Console.WriteLine($"unused {NonUniqueShortcutKeyword} in \"{snippet.First().FilePath}\"");
            }

            foreach (ShortcutInfo shortcutInfo in SnippetChecker.FindDuplicateShortcuts(dirPaths, NonUniqueShortcutKeyword))
            {
                Console.WriteLine();
                Console.WriteLine($"shortcut duplicate: {shortcutInfo.Shortcut}");

                foreach (Snippet item in shortcutInfo.Snippets)
                {
                    Console.WriteLine($"  {item.FilePath}");
                }
            }
            ;

            SaveSnippets(snippets);

            Assert(false);
        }