Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StyleCop upgrade and many warning was resolved or disabled #261

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Next Next commit
Some warning was removed.
  • Loading branch information
soroshsabz committed Jul 10, 2022
commit ffb62ff8f1468abd3b02c2584299eb4b5f3a8b58
3 changes: 3 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.cs]
indent_style = space
indent_size = 4
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Nerdbank.GitVersioning" Version="1.6.30" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Nerdbank.GitVersioning" Version="1.6.30" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EnvDTE" Version="17.0.31902.203" />
<PackageReference Include="EnvDTE" Version="17.2.32505.113" />

<PackageReference Include="Microsoft.VisualStudio.Internal.MicroBuild.VisualStudio" Version="2.0.66" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.0.5232" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.2.2186">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.0.31902.203" />
<PackageReference Include="Microsoft.Web.Xdt" Version="3.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Jdt" Version="0.9.23" />
<PackageReference Include="NuGet.VisualStudio" Version="5.11.0" />
<PackageReference Include="NuGet.VisualStudio" Version="17.2.1" />
<PackageReference Include="Nerdbank.GitVersioning" Version="1.6.30" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="NuGet.VisualStudio.Contracts" Version="17.2.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public BackgroundInstallationHandler(IPackageHandler successor)
/// <inheritdoc/>
public override async TPL.Task Execute(Project project)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
string projName = project.UniqueName;
bool needInstall = true;
lock (SyncObject)
Expand All @@ -48,7 +49,7 @@ public override async TPL.Task Execute(Project project)
{
string warningTitle = this.IsUpdate ? Resources.Resources.NugetUpdate_Title : Resources.Resources.NugetInstall_Title;
string warningMessage = this.IsUpdate ? Resources.Resources.NugetUpdate_Text : Resources.Resources.NugetInstall_Text;
if (await this.HasUserAcceptedWarningMessage(warningTitle, warningMessage))
if (await this.HasUserAcceptedWarningMessageAsync(warningTitle, warningMessage))
{
// Gets the general output pane to inform user of installation
IVsOutputWindowPane outputWindow = (IVsOutputWindowPane)await this.Package.GetServiceAsync(typeof(SVsGeneralOutputWindowPane));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public DialogInstallationHandler(IPackageHandler successor)
/// <inheritdoc/>
public override async TPL.Task Execute(Project project)
{
if (await this.HasUserAcceptedWarningMessage(Resources.Resources.NugetUpdate_Title, Resources.Resources.NugetUpdate_Text))
if (await this.HasUserAcceptedWarningMessageAsync(Resources.Resources.NugetUpdate_Title, Resources.Resources.NugetUpdate_Text))
{
// Creates dialog informing the user to wait for the installation to finish
IVsThreadedWaitDialogFactory twdFactory = await this.Package.GetServiceAsync(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.SlowCheetah.VS
{
using EnvDTE;
using Microsoft;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
using NuGet.VisualStudio;
Expand All @@ -27,6 +28,7 @@ public NuGetUninstaller(IPackageHandler successor)
public override async TPL.Task Execute(Project project)
{
var componentModel = (IComponentModel)await this.Package.GetServiceAsync(typeof(SComponentModel));
Assumes.Present(componentModel);
IVsPackageUninstaller packageUninstaller = componentModel.GetService<IVsPackageUninstaller>();
packageUninstaller.UninstallPackage(project, SlowCheetahNuGetManager.OldPackageName, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.VisualStudio.SlowCheetah.VS
using System.Linq;
using EnvDTE;
using Microsoft.Build.Construction;
using Microsoft.VisualStudio.Shell;
using TPL = System.Threading.Tasks;

/// <summary>
Expand All @@ -27,6 +28,7 @@ public override async TPL.Task Execute(Project project)
{
// We handle any NuGet package logic before editing the project file
await this.Successor.Execute(project);
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

project.Save();
ProjectRootElement projectRoot = ProjectRootElement.Open(project.FullName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public UserInstallationHandler(IPackageHandler successor)
/// <param name="title">The title of the message box</param>
/// <param name="message">The message to be shown</param>
/// <returns>True if the user has accepted the warning message</returns>
protected async Task<bool> HasUserAcceptedWarningMessage(string title, string message)
protected async Task<bool> HasUserAcceptedWarningMessageAsync(string title, string message)
{
var shell = (IVsUIShell)await this.Package.GetServiceAsync(typeof(SVsUIShell));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ namespace Microsoft.VisualStudio.SlowCheetah.VS
using System;
using System.Collections.Generic;
using EnvDTE;
using Microsoft;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using NuGet.VisualStudio;
using NuGet.VisualStudio.Contracts;
using TPL = System.Threading.Tasks;

/// <summary>
Expand Down Expand Up @@ -71,9 +73,10 @@ public SlowCheetahNuGetManager(AsyncPackage package)
/// <returns>True if the project supports NuGet</returns>
/// <remarks>This implementation is derived of the internal NuGet method IsSupported
/// https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Utility/EnvDTEProjectUtility.cs#L441
/// This should be removed when NuGet adds this to their public API</remarks>
/// This should be removed when NuGet adds this to their public API.</remarks>
public bool ProjectSupportsNuget(IVsHierarchy hierarchy)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (hierarchy == null)
{
throw new ArgumentNullException(nameof(hierarchy));
Expand Down Expand Up @@ -113,8 +116,9 @@ public bool ProjectSupportsNuget(IVsHierarchy hierarchy)
/// </summary>
/// <param name="hierarchy">Hierarchy of the project to be verified</param>
/// <returns>A <see cref="TPL.Task"/> representing the asynchronous operation.</returns>
public async TPL.Task CheckSlowCheetahInstallation(IVsHierarchy hierarchy)
public async TPL.Task CheckSlowCheetahInstallationAsync(IVsHierarchy hierarchy)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (hierarchy == null)
{
throw new ArgumentNullException(nameof(hierarchy));
Expand Down Expand Up @@ -160,7 +164,7 @@ public async TPL.Task CheckSlowCheetahInstallation(IVsHierarchy hierarchy)
plan = new BackgroundInstallationHandler(plan)
{
// If the old package is installed, this is an update operation
IsUpdate = isOldScPackageInstalled
IsUpdate = isOldScPackageInstalled,
};
}

Expand All @@ -170,12 +174,14 @@ public async TPL.Task CheckSlowCheetahInstallation(IVsHierarchy hierarchy)
private static IVsPackageInstallerServices GetInstallerServices(IServiceProvider package)
{
var componentModel = (IComponentModel)package.GetService(typeof(SComponentModel));
Assumes.Present(componentModel);
IVsPackageInstallerServices installerServices = componentModel.GetService<IVsPackageInstallerServices>();
return installerServices;
}

private static bool IsOldSlowCheetahInstalled(IVsBuildPropertyStorage buildPropertyStorage)
{
ThreadHelper.ThrowIfNotOnUIThread();
buildPropertyStorage.GetPropertyValue("SlowCheetahImport", null, (uint)_PersistStorageType.PST_PROJECT_FILE, out string propertyValue);
if (!string.IsNullOrEmpty(propertyValue))
{
Expand All @@ -193,6 +199,7 @@ private static bool IsOldSlowCheetahInstalled(IVsBuildPropertyStorage buildPrope

private static bool SupportsINugetProjectSystem(IVsHierarchy hierarchy)
{
ThreadHelper.ThrowIfNotOnUIThread();
var vsProject = hierarchy as IVsProject;
if (vsProject == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected override IWin32Window Window
/// <inheritdoc/>
public override void SaveSettingsToXml(IVsSettingsWriter writer)
{
Shell.ThreadHelper.ThrowIfNotOnUIThread();
try
{
base.SaveSettingsToXml(writer);
Expand All @@ -68,6 +69,7 @@ public override void SaveSettingsToXml(IVsSettingsWriter writer)
/// <inheritdoc/>
public override void LoadSettingsFromXml(IVsSettingsReader reader)
{
Shell.ThreadHelper.ThrowIfNotOnUIThread();
try
{
this.InitializeDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected override IWin32Window Window
/// <inheritdoc/>
public override void SaveSettingsToXml(IVsSettingsWriter writer)
{
Shell.ThreadHelper.ThrowIfNotOnUIThread();
try
{
base.SaveSettingsToXml(writer);
Expand All @@ -70,6 +71,7 @@ public override void SaveSettingsToXml(IVsSettingsWriter writer)
/// <inheritdoc/>
public override void LoadSettingsFromXml(IVsSettingsReader reader)
{
Shell.ThreadHelper.ThrowIfNotOnUIThread();
try
{
this.InitializeDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected override void OnChange(object sender, EventArgs e)
/// <inheritdoc/>
protected override void OnBeforeQueryStatus(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
// get the menu that fired the event
if (sender is OleMenuCommand menuCommand)
{
Expand Down Expand Up @@ -83,6 +84,7 @@ protected override void OnBeforeQueryStatus(object sender, EventArgs e)
/// <inheritdoc/>
protected override void OnInvoke(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
uint itemid = VSConstants.VSITEMID_NIL;

if (!ProjectUtilities.IsSingleProjectItemSelection(out IVsHierarchy hierarchy, out itemid))
Expand Down Expand Up @@ -133,7 +135,7 @@ protected override void OnInvoke(object sender, EventArgs e)
}

// Checks the SlowCheetah NuGet package installation
this.package.JoinableTaskFactory.Run(() => this.nuGetManager.CheckSlowCheetahInstallation(hierarchy));
this.package.JoinableTaskFactory.Run(() => this.nuGetManager.CheckSlowCheetahInstallationAsync(hierarchy));

// need to enure that this item has metadata TransformOnBuild set to true
buildPropertyStorage.SetItemAttribute(itemid, SlowCheetahPackage.TransformOnBuild, "true");
Expand Down Expand Up @@ -191,6 +193,7 @@ protected override void OnInvoke(object sender, EventArgs e)
string projectPath,
bool addDependentUpon)
{
ThreadHelper.ThrowIfNotOnUIThread();
try
{
string transformPath = Path.Combine(projectPath, itemName);
Expand Down Expand Up @@ -245,6 +248,7 @@ protected override void OnInvoke(object sender, EventArgs e)
/// <returns>True if the item supports transforms</returns>
private bool ItemSupportsTransforms(IVsProject project, uint itemid)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (ErrorHandler.Failed(project.GetMkDocument(itemid, out string itemFullPath)))
{
return false;
Expand Down Expand Up @@ -279,6 +283,7 @@ private bool ItemSupportsTransforms(IVsProject project, uint itemid)
/// <returns>List of publish profile names</returns>
private IEnumerable<string> GetPublishProfileTransforms(IVsHierarchy hierarchy, string projectPath)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (hierarchy == null)
{
throw new ArgumentNullException(nameof(hierarchy));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ protected override void OnChange(object sender, EventArgs e)
/// <inheritdoc/>
protected override void OnBeforeQueryStatus(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();

// Get the menu that fired the event
if (sender is OleMenuCommand menuCommand)
{
Expand Down Expand Up @@ -117,6 +119,7 @@ protected override void OnBeforeQueryStatus(object sender, EventArgs e)
/// <inheritdoc/>
protected override void OnInvoke(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
uint itemId = VSConstants.VSITEMID_NIL;

// Verify only one item is selected
Expand All @@ -139,7 +142,7 @@ protected override void OnInvoke(object sender, EventArgs e)
}

// Checks the SlowCheetah NuGet package installation
this.ScPackage.JoinableTaskFactory.Run(() => this.NuGetManager.CheckSlowCheetahInstallation(hierarchy));
this.ScPackage.JoinableTaskFactory.Run(() => this.NuGetManager.CheckSlowCheetahInstallationAsync(hierarchy));

// Get the parent of the file to start searching for the source file
ErrorHandler.ThrowOnFailure(hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_Parent, out object parentIdObj));
Expand Down Expand Up @@ -177,6 +180,7 @@ protected override void OnInvoke(object sender, EventArgs e)
/// <param name="transformFile">Full path to the transformation file</param>
private void PreviewTransform(IVsHierarchy hier, string sourceFile, string transformFile)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (string.IsNullOrWhiteSpace(sourceFile))
{
throw new ArgumentNullException(nameof(sourceFile));
Expand Down Expand Up @@ -261,7 +265,7 @@ private void PreviewTransform(IVsHierarchy hier, string sourceFile, string trans
ProcessStartInfo psi = new ProcessStartInfo(advancedOptionsPage.PreviewToolExecutablePath, string.Format(CultureInfo.CurrentCulture, advancedOptionsPage.PreviewToolCommandLine, $"\"{sourceFile}\"", $"\"{destFile}\""))
{
CreateNoWindow = true,
UseShellExecute = false
UseShellExecute = false,
};
System.Diagnostics.Process.Start(psi);
}
Expand All @@ -281,6 +285,7 @@ private void PreviewTransform(IVsHierarchy hier, string sourceFile, string trans
/// <returns>True if the correct file was found</returns>
private bool TryGetFileToTransform(IVsHierarchy hierarchy, uint parentId, string transformName, out uint docId, out string documentPath)
{
ThreadHelper.ThrowIfNotOnUIThread();
IVsProject project = (IVsProject)hierarchy;

// Get the project configurations to use in comparing the name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public SlowCheetahPackageLogger(IServiceProvider package)
/// <param name="args">The message arguments</param>
public void LogMessage(string message, params object[] args)
{
Shell.ThreadHelper.ThrowIfNotOnUIThread();
if (string.IsNullOrWhiteSpace(message))
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public SlowCheetahPackage()
/// <returns>True if the project supports transformation</returns>
public bool ProjectSupportsTransforms(IVsProject project)
{
ThreadHelper.ThrowIfNotOnUIThread();
return this.NuGetManager.ProjectSupportsNuget(project as IVsHierarchy);
}

Expand All @@ -112,6 +113,7 @@ public bool ProjectSupportsTransforms(IVsProject project)
/// <returns>True if the item has a transform</returns>
public bool IsItemTransformItem(IVsProject vsProject, uint itemid)
{
ThreadHelper.ThrowIfNotOnUIThread();
IVsBuildPropertyStorage buildPropertyStorage = vsProject as IVsBuildPropertyStorage;
if (buildPropertyStorage == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public static bool IsPathValid(string path)
public static T GetAutomationFromHierarchy<T>(IVsHierarchy pHierarchy, uint itemID)
where T : class
{
Shell.ThreadHelper.ThrowIfNotOnUIThread();
ErrorHandler.ThrowOnFailure(pHierarchy.GetProperty(itemID, (int)__VSHPROPID.VSHPROPID_ExtObject, out object propertyValue));
T projectItem = propertyValue as T;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static DTE GetDTE()
/// <returns>True if a single item is selected</returns>
public static bool IsSingleProjectItemSelection(out IVsHierarchy hierarchy, out uint itemid)
{
ThreadHelper.ThrowIfNotOnUIThread();
hierarchy = null;
itemid = VSConstants.VSITEMID_NIL;
int hr = VSConstants.S_OK;
Expand Down Expand Up @@ -210,6 +211,7 @@ public static bool IsProjectWebApp(IVsProject project)

private static IEnumerable<string> GetSupportedExtensions(IVsSettingsManager settingsManager, string rootKey)
{
ThreadHelper.ThrowIfNotOnUIThread();
ErrorHandler.ThrowOnFailure(settingsManager.GetReadOnlySettingsStore((uint)__VsSettingsScope.SettingsScope_Configuration, out IVsSettingsStore settings));
ErrorHandler.ThrowOnFailure(settings.GetSubCollectionCount(rootKey, out uint count));

Expand Down
Loading