diff options
| author | dundargoc <gocdundar@gmail.com> | 2022-10-22 12:36:38 +0200 |
|---|---|---|
| committer | dundargoc <gocdundar@gmail.com> | 2022-11-06 11:44:10 +0100 |
| commit | 731cdde28ea8d48cc23ba2752a08c261c87eee92 (patch) | |
| tree | 92e814050fdbca64aca435f03975b6d5678fbdf3 /src/nvim | |
| parent | a79d28e4d7939c13f38cf4ce63ff240011bca96d (diff) | |
| download | rneovim-731cdde28ea8d48cc23ba2752a08c261c87eee92.tar.gz rneovim-731cdde28ea8d48cc23ba2752a08c261c87eee92.tar.bz2 rneovim-731cdde28ea8d48cc23ba2752a08c261c87eee92.zip | |
refactor: fix clang-tidy warnings
Enable and fix bugprone-misplaced-widening-cast warning.
Fix some modernize-macro-to-enum and readability-else-after-return
warnings, but don't enable them. While the warnings can be useful, they
are in general too noisy to enable.
Diffstat (limited to 'src/nvim')
55 files changed, 558 insertions, 547 deletions
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index 3b1b470629..fee6876469 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -833,9 +833,8 @@ uint32_t src2ns(Integer *src_id) } if (*src_id < 0) { return (((uint32_t)1) << 31) - 1; - } else { - return (uint32_t)(*src_id); } + return (uint32_t)(*src_id); } /// Adds a highlight to buffer. diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c index b81fc3b7d7..31f9fab82a 100644 --- a/src/nvim/api/tabpage.c +++ b/src/nvim/api/tabpage.c @@ -110,15 +110,14 @@ Window nvim_tabpage_get_win(Tabpage tabpage, Error *err) if (tab == curtab) { return nvim_get_current_win(); - } else { - FOR_ALL_WINDOWS_IN_TAB(wp, tab) { - if (wp == tab->tp_curwin) { - return wp->handle; - } + } + FOR_ALL_WINDOWS_IN_TAB(wp, tab) { + if (wp == tab->tp_curwin) { + return wp->handle; } - // There should always be a current window for a tabpage - abort(); } + // There should always be a current window for a tabpage + abort(); } /// Gets the tabpage number diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index 71209c9ab6..dccc2d42d8 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -532,7 +532,7 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight, E kv_drop(ast_conv_stack, 1); } else { if (cur_item.ret_node_p->type == kObjectTypeNil) { - size_t items_size = (size_t)(3 // "type", "start" and "len" + size_t items_size = (size_t)(3 // "type", "start" and "len" // NOLINT(bugprone-misplaced-widening-cast) + (node->children != NULL) // "children" + (node->type == kExprNodeOption || node->type == kExprNodePlainIdentifier) // "scope" diff --git a/src/nvim/arabic.c b/src/nvim/arabic.c index b57019286f..ac6269493d 100644 --- a/src/nvim/arabic.c +++ b/src/nvim/arabic.c @@ -27,70 +27,72 @@ #include "nvim/vim.h" // Unicode values for Arabic characters. -#define a_HAMZA 0x0621 -#define a_ALEF_MADDA 0x0622 -#define a_ALEF_HAMZA_ABOVE 0x0623 -#define a_WAW_HAMZA 0x0624 -#define a_ALEF_HAMZA_BELOW 0x0625 -#define a_YEH_HAMZA 0x0626 -#define a_ALEF 0x0627 -#define a_BEH 0x0628 -#define a_TEH_MARBUTA 0x0629 -#define a_TEH 0x062a -#define a_THEH 0x062b -#define a_JEEM 0x062c -#define a_HAH 0x062d -#define a_KHAH 0x062e -#define a_DAL 0x062f -#define a_THAL 0x0630 -#define a_REH 0x0631 -#define a_ZAIN 0x0632 -#define a_SEEN 0x0633 -#define a_SHEEN 0x0634 -#define a_SAD 0x0635 -#define a_DAD 0x0636 -#define a_TAH 0x0637 -#define a_ZAH 0x0638 -#define a_AIN 0x0639 -#define a_GHAIN 0x063a -#define a_TATWEEL 0x0640 -#define a_FEH 0x0641 -#define a_QAF 0x0642 -#define a_KAF 0x0643 -#define a_LAM 0x0644 -#define a_MEEM 0x0645 -#define a_NOON 0x0646 -#define a_HEH 0x0647 -#define a_WAW 0x0648 -#define a_ALEF_MAKSURA 0x0649 -#define a_YEH 0x064a -#define a_FATHATAN 0x064b -#define a_DAMMATAN 0x064c -#define a_KASRATAN 0x064d -#define a_FATHA 0x064e -#define a_DAMMA 0x064f -#define a_KASRA 0x0650 -#define a_SHADDA 0x0651 -#define a_SUKUN 0x0652 -#define a_MADDA_ABOVE 0x0653 -#define a_HAMZA_ABOVE 0x0654 -#define a_HAMZA_BELOW 0x0655 - -#define a_PEH 0x067e -#define a_TCHEH 0x0686 -#define a_JEH 0x0698 -#define a_FKAF 0x06a9 -#define a_GAF 0x06af -#define a_FYEH 0x06cc - -#define a_s_LAM_ALEF_MADDA_ABOVE 0xfef5 -#define a_f_LAM_ALEF_MADDA_ABOVE 0xfef6 -#define a_s_LAM_ALEF_HAMZA_ABOVE 0xfef7 -#define a_f_LAM_ALEF_HAMZA_ABOVE 0xfef8 -#define a_s_LAM_ALEF_HAMZA_BELOW 0xfef9 -#define a_f_LAM_ALEF_HAMZA_BELOW 0xfefa -#define a_s_LAM_ALEF 0xfefb -#define a_f_LAM_ALEF 0xfefc +enum { + a_HAMZA = 0x0621, + a_ALEF_MADDA = 0x0622, + a_ALEF_HAMZA_ABOVE = 0x0623, + a_WAW_HAMZA = 0x0624, + a_ALEF_HAMZA_BELOW = 0x0625, + a_YEH_HAMZA = 0x0626, + a_ALEF = 0x0627, + a_BEH = 0x0628, + a_TEH_MARBUTA = 0x0629, + a_TEH = 0x062a, + a_THEH = 0x062b, + a_JEEM = 0x062c, + a_HAH = 0x062d, + a_KHAH = 0x062e, + a_DAL = 0x062f, + a_THAL = 0x0630, + a_REH = 0x0631, + a_ZAIN = 0x0632, + a_SEEN = 0x0633, + a_SHEEN = 0x0634, + a_SAD = 0x0635, + a_DAD = 0x0636, + a_TAH = 0x0637, + a_ZAH = 0x0638, + a_AIN = 0x0639, + a_GHAIN = 0x063a, + a_TATWEEL = 0x0640, + a_FEH = 0x0641, + a_QAF = 0x0642, + a_KAF = 0x0643, + a_LAM = 0x0644, + a_MEEM = 0x0645, + a_NOON = 0x0646, + a_HEH = 0x0647, + a_WAW = 0x0648, + a_ALEF_MAKSURA = 0x0649, + a_YEH = 0x064a, + a_FATHATAN = 0x064b, + a_DAMMATAN = 0x064c, + a_KASRATAN = 0x064d, + a_FATHA = 0x064e, + a_DAMMA = 0x064f, + a_KASRA = 0x0650, + a_SHADDA = 0x0651, + a_SUKUN = 0x0652, + a_MADDA_ABOVE = 0x0653, + a_HAMZA_ABOVE = 0x0654, + a_HAMZA_BELOW = 0x0655, + + a_PEH = 0x067e, + a_TCHEH = 0x0686, + a_JEH = 0x0698, + a_FKAF = 0x06a9, + a_GAF = 0x06af, + a_FYEH = 0x06cc, + + a_s_LAM_ALEF_MADDA_ABOVE = 0xfef5, + a_f_LAM_ALEF_MADDA_ABOVE = 0xfef6, + a_s_LAM_ALEF_HAMZA_ABOVE = 0xfef7, + a_f_LAM_ALEF_HAMZA_ABOVE = 0xfef8, + a_s_LAM_ALEF_HAMZA_BELOW = 0xfef9, + a_f_LAM_ALEF_HAMZA_BELOW = 0xfefa, + a_s_LAM_ALEF = 0xfefb, + a_f_LAM_ALEF = 0xfefc, +}; static struct achar { unsigned c; diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c index 5a1708a57c..19e99fa7a6 100644 --- a/src/nvim/decoration.c +++ b/src/nvim/decoration.c @@ -169,13 +169,12 @@ Decoration get_decor(mtkey_t mark) { if (mark.decor_full) { return *mark.decor_full; - } else { - Decoration fake = DECORATION_INIT; - fake.hl_id = mark.hl_id; - fake.priority = mark.priority; - fake.hl_eol = (mark.flags & MT_FLAG_HL_EOL); - return fake; } + Decoration fake = DECORATION_INIT; + fake.hl_id = mark.hl_id; + fake.priority = mark.priority; + fake.hl_eol = (mark.flags & MT_FLAG_HL_EOL); + return fake; } /// @return true if decor has a virtual position (virtual text or ui_watched) diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 503e546562..b20d0976e4 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1133,37 +1133,36 @@ static int diff_file(diffio_T *dio) // Use xdiff for generating the diff. if (dio->dio_internal) { return diff_file_internal(dio); - } else { - const size_t len = (strlen(tmp_orig) + strlen(tmp_new) + strlen(tmp_diff) - + strlen(p_srr) + 27); - char *const cmd = xmalloc(len); - - // We don't want $DIFF_OPTIONS to get in the way. - if (os_getenv("DIFF_OPTIONS")) { - os_unsetenv("DIFF_OPTIONS"); - } - - // Build the diff command and execute it. Always use -a, binary - // differences are of no use. Ignore errors, diff returns - // non-zero when differences have been found. - vim_snprintf(cmd, len, "diff %s%s%s%s%s%s%s%s %s", - diff_a_works == kFalse ? "" : "-a ", - "", - (diff_flags & DIFF_IWHITE) ? "-b " : "", - (diff_flags & DIFF_IWHITEALL) ? "-w " : "", - (diff_flags & DIFF_IWHITEEOL) ? "-Z " : "", - (diff_flags & DIFF_IBLANK) ? "-B " : "", - (diff_flags & DIFF_ICASE) ? "-i " : "", - tmp_orig, tmp_new); - append_redir(cmd, len, p_srr, tmp_diff); - block_autocmds(); // Avoid ShellCmdPost stuff - (void)call_shell((char_u *)cmd, - kShellOptFilter | kShellOptSilent | kShellOptDoOut, - NULL); - unblock_autocmds(); - xfree(cmd); - return OK; } + const size_t len = (strlen(tmp_orig) + strlen(tmp_new) + strlen(tmp_diff) + + strlen(p_srr) + 27); + char *const cmd = xmalloc(len); + + // We don't want $DIFF_OPTIONS to get in the way. + if (os_getenv("DIFF_OPTIONS")) { + os_unsetenv("DIFF_OPTIONS"); + } + + // Build the diff command and execute it. Always use -a, binary + // differences are of no use. Ignore errors, diff returns + // non-zero when differences have been found. + vim_snprintf(cmd, len, "diff %s%s%s%s%s%s%s%s %s", + diff_a_works == kFalse ? "" : "-a ", + "", + (diff_flags & DIFF_IWHITE) ? "-b " : "", + (diff_flags & DIFF_IWHITEALL) ? "-w " : "", + (diff_flags & DIFF_IWHITEEOL) ? "-Z " : "", + (diff_flags & DIFF_IBLANK) ? "-B " : "", + (diff_flags & DIFF_ICASE) ? "-i " : "", + tmp_orig, tmp_new); + append_redir(cmd, len, p_srr, tmp_diff); + block_autocmds(); // Avoid ShellCmdPost stuff + (void)call_shell((char_u *)cmd, + kShellOptFilter | kShellOptSilent | kShellOptDoOut, + NULL); + unblock_autocmds(); + xfree(cmd); + return OK; } /// Create a new version of a file from the current buffer and a diff file. diff --git a/src/nvim/edit.c b/src/nvim/edit.c index c99449e0f3..4540ddf4fe 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -87,10 +87,12 @@ typedef struct insert_state { #ifdef INCLUDE_GENERATED_DECLARATIONS # include "edit.c.generated.h" #endif -#define BACKSPACE_CHAR 1 -#define BACKSPACE_WORD 2 -#define BACKSPACE_WORD_NOT_SPACE 3 -#define BACKSPACE_LINE 4 +enum { + BACKSPACE_CHAR = 1, + BACKSPACE_WORD = 2, + BACKSPACE_WORD_NOT_SPACE = 3, + BACKSPACE_LINE = 4, +}; /// Set when doing something for completion that may call edit() recursively, /// which is not allowed. @@ -1227,9 +1229,8 @@ bool edit(int cmdchar, bool startln, long count) restart_edit = 'i'; force_restart_edit = true; return false; - } else { - return terminal_enter(); } + return terminal_enter(); } // Don't allow inserting in the sandbox. diff --git a/src/nvim/eval.c b/src/nvim/eval.c index fe4ae92834..f39cebefb2 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1942,11 +1942,10 @@ bool next_for_item(void *fi_void, char *arg) listitem_T *item = fi->fi_lw.lw_item; if (item == NULL) { return false; - } else { - fi->fi_lw.lw_item = TV_LIST_ITEM_NEXT(fi->fi_list, item); - return (ex_let_vars(arg, TV_LIST_ITEM_TV(item), true, - fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK); } + fi->fi_lw.lw_item = TV_LIST_ITEM_NEXT(fi->fi_list, item); + return (ex_let_vars(arg, TV_LIST_ITEM_TV(item), true, + fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK); } // TODO(ZyX-I): move to eval/ex_cmds @@ -7172,9 +7171,8 @@ int check_luafunc_name(const char *const str, const bool paren) const char *const p = skip_luafunc_name(str); if (*p != (paren ? '(' : NUL)) { return 0; - } else { - return (int)(p - str); } + return (int)(p - str); } /// Handle: @@ -7920,9 +7918,8 @@ static var_flavour_T var_flavour(char *varname) } } return VAR_FLAVOUR_SHADA; - } else { - return VAR_FLAVOUR_DEFAULT; } + return VAR_FLAVOUR_DEFAULT; } /// Iterate over global variables diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index 6b7eb2f8f8..f677148e08 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -284,13 +284,12 @@ typval_T decode_string(const char *const s, const size_t len, const TriState has } } return tv; - } else { - return (typval_T) { - .v_type = VAR_STRING, - .v_lock = VAR_UNLOCKED, - .vval = { .v_string = ((s == NULL || s_allocated) ? (char *)s : xmemdupz(s, len)) }, - }; } + return (typval_T) { + .v_type = VAR_STRING, + .v_lock = VAR_UNLOCKED, + .vval = { .v_string = ((s == NULL || s_allocated) ? (char *)s : xmemdupz(s, len)) }, + }; } /// Parse JSON double-quoted string diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 26a5c133da..5acc37bfb1 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -5238,10 +5238,9 @@ static void f_mkdir(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) xfree(failed_dir); rettv->vval.v_number = FAIL; return; - } else { - rettv->vval.v_number = OK; - return; } + rettv->vval.v_number = OK; + return; } } rettv->vval.v_number = vim_mkdir_emsg(dir, prot); @@ -7483,9 +7482,8 @@ static void f_serverstart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (argvars[0].v_type != VAR_STRING) { emsg(_(e_invarg)); return; - } else { - address = xstrdup(tv_get_string(argvars)); } + address = xstrdup(tv_get_string(argvars)); } else { address = server_address_new(NULL); } diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 13d836071d..e09fda173b 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1747,9 +1747,8 @@ static bool tv_dict_watcher_matches(DictWatcher *watcher, const char *const key) const size_t len = watcher->key_pattern_len; if (len && watcher->key_pattern[len - 1] == '*') { return strncmp(key, watcher->key_pattern, len - 1) == 0; - } else { - return strcmp(key, watcher->key_pattern) == 0; } + return strcmp(key, watcher->key_pattern) == 0; } /// Send a change notification to all dictionary watchers that match given key diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index ef74ca58e3..638573a235 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -2019,9 +2019,8 @@ void ex_function(exarg_T *eap) } xfree(fudi.fd_newkey); return; - } else { - eap->skip = true; } + eap->skip = true; } // An error in a function call during evaluation of an expression in magic diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index 139e7ed66b..97630d4953 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -380,9 +380,8 @@ const char *skip_var_list(const char *arg, int *var_count, int *semicolon) } } return p + 1; - } else { - return skip_var_one((char *)arg); } + return skip_var_one((char *)arg); } /// Skip one (assignable) variable name, including @r, $VAR, &option, d.key, @@ -884,9 +883,8 @@ static int do_unlet_var(lval_T *lp, char *name_end, exarg_T *eap, int deep FUNC_ lp->ll_n1++; if (lp->ll_li == NULL || (!lp->ll_empty2 && lp->ll_n2 < lp->ll_n1)) { break; - } else { - last_li = lp->ll_li; } + last_li = lp->ll_li; } tv_list_remove_items(lp->ll_list, first_li, last_li); } else { diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 89e6d47950..1b850ab425 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2137,9 +2137,8 @@ static int check_readonly(int *forceit, buf_T *buf) // Set forceit, to force the writing of a readonly file *forceit = true; return false; - } else { - return true; } + return true; } else if (buf->b_p_ro) { emsg(_(e_readonly)); } else { diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index dc2b7247f1..0c2a92ef43 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -4357,9 +4357,8 @@ char *check_nextcmd(char *p) if (*s == '|' || *s == '\n') { return s + 1; - } else { - return NULL; } + return NULL; } /// - if there are more files to edit @@ -4758,9 +4757,8 @@ static void ex_only(exarg_T *eap) for (wp = firstwin; --wnr > 0;) { if (wp->w_next == NULL) { break; - } else { - wp = wp->w_next; } + wp = wp->w_next; } } else { wp = curwin; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index c780f64a7a..414a32fab3 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -72,15 +72,17 @@ #endif #define HAS_BW_FLAGS -#define FIO_LATIN1 0x01 // convert Latin1 -#define FIO_UTF8 0x02 // convert UTF-8 -#define FIO_UCS2 0x04 // convert UCS-2 -#define FIO_UCS4 0x08 // convert UCS-4 -#define FIO_UTF16 0x10 // convert UTF-16 -#define FIO_ENDIAN_L 0x80 // little endian -#define FIO_NOCONVERT 0x2000 // skip encoding conversion -#define FIO_UCSBOM 0x4000 // check for BOM at start of file -#define FIO_ALL (-1) // allow all formats +enum { + FIO_LATIN1 = 0x01, // convert Latin1 + FIO_UTF8 = 0x02, // convert UTF-8 + FIO_UCS2 = 0x04, // convert UCS-2 + FIO_UCS4 = 0x08, // convert UCS-4 + FIO_UTF16 = 0x10, // convert UTF-16 + FIO_ENDIAN_L = 0x80, // little endian + FIO_NOCONVERT = 0x2000, // skip encoding conversion + FIO_UCSBOM = 0x4000, // check for BOM at start of file + FIO_ALL = -1, // allow all formats +}; // When converting, a read() or write() may leave some bytes to be converted // for the next call. The value is guessed... @@ -498,18 +500,17 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, return FAIL; } return OK; // a new file is not an error - } else { - filemess(curbuf, sfname, ((fd == UV_EFBIG) ? _("[File too big]") : + } + filemess(curbuf, sfname, ((fd == UV_EFBIG) ? _("[File too big]") : #if defined(UNIX) && defined(EOVERFLOW) - // libuv only returns -errno - // in Unix and in Windows - // open() does not set - // EOVERFLOW - (fd == -EOVERFLOW) ? _("[File too big]") : + // libuv only returns -errno + // in Unix and in Windows + // open() does not set + // EOVERFLOW + (fd == -EOVERFLOW) ? _("[File too big]") : #endif - _("[Permission Denied]")), 0); - curbuf->b_p_ro = true; // must use "w!" now - } + _("[Permission Denied]")), 0); + curbuf->b_p_ro = true; // must use "w!" now return FAIL; } @@ -5232,10 +5233,9 @@ static void vim_mktempdir(void) if (vim_settempdir(path)) { // Successfully created and set temporary directory so stop trying. break; - } else { - // Couldn't set `vim_tempdir` to `path` so remove created directory. - os_rmdir(path); } + // Couldn't set `vim_tempdir` to `path` so remove created directory. + os_rmdir(path); } (void)umask(umask_save); } diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 02fbbc20db..dd74971ab5 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -57,9 +57,11 @@ typedef struct { // folds too } fold_T; -#define FD_OPEN 0 // fold is open (nested ones can be closed) -#define FD_CLOSED 1 // fold is closed -#define FD_LEVEL 2 // depends on 'foldlevel' (nested folds too) +enum { + FD_OPEN = 0, // f |