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

Add missing string comparison type to equals comparisons #15675

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
54 changes: 54 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,58 @@
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
</PropertyGroup>

<PropertyGroup Label="Analysis rules">

<AnalysisLevel>latest-Recommended</AnalysisLevel>

<!-- Member is explicitly initialized to its default value -->
<NoWarn>$(NoWarn);CA1805</NoWarn>

<!-- The behavior could vary based on the current user's locale setting -->
<NoWarn>$(NoWarn);CA1304;CA1305;CA1310</NoWarn>

<!-- Specify a culture or use an invariant version to avoid implicit dependency on current culture -->
<NoWarn>$(NoWarn);CA1311</NoWarn>

<!-- Do not declare static members on generic types -->
<NoWarn>$(NoWarn);CA1000</NoWarn>

<!-- For improved performance, use the LoggerMessage delegates -->
<NoWarn>$(NoWarn);CA1848</NoWarn>

<!-- Identifier contains type name -->
<NoWarn>$(NoWarn);CA1720</NoWarn>

<!-- Do not declare visible instance fields -->
<NoWarn>$(NoWarn);CA1051</NoWarn>

<!-- Avoid using cref tags with a prefix -->
<NoWarn>$(NoWarn);CA1200</NoWarn>

<!--Rename type name X so that it does not end in 'Delegate', 'EventHandler', 'Permission' etc -->
<NoWarn>$(NoWarn);CA1711</NoWarn>

<!-- Parameter name differs from original overriden implemented name -->
<NoWarn>$(NoWarn);CA1725</NoWarn>

<!-- Reserved keyword -->
<NoWarn>$(NoWarn);CA1716</NoWarn>

<!-- Type owns disposable field(s) -->
<NoWarn>$(NoWarn);CA1001</NoWarn>

<!-- Exception type is not sufficiently specific -->
<NoWarn>$(NoWarn);CA2201</NoWarn>

<!-- Remove the underscores from member name -->
<NoWarn>$(NoWarn);CA1707</NoWarn>

<!-- Use PascalCase for named placeholders in the logging message template -->
<NoWarn>$(NoWarn);CA1727</NoWarn>

<!--CA1861 : Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array -->
<NoWarn>$(NoWarn);CA1861</NoWarn>

</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public override async Task CloningAsync(CloneContentContext context, AliasPart p
private async Task<string> GetPatternAsync(AliasPart part)
{
var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType);
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, nameof(AliasPart)));
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, nameof(AliasPart), System.StringComparison.Ordinal));
var pattern = contentTypePartDefinition.GetSettings<AliasPartSettings>().Pattern;

return pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context,
return context.ForAsync<RouteHandlerAspect>(async aspect =>
{
var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType);
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "AutoroutePart"));
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "AutoroutePart", StringComparison.Ordinal));
var settings = contentTypePartDefinition.GetSettings<AutoroutePartSettings>();
if (settings.ManageContainedItemRoutes)
{
Expand Down Expand Up @@ -425,7 +425,7 @@ private async Task GenerateContainerPathFromPatternAsync(AutoroutePart part)
private async Task<string> GetPatternAsync(AutoroutePart part)
{
var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType);
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, nameof(AutoroutePart)));
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, nameof(AutoroutePart), StringComparison.Ordinal));
var pattern = contentTypePartDefinition.GetSettings<AutoroutePartSettings>().Pattern;

return pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ private static async ValueTask<object> RenderHtml(IResolveFieldContext<HtmlField
var partName = paths[0];
var fieldName = paths[1];
var contentTypeDefinition = await contentDefinitionManager.GetTypeDefinitionAsync(ctx.Source.ContentItem.ContentType);
var contentPartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.Name, partName));
var contentPartFieldDefinition = contentPartDefinition.PartDefinition.Fields.FirstOrDefault(x => string.Equals(x.Name, fieldName));
var contentPartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.Name, partName, System.StringComparison.Ordinal));
var contentPartFieldDefinition = contentPartDefinition.PartDefinition.Fields.FirstOrDefault(x => string.Equals(x.Name, fieldName, System.StringComparison.Ordinal));
var settings = contentPartFieldDefinition.GetSettings<HtmlFieldSettings>();

