Skip to content

Commit 0fe60f8

Browse files
committed
Include gdscript warning name in the warning message.
Occasionally you want to ignore a warning with a `warning-ignore` comment, and you have to go into the settings to look up what the actual name of the warning is. This patch appends the warning name to the end of the warning so you know what string to use to ignore it, similar to other linters like pylint. For example ``` "The signal 'blah' is declared but never emitted."; ``` is now ``` "The signal 'blah' is declared but never emitted. (UNUSED_SIGNAL)"; ```
1 parent 89cc23b commit 0fe60f8

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

modules/gdscript/gdscript.cpp

+33-30
Original file line numberDiff line numberDiff line change
@@ -2020,113 +2020,116 @@ String GDScriptWarning::get_message() const {
20202020

20212021
#define CHECK_SYMBOLS(m_amount) ERR_FAIL_COND_V(symbols.size() < m_amount, String());
20222022

2023+
String msg;
2024+
20232025
switch (code) {
20242026
case UNASSIGNED_VARIABLE_OP_ASSIGN: {
20252027
CHECK_SYMBOLS(1);
2026-
return "Using assignment with operation but the variable '" + symbols[0] + "' was not previously assigned a value.";
2028+
msg = "Using assignment with operation but the variable '" + symbols[0] + "' was not previously assigned a value.";
20272029
} break;
20282030
case UNASSIGNED_VARIABLE: {
20292031
CHECK_SYMBOLS(1);
2030-
return "The variable '" + symbols[0] + "' was used but never assigned a value.";
2032+
msg = "The variable '" + symbols[0] + "' was used but never assigned a value.";
20312033
} break;
20322034
case UNUSED_VARIABLE: {
20332035
CHECK_SYMBOLS(1);
2034-
return "The local variable '" + symbols[0] + "' is declared but never used in the block. If this is intended, prefix it with an underscore: '_" + symbols[0] + "'";
2036+
msg = "The local variable '" + symbols[0] + "' is declared but never used in the block. If this is intended, prefix it with an underscore: '_" + symbols[0] + "'";
20352037
} break;
20362038
case SHADOWED_VARIABLE: {
20372039
CHECK_SYMBOLS(2);
2038-
return "The local variable '" + symbols[0] + "' is shadowing an already-defined variable at line " + symbols[1] + ".";
2040+
msg = "The local variable '" + symbols[0] + "' is shadowing an already-defined variable at line " + symbols[1] + ".";
20392041
} break;
20402042
case UNUSED_CLASS_VARIABLE: {
20412043
CHECK_SYMBOLS(1);
2042-
return "The class variable '" + symbols[0] + "' is declared but never used in the script.";
2044+
msg = "The class variable '" + symbols[0] + "' is declared but never used in the script.";
20432045
} break;
20442046
case UNUSED_ARGUMENT: {
20452047
CHECK_SYMBOLS(2);
2046-
return "The argument '" + symbols[1] + "' is never used in the function '" + symbols[0] + "'. If this is intended, prefix it with an underscore: '_" + symbols[1] + "'";
2048+
msg = "The argument '" + symbols[1] + "' is never used in the function '" + symbols[0] + "'. If this is intended, prefix it with an underscore: '_" + symbols[1] + "'";
20472049
} break;
20482050
case UNREACHABLE_CODE: {
20492051
CHECK_SYMBOLS(1);
2050-
return "Unreachable code (statement after return) in function '" + symbols[0] + "()'.";
2052+
msg = "Unreachable code (statement after return) in function '" + symbols[0] + "()'.";
20512053
} break;
20522054
case STANDALONE_EXPRESSION: {
2053-
return "Standalone expression (the line has no effect).";
2055+
msg = "Standalone expression (the line has no effect).";
20542056
} break;
20552057
case VOID_ASSIGNMENT: {
20562058
CHECK_SYMBOLS(1);
2057-
return "Assignment operation, but the function '" + symbols[0] + "()' returns void.";
2059+
msg = "Assignment operation, but the function '" + symbols[0] + "()' returns void.";
20582060
} break;
20592061
case NARROWING_CONVERSION: {
2060-
return "Narrowing conversion (float is converted to int and loses precision).";
2062+
msg = "Narrowing conversion (float is converted to int and loses precision).";
20612063
} break;
20622064
case FUNCTION_MAY_YIELD: {
20632065
CHECK_SYMBOLS(1);
2064-
return "Assigned variable is typed but the function '" + symbols[0] + "()' may yield and return a GDScriptFunctionState instead.";
2066+
msg = "Assigned variable is typed but the function '" + symbols[0] + "()' may yield and return a GDScriptFunctionState instead.";
20652067
} break;
20662068
case VARIABLE_CONFLICTS_FUNCTION: {
20672069
CHECK_SYMBOLS(1);
2068-
return "Variable declaration of '" + symbols[0] + "' conflicts with a function of the same name.";
2070+
msg = "Variable declaration of '" + symbols[0] + "' conflicts with a function of the same name.";
20692071
} break;
20702072
case FUNCTION_CONFLICTS_VARIABLE: {
20712073
CHECK_SYMBOLS(1);
2072-
return "Function declaration of '" + symbols[0] + "()' conflicts with a variable of the same name.";
2074+
msg = "Function declaration of '" + symbols[0] + "()' conflicts with a variable of the same name.";
20732075
} break;
20742076
case FUNCTION_CONFLICTS_CONSTANT: {
20752077
CHECK_SYMBOLS(1);
2076-
return "Function declaration of '" + symbols[0] + "()' conflicts with a constant of the same name.";
2078+
msg = "Function declaration of '" + symbols[0] + "()' conflicts with a constant of the same name.";
20772079
} break;
20782080
case INCOMPATIBLE_TERNARY: {
2079-
return "Values of the ternary conditional are not mutually compatible.";
2081+
msg = "Values of the ternary conditional are not mutually compatible.";
20802082
} break;
20812083
case UNUSED_SIGNAL: {
20822084
CHECK_SYMBOLS(1);
2083-
return "The signal '" + symbols[0] + "' is declared but never emitted.";
2085+
msg = "The signal '" + symbols[0] + "' is declared but never emitted.";
20842086
} break;
20852087
case RETURN_VALUE_DISCARDED: {
20862088
CHECK_SYMBOLS(1);
2087-
return "The function '" + symbols[0] + "()' returns a value, but this value is never used.";
2089+
msg = "The function '" + symbols[0] + "()' returns a value, but this value is never used.";
20882090
} break;
20892091
case PROPERTY_USED_AS_FUNCTION: {
20902092
CHECK_SYMBOLS(2);
2091-
return "The method '" + symbols[0] + "()' was not found in base '" + symbols[1] + "' but there's a property with the same name. Did you mean to access it?";
2093+
msg = "The method '" + symbols[0] + "()' was not found in base '" + symbols[1] + "' but there's a property with the same name. Did you mean to access it?";
20922094
} break;
20932095
case CONSTANT_USED_AS_FUNCTION: {
20942096
CHECK_SYMBOLS(2);
2095-
return "The method '" + symbols[0] + "()' was not found in base '" + symbols[1] + "' but there's a constant with the same name. Did you mean to access it?";
2097+
msg = "The method '" + symbols[0] + "()' was not found in base '" + symbols[1] + "' but there's a constant with the same name. Did you mean to access it?";
20962098
} break;
20972099
case FUNCTION_USED_AS_PROPERTY: {
20982100
CHECK_SYMBOLS(2);
2099-
return "The property '" + symbols[0] + "' was not found in base '" + symbols[1] + "' but there's a method with the same name. Did you mean to call it?";
2101+
msg = "The property '" + symbols[0] + "' was not found in base '" + symbols[1] + "' but there's a method with the same name. Did you mean to call it?";
21002102
} break;
21012103
case INTEGER_DIVISION: {
2102-
return "Integer division, decimal part will be discarded.";
2104+
msg = "Integer division, decimal part will be discarded.";
21032105
} break;
21042106
case UNSAFE_PROPERTY_ACCESS: {
21052107
CHECK_SYMBOLS(2);
2106-
return "The property '" + symbols[0] + "' is not present on the inferred type '" + symbols[1] + "' (but may be present on a subtype).";
2108+
msg = "The property '" + symbols[0] + "' is not present on the inferred type '" + symbols[1] + "' (but may be present on a subtype).";
21072109
} break;
21082110
case UNSAFE_METHOD_ACCESS: {
21092111
CHECK_SYMBOLS(2);
2110-
return "The method '" + symbols[0] + "' is not present on the inferred type '" + symbols[1] + "' (but may be present on a subtype).";
2112+
msg = "The method '" + symbols[0] + "' is not present on the inferred type '" + symbols[1] + "' (but may be present on a subtype).";
21112113
} break;
21122114
case UNSAFE_CAST: {
21132115
CHECK_SYMBOLS(1);
2114-
return "The value is cast to '" + symbols[0] + "' but has an unknown type.";
2116+
msg = "The value is cast to '" + symbols[0] + "' but has an unknown type.";
21152117
} break;
21162118
case UNSAFE_CALL_ARGUMENT: {
21172119
CHECK_SYMBOLS(4);
2118-
return "The argument '" + symbols[0] + "' of the function '" + symbols[1] + "' requires a the subtype '" + symbols[2] + "' but the supertype '" + symbols[3] + "' was provided";
2120+
msg = "The argument '" + symbols[0] + "' of the function '" + symbols[1] + "' requires a the subtype '" + symbols[2] + "' but the supertype '" + symbols[3] + "' was provided";
21192121
} break;
21202122
case DEPRECATED_KEYWORD: {
21212123
CHECK_SYMBOLS(2);
2122-
return "The '" + symbols[0] + "' keyword is deprecated and will be removed in a future release, please replace its uses by '" + symbols[1] + "'.";
2124+
msg = "The '" + symbols[0] + "' keyword is deprecated and will be removed in a future release, please replace its uses by '" + symbols[1] + "'.";
21232125
} break;
21242126
case STANDALONE_TERNARY: {
2125-
return "Standalone ternary conditional operator: the return value is being discarded.";
2126-
}
2127-
case WARNING_MAX: break; // Can't happen, but silences warning
2127+
msg = "Standalone ternary conditional operator: the return value is being discarded.";
2128+
} break;
2129+
case WARNING_MAX:
2130+
ERR_FAIL_V_MSG(String(), "Invalid GDScript warning code: " + get_name_from_code(code) + ".");
21282131
}
2129-
ERR_FAIL_V_MSG(String(), "Invalid GDScript warning code: " + get_name_from_code(code) + ".");
2132+
return msg + " [" + get_name() + "]";
21302133

21312134
#undef CHECK_SYMBOLS
21322135
}

0 commit comments

Comments
 (0)