Skip to content

Commit

Permalink
Fix CodeQL issues (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r committed Feb 26, 2023
1 parent 83927e6 commit 10564ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/PublicApiGenerator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PublicApiGenerator.Tool", "
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{FDD9792D-8E91-41C6-B42A-9E69831F61DF}"
ProjectSection(SolutionItems) = preProject
..\.github\codecov.yml = ..\.github\codecov.yml
..\.github\dependabot.yml = ..\.github\dependabot.yml
..\.github\labeler.yml = ..\.github\labeler.yml
EndProjectSection
Expand Down
18 changes: 8 additions & 10 deletions src/PublicApiGenerator/ApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,14 @@ bool IsSpecialConstraint(GenericParameterConstraint constraint)
PopulateAttributesThatDontAppearInCustomAttributes(type, attributes);
}

static void PopulateAttributesThatDontAppearInCustomAttributes(ICustomAttributeProvider type,
private static void PopulateAttributesThatDontAppearInCustomAttributes(ICustomAttributeProvider type,
CodeAttributeDeclarationCollection attributes)
{
if (type is TypeDefinition typeDefinition)
if (type is TypeDefinition typeDefinition && typeDefinition.Attributes.HasFlag(Mono.Cecil.TypeAttributes.Serializable))
{
if (typeDefinition.Attributes.HasFlag(Mono.Cecil.TypeAttributes.Serializable))
{
var attribute = new CodeAttributeDeclaration("System.SerializableAttribute");
attribute.Name = AttributeNameBuilder.Get(attribute.Name);
attributes.Add(attribute);
}
var attribute = new CodeAttributeDeclaration("System.SerializableAttribute");
attribute.Name = AttributeNameBuilder.Get(attribute.Name);
attributes.Add(attribute);
}
}

Expand Down Expand Up @@ -565,8 +562,9 @@ private static CodeExpression CreateInitialiserExpression(CustomAttributeArgumen
{
// CodeDOM outputs a verbatim string. Any string with \n is treated as such, so normalize
// it to make it easier for comparisons
value = Regex.Replace(s, @"\n", "\\n");
value = Regex.Replace(s, @"\r\n|\r\\n", "\\r\\n");
s = Regex.Replace(s, @"\n", "\\n");
s = Regex.Replace(s, @"\r\n|\r\\n", "\\r\\n");
value = s;
}

return new CodePrimitiveExpression(value);
Expand Down
7 changes: 3 additions & 4 deletions src/PublicApiGenerator/CodeTypeReferenceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ private static string GetTypeNameCore(TypeReference type, IEnumerator<bool?>? nu

if (type is ArrayType array)
{
if (nullable)
return CSharpTypeKeyword.Get(GetTypeName(array.ElementType, nullabilityMap, NullableMode.Default, disableNested)) + "[]";
else
return GetTypeName(array.ElementType, nullabilityMap, NullableMode.Default, disableNested) + "[]";
return nullable
? CSharpTypeKeyword.Get(GetTypeName(array.ElementType, nullabilityMap, NullableMode.Default, disableNested)) + "[]"
: GetTypeName(array.ElementType, nullabilityMap, NullableMode.Default, disableNested) + "[]";
}

if (type is PointerType pointer)
Expand Down

0 comments on commit 10564ed

Please sign in to comment.