1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-12 17:44:24 +02:00

Feature/update check icon pr py (#1406)

* add check for 'name' attribute

* add check for 'altnames' attribute

* add extra check for content of aliases field in devicon.json

* Change from single quotes to escaped double quotes

Apply suggestions from code review. Thanks @lunatic-fox

Co-authored-by: Josélio Júnior <76992016+lunatic-fox@users.noreply.github.com>

* Replace ' with \"

Apply suggestions from code review

Co-authored-by: David Leal <halfpacho@gmail.com>

---------

Co-authored-by: Josélio Júnior <76992016+lunatic-fox@users.noreply.github.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
Jørgen Kalsnes Hagen
2023-03-17 10:03:40 +01:00
committed by GitHub
parent 8534f898b1
commit 67c06f451f

View File

@@ -67,6 +67,24 @@ def check_devicon_object(icon: dict):
:return a string containing the error messages if any.
"""
err_msgs = []
try:
if type(icon["name"]) != str:
err_msgs.append("- Property \"name\" value must be type string.")
except KeyError:
err_msgs.append("- Missing property key: \"name\".")
try:
for altname in icon["altnames"]:
if type(altname) != str:
raise TypeError()
if altname == icon["name"]:
err_msgs.append(f"- \"altnames\" should not contain the same name as \"name\" property. Please remove \"{altname}\" from \"altnames\"")
except TypeError:
err_msgs.append("- \"altnames\" must be an array of strings, not: " + str(icon["altnames"]))
except KeyError:
err_msgs.append("- Missing property key: \"altnames\".")
try:
for tag in icon["tags"]:
if type(tag) != str:
@@ -110,12 +128,37 @@ def check_devicon_object(icon: dict):
try:
if type(icon["aliases"]) != list:
err_msgs.append("- 'aliases' must be an array.")
err_msgs.append("- \"aliases\" must be an array of objects.")
except KeyError:
err_msgs.append("- missing key: 'aliases'.")
try:
for alias_objects in icon["aliases"]:
if type(alias_objects) != dict:
raise TypeError()
except TypeError:
err_msgs.append("- \"aliases\" must be an array of objects, not: " + str(icon["aliases"]))
try:
for alias_objects in icon["aliases"]:
if type(alias_objects["base"]) != str:
err_msgs.append("- must contain at least 1 base in aliases.")
if not util.is_svg_version_valid(alias_objects['base']):
err_msgs.append(f"- Invalid base name in aliases[\"base\"]: \"{alias_objects['base']}\". Must match regexp: (original|plain|line)(-wordmark)?")
except KeyError:
err_msgs.append("- missing key: \"base\" in \"aliases\".")
try:
for alias_objects in icon["aliases"]:
if type(alias_objects["alias"]) != str:
err_msgs.append("- must contain at least 1 alias in aliases.")
if not util.is_svg_version_valid(alias_objects['alias']):
err_msgs.append(f"- Invalid alias name in aliases['alias']: \"{alias_objects['alias']}\". Must match regexp: (original|plain|line)(-wordmark)?")
except KeyError:
err_msgs.append("- missing key: \"alias\" in \"aliases\".")
if len(err_msgs) > 0:
message = "Error found in 'devicon.json' for '{}' entry: \n{}".format(icon["name"], "\n".join(err_msgs))
message = "Error found in \"devicon.json\" for \"{}\" entry: \n{}".format(icon["name"], "\n".join(err_msgs))
return message
return ""