Skip to content

Commit

Permalink
Enabling static analysis on indexer plugin and fixing errors (#5220)
Browse files Browse the repository at this point in the history
* Enabling code analysis, and treating warnings as errors

* Error CA1724 The type name Settings conflicts in whole or in part with the namespace name 'Microsoft.PowerToys.Settings'. Change either name to eliminate the conflict. Microsoft.Plugin.Indexer C:\repos\powertoys\src\modules\launcher\Plugins\Microsoft.Plugin.Indexer\Settings.cs 9 Active

* Removing keyword "Interface" from namespace to fix fxcop warnings

* Fixing static analysis warnings on ContextMenuLoader

* Fixing general exception warnings for static analysis

* Fixing public list variables, non static methods, and general exception warning

* Implementing IDisposable on OleDBSearch although in practice these objects were already being disposed.

Also Validated we were not using user input directly for sql strings.

* Removing VS generated comments from dispose methods as per PR feedback.

* Setting translated text to use current culture as per PR feedback.

* Explicity specifying 'internal' access modifier for Indexer 'Main' class, as per PR feedback

* Updating to FxCop 3.0.0
  • Loading branch information
ryanbodrug-microsoft committed Jul 30, 2020
1 parent aa8c31e commit 8f17f72
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public enum ResultType
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 and show an error message")]
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
{
var contextMenus = new List<ContextMenuResult>();
Expand Down Expand Up @@ -111,6 +112,7 @@ public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
}

// Function to add the context menu item to run as admin
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log the exeption message")]
private ContextMenuResult CreateRunAsAdminContextMenu(SearchResult record)
{
return new ContextMenuResult
Expand Down Expand Up @@ -152,7 +154,7 @@ private bool CanFileBeRunAsAdmin(string path)
return false;
}


[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log and show an error message")]
private ContextMenuResult CreateOpenContainingFolderResult(SearchResult record)
{
return new ContextMenuResult
Expand Down Expand Up @@ -182,7 +184,7 @@ private ContextMenuResult CreateOpenContainingFolderResult(SearchResult record)
};
}

public void LogException(string message, Exception e)
public static void LogException(string message, Exception e)
{
Log.Exception($"|Microsoft.Plugin.Folder.ContextMenu|{message}", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Plugin.Indexer.DriveDetection;
using Microsoft.Plugin.Indexer.Interface;

namespace Microsoft.Plugin.Indexer.DriveDetection
namespace Microsoft.Plugin.Indexer.DriveDetection
{
public class IndexerDriveDetection
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
using Microsoft.Plugin.Indexer.Interface;
using Microsoft.Plugin.Indexer;
using Microsoft.Win32;

namespace Microsoft.Plugin.Indexer.DriveDetection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Plugin.Indexer.Interface
namespace Microsoft.Plugin.Indexer
{
public interface IRegistryWrapper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Plugin.Indexer.SearchHelper;
using System.Collections.Generic;

namespace Microsoft.Plugin.Indexer.Interface
namespace Microsoft.Plugin.Indexer
{
public interface ISearch
{
Expand Down

0 comments on commit 8f17f72

Please sign in to comment.