Skip to content

Commit

Permalink
[PowerToys Run] Plugins StyleCop and warnings fix (#12623)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegiacometti committed Aug 11, 2021
1 parent 7ea1f26 commit 1791246
Show file tree
Hide file tree
Showing 25 changed files with 250 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void ColorRGBtoHSITest(string hexValue, double hue, double saturation, do
}

Assert.IsTrue(hexValue.Length >= 6);

var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Expand Down Expand Up @@ -287,7 +287,7 @@ public void ColorRGBtoNColTest(string hexValue, string hue, double whiteness, do

Assert.IsTrue(hexValue.Length >= 6);

var red = int.Parse( hexValue.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);

Expand Down Expand Up @@ -322,6 +322,7 @@ public void ColorRGBtoCMYKZeroDivTest()
_ = ColorHelper.ConvertToCMYKColor(color);
}
#pragma warning disable CA1031 // Do not catch general exception types

// intentionally trying to catch
catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,23 @@
</PackageReference>
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\settings-ui\Microsoft.PowerToys.Settings.UI.Library\Microsoft.PowerToys.Settings.UI.Library.csproj" />
<ProjectReference Include="..\ColorPickerUI\ColorPickerUI.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
<AdditionalFiles Include="..\..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Globalization;
using NUnit.Framework;
using Wox.Plugin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Globalization;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Linq;
using NUnit.Framework;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -39,6 +39,7 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows;
using System.Windows.Input;
using ManagedCommon;
using UnitsNet;
using Wox.Plugin;

namespace Community.PowerToys.Run.Plugin.UnitConverter
Expand Down Expand Up @@ -142,7 +144,7 @@ public string GetTranslatedPluginDescription()
return Properties.Resources.plugin_description;
}

private void OnThemeChanged(Theme _, Theme newTheme)
private void OnThemeChanged(Theme currentTheme, Theme newTheme)
{
UpdateIconPath(newTheme);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using UnitsNet;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using UnitsNet;

namespace Community.PowerToys.Run.Plugin.UnitConverter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -37,6 +38,7 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand All @@ -50,10 +52,22 @@
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
<AdditionalFiles Include="..\..\..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Runtime" Version="4.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
Expand All @@ -13,7 +17,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
{
public class Main : IPlugin, IPluginI18n
{
public PluginInitContext _context { get; private set; }
private PluginInitContext _context;

public string Name => GetTranslatedPluginTitle();

Expand All @@ -24,9 +28,9 @@ public Main()
VSCodeInstances.LoadVSCodeInstances();
}

public readonly VSCodeWorkspacesApi _workspacesApi = new VSCodeWorkspacesApi();
private readonly VSCodeWorkspacesApi _workspacesApi = new VSCodeWorkspacesApi();

public readonly VSCodeRemoteMachinesApi _machinesApi = new VSCodeRemoteMachinesApi();
private readonly VSCodeRemoteMachinesApi _machinesApi = new VSCodeRemoteMachinesApi();

public List<Result> Query(Query query)
{
Expand All @@ -49,12 +53,12 @@ public List<Result> Query(Query query)
title += $" - {(a.ExtraInfo != null ? $"{a.ExtraInfo} ({typeWorkspace})" : typeWorkspace)}";
}
var tooltip = new ToolTipData(title, $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : "")}: {SystemPath.RealPath(a.RelativePath)}");
var tooltip = new ToolTipData(title, $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(a.RelativePath)}");
results.Add(new Result
{
Title = title,
SubTitle = $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : "")}: {SystemPath.RealPath(a.RelativePath)}",
SubTitle = $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(a.RelativePath)}",
Icon = a.VSCodeInstance.WorkspaceIcon,
ToolTipData = tooltip,
Action = c =>
Expand All @@ -67,7 +71,7 @@ public List<Result> Query(Query query)
FileName = a.VSCodeInstance.ExecutablePath,
UseShellExecute = true,
Arguments = $"--folder-uri {a.Path}",
WindowStyle = ProcessWindowStyle.Hidden
WindowStyle = ProcessWindowStyle.Hidden,
};
Process.Start(process);
Expand All @@ -80,13 +84,13 @@ public List<Result> Query(Query query)
_context.API.ShowMsg(name, msg, string.Empty);
hide = false;
}
return hide;
},
ContextData = a,
});
});


// Search opened remote machines
_machinesApi.Machines.ForEach(a =>
{
Expand Down Expand Up @@ -128,6 +132,7 @@ public List<Result> Query(Query query)
_context.API.ShowMsg(name, msg, string.Empty);
hide = false;
}
return hide;
},
ContextData = a,
Expand All @@ -147,20 +152,20 @@ public List<Result> Query(Query query)
x.Score = 100;
}
//intersect the title with the query
// intersect the title with the query
var intersection = Convert.ToInt32(x.Title.ToLowerInvariant().Intersect(query.Search.ToLowerInvariant()).Count() * query.Search.Count());
var differenceWithQuery = Convert.ToInt32((x.Title.Count() - intersection) * query.Search.Count() * 0.7);
x.Score = x.Score - differenceWithQuery + intersection;
//if is a remote machine give it 12 extra points
// if is a remote machine give it 12 extra points
if (x.ContextData is VSCodeRemoteMachine)
{
x.Score = Convert.ToInt32(x.Score + intersection * 2);
x.Score = Convert.ToInt32(x.Score + (intersection * 2));
}
});

results = results.OrderByDescending(x => x.Score).ToList();
if (query.Search == string.Empty || query.Search.Replace(" ", "") == string.Empty)
if (query.Search == string.Empty || query.Search.Replace(" ", string.Empty) == string.Empty)
{
results = results.OrderBy(x => x.Title).ToList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;

namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser;
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
using Newtonsoft.Json;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.IO;
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser;
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
using Newtonsoft.Json;
using Wox.Plugin.Logger;

namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
{
public class VSCodeRemoteMachinesApi
{
public VSCodeRemoteMachinesApi() { }
public VSCodeRemoteMachinesApi()
{
}

public List<VSCodeRemoteMachine> Machines
{
get
{
var results = new List<VSCodeRemoteMachine>();

foreach (var vscodeInstance in VSCodeInstances.instances)
foreach (var vscodeInstance in VSCodeInstances.Instances)
{
// settings.json contains path of ssh_config
var vscode_settings = Path.Combine(vscodeInstance.AppData, "User\\settings.json");
Expand All @@ -40,8 +46,8 @@ public List<VSCodeRemoteMachine> Machines
var machine = new VSCodeRemoteMachine();
machine.Host = h.Host;
machine.VSCodeInstance = vscodeInstance;
machine.HostName = h.HostName != null ? h.HostName : String.Empty;
machine.User = h.User != null ? h.User : String.Empty;
machine.HostName = h.HostName != null ? h.HostName : string.Empty;
machine.User = h.User != null ? h.User : string.Empty;

results.Add(machine);
}
Expand All @@ -57,8 +63,7 @@ public List<VSCodeRemoteMachine> Machines
}

return results;

}
}
}
}
}

0 comments on commit 1791246

Please sign in to comment.