Skip to content

Commit

Permalink
Fix issues detected by Sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
mingyaulee committed Dec 11, 2021
1 parent 43a2abb commit b2b575b
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private string GetTypeId(TypeReference? typeReference, NamespaceEntity namespace

if (typeReference.Ref is not null)
{
if (typeReference.Ref.Contains(".") || string.IsNullOrEmpty(namespaceEntity.FullFormattedName))
if (typeReference.Ref.Contains('.') || string.IsNullOrEmpty(namespaceEntity.FullFormattedName))
{
var capitalizedRef = string.Join('.', typeReference.Ref.Split('.').Select(x => x.ToCapitalCase()));
return $"{Constants.RelativeNamespaceToken}.{capitalizedRef}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ protected virtual void AddClassFunctions(TypeEntity typeEntity, List<FunctionDef
classFunctions.AddRange(typeEntity.Definition.ObjectFunctions);
}

foreach (var typeExtension in typeEntity.Extensions)
{
if (typeExtension.ObjectFunctions is not null)
{
classFunctions.AddRange(typeExtension.ObjectFunctions);
}
}
var typeExtensionFunctions = typeEntity.Extensions
.Where(typeExtension => typeExtension.ObjectFunctions is not null)
.SelectMany(typeExtension => typeExtension.ObjectFunctions!);
classFunctions.AddRange(typeExtensionFunctions);
}

protected virtual void AddClassProperties(TypeEntity typeEntity, List<KeyValuePair<string, PropertyDefinition>> classProperties)
Expand All @@ -75,13 +72,10 @@ protected virtual void AddClassProperties(TypeEntity typeEntity, List<KeyValuePa
classProperties.AddRange(typeEntity.Definition.ObjectProperties);
}

foreach (var typeExtension in typeEntity.Extensions)
{
if (typeExtension.ObjectProperties is not null)
{
classProperties.AddRange(typeExtension.ObjectProperties);
}
}
var typeExtensionProperties = typeEntity.Extensions
.Where(typeExtension => typeExtension.ObjectProperties is not null)
.SelectMany(typeExtension => typeExtension.ObjectProperties!);
classProperties.AddRange(typeExtensionProperties);
}

