Skip to content

Commit

Permalink
Style: Enforce braces around if blocks and loops
Browse files Browse the repository at this point in the history
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
  • Loading branch information
akien-mga committed May 14, 2020
1 parent 07bc4e2 commit 0ee0fa4
Show file tree
Hide file tree
Showing 683 changed files with 22,790 additions and 12,212 deletions.
6 changes: 3 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-nullptr'
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-nullptr,readability-braces-around-statements'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
Expand All @@ -14,8 +14,6 @@ CheckOptions:
value: '1'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
Expand All @@ -40,5 +38,7 @@ CheckOptions:
value: '1'
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
- key: readability-braces-around-statements.ShortStatementLines
value: '0'
...

30 changes: 20 additions & 10 deletions core/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ void Array::_ref(const Array &p_from) const {

ERR_FAIL_COND(!_fp); // should NOT happen.

if (_fp == _p)
if (_fp == _p) {
return; // whatever it is, nothing to do here move along
}

bool success = _fp->refcount.ref();

Expand All @@ -63,8 +64,9 @@ void Array::_ref(const Array &p_from) const {
}

void Array::_unref() const {
if (!_p)
if (!_p) {
return;
}

if (_p->refcount.unref()) {
memdelete(_p);
Expand Down Expand Up @@ -189,8 +191,9 @@ int Array::find(const Variant &p_value, int p_from) const {
}

int Array::rfind(const Variant &p_value, int p_from) const {
if (_p->array.size() == 0)
if (_p->array.size() == 0) {
return -1;
}
ERR_FAIL_COND_V(!_p->typed.validate(p_value, "rfind"), -1);

if (p_from < 0) {
Expand Down Expand Up @@ -218,8 +221,9 @@ int Array::find_last(const Variant &p_value) const {

int Array::count(const Variant &p_value) const {
ERR_FAIL_COND_V(!_p->typed.validate(p_value, "count"), 0);
if (_p->array.size() == 0)
if (_p->array.size() == 0) {
return 0;
}

int amount = 0;
for (int i = 0; i < _p->array.size(); i++) {
Expand Down Expand Up @@ -278,14 +282,17 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // l

ERR_FAIL_COND_V_MSG(p_step == 0, new_arr, "Array slice step size cannot be zero.");

if (empty()) // Don't try to slice empty arrays.
if (empty()) { // Don't try to slice empty arrays.
return new_arr;
}
if (p_step > 0) {
if (p_begin >= size() || p_end < -size())
if (p_begin >= size() || p_end < -size()) {
return new_arr;
}
} else { // p_step < 0
if (p_begin < -size() || p_end >= size())
if (p_begin < -size() || p_end >= size()) {
return new_arr;
}
}

int begin = _clamp_slice_index(p_begin);
Expand Down Expand Up @@ -316,8 +323,9 @@ struct _ArrayVariantSort {
bool valid = false;
Variant res;
Variant::evaluate(Variant::OP_LESS, p_l, p_r, res, valid);
if (!valid)
if (!valid) {
res = false;
}
return res;
}
};
Expand All @@ -335,8 +343,9 @@ struct _ArrayVariantSortCustom {
const Variant *args[2] = { &p_l, &p_r };
Callable::CallError err;
bool res = obj->call(func, args, 2, err);
if (err.error != Callable::CallError::CALL_OK)
if (err.error != Callable::CallError::CALL_OK) {
res = false;
}
return res;
}
};
Expand All @@ -352,8 +361,9 @@ Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {

void Array::shuffle() {
const int n = _p->array.size();
if (n < 2)
if (n < 2) {
return;
}
Variant *data = _p->array.ptrw();
for (int i = n - 1; i >= 1; i--) {
const int j = Math::rand() % (i + 1);
Expand Down
86 changes: 56 additions & 30 deletions core/bind/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,20 @@ int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p
OS::ProcessID pid = -2;
int exitcode = 0;
List<String> args;
for (int i = 0; i < p_arguments.size(); i++)
for (int i = 0; i < p_arguments.size(); i++) {
args.push_back(p_arguments[i]);
}
String pipe;
Error err = OS::get_singleton()->execute(p_path, args, p_blocking, &pid, &pipe, &exitcode, p_read_stderr);
p_output.clear();
p_output.push_back(pipe);
if (err != OK)
if (err != OK) {
return -1;
else if (p_blocking)
} else if (p_blocking) {
return exitcode;
else
} else {
return pid;
}
}

Error _OS::kill(int p_pid) {
Expand Down Expand Up @@ -564,8 +566,9 @@ void _OS::print_all_textures_by_size() {
ResourceCache::get_cached_resources(&rsrc);

for (List<Ref<Resource>>::Element *E = rsrc.front(); E; E = E->next()) {
if (!E->get()->is_class("ImageTexture"))
if (!E->get()->is_class("ImageTexture")) {
continue;
}

Size2 size = E->get()->call("get_size");
int fmt = E->get()->call("get_format");
Expand Down Expand Up @@ -603,11 +606,13 @@ void _OS::print_resources_by_type(const Vector<String> &p_types) {
bool found = false;

for (int i = 0; i < p_types.size(); i++) {
if (r->is_class(p_types[i]))
if (r->is_class(p_types[i])) {
found = true;
}
}
if (!found)
if (!found) {
continue;
}

if (!type_count.has(r->get_class())) {
type_count[r->get_class()] = 0;
Expand Down Expand Up @@ -889,18 +894,20 @@ Vector3 _Geometry::get_closest_point_to_segment_uncapped(const Vector3 &p_point,

Variant _Geometry::ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
Vector3 res;
if (Geometry::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res))
if (Geometry::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res)) {
return res;
else
} else {
return Variant();
}
}

Variant _Geometry::segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
Vector3 res;
if (Geometry::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res))
if (Geometry::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res)) {
return res;
else
} else {
return Variant();
}
}

bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
Expand All @@ -910,8 +917,9 @@ bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, con
Vector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) {
Vector<Vector3> r;
Vector3 res, norm;
if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm))
if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm)) {
return r;
}

r.resize(2);
r.set(0, res);
Expand All @@ -922,8 +930,9 @@ Vector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, cons
Vector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
Vector<Vector3> r;
Vector3 res, norm;
if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm))
if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm)) {
return r;
}

