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

Correct zero length check expressions #16463

Merged
merged 4 commits into from
Jul 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private async Task<IEnumerable<ContentTypeDefinition>> GetContainedContentTypesA
{
var settings = (await _contentDefinitionManager.GetTypeDefinitionAsync(contentType))?.Parts.SingleOrDefault(x => x.Name == partName)?.GetSettings<FlowPartSettings>();

if (settings?.ContainedContentTypes?.Length == 0)
if (settings?.ContainedContentTypes == null || settings.ContainedContentTypes.Length == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I checked if the more succinct items?.Any() == false pattern would work. It wouldn't, as it (I don't understand why) produces null; and it also violates CA1860, nudging you towards items?.Count == 0. So, that's not an option.

{
return (await _contentDefinitionManager.ListTypeDefinitionsAsync()).Where(t => t.StereotypeEquals("Widget"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private async Task<IEnumerable<ContentTypeDefinition>> GetContainedContentTypesA
{
var settings = typePartDefinition.GetSettings<FlowPartSettings>();

if (settings?.ContainedContentTypes?.Length == 0)
if (settings?.ContainedContentTypes == null || settings.ContainedContentTypes.Length == 0)
{
return (await _contentDefinitionManager.ListTypeDefinitionsAsync())
.Where(t => t.StereotypeEquals("Widget"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
model.Multiple = settings.Multiple;
model.AllowMediaText = settings.AllowMediaText;
model.AllowAnchors = settings.AllowAnchors;
model.AllowAllDefaultMediaTypes = settings.AllowedExtensions?.Length == 0;
model.AllowAllDefaultMediaTypes = settings.AllowedExtensions == null || settings.AllowedExtensions.Length == 0;

var items = new List<MediaTypeViewModel>();
foreach (var extension in _mediaOptions.AllowedFileExtensions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
return;
}

@if (Model.SearchIndexes == null || Model.SearchIndexes?.Count == 0)
@if (Model.SearchIndexes == null || Model.SearchIndexes.Count == 0)
{
<div class="alert alert-warning" role="alert">
@T["No indices exist! Please create at least one index to configure Azure AI Search service."]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public async Task<IEnumerable<ContentItem>> GetAsync(IEnumerable<string> content
.Distinct()
.ToArray();

if (ids?.Length == 0)
if (ids == null || ids.Length == 0)
{
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public async Task UpdateAsync(Query query, JsonNode data = null)

public async Task SaveAsync(params Query[] queries)
{
if (queries?.Length == 0)
if (queries == null || queries.Length == 0)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class AzureAISearchIndexSettingsStep : IRecipeStepHandler
private readonly AzureAIIndexDocumentManager _azureAIIndexDocumentManager;
private readonly AzureAISearchIndexSettingsService _azureAISearchIndexSettingsService;

internal readonly IStringLocalizer S;
internal IStringLocalizer S;

public AzureAISearchIndexSettingsStep(
AzureAISearchIndexManager indexManager,
Expand Down Expand Up @@ -68,7 +68,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
continue;
}

if (indexInfo.IndexedContentTypes?.Length == 0)
if (indexInfo.IndexedContentTypes == null || indexInfo.IndexedContentTypes.Length == 0)
{
context.Errors.Add(S["No {0} were provided in the recipe step. IndexName: {1}.", nameof(indexInfo.IndexedContentTypes), indexInfo.IndexName]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private bool HasConnectionInfo(ElasticConnectionOptions elasticConnectionOptions
optionsAreValid = false;
}

if (elasticConnectionOptions.Ports?.Length == 0)
if (elasticConnectionOptions.Ports == null || elasticConnectionOptions.Ports.Length == 0)
{
_logger.LogError("Elasticsearch is enabled but not active because a port is missing in application configuration.");
optionsAreValid = false;
Expand Down