private static async Task Main(string[] args) { if (args == null || args.Length == 0) { #if DEBUG args = new[] { @"..\..\..\..\.." }; #else args = new string[] { Environment.CurrentDirectory }; #endif } string rootPath = args[0]; StringComparer comparer = StringComparer.InvariantCulture; var metadata = new RoslynatorMetadata(rootPath); ImmutableArray <AnalyzerMetadata> analyzers = metadata.Analyzers; ImmutableArray <AnalyzerMetadata> codeAnalysisAnalyzers = metadata.CodeAnalysisAnalyzers; ImmutableArray <AnalyzerMetadata> formattingAnalyzers = metadata.FormattingAnalyzers; ImmutableArray <RefactoringMetadata> refactorings = metadata.Refactorings; ImmutableArray <CodeFixMetadata> codeFixes = metadata.CodeFixes; ImmutableArray <CompilerDiagnosticMetadata> compilerDiagnostics = metadata.CompilerDiagnostics; WriteAnalyzersReadMe(@"Analyzers\README.md", analyzers, "Roslynator.Analyzers"); WriteAnalyzersReadMe(@"CodeAnalysis.Analyzers\README.md", codeAnalysisAnalyzers, "Roslynator.CodeAnalysis.Analyzers"); WriteAnalyzersReadMe(@"Formatting.Analyzers\README.md", formattingAnalyzers, "Roslynator.Formatting.Analyzers"); #if !DEBUG VisualStudioInstance instance = MSBuildLocator.QueryVisualStudioInstances().First(f => f.Version.Major == 16); MSBuildLocator.RegisterInstance(instance); using (MSBuildWorkspace workspace = MSBuildWorkspace.Create()) { workspace.WorkspaceFailed += (o, e) => Console.WriteLine(e.Diagnostic.Message); string solutionPath = Path.Combine(rootPath, "Roslynator.sln"); Console.WriteLine($"Loading solution '{solutionPath}'"); Solution solution = await workspace.OpenSolutionAsync(solutionPath).ConfigureAwait(false); Console.WriteLine($"Finished loading solution '{solutionPath}'"); RoslynatorInfo roslynatorInfo = await RoslynatorInfo.Create(solution).ConfigureAwait(false); IOrderedEnumerable <SourceFile> sourceFiles = analyzers .Concat(codeAnalysisAnalyzers) .Concat(formattingAnalyzers) .Select(f => new SourceFile(f.Id, roslynatorInfo.GetAnalyzerFilesAsync(f.Identifier).Result)) .Concat(refactorings .Select(f => new SourceFile(f.Id, roslynatorInfo.GetRefactoringFilesAsync(f.Identifier).Result))) .OrderBy(f => f.Id); MetadataFile.SaveSourceFiles(sourceFiles, @"..\SourceFiles.xml"); } #endif WriteAnalyzerMarkdowns(codeAnalysisAnalyzers, new (string, string)[] { ("Roslynator.CodeAnalysis.Analyzers", "https://www.nuget.org/packages/Roslynator.CodeAnalysis.Analyzers") });
private static void Main(string[] args) { #if DEBUG string rootPath = @"..\..\..\..\.."; #else string rootPath = System.Environment.CurrentDirectory; #endif if (args?.Length > 0) { rootPath = args[0]; } var metadata = new RoslynatorMetadata(rootPath); string path = Path.Combine(rootPath, "default.editorconfig"); var sb = new StringBuilder(); foreach (AnalyzerMetadata analyzer in metadata.Analyzers .Where(f => !f.IsObsolete) .OrderBy(f => f.Id)) { sb.Append("dotnet_diagnostic."); sb.Append(analyzer.Id); sb.AppendLine(".severity = default"); } string content = sb.ToString(); FileHelper.WriteAllText(path, content, Encoding.UTF8, onlyIfChanges: false, fileMustExists: false); }
private static string CreateDefaultRuleSet(RoslynatorMetadata metadata, string action = null) { using (var stringWriter = new Utf8StringWriter()) { using (XmlWriter writer = XmlWriter.Create(stringWriter, new XmlWriterSettings() { Indent = true, IndentChars = " " })) { string newLineChars = writer.Settings.NewLineChars; string indentChars = writer.Settings.IndentChars; writer.WriteStartDocument(); writer.WriteStartElement("RuleSet"); writer.WriteAttributeString("Name", "Default Rules"); writer.WriteAttributeString("ToolsVersion", "15.0"); WriteRules(writer, metadata.Analyzers, "Roslynator.CSharp.Analyzers", action); WriteRules(writer, metadata.FormattingAnalyzers, "Roslynator.Formatting.Analyzers", action); WriteRules(writer, metadata.CodeAnalysisAnalyzers, "Roslynator.CodeAnalysis.Analyzers", action); } return(stringWriter.ToString()); } }
private static void Main(string[] args) { #if DEBUG string rootPath = @"..\..\..\..\.."; #else string rootPath = System.Environment.CurrentDirectory; #endif if (args?.Length > 0) { rootPath = args[0]; } var metadata = new RoslynatorMetadata(rootPath); string content = CreateDefaultConfigFile(metadata.Refactorings, metadata.CodeFixes); FileHelper.WriteAllText("default.roslynator.config", content, Encoding.UTF8, onlyIfChanges: false, fileMustExists: false); }
private static void Main(string[] args) { #if DEBUG string rootPath = @"..\..\..\..\.."; #else string rootPath = System.Environment.CurrentDirectory; #endif if (args?.Length > 0) { rootPath = args[0]; } var metadata = new RoslynatorMetadata(rootPath); string path = Path.Combine(rootPath, "default.ruleset"); string content = CreateDefaultRuleSet(metadata.Analyzers); FileHelper.WriteAllText(path, content, Encoding.UTF8, onlyIfChanges: false, fileMustExists: false); }
private static void Main(string[] args) { if (args == null || args.Length == 0) { #if DEBUG args = new[] { @"..\..\..\..\.." }; #else args = new string[] { Environment.CurrentDirectory }; #endif } string rootPath = args[0]; StringComparer comparer = StringComparer.InvariantCulture; var metadata = new RoslynatorMetadata(rootPath); ImmutableArray <AnalyzerMetadata> analyzers = metadata.Analyzers; ImmutableArray <AnalyzerMetadata> codeAnalysisAnalyzers = metadata.CodeAnalysisAnalyzers; ImmutableArray <AnalyzerMetadata> formattingAnalyzers = metadata.FormattingAnalyzers; ImmutableArray <RefactoringMetadata> refactorings = metadata.Refactorings; ImmutableArray <CodeFixMetadata> codeFixes = metadata.CodeFixes; ImmutableArray <CompilerDiagnosticMetadata> compilerDiagnostics = metadata.CompilerDiagnostics; WriteCompilationUnit( @"Refactorings\CSharp\RefactoringIdentifiers.Generated.cs", RefactoringIdentifiersGenerator.Generate(refactorings, obsolete: false, comparer: comparer)); WriteCompilationUnit( @"Refactorings\CSharp\RefactoringIdentifiers.Deprecated.Generated.cs", RefactoringIdentifiersGenerator.Generate(refactorings, obsolete: true, comparer: comparer)); WriteCompilationUnit( @"VisualStudio.Common\RefactoringsOptionsPage.Generated.cs", RefactoringsOptionsPageGenerator.Generate(refactorings.Where(f => !f.IsObsolete), comparer)); WriteDiagnostics(@"Analyzers\CSharp", analyzers, @namespace: "Roslynator.CSharp"); WriteDiagnostics(@"CodeAnalysis.Analyzers\CSharp", codeAnalysisAnalyzers, @namespace: "Roslynator.CodeAnalysis.CSharp"); WriteDiagnostics(@"Formatting.Analyzers\CSharp", formattingAnalyzers, @namespace: "Roslynator.Formatting.CSharp"); WriteCompilationUnit( @"CodeFixes\CSharp\CompilerDiagnosticDescriptors.Generated.cs", CompilerDiagnosticDescriptorsGenerator.Generate(compilerDiagnostics, comparer: comparer, @namespace: "Roslynator.CSharp"), normalizeWhitespace: false); WriteCompilationUnit( @"CodeFixes\CSharp\CodeFixDescriptors.Generated.cs", CodeFixDescriptorsGenerator.Generate(codeFixes.Where(f => !f.IsObsolete), comparer: comparer, @namespace: "Roslynator.CSharp"), normalizeWhitespace: false); WriteCompilationUnit( @"CodeFixes\CSharp\CodeFixIdentifiers.Generated.cs", CodeFixIdentifiersGenerator.Generate(codeFixes, comparer)); WriteCompilationUnit( @"VisualStudio.Common\CodeFixesOptionsPage.Generated.cs", CodeFixesOptionsPageGenerator.Generate(codeFixes, comparer)); WriteCompilationUnit( @"CSharp\CSharp\CompilerDiagnosticIdentifiers.Generated.cs", CompilerDiagnosticIdentifiersGenerator.Generate(compilerDiagnostics, comparer)); WriteCompilationUnit( @"Tools\CodeGeneration\CSharp\Symbols.Generated.cs", SymbolsGetKindsGenerator.Generate()); WriteCompilationUnit( @"CSharp\CSharp\SyntaxWalkers\CSharpSyntaxNodeWalker.cs", CSharpSyntaxNodeWalkerGenerator.Generate()); string ruleSetXml = File.ReadAllText(Path.Combine(rootPath, @"Tools\CodeGeneration\DefaultRuleSet.xml")); WriteCompilationUnit( @"VisualStudio.Common\RuleSetHelpers.Generated.cs", RuleSetGenerator.Generate(ruleSetXml)); File.WriteAllText( Path.Combine(rootPath, @"VisualStudioCode\package\src\configurationFiles.generated.ts"), @"export const configurationFileContent = { ruleset: `" + ruleSetXml + @"`, config: `<?xml version=""1.0"" encoding=""utf-8""?> <Roslynator> <Settings> <General> <!-- <PrefixFieldIdentifierWithUnderscore>true</PrefixFieldIdentifierWithUnderscore> --> </General> <Refactorings> <!-- <Refactoring Id=""RRxxxx"" IsEnabled=""false"" /> --> </Refactorings> <CodeFixes> <!-- <CodeFix Id=""CSxxxx.RCFxxxx"" IsEnabled=""false"" /> --> <!-- <CodeFix Id=""CSxxxx"" IsEnabled=""false"" /> --> <!-- <CodeFix Id=""RCFxxxx"" IsEnabled=""false"" /> --> </CodeFixes> </Settings> </Roslynator>` };", new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); Console.WriteLine($"number of analyzers: {analyzers.Count(f => !f.IsObsolete)}"); Console.WriteLine($"number of code analysis analyzers: {codeAnalysisAnalyzers.Count(f => !f.IsObsolete)}"); Console.WriteLine($"number of formatting analyzers: {formattingAnalyzers.Count(f => !f.IsObsolete)}"); Console.WriteLine($"number of refactorings: {refactorings.Length}"); Console.WriteLine($"number of code fixes: {codeFixes.Length}"); Console.WriteLine($"number of fixable compiler diagnostics: {codeFixes.SelectMany(f => f.FixableDiagnosticIds).Distinct().Count()}"); void WriteDiagnostics( string dirPath, ImmutableArray <AnalyzerMetadata> analyzers, string @namespace, string descriptorsClassName = "DiagnosticDescriptors", string identifiersClassName = "DiagnosticIdentifiers") { WriteCompilationUnit( Path.Combine(dirPath, $"{descriptorsClassName}.Generated.cs"), DiagnosticDescriptorsGenerator.Generate(analyzers, obsolete: false, comparer: comparer, @namespace: @namespace, className: descriptorsClassName, identifiersClassName: identifiersClassName), normalizeWhitespace: false); WriteCompilationUnit( Path.Combine(dirPath, $"{descriptorsClassName}.Deprecated.Generated.cs"), DiagnosticDescriptorsGenerator.Generate(analyzers, obsolete: true, comparer: comparer, @namespace: @namespace, className: descriptorsClassName, identifiersClassName: identifiersClassName), normalizeWhitespace: false); WriteCompilationUnit( Path.Combine(dirPath, $"{identifiersClassName}.Generated.cs"), DiagnosticIdentifiersGenerator.Generate(analyzers, obsolete: false, comparer: comparer, @namespace: @namespace, className: identifiersClassName)); WriteCompilationUnit( Path.Combine(dirPath, $"{identifiersClassName}.Deprecated.Generated.cs"), DiagnosticIdentifiersGenerator.Generate(analyzers, obsolete: true, comparer: comparer, @namespace: @namespace, className: identifiersClassName)); IEnumerable <AnalyzerMetadata> optionAnalyzers = analyzers.SelectMany(f => f.OptionAnalyzers); if (optionAnalyzers.Any()) { WriteCompilationUnit( Path.Combine(dirPath, "AnalyzerOptions.Generated.cs"), DiagnosticDescriptorsGenerator.Generate(optionAnalyzers, obsolete: false, comparer: comparer, @namespace: @namespace, className: "AnalyzerOptions", identifiersClassName: "AnalyzerOptionIdentifiers"), normalizeWhitespace: false, fileMustExist: false); WriteCompilationUnit( Path.Combine(dirPath, "AnalyzerOptionIdentifiers.Generated.cs"), DiagnosticIdentifiersGenerator.Generate(optionAnalyzers, obsolete: false, comparer: comparer, @namespace: @namespace, className: "AnalyzerOptionIdentifiers"), fileMustExist: false); } IEnumerable <string> analyzerOptionIdentifiers = analyzers .SelectMany(f => f.OptionAnalyzers) .Select(f => f.Identifier); WriteCompilationUnit( Path.Combine(dirPath, "AnalyzerOptionsAnalyzer.Generated.cs"), AnalyzerOptionsAnalyzerGenerator.Generate(analyzerOptionIdentifiers, @namespace: @namespace), fileMustExist: false); } void WriteCompilationUnit( string path, CompilationUnitSyntax compilationUnit, bool autoGenerated = true, bool normalizeWhitespace = true, bool fileMustExist = true, bool overwrite = true) { CodeGenerationHelpers.WriteCompilationUnit( path: Path.Combine(rootPath, path), compilationUnit: compilationUnit, banner: "Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.", autoGenerated: autoGenerated, normalizeWhitespace: normalizeWhitespace, fileMustExist: fileMustExist, overwrite: overwrite); } }
private static void Main(string[] args) { #if DEBUG string rootPath = @"..\..\..\..\.."; #else string rootPath = System.Environment.CurrentDirectory; #endif if (args?.Length > 0) { rootPath = args[0]; } var metadata = new RoslynatorMetadata(rootPath); var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("# Options"); foreach (string value in metadata.GetAllAnalyzers() .SelectMany(f => f.Options) .Select(analyzerOption => { string optionKey = analyzerOption.OptionKey; if (!optionKey.StartsWith("roslynator.", StringComparison.Ordinal)) { optionKey = $"roslynator.{analyzerOption.ParentId}.{optionKey}"; } return("#" + optionKey + " = " + (analyzerOption.OptionValue ?? "true")); }) .OrderBy(f => f)) { sb.AppendLine(value); } GenerateRules(metadata.Analyzers, "Roslynator.Analyzers"); GenerateRules(metadata.FormattingAnalyzers, "Roslynator.Formatting.Analyzers"); GenerateRules(metadata.CodeAnalysisAnalyzers, "Roslynator.CodeAnalysis.Analyzers"); string content = sb.ToString(); FileHelper.WriteAllText("default.editorconfig", content, Encoding.UTF8, onlyIfChanges: false, fileMustExists: false); void GenerateRules(IEnumerable <AnalyzerMetadata> analyzers, string heading) { sb.AppendLine(); sb.Append("# "); sb.AppendLine(heading); foreach (AnalyzerMetadata analyzer in analyzers .Where(f => !f.IsObsolete) .OrderBy(f => f.Id)) { sb.Append("dotnet_diagnostic."); sb.Append(analyzer.Id); sb.Append(".severity = "); sb.AppendLine(GetSeverity(analyzer)); } } string GetSeverity(AnalyzerMetadata analyzer) { if (!analyzer.IsEnabledByDefault) { return("none"); } switch (analyzer.DefaultSeverity) { case "Hidden": return("silent"); case "Info": return("suggestion"); case "Warning": return("warning"); case "Error": return("error"); default: throw new InvalidOperationException(); } } }
private static async Task Main(string[] args) { if (args == null || args.Length == 0) { #if DEBUG args = new string[] { @"..\..\..\..\.." }; #else args = new string[] { Environment.CurrentDirectory }; #endif } string rootPath = args[0]; StringComparer comparer = StringComparer.InvariantCulture; var metadata = new RoslynatorMetadata(rootPath); ImmutableArray <AnalyzerMetadata> analyzers = metadata.Analyzers; ImmutableArray <RefactoringMetadata> refactorings = metadata.Refactorings; ImmutableArray <CodeFixMetadata> codeFixes = metadata.CodeFixes; ImmutableArray <CompilerDiagnosticMetadata> compilerDiagnostics = metadata.CompilerDiagnostics; WriteAnalyzersReadMe(@"Analyzers\README.md", analyzers); WriteAnalyzersByCategory(@"Analyzers\AnalyzersByCategory.md", analyzers); #if !DEBUG VisualStudioInstance instance = MSBuildLocator.QueryVisualStudioInstances().First(f => f.Version.Major == 15); MSBuildLocator.RegisterInstance(instance); using (MSBuildWorkspace workspace = MSBuildWorkspace.Create()) { workspace.WorkspaceFailed += (o, e) => Console.WriteLine(e.Diagnostic.Message); string solutionPath = Path.Combine(rootPath, "Roslynator.sln"); Console.WriteLine($"Loading solution '{solutionPath}'"); Solution solution = await workspace.OpenSolutionAsync(solutionPath).ConfigureAwait(false); Console.WriteLine($"Finished loading solution '{solutionPath}'"); RoslynatorInfo roslynatorInfo = await RoslynatorInfo.Create(solution).ConfigureAwait(false); IOrderedEnumerable <SourceFile> sourceFiles = analyzers .Select(f => new SourceFile(f.Id, roslynatorInfo.GetAnalyzerFilesAsync(f.Identifier).Result)) .Concat(refactorings .Select(f => new SourceFile(f.Id, roslynatorInfo.GetRefactoringFilesAsync(f.Identifier).Result))) .OrderBy(f => f.Id); MetadataFile.SaveSourceFiles(sourceFiles, @"..\SourceFiles.xml"); } #endif foreach (AnalyzerMetadata analyzer in analyzers) { WriteAllText( $@"..\docs\analyzers\{analyzer.Id}.md", MarkdownGenerator.CreateAnalyzerMarkdown(analyzer, Array.Empty <string>()), fileMustExists: false); } foreach (RefactoringMetadata refactoring in refactorings) { WriteAllText( $@"..\docs\refactorings\{refactoring.Id}.md", MarkdownGenerator.CreateRefactoringMarkdown(refactoring, Array.Empty <string>()), fileMustExists: false); } foreach (CompilerDiagnosticMetadata diagnostic in compilerDiagnostics) { WriteAllText( $@"..\docs\cs\{diagnostic.Id}.md", MarkdownGenerator.CreateCompilerDiagnosticMarkdown(diagnostic, codeFixes, comparer, Array.Empty <string>()), fileMustExists: false); } WriteAllText( @"..\docs\refactorings\Refactorings.md", MarkdownGenerator.CreateRefactoringsMarkdown(refactorings, comparer)); WriteAllText( @"Refactorings\README.md", MarkdownGenerator.CreateRefactoringsReadMe(refactorings.Where(f => !f.IsObsolete), comparer)); WriteAllText( @"CodeFixes\README.md", MarkdownGenerator.CreateCodeFixesReadMe(compilerDiagnostics, comparer)); WriteAllText( "DefaultConfigFile.xml", XmlGenerator.CreateDefaultConfigFile(refactorings, codeFixes)); WriteAllText( "default.ruleset", XmlGenerator.CreateDefaultRuleSet(analyzers)); // find files to delete foreach (string path in Directory.EnumerateFiles(GetPath(@"..\docs\refactorings"))) { if (Path.GetFileName(path) != "Refactorings.md" && !refactorings.Any(f => f.Id == Path.GetFileNameWithoutExtension(path))) { Console.WriteLine($"FILE TO DELETE: {path}"); } } // find missing samples foreach (RefactoringMetadata refactoring in refactorings) { if (refactoring.Samples.Count == 0) { foreach (ImageMetadata image in refactoring.ImagesOrDefaultImage()) { string imagePath = Path.Combine(GetPath(@"..\images\refactorings"), image.Name + ".png"); if (!File.Exists(imagePath)) { Console.WriteLine($"MISSING SAMPLE: {imagePath}"); } } } } void WriteAnalyzersReadMe(string path, ImmutableArray <AnalyzerMetadata> descriptors) { WriteAllText( path, MarkdownGenerator.CreateAnalyzersReadMe(descriptors.Where(f => !f.IsObsolete), comparer)); } void WriteAnalyzersByCategory(string path, ImmutableArray <AnalyzerMetadata> descriptors) { WriteAllText( path, MarkdownGenerator.CreateAnalyzersByCategoryMarkdown(descriptors.Where(f => !f.IsObsolete), comparer)); } void WriteAllText(string relativePath, string content, bool onlyIfChanges = true, bool fileMustExists = true) { string path = GetPath(relativePath); Encoding encoding = (Path.GetExtension(path) == ".md") ? _utf8NoBom : Encoding.UTF8; FileHelper.WriteAllText(path, content, encoding, onlyIfChanges, fileMustExists); } string GetPath(string path) { return(Path.Combine(rootPath, path)); } }
private static void Main(string[] args) { string rootPath = args[0]; var metadata = new RoslynatorMetadata(rootPath); ImmutableArray <AnalyzerMetadata> analyzers = metadata.Analyzers; ImmutableArray <RefactoringMetadata> refactorings = metadata.Refactorings; ImmutableArray <CompilerDiagnosticMetadata> compilerDiagnostics = metadata.CompilerDiagnostics; foreach (string id in args.Skip(1)) { if (_analyzerIdRegex.IsMatch(id)) { AnalyzerMetadata analyzer = analyzers.FirstOrDefault(f => string.Equals(f.Id, id, StringComparison.OrdinalIgnoreCase)); if (analyzer == null) { Console.WriteLine($"Analyzer '{id}' not found"); continue; } string className = $"{analyzer.Id}{analyzer.Identifier}Tests"; WriteCompilationUnit( $@"Tests\Analyzers.Tests\{className}.cs", AnalyzerTestGenerator.Generate(analyzer, className), autoGenerated: false, normalizeWhitespace: false, fileMustExist: false, overwrite: false); } else if (_refactoringIdRegex.IsMatch(id)) { RefactoringMetadata refactoring = refactorings.FirstOrDefault(f => string.Equals(f.Id, id, StringComparison.OrdinalIgnoreCase)); if (refactoring == null) { Console.WriteLine($"Refactoring '{id}' not found"); continue; } string className = $"{refactoring.Id}{refactoring.Identifier}Tests"; WriteCompilationUnit( $@"Tests\Refactorings.Tests\{className}.cs", RefactoringTestGenerator.Generate(refactoring, className), autoGenerated: false, normalizeWhitespace: false, fileMustExist: false, overwrite: false); } else if (_codeFixIdRegex.IsMatch(id)) { CompilerDiagnosticMetadata compilerDiagnostic = compilerDiagnostics.FirstOrDefault(f => string.Equals(f.Id, id, StringComparison.OrdinalIgnoreCase)); if (compilerDiagnostic == null) { Console.WriteLine($"Compiler diagnostic '{id}' not found"); continue; } string className = $"{compilerDiagnostic.Id}{compilerDiagnostic.Identifier}Tests"; WriteCompilationUnit( $@"Tests\CodeFixes.Tests\{className}.cs", CodeFixTestGenerator.Generate(compilerDiagnostic, className), autoGenerated: false, normalizeWhitespace: false, fileMustExist: false, overwrite: false); } else { Console.WriteLine($"Id '{id}' not recognized"); } } void WriteCompilationUnit( string path, CompilationUnitSyntax compilationUnit, bool autoGenerated = true, bool normalizeWhitespace = true, bool fileMustExist = true, bool overwrite = true) { CodeGenerationHelpers.WriteCompilationUnit( path: Path.Combine(rootPath, path), compilationUnit: compilationUnit, banner: CodeGenerationHelpers.CopyrightBanner, autoGenerated: autoGenerated, normalizeWhitespace: normalizeWhitespace, fileMustExist: fileMustExist, overwrite: overwrite); } }
private static void Main(string[] args) { if (args == null || args.Length == 0) { #if DEBUG args = new string[] { @"..\..\..\..\.." }; #else args = new string[] { Environment.CurrentDirectory }; #endif } string rootPath = args[0]; StringComparer comparer = StringComparer.InvariantCulture; var metadata = new RoslynatorMetadata(rootPath); ImmutableArray <AnalyzerMetadata> analyzers = metadata.Analyzers; ImmutableArray <AnalyzerMetadata> codeAnalysisAnalyzers = metadata.CodeAnalysisAnalyzers; ImmutableArray <RefactoringMetadata> refactorings = metadata.Refactorings; ImmutableArray <CodeFixMetadata> codeFixes = metadata.CodeFixes; ImmutableArray <CompilerDiagnosticMetadata> compilerDiagnostics = metadata.CompilerDiagnostics; WriteCompilationUnit( @"Refactorings\CSharp\RefactoringIdentifiers.Generated.cs", RefactoringIdentifiersGenerator.Generate(refactorings, obsolete: false, comparer: comparer)); WriteCompilationUnit( @"Refactorings\CSharp\RefactoringIdentifiers.Deprecated.Generated.cs", RefactoringIdentifiersGenerator.Generate(refactorings, obsolete: true, comparer: comparer)); WriteCompilationUnit( @"VisualStudio.Common\RefactoringsOptionsPage.Generated.cs", RefactoringsOptionsPageGenerator.Generate(refactorings.Where(f => !f.IsObsolete), comparer)); WriteDiagnostics(@"Analyzers\CSharp", analyzers, @namespace: "Roslynator.CSharp"); WriteDiagnostics(@"CodeAnalysis.Analyzers\CSharp", codeAnalysisAnalyzers, @namespace: "Roslynator.CodeAnalysis.CSharp"); WriteCompilationUnit( @"CodeFixes\CSharp\CompilerDiagnosticDescriptors.Generated.cs", CompilerDiagnosticDescriptorsGenerator.Generate(compilerDiagnostics, comparer: comparer, @namespace: "Roslynator.CSharp"), normalizeWhitespace: false); WriteCompilationUnit( @"CodeFixes\CSharp\CodeFixDescriptors.Generated.cs", CodeFixDescriptorsGenerator.Generate(codeFixes.Where(f => !f.IsObsolete), comparer: comparer, @namespace: "Roslynator.CSharp"), normalizeWhitespace: false); WriteCompilationUnit( @"CodeFixes\CSharp\CodeFixIdentifiers.Generated.cs", CodeFixIdentifiersGenerator.Generate(codeFixes, comparer)); WriteCompilationUnit( @"VisualStudio.Common\CodeFixesOptionsPage.Generated.cs", CodeFixesOptionsPageGenerator.Generate(codeFixes, compilerDiagnostics, comparer)); WriteCompilationUnit( @"VisualStudio.Common\GlobalSuppressionsOptionsPage.Generated.cs", GlobalSuppressionsOptionsPageGenerator.Generate(analyzers.Where(f => !f.IsObsolete), comparer)); WriteCompilationUnit( @"CSharp\CSharp\CompilerDiagnosticIdentifiers.Generated.cs", CompilerDiagnosticIdentifiersGenerator.Generate(compilerDiagnostics, comparer)); WriteCompilationUnit( @"Tools\CodeGeneration\CSharp\Symbols.Generated.cs", SymbolsGetKindsGenerator.Generate()); WriteCompilationUnit( @"CSharp\CSharp\SyntaxWalkers\CSharpSyntaxNodeWalker.cs", CSharpSyntaxNodeWalkerGenerator.Generate()); Console.WriteLine($"number of analyzers: {analyzers.Count(f => !f.IsObsolete)}"); Console.WriteLine($"number of code analysis analyzers: {codeAnalysisAnalyzers.Count(f => !f.IsObsolete)}"); Console.WriteLine($"number of refactorings: {refactorings.Length}"); Console.WriteLine($"number of code fixes: {codeFixes.Length}"); Console.WriteLine($"number of fixable compiler diagnostics: {codeFixes.SelectMany(f => f.FixableDiagnosticIds).Distinct().Count()}"); void WriteDiagnostics(string dirPath, ImmutableArray <AnalyzerMetadata> analyzers2, string @namespace) { WriteCompilationUnit( Path.Combine(dirPath, "DiagnosticDescriptors.Generated.cs"), DiagnosticDescriptorsGenerator.Generate(analyzers2, obsolete: false, comparer: comparer, @namespace: @namespace), normalizeWhitespace: false); WriteCompilationUnit( Path.Combine(dirPath, "DiagnosticDescriptors.Deprecated.Generated.cs"), DiagnosticDescriptorsGenerator.Generate(analyzers2, obsolete: true, comparer: comparer, @namespace: @namespace), normalizeWhitespace: false); WriteCompilationUnit( Path.Combine(dirPath, "DiagnosticIdentifiers.Generated.cs"), DiagnosticIdentifiersGenerator.Generate(analyzers2, obsolete: false, comparer: comparer, @namespace: @namespace)); WriteCompilationUnit( Path.Combine(dirPath, "DiagnosticIdentifiers.Deprecated.Generated.cs"), DiagnosticIdentifiersGenerator.Generate(analyzers2, obsolete: true, comparer: comparer, @namespace: @namespace)); } void WriteCompilationUnit( string path, CompilationUnitSyntax compilationUnit, bool autoGenerated = true, bool normalizeWhitespace = true, bool fileMustExist = true, bool overwrite = true) { CodeGenerationHelpers.WriteCompilationUnit( path: Path.Combine(rootPath, path), compilationUnit: compilationUnit, banner: "Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.", autoGenerated: autoGenerated, normalizeWhitespace: normalizeWhitespace, fileMustExist: fileMustExist, overwrite: overwrite); } }
private static void Main(string[] args) { if (args == null || args.Length == 0) { #if DEBUG args = new[] { @"..\..\..\..\.." }; #else args = new string[] { Environment.CurrentDirectory }; #endif } string rootPath = args[0]; StringComparer comparer = StringComparer.InvariantCulture; var metadata = new RoslynatorMetadata(rootPath); ImmutableArray <AnalyzerMetadata> analyzers = metadata.Analyzers; ImmutableArray <AnalyzerMetadata> codeAnalysisAnalyzers = metadata.CodeAnalysisAnalyzers; ImmutableArray <AnalyzerMetadata> formattingAnalyzers = metadata.FormattingAnalyzers; ImmutableArray <RefactoringMetadata> refactorings = metadata.Refactorings; ImmutableArray <CodeFixMetadata> codeFixes = metadata.CodeFixes; ImmutableArray <CompilerDiagnosticMetadata> compilerDiagnostics = metadata.CompilerDiagnostics; ImmutableArray <ConfigOptionMetadata> options = metadata.ConfigOptions; WriteCompilationUnit( @"Refactorings\CSharp\RefactoringDescriptors.Generated.cs", RefactoringDescriptorsGenerator.Generate(refactorings.Where(f => !f.IsObsolete), comparer: comparer)); WriteCompilationUnit( @"Refactorings\CSharp\RefactoringIdentifiers.Generated.cs", RefactoringIdentifiersGenerator.Generate(refactorings, obsolete: false, comparer: comparer)); WriteCompilationUnit( @"Refactorings\CSharp\RefactoringIdentifiers.Deprecated.Generated.cs", RefactoringIdentifiersGenerator.Generate(refactorings, obsolete: true, comparer: comparer)); WriteCompilationUnit( @"VisualStudio.Common\RefactoringsOptionsPage.Generated.cs", RefactoringsOptionsPageGenerator.Generate(refactorings.Where(f => !f.IsObsolete), comparer)); WriteDiagnostics(@"Analyzers\CSharp", analyzers, @namespace: "Roslynator.CSharp", categoryName: nameof(DiagnosticCategories.Roslynator)); WriteDiagnostics(@"CodeAnalysis.Analyzers\CSharp", codeAnalysisAnalyzers, @namespace: "Roslynator.CodeAnalysis.CSharp", categoryName: nameof(DiagnosticCategories.Roslynator)); WriteDiagnostics(@"Formatting.Analyzers\CSharp", formattingAnalyzers, @namespace: "Roslynator.Formatting.CSharp", categoryName: nameof(DiagnosticCategories.Roslynator)); WriteCompilationUnit( @"CodeFixes\CSharp\CompilerDiagnosticRules.Generated.cs", CompilerDiagnosticRulesGenerator.Generate(compilerDiagnostics, comparer: comparer, @namespace: "Roslynator.CSharp"), normalizeWhitespace: false); WriteCompilationUnit( @"CodeFixes\CSharp\CodeFixDescriptors.Generated.cs", CodeFixDescriptorsGenerator.Generate(codeFixes.Where(f => !f.IsObsolete), comparer: comparer, @namespace: "Roslynator.CSharp"), normalizeWhitespace: false); WriteCompilationUnit( @"CodeFixes\CSharp\CodeFixIdentifiers.Generated.cs", CodeFixIdentifiersGenerator.Generate(codeFixes, comparer)); WriteCompilationUnit( @"VisualStudio.Common\CodeFixesOptionsPage.Generated.cs", CodeFixesOptionsPageGenerator.Generate()); WriteCompilationUnit( @"CSharp\CSharp\CompilerDiagnosticIdentifiers.Generated.cs", CompilerDiagnosticIdentifiersGenerator.Generate(compilerDiagnostics, comparer)); WriteCompilationUnit( @"Common\ConfigOptions.Generated.cs", CodeGenerator.GenerateConfigOptions(options, metadata.GetAllAnalyzers()), normalizeWhitespace: false); WriteCompilationUnit( @"Common\LegacyConfigOptions.Generated.cs", CodeGenerator.GenerateLegacyConfigOptions(metadata.GetAllAnalyzers())); WriteCompilationUnit( @"Common\ConfigOptionKeys.Generated.cs", CodeGenerator.GenerateConfigOptionKeys(options), normalizeWhitespace: false); WriteCompilationUnit( @"Common\ConfigOptionValues.Generated.cs", CodeGenerator.GenerateConfigOptionValues(options), normalizeWhitespace: false); WriteCompilationUnit( @"Tools\CodeGeneration\CSharp\Symbols.Generated.cs", SymbolsGetKindsGenerator.Generate()); WriteCompilationUnit( @"CSharp\CSharp\SyntaxWalkers\CSharpSyntaxNodeWalker.cs", CSharpSyntaxNodeWalkerGenerator.Generate()); string configFileContent = File.ReadAllText(Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "Configuration.md")); configFileContent += @"# Full List of Options ```editorconfig" + EditorConfigGenerator.GenerateEditorConfig(metadata, commentOut: false) + @"``` "; var utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); File.WriteAllText( Path.Combine(rootPath, "../docs/Configuration.md"), configFileContent, utf8NoBom); File.WriteAllText( Path.Combine(rootPath, @"VisualStudioCode\package\src\configurationFiles.generated.ts"), @"export const configurationFileContent = { roslynatorconfig: `" + EditorConfigCodeAnalysisConfig.FileDefaultContent + EditorConfigGenerator.GenerateEditorConfig(metadata, commentOut: true) + @"` };", utf8NoBom); Console.WriteLine($"number of analyzers: {analyzers.Count(f => !f.IsObsolete)}"); Console.WriteLine($"number of code analysis analyzers: {codeAnalysisAnalyzers.Count(f => !f.IsObsolete)}"); Console.WriteLine($"number of formatting analyzers: {formattingAnalyzers.Count(f => !f.IsObsolete)}"); Console.WriteLine($"number of refactorings: {refactorings.Length}"); Console.WriteLine($"number of code fixes: {codeFixes.Length}"); Console.WriteLine($"number of fixable compiler diagnostics: {codeFixes.SelectMany(f => f.FixableDiagnosticIds).Distinct().Count()}"); void WriteDiagnostics( string dirPath, ImmutableArray <AnalyzerMetadata> analyzers, string @namespace, string categoryName, string descriptorsClassName = "DiagnosticRules", string identifiersClassName = "DiagnosticIdentifiers") { WriteCompilationUnit( Path.Combine(dirPath, $"{descriptorsClassName}.Generated.cs"), DiagnosticRulesGenerators.Default.Generate(analyzers, obsolete: false, comparer: comparer, @namespace: @namespace, className: descriptorsClassName, identifiersClassName: identifiersClassName, categoryName: categoryName), normalizeWhitespace: false); WriteCompilationUnit( Path.Combine(dirPath, $"{descriptorsClassName}.Deprecated.Generated.cs"), DiagnosticRulesGenerators.Default.Generate(analyzers, obsolete: true, comparer: comparer, @namespace: @namespace, className: descriptorsClassName, identifiersClassName: identifiersClassName, categoryName: categoryName), normalizeWhitespace: false); WriteCompilationUnit( Path.Combine(dirPath, $"{identifiersClassName}.Generated.cs"), DiagnosticIdentifiersGenerator.Generate(analyzers, obsolete: false, comparer: comparer, @namespace: @namespace, className: identifiersClassName)); WriteCompilationUnit( Path.Combine(dirPath, $"{identifiersClassName}.Deprecated.Generated.cs"), DiagnosticIdentifiersGenerator.Generate(analyzers, obsolete: true, comparer: comparer, @namespace: @namespace, className: identifiersClassName)); } void WriteCompilationUnit( string path, CompilationUnitSyntax compilationUnit, bool autoGenerated = true, bool normalizeWhitespace = true, bool fileMustExist = true, bool overwrite = true) { CodeGenerationHelpers.WriteCompilationUnit( path: Path.Combine(rootPath, path), compilationUnit: compilationUnit, banner: "Copyright (c) Josef Pihrt and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.", autoGenerated: autoGenerated, normalizeWhitespace: normalizeWhitespace, fileMustExist: fileMustExist, overwrite: overwrite); } }