Skip to content

Commit 498edd6

Browse files
committed
feat: Improve handle temporarySuppressions when MSB and NU errors is found
1 parent 1164490 commit 498edd6

File tree

1 file changed

+51
-28
lines changed

1 file changed

+51
-28
lines changed

src/Atc.CodingRules.Updater.CLI/ProjectHelper.cs

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Atc.CodingRules.Updater.CLI.Models.Options;
21
using Atc.DotNet;
32
using OfficeOpenXml;
43
using OfficeOpenXml.Style;
@@ -198,40 +197,64 @@ private static async Task HandleTemporarySuppressions(
198197
return;
199198
}
200199

201-
var suppressionLinesPrAnalyzer = GetSuppressionLines(analyzerProviderBaseRules, buildResult);
202-
if (!suppressionLinesPrAnalyzer.Any())
200+
if (buildResult.Any(x => x.Key.StartsWith("MSB", StringComparison.Ordinal)))
203201
{
204-
logger.LogTrace(" No suppressions to add.");
205-
return;
206-
}
207-
208-
await EditorConfigHelper.UpdateRootFileAddCustomAtcAutogeneratedRuleSuppressions(projectPath, suppressionLinesPrAnalyzer);
209-
for (var i = 0; i < MaxNumberOfTimesToBuild; i++)
210-
{
211-
var runAgain = await BuildAndCollectErrorsAgainAndUpdateFile(
212-
logger,
213-
projectPath,
214-
2 + i,
215-
buildFile,
216-
buildResult,
217-
analyzerProviderBaseRules);
202+
var errorTypes = buildResult
203+
.Where(x => x.Key.StartsWith("MSB", StringComparison.Ordinal))
204+
.Select(x => x.Key)
205+
.OrderBy(x => x)
206+
.ToList();
218207

219-
if (!runAgain)
220-
{
221-
break;
222-
}
208+
logger.LogWarning($" MSB-errors ({string.Join(',', errorTypes)}) was found, please correct them manually first and try again.");
223209
}
224-
225-
suppressionLinesPrAnalyzer = GetSuppressionLines(analyzerProviderBaseRules, buildResult);
226-
if (temporarySuppressionsPath is not null)
210+
else if (buildResult.Any(x => x.Key.StartsWith("NU", StringComparison.Ordinal)))
227211
{
228-
await EditorConfigHelper.WriteAllText(projectPath, rootEditorConfigContent);
229-
await CreateSuppressionsFileInTempPath(logger, temporarySuppressionsPath, temporarySuppressionAsExcel, suppressionLinesPrAnalyzer);
212+
var errorTypes = buildResult
213+
.Where(x => x.Key.StartsWith("NU", StringComparison.Ordinal))
214+
.Select(x => x.Key)
215+
.OrderBy(x => x)
216+
.ToList();
217+
218+
logger.LogWarning($" NU-errors ({string.Join(',', errorTypes)}) was found, please correct them manually first and try again.");
230219
}
231220
else
232221
{
233-
var totalSuppressions = suppressionLinesPrAnalyzer.Sum(x => x.Item2.Count);
234-
logger.LogInformation($"{EmojisConstants.FileUpdated} [yellow]/[/]{EditorConfigHelper.FileName} is updated with {totalSuppressions} suppressions");
222+
var suppressionLinesPrAnalyzer = GetSuppressionLines(analyzerProviderBaseRules, buildResult);
223+
if (suppressionLinesPrAnalyzer.Any())
224+
{
225+
await EditorConfigHelper.UpdateRootFileAddCustomAtcAutogeneratedRuleSuppressions(projectPath, suppressionLinesPrAnalyzer);
226+
for (var i = 0; i < MaxNumberOfTimesToBuild; i++)
227+
{
228+
var runAgain = await BuildAndCollectErrorsAgainAndUpdateFile(
229+
logger,
230+
projectPath,
231+
2 + i,
232+
buildFile,
233+
buildResult,
234+
analyzerProviderBaseRules);
235+
236+
if (!runAgain)
237+
{
238+
break;
239+
}
240+
}
241+
242+
suppressionLinesPrAnalyzer = GetSuppressionLines(analyzerProviderBaseRules, buildResult);
243+
if (temporarySuppressionsPath is not null)
244+
{
245+
await EditorConfigHelper.WriteAllText(projectPath, rootEditorConfigContent);
246+
await CreateSuppressionsFileInTempPath(logger, temporarySuppressionsPath, temporarySuppressionAsExcel, suppressionLinesPrAnalyzer);
247+
}
248+
else
249+
{
250+
var totalSuppressions = suppressionLinesPrAnalyzer.Sum(x => x.Item2.Count);
251+
logger.LogInformation($"{EmojisConstants.FileUpdated} [yellow]/[/]{EditorConfigHelper.FileName} is updated with {totalSuppressions} suppressions");
252+
}
253+
}
254+
else
255+
{
256+
logger.LogTrace(" No suppressions to add.");
257+
}
235258
}
236259

237260
stopwatch.Stop();

0 commit comments

Comments
 (0)