]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add warnings when TagSystem methods are called with string literals (#36281)
authorTayrtahn <tayrtahn@gmail.com>
Sat, 12 Apr 2025 14:18:31 +0000 (10:18 -0400)
committerGitHub <noreply@github.com>
Sat, 12 Apr 2025 14:18:31 +0000 (16:18 +0200)
Apply ForbidLiteralAttribute to all appropriate TagSystem methods

Content.Shared/Tag/TagSystem.cs

index f1f620a69494e0eee9bbf6a0e51592814efc1430..b75e2a4af1016c953c7555c2ecf6a7c80331ac94 100644 (file)
@@ -50,7 +50,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if no <see cref="TagPrototype"/> exists with the given id.
     /// </exception>
-    public bool AddTag(EntityUid entityUid, ProtoId<TagPrototype> tag)
+    public bool AddTag(EntityUid entityUid, [ForbidLiteral] ProtoId<TagPrototype> tag)
     {
         return AddTag((entityUid, EnsureComp<TagComponent>(entityUid)), tag);
     }
@@ -64,9 +64,9 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool AddTags(EntityUid entityUid, params ProtoId<TagPrototype>[] tags)
+    public bool AddTags(EntityUid entityUid, [ForbidLiteral] params ProtoId<TagPrototype>[] tags)
     {
-        return AddTags(entityUid,  (IEnumerable<ProtoId<TagPrototype>>)tags);
+        return AddTags(entityUid, (IEnumerable<ProtoId<TagPrototype>>)tags);
     }
 
     /// <summary>
@@ -78,7 +78,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool AddTags(EntityUid entityUid, IEnumerable<ProtoId<TagPrototype>> tags)
+    public bool AddTags(EntityUid entityUid, [ForbidLiteral] IEnumerable<ProtoId<TagPrototype>> tags)
     {
         return AddTags((entityUid, EnsureComp<TagComponent>(entityUid)), tags);
     }
@@ -93,7 +93,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if no <see cref="TagPrototype"/> exists with the given id.
     /// </exception>
-    public bool TryAddTag(EntityUid entityUid, ProtoId<TagPrototype> tag)
+    public bool TryAddTag(EntityUid entityUid, [ForbidLiteral] ProtoId<TagPrototype> tag)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                AddTag((entityUid, component), tag);
@@ -109,7 +109,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool TryAddTags(EntityUid entityUid, params ProtoId<TagPrototype>[] tags)
+    public bool TryAddTags(EntityUid entityUid, [ForbidLiteral] params ProtoId<TagPrototype>[] tags)
     {
         return TryAddTags(entityUid, (IEnumerable<ProtoId<TagPrototype>>)tags);
     }
@@ -124,7 +124,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool TryAddTags(EntityUid entityUid, IEnumerable<ProtoId<TagPrototype>> tags)
+    public bool TryAddTags(EntityUid entityUid, [ForbidLiteral] IEnumerable<ProtoId<TagPrototype>> tags)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                AddTags((entityUid, component), tags);
@@ -139,7 +139,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if no <see cref="TagPrototype"/> exists with the given id.
     /// </exception>
-    public bool HasTag(EntityUid entityUid, ProtoId<TagPrototype> tag)
+    public bool HasTag(EntityUid entityUid, [ForbidLiteral] ProtoId<TagPrototype> tag)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                HasTag(component, tag);
@@ -166,7 +166,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAllTags(EntityUid entityUid, params ProtoId<TagPrototype>[] tags)
+    public bool HasAllTags(EntityUid entityUid, [ForbidLiteral] params ProtoId<TagPrototype>[] tags)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                HasAllTags(component, tags);
@@ -181,7 +181,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAllTags(EntityUid entityUid, HashSet<ProtoId<TagPrototype>> tags)
+    public bool HasAllTags(EntityUid entityUid, [ForbidLiteral] HashSet<ProtoId<TagPrototype>> tags)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                HasAllTags(component, tags);
@@ -196,7 +196,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAllTags(EntityUid entityUid, List<ProtoId<TagPrototype>> tags)
+    public bool HasAllTags(EntityUid entityUid, [ForbidLiteral] List<ProtoId<TagPrototype>> tags)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                HasAllTags(component, tags);
@@ -211,7 +211,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAllTags(EntityUid entityUid, IEnumerable<ProtoId<TagPrototype>> tags)
+    public bool HasAllTags(EntityUid entityUid, [ForbidLiteral] IEnumerable<ProtoId<TagPrototype>> tags)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                HasAllTags(component, tags);
@@ -226,7 +226,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if no <see cref="TagPrototype"/> exists with the given id.
     /// </exception>
-    public bool HasAnyTag(EntityUid entityUid, ProtoId<TagPrototype> tag) =>
+    public bool HasAnyTag(EntityUid entityUid, [ForbidLiteral] ProtoId<TagPrototype> tag) =>
         HasTag(entityUid, tag);
 
     /// <summary>
@@ -238,7 +238,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAnyTag(EntityUid entityUid, params ProtoId<TagPrototype>[] tags)
+    public bool HasAnyTag(EntityUid entityUid, [ForbidLiteral] params ProtoId<TagPrototype>[] tags)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                HasAnyTag(component, tags);
@@ -253,7 +253,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAnyTag(EntityUid entityUid, HashSet<ProtoId<TagPrototype>> tags)
+    public bool HasAnyTag(EntityUid entityUid, [ForbidLiteral] HashSet<ProtoId<TagPrototype>> tags)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                HasAnyTag(component, tags);
@@ -268,7 +268,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAnyTag(EntityUid entityUid, List<ProtoId<TagPrototype>> tags)
+    public bool HasAnyTag(EntityUid entityUid, [ForbidLiteral] List<ProtoId<TagPrototype>> tags)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                HasAnyTag(component, tags);
@@ -283,7 +283,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAnyTag(EntityUid entityUid, IEnumerable<ProtoId<TagPrototype>> tags)
+    public bool HasAnyTag(EntityUid entityUid, [ForbidLiteral] IEnumerable<ProtoId<TagPrototype>> tags)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                HasAnyTag(component, tags);
@@ -298,7 +298,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if no <see cref="TagPrototype"/> exists with the given id.
     /// </exception>
-    public bool HasTag(TagComponent component, ProtoId<TagPrototype> tag)
+    public bool HasTag(TagComponent component, [ForbidLiteral] ProtoId<TagPrototype> tag)
     {
 #if DEBUG
         AssertValidTag(tag);
@@ -315,7 +315,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if no <see cref="TagPrototype"/> exists with the given id.
     /// </exception>
-    public bool HasAllTags(TagComponent component, ProtoId<TagPrototype> tag) =>
+    public bool HasAllTags(TagComponent component, [ForbidLiteral] ProtoId<TagPrototype> tag) =>
         HasTag(component, tag);
 
     /// <summary>
@@ -327,7 +327,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAllTags(TagComponent component, params ProtoId<TagPrototype>[] tags)
+    public bool HasAllTags(TagComponent component, [ForbidLiteral] params ProtoId<TagPrototype>[] tags)
     {
         foreach (var tag in tags)
         {
@@ -350,7 +350,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAllTagsArray(TagComponent component, ProtoId<TagPrototype>[] tags)
+    public bool HasAllTagsArray(TagComponent component, [ForbidLiteral] ProtoId<TagPrototype>[] tags)
     {
         foreach (var tag in tags)
         {
@@ -373,7 +373,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAllTags(TagComponent component, List<ProtoId<TagPrototype>> tags)
+    public bool HasAllTags(TagComponent component, [ForbidLiteral] List<ProtoId<TagPrototype>> tags)
     {
         foreach (var tag in tags)
         {
@@ -396,7 +396,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAllTags(TagComponent component, HashSet<ProtoId<TagPrototype>> tags)
+    public bool HasAllTags(TagComponent component, [ForbidLiteral] HashSet<ProtoId<TagPrototype>> tags)
     {
         foreach (var tag in tags)
         {
@@ -419,7 +419,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAllTags(TagComponent component, IEnumerable<ProtoId<TagPrototype>> tags)
+    public bool HasAllTags(TagComponent component, [ForbidLiteral] IEnumerable<ProtoId<TagPrototype>> tags)
     {
         foreach (var tag in tags)
         {
@@ -442,7 +442,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if no <see cref="TagPrototype"/> exists with the given id.
     /// </exception>
-    public bool HasAnyTag(TagComponent component, ProtoId<TagPrototype> tag) =>
+    public bool HasAnyTag(TagComponent component, [ForbidLiteral] ProtoId<TagPrototype> tag) =>
         HasTag(component, tag);
 
     /// <summary>
@@ -454,7 +454,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAnyTag(TagComponent component, params ProtoId<TagPrototype>[] tags)
+    public bool HasAnyTag(TagComponent component, [ForbidLiteral] params ProtoId<TagPrototype>[] tags)
     {
         foreach (var tag in tags)
         {
@@ -477,7 +477,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAnyTag(TagComponent component, HashSet<ProtoId<TagPrototype>> tags)
+    public bool HasAnyTag(TagComponent component, [ForbidLiteral] HashSet<ProtoId<TagPrototype>> tags)
     {
         foreach (var tag in tags)
         {
@@ -500,7 +500,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAnyTag(TagComponent component, List<ProtoId<TagPrototype>> tags)
+    public bool HasAnyTag(TagComponent component, [ForbidLiteral] List<ProtoId<TagPrototype>> tags)
     {
         foreach (var tag in tags)
         {
@@ -523,7 +523,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAnyTag(TagComponent component, IEnumerable<ProtoId<TagPrototype>> tags)
+    public bool HasAnyTag(TagComponent component, [ForbidLiteral] IEnumerable<ProtoId<TagPrototype>> tags)
     {
         foreach (var tag in tags)
         {
@@ -546,7 +546,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if no <see cref="TagPrototype"/> exists with the given id.
     /// </exception>
-    public bool RemoveTag(EntityUid entityUid, ProtoId<TagPrototype> tag)
+    public bool RemoveTag(EntityUid entityUid, [ForbidLiteral] ProtoId<TagPrototype> tag)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                RemoveTag((entityUid, component), tag);
@@ -561,7 +561,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool RemoveTags(EntityUid entityUid, params ProtoId<TagPrototype>[] tags)
+    public bool RemoveTags(EntityUid entityUid, [ForbidLiteral] params ProtoId<TagPrototype>[] tags)
     {
         return RemoveTags(entityUid, (IEnumerable<ProtoId<TagPrototype>>)tags);
     }
@@ -575,7 +575,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool RemoveTags(EntityUid entityUid, IEnumerable<ProtoId<TagPrototype>> tags)
+    public bool RemoveTags(EntityUid entityUid, [ForbidLiteral] IEnumerable<ProtoId<TagPrototype>> tags)
     {
         return _tagQuery.TryComp(entityUid, out var component) &&
                RemoveTags((entityUid, component), tags);
@@ -590,7 +590,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if no <see cref="TagPrototype"/> exists with the given id.
     /// </exception>
-    public bool AddTag(Entity<TagComponent> entity, ProtoId<TagPrototype> tag)
+    public bool AddTag(Entity<TagComponent> entity, [ForbidLiteral] ProtoId<TagPrototype> tag)
     {
 #if DEBUG
         AssertValidTag(tag);
@@ -611,7 +611,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool AddTags(Entity<TagComponent> entity, params ProtoId<TagPrototype>[] tags)
+    public bool AddTags(Entity<TagComponent> entity, [ForbidLiteral] params ProtoId<TagPrototype>[] tags)
     {
         return AddTags(entity, (IEnumerable<ProtoId<TagPrototype>>)tags);
     }
@@ -625,7 +625,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool AddTags(Entity<TagComponent> entity, IEnumerable<ProtoId<TagPrototype>> tags)
+    public bool AddTags(Entity<TagComponent> entity, [ForbidLiteral] IEnumerable<ProtoId<TagPrototype>> tags)
     {
         var update = false;
         foreach (var tag in tags)
@@ -653,7 +653,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if no <see cref="TagPrototype"/> exists with the given id.
     /// </exception>
-    public bool RemoveTag(Entity<TagComponent> entity, ProtoId<TagPrototype> tag)
+    public bool RemoveTag(Entity<TagComponent> entity, [ForbidLiteral] ProtoId<TagPrototype> tag)
     {
 #if DEBUG
         AssertValidTag(tag);
@@ -675,7 +675,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool RemoveTags(Entity<TagComponent> entity, params ProtoId<TagPrototype>[] tags)
+    public bool RemoveTags(Entity<TagComponent> entity, [ForbidLiteral] params ProtoId<TagPrototype>[] tags)
     {
         return RemoveTags(entity, (IEnumerable<ProtoId<TagPrototype>>)tags);
     }
@@ -689,7 +689,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     /// Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool RemoveTags(Entity<TagComponent> entity, IEnumerable<ProtoId<TagPrototype>> tags)
+    public bool RemoveTags(Entity<TagComponent> entity, [ForbidLiteral] IEnumerable<ProtoId<TagPrototype>> tags)
     {
         var update = false;
         foreach (var tag in tags)