From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- editor/script_create_dialog.cpp | 29 ----------------------------- 1 file changed, 29 deletions(-) (limited to 'editor/script_create_dialog.cpp') diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index f84b7e73ed..721384035f 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -68,7 +68,6 @@ void ScriptCreateDialog::_theme_changed() { status_panel->add_theme_style_override("panel", gc->get_theme_stylebox("bg", "Tree")); } void ScriptCreateDialog::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_ENTER_TREE: { _theme_changed(); @@ -99,7 +98,6 @@ bool ScriptCreateDialog::_can_be_built_in() { } void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled, bool p_load_enabled) { - class_name->set_text(""); class_name->deselect(); parent_name->set_text(p_base_name); @@ -124,12 +122,10 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_ } void ScriptCreateDialog::set_inheritance_base_type(const String &p_base) { - base_type = p_base; } bool ScriptCreateDialog::_validate_parent(const String &p_string) { - if (p_string.length() == 0) return false; @@ -143,12 +139,10 @@ bool ScriptCreateDialog::_validate_parent(const String &p_string) { } bool ScriptCreateDialog::_validate_class(const String &p_string) { - if (p_string.length() == 0) return false; for (int i = 0; i < p_string.length(); i++) { - if (i == 0) { if (p_string[0] >= '0' && p_string[0] <= '9') return false; // no start with number plz @@ -164,7 +158,6 @@ bool ScriptCreateDialog::_validate_class(const String &p_string) { } String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must_exist) { - String p = p_path.strip_edges(); if (p == "") @@ -234,7 +227,6 @@ String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must } void ScriptCreateDialog::_class_name_changed(const String &p_name) { - if (_validate_class(class_name->get_text())) { is_class_name_valid = true; } else { @@ -244,7 +236,6 @@ void ScriptCreateDialog::_class_name_changed(const String &p_name) { } void ScriptCreateDialog::_parent_name_changed(const String &p_parent) { - if (_validate_parent(parent_name->get_text())) { is_parent_name_valid = true; } else { @@ -254,7 +245,6 @@ void ScriptCreateDialog::_parent_name_changed(const String &p_parent) { } void ScriptCreateDialog::_template_changed(int p_template) { - String selected_template = p_template == 0 ? "" : template_menu->get_item_text(p_template); EditorSettings::get_singleton()->set_project_metadata("script_setup", "last_selected_template", selected_template); if (p_template == 0) { @@ -274,7 +264,6 @@ void ScriptCreateDialog::_template_changed(int p_template) { } void ScriptCreateDialog::ok_pressed() { - if (is_new_script_created) { _create_new(); } else { @@ -286,7 +275,6 @@ void ScriptCreateDialog::ok_pressed() { } void ScriptCreateDialog::_create_new() { - String cname_param; if (has_named_classes) { @@ -331,7 +319,6 @@ void ScriptCreateDialog::_create_new() { } void ScriptCreateDialog::_load_exist() { - String path = file_path->get_text(); RES p_script = ResourceLoader::load(path, "Script"); if (p_script.is_null()) { @@ -345,7 +332,6 @@ void ScriptCreateDialog::_load_exist() { } void ScriptCreateDialog::_lang_changed(int l) { - ScriptLanguage *language = ScriptServer::get_language(l); has_named_classes = language->has_named_classes(); @@ -409,7 +395,6 @@ void ScriptCreateDialog::_lang_changed(int l) { // Populate script template items previously sorted and now grouped by origin for (int i = 0; i < template_list.size(); i++) { - if (int(templates[i].origin) != cur_origin) { template_menu->add_separator(); @@ -474,7 +459,6 @@ void ScriptCreateDialog::_lang_changed(int l) { } void ScriptCreateDialog::_update_script_templates(const String &p_extension) { - template_list.clear(); template_overrides.clear(); @@ -485,7 +469,6 @@ void ScriptCreateDialog::_update_script_templates(const String &p_extension) { dirs.push_back(EditorSettings::get_singleton()->get_script_templates_dir()); for (int i = 0; i < dirs.size(); i++) { - Vector list = EditorSettings::get_singleton()->get_script_templates(p_extension, dirs[i]); for (int j = 0; j < list.size(); j++) { @@ -509,7 +492,6 @@ void ScriptCreateDialog::_update_script_templates(const String &p_extension) { } void ScriptCreateDialog::_built_in_pressed() { - if (internal->is_pressed()) { is_built_in = true; is_new_script_created = true; @@ -521,7 +503,6 @@ void ScriptCreateDialog::_built_in_pressed() { } void ScriptCreateDialog::_browse_path(bool browse_parent, bool p_save) { - is_browsing_parent = browse_parent; if (p_save) { @@ -549,7 +530,6 @@ void ScriptCreateDialog::_browse_path(bool browse_parent, bool p_save) { } void ScriptCreateDialog::_file_selected(const String &p_file) { - String p = ProjectSettings::get_singleton()->localize_path(p_file); if (is_browsing_parent) { parent_name->set_text("\"" + p + "\""); @@ -567,19 +547,16 @@ void ScriptCreateDialog::_file_selected(const String &p_file) { } void ScriptCreateDialog::_create() { - parent_name->set_text(select_class->get_selected_type().split(" ")[0]); _parent_name_changed(parent_name->get_text()); } void ScriptCreateDialog::_browse_class_in_tree() { - select_class->set_base_type(base_type); select_class->popup_create(true); } void ScriptCreateDialog::_path_changed(const String &p_path) { - if (is_built_in) { return; } @@ -612,7 +589,6 @@ void ScriptCreateDialog::_path_entered(const String &p_path) { } void ScriptCreateDialog::_msg_script_valid(bool valid, const String &p_msg) { - error_label->set_text("- " + TTR(p_msg)); if (valid) { error_label->add_theme_color_override("font_color", gc->get_theme_color("success_color", "Editor")); @@ -622,7 +598,6 @@ void ScriptCreateDialog::_msg_script_valid(bool valid, const String &p_msg) { } void ScriptCreateDialog::_msg_path_valid(bool valid, const String &p_msg) { - path_error_label->set_text("- " + TTR(p_msg)); if (valid) { path_error_label->add_theme_color_override("font_color", gc->get_theme_color("success_color", "Editor")); @@ -632,7 +607,6 @@ void ScriptCreateDialog::_msg_path_valid(bool valid, const String &p_msg) { } void ScriptCreateDialog::_update_dialog() { - /* "Add Script Dialog" GUI logic and script checks. */ bool script_ok = true; @@ -737,14 +711,12 @@ void ScriptCreateDialog::_update_dialog() { } void ScriptCreateDialog::_bind_methods() { - ClassDB::bind_method(D_METHOD("config", "inherits", "path", "built_in_enabled", "load_enabled"), &ScriptCreateDialog::config, DEFVAL(true), DEFVAL(true)); ADD_SIGNAL(MethodInfo("script_created", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script"))); } ScriptCreateDialog::ScriptCreateDialog() { - /* DIALOG */ /* Main Controls */ @@ -799,7 +771,6 @@ ScriptCreateDialog::ScriptCreateDialog() { default_language = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { - String lang = ScriptServer::get_language(i)->get_name(); language_menu->add_item(lang); if (lang == "GDScript") { -- cgit v1.2.3 From 07bc4e2f96f8f47991339654ff4ab16acc19d44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 14:29:06 +0200 Subject: Style: Enforce separation line between function definitions I couldn't find a tool that enforces it, so I went the manual route: ``` find -name "thirdparty" -prune \ -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \ -o -name "*.glsl" > files perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files) misc/scripts/fix_style.sh -c ``` This adds a newline after all `}` on the first column, unless they are followed by `#` (typically `#endif`). This leads to having lots of places with two lines between function/class definitions, but clang-format then fixes it as we enforce max one line of separation. This doesn't fix potential occurrences of function definitions which are indented (e.g. for a helper class defined in a .cpp), but it's better than nothing. Also can't be made to run easily on CI/hooks so we'll have to be careful with new code. Part of #33027. --- editor/script_create_dialog.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'editor/script_create_dialog.cpp') diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 721384035f..d0346a6c3e 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -67,6 +67,7 @@ void ScriptCreateDialog::_theme_changed() { parent_search_button->set_icon(gc->get_theme_icon("ClassList", "EditorIcons")); status_panel->add_theme_style_override("panel", gc->get_theme_stylebox("bg", "Tree")); } + void ScriptCreateDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- editor/script_create_dialog.cpp | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'editor/script_create_dialog.cpp') diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index d0346a6c3e..04fbfdff9d 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -127,32 +127,37 @@ void ScriptCreateDialog::set_inheritance_base_type(const String &p_base) { } bool ScriptCreateDialog::_validate_parent(const String &p_string) { - if (p_string.length() == 0) + if (p_string.length() == 0) { return false; + } if (can_inherit_from_file && p_string.is_quoted()) { String p = p_string.substr(1, p_string.length() - 2); - if (_validate_path(p, true) == "") + if (_validate_path(p, true) == "") { return true; + } } return ClassDB::class_exists(p_string) || ScriptServer::is_global_class(p_string); } bool ScriptCreateDialog::_validate_class(const String &p_string) { - if (p_string.length() == 0) + if (p_string.length() == 0) { return false; + } for (int i = 0; i < p_string.length(); i++) { if (i == 0) { - if (p_string[0] >= '0' && p_string[0] <= '9') + if (p_string[0] >= '0' && p_string[0] <= '9') { return false; // no start with number plz + } } bool valid_char = (p_string[i] >= '0' && p_string[i] <= '9') || (p_string[i] >= 'a' && p_string[i] <= 'z') || (p_string[i] >= 'A' && p_string[i] <= 'Z') || p_string[i] == '_' || p_string[i] == '.'; - if (!valid_char) + if (!valid_char) { return false; + } } return true; @@ -161,14 +166,17 @@ bool ScriptCreateDialog::_validate_class(const String &p_string) { String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must_exist) { String p = p_path.strip_edges(); - if (p == "") + if (p == "") { return TTR("Path is empty."); - if (p.get_file().get_basename() == "") + } + if (p.get_file().get_basename() == "") { return TTR("Filename is empty."); + } p = ProjectSettings::get_singleton()->localize_path(p); - if (!p.begins_with("res://")) + if (!p.begins_with("res://")) { return TTR("Path is not local."); + } DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (d->change_dir(p.get_base_dir()) != OK) { @@ -213,15 +221,18 @@ String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must index++; } - if (!found) + if (!found) { return TTR("Invalid extension."); - if (!match) + } + if (!match) { return TTR("Wrong extension chosen."); + } /* Let ScriptLanguage do custom validation */ String path_error = ScriptServer::get_language(language_menu->get_selected())->validate_path(p); - if (path_error != "") + if (path_error != "") { return path_error; + } /* All checks passed */ return ""; @@ -300,8 +311,9 @@ void ScriptCreateDialog::_create_new() { if (has_named_classes) { String cname = class_name->get_text(); - if (cname.length()) + if (cname.length()) { scr->set_name(cname); + } } if (!is_built_in) { @@ -338,8 +350,9 @@ void ScriptCreateDialog::_lang_changed(int l) { has_named_classes = language->has_named_classes(); can_inherit_from_file = language->can_inherit_from_file(); supports_built_in = language->supports_builtin_mode(); - if (!supports_built_in) + if (!supports_built_in) { is_built_in = false; + } String selected_ext = "." + language->get_extension(); String path = file_path->get_text(); -- cgit v1.2.3