Skip to content

Commit f28ddc3

Browse files
Fix remaining violations and suppress multi-target false positives in .editorconfig
Additional fixes applied: - IDE0018: Inline variable declaration - IDE0059: Remove unnecessary value assignments - IDE0036: Order modifiers - IDE1005: Use conditional delegate call - IDE0305: Use collection expression (fluent) - IDE0083: Use pattern matching 'is not null' - IDE0300/IDE0301: Use collection expressions - IDE0290: Additional primary constructor fixes - CA1854: Prefer TryGetValue over ContainsKey - CA1860/CA1861: Enumerable.Any, constant array fixes .editorconfig: Suppress rules that are multi-target false positives: - IDE0039: Lambda->local function breaks VSTHRD200 naming convention - IDE0051/IDE0052: Removes members used in other TFMs via #if blocks - IDE0056: Range/index operator requires .NET 5+ - CA1845/CA1846: Span-based overloads require .NET 5+ - CA1850: HashData requires .NET 5+ - CA2250/CA1512/CA1513: ThrowIfX methods require .NET 6+/8+ Remaining unfixable violations: - IDE1006 (382): Naming - no Fix All support in dotnet format - IDE0130 (359): Namespace != folder - crashes dotnet format - IDE0090 (44): new() in preprocessor blocks - CA1859 (20): No code fix available - IDE0060 (16): Unused parameter - no code fix Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e6bcf6d commit f28ddc3

20 files changed

Lines changed: 55 additions & 49 deletions

.editorconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,30 @@ dotnet_diagnostic.IDE0057.severity = none
875875
# Disabled: introduces duplicate variable declarations in #if multi-target preprocessor blocks
876876
dotnet_diagnostic.IDE0019.severity = none
877877

878+
# Use local function instead of lambda (IDE0039)
879+
# Disabled: local functions require Async suffix per VSTHRD200; lambda conversions break naming convention
880+
dotnet_diagnostic.IDE0039.severity = none
881+
882+
# Remove unused private members (IDE0051/IDE0052)
883+
# Disabled: members may be used in other TFMs inside #if preprocessor blocks
884+
dotnet_diagnostic.IDE0051.severity = none
885+
dotnet_diagnostic.IDE0052.severity = none
886+
887+
# Use range subscript operator (x[^1]) - requires .NET 5+ (System.Index not available in net462/netstandard2.0)
888+
dotnet_diagnostic.IDE0056.severity = none
889+
890+
# Use Span-based string comparison / overloads - requires .NET 5+
891+
dotnet_diagnostic.CA1845.severity = none
892+
dotnet_diagnostic.CA1846.severity = none
893+
894+
# Use HashData instead of ComputeHash - requires .NET 5+
895+
dotnet_diagnostic.CA1850.severity = none
896+
897+
# Use ThrowIfCancellationRequested / ThrowIfNegativeOrZero / ObjectDisposedException.ThrowIf - requires .NET 6+/8+
898+
dotnet_diagnostic.CA2250.severity = none
899+
dotnet_diagnostic.CA1512.severity = none
900+
dotnet_diagnostic.CA1513.severity = none
901+
878902
# Dispose objects before losing scope
879903
dotnet_diagnostic.CA2000.severity = none
880904

src/client/Microsoft.Identity.Client/AppConfig/AuthorityInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ internal bool IsDefaultAuthority
304304
}
305305
}
306306

307-
internal static readonly char[] separator = new[]
308-
{
307+
internal static readonly char[] separator =
308+
[
309309
'/'
310-
};
310+
];
311311

