GDScript: Ignore unused arguments/local vars that start with _

Makes it simple to ignore particular arguments without adding special
comments, especially in engine-defined functions.
This commit is contained in:
George Marques 2018-08-21 20:19:35 -03:00
parent 4d2b9a4b35
commit 94d662ad55
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D

View file

@ -7397,7 +7397,7 @@ void GDScriptParser::_check_function_types(FunctionNode *p_function) {
}
}
#ifdef DEBUG_ENABLED
if (p_function->arguments_usage[i] == 0) {
if (p_function->arguments_usage[i] == 0 && !p_function->arguments[i].operator String().begins_with("_")) {
_add_warning(GDScriptWarning::UNUSED_ARGUMENT, p_function->line, p_function->name, p_function->arguments[i].operator String());
}
#endif // DEBUG_ENABLED
@ -7855,10 +7855,12 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
// Warnings check
for (Map<StringName, LocalVarNode *>::Element *E = p_block->variables.front(); E; E = E->next()) {
LocalVarNode *lv = E->get();
if (lv->usages == 0) {
_add_warning(GDScriptWarning::UNUSED_VARIABLE, lv->line, lv->name);
} else if (lv->assignments == 0) {
_add_warning(GDScriptWarning::UNASSIGNED_VARIABLE, lv->line, lv->name);
if (!lv->name.operator String().begins_with("_")) {
if (lv->usages == 0) {
_add_warning(GDScriptWarning::UNUSED_VARIABLE, lv->line, lv->name);
} else if (lv->assignments == 0) {
_add_warning(GDScriptWarning::UNASSIGNED_VARIABLE, lv->line, lv->name);
}
}
}
#endif // DEBUG_ENABLED