Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tutorials/scripting/c_sharp/diagnostics/GD0001.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
GD0001: Missing partial modifier on declaration of type which is a subclass of GodotObject
==========================================================================================

==================================== ======================================
Value
==================================== ======================================
**Rule ID** GD0001
**Category** Usage
**Fix is breaking or non-breaking** Non-breaking
**Enabled by default** Yes
==================================== ======================================

Cause
-----

A type that derives from ``GodotObject`` is not declared partial.

Rule description
----------------

Godot source generators add generated code to user-defined types to implement
the integration with the engine. Source generators can't add generated code to
types that aren't declared partial.

.. code-block:: csharp

// The source generators can't enhance this type to work with Godot.
public class InvalidNode : Node { }

// The source generators can enhance this type to work with Godot.
public partial class ValidNode { }

How to fix violations
---------------------

To fix a violation of this rule, add the ``partial`` keyword to the type
declaration.

When to suppress warnings
-------------------------

Do not suppress a warning from this rule. Types that derive from ``GodotObject``
but aren't partial can't be enhanced by the source generators, resulting in
unexpected runtime errors.
52 changes: 52 additions & 0 deletions tutorials/scripting/c_sharp/diagnostics/GD0002.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
GD0002: Missing partial modifier on declaration of type which contains one or more subclasses of GodotObject
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GD0002: Missing partial modifier on declaration of type which contains one or more subclasses of GodotObject
GD0002: Missing partial modifier on declaration of type which contains one or more subclass of GodotObject

(I think) But this is probably because the actual diagnostic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I just copied the diagnostic title, we could change it. I think I would use nested classes rather than subclasses here, what do you think? But I think it has to be plural because of the one or more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just looked wrong to me, with some more thought, both versions are probably fine, but if we want to change it I would also go to a different wording like contains nested classes that are derived from GodotObject

Copy link
Member Author

@raulsntos raulsntos Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that wording. This change needs to be done in the main repository as well, is there any other diagnostic that you think could be worded better? It'd be nice to make all the changes in a single PR while we're at it.

WIP: raulsntos/godot@79622bb

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

============================================================================================================

==================================== ======================================
Value
==================================== ======================================
**Rule ID** GD0002
**Category** Usage
**Fix is breaking or non-breaking** Non-breaking
**Enabled by default** Yes
==================================== ======================================

Cause
-----

A type that derives from ``GodotObject`` is contained in a non-partial type declaration.

Rule description
----------------

Godot source generators add generated code to user-defined types to implement
the integration with the engine. Source generators can't add generated code to
types that aren't declared partial.

.. code-block:: csharp

public class InvalidParentType
{
// MyNode is contained in a non-partial type so the source generators
// can't enhance this type to work with Godot.
public partial class MyNode : Node { }
}

public partial class ValidParentType
{
// MyNode is contained in a partial type so the source generators
// can enhance this type to work with Godot.
public partial class MyNode : Node { }
}

How to fix violations
---------------------

To fix a violation of this rule, add the ``partial`` keyword to the type
declaration.

When to suppress warnings
-------------------------

Do not suppress a warning from this rule. Types that derive from ``GodotObject``
but aren't partial can't be enhanced by the source generators, resulting in
unexpected runtime errors.
46 changes: 46 additions & 0 deletions tutorials/scripting/c_sharp/diagnostics/GD0101.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
GD0101: Attempted to export static member
=========================================

==================================== ======================================
Value
==================================== ======================================
**Rule ID** GD0101
**Category** Usage
**Fix is breaking or non-breaking** Breaking - If the ``static`` keyword is removed

Non-breaking - If the ``[Export]`` attribute is removed
**Enabled by default** Yes
==================================== ======================================

Cause
-----

A static member is annotated with the ``[Export]`` attribute. Static members
can't be exported.

Rule description
----------------

Godot doesn't allow exporting static members.

.. code-block:: csharp

// Static members can't be exported.
[Export]
public static int InvalidProperty { get; set; }

// Instance members can be exported.
[Export]
public int ValidProperty { get; set; }

How to fix violations
---------------------

To fix a violation of this rule, remove the ``[Export]`` attribute or remove the
``static`` keyword.

When to suppress warnings
-------------------------

Do not suppress a warning from this rule. Static members can't be exported so
they will be ignored by Godot, resulting in runtime errors.
50 changes: 50 additions & 0 deletions tutorials/scripting/c_sharp/diagnostics/GD0102.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
GD0102: The type of the exported member is not supported
========================================================

