private static void HandleEditorConfigFiles( ILogger logger, DirectoryInfo projectPath, OptionsFile options) { logger.LogInformation($"{AppEmojisConstants.AreaEditorConfig} Working on EditorConfig files"); var rawCodingRulesDistributionProjectTargetBaseUrl = $"{RawCodingRulesDistributionBaseUrl}/{options.ProjectTarget.ToStringLowerCase()}"; EditorConfigHelper.HandleFile(logger, "root", rawCodingRulesDistributionProjectTargetBaseUrl, projectPath, string.Empty); foreach (var item in options.Mappings.Sample.Paths) { var path = new DirectoryInfo(item); EditorConfigHelper.HandleFile(logger, "sample", rawCodingRulesDistributionProjectTargetBaseUrl, path, "sample"); } foreach (var item in options.Mappings.Src.Paths) { var path = new DirectoryInfo(item); EditorConfigHelper.HandleFile(logger, "src", rawCodingRulesDistributionProjectTargetBaseUrl, path, "src"); } foreach (var item in options.Mappings.Test.Paths) { var path = new DirectoryInfo(item); EditorConfigHelper.HandleFile(logger, "test", rawCodingRulesDistributionProjectTargetBaseUrl, path, "test"); } }
public void DotNet6_Root_NothingToUpdate2() { // Arrange using var logger = testOutput.BuildLogger(); var outputFile = PrepareOutputFile("test1.txt"); var contentGit = GetContentFromTestFile("Git_DotNet6_Root_1c.txt"); var contentFile = GetContentFromTestFile("Git_DotNet6_Root_1c.txt"); // Act EditorConfigHelper.HandleFile( logger, "log-area", contentGit, contentFile, "log-description-part", outputFile); // Assert Assert.False(outputFile.Exists); logger.Entries .Should().HaveCount(1) .And.Subject.Should().Contain(x => x.Message.Contains("log-description-part nothing to update")); }
public void DotNet6_Root_Update1() { // Arrange using var logger = testOutput.BuildLogger(); var outputFile = PrepareOutputFile("test1.txt"); var expectedContent = GetContentFromTestFile("Result_DotNet6_Root_1a.txt"); var contentGit = GetContentFromTestFile("Git_DotNet6_Root_1c.txt"); var contentFile = GetContentFromTestFile("Git_DotNet6_Root_1a.txt"); // Act EditorConfigHelper.HandleFile( logger, "log-area", contentGit, contentFile, "log-description-part", outputFile); var actual = FileHelper.ReadAllText(outputFile); // Assert Assert.Equal(expectedContent, actual); logger.Entries .Should().HaveCount(1) .And.Subject.Should().Contain(x => x.Message.Contains("log-description-part files merged")); }
public void DotNet6_Root_Update3_NewKey() { // Arrange using var logger = testOutput.BuildLogger(); var outputFile = PrepareOutputFile("test1.txt"); var expectedContent = GetContentFromTestFile("Result_DotNet6_Root_1b.txt"); var contentGit = GetContentFromTestFile("Git_DotNet6_Root_1d.txt"); var contentFile = GetContentFromTestFile("File_DotNet6_Root_1a.txt"); // Act EditorConfigHelper.HandleFile( logger, "log-area", contentGit, contentFile, "log-description-part", outputFile); var actual = FileHelper.ReadAllText(outputFile); // Assert Assert.Equal(expectedContent, actual); logger.Entries .Should().HaveCount(5) .And.Subject.Should().Contain(x => x.Message.Contains("Duplicate key: dotnet_diagnostic.SA1200.severity")) .And.Subject.Should().Contain(x => x.Message.Contains("GitHub section (line 0478)")) .And.Subject.Should().Contain(x => x.Message.Contains("Custom section (line 0506)")) .And.Subject.Should().Contain(x => x.Message.Contains("New key/value - dotnet_diagnostic.SA1201.severity = none # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/StyleCop/SA1201.md")); }
private static async Task <bool> BuildAndCollectErrorsAgainAndUpdateFile( ILogger logger, DirectoryInfo projectPath, int runNumber, FileInfo?buildFile, Dictionary <string, int> buildResult, Collection <AnalyzerProviderBaseRuleData> analyzerProviderBaseRules) { bool hasFoundNewErrors; try { var buildResultNextRun = await DotnetBuildHelper.BuildAndCollectErrors( logger, projectPath, runNumber, buildFile, useNugetRestore : true, useConfigurationReleaseMode : true, BuildDefaultTimeoutInSec, " "); hasFoundNewErrors = buildResultNextRun.Count > 0; foreach (var(key, value) in buildResultNextRun) { if (buildResult.ContainsKey(key)) { buildResult[key] += value; } else { buildResult.Add(key, value); } } } catch (DataException ex) { logger.LogError($"{EmojisConstants.Error} {ex.Message}"); return(false); } if (hasFoundNewErrors) { var suppressionLinesPrAnalyzer = GetSuppressionLines(analyzerProviderBaseRules, buildResult); if (suppressionLinesPrAnalyzer.Any()) { await EditorConfigHelper.UpdateRootFileRemoveCustomAtcAutogeneratedRuleSuppressions(projectPath); await EditorConfigHelper.UpdateRootFileAddCustomAtcAutogeneratedRuleSuppressions(projectPath, suppressionLinesPrAnalyzer); return(true); } } return(false); }
private static async Task HandleTemporarySuppressions( ILogger logger, DirectoryInfo projectPath, FileInfo?buildFile, DirectoryInfo?temporarySuppressionsPath, bool temporarySuppressionAsExcel) { logger.LogInformation($"{AppEmojisConstants.AreaTemporarySuppression} Working on temporary suppressions"); if (!FileHelper.ContainsSolutionOrProjectFile(projectPath) && !FileHelper.IsSolutionOrProjectFile(buildFile)) { logger.LogInformation(" Nothing to build! -projectPath do not contains a .sln or .csproj file"); return; } var analyzerProviderBaseRules = await AnalyzerProviderBaseRulesHelper.GetAnalyzerProviderBaseRules( logger, ProviderCollectingMode.LocalCache, logWithAnsiConsoleMarkup : true); var stopwatch = Stopwatch.StartNew(); logger.LogTrace(" Collecting build errors"); var rootEditorConfigContent = string.Empty; if (temporarySuppressionsPath is null) { await EditorConfigHelper.UpdateRootFileRemoveCustomAtcAutogeneratedRuleSuppressions(projectPath); } else { rootEditorConfigContent = await EditorConfigHelper.ReadAllText(projectPath); DeleteSuppressionsFileInTempPath(temporarySuppressionsPath, temporarySuppressionAsExcel); } Dictionary <string, int> buildResult; try { buildResult = await DotnetBuildHelper.BuildAndCollectErrors( logger, projectPath, 1, buildFile, useNugetRestore : true, useConfigurationReleaseMode : true, BuildDefaultTimeoutInSec, " "); } catch (DataException ex) { logger.LogError($"{EmojisConstants.Error} {ex.Message}"); return; } catch (IOException ex) { logger.LogError($"{EmojisConstants.Error} {ex.Message}"); return; } if (buildResult.Any(x => x.Key.StartsWith("MSB", StringComparison.Ordinal))) { var errorTypes = buildResult .Where(x => x.Key.StartsWith("MSB", StringComparison.Ordinal)) .Select(x => x.Key) .OrderBy(x => x) .ToList(); logger.LogWarning($" MSB-errors ({string.Join(',', errorTypes)}) was found, please correct them manually first and try again."); } else if (buildResult.Any(x => x.Key.StartsWith("NU", StringComparison.Ordinal))) { var errorTypes = buildResult .Where(x => x.Key.StartsWith("NU", StringComparison.Ordinal)) .Select(x => x.Key) .OrderBy(x => x) .ToList(); logger.LogWarning($" NU-errors ({string.Join(',', errorTypes)}) was found, please correct them manually first and try again."); } else { var suppressionLinesPrAnalyzer = GetSuppressionLines(analyzerProviderBaseRules, buildResult); if (suppressionLinesPrAnalyzer.Any()) { await EditorConfigHelper.UpdateRootFileAddCustomAtcAutogeneratedRuleSuppressions(projectPath, suppressionLinesPrAnalyzer); for (var i = 0; i < MaxNumberOfTimesToBuild; i++) { var runAgain = await BuildAndCollectErrorsAgainAndUpdateFile( logger, projectPath, 2 + i, buildFile, buildResult, analyzerProviderBaseRules); if (!runAgain) { break; } } suppressionLinesPrAnalyzer = GetSuppressionLines(analyzerProviderBaseRules, buildResult); if (temporarySuppressionsPath is not null) { await EditorConfigHelper.WriteAllText(projectPath, rootEditorConfigContent); await CreateSuppressionsFileInTempPath(logger, temporarySuppressionsPath, temporarySuppressionAsExcel, suppressionLinesPrAnalyzer); } else { var totalSuppressions = suppressionLinesPrAnalyzer.Sum(x => x.Item2.Count); logger.LogInformation($"{EmojisConstants.FileUpdated} [yellow]/[/]{EditorConfigHelper.FileName} is updated with {totalSuppressions} suppressions"); } } else { logger.LogTrace(" No suppressions to add."); } } stopwatch.Stop(); logger.LogTrace($" Collecting build errors time: {stopwatch.Elapsed.GetPrettyTime()}"); }