public static string CreateCodeFixesByDiagnosticId(IEnumerable <CodeFixDescriptor> codeFixes, IEnumerable <CompilerDiagnosticDescriptor> diagnostics) { using (var sw = new StringWriter()) { sw.WriteLine("## Roslynator Code Fixes by Diagnostic Id"); sw.WriteLine(); sw.WriteLine("Diagnostic | Code Fixes"); sw.WriteLine("--- | ---"); foreach (var grouping in codeFixes .SelectMany(f => f.FixableDiagnosticIds.Select(ff => new { DiagnosticId = ff, CodeFixDescriptor = f })) .OrderBy(f => f.DiagnosticId) .ThenBy(f => f.CodeFixDescriptor.Id) .GroupBy(f => f.DiagnosticId)) { CompilerDiagnosticDescriptor diagnostic = diagnostics.FirstOrDefault(f => f.Id == grouping.Key); if (!string.IsNullOrEmpty(diagnostic?.HelpUrl)) { sw.Write($"[{diagnostic.Id}]({diagnostic.HelpUrl})"); } else { sw.Write(grouping.Key); } sw.Write('|'); sw.Write(string.Join(", ", grouping.Select(f => f.CodeFixDescriptor.Id))); sw.WriteLine(); } return(sw.ToString()); } }
public static string CreateCodeFixesByDiagnosticId(IEnumerable <CodeFixDescriptor> codeFixes, IEnumerable <CompilerDiagnosticDescriptor> diagnostics) { var sb = new StringBuilder(); sb.AppendHeader2("Roslynator Code Fixes by Diagnostic Id"); sb.AppendLine(); sb.AppendTableHeader("Diagnostic", "Code Fixes"); foreach (var grouping in codeFixes .SelectMany(codeFix => codeFix.FixableDiagnosticIds.Select(diagnosticId => new { DiagnosticId = diagnosticId, CodeFixDescriptor = codeFix })) .OrderBy(f => f.DiagnosticId) .ThenBy(f => f.CodeFixDescriptor.Id) .GroupBy(f => f.DiagnosticId)) { CompilerDiagnosticDescriptor diagnostic = diagnostics.FirstOrDefault(f => f.Id == grouping.Key); if (!string.IsNullOrEmpty(diagnostic?.HelpUrl)) { sb.AppendLink(diagnostic.Id, diagnostic.HelpUrl); } else { sb.Append(grouping.Key); } sb.Append('|'); sb.Append(string.Join(", ", grouping.Select(f => f.CodeFixDescriptor.Id))); sb.AppendLine(); } return(sb.ToString()); }
public static string CreateCodeFixesByDiagnosticId(IEnumerable <CodeFixDescriptor> codeFixes, IEnumerable <CompilerDiagnosticDescriptor> diagnostics) { var mb = new MarkdownBuilder(); mb.AppendHeader2("Roslynator Code Fixes by Diagnostic Id"); Table table = Table("Diagnostic", "Code Fixes"); foreach (var grouping in codeFixes .SelectMany(codeFix => codeFix.FixableDiagnosticIds.Select(diagnosticId => new { DiagnosticId = diagnosticId, CodeFixDescriptor = codeFix })) .OrderBy(f => f.DiagnosticId) .ThenBy(f => f.CodeFixDescriptor.Id) .GroupBy(f => f.DiagnosticId)) { CompilerDiagnosticDescriptor diagnostic = diagnostics.FirstOrDefault(f => f.Id == grouping.Key); table.AddRow( Link(diagnostic?.Id ?? grouping.Key, diagnostic?.HelpUrl), Join(", ", grouping.Select(f => f.CodeFixDescriptor.Id))); } mb.Append(table); return(mb.ToString()); }
public static CompilationUnitSyntax Generate(CompilerDiagnosticDescriptor compilerDiagnostic, string className) { string s = _sourceTemplate .Replace("$ClassName$", className) .Replace("$Id$", compilerDiagnostic.Id) .Replace("$Identifier$", compilerDiagnostic.Identifier); return(ParseCompilationUnit(s)); }
public static string CreateCompilerDiagnosticMarkdown(CompilerDiagnosticDescriptor diagnostic, IEnumerable <CodeFixDescriptor> codeFixes, IComparer <string> comparer) { MDocument document = Document( Heading1(diagnostic.Id), Table( TableRow("Property", "Value"), TableRow("Id", diagnostic.Id), TableRow("Title", diagnostic.Title), TableRow("Severity", diagnostic.Severity), (!string.IsNullOrEmpty(diagnostic.HelpUrl)) ? TableRow("Official Documentation", Link("link", diagnostic.HelpUrl)) : null), Heading2("Code Fixes"), BulletList(codeFixes .Where(f => f.FixableDiagnosticIds.Any(diagnosticId => diagnosticId == diagnostic.Id)) .Select(f => f.Title) .OrderBy(f => f, comparer))); return(document.ToString(MarkdownFormat.Default.WithTableOptions(MarkdownFormat.Default.TableOptions | TableOptions.FormatContent))); }
private static void Main(string[] args) { string rootPath = args[0]; var metadata = new RoslynatorMetadata(rootPath); ImmutableArray <AnalyzerDescriptor> analyzers = metadata.Analyzers; ImmutableArray <RefactoringDescriptor> refactorings = metadata.Refactorings; ImmutableArray <CompilerDiagnosticDescriptor> compilerDiagnostics = metadata.CompilerDiagnostics; foreach (string id in args.Skip(1)) { if (_analyzerIdRegex.IsMatch(id)) { AnalyzerDescriptor 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)) { RefactoringDescriptor 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)) { CompilerDiagnosticDescriptor 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); } }