==================================== ======================================
Value
==================================== ======================================
**Rule ID** GD0102
**Category** Usage
**Fix is breaking or non-breaking** Breaking - If the member type is changed

Non-breaking - If the ``[Export]`` attribute is removed
**Enabled by default** Yes
==================================== ======================================

Cause
-----

An unsupported type is specified for a member annotated with the ``[Export]``
attribute when a :ref:`Variant-compatible <doc_c_sharp_variant>` type is expected.

Rule description
----------------

Every exported member must be Variant-compatible so it can be marshalled by
the engine.

.. code-block:: csharp

class SomeType { }

// SomeType is not a valid member type because it doesn't derive from GodotObject,
// so it's not compatible with Variant.
[Export]
public SomeType InvalidProperty { get; set; }

// System.Int32 is a valid type because it's compatible with Variant.
[Export]
public int ValidProperty { get; set; }

How to fix violations
---------------------

To fix a violation of this rule, change the member's type to be Variant-compatible
or remove the ``[Export]`` attribute.

When to suppress warnings
-------------------------

Do not suppress a warning from this rule. Members with types that can't be marshalled
will result in runtime errors.
55 changes: 55 additions & 0 deletions tutorials/scripting/c_sharp/diagnostics/GD0103.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
GD0103: The exported member is read-only
========================================

==================================== ======================================
Value
==================================== ======================================
**Rule ID** GD0103
**Category** Usage
**Fix is breaking or non-breaking** Non-breaking
**Enabled by default** Yes
==================================== ======================================

Cause
-----

A read-only member is annotated with the ``[Export]`` attribute. Read-only members
can't be exported.

Rule description
----------------

Godot doesn't allow exporting read-only members.

.. code-block:: csharp

// Read-only fields can't be exported.
[Export]
public readonly int invalidField;

// This field can be exported because it's not declared 'readonly'.
[Export]
public int validField;

// Read-only properties can't be exported.
[Export]
public int InvalidProperty { get; }

// This property can be exported because it has both a getter and a setter.
[Export]
public int ValidProperty { get; set; }

How to fix violations
---------------------

To fix a violation of this rule for fields, remove the ``readonly`` keyword or
remove the ``[Export]`` attribute.

To fix a violation of this rule for properties, make sure the property declares
both a getter and a setter, or remove the ``[Export]`` attribute.

When to suppress warnings
-------------------------

Do not suppress a warning from this rule. Read-only members can't be exported so
they will be ignored by Godot, resulting in runtime errors.
46 changes: 46 additions & 0 deletions tutorials/scripting/c_sharp/diagnostics/GD0104.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
GD0104: The exported property is write-only
===========================================

==================================== ======================================
Value
==================================== ======================================
**Rule ID** GD0104
**Category** Usage
**Fix is breaking or non-breaking** Non-breaking
**Enabled by default** Yes
==================================== ======================================

Cause
-----

A write-only property is annotated with the ``[Export]`` attribute. Write-only properties
can't be exported.

Rule description
----------------

Godot doesn't allow exporting write-only properties.

.. code-block:: csharp

private int _backingField;

// Write-only properties can't be exported.
[Export]
public int InvalidProperty { set => _backingField = value; }

// This property can be exported because it has both a getter and a setter.
[Export]
public int ValidProperty { get; set; }

How to fix violations
---------------------

To fix a violation of this rule, make sure the property declares
both a getter and a setter, or remove the ``[Export]`` attribute.

When to suppress warnings
-------------------------

Do not suppress a warning from this rule. Write-only members can't be exported so
they will be ignored by Godot, resulting in runtime errors.
44 changes: 44 additions & 0 deletions tutorials/scripting/c_sharp/diagnostics/GD0105.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
GD0105: Attempted to export indexer property
============================================

==================================== ======================================
Value
==================================== ======================================
**Rule ID** GD0105
**Category** Usage
**Fix is breaking or non-breaking** Non-breaking
**Enabled by default** Yes
==================================== ======================================

Cause
-----

An indexer is annotated with the ``[Export]`` attribute. Indexers can't be exported.

Rule description
----------------

Godot doesn't allow exporting indexer properties.

.. code-block:: csharp

private int[] _backingField;

// Indexers can't be exported.
[Export]
public int this[int index]
{
get => _backingField[index];
set => _backingField[index] = value;
}

How to fix violations
---------------------

To fix a violation of this rule, remove the ``[Export]`` attribute.

When to suppress warnings
-------------------------

Do not suppress a warning from this rule. Indexers can't be exported so
they will be ignored by Godot, resulting in runtime errors.
Loading