|
56 | 56 | {
|
57 | 57 | // The main readme is embedded into the NuGet package and rendered by nuget.org.
|
58 | 58 | // nuget.org's markdown support is limited. Raw html in table is not supported.
|
59 |
| - var readmePath = Path.GetFullPath(Path.Combine(outputFolder, "README.md")); |
| 59 | + var readmePath = outputFolder / "README.md"; |
60 | 60 | var readmeContent = await File.ReadAllTextAsync(readmePath);
|
61 | 61 | var newContent = Regex.Replace(readmeContent, "(?<=<!-- rules -->\\r?\\n).*(?=<!-- rules -->)", "\n" + GenerateRulesTable(diagnosticAnalyzers, codeFixProviders, addTitle: false) + "\n", RegexOptions.Singleline);
|
62 | 62 | newContent = Regex.Replace(newContent, "(?<=<!-- suppressions -->\\r?\\n).*(?=<!-- suppressions -->)", "\n" + GenerateSuppressorsTable(diagnosticSuppressors) + "\n", RegexOptions.Singleline);
|
|
65 | 65 |
|
66 | 66 | // Update doc readme
|
67 | 67 | {
|
68 |
| - var path = Path.GetFullPath(Path.Combine(outputFolder, "docs", "README.md")); |
| 68 | + var path = outputFolder / "docs" / "README.md"; |
69 | 69 | Console.WriteLine(path);
|
70 | 70 | WriteFileIfChanged(path, sb.ToString());
|
71 | 71 | }
|
|
75 | 75 | foreach (var diagnostic in diagnosticAnalyzers.SelectMany(diagnosticAnalyzer => diagnosticAnalyzer.SupportedDiagnostics).DistinctBy(diag => diag.Id).OrderBy(diag => diag.Id, StringComparer.Ordinal))
|
76 | 76 | {
|
77 | 77 | var title = $"# {diagnostic.Id} - {EscapeMarkdown(diagnostic.Title.ToString(CultureInfo.InvariantCulture))}";
|
78 |
| - var detailPath = Path.GetFullPath(Path.Combine(outputFolder, "docs", "Rules", diagnostic.Id + ".md")); |
| 78 | + var detailPath = outputFolder / "docs" / "Rules" / (diagnostic.Id + ".md"); |
79 | 79 | if (File.Exists(detailPath))
|
80 | 80 | {
|
81 | 81 | var lines = await File.ReadAllLinesAsync(detailPath);
|
|
89 | 89 | }
|
90 | 90 | }
|
91 | 91 |
|
| 92 | +// Update editorconfig files for NuGet package |
| 93 | +{ |
| 94 | + GenerateFile(outputFolder / "src" / "Meziantou.Analyzer.Pack" / "configuration" / "none.editorconfig", sb => GenerateEditorConfig(sb, diagnosticAnalyzers, overrideSeverity: "none", appendCodeBlock: false)); |
| 95 | + GenerateFile(outputFolder / "src" / "Meziantou.Analyzer.Pack" / "configuration" / "default.editorconfig", sb => GenerateEditorConfig(sb, diagnosticAnalyzers, overrideSeverity: null, appendCodeBlock: false)); |
| 96 | + void GenerateFile(FullPath outputPath, Action<StringBuilder> code) |
| 97 | + { |
| 98 | + var sb = new StringBuilder(); |
| 99 | + sb.Append("# This file is generated by the build process. Do not edit it manually.\n"); |
| 100 | + sb.Append("is_global = true\n"); |
| 101 | + sb.Append("global_level = 0\n"); |
| 102 | + sb.Append('\n'); |
| 103 | + code(sb); |
| 104 | + WriteFileIfChanged(outputPath, sb.ToString()); |
| 105 | + } |
| 106 | +} |
| 107 | + |
92 | 108 | return fileWritten;
|
93 | 109 |
|
94 |
| -void WriteFileIfChanged(string path, string content) |
| 110 | +void WriteFileIfChanged(FullPath path, string content) |
95 | 111 | {
|
96 | 112 | content = content.ReplaceLineEndings("\n");
|
97 |
| - |
98 | 113 | if (!File.Exists(path))
|
99 | 114 | {
|
| 115 | + path.CreateParentDirectory(); |
100 | 116 | File.WriteAllText(path, content);
|
101 | 117 | fileWritten++;
|
102 | 118 | return;
|
@@ -200,9 +216,13 @@ static string GenerateSuppressorsTable(List<DiagnosticSuppressor> diagnosticSupp
|
200 | 216 | return sb.ToString();
|
201 | 217 | }
|
202 | 218 |
|
203 |
| -static void GenerateEditorConfig(StringBuilder sb, List<DiagnosticAnalyzer> analyzers, string? overrideSeverity = null) |
| 219 | +static void GenerateEditorConfig(StringBuilder sb, List<DiagnosticAnalyzer> analyzers, string? overrideSeverity = null, bool appendCodeBlock = true) |
204 | 220 | {
|
205 |
| - sb.Append("```editorconfig\n"); |
| 221 | + if (appendCodeBlock) |
| 222 | + { |
| 223 | + sb.Append("```editorconfig\n"); |
| 224 | + } |
| 225 | + |
206 | 226 | var first = true;
|
207 | 227 | foreach (var diagnostic in analyzers.SelectMany(diagnosticAnalyzer => diagnosticAnalyzer.SupportedDiagnostics).DistinctBy(diag => diag.Id).OrderBy(diag => diag.Id, StringComparer.Ordinal))
|
208 | 228 | {
|
@@ -237,7 +257,10 @@ static void GenerateEditorConfig(StringBuilder sb, List<DiagnosticAnalyzer> anal
|
237 | 257 | first = false;
|
238 | 258 | }
|
239 | 259 |
|
240 |
| - sb.Append("```\n"); |
| 260 | + if (appendCodeBlock) |
| 261 | + { |
| 262 | + sb.Append("```\n"); |
| 263 | + } |
241 | 264 | }
|
242 | 265 |
|
243 | 266 | static string GetSeverity(DiagnosticSeverity severity)
|
|
0 commit comments