From 6d9107b360894c1025f4d459bee11f0443e489d1 Mon Sep 17 00:00:00 2001 From: javalsai Date: Wed, 27 Aug 2025 19:47:19 +0200 Subject: [PATCH] lint: stricter casing rules --- .clang-tidy | 4 ++++ include/config.h | 10 +++++----- include/keys.h | 4 ++-- include/pam.h | 2 +- include/sessions.h | 4 ++-- include/ui.h | 4 ++-- include/ui_state.h | 4 ++-- include/util.h | 4 ++-- src/config.c | 4 ++-- src/pam.c | 4 ++-- src/sessions.c | 4 ++-- src/ui.c | 6 +++--- src/ui_state.c | 4 ++-- src/util.c | 8 ++++---- 14 files changed, 35 insertions(+), 31 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index ab01ac3..39c2af4 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -30,6 +30,10 @@ CheckOptions: - key: readability-identifier-naming.ConstantCase value: "UPPER_CASE" + - key: readability-identifier-naming.EnumCase + value: "CamelCase" + - key: readability-identifier-naming.FunctionCase + value: "lower_case" - key: readability-identifier-length.VariableThreshold value: "2" diff --git a/include/config.h b/include/config.h index 2b120a9..ffc9657 100644 --- a/include/config.h +++ b/include/config.h @@ -8,7 +8,7 @@ #include "macros.h" #include "util.h" -enum introspection_type { +enum IntrospectionType { STRING, BOOL, NUMBER, @@ -26,7 +26,7 @@ static const char* NNULLABLE const INTROS_TYS_NAMES[] = { struct introspection_item { char* NNULLABLE name; size_t offset; - enum introspection_type typ; + enum IntrospectionType typ; }; #define INTROS_ITEM(key, table, ty) \ @@ -90,9 +90,9 @@ BUILD(colors, COLORS, TABLE_COLORS); BUILD(chars, CHARS, TABLE_CHARS); #define TABLE_FUNCTIONS(F, name) \ - F(enum keys, poweroff, KEY, F1, name) \ - F(enum keys, reboot, KEY, F2, name) \ - F(enum keys, refresh, KEY, F5, name) + F(enum Keys, poweroff, KEY, F1, name) \ + F(enum Keys, reboot, KEY, F2, name) \ + F(enum Keys, refresh, KEY, F5, name) BUILD(functions, FUNCTIONS, TABLE_FUNCTIONS); diff --git a/include/keys.h b/include/keys.h index 8b37764..391c477 100644 --- a/include/keys.h +++ b/include/keys.h @@ -3,7 +3,7 @@ #include -enum keys { +enum Keys { ESC, F1, F2, @@ -66,7 +66,7 @@ static const char* const KEY_NAMES[] = { }; struct key_mapping { - enum keys key; + enum Keys key; const char* sequences[3]; }; diff --git a/include/pam.h b/include/pam.h index dc03299..ccc1604 100644 --- a/include/pam.h +++ b/include/pam.h @@ -26,7 +26,7 @@ struct pamh_getenv_status { struct pamh_getenv_status pamh_get_complete_env(pam_handle_t* handle, char* NNULLABLE user, struct passwd* NNULLABLE pw, - enum session_type session_typ); + enum SessionType session_typ); void free_envlist(char** NNULLABLE envlist); pam_handle_t* NULLABLE get_pamh(char* NNULLABLE user, char* NNULLABLE passwd); diff --git a/include/sessions.h b/include/sessions.h index d10eaee..e7b5210 100644 --- a/include/sessions.h +++ b/include/sessions.h @@ -6,7 +6,7 @@ #include "macros.h" #include "util.h" -enum session_type { +enum SessionType { XORG, WAYLAND, SHELL, @@ -16,7 +16,7 @@ struct session { char* NNULLABLE name; char* NNULLABLE exec; char* NULLABLE tryexec; - enum session_type type; + enum SessionType type; }; struct Vector get_avaliable_sessions(); diff --git a/include/ui.h b/include/ui.h index d37df95..5ea13d8 100644 --- a/include/ui.h +++ b/include/ui.h @@ -39,7 +39,7 @@ #define VALUES_SEPR 3 #define VALUE_MAXLEN (BOX_WIDTH - VALUES_COL + 1 - BOX_HMARGIN - 2) -enum input { SESSION, USER, PASSWD }; +enum Input { SESSION, USER, PASSWD }; extern const u_char INPUTS_N; void setup(struct config* config); @@ -47,7 +47,7 @@ int load(struct Vector* users, struct Vector* sessions); void print_err(const char* /*msg*/); void print_errno(const char* /*descr*/); -void ui_update_field(enum input focused_input); +void ui_update_field(enum Input focused_input); void ui_update_ffield(); void ui_update_ofield(struct opts_field* self); void ui_update_cursor_focus(); diff --git a/include/ui_state.h b/include/ui_state.h index 52e6df4..cde6e76 100644 --- a/include/ui_state.h +++ b/include/ui_state.h @@ -6,7 +6,7 @@ #include "macros.h" #include "ui.h" -extern enum input focused_input; +extern enum Input focused_input; extern struct opts_field of_session; extern struct opts_field of_user; @@ -15,7 +15,7 @@ extern struct opts_field of_passwd; extern struct Vector* UNULLABLE gusers; extern struct Vector* UNULLABLE gsessions; -struct opts_field* NNULLABLE get_opts_field(enum input from); +struct opts_field* NNULLABLE get_opts_field(enum Input from); struct opts_field* NNULLABLE get_opts_ffield(); struct user st_user(); diff --git a/include/util.h b/include/util.h index 233e563..35e049a 100644 --- a/include/util.h +++ b/include/util.h @@ -10,8 +10,8 @@ #include "keys.h" -int find_keyname(enum keys* at, const char* name); -enum keys find_ansi(const char* seq); +int find_keyname(enum Keys* at, const char* name); +enum Keys find_ansi(const char* seq); void read_press(u_char* length, char* out); // non blocking, waits up to tv or interrupt, returns true if actually read bool read_press_nb(u_char* length, char* out, struct timeval* tv); diff --git a/src/config.c b/src/config.c index 3c9e7ea..f9aba1a 100644 --- a/src/config.c +++ b/src/config.c @@ -117,11 +117,11 @@ union typ_ptr { char** string; long long* number; bool* boolean; - enum keys* key; + enum Keys* key; struct Vector* vec; uintptr_t ptr; }; -struct parser_error parse_key(enum introspection_type typ, union typ_ptr at, +struct parser_error parse_key(enum IntrospectionType typ, union typ_ptr at, char* key, size_t offset) { char* aux_str = NULL; struct parser_error aux_err; diff --git a/src/pam.c b/src/pam.c index 8802a1d..ddcf976 100644 --- a/src/pam.c +++ b/src/pam.c @@ -68,7 +68,7 @@ free_new_envlist_extra: return NULL; } -char* NULLABLE xdg_ssession_type_str(enum session_type typ) { +char* NULLABLE xdg_ssession_type_str(enum SessionType typ) { char* xdg_session_type = NULL; if (typ == SHELL) xdg_session_type = "tty"; if (typ == XORG) xdg_session_type = "x11"; @@ -91,7 +91,7 @@ char* NULLABLE xdg_ssession_type_str(enum session_type typ) { struct pamh_getenv_status pamh_get_complete_env(pam_handle_t* handle, char* NNULLABLE user, struct passwd* NNULLABLE pw, - enum session_type session_typ) { + enum SessionType session_typ) { struct pamh_getenv_status status; char** envlist = pam_getenvlist(handle); if (!envlist) FAIL(status, PAMH_ERR_ERRNO, "pam_getenvlist"); diff --git a/src/sessions.c b/src/sessions.c index 4d36bc5..260c4fb 100644 --- a/src/sessions.c +++ b/src/sessions.c @@ -13,7 +13,7 @@ #include "util.h" struct source_dir { - enum session_type type; + enum SessionType type; char* dir; }; @@ -72,7 +72,7 @@ struct status cb(void* _ctx, char* NULLABLE table, char* key, char* value) { // also, always return 0 or we will break parsing and we don't want a bad // desktop file to break all possible sessions -static enum session_type session_type; +static enum SessionType session_type; // NOLINTNEXTLINE(readability-function-cognitive-complexity) static int fn(const char* fpath, const struct stat* sb, int typeflag) { // guessing symlink behavior diff --git a/src/ui.c b/src/ui.c index 4bc5512..05bda97 100644 --- a/src/ui.c +++ b/src/ui.c @@ -151,7 +151,7 @@ void ui_update_cursor_focus() { (void)printf("\x1b[%d;%dH", line, col); } -void ui_update_field(enum input focused_input) { +void ui_update_field(enum Input focused_input) { if (focused_input == PASSWD) { print_passwd(utf8len(of_passwd.efield.content), false); } else if (focused_input == SESSION) { @@ -170,7 +170,7 @@ void ui_update_ffield() { } void ui_update_ofield(struct opts_field* NNULLABLE self) { - enum input input; + enum Input input; if (self == &of_session) input = SESSION; else if (self == &of_user) @@ -280,7 +280,7 @@ int load(struct Vector* users, struct Vector* sessions) { (void)fflush(stdout); if (!read_press_nb(&len, seq, &tv)) continue; if (*seq == '\x1b') { - enum keys ansi_code = find_ansi(seq); + enum Keys ansi_code = find_ansi(seq); if (ansi_code != -1) { if (ansi_code == ESC) { esc = 2; diff --git a/src/ui_state.c b/src/ui_state.c index 18e1b09..d701a4c 100644 --- a/src/ui_state.c +++ b/src/ui_state.c @@ -4,7 +4,7 @@ #include "ui.h" #include "users.h" -enum input focused_input = PASSWD; +enum Input focused_input = PASSWD; struct Vector* gusers; struct Vector* gsessions; @@ -13,7 +13,7 @@ struct opts_field of_session; struct opts_field of_user; struct opts_field of_passwd; -struct opts_field* NNULLABLE get_opts_field(enum input from) { +struct opts_field* NNULLABLE get_opts_field(enum Input from) { if (from == SESSION) return &of_session; if (from == USER) return &of_user; if (from == PASSWD) return &of_passwd; diff --git a/src/util.c b/src/util.c index 33a4330..819f4f1 100644 --- a/src/util.c +++ b/src/util.c @@ -13,10 +13,10 @@ static int selret_magic(); -int find_keyname(enum keys* at, const char* name) { +int find_keyname(enum Keys* at, const char* name) { for (size_t i = 0; i < LEN(KEY_MAPPINGS); i++) { if (strcmp(KEY_NAMES[i], name) == 0) { - *at = (enum keys)i; + *at = (enum Keys)i; return 0; } } @@ -24,12 +24,12 @@ int find_keyname(enum keys* at, const char* name) { return -1; } -enum keys find_ansi(const char* seq) { +enum Keys find_ansi(const char* seq) { for (size_t i = 0; i < LEN(KEY_MAPPINGS); i++) { struct key_mapping mapping = KEY_MAPPINGS[i]; for (size_t j = 0; mapping.sequences[j] != NULL; j++) { if (strcmp(mapping.sequences[j], seq) == 0) { - return (enum keys)i; + return (enum Keys)i; } } }