Skip to content

Commit

Permalink
Fix/suppress warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamTheCoder committed Apr 3, 2022
1 parent 4412bd6 commit 69a16a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CodeConverter/CSharp/QueryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ private static bool RequiresMethodInvocation(VBSyntax.QueryClauseSyntax queryCla
private static bool RequiredContinuation(VBSyntax.QueryClauseSyntax queryClauseSyntax, int clausesAfter) => queryClauseSyntax is VBSyntax.GroupByClauseSyntax
|| queryClauseSyntax is VBSyntax.SelectClauseSyntax sc && (sc.Variables.Any(v => v.NameEquals is null) || clausesAfter == 0);

private async Task<IEnumerable<CSSyntax.FromClauseSyntax>> ConvertFromClauseSyntaxAsync(VBSyntax.FromClauseSyntax vbFromClause) => await vbFromClause.Variables.SelectAsync(ConvertFromClauseVariable);
private async Task<IEnumerable<CSSyntax.FromClauseSyntax>> ConvertFromClauseSyntaxAsync(VBSyntax.FromClauseSyntax vbFromClause) => await vbFromClause.Variables.SelectAsync(ConvertFromClauseVariableAsync);

private async Task<CSSyntax.FromClauseSyntax> ConvertFromClauseVariable(CollectionRangeVariableSyntax collectionRangeVariableSyntax)
private async Task<CSSyntax.FromClauseSyntax> ConvertFromClauseVariableAsync(CollectionRangeVariableSyntax collectionRangeVariableSyntax)
{
var expression = await collectionRangeVariableSyntax.Expression.AcceptAsync<CSSyntax.ExpressionSyntax>(_triviaConvertingVisitor);
var parentOperation = _semanticModel.GetOperation(collectionRangeVariableSyntax.Expression)?.Parent;
Expand Down
23 changes: 13 additions & 10 deletions CommandLine/CodeConv.Shared/CodeConvProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
using System.Text.RegularExpressions;
using Microsoft.CodeAnalysis;
using ICSharpCode.CodeConverter.CommandLine.Util;
using CodeConv.Shared.Util;
using System.Reflection;
using System.Diagnostics;
using Microsoft.VisualStudio.Threading;
// ReSharper disable UnassignedGetOnlyAutoProperty - Command line framework initializes these by reflection

namespace ICSharpCode.CodeConverter.CommandLine
{
Expand All @@ -33,8 +33,11 @@ public partial class CodeConvProgram

/// <remarks>Calls <see cref="OnExecuteAsync(CommandLineApplication)"/> by reflection</remarks>
public static async Task<int> Main(string[] args) => await CommandLineApplication.ExecuteAsync<CodeConvProgram>(args);
/// <remarks>Used by reflection in CommandLineApplication.ExecuteAsync</remarks>
// ReSharper disable once UnusedMember.Local - Used by reflection in CommandLineApplication.ExecuteAsync
#pragma warning disable IDE0052 // Remove unread private members - Used by reflection in CommandLineApplication.ExecuteAsync
// ReSharper disable once UnusedParameter.Local - Used by reflection in CommandLineApplication.ExecuteAsync
private async Task<int> OnExecuteAsync(CommandLineApplication _) => await ExecuteAsync();
#pragma warning restore IDE0052 // Remove unread private members

[FileExists]
[Required]
Expand Down Expand Up @@ -82,7 +85,7 @@ private async Task<int> ExecuteAsync()
}

try {
Progress<ConversionProgress>? progress = new Progress<ConversionProgress>(s => Console.Out.WriteLine(s.ToString()));
Progress<ConversionProgress> progress = new Progress<ConversionProgress>(s => Console.Out.WriteLine(s.ToString()));
await ConvertAsync(progress, CancellationToken.None);
} catch (Exception ex) {
await Task.Delay(100); // Give any async progress updates a moment to flush so they don't clash with this:
Expand Down Expand Up @@ -114,9 +117,9 @@ private static async Task<int> RunNetFrameworkExeAsync(string latestMsBuildExePa
var args = Environment.GetCommandLineArgs().Skip(1).ToArray();
if (string.IsNullOrWhiteSpace(assemblyDirectoryPath)) throw new InvalidOperationException("Could not retrieve executing assembly directory");
var netFrameworkExe = Path.Combine(assemblyDirectoryPath, "..", "..", "NetFramework", "ICSharpCode.CodeConverter.CodeConv.NetFramework.exe");
if (!File.Exists(netFrameworkExe)) {
var debugAssemblyDirectoryPath = Path.GetDirectoryName(assemblyDirectoryPath).Replace("CommandLine\\CodeConv\\", "CommandLine\\CodeConv.NetFramework\\");
if (!File.Exists(netFrameworkExe) && Path.GetDirectoryName(assemblyDirectoryPath) is { } assemblyDirectoryParentPath) {

var debugAssemblyDirectoryPath = assemblyDirectoryParentPath.Replace("CommandLine\\CodeConv\\", "CommandLine\\CodeConv.NetFramework\\");
var debugNetFrameworkExe = Path.Combine(debugAssemblyDirectoryPath, "ICSharpCode.CodeConverter.CodeConv.NetFramework.exe");
netFrameworkExe = File.Exists(debugNetFrameworkExe) ? debugNetFrameworkExe : throw new FileNotFoundException($"Cannot find net framework exe at `{netFrameworkExe}`. Using the --core-only flag to get work around this.");
}
Expand All @@ -140,7 +143,7 @@ private async Task ConvertAsync(IProgress<ConversionProgress> progress, Cancella
var outputDirectory = new DirectoryInfo(directoryName ?? throw new InvalidOperationException("Output directory could not be determined"));
if (await CouldOverwriteUncommittedFilesAsync(outputDirectory)) {
var action = string.IsNullOrWhiteSpace(OutputDirectory) ? "may be overwritten" : "will be deleted";
strProgress.Report($"WARNING: There are files in {outputDirectory.FullName} which {action}, and aren't comitted to git");
strProgress.Report($"WARNING: There are files in {outputDirectory.FullName} which {action}, and aren't committed to git");
if (Force) strProgress.Report("Continuing with possibility of data loss due to force option.");
else throw new ValidationException("Aborting to avoid data loss (see above warning). Commit the files to git, remove them, or use the --force option to override this check.");
}
Expand Down Expand Up @@ -172,16 +175,16 @@ private string GetValidatedPropertyValue(string[] s)

private bool ShouldIncludeProject(Project project)
{
string? projectFilePath = project.FilePath ?? "";
string projectFilePath = project.FilePath ?? "";
var isIncluded = !Include.Any() || Include.Any(regex => Regex.IsMatch(projectFilePath, regex));
return isIncluded && Exclude.All(regex => !Regex.IsMatch(projectFilePath, regex));
}

private static async Task<string?> GetLatestMsBuildExePathAsync()
{
// The second path here is available on github action agents: https://github.com/microsoft/setup-msbuild#how-does-this-work
var pathsToCheck = new[] { @"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe", @"%ProgramData%\chocolatey\bin" }
.Select(Environment.ExpandEnvironmentVariables);
var pathsToCheck = new[] {@"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe", @"%ProgramData%\chocolatey\bin"}
.Select(Environment.ExpandEnvironmentVariables).ToArray();
var vsWhereExe = pathsToCheck.FirstOrDefault(File.Exists)
?? throw new FileNotFoundException($"Could not find VSWhere in: {string.Join(", ", pathsToCheck.Select(p => $"`{p}`"))}");
var args = new[] { "-latest", "-prerelease", "-products", "*", "-requires", "Microsoft.Component.MSBuild", "-version", "[16.0,]", "-find", @"MSBuild\**\Bin\MSBuild.exe" };
Expand Down

0 comments on commit 69a16a7

Please # to comment.