From feb8e62223fb9afce015773158225a8223cabf98 Mon Sep 17 00:00:00 2001 From: Jeroen van Warmerdam Date: Sun, 18 Aug 2024 17:46:57 +0200 Subject: [PATCH] Bind SonarCloud --- .sonarlint/Jvw.DevToys.SemverCalculator.json | 4 ++++ .../Components/CheatSheetComponent.cs | 2 +- Jvw.DevToys.SemverCalculator/Gui.cs | 15 +++++++++------ Jvw.DevToys.SemverCalculator/Models/Settings.cs | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 .sonarlint/Jvw.DevToys.SemverCalculator.json diff --git a/.sonarlint/Jvw.DevToys.SemverCalculator.json b/.sonarlint/Jvw.DevToys.SemverCalculator.json new file mode 100644 index 0000000..821ff99 --- /dev/null +++ b/.sonarlint/Jvw.DevToys.SemverCalculator.json @@ -0,0 +1,4 @@ +{ + "SonarCloudOrganization": "jerone", + "ProjectKey": "jerone_Jvw.DevToys.SemverCalculator" +} \ No newline at end of file diff --git a/Jvw.DevToys.SemverCalculator/Components/CheatSheetComponent.cs b/Jvw.DevToys.SemverCalculator/Components/CheatSheetComponent.cs index c5fa7a6..9500dbf 100644 --- a/Jvw.DevToys.SemverCalculator/Components/CheatSheetComponent.cs +++ b/Jvw.DevToys.SemverCalculator/Components/CheatSheetComponent.cs @@ -7,7 +7,7 @@ namespace Jvw.DevToys.SemverCalculator.Components; /// /// Cheat sheet component. /// -internal class CheatSheetComponent +internal static class CheatSheetComponent { /// /// Columns for the cheat sheet. diff --git a/Jvw.DevToys.SemverCalculator/Gui.cs b/Jvw.DevToys.SemverCalculator/Gui.cs index 16fa302..c2d9fbe 100644 --- a/Jvw.DevToys.SemverCalculator/Gui.cs +++ b/Jvw.DevToys.SemverCalculator/Gui.cs @@ -1,4 +1,5 @@ using System.ComponentModel.Composition; +using System.Diagnostics; using System.Net; using System.Text.Json; using DevToys.Api; @@ -232,7 +233,7 @@ private List MatchVersions() foreach (var version in versions) { - if (_includePreReleases == false && version.IsPrerelease) + if (!_includePreReleases && version.IsPrerelease) { continue; } @@ -258,7 +259,7 @@ public void OnDataReceived(string dataTypeName, object? parsedData) private async Task FetchPackage(string packageName) { - _logger.LogInformation($"Fetching package \"{packageName}\"..."); + _logger.LogInformation("Fetching package \"{PackageName}\"...", packageName); try { var client = new HttpClient(); @@ -268,7 +269,7 @@ public void OnDataReceived(string dataTypeName, object? parsedData) var response = await client.GetAsync($"https://registry.npmjs.org/{packageName}/"); response.EnsureSuccessStatusCode(); - _logger.LogInformation($"Fetched packages \"{packageName}\"."); + _logger.LogInformation("Fetched packages \"{PackageName}\".", packageName); var contentStream = await response.Content.ReadAsStreamAsync(); @@ -281,13 +282,15 @@ public void OnDataReceived(string dataTypeName, object? parsedData) } catch (HttpRequestException e) when (e.StatusCode == HttpStatusCode.NotFound) { - _logger.LogWarning($"Package \"{packageName}\" not found."); - Console.WriteLine(e.Message); +#pragma warning disable S6667 + _logger.LogWarning("Package \"{PackageName}\" not found.", packageName); +#pragma warning restore S6667 + Debug.WriteLine(e.Message); return null; } catch (Exception e) { - _logger.LogError(e, $"Failed to fetch package \"{packageName}\"."); + _logger.LogError(e, "Failed to fetch package \"{PackageName}\".", packageName); Console.WriteLine(e.Message); return null; } diff --git a/Jvw.DevToys.SemverCalculator/Models/Settings.cs b/Jvw.DevToys.SemverCalculator/Models/Settings.cs index 745f2ee..81019e2 100644 --- a/Jvw.DevToys.SemverCalculator/Models/Settings.cs +++ b/Jvw.DevToys.SemverCalculator/Models/Settings.cs @@ -10,6 +10,6 @@ internal static class Settings /// /// When user closes the HTTP agreement info-bar, this setting is set to true. /// - public static SettingDefinition HttpAgreementClosed = + public static readonly SettingDefinition HttpAgreementClosed = new(name: "Settings." + nameof(HttpAgreementClosed), defaultValue: false); }