29 Commits

Author SHA1 Message Date
Tayrtahn
d7abbad717 Add validation for DirtyField strings (#5713)
* Add ValidateMemberAttribute, analyzer and test

* Use attribute on DirtyFields methods

* Defer member lookup

* Additional test case

* Add support for collection types

* Poke tests

* Revert "Add support for collection types"

This reverts commit 2b8f5534bd.

* break, not continue

* Cheaper attribute check with AttributeHelper

* Clean up unused helper method

---------

Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
2025-12-17 19:32:34 +01:00
Tayrtahn
c1737a540f Analyzer & Fixer for redundant Prototype type strings (#5718)
* Add Prototype analyzer

* Add Prototype fixer

* Early return after finding prototype attribute

* Add PrototypeEndsWithPrototypeRule diagnostic

* Oops. Uncomment parallelizable.

* Rework to ignore redundancy for non-literal string values

* Allow redundancy when removal would expose class name not ending in "Prototype"

* Promote PrototypeEndsWithPrototypeRule from warning to error, since it causes a runtime error.

* No need to get the symbol to get the class identifier

* Minor cleanup

* A little more cleanup

* More specific location for redundant name

* Refactor redundant name fixer so argument order is no longer important

* Add failing test

* Use symbol analysis to fix alias handling

* Oops! We have to go back to the previous syntax-based approach.

Now it's a hybrid.

Also fixed tests to not copy the prototype definitions.

---------

Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
2025-12-17 18:15:32 +01:00
PJB3005
ddfa12808c Fix some roslyn tests 2025-12-17 16:55:33 +01:00
PJB3005
788e9386fd Split up test project
Robust.UnitTesting was both ALL tests for RT, and also API surface for content tests.

Tests are now split into separate projects as appropriate, and the API side has also been split off.
2025-12-16 01:36:53 +01:00
Tayrtahn
e771530de2 Mark AutoGenerateComponentStateAttribute fields as readonly (redo) (#6129)
* Mark AutoGenerateComponentStateAttribute fields as readonly

* Remove no-longer-valid test case
2025-08-05 00:48:36 -04:00
Perry Fraser
1983734e2d feat: add analyzer for correct AfterAutoHandleStateEvent usage (#6117)
* feat: add analyzer for AfterAutoHandleStateEvent

* fix: correct TestOf attribute

Oopsieeeee.

Also weird newline plus unused import.

* Rerun content tests

* refactor: use ==, not .Contains

* feat: make AttributeHelper.HasAttribute looser

* refactor: use AttributeHelper.HasAttribute

* perf: cache AutoGenStateAttribute's type

* refactor: more pattern matching

ElementAtOrDefault with constant arg is bad; just use positional
matching.
2025-08-04 18:22:06 -04:00
Tayrtahn
63e383bb17 Fix NotYamlSerializable analyzer ignoring nullable structs (#5934)
Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
2025-08-02 19:25:48 +02:00
Łukasz Mędrek
7d9a039252 add: Dictionary<T, TimeSpan> OnUnpaused generator (#6119)
* add: Dictionary<T, TimeSpan> OnUnpaused generator

* fix

* add: test

* Fix compiler warning from duplicate using

---------

Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
2025-08-02 16:57:43 +02:00
Pieter-Jan Briers
c73b54862e Add analyzers to detect some prototype misuse (#6048)
* Add analyzers to detect some prototype misuse

Detects people marking prototype as NetSerializable.

Detects people creating new prototype instances themselves.

* Update Robust.Analyzers/PrototypeNetSerializableAnalyzer.cs

Co-authored-by: Tayrtahn <tayrtahn@gmail.com>

---------

Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
2025-06-26 22:24:23 +02:00
Tayrtahn
7765e71dca Add tests for remaining DataDefinitionAnalyzer diagnostics (#6034)
* Add tests for partial datadefs and partial nested datadefs

* Add test for redundant datafield tag

* Blank lines upset me
2025-06-20 02:26:08 +02:00
Tayrtahn
b3cf427013 Catch NotYamlSerializable DataFields with analyzer (#5704)
* Catch NotYamlSerializable DataFields with analyzer

* Extract common defs into shared source
2025-05-10 21:36:33 +10:00
Pieter-Jan Briers
72d893dec5 Add "obsolete inheritance" analyzer (#5858)
This allows us to make it obsolete to *inherit* from a class, and only that.

Intended so people stop inheriting UI controls for no good reason.

Fixes #5856
2025-04-19 17:29:17 +10:00
Tayrtahn
378a10678c Improve location reporting for non-writeable DataFields (#5715)
* Better location reporting for readonly DataField errors

* Better location reporting for readonly DataField property errors

* Use SyntaxKind instead of string for TryGetModifierLocation
2025-04-13 16:22:05 +10:00
Tayrtahn
45bb8740a0 Add ForbidLiteralAttribute and analyzer (#5808)
* Add ForbidLiteral attribute, analyzer, and test

* Removed unused code

* Switch order of methods. It's better this way.
2025-04-08 16:39:38 +02:00
PJB3005
c463fc5e78 Make source generators emit EditorBrowsable(Never)
This hides the generated types from intellisense if you have the relevant option in Rider enabled.

Good because honestly these just bloat IntelliSense, and if you want to show them there's an IDE setting for it.
2025-01-18 01:23:35 +01:00
PJB3005
67c44a5fc5 Add unit test for ByRefEventAnalyzer 2025-01-13 05:44:35 +01:00
Pieter-Jan Briers
dfc4894c8b Dependencies update & cleanup (#5590)
* Dependencies update & cleanup

Fixes security vuln warnings etc

* Remove ILReader dependency

RIP in piss FastAccessors.
2025-01-08 02:19:27 +01:00
Pieter-Jan Briers
f0ed3537ee Duplicate dependency field analyzer (#5463)
* Duplicate dependency field analyzer

Detects cases of duplicate [Dependency] fields in a type. We apparently have 27 of these across RT + SS14.

* Fix duplicate dependencies in Robust
2024-09-28 15:35:18 +10:00
Tayrtahn
9781405f5e Better location reporting for DataField analyzers (#5344)
* Better location reporting for DataField analyzers

* Update test

* Use const string in both methods
2024-08-13 11:40:23 +02:00
Tayrtahn
b6548c870c Add analyzer/fixer for replacing ProtoId<EntityPrototype> with EntProtoId (#5312)
* Add PreferOtherTypeAttribute, analyzer, and test.

* nullable enable

* Add nuget package for CodeFix verifier

* Add fixer for PreferOtherType

* Rename arguments

* Adjust diagnostic message

* Move attribute lookup
2024-07-23 19:01:43 +02:00
Tayrtahn
c3d8080a8e Add PreferNonGenericVariantFor attribute and analyzer (#5190)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2024-07-10 12:33:56 +02:00
Tayrtahn
8e50924607 Add analyzer/fixer for DataFields with ReadWrite VV (#5164)
* Add analyzer/fixer for datafields with ReadWrite VV

* Nothing to see here
2024-07-10 02:04:55 +02:00
Pieter-Jan Briers
75b3431ee6 New "must call base" analyzer. (#5266)
* New "must call base" analyzer.

This enforces that you actually call base when overriding stuff. This is intended for base methods like entity system's, where server/client systems overriding shared ones SHOULD call Initialize() and such.

* Add MustCallBase to entity system methods
2024-06-28 14:44:49 +10:00
Pieter-Jan Briers
4d528dd577 Analyzer to ban uncached regexes (#5107)
Using static Regex functions that take in a pattern is bad, because they constantly have to be re-parsed. Cache the Regex instance.
2024-05-06 10:30:31 +10:00
Pieter-Jan Briers
b50f68866f Enable roslyn extension tests in CI (#5038)
* Enable roslyn extension tests in CI

* I'll be real I kinda just hoped that last one would work. dotnet test's --help documentation is useless garbage so I couldn't tell if that was supported or not. Guess not.

* Actually fix the Roslyn tests.

As far as I can tell, Roslyn tests haven't worked since #2976.

The tests used a pretty awful technique of linking the test code against the analyzer, so that the analyzer's copy of the relevant attributes got included into the test. This then broke when the namespace got changed by the linked PR.

Now the tests get an EmbeddedResource for the necessary test files compiled instead.

Also applied this to DependencyAssignAnalyzerTest because why not.
2024-04-14 09:26:07 +02:00
Pieter-Jan Briers
cd67c67a5c Add analyzer to warn for assignment to dependency fields. 2024-04-14 05:14:12 +02:00
Pieter-Jan Briers
ae6cebbfbb Source gen reorganizations + component unpause generator. (#4896)
* Source gen reorganizations + component unpause generator.

This commit (and subsequent commits) aims to clean up our Roslyn plugin (source gens + analyzers) stack to more sanely re-use common code

I also built a new source-gen that automatically generates unpausing implementations for components, incrementing attributed TimeSpan field when unpaused.

* Fix warnings in all Roslyn projects
2024-02-20 10:15:32 +01:00
Pieter-Jan Briers
0094040d68 Dependency update / fixes / skrungle bungle (#4825)
* Move to Central Package Management.

Allows us to store NuGet package versions all in one place. Yay!

* Update NuGet packages and fix code for changes.

Notable:

Changes to ILVerify.
Npgsql doesn't need hacks for inet anymore, now we need hacks to make the old code work with this new reality.
NUnit's analyzers are already complaining and I didn't even update it to 4.x yet.
TerraFX changed to GetLastSystemError so error handling had to be changed.
Buncha APIs have more NRT annotations.

* Remove dotnet-eng NuGet package source.

I genuinely don't know what this was for, and Central Package Management starts throwing warnings about it, so YEET.

* Fix double loading of assemblies due to ALC shenanigans.

Due to how the "sideloading" code for the ModLoader was set up, it would first try to load Microsoft.Extensions.Primitives from next to the content dll. But we already have that library in Robust!

Chaos ensues.

We now try to forcibly prioritize loading from the default ALC first to avoid this.

* Remove Robust.Physics project.

Never used.

* Remove erroneous NVorbis reference.

Should be VorbisPizza and otherwise wasn't used.

* Sandbox fixes

* Remove unused unit test package references.

Castle.Core and NUnit.ConsoleRunner.

* Update NUnit to 4.0.1

This requires replacing all the old assertion methods because they removed them 🥲

* Mute CA1416 (platform check) errors

TerraFX started annotating APIs with this and I can't be arsed to entertain this analyzer so out it goes.

* Fine ya cranky, no more CPM for Robust.Client.Injectors

* Changelog

* Oh so that's what dotnet-eng was used for. Yeah ok that makes sense.

* Central package management for remaining 2 robust projects

* Ok that was a bad idea let's just use NUnit 3 on the analyzer test project

* Oh right forgot to remove this one

* Update to a newer version of RemoteExecutor

* Disable RemoteExecutor test

https://github.com/dotnet/arcade/issues/8483 Yeah this package is not well maintained and clearly we can't rely on it.

* Fix immutable list serialization
2024-01-12 22:59:52 +01:00
Pieter-Jan Briers
1ea18b9448 Move analyzer tests over to separate project.
Safe to say the build system and Rider do not like the double-project-reference shenanigans going on in Robust.UnitTesting.
2022-06-12 12:35:57 +02:00