User/ryanbod/folders enable staticanalysis (#5137)

* Enabling static analysis and settings treat warnings as errors

* Fixing/Supressing static analysis warnings in ContextmenuLoader and removing unused code

* Fixing static analysis errors in Main.cs

* Fixing static analysis warnings for folderpluginSettings.xaml.cs
This commit is contained in:
ryanbodrug-microsoft
2020-07-23 16:05:36 -07:00
committed by GitHub
parent 47736603af
commit 53c4c6cbb8
5 changed files with 81 additions and 90 deletions

View File

@@ -21,8 +21,9 @@ namespace Microsoft.Plugin.Folder
public ContextMenuLoader(PluginInitContext context)
{
_context = context;
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log the exception")]
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
{
var contextMenus = new List<ContextMenuResult>();
@@ -95,6 +96,7 @@ namespace Microsoft.Plugin.Folder
return contextMenus;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log the exception")]
private ContextMenuResult CreateOpenContainingFolderResult(SearchResult record)
{
return new ContextMenuResult
@@ -124,35 +126,7 @@ namespace Microsoft.Plugin.Folder
};
}
private Result CreateOpenWithEditorResult(SearchResult record)
{
string editorPath = "notepad.exe"; // TODO add the ability to create a custom editor
var name = "Open With Editor: " + Path.GetFileNameWithoutExtension(editorPath);
return new Result
{
Title = name,
Action = _ =>
{
try
{
Process.Start(editorPath, record.FullPath);
return true;
}
catch (Exception e)
{
var message = $"Fail to editor for file at {record.FullPath}";
LogException(message, e);
_context.API.ShowMsg(message);
return false;
}
},
IcoPath = editorPath
};
}
public void LogException(string message, Exception e)
public static void LogException(string message, Exception e)
{
Log.Exception($"|Microsoft.Plugin.Folder.ContextMenu|{message}", e);
}