Skip to content

Commit e5c7e63

Browse files
authored
Merge pull request godotengine#7781 from raulsntos/dotnet/diagnostics
2 parents 730ed46 + 44029d1 commit e5c7e63

File tree

18 files changed

+839
-0
lines changed

18 files changed

+839
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
GD0001: Missing partial modifier on declaration of type which is a subclass of GodotObject
2+
==========================================================================================
3+
4+
==================================== ======================================
5+
Value
6+
==================================== ======================================
7+
**Rule ID** GD0001
8+
**Category** Usage
9+
**Fix is breaking or non-breaking** Non-breaking
10+
**Enabled by default** Yes
11+
==================================== ======================================
12+
13+
Cause
14+
-----
15+
16+
A type that derives from ``GodotObject`` is not declared partial.
17+
18+
Rule description
19+
----------------
20+
21+
Godot source generators add generated code to user-defined types to implement
22+
the integration with the engine. Source generators can't add generated code to
23+
types that aren't declared partial.
24+
25+
.. code-block:: csharp
26+
27+
// The source generators can't enhance this type to work with Godot.
28+
public class InvalidNode : Node { }
29+
30+
// The source generators can enhance this type to work with Godot.
31+
public partial class ValidNode { }
32+
33+
How to fix violations
34+
---------------------
35+
36+
To fix a violation of this rule, add the ``partial`` keyword to the type
37+
declaration.
38+
39+
When to suppress warnings
40+
-------------------------
41+
42+
Do not suppress a warning from this rule. Types that derive from ``GodotObject``
43+
but aren't partial can't be enhanced by the source generators, resulting in
44+
unexpected runtime errors.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
GD0002: Missing partial modifier on declaration of type which contains one or more subclasses of GodotObject
2+
============================================================================================================
3+
4+
==================================== ======================================
5+
Value
6+
==================================== ======================================
7+
**Rule ID** GD0002
8+
**Category** Usage
9+
**Fix is breaking or non-breaking** Non-breaking
10+
**Enabled by default** Yes
11+
==================================== ======================================
12+
13+
Cause
14+
-----
15+
16+
A type that derives from ``GodotObject`` is contained in a non-partial type declaration.
17+
18+
Rule description
19+
----------------
20+
21+
Godot source generators add generated code to user-defined types to implement
22+
the integration with the engine. Source generators can't add generated code to
23+
types that aren't declared partial.
24+
25+
.. code-block:: csharp
26+
27+
public class InvalidParentType
28+
{
29+
// MyNode is contained in a non-partial type so the source generators
30+
// can't enhance this type to work with Godot.
31+
public partial class MyNode : Node { }
32+
}
33+
34+
public partial class ValidParentType
35+
{
36+
// MyNode is contained in a partial type so the source generators
37+
// can enhance this type to work with Godot.
38+
public partial class MyNode : Node { }
39+
}
40+
41+
How to fix violations
42+
---------------------
43+
44+
To fix a violation of this rule, add the ``partial`` keyword to the type
45+
declaration.
46+
47+
When to suppress warnings
48+
-------------------------
49+
50+
Do not suppress a warning from this rule. Types that derive from ``GodotObject``
51+
but aren't partial can't be enhanced by the source generators, resulting in
52+
unexpected runtime errors.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
GD0101: Attempted to export static member
2+
=========================================
3+
4+
==================================== ======================================
5+
Value
6+
==================================== ======================================
7+
**Rule ID** GD0101
8+
**Category** Usage
9+
**Fix is breaking or non-breaking** Breaking - If the ``static`` keyword is removed
10+
11+
Non-breaking - If the ``[Export]`` attribute is removed
12+
**Enabled by default** Yes
13+
==================================== ======================================
14+
15+
Cause
16+
-----
17+
18+
A static member is annotated with the ``[Export]`` attribute. Static members
19+
can't be exported.
20+
21+
Rule description
22+
----------------
23+
24+
Godot doesn't allow exporting static members.
25+
26+
.. code-block:: csharp
27+
28+
// Static members can't be exported.
29+
[Export]
30+
public static int InvalidProperty { get; set; }
31+
32+
// Instance members can be exported.
33+
[Export]
34+
public int ValidProperty { get; set; }
35+
36+
How to fix violations
37+
---------------------
38+
39+
To fix a violation of this rule, remove the ``[Export]`` attribute or remove the
40+
``static`` keyword.
41+
42+
When to suppress warnings
43+
-------------------------
44+
45+
Do not suppress a warning from this rule. Static members can't be exported so
46+
they will be ignored by Godot, resulting in runtime errors.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
GD0102: The type of the exported member is not supported
2+
========================================================
3+
4+
==================================== ======================================
5+
Value
6+
==================================== ======================================
7+
**Rule ID** GD0102
8+
**Category** Usage
9+
**Fix is breaking or non-breaking** Breaking - If the member type is changed
10+
11+
Non-breaking - If the ``[Export]`` attribute is removed
12+
**Enabled by default** Yes
13+
==================================== ======================================
14+
15+
Cause
16+
-----
17+
18+
An unsupported type is specified for a member annotated with the ``[Export]``
19+
attribute when a :ref:`Variant-compatible <doc_c_sharp_variant>` type is expected.
20+
21+
Rule description
22+
----------------
23+
24+
Every exported member must be Variant-compatible so it can be marshalled by
25+
the engine.
26+
27+
.. code-block:: csharp
28+
29+
class SomeType { }
30+
31+
// SomeType is not a valid member type because it doesn't derive from GodotObject,
32+
// so it's not compatible with Variant.
33+
[Export]
34+
public SomeType InvalidProperty { get; set; }
35+
36+
// System.Int32 is a valid type because it's compatible with Variant.
37+
[Export]
38+
public int ValidProperty { get; set; }
39+
40+
How to fix violations
41+
---------------------
42+
43+
To fix a violation of this rule, change the member's type to be Variant-compatible
44+
or remove the ``[Export]`` attribute.
45+
46+
When to suppress warnings
47+
-------------------------
48+
49+
Do not suppress a warning from this rule. Members with types that can't be marshalled
50+
will result in runtime errors.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
GD0103: The exported member is read-only
2+
========================================
3+
4+
==================================== ======================================
5+
Value
6+
==================================== ======================================
7+
**Rule ID** GD0103
8+
**Category** Usage
9+
**Fix is breaking or non-breaking** Non-breaking
10+
**Enabled by default** Yes
11+
==================================== ======================================
12+
13+
Cause
14+
-----
15+
16+
A read-only member is annotated with the ``[Export]`` attribute. Read-only members
17+
can't be exported.
18+
19+
Rule description
20+
----------------
21+
22+
Godot doesn't allow exporting read-only members.
23+
24+
.. code-block:: csharp
25+
26+
// Read-only fields can't be exported.
27+
[Export]
28+
public readonly int invalidField;
29+
30+
// This field can be exported because it's not declared 'readonly'.
31+
[Export]
32+
public int validField;
33+
34+
// Read-only properties can't be exported.
35+
[Export]
36+
public int InvalidProperty { get; }
37+
38+
// This property can be exported because it has both a getter and a setter.
39+
[Export]
40+
public int ValidProperty { get; set; }
41+
42+
How to fix violations
43+
---------------------
44+
45+
To fix a violation of this rule for fields, remove the ``readonly`` keyword or
46+
remove the ``[Export]`` attribute.
47+
48+
To fix a violation of this rule for properties, make sure the property declares
49+
both a getter and a setter, or remove the ``[Export]`` attribute.
50+
51+
When to suppress warnings
52+
-------------------------
53+
54+
Do not suppress a warning from this rule. Read-only members can't be exported so
55+
they will be ignored by Godot, resulting in runtime errors.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
GD0104: The exported property is write-only
2+
===========================================
3+
4+
==================================== ======================================
5+
Value
6+
==================================== ======================================
7+
**Rule ID** GD0104
8+
**Category** Usage
9+
**Fix is breaking or non-breaking** Non-breaking
10+
**Enabled by default** Yes
11+
==================================== ======================================
12+
13+
Cause
14+
-----
15+
16+
A write-only property is annotated with the ``[Export]`` attribute. Write-only properties
17+
can't be exported.
18+
19+
Rule description
20+
----------------
21+
22+
Godot doesn't allow exporting write-only properties.
23+
24+
.. code-block:: csharp
25+
26+
private int _backingField;
27+
28+
// Write-only properties can't be exported.
29+
[Export]
30+
public int InvalidProperty { set => _backingField = value; }
31+
32+
// This property can be exported because it has both a getter and a setter.
33+
[Export]
34+
public int ValidProperty { get; set; }
35+
36+
How to fix violations
37+
---------------------
38+
39+
To fix a violation of this rule, make sure the property declares
40+
both a getter and a setter, or remove the ``[Export]`` attribute.
41+
42+
When to suppress warnings
43+
-------------------------
44+
45+
Do not suppress a warning from this rule. Write-only members can't be exported so
46+
they will be ignored by Godot, resulting in runtime errors.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
GD0105: Attempted to export indexer property
2+
============================================
3+
4+
==================================== ======================================
5+
Value
6+
==================================== ======================================
7+
**Rule ID** GD0105
8+
**Category** Usage
9+
**Fix is breaking or non-breaking** Non-breaking
10+
**Enabled by default** Yes
11+
==================================== ======================================
12+
13+
Cause
14+
-----
15+
16+
An indexer is annotated with the ``[Export]`` attribute. Indexers can't be exported.
17+
18+
Rule description
19+
----------------
20+
21+
Godot doesn't allow exporting indexer properties.
22+
23+
.. code-block:: csharp
24+
25+
private int[] _backingField;
26+
27+
// Indexers can't be exported.
28+
[Export]
29+
public int this[int index]
30+
{
31+
get => _backingField[index];
32+
set => _backingField[index] = value;
33+
}
34+
35+
How to fix violations
36+
---------------------
37+
38+
To fix a violation of this rule, remove the ``[Export]`` attribute.
39+
40+
When to suppress warnings
41+
-------------------------
42+
43+
Do not suppress a warning from this rule. Indexers can't be exported so
44+
they will be ignored by Godot, resulting in runtime errors.

0 commit comments

Comments
 (0)