From 7d1cc992e544465e2520e863e7c277bbdf10e7c6 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 25 Nov 2019 16:51:28 -0800 Subject: [PATCH] [clang-tidy] Simplify boolean expressions Found with readability-simplify-boolean-expr Signed-off-by: Rosen Penev --- src/builtin_functions.cpp | 2 +- src/builtin_wait.cpp | 5 +---- src/color.cpp | 2 +- src/complete.cpp | 2 +- src/exec.cpp | 2 +- src/expand.cpp | 3 +-- src/history.cpp | 5 +---- src/reader.cpp | 4 +--- src/wutil.cpp | 3 +-- 9 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index e901e15fe..f25a3377c 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -299,7 +299,7 @@ int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) { } // Erase, desc, query, copy and list are mutually exclusive. - bool describe = opts.description ? true : false; + bool describe = opts.description != nullptr; if (describe + opts.erase + opts.list + opts.query + opts.copy > 1) { streams.err.append_format(BUILTIN_ERR_COMBO, cmd); builtin_print_error_trailer(parser, streams.err, cmd); diff --git a/src/builtin_wait.cpp b/src/builtin_wait.cpp index f514c09f6..678caf32e 100644 --- a/src/builtin_wait.cpp +++ b/src/builtin_wait.cpp @@ -60,10 +60,7 @@ static bool any_jobs_finished(size_t jobs_len, const parser_t &parser) { no_jobs_running = false; } } - if (no_jobs_running) { - return true; - } - return false; + return no_jobs_running; } static int wait_for_backgrounds(parser_t &parser, bool any_flag) { diff --git a/src/color.cpp b/src/color.cpp index 6594cee92..0a5857f4d 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -174,7 +174,7 @@ wcstring_list_t rgb_color_t::named_color_names() { wcstring_list_t result; result.reserve(1 + count); for (size_t i = 0; i < count; i++) { - if (named_colors[i].hidden == false) { + if (!named_colors[i].hidden) { result.push_back(named_colors[i].name); } } diff --git a/src/complete.cpp b/src/complete.cpp index a31496262..e014ead62 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -902,7 +902,7 @@ bool completer_t::complete_param(const wcstring &cmd_orig, const wcstring &popt, // FLOGF(error, L"\nThinking about looking up completions for %ls\n", cmd.c_str()); bool head_exists = builtin_exists(cmd); // Only reload environment variables if builtin_exists returned false, as an optimization - if (head_exists == false) { + if (!head_exists) { head_exists = function_exists_no_autoload(cmd); // While it may seem like first testing `path_get_path` before resorting to an env lookup // may be faster, path_get_path can potentially do a lot of FS/IO access, so env.get() + diff --git a/src/exec.cpp b/src/exec.cpp index a627cc362..767291b03 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -1128,7 +1128,7 @@ bool exec_job(parser_t &parser, shared_ptr j) { internal_exec(parser.vars(), j.get(), all_ios); // internal_exec only returns if it failed to set up redirections. // In case of an successful exec, this code is not reached. - bool status = j->flags().negate ? false : true; + bool status = !j->flags().negate; parser.set_last_statuses(statuses_t::just(status)); return false; } diff --git a/src/expand.cpp b/src/expand.cpp index 09ae53913..f1334cb41 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -671,8 +671,7 @@ static bool expand_cmdsubst(wcstring input, parser_t &parser, std::vectorget_selected_column(data->current_page_rendering); - if (col != 0 && col != PAGER_SELECTION_NONE) return false; - - return true; + return !(col != 0 && col != PAGER_SELECTION_NONE); } static relaxed_atomic_t run_count{0}; diff --git a/src/wutil.cpp b/src/wutil.cpp index 330ccb70b..45b24922d 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -127,8 +127,7 @@ bool wreaddir_for_dirs(DIR *dir, wcstring *out_name) { if (result && out_name) { *out_name = str2wcstring(result->d_name); } - if (!result) return false; - return true; + return result != nullptr; } const wcstring wgetcwd() {