var html = ctx.Source.Html;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public async Task GetContentItemsAsync(ContentTypesSitemapSource source, Content
{
// Test that content type is still valid to include in sitemap.
var contentType = routeableContentTypeDefinitions
.FirstOrDefault(ctd => string.Equals(source.LimitedContentType.ContentTypeName, ctd.Name));
.FirstOrDefault(ctd => string.Equals(source.LimitedContentType.ContentTypeName, ctd.Name, System.StringComparison.Ordinal));

if (contentType == null)
{
return;
}

if (contentType.Parts.Any(ctd => string.Equals(ctd.Name, nameof(LocalizationPart))))
if (contentType.Parts.Any(ctd => string.Equals(ctd.Name, nameof(LocalizationPart), System.StringComparison.Ordinal)))
{
// Get all content items here for reference. Then reduce by default culture.
// We know that the content item should be localized.
Expand All @@ -77,7 +77,7 @@ public async Task GetContentItemsAsync(ContentTypesSitemapSource source, Content

// Reduce by default culture.
var items = queryResults
.Where(ci => string.Equals(ci.As<LocalizationPart>().Culture, defaultCulture))
.Where(ci => string.Equals(ci.As<LocalizationPart>().Culture, defaultCulture, System.StringComparison.Ordinal))
.Skip(source.LimitedContentType.Skip)
.Take(source.LimitedContentType.Take);

Expand All @@ -104,7 +104,7 @@ public async Task GetContentItemsAsync(ContentTypesSitemapSource source, Content
{
// Test that content types are still valid to include in sitemap.
var typesToIndex = routeableContentTypeDefinitions
.Where(ctd => source.ContentTypes.Any(s => string.Equals(ctd.Name, s.ContentTypeName)))
.Where(ctd => source.ContentTypes.Any(s => string.Equals(ctd.Name, s.ContentTypeName, System.StringComparison.Ordinal)))
.Select(x => x.Name);

// No advantage here in reducing with localized index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public PreviewPartHandler(
private async Task<string> GetPatternAsync(PreviewPart part)
{
var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType);
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "PreviewPart"));
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "PreviewPart", System.StringComparison.Ordinal));
var pattern = contentTypePartDefinition.GetSettings<PreviewPartSettings>().Pattern;

return pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public class AuditTrailPartSettingsDisplayDriver : ContentTypePartDefinitionDisp
{
public override IDisplayResult Edit(ContentTypePartDefinition model, IUpdateModel updater)
{
if (!string.Equals(nameof(AuditTrailPart), model.PartDefinition.Name)) return null;
if (!string.Equals(nameof(AuditTrailPart), model.PartDefinition.Name, System.StringComparison.Ordinal))
{
return null;
}

return Initialize<AuditTrailPartSettingsViewModel>("AuditTrailPartSettings_Edit", viewModel =>
{
Expand All @@ -24,7 +27,10 @@ public override IDisplayResult Edit(ContentTypePartDefinition model, IUpdateMode

public override async Task<IDisplayResult> UpdateAsync(ContentTypePartDefinition model, UpdateTypePartEditorContext context)
{
if (!string.Equals(nameof(AuditTrailPart), model.PartDefinition.Name)) return null;
if (!string.Equals(nameof(AuditTrailPart), model.PartDefinition.Name, System.StringComparison.Ordinal))
{
return null;
}

var viewModel = new AuditTrailPartSettingsViewModel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ private async Task<List<SelectListItem>> GetListableContentTypeOptionsAsync(
continue;
}

items.Add(new SelectListItem(definition.DisplayName, definition.Name, string.Equals(definition.Name, selectedContentType)));
items.Add(new SelectListItem(definition.DisplayName, definition.Name, string.Equals(definition.Name, selectedContentType, StringComparison.Ordinal)));
}

return items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private async Task PopulateChangeFrequencyPriority(ContentTypesSitemapSource sou
else
{
var sitemapEntry = source.ContentTypes
.FirstOrDefault(ct => string.Equals(ct.ContentTypeName, contentItem.ContentType));
.FirstOrDefault(ct => string.Equals(ct.ContentTypeName, contentItem.ContentType, System.StringComparison.Ordinal));

changeFrequencyValue = sitemapEntry.ChangeFrequency.ToString();
}
Expand All @@ -138,7 +138,7 @@ private async Task PopulateChangeFrequencyPriority(ContentTypesSitemapSource sou
else
{
var sitemapEntry = source.ContentTypes
.FirstOrDefault(ct => string.Equals(ct.ContentTypeName, contentItem.ContentType));
.FirstOrDefault(ct => string.Equals(ct.ContentTypeName, contentItem.ContentType, System.StringComparison.Ordinal));

priorityIntValue = sitemapEntry.Priority;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public override async Task<IDisplayResult> EditAsync(ContentTypesSitemapSource s
{
ContentTypeName = ctd.Name,
ContentTypeDisplayName = ctd.DisplayName,
IsChecked = sitemapSource.ContentTypes.Any(s => string.Equals(s.ContentTypeName, ctd.Name)),
ChangeFrequency = sitemapSource.ContentTypes.FirstOrDefault(s => string.Equals(s.ContentTypeName, ctd.Name))?.ChangeFrequency ?? ChangeFrequency.Daily,
Priority = sitemapSource.ContentTypes.FirstOrDefault(s => string.Equals(s.ContentTypeName, ctd.Name))?.Priority ?? 5,
IsChecked = sitemapSource.ContentTypes.Any(s => string.Equals(s.ContentTypeName, ctd.Name, System.StringComparison.Ordinal)),
ChangeFrequency = sitemapSource.ContentTypes.FirstOrDefault(s => string.Equals(s.ContentTypeName, ctd.Name, System.StringComparison.Ordinal))?.ChangeFrequency ?? ChangeFrequency.Daily,
Priority = sitemapSource.ContentTypes.FirstOrDefault(s => string.Equals(s.ContentTypeName, ctd.Name, System.StringComparison.Ordinal))?.Priority ?? 5,
})
.OrderBy(ctd => ctd.ContentTypeDisplayName)
.ToArray();
Expand All @@ -53,11 +53,11 @@ public override async Task<IDisplayResult> EditAsync(ContentTypesSitemapSource s
.ToArray();

var limitedCtd = contentTypeDefinitions
.FirstOrDefault(ctd => string.Equals(sitemapSource.LimitedContentType.ContentTypeName, ctd.Name));
.FirstOrDefault(ctd => string.Equals(sitemapSource.LimitedContentType.ContentTypeName, ctd.Name, System.StringComparison.Ordinal));

if (limitedCtd != null)
{
var limitedEntry = limitedEntries.FirstOrDefault(le => string.Equals(le.ContentTypeName, limitedCtd.Name));
var limitedEntry = limitedEntries.FirstOrDefault(le => string.Equals(le.ContentTypeName, limitedCtd.Name, System.StringComparison.Ordinal));
limitedEntry.Priority = sitemapSource.LimitedContentType.Priority;
limitedEntry.ChangeFrequency = sitemapSource.LimitedContentType.ChangeFrequency;
limitedEntry.Skip = sitemapSource.LimitedContentType.Skip;
Expand Down Expand Up @@ -106,7 +106,7 @@ public override async Task<IDisplayResult> UpdateAsync(ContentTypesSitemapSource
})
.ToArray();

var limitedEntry = model.LimitedContentTypes.FirstOrDefault(lct => string.Equals(lct.ContentTypeName, model.LimitedContentType));
var limitedEntry = model.LimitedContentTypes.FirstOrDefault(lct => string.Equals(lct.ContentTypeName, model.LimitedContentType, System.StringComparison.Ordinal));
if (limitedEntry != null)
{
sitemap.LimitedContentType.ContentTypeName = limitedEntry.ContentTypeName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ISession session
else
{
var typesToIndex = (await _routeableContentTypeCoordinator.ListRoutableTypeDefinitionsAsync())
.Where(ctd => source.ContentTypes.Any(s => string.Equals(ctd.Name, s.ContentTypeName)))
.Where(ctd => source.ContentTypes.Any(s => string.Equals(ctd.Name, s.ContentTypeName, StringComparison.Ordinal)))
.Select(ctd => ctd.Name);

// This is an estimate, so doesn't take into account Take/Skip values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public async Task UpdateSitemapAsync(SitemapUpdateContext context)
sitemap.Identifier = IdGenerator.GenerateId();
break;
}
else if (source.LimitItems && string.Equals(source.LimitedContentType.ContentTypeName, contentTypeName))
else if (source.LimitItems && string.Equals(source.LimitedContentType.ContentTypeName, contentTypeName, System.StringComparison.Ordinal))
{
sitemap.Identifier = IdGenerator.GenerateId();
break;
}
else if (source.ContentTypes.Any(ct => string.Equals(ct.ContentTypeName, contentTypeName)))
else if (source.ContentTypes.Any(ct => string.Equals(ct.ContentTypeName, contentTypeName, System.StringComparison.Ordinal)))
{
sitemap.Identifier = IdGenerator.GenerateId();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task GetContentItemsAsync(ContentTypesSitemapSource source, Content
{
// Test that content type is still valid to include in sitemap.
var typeIsValid = routeableContentTypeDefinitions
.Any(ctd => string.Equals(source.LimitedContentType.ContentTypeName, ctd.Name));
.Any(ctd => string.Equals(source.LimitedContentType.ContentTypeName, ctd.Name, System.StringComparison.Ordinal));

if (typeIsValid)
{
Expand All @@ -61,7 +61,7 @@ public async Task GetContentItemsAsync(ContentTypesSitemapSource source, Content
{
// Test that content types are still valid to include in sitemap.
var typesToIndex = routeableContentTypeDefinitions
.Where(ctd => source.ContentTypes.Any(s => string.Equals(ctd.Name, s.ContentTypeName)))
.Where(ctd => source.ContentTypes.Any(s => string.Equals(ctd.Name, s.ContentTypeName, System.StringComparison.Ordinal)))
.Select(x => x.Name);

var queryResults = await _session.Query<ContentItem>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace OrchardCore.Email.Services;

[Obsolete]
[Obsolete("Use IEmailService and its implementations instead")]
public class SmtpService : ISmtpService
{
private readonly EmailProviderOptions _emailProviderOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public class EmailMigrations : DataMigration
{
private const string SmtpFeatureId = "OrchardCore.Email.Smtp";

#pragma warning disable CA1822 // Member can be static
public int Create()
#pragma warning restore CA1822
{
// In version 1.9, the OrchardCore.Email.Smtp was split from OrchardCore.Email. To ensure we keep the change
// backward compatible, we added this migration step to auto-enable the new SMTP feature for sites that use the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void Configure(AuthenticationOptions options)
public void Configure(string name, FacebookOptions options)
{
// Ignore OpenID Connect client handler instances that don't correspond to the instance managed by the OpenID module.
if (!string.Equals(name, FacebookDefaults.AuthenticationScheme))
if (!string.Equals(name, FacebookDefaults.AuthenticationScheme, System.StringComparison.Ordinal))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private async Task<FacebookPluginPartSettings> GetFacebookPluginPartSettingsAsyn
ArgumentNullException.ThrowIfNull(part);

var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(part.ContentItem.ContentType);
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, nameof(FacebookPluginPart)));
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, nameof(FacebookPluginPart), StringComparison.Ordinal));
return contentTypePartDefinition.GetSettings<FacebookPluginPartSettings>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Configure(AuthenticationOptions options)
public void Configure(string name, GitHubOptions options)
{
// Ignore OpenID Connect client handler instances that don't correspond to the instance managed by the OpenID module.
if (!string.Equals(name, GitHubDefaults.AuthenticationScheme))
if (!string.Equals(name, GitHubDefaults.AuthenticationScheme, System.StringComparison.Ordinal))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Configure(AuthenticationOptions options)

public void Configure(string name, GoogleOptions options)
{
if (!string.Equals(name, GoogleDefaults.AuthenticationScheme))
if (!string.Equals(name, GoogleDefaults.AuthenticationScheme, System.StringComparison.Ordinal))
{
return;
}
Expand Down
Loading
Loading