From 7c9a162e6522ce993684dea484d9bb49e70a5d01 Mon Sep 17 00:00:00 2001 From: Gabriela Trutan Date: Wed, 8 Jan 2025 13:15:15 +0100 Subject: [PATCH] Manually cleanup code in touched files --- .../UI/ConnectedModeServicesTests.cs | 8 +-- src/ConnectedMode/UI/ConnectedModeServices.cs | 11 ++-- .../ServerSelectionDialog.xaml.cs | 59 +++++++++---------- src/Core/Telemetry/ITelemetryManager.cs | 27 +++++---- src/Core/Telemetry/TelemetryLinks.cs | 2 +- src/Integration/Telemetry/TelemetryManager.cs | 51 ++++------------ 6 files changed, 65 insertions(+), 93 deletions(-) diff --git a/src/ConnectedMode.UnitTests/UI/ConnectedModeServicesTests.cs b/src/ConnectedMode.UnitTests/UI/ConnectedModeServicesTests.cs index 49cf52fd9..60ae49943 100644 --- a/src/ConnectedMode.UnitTests/UI/ConnectedModeServicesTests.cs +++ b/src/ConnectedMode.UnitTests/UI/ConnectedModeServicesTests.cs @@ -18,11 +18,11 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using SonarLint.VisualStudio.Core; -using SonarLint.VisualStudio.TestInfrastructure; using SonarLint.VisualStudio.ConnectedMode.UI; +using SonarLint.VisualStudio.Core; using SonarLint.VisualStudio.Core.Binding; using SonarLint.VisualStudio.Core.Telemetry; +using SonarLint.VisualStudio.TestInfrastructure; namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.UI; @@ -30,8 +30,7 @@ namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.UI; public class ConnectedModeServicesTests { [TestMethod] - public void MefCtor_CheckIsExported() - { + public void MefCtor_CheckIsExported() => MefTestHelpers.CheckTypeCanBeImported( MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport(), @@ -41,5 +40,4 @@ public void MefCtor_CheckIsExported() MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport(), MefTestHelpers.CreateExport()); - } } diff --git a/src/ConnectedMode/UI/ConnectedModeServices.cs b/src/ConnectedMode/UI/ConnectedModeServices.cs index 5d541e1a3..0e9110376 100644 --- a/src/ConnectedMode/UI/ConnectedModeServices.cs +++ b/src/ConnectedMode/UI/ConnectedModeServices.cs @@ -19,7 +19,6 @@ */ using System.ComponentModel.Composition; -using SonarLint.VisualStudio.ConnectedMode.Shared; using SonarLint.VisualStudio.Core; using SonarLint.VisualStudio.Core.Binding; using SonarLint.VisualStudio.Core.Telemetry; @@ -28,11 +27,11 @@ namespace SonarLint.VisualStudio.ConnectedMode.UI; public interface IConnectedModeServices { - public IBrowserService BrowserService { get; } - public IThreadHandling ThreadHandling { get; } - public ILogger Logger { get; } - public ISlCoreConnectionAdapter SlCoreConnectionAdapter { get; } - public IConfigurationProvider ConfigurationProvider { get; } + public IBrowserService BrowserService { get; } + public IThreadHandling ThreadHandling { get; } + public ILogger Logger { get; } + public ISlCoreConnectionAdapter SlCoreConnectionAdapter { get; } + public IConfigurationProvider ConfigurationProvider { get; } public IServerConnectionsRepositoryAdapter ServerConnectionsRepositoryAdapter { get; } public IMessageBox MessageBox { get; } public ITelemetryManager TelemetryManager { get; } diff --git a/src/ConnectedMode/UI/ServerSelection/ServerSelectionDialog.xaml.cs b/src/ConnectedMode/UI/ServerSelection/ServerSelectionDialog.xaml.cs index 861351ad2..1f29d5306 100644 --- a/src/ConnectedMode/UI/ServerSelection/ServerSelectionDialog.xaml.cs +++ b/src/ConnectedMode/UI/ServerSelection/ServerSelectionDialog.xaml.cs @@ -23,40 +23,35 @@ using System.Windows.Navigation; using SonarLint.VisualStudio.Core; using SonarLint.VisualStudio.Core.Telemetry; -using SonarLint.VisualStudio.Integration.Telemetry; -namespace SonarLint.VisualStudio.ConnectedMode.UI.ServerSelection +namespace SonarLint.VisualStudio.ConnectedMode.UI.ServerSelection; + +[ExcludeFromCodeCoverage] // UI, not really unit-testable +public partial class ServerSelectionDialog : Window { - [ExcludeFromCodeCoverage] // UI, not really unit-testable - public partial class ServerSelectionDialog : Window + private readonly IBrowserService browserService; + private readonly ITelemetryManager telemetryManager; + + public ServerSelectionViewModel ViewModel { get; } = new(); + + public ServerSelectionDialog(IBrowserService browserService, ITelemetryManager telemetryManager) + { + this.browserService = browserService; + this.telemetryManager = telemetryManager; + InitializeComponent(); + } + + private void ViewWebsite(object sender, RequestNavigateEventArgs e) => browserService.Navigate(e.Uri.AbsoluteUri); + + private void FreeSonaQubeCloudFreeTier_OnRequestNavigate(object sender, RequestNavigateEventArgs e) + { + ViewWebsite(sender, e); + telemetryManager.LinkClicked(TelemetryLinks.SonarQubeCloudFreeSignUp); + } + + private void OkButton_OnClick(object sender, RoutedEventArgs e) { - private readonly IBrowserService browserService; - private readonly ITelemetryManager telemetryManager; - - public ServerSelectionDialog(IBrowserService browserService, ITelemetryManager telemetryManager) - { - this.browserService = browserService; - this.telemetryManager = telemetryManager; - InitializeComponent(); - } - - public ServerSelectionViewModel ViewModel { get; } = new(); - - private void ViewWebsite(object sender, RequestNavigateEventArgs e) - { - browserService.Navigate(e.Uri.AbsoluteUri); - } - - private void FreeSonaQubeCloudFreeTier_OnRequestNavigate(object sender, RequestNavigateEventArgs e) - { - ViewWebsite(sender, e); - telemetryManager.LinkClicked(TelemetryLinks.SonarQubeCloudFreeSignUp); - } - - private void OkButton_OnClick(object sender, RoutedEventArgs e) - { - DialogResult = true; - Close(); - } + DialogResult = true; + Close(); } } diff --git a/src/Core/Telemetry/ITelemetryManager.cs b/src/Core/Telemetry/ITelemetryManager.cs index b3f4089cb..2aae9e8cd 100644 --- a/src/Core/Telemetry/ITelemetryManager.cs +++ b/src/Core/Telemetry/ITelemetryManager.cs @@ -18,16 +18,21 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -namespace SonarLint.VisualStudio.Core.Telemetry +namespace SonarLint.VisualStudio.Core.Telemetry; + +public interface ITelemetryManager { - public interface ITelemetryManager - { - SlCoreTelemetryStatus GetStatus(); - void OptOut(); - void OptIn(); - void LanguageAnalyzed(string languageKey, TimeSpan analysisTime); - void TaintIssueInvestigatedLocally(); - void TaintIssueInvestigatedRemotely(); - void LinkClicked(string linkId); - } + SlCoreTelemetryStatus GetStatus(); + + void OptOut(); + + void OptIn(); + + void LanguageAnalyzed(string languageKey, TimeSpan analysisTime); + + void TaintIssueInvestigatedLocally(); + + void TaintIssueInvestigatedRemotely(); + + void LinkClicked(string linkId); } diff --git a/src/Core/Telemetry/TelemetryLinks.cs b/src/Core/Telemetry/TelemetryLinks.cs index 57e5e1001..a9df55baf 100644 --- a/src/Core/Telemetry/TelemetryLinks.cs +++ b/src/Core/Telemetry/TelemetryLinks.cs @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -namespace SonarLint.VisualStudio.Integration.Telemetry; +namespace SonarLint.VisualStudio.Core.Telemetry; public static class TelemetryLinks { diff --git a/src/Integration/Telemetry/TelemetryManager.cs b/src/Integration/Telemetry/TelemetryManager.cs index abd078550..3f8c66962 100644 --- a/src/Integration/Telemetry/TelemetryManager.cs +++ b/src/Integration/Telemetry/TelemetryManager.cs @@ -34,8 +34,8 @@ internal sealed class TelemetryManager : ITelemetryManager, IQuickFixesTelemetryManager, IDisposable { - private readonly ISlCoreTelemetryHelper telemetryHelper; private readonly IKnownUIContexts knownUiContexts; + private readonly ISlCoreTelemetryHelper telemetryHelper; [ImportingConstructor] public TelemetryManager(ISlCoreTelemetryHelper telemetryHelper, IKnownUIContexts knownUIContexts) @@ -46,26 +46,19 @@ public TelemetryManager(ISlCoreTelemetryHelper telemetryHelper, IKnownUIContexts knownUiContexts.VBProjectContextChanged += OnVBProjectContextChanged; } - public void QuickFixApplied(string ruleId) + public void Dispose() { - telemetryHelper.Notify(telemetryService => telemetryService.AddQuickFixAppliedForRule(new AddQuickFixAppliedForRuleParams(ruleId))); + knownUiContexts.CSharpProjectContextChanged -= OnCSharpProjectContextChanged; + knownUiContexts.VBProjectContextChanged -= OnVBProjectContextChanged; } - public SlCoreTelemetryStatus GetStatus() - { - return telemetryHelper.GetStatus(); - } + public void QuickFixApplied(string ruleId) => telemetryHelper.Notify(telemetryService => telemetryService.AddQuickFixAppliedForRule(new AddQuickFixAppliedForRuleParams(ruleId))); - public void OptIn() - { - telemetryHelper.Notify(telemetryService => telemetryService.EnableTelemetry()); - } + public SlCoreTelemetryStatus GetStatus() => telemetryHelper.GetStatus(); + public void OptIn() => telemetryHelper.Notify(telemetryService => telemetryService.EnableTelemetry()); - public void OptOut() - { - telemetryHelper.Notify(telemetryService => telemetryService.DisableTelemetry()); - } + public void OptOut() => telemetryHelper.Notify(telemetryService => telemetryService.DisableTelemetry()); public void LanguageAnalyzed(string languageKey, TimeSpan analysisTime) { @@ -74,27 +67,11 @@ public void LanguageAnalyzed(string languageKey, TimeSpan analysisTime) telemetryService.AnalysisDoneOnSingleLanguage(new AnalysisDoneOnSingleLanguageParams(language, (int)Math.Round(analysisTime.TotalMilliseconds)))); } - public void TaintIssueInvestigatedLocally() - { - telemetryHelper.Notify(telemetryService => telemetryService.TaintVulnerabilitiesInvestigatedLocally()); - } - - public void TaintIssueInvestigatedRemotely() - { - telemetryHelper.Notify(telemetryService => telemetryService.TaintVulnerabilitiesInvestigatedRemotely()); - } + public void TaintIssueInvestigatedLocally() => telemetryHelper.Notify(telemetryService => telemetryService.TaintVulnerabilitiesInvestigatedLocally()); + public void TaintIssueInvestigatedRemotely() => telemetryHelper.Notify(telemetryService => telemetryService.TaintVulnerabilitiesInvestigatedRemotely()); - public void LinkClicked(string linkId) - { - telemetryHelper.Notify(telemetryService => telemetryService.HelpAndFeedbackLinkClicked(new HelpAndFeedbackClickedParams(linkId))); - } - - public void Dispose() - { - knownUiContexts.CSharpProjectContextChanged -= OnCSharpProjectContextChanged; - knownUiContexts.VBProjectContextChanged -= OnVBProjectContextChanged; - } + public void LinkClicked(string linkId) => telemetryHelper.Notify(telemetryService => telemetryService.HelpAndFeedbackLinkClicked(new HelpAndFeedbackClickedParams(linkId))); private void OnCSharpProjectContextChanged(object sender, UIContextChangedEventArgs e) { @@ -112,9 +89,8 @@ private void OnVBProjectContextChanged(object sender, UIContextChangedEventArgs } } - private static Language Convert(string languageKey) - { - return languageKey switch + private static Language Convert(string languageKey) => + languageKey switch { SonarLanguageKeys.CPlusPlus => Language.CPP, SonarLanguageKeys.C => Language.C, @@ -126,5 +102,4 @@ private static Language Convert(string languageKey) SonarLanguageKeys.Secrets => Language.SECRETS, _ => throw new ArgumentOutOfRangeException(nameof(languageKey), languageKey, null) }; - } }