Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #567 from Microsoft/dev
Browse files Browse the repository at this point in the history
Fixing FxCop issues
  • Loading branch information
conniey committed Jan 31, 2018
2 parents 7c80ef6 + d0a5683 commit 3995a05
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 41 deletions.
7 changes: 3 additions & 4 deletions src/ApiPort.VisualStudio.2015/ProjectBuilder2015.cs
Expand Up @@ -5,17 +5,16 @@
using ApiPortVS.Contracts;
using EnvDTE;
using Microsoft.VisualStudio.ProjectSystem;
using Microsoft.VisualStudio.ProjectSystem.Build;
using Microsoft.VisualStudio.ProjectSystem.Designers;
using Microsoft.VisualStudio.ProjectSystem.Utilities;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using static Microsoft.Fx.Portability.Utils.FormattableStringHelper;

namespace ApiPortVS.VS2015
{
Expand Down Expand Up @@ -57,7 +56,7 @@ public override async Task<IEnumerable<string>> GetBuildOutputFilesAsync(Project
/// project is not a CPS project.</returns>
private async Task<IEnumerable<string>> GetBuildOutputFilesFromCPSAsync(
Project project,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (project == null)
{
Expand All @@ -68,7 +67,7 @@ public override async Task<IEnumerable<string>> GetBuildOutputFilesAsync(Project

if (hierarchy == null)
{
Trace.TraceWarning($"Unable to locate {nameof(IVsHierarchy)} for {project.Name}");
Trace.TraceWarning(ToCurrentCulture($"Unable to locate {nameof(IVsHierarchy)} for {project.Name}"));
return null;
}

Expand Down
@@ -1,28 +1,27 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using ApiPortVS.Common;
using ApiPortVS.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
using Microsoft.VisualStudio.Shell.Interop;
using System.Threading;
using ApiPortVS.Common;
using System.Diagnostics;
using Microsoft.VisualStudio.ProjectSystem;
using Microsoft.VisualStudio.ProjectSystem.Build;
using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Collections.Concurrent;
using Microsoft.VisualStudio.ProjectSystem.Build;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using static Microsoft.Fx.Portability.Utils.FormattableStringHelper;

namespace ApiPortVS.VS2017
{
public class ProjectBuilder2015 : DefaultProjectBuilder
public class ProjectBuilder2017 : DefaultProjectBuilder
{
public ProjectBuilder2015(
public ProjectBuilder2017(
IVsSolutionBuildManager2 buildManager,
IVSThreadingService threadingService,
IProjectMapper projectMapper)
Expand All @@ -36,7 +35,7 @@ public class ProjectBuilder2015 : DefaultProjectBuilder
/// https://github.com/Microsoft/visualfsharp/blob/master/vsintegration/tests/unittests/Tests.ProjectSystem.Miscellaneous.fs#L168-L182
/// </summary>
/// <returns>null if it is unable to retrieve VS configuration objects</returns>
public override async Task<IEnumerable<string>> GetBuildOutputFilesAsync(Project project, CancellationToken cancellationToken = default(CancellationToken))
public override async Task<IEnumerable<string>> GetBuildOutputFilesAsync(Project project, CancellationToken cancellationToken = default)
{
if (project == null)
{
Expand All @@ -61,7 +60,7 @@ public override async Task<IEnumerable<string>> GetBuildOutputFilesAsync(Project
/// project is not a CPS project.</returns>
private async Task<IEnumerable<string>> GetBuildOutputFilesFromCPSAsync(
Project project,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (project == null)
{
Expand All @@ -72,7 +71,7 @@ public override async Task<IEnumerable<string>> GetBuildOutputFilesAsync(Project

if (hierarchy == null)
{
Trace.TraceWarning($"Unable to locate {nameof(IVsHierarchy)} for {project.Name}");
Trace.TraceWarning(ToCurrentCulture($"Unable to locate {nameof(IVsHierarchy)} for {project.Name}"));
return null;
}

Expand Down Expand Up @@ -110,7 +109,7 @@ public override async Task<IEnumerable<string>> GetBuildOutputFilesAsync(Project
}
catch (Exception e)
{
Trace.TraceError($"Could not fetch key output from project configuration {proj.ProjectConfiguration.Name}. Exception: {e}", e);
Trace.TraceError(ToCurrentCulture($"Could not fetch key output from project configuration {proj.ProjectConfiguration.Name}. Exception: {e}"), e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ApiPort.VisualStudio.2017/ServiceProvider.cs
Expand Up @@ -24,7 +24,7 @@ protected override void Load(ContainerBuilder builder)
builder.RegisterType<VSThreadingService>()
.As<IVSThreadingService>()
.SingleInstance();
builder.RegisterType<ProjectBuilder2015>()
builder.RegisterType<ProjectBuilder2017>()
.As<IProjectBuilder>()
.SingleInstance();
}
Expand Down
9 changes: 5 additions & 4 deletions src/ApiPort.VisualStudio.Common/ComProjectMapper.cs
Expand Up @@ -9,6 +9,7 @@
using System.Diagnostics;
using System.Threading.Tasks;
using VisualStudio = Microsoft.VisualStudio.Shell;
using static Microsoft.Fx.Portability.Utils.FormattableStringHelper;

namespace ApiPortVS
{
Expand Down Expand Up @@ -67,18 +68,18 @@ public async Task<IVsCfg> GetVsProjectConfigurationAsync(Project project)

if (getConfigurationProvider == null)
{
Trace.TraceError($"Could not retrieve {nameof(IVsGetCfgProvider)} from project: {project.Name}");
Trace.TraceError(ToCurrentCulture($"Could not retrieve {nameof(IVsGetCfgProvider)} from project: {project.Name}"));
return null;
}

if (ErrorHandler.Failed(getConfigurationProvider.GetCfgProvider(out IVsCfgProvider provider)))
{
Trace.TraceError($"Could not retrieve {nameof(IVsCfgProvider)} from project: {project.Name}");
Trace.TraceError(ToCurrentCulture($"Could not retrieve {nameof(IVsCfgProvider)} from project: {project.Name}"));
return null;
}
if (!(provider is IVsCfgProvider2))
{
Trace.TraceError($"IVsCfgProvider returned {provider.GetType()} is not of the right type. Expected: {nameof(IVsCfgProvider2)}");
Trace.TraceError(ToCurrentCulture($"IVsCfgProvider returned {provider.GetType()} is not of the right type. Expected: {nameof(IVsCfgProvider2)}"));
return null;
}

Expand All @@ -87,7 +88,7 @@ public async Task<IVsCfg> GetVsProjectConfigurationAsync(Project project)

if (ErrorHandler.Failed(provider2.GetCfgOfName(activeConfiguration.ConfigurationName, activeConfiguration.PlatformName, out IVsCfg configuration)))
{
Trace.TraceError($"Could not retrieve {nameof(IVsCfg)} from project: {project.Name}");
Trace.TraceError(ToCurrentCulture($"Could not retrieve {nameof(IVsCfg)} from project: {project.Name}"));
return null;
}

Expand Down
9 changes: 5 additions & 4 deletions src/ApiPort.VisualStudio.Common/DefaultProjectBuilder.cs
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;

using static Microsoft.VisualStudio.VSConstants;
using static Microsoft.Fx.Portability.Utils.FormattableStringHelper;
using System;
using System.Threading;
using Microsoft.VisualStudio;
Expand Down Expand Up @@ -99,27 +100,27 @@ public virtual async Task<IEnumerable<string>> GetBuildOutputFilesAsync(Project

if (!(configuration is IVsProjectCfg2 configuration2))
{
Trace.TraceError($"IVsCfg returned {configuration.GetType()} is not of the right type. Expected: {nameof(IVsProjectCfg2)}");
Trace.TraceError(ToCurrentCulture($"IVsCfg returned {configuration.GetType()} is not of the right type. Expected: {nameof(IVsProjectCfg2)}"));
return null;
}

await _threadingService.SwitchToMainThreadAsync();

if (ErrorHandler.Failed(configuration2.OpenOutputGroup(Common.Constants.OutputGroups.BuiltProject, out IVsOutputGroup outputGroup)))
{
Trace.TraceError($"Could not retrieve {nameof(IVsOutputGroup)} from project: {project.Name}");
Trace.TraceError(ToCurrentCulture($"Could not retrieve {nameof(IVsOutputGroup)} from project: {project.Name}"));
return null;
}

if (!(outputGroup is IVsOutputGroup2 outputGroup2))
{
Trace.TraceError($"Could not retrieve {nameof(IVsOutputGroup2)} from project: {project.Name}");
Trace.TraceError(ToCurrentCulture($"Could not retrieve {nameof(IVsOutputGroup2)} from project: {project.Name}"));
return null;
}

if (ErrorHandler.Failed(outputGroup2.get_KeyOutputObject(out IVsOutput2 keyGroup)))
{
Trace.TraceError($"Could not retrieve {nameof(IVsOutput2)} from project: {project.Name}");
Trace.TraceError(ToCurrentCulture($"Could not retrieve {nameof(IVsOutput2)} from project: {project.Name}"));
return null;
}

Expand Down
9 changes: 5 additions & 4 deletions src/ApiPort/DocIdSearchRepl.cs
Expand Up @@ -7,6 +7,7 @@
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using static Microsoft.Fx.Portability.Utils.FormattableStringHelper;

namespace ApiPort
{
Expand All @@ -20,15 +21,15 @@ public DocIdSearchRepl(ISearcher<string> searcher)

public async Task DocIdSearchAsync()
{
var countOption = $"{LocalizedStrings.ReplOptionCount}[{LocalizedStrings.Number}]";
var countOption = ToCurrentCulture($"{LocalizedStrings.ReplOptionCount}[{LocalizedStrings.Number}]");
var optionColumnWidth = Math.Max(countOption.Length, LocalizedStrings.ReplOptionExit.Length);

Console.WriteLine();
Console.WriteLine(LocalizedStrings.ReplEnterQuery);
Console.WriteLine();
Console.WriteLine(LocalizedStrings.ReplOptionsHeader);
Console.WriteLine($" {LocalizedStrings.ReplOptionExit.PadRight(optionColumnWidth)}\t{LocalizedStrings.ReplOptionExit_Text}");
Console.WriteLine($" {countOption.PadRight(optionColumnWidth)}\t{LocalizedStrings.ReplOptionCount_Text}");
Console.WriteLine(ToCurrentCulture($" {LocalizedStrings.ReplOptionExit.PadRight(optionColumnWidth)}\t{LocalizedStrings.ReplOptionExit_Text}"));
Console.WriteLine(ToCurrentCulture($" {countOption.PadRight(optionColumnWidth)}\t{LocalizedStrings.ReplOptionCount_Text}"));
Console.WriteLine();

Console.CancelKeyPress += ConsoleCancelKeyPress;
Expand Down Expand Up @@ -95,7 +96,7 @@ private async Task ReplLoopAsync()
{
foreach (var result in results)
{
WriteColorLine($"\"{result}\",", ConsoleColor.Cyan);
WriteColorLine(ToCurrentCulture($"\"{result}\","), ConsoleColor.Cyan);
}
}
else
Expand Down
5 changes: 3 additions & 2 deletions src/Microsoft.Fx.Portability.Reports.Html/HtmlReportWriter.cs
Expand Up @@ -12,6 +12,7 @@
using System;
using Microsoft.Fx.Portability.Reports.Html;
using Microsoft.Fx.Portability.Reports.Html.Resources;
using static System.FormattableString;

namespace Microsoft.Fx.Portability.Reports
{
Expand Down Expand Up @@ -115,7 +116,7 @@ public IEncodedString TargetSupportCell(TargetSupportedIn supportStatus)
var className = supported ? "IconSuccessEncoded" : "IconErrorEncoded";
var title = supported ? LocalizedStrings.Supported : LocalizedStrings.NotSupported;

return Raw($"<td class=\"{className}\" title=\"{title}\"></td>");
return Raw(Invariant($"<td class=\"{className}\" title=\"{title}\"></td>"));
}

public IEncodedString BreakingChangeCountCell(int breaks, int warningThreshold, int errorThreshold)
Expand All @@ -130,7 +131,7 @@ public IEncodedString BreakingChangeCountCell(int breaks, int warningThreshold,
className = breaks <= errorThreshold ? "FewBreakingChanges" : "ManyBreakingChanges";
}

return Raw($"<td class=\"textCentered {className}\">{breaks}</td>");
return Raw(Invariant($"<td class=\"textCentered {className}\">{breaks}</td>"));
}
#pragma warning restore CA1822 // Mark members as static
}
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.Fx.Portability/Microsoft.Fx.Portability.csproj
Expand Up @@ -7,6 +7,8 @@
-->
<TargetFrameworks>netstandard1.3;net46</TargetFrameworks>
<Description>The core data structures and network calls for .NET Portability Analyzer</Description>
<!-- Adding this to properly suppress CA3053. -->
<DefineConstants>$(DefineConstants);CODE_ANALYSIS</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'== 'net46'">
Expand Down
13 changes: 8 additions & 5 deletions src/Microsoft.Fx.Portability/TargetMapper.cs
Expand Up @@ -85,10 +85,7 @@ public void Load(Stream stream)
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver",
Justification = @"For the call to XmlReader.Create() below, CA3053 recommends setting the
XmlReaderSettings.XmlResolver property to either null or an instance of XmlSecureResolver.
However, the said XmlResolver property no longer exists in .NET portable framework (i.e. core framework) which means there is no way to set it.
So we suppress this error until the reporting for CA3053 has been updated to account for .NET portable framework.")]
Justification = @"We have set this in line 99 and 115. This is a false positive. https://msdn.microsoft.com/en-us/library/mt661872.aspx")]
private void Load(Stream stream, string path)
{
var readerSettings = new XmlReaderSettings
Expand All @@ -97,6 +94,10 @@ private void Load(Stream stream, string path)
CloseInput = false,
IgnoreComments = true,
IgnoreWhitespace = true,
DtdProcessing = DtdProcessing.Prohibit,
#if NET46
XmlResolver = null
#endif
};

try
Expand All @@ -114,7 +115,9 @@ private void Load(Stream stream, string path)
XmlResolver = null
};

schemas.Add(null, XmlReader.Create(xsdStream, xmlReaderSettings));
var reader = XmlReader.Create(xsdStream, xmlReaderSettings);

schemas.Add(null, reader);
doc.Validate(schemas, (s, e) => { throw new TargetMapperException(e.Message, e.Exception); });
}
#endif
Expand Down
13 changes: 13 additions & 0 deletions src/Microsoft.Fx.Portability/Utils/FormattableStringHelper.cs
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Globalization;

namespace Microsoft.Fx.Portability.Utils
{
public static class FormattableStringHelper
{
public static string ToCurrentCulture(FormattableString formattableString) => formattableString.ToString(CultureInfo.CurrentCulture);
}
}

0 comments on commit 3995a05

Please sign in to comment.