Lint for prototype IDs with spaces (#6087)

* feat: lint for prototype IDs with spaces

* feat: also disallow periods

* Update RELEASE-NOTES.md

---------

Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
Perry Fraser
2025-07-22 06:16:57 -04:00
committed by GitHub
parent f2b7f0d8d2
commit 0fc9b0acd0
2 changed files with 13 additions and 0 deletions

View File

@@ -36,6 +36,7 @@ END TEMPLATE-->
### Breaking changes
* More members in `IntegrationInstance` now enforce that the instance is idle before accessing it.
* `Prototype.ValidateDirectory` now requires that prototype IDs have no spaces or periods in them.
* `IPrototypeManager.TryIndex` no longer logs errors unless using the overload with an optional parameter. Use `Resolve()` instead if error logging is desired.
### New features

View File

@@ -13,6 +13,11 @@ namespace Robust.Shared.Prototypes;
public partial class PrototypeManager
{
// Characters that we don't allow in prototype IDs. Spaces and periods both
// break generated localization strings for entity prototypes, so we just
// disallow them for all prototypes.
private static readonly char[] DisallowedIdChars = [' ', '.'];
public Dictionary<string, HashSet<ErrorNode>> ValidateDirectory(ResPath path) => ValidateDirectory(path, out _);
public Dictionary<string, HashSet<ErrorNode>> ValidateDirectory(ResPath path,
@@ -56,6 +61,13 @@ public partial class PrototypeManager
var data = new PrototypeValidationData(id, mapping, resourcePath.ToString());
mapping.Remove("type");
if (DisallowedIdChars.TryFirstOrNull(c => id.Contains(c), out var letter))
{
dict.GetOrNew(data.File)
.Add(new ErrorNode(mapping, $"Prototype '{id}' ({type}) contains disallowed "
+ $"character '{letter}'."));
}
if (prototypes.GetOrNew(type).TryAdd(id, data))
continue;