312312
internal Authority CreateAuthority()
313313
{

src/client/Microsoft.Identity.Client/Cache/Items/MsalAccessTokenCacheItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ internal void InitCacheKey()
215215
_credentialDescriptor = StorageJsonValues.CredentialTypeAccessTokenExtended;
216216
if (_extraKeyParts != null)
217217
{
218-
_extraKeyParts = _extraKeyParts.Concat(new[] { CoreHelpers.ComputeAccessTokenExtCacheKey(AdditionalCacheKeyComponents) }).ToArray();
218+
_extraKeyParts = [.. _extraKeyParts, .. new[] { CoreHelpers.ComputeAccessTokenExtCacheKey(AdditionalCacheKeyComponents) }];
219219
}
220220
else
221221
{

src/client/Microsoft.Identity.Client/ClientApplicationBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ private async Task<IEnumerable<IAccount>> GetAccountsInternalAsync(ApiIds apiId,
207207

208208
IEnumerable<IAccount> accountsFromCache = await cacheSessionManager.GetAccountsAsync().ConfigureAwait(false);
209209
IEnumerable<IAccount> accountsFromBroker = await GetAccountsFromBrokerAsync(homeAccountIdFilter, cacheSessionManager, cancellationToken).ConfigureAwait(false);
210-
accountsFromCache ??= Enumerable.Empty<IAccount>();
211-
accountsFromBroker ??= Enumerable.Empty<IAccount>();
210+
accountsFromCache ??= [];
211+
accountsFromBroker ??= [];
212212

213213
ServiceBundle.ApplicationLogger.Info(() => $"Found {accountsFromCache.Count()} cache accounts and {accountsFromBroker.Count()} broker accounts");
214214
IEnumerable<IAccount> cacheAndBrokerAccounts = MergeAccounts(accountsFromCache, accountsFromBroker);
@@ -249,7 +249,7 @@ private async Task<IEnumerable<IAccount>> GetAccountsFromBrokerAsync(
249249
}
250250
}
251251

252-
return Enumerable.Empty<IAccount>();
252+
return [];
253253
}
254254

255255
// Not all brokers return the accounts only for the given env

src/client/Microsoft.Identity.Client/Instance/Discovery/InstanceDiscoveryManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private async Task<InstanceDiscoveryMetadataEntry> FetchNetworkMetadataOrFallbac
208208
$" Exception: {e} ");
209209

210210
return
211-
_knownMetadataProvider.GetMetadata(authorityUri.Host, Enumerable.Empty<string>(), requestContext.Logger)
211+
_knownMetadataProvider.GetMetadata(authorityUri.Host, [], requestContext.Logger)
212212
?? CreateEntryForSingleAuthority(authorityUri);
213213
}
214214
}

src/client/Microsoft.Identity.Client/Instance/Discovery/KnownMetadataProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public InstanceDiscoveryMetadataEntry GetMetadata(
122122
IEnumerable<string> existingEnvironmentsInCache,
123123
ILoggerAdapter logger)
124124
{
125-
existingEnvironmentsInCache ??= Enumerable.Empty<string>();
125+
existingEnvironmentsInCache ??= [];
126126

127127
bool canUseProvider = existingEnvironmentsInCache.All(e => s_knownEnvironments.ContainsOrdinalIgnoreCase(e));
128128

src/client/Microsoft.Identity.Client/Internal/Broker/BrokerInteractiveRequestComponent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ private static string ExtractAppLink(string authCode)
115115

116116
Dictionary<string, string> queryDict = CoreHelpers.ParseKeyValueList(query, '&', true, true, null);
117117

118-
if (!queryDict.ContainsKey(BrokerParameter.AppLink))
118+
if (!queryDict.TryGetValue(BrokerParameter.AppLink, out string value))
119119
{
120120
return null;
121121
}
122122

123-
return queryDict[BrokerParameter.AppLink];
123+
return value;
124124
}
125125
}
126126
}

src/client/Microsoft.Identity.Client/Kerberos/KerberosSupplementalTicketManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public static class KerberosSupplementalTicketManager
2929
{
3030
private const int DefaultLogonId = 0;
3131
private const string KerberosClaimType = "xms_as_rep";
32-
private const string IdTokenAsRepTemplate = @"{{""id_token"": {{ ""xms_as_rep"":{{""essential"":""false"",""value"":""{0}""}} }} }}";
33-
private const string AccessTokenAsRepTemplate = @"{{""access_token"": {{ ""xms_as_rep"":{{""essential"":""false"",""value"":""{0}""}} }} }}";
3432

3533
/// <summary>
3634
/// Creates a <see cref="KerberosSupplementalTicket"/> object from given ID token string..

src/client/Microsoft.Identity.Client/ManagedIdentity/AzureArcManagedIdentitySource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal class AzureArcManagedIdentitySource : AbstractManagedIdentity
2121
private const string AzureArc = "Azure Arc";
2222

2323
private readonly Uri _endpoint;
24-
internal static readonly char[] separator = new char[] { '=' };
24+
internal static readonly char[] separator = ['='];
2525

2626
public static AbstractManagedIdentity Create(RequestContext requestContext)
2727
{

src/client/Microsoft.Identity.Client/ManagedIdentity/MachineLearningManagedIdentitySource.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ namespace Microsoft.Identity.Client.ManagedIdentity
1111
{
1212
internal class MachineLearningManagedIdentitySource : AbstractManagedIdentity
1313
{
14-
private const string MachineLearning = "Machine Learning";
15-
1614
private const string MachineLearningMsiApiVersion = "2017-09-01";
1715
private const string SecretHeaderName = "secret";
1816

0 commit comments

Comments
 (0)