r.resize(2);
r.set(0, res);
Expand All @@ -934,8 +943,9 @@ Vector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, co
Vector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes) {
Vector<Vector3> r;
Vector3 res, norm;
if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm))
if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm)) {
return r;
}

r.resize(2);
r.set(0, res);
Expand Down Expand Up @@ -1151,8 +1161,9 @@ void _Geometry::_bind_methods() {

Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key) {
Error err = open(p_path, p_mode_flags);
if (err)
if (err) {
return err;
}

FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse(f, p_key, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
Expand All @@ -1167,8 +1178,9 @@ Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const

Error _File::open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass) {
Error err = open(p_path, p_mode_flags);
if (err)
if (err) {
return err;
}

FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse_password(f, p_pass, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
Expand Down Expand Up @@ -1202,14 +1214,16 @@ Error _File::open(const String &p_path, ModeFlags p_mode_flags) {
close();
Error err;
f = FileAccess::open(p_path, p_mode_flags, &err);
if (f)
if (f) {
f->set_endian_swap(eswap);
}
return err;
}

void _File::close() {
if (f)
if (f) {
memdelete(f);
}
f = nullptr;
}

Expand Down Expand Up @@ -1292,8 +1306,9 @@ Vector<uint8_t> _File::get_buffer(int p_length) const {
ERR_FAIL_COND_V_MSG(!f, data, "File must be opened before use.");

ERR_FAIL_COND_V_MSG(p_length < 0, data, "Length of buffer cannot be smaller than 0.");
if (p_length == 0)
if (p_length == 0) {
return data;
}

Error err = data.resize(p_length);
ERR_FAIL_COND_V_MSG(err != OK, data, "Can't resize data to " + itos(p_length) + " elements.");
Expand All @@ -1302,8 +1317,9 @@ Vector<uint8_t> _File::get_buffer(int p_length) const {
int len = f->get_buffer(&w[0], p_length);
ERR_FAIL_COND_V(len < 0, Vector<uint8_t>());

if (len < p_length)
if (len < p_length) {
data.resize(p_length);
}

return data;
}
Expand Down Expand Up @@ -1352,17 +1368,19 @@ Vector<String> _File::get_csv_line(const String &p_delim) const {

void _File::set_endian_swap(bool p_swap) {
eswap = p_swap;
if (f)
if (f) {
f->set_endian_swap(p_swap);
}
}

bool _File::get_endian_swap() {
return eswap;
}

Error _File::get_error() const {
if (!f)
if (!f) {
return ERR_UNCONFIGURED;
}
return f->get_error();
}

Expand Down Expand Up @@ -1440,8 +1458,9 @@ void _File::store_buffer(const Vector<uint8_t> &p_buffer) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");

int len = p_buffer.size();
if (len == 0)
if (len == 0) {
return;
}

const uint8_t *r = p_buffer.ptr();

Expand Down Expand Up @@ -1554,8 +1573,9 @@ void _File::_bind_methods() {
}

_File::~_File() {
if (f)
if (f) {
memdelete(f);
}
}

////// _Directory //////
Expand All @@ -1564,10 +1584,12 @@ Error _Directory::open(const String &p_path) {
Error err;
DirAccess *alt = DirAccess::open(p_path, &err);

if (!alt)
if (!alt) {
return err;
if (d)
}
if (d) {
memdelete(d);
}
d = alt;

return OK;
Expand Down Expand Up @@ -1733,8 +1755,9 @@ _Directory::_Directory() {
}

_Directory::~_Directory() {
if (d)
if (d) {
memdelete(d);
}
}

////// _Marshalls //////
Expand Down Expand Up @@ -1943,8 +1966,9 @@ Error _Thread::start(Object *p_instance, const StringName &p_method, const Varia
}

String _Thread::get_id() const {
if (!thread)
if (!thread) {
return String();
}

return itos(thread->get_id());
}
Expand All @@ -1962,8 +1986,9 @@ Variant _Thread::wait_to_finish() {
target_method = StringName();
target_instance = nullptr;
userdata = Variant();
if (thread)
if (thread) {
memdelete(thread);
}
thread = nullptr;

return r;
Expand Down Expand Up @@ -2032,8 +2057,9 @@ bool _ClassDB::can_instance(const StringName &p_class) const {

Variant _ClassDB::instance(const StringName &p_class) const {
Object *obj = ClassDB::instance(p_class);
if (!obj)
if (!obj) {
return Variant();
}

Reference *r = Object::cast_to<Reference>(obj);
if (r) {
Expand Down
Loading

0 comments on commit 0ee0fa4

Please sign in to comment.