Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update StyleCop #345

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false
#Formatting - wrapping options

#leave code block on separate lines
csharp_preserve_single_line_blocks = false
csharp_preserve_single_line_blocks = true

#Style - Code block preferences

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</PropertyGroup>

<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
3 changes: 0 additions & 3 deletions codeAnalysis/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
// a specific target and scoped to a namespace, type, member, etc.
using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009:ClosingParenthesisMustBeSpacedCorrectly", Justification = "All current violations are due to Tuple shorthand and so valid.")]
[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1011:ClosingSquareBracketsMustBeSpacedCorrectly", Justification = "Optional arrays need to be supported. Ex []?")]

[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "We follow the C# Core Coding Style which avoids using `this` unless absolutely necessary.")]

[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:UsingDirectivesMustBePlacedWithinNamespace", Justification = "We follow the C# Core Coding Style which puts using statements outside the namespace.")]
Expand Down
40 changes: 0 additions & 40 deletions src/GitHubExtension/Client/Exceptions.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/GitHubExtension/Client/GithubClientProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class GitHubClientProvider
{
private readonly GitHubClient publicRepoClient;

private static readonly object InstanceLock = new ();
private static readonly object InstanceLock = new();

private static GitHubClientProvider? _instance;

Expand Down
16 changes: 16 additions & 0 deletions src/GitHubExtension/Client/InvalidApiException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace GitHubExtension.Client;

public class InvalidApiException : Exception
{
public InvalidApiException()
{
}

public InvalidApiException(string message)
: base(message)
{
}
}
16 changes: 16 additions & 0 deletions src/GitHubExtension/Client/InvalidGitHubUrlException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace GitHubExtension.Client;

public class InvalidGitHubUrlException : Exception
{
public InvalidGitHubUrlException()
{
}

public InvalidGitHubUrlException(string message)
: base(message)
{
}
}
16 changes: 16 additions & 0 deletions src/GitHubExtension/Client/InvalidUrlException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace GitHubExtension.Client;

public class InvalidUrlException : Exception
{
public InvalidUrlException()
{
}

public InvalidUrlException(string message)
: base(message)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@

namespace GitHubExtension;

public class RepositoryNotFoundException : ApplicationException
{
public RepositoryNotFoundException()
{
}

public RepositoryNotFoundException(string message)
: base(message)
{
}
}

public class DataStoreInaccessibleException : ApplicationException
{
public DataStoreInaccessibleException()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.Windows.DevHome.SDK;

namespace GitHubExtension;

public class DataStoreOperationParameters
{
// parameters for updating the data store.
Expand Down
4 changes: 2 additions & 2 deletions src/GitHubExtension/DataManager/GitHubDataManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using GitHubExtension.Client;
Expand Down Expand Up @@ -763,7 +763,7 @@ private void ValidateDataStore()

// Making the default options a singleton to avoid repeatedly calling the storage APIs and
// creating a new GitHubDataStoreSchema when not necessary.
private static readonly Lazy<DataStoreOptions> LazyDataStoreOptions = new (DefaultOptionsInit);
private static readonly Lazy<DataStoreOptions> LazyDataStoreOptions = new(DefaultOptionsInit);

private static DataStoreOptions DefaultOptions => LazyDataStoreOptions.Value;

Expand Down
16 changes: 16 additions & 0 deletions src/GitHubExtension/DataManager/RepositoryNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace GitHubExtension.DataManager;

public class RepositoryNotFoundException : ApplicationException
{
public RepositoryNotFoundException()
{
}

public RepositoryNotFoundException(string message)
: base(message)
{
}
}
2 changes: 1 addition & 1 deletion src/GitHubExtension/DataModel/GitHubDataStoreSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public GitHubDataStoreSchema()
"CREATE UNIQUE INDEX IDX_Review_InternalId ON Review (InternalId);";

// All Sqls together.
private static readonly List<string> SchemaSqlsValue = new ()
private static readonly List<string> SchemaSqlsValue = new()
{
Metadata,
User,
Expand Down
2 changes: 1 addition & 1 deletion src/GitHubExtension/DeveloperId/CredentialVault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void SaveCredentials(string loginId, SecureString? accessToken)
Marshal.Copy(credentialObject.CredentialBlob, accessTokenInChars, 0, accessTokenInChars.Length);

// convert accessTokenInChars to string
string accessTokenString = new (accessTokenInChars);
string accessTokenString = new(accessTokenInChars);

for (var i = 0; i < accessTokenInChars.Length; i++)
{
Expand Down
6 changes: 3 additions & 3 deletions src/GitHubExtension/DeveloperId/DeveloperId.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.Windows.DevHome.SDK;
Expand Down Expand Up @@ -26,7 +26,7 @@ public DeveloperId()
DisplayName = string.Empty;
Email = string.Empty;
Url = string.Empty;
GitHubClient = new (new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME));
GitHubClient = new(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME));
}

public DeveloperId(string loginId, string displayName, string email, string url, GitHubClient gitHubClient)
Expand Down Expand Up @@ -65,7 +65,7 @@ public Windows.Security.Credentials.PasswordCredential RefreshDeveloperId()
CredentialExpiryTime = DateTime.MaxValue;
DeveloperIdProvider.GetInstance().RefreshDeveloperId(this);
var credential = DeveloperIdProvider.GetInstance().GetCredentials(this) ?? throw new InvalidOperationException("Invalid credential present for valid DeveloperId");
GitHubClient.Credentials = new (credential.Password);
GitHubClient.Credentials = new(credential.Password);
return credential;
}

Expand Down
26 changes: 13 additions & 13 deletions src/GitHubExtension/DeveloperId/DeveloperIdProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace GitHubExtension.DeveloperId;
public class DeveloperIdProvider : IDeveloperIdProviderInternal
{
// Locks to control access to Singleton class members.
private static readonly object _developerIdsLock = new ();
private static readonly object _developerIdsLock = new();

private static readonly object _oAuthRequestsLock = new ();
private static readonly object _oAuthRequestsLock = new();

// DeveloperId list containing all Logged in Ids.
private List<DeveloperId> DeveloperIds
Expand All @@ -39,7 +39,7 @@ private List<OAuthRequest> OAuthRequests
public string DisplayName => "GitHub";

// DeveloperIdProvider uses singleton pattern.
private static Lazy<DeveloperIdProvider> _singletonDeveloperIdProvider = new (() => new DeveloperIdProvider());
private static Lazy<DeveloperIdProvider> _singletonDeveloperIdProvider = new(() => new DeveloperIdProvider());

public static DeveloperIdProvider GetInstance()
{
Expand All @@ -51,7 +51,7 @@ private DeveloperIdProvider()
{
Log.Logger()?.ReportInfo($"Creating DeveloperIdProvider singleton instance");

_credentialVault = new (() => new CredentialVault());
_credentialVault = new(() => new CredentialVault());

lock (_oAuthRequestsLock)
{
Expand All @@ -76,7 +76,7 @@ private DeveloperIdProvider()

public DeveloperIdsResult GetLoggedInDeveloperIds()
{
List<IDeveloperId> iDeveloperIds = new ();
List<IDeveloperId> iDeveloperIds = new();
lock (_developerIdsLock)
{
iDeveloperIds.AddRange(DeveloperIds);
Expand Down Expand Up @@ -113,11 +113,11 @@ public DeveloperId LoginNewDeveloperIdWithPAT(Uri hostAddress, SecureString pers
{
try
{
GitHubClient gitHubClient = new (new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME), hostAddress);
GitHubClient gitHubClient = new(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME), hostAddress);
var credentials = new Credentials(new System.Net.NetworkCredential(string.Empty, personalAccessToken).Password);
gitHubClient.Credentials = credentials;
var newUser = gitHubClient.User.Current().Result;
DeveloperId developerId = new (newUser.Login, newUser.Name, newUser.Email, newUser.Url, gitHubClient);
DeveloperId developerId = new(newUser.Login, newUser.Name, newUser.Email, newUser.Url, gitHubClient);
SaveOrOverwriteDeveloperId(developerId, personalAccessToken);

Log.Logger()?.ReportInfo($"{developerId.LoginId} logged in with PAT flow to {developerId.GetHostAddress()}");
Expand All @@ -133,7 +133,7 @@ public DeveloperId LoginNewDeveloperIdWithPAT(Uri hostAddress, SecureString pers

private OAuthRequest? LoginNewDeveloperId()
{
OAuthRequest oauthRequest = new ();
OAuthRequest oauthRequest = new();

lock (_oAuthRequestsLock)
{
Expand Down Expand Up @@ -222,7 +222,7 @@ public void HandleOauthRedirection(Uri authorizationResponse)

public IEnumerable<DeveloperId> GetLoggedInDeveloperIdsInternal()
{
List<DeveloperId> iDeveloperIds = new ();
List<DeveloperId> iDeveloperIds = new();
lock (_developerIdsLock)
{
iDeveloperIds.AddRange(DeveloperIds);
Expand Down Expand Up @@ -321,15 +321,15 @@ private void RestoreDeveloperIds(IEnumerable<string> loginIdsAndUrls)
// For loginIds without URL, use GitHub.com as default.
var hostAddress = isUrl ? new Uri(loginIdOrUrl) : new Uri(Constants.GITHUB_COM_URL);

GitHubClient gitHubClient = new (new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME), hostAddress)
GitHubClient gitHubClient = new(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME), hostAddress)
{
Credentials = new (_credentialVault.Value.GetCredentials(loginIdOrUrl)?.Password),
Credentials = new(_credentialVault.Value.GetCredentials(loginIdOrUrl)?.Password),
};

try
{
var user = gitHubClient.User.Current().Result;
DeveloperId developerId = new (user.Login, user.Name, user.Email, user.Url, gitHubClient);
DeveloperId developerId = new(user.Login, user.Name, user.Email, user.Url, gitHubClient);
lock (_developerIdsLock)
{
DeveloperIds.Add(developerId);
Expand Down Expand Up @@ -396,7 +396,7 @@ public void Dispose()
// This function is to be used for testing purposes only.
public static void ResetInstanceForTests()
{
_singletonDeveloperIdProvider = new (() => new DeveloperIdProvider());
_singletonDeveloperIdProvider = new(() => new DeveloperIdProvider());
}

public IAsyncOperation<DeveloperIdResult> ShowLogonSession(WindowId windowHandle) => throw new NotImplementedException();
Expand Down
6 changes: 3 additions & 3 deletions src/GitHubExtension/DeveloperId/OAuthRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ internal DateTime StartTime

internal OAuthRequest()
{
gitHubClient = new (new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME));
oAuthCompleted = new (0);
gitHubClient = new(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME));
oAuthCompleted = new(0);
State = string.Empty;
}

Expand Down Expand Up @@ -133,7 +133,7 @@ internal DeveloperId RetrieveDeveloperId()
}

var newUser = gitHubClient.User.Current().Result;
DeveloperId developerId = new (newUser.Login, newUser.Name, newUser.Email, newUser.Url, gitHubClient);
DeveloperId developerId = new(newUser.Login, newUser.Name, newUser.Email, newUser.Url, gitHubClient);

return developerId;
}
Expand Down
2 changes: 1 addition & 1 deletion src/GitHubExtension/Helpers/EnumHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class EnumHelper
SearchCategory.Issues => "Issues",
SearchCategory.PullRequests => "PullRequests",
SearchCategory.IssuesAndPullRequests => "IssuesAndPullRequests",
_ => "unknown"
_ => "unknown",
};

public static SearchCategory StringToSearchCategory(string value)
Expand Down
2 changes: 1 addition & 1 deletion src/GitHubExtension/Helpers/IconLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace GitHubExtension.Helpers;

public class IconLoader
{
private static readonly Dictionary<string, string> Base64ImageRegistry = new ();
private static readonly Dictionary<string, string> Base64ImageRegistry = new();

public static string GetIconAsBase64(string filename)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GitHubExtension/Providers/RepositoryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ IAsyncOperation<RepositoriesResult> IRepositoryProvider.GetRepositoriesAsync(IDe
var repositoryList = new List<IRepository>();
try
{
ApiOptions apiOptions = new ()
ApiOptions apiOptions = new()
{
PageSize = 50,
PageCount = 1,
Expand Down
2 changes: 1 addition & 1 deletion src/GitHubExtension/Providers/SettingsUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class SettingsUIController : IExtensionAdaptiveCardSession
private static readonly string _notificationsEnabledString = "NotificationsEnabled";

private IExtensionAdaptiveCard? _settingsUI;
private static readonly SettingsUITemplate _settingsUITemplate = new ();
private static readonly SettingsUITemplate _settingsUITemplate = new();

public void Dispose()
{
Expand Down
2 changes: 1 addition & 1 deletion src/GitHubExtension/Widgets/GitHubPullsWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class GitHubPullsWidget : GitHubRepositoryWidget
{
private readonly string pullsIconData = IconLoader.GetIconAsBase64("pulls.png");

private static Dictionary<string, string> Templates { get; set; } = new ();
private static Dictionary<string, string> Templates { get; set; } = new();

protected static readonly new string Name = nameof(GitHubPullsWidget);

Expand Down
Loading
Loading