From 76e72893c932b55beb82081bc1effae4095a7547 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Sat, 12 Apr 2025 10:18:31 -0400 Subject: [PATCH] Add warnings when TagSystem methods are called with string literals (#36281) Apply ForbidLiteralAttribute to all appropriate TagSystem methods --- Content.Shared/Tag/TagSystem.cs | 76 ++++++++++++++++----------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/Content.Shared/Tag/TagSystem.cs b/Content.Shared/Tag/TagSystem.cs index f1f620a694..b75e2a4af1 100644 --- a/Content.Shared/Tag/TagSystem.cs +++ b/Content.Shared/Tag/TagSystem.cs @@ -50,7 +50,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if no exists with the given id. /// - public bool AddTag(EntityUid entityUid, ProtoId tag) + public bool AddTag(EntityUid entityUid, [ForbidLiteral] ProtoId tag) { return AddTag((entityUid, EnsureComp(entityUid)), tag); } @@ -64,9 +64,9 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool AddTags(EntityUid entityUid, params ProtoId[] tags) + public bool AddTags(EntityUid entityUid, [ForbidLiteral] params ProtoId[] tags) { - return AddTags(entityUid, (IEnumerable>)tags); + return AddTags(entityUid, (IEnumerable>)tags); } /// @@ -78,7 +78,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool AddTags(EntityUid entityUid, IEnumerable> tags) + public bool AddTags(EntityUid entityUid, [ForbidLiteral] IEnumerable> tags) { return AddTags((entityUid, EnsureComp(entityUid)), tags); } @@ -93,7 +93,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if no exists with the given id. /// - public bool TryAddTag(EntityUid entityUid, ProtoId tag) + public bool TryAddTag(EntityUid entityUid, [ForbidLiteral] ProtoId tag) { return _tagQuery.TryComp(entityUid, out var component) && AddTag((entityUid, component), tag); @@ -109,7 +109,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool TryAddTags(EntityUid entityUid, params ProtoId[] tags) + public bool TryAddTags(EntityUid entityUid, [ForbidLiteral] params ProtoId[] tags) { return TryAddTags(entityUid, (IEnumerable>)tags); } @@ -124,7 +124,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool TryAddTags(EntityUid entityUid, IEnumerable> tags) + public bool TryAddTags(EntityUid entityUid, [ForbidLiteral] IEnumerable> tags) { return _tagQuery.TryComp(entityUid, out var component) && AddTags((entityUid, component), tags); @@ -139,7 +139,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if no exists with the given id. /// - public bool HasTag(EntityUid entityUid, ProtoId tag) + public bool HasTag(EntityUid entityUid, [ForbidLiteral] ProtoId tag) { return _tagQuery.TryComp(entityUid, out var component) && HasTag(component, tag); @@ -166,7 +166,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAllTags(EntityUid entityUid, params ProtoId[] tags) + public bool HasAllTags(EntityUid entityUid, [ForbidLiteral] params ProtoId[] tags) { return _tagQuery.TryComp(entityUid, out var component) && HasAllTags(component, tags); @@ -181,7 +181,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAllTags(EntityUid entityUid, HashSet> tags) + public bool HasAllTags(EntityUid entityUid, [ForbidLiteral] HashSet> tags) { return _tagQuery.TryComp(entityUid, out var component) && HasAllTags(component, tags); @@ -196,7 +196,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAllTags(EntityUid entityUid, List> tags) + public bool HasAllTags(EntityUid entityUid, [ForbidLiteral] List> tags) { return _tagQuery.TryComp(entityUid, out var component) && HasAllTags(component, tags); @@ -211,7 +211,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAllTags(EntityUid entityUid, IEnumerable> tags) + public bool HasAllTags(EntityUid entityUid, [ForbidLiteral] IEnumerable> tags) { return _tagQuery.TryComp(entityUid, out var component) && HasAllTags(component, tags); @@ -226,7 +226,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if no exists with the given id. /// - public bool HasAnyTag(EntityUid entityUid, ProtoId tag) => + public bool HasAnyTag(EntityUid entityUid, [ForbidLiteral] ProtoId tag) => HasTag(entityUid, tag); /// @@ -238,7 +238,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAnyTag(EntityUid entityUid, params ProtoId[] tags) + public bool HasAnyTag(EntityUid entityUid, [ForbidLiteral] params ProtoId[] tags) { return _tagQuery.TryComp(entityUid, out var component) && HasAnyTag(component, tags); @@ -253,7 +253,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAnyTag(EntityUid entityUid, HashSet> tags) + public bool HasAnyTag(EntityUid entityUid, [ForbidLiteral] HashSet> tags) { return _tagQuery.TryComp(entityUid, out var component) && HasAnyTag(component, tags); @@ -268,7 +268,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAnyTag(EntityUid entityUid, List> tags) + public bool HasAnyTag(EntityUid entityUid, [ForbidLiteral] List> tags) { return _tagQuery.TryComp(entityUid, out var component) && HasAnyTag(component, tags); @@ -283,7 +283,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAnyTag(EntityUid entityUid, IEnumerable> tags) + public bool HasAnyTag(EntityUid entityUid, [ForbidLiteral] IEnumerable> tags) { return _tagQuery.TryComp(entityUid, out var component) && HasAnyTag(component, tags); @@ -298,7 +298,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if no exists with the given id. /// - public bool HasTag(TagComponent component, ProtoId tag) + public bool HasTag(TagComponent component, [ForbidLiteral] ProtoId tag) { #if DEBUG AssertValidTag(tag); @@ -315,7 +315,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if no exists with the given id. /// - public bool HasAllTags(TagComponent component, ProtoId tag) => + public bool HasAllTags(TagComponent component, [ForbidLiteral] ProtoId tag) => HasTag(component, tag); /// @@ -327,7 +327,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAllTags(TagComponent component, params ProtoId[] tags) + public bool HasAllTags(TagComponent component, [ForbidLiteral] params ProtoId[] tags) { foreach (var tag in tags) { @@ -350,7 +350,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAllTagsArray(TagComponent component, ProtoId[] tags) + public bool HasAllTagsArray(TagComponent component, [ForbidLiteral] ProtoId[] tags) { foreach (var tag in tags) { @@ -373,7 +373,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAllTags(TagComponent component, List> tags) + public bool HasAllTags(TagComponent component, [ForbidLiteral] List> tags) { foreach (var tag in tags) { @@ -396,7 +396,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAllTags(TagComponent component, HashSet> tags) + public bool HasAllTags(TagComponent component, [ForbidLiteral] HashSet> tags) { foreach (var tag in tags) { @@ -419,7 +419,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAllTags(TagComponent component, IEnumerable> tags) + public bool HasAllTags(TagComponent component, [ForbidLiteral] IEnumerable> tags) { foreach (var tag in tags) { @@ -442,7 +442,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if no exists with the given id. /// - public bool HasAnyTag(TagComponent component, ProtoId tag) => + public bool HasAnyTag(TagComponent component, [ForbidLiteral] ProtoId tag) => HasTag(component, tag); /// @@ -454,7 +454,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAnyTag(TagComponent component, params ProtoId[] tags) + public bool HasAnyTag(TagComponent component, [ForbidLiteral] params ProtoId[] tags) { foreach (var tag in tags) { @@ -477,7 +477,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAnyTag(TagComponent component, HashSet> tags) + public bool HasAnyTag(TagComponent component, [ForbidLiteral] HashSet> tags) { foreach (var tag in tags) { @@ -500,7 +500,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAnyTag(TagComponent component, List> tags) + public bool HasAnyTag(TagComponent component, [ForbidLiteral] List> tags) { foreach (var tag in tags) { @@ -523,7 +523,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool HasAnyTag(TagComponent component, IEnumerable> tags) + public bool HasAnyTag(TagComponent component, [ForbidLiteral] IEnumerable> tags) { foreach (var tag in tags) { @@ -546,7 +546,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if no exists with the given id. /// - public bool RemoveTag(EntityUid entityUid, ProtoId tag) + public bool RemoveTag(EntityUid entityUid, [ForbidLiteral] ProtoId tag) { return _tagQuery.TryComp(entityUid, out var component) && RemoveTag((entityUid, component), tag); @@ -561,7 +561,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool RemoveTags(EntityUid entityUid, params ProtoId[] tags) + public bool RemoveTags(EntityUid entityUid, [ForbidLiteral] params ProtoId[] tags) { return RemoveTags(entityUid, (IEnumerable>)tags); } @@ -575,7 +575,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool RemoveTags(EntityUid entityUid, IEnumerable> tags) + public bool RemoveTags(EntityUid entityUid, [ForbidLiteral] IEnumerable> tags) { return _tagQuery.TryComp(entityUid, out var component) && RemoveTags((entityUid, component), tags); @@ -590,7 +590,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if no exists with the given id. /// - public bool AddTag(Entity entity, ProtoId tag) + public bool AddTag(Entity entity, [ForbidLiteral] ProtoId tag) { #if DEBUG AssertValidTag(tag); @@ -611,7 +611,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool AddTags(Entity entity, params ProtoId[] tags) + public bool AddTags(Entity entity, [ForbidLiteral] params ProtoId[] tags) { return AddTags(entity, (IEnumerable>)tags); } @@ -625,7 +625,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool AddTags(Entity entity, IEnumerable> tags) + public bool AddTags(Entity entity, [ForbidLiteral] IEnumerable> tags) { var update = false; foreach (var tag in tags) @@ -653,7 +653,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if no exists with the given id. /// - public bool RemoveTag(Entity entity, ProtoId tag) + public bool RemoveTag(Entity entity, [ForbidLiteral] ProtoId tag) { #if DEBUG AssertValidTag(tag); @@ -675,7 +675,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool RemoveTags(Entity entity, params ProtoId[] tags) + public bool RemoveTags(Entity entity, [ForbidLiteral] params ProtoId[] tags) { return RemoveTags(entity, (IEnumerable>)tags); } @@ -689,7 +689,7 @@ public sealed class TagSystem : EntitySystem /// /// Thrown if one of the ids represents an unregistered . /// - public bool RemoveTags(Entity entity, IEnumerable> tags) + public bool RemoveTags(Entity entity, [ForbidLiteral] IEnumerable> tags) { var update = false; foreach (var tag in tags)