private static void AddPropertiesToClassEntity(IEnumerable<KeyValuePair<string, PropertyDefinition>> propertyDefinitionPairs, ClassEntity classEntity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public IEnumerable<NamespaceEntity> GetAllNamespaceEntities()
{
if (namespaceDefinition.Namespace is null)
{
logger.LogInformation($"Namespace is null for namespace definition in source '{namespaceDefinition.Source?.HttpUrl}'");
logger.LogInformation("Namespace is null for namespace definition in source '{HttpUrl}'", namespaceDefinition.Source?.HttpUrl);
return null;
}

NamespaceEntity? parentEntity = null;
var @namespace = namespaceDefinition.Namespace;
if (@namespace.Contains("."))
if (@namespace.Contains('.'))
{
var parentNamespaces = @namespace.Split('.');
@namespace = parentNamespaces.Last();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public bool ShouldProcess(NamespaceEntity namespaceEntity)
{
if (registrationOptions.ExcludeNamespaces is not null && registrationOptions.ExcludeNamespaces.Contains(namespaceEntity.FullName))
{
logger.LogWarning($"Skipped namespace '{namespaceEntity.FullName}'.");
logger.LogWarning("Skipped namespace '{FullName}'.", namespaceEntity.FullName);
return false;
}

if (registrationOptions.IncludeNamespaces is not null && !registrationOptions.IncludeNamespaces.Contains(namespaceEntity.FullName))
{
logger.LogError($"Namespace '{namespaceEntity.FullName}' is not recognized.");
logger.LogError("Namespace '{FullName}' is not recognized.", namespaceEntity.FullName);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void RegisterNamespaceType(TypeDefinition typeDefinition, NamespaceEntity
}
else
{
logger.LogError($"Type definition in namespace '{namespaceEntity.FullName}' must have an ID or extends another type. {JsonSerializer.Serialize(typeDefinition)}");
logger.LogError("Type definition in namespace '{FullName}' must have an ID or extends another type. {TypeDefinition}", namespaceEntity.FullName, JsonSerializer.Serialize(typeDefinition));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void RegisterTypeEntitiesAsClassEntities()
{
if (!typeEntity.IsReferenced)
{
logger.LogWarning($"Skipped Type '{typeEntity.NamespaceQualifiedId}' because it is not referenced.");
logger.LogWarning("Skipped Type '{NamespaceQualifiedId}' because it is not referenced.", typeEntity.NamespaceQualifiedId);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class NamespaceEntityExtensions
{
public static string GetNamespaceQualifiedId(this NamespaceEntity namespaceEntity, string id)
{
if (string.IsNullOrEmpty(namespaceEntity.FullName) || id.Contains("."))
if (string.IsNullOrEmpty(namespaceEntity.FullName) || id.Contains('.'))
{
return id;
}
Expand Down
6 changes: 3 additions & 3 deletions src/WebExtensions.Net.Generator/FilesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public void CleanDirectory()
{
foreach (var directory in Directory.GetDirectories(options.RootDirectory))
{
logger.LogInformation($"Deleting directory {directory}");
logger.LogInformation("Deleting directory {Directory}", directory);
DeleteDirectory(directory);
}

foreach (var file in Directory.GetFiles(options.RootDirectory))
{
logger.LogInformation($"Deleting file {file}");
logger.LogInformation("Deleting file {File}", file);
DeleteFile(file);
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ private void CreateDirectoryIfNotExist(string directory)
{
if (!Directory.Exists(directory))
{
logger.LogInformation($"Creating directory {directory}");
logger.LogInformation("Creating directory {Directory}", directory);
Directory.CreateDirectory(directory);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task<IEnumerable<NamespaceDefinition>> GetNamespaceDefinitions(IEnu

private async Task<IEnumerable<NamespaceDefinition>> GetNamespaceDefinition(NamespaceSourceDefinition namespaceSourceDefinition)
{
logger.LogInformation($"Reading from URL {namespaceSourceDefinition.HttpUrl}");
logger.LogInformation("Reading from URL {HttpUrl}", namespaceSourceDefinition.HttpUrl);

IEnumerable<NamespaceDefinition>? namespaceDefinitionsResponse;
try
Expand All @@ -82,7 +82,7 @@ private async Task<IEnumerable<NamespaceDefinition>> GetNamespaceDefinition(Name
namespaceDefinition.Source = namespaceSourceDefinition;
}

logger.LogInformation($"Reading complete for URL {namespaceSourceDefinition.HttpUrl}");
logger.LogInformation("Reading complete for URL {HttpUrl}", namespaceSourceDefinition.HttpUrl);
return namespaceDefinitionsResponse;
}

Expand All @@ -94,7 +94,7 @@ private async Task<List<NamespaceSourceDefinition>> GetNamespaceSourceDefinition
var namespaceSourceDefinitionDictionary = await GetFromHttpWithRetry<IDictionary<string, NamespaceSourceDefinition>>(source.BaseUrl + source.FileName);
if (namespaceSourceDefinitionDictionary is null)
{
logger.LogError($"Failed to retrieve namespace source definitions from source url. Source url: '{source}'");
logger.LogError("Failed to retrieve namespace source definitions from source url. Source url: '{Source}'", source);
continue;
}

Expand All @@ -105,7 +105,7 @@ private async Task<List<NamespaceSourceDefinition>> GetNamespaceSourceDefinition

if (namespaceSourceDefinition.Schema is null)
{
logger.LogWarning($"Skipping source definition: Namespace definition schema url is null. Key: '{item.Key}'");
logger.LogWarning("Skipping source definition: Namespace definition schema url is null. Key: '{Key}'", item.Key);
continue;
}
var namespaceSource = sources.Single(s => namespaceSourceDefinition.Schema.StartsWith(s.SchemaBaseUrl));
Expand Down

0 comments on commit b2b575b

Please sign in to comment.