Skip to content

Commit 2672dbb

Browse files
style(k8s): apply clang-format to k8s and infra-pass source files
- Fix alignment violations in extract_k8s.c, pass_k8s.c, pass_infrascan.c - Fix spacing in language.c filename table rows (kustomization.yml entry) - Fix alignment in cbm.h CBMLanguage enum comments - Fix pipeline.c empty-body brace style Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ba1b915 commit 2672dbb

6 files changed

Lines changed: 39 additions & 33 deletions

File tree

internal/cbm/cbm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ typedef enum {
7575
CBM_LANG_FORM,
7676
CBM_LANG_MAGMA,
7777
CBM_LANG_WOLFRAM,
78-
CBM_LANG_KUSTOMIZE, // kustomization.yaml — Kubernetes overlay tool
79-
CBM_LANG_K8S, // Generic Kubernetes manifest (apiVersion: detected)
78+
CBM_LANG_KUSTOMIZE, // kustomization.yaml — Kubernetes overlay tool
79+
CBM_LANG_K8S, // Generic Kubernetes manifest (apiVersion: detected)
8080
CBM_LANG_COUNT
8181
} CBMLanguage;
8282

internal/cbm/extract_k8s.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ static int is_kustomize_list_key(const char *key) {
6666

6767
// Walk a block_sequence node and emit one CBMImport per block_sequence_item
6868
// scalar child, using key_name as the local_name.
69-
static void emit_kustomize_sequence(CBMExtractCtx *ctx, TSNode seq_node,
70-
const char *key_name) {
69+
static void emit_kustomize_sequence(CBMExtractCtx *ctx, TSNode seq_node, const char *key_name) {
7170
CBMArena *a = ctx->arena;
7271
uint32_t n = ts_node_child_count(seq_node);
7372
for (uint32_t i = 0; i < n; i++) {
@@ -84,7 +83,7 @@ static void emit_kustomize_sequence(CBMExtractCtx *ctx, TSNode seq_node,
8483
continue;
8584
}
8685
CBMImport imp = {
87-
.local_name = cbm_arena_strdup(a, key_name),
86+
.local_name = cbm_arena_strdup(a, key_name),
8887
.module_path = cbm_arena_strdup(a, scalar),
8988
};
9089
cbm_imports_push(&ctx->result->imports, a, imp);
@@ -157,11 +156,10 @@ static void extract_kustomize(CBMExtractCtx *ctx) {
157156

158157
// Descend into the first block_mapping of a document and extract apiVersion,
159158
// kind, and metadata.name. Returns void; fills kind_buf and meta_name_buf.
160-
static void extract_k8s_scalars(CBMExtractCtx *ctx, TSNode mapping,
161-
char *kind_buf, size_t kind_sz,
162-
char *meta_name_buf, size_t meta_sz) {
159+
static void extract_k8s_scalars(CBMExtractCtx *ctx, TSNode mapping, char *kind_buf, size_t kind_sz,
160+
char *meta_name_buf, size_t meta_sz) {
163161
CBMArena *a = ctx->arena;
164-
kind_buf[0] = '\0';
162+
kind_buf[0] = '\0';
165163
meta_name_buf[0] = '\0';
166164

167165
uint32_t n = ts_node_child_count(mapping);
@@ -255,7 +253,7 @@ static void extract_k8s_manifest(CBMExtractCtx *ctx) {
255253
continue;
256254
}
257255

258-
char kind_buf[256] = {0};
256+
char kind_buf[256] = {0};
259257
char meta_name_buf[256] = {0};
260258
extract_k8s_scalars(ctx, mapping, kind_buf, sizeof(kind_buf), meta_name_buf,
261259
sizeof(meta_name_buf));
@@ -269,12 +267,12 @@ static void extract_k8s_manifest(CBMExtractCtx *ctx) {
269267
snprintf(def_name, sizeof(def_name), "%s/%s", kind_buf, meta_name_buf);
270268

271269
CBMDefinition def = {0};
272-
def.name = cbm_arena_strdup(a, def_name);
270+
def.name = cbm_arena_strdup(a, def_name);
273271
def.qualified_name = cbm_arena_sprintf(a, "%s.%s", ctx->module_qn, def_name);
274-
def.label = "Resource";
275-
def.file_path = ctx->rel_path;
276-
def.start_line = ts_node_start_point(mapping).row + 1;
277-
def.end_line = ts_node_end_point(mapping).row + 1;
272+
def.label = "Resource";
273+
def.file_path = ctx->rel_path;
274+
def.start_line = ts_node_start_point(mapping).row + 1;
275+
def.end_line = ts_node_end_point(mapping).row + 1;
278276
cbm_defs_push(&ctx->result->defs, a, def);
279277

280278
break; // Only the first document per file

src/discover/language.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,16 @@ typedef struct {
269269
} filename_entry_t;
270270

271271
static const filename_entry_t FILENAME_TABLE[] = {
272-
{"CMakeLists.txt", CBM_LANG_CMAKE}, {"Dockerfile", CBM_LANG_DOCKERFILE},
273-
{"GNUmakefile", CBM_LANG_MAKEFILE}, {"Makefile", CBM_LANG_MAKEFILE},
274-
{"makefile", CBM_LANG_MAKEFILE}, {"meson.build", CBM_LANG_MESON},
275-
{"meson.options", CBM_LANG_MESON}, {"meson_options.txt", CBM_LANG_MESON},
272+
{"CMakeLists.txt", CBM_LANG_CMAKE},
273+
{"Dockerfile", CBM_LANG_DOCKERFILE},
274+
{"GNUmakefile", CBM_LANG_MAKEFILE},
275+
{"Makefile", CBM_LANG_MAKEFILE},
276+
{"makefile", CBM_LANG_MAKEFILE},
277+
{"meson.build", CBM_LANG_MESON},
278+
{"meson.options", CBM_LANG_MESON},
279+
{"meson_options.txt", CBM_LANG_MESON},
276280
{"kustomization.yaml", CBM_LANG_KUSTOMIZE},
277-
{"kustomization.yml", CBM_LANG_KUSTOMIZE},
281+
{"kustomization.yml", CBM_LANG_KUSTOMIZE},
278282
{".vimrc", CBM_LANG_VIMSCRIPT},
279283
};
280284

@@ -348,7 +352,7 @@ static const char *LANG_NAMES[CBM_LANG_COUNT] = {
348352
[CBM_LANG_MAGMA] = "Magma",
349353
[CBM_LANG_WOLFRAM] = "Wolfram",
350354
[CBM_LANG_KUSTOMIZE] = "Kustomize",
351-
[CBM_LANG_K8S] = "Kubernetes",
355+
[CBM_LANG_K8S] = "Kubernetes",
352356
};
353357

354358
/* ── Public API ──────────────────────────────────────────────────── */

src/pipeline/pass_infrascan.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,24 @@ bool cbm_is_env_file(const char *name) {
193193
}
194194

195195
bool cbm_is_kustomize_file(const char *name) {
196-
if (!name) { return false; }
196+
if (!name) {
197+
return false;
198+
}
197199
char lower[256];
198200
to_lower(name, lower, sizeof(lower));
199-
return (strcmp(lower, "kustomization.yaml") == 0 ||
200-
strcmp(lower, "kustomization.yml") == 0);
201+
return (strcmp(lower, "kustomization.yaml") == 0 || strcmp(lower, "kustomization.yml") == 0);
201202
}
202203

203204
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
204205
bool cbm_is_k8s_manifest(const char *name, const char *content) {
205-
if (!name || !content || cbm_is_kustomize_file(name)) { return false; }
206+
if (!name || !content || cbm_is_kustomize_file(name)) {
207+
return false;
208+
}
206209
char buf[4097];
207210
size_t n = strlen(content);
208-
if (n > 4096) { n = 4096; }
211+
if (n > 4096) {
212+
n = 4096;
213+
}
209214
memcpy(buf, content, n);
210215
buf[n] = '\0';
211216
return ci_strstr(buf, "apiVersion:") != NULL;

src/pipeline/pass_k8s.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ static void handle_kustomize(cbm_pipeline_ctx_t *ctx, const char *path, const ch
8282
}
8383

8484
// NOLINTNEXTLINE(misc-include-cleaner)
85-
int64_t mod_id =
86-
cbm_gbuf_upsert_node(ctx->gbuf, "Module", k8s_basename(rel_path), mod_qn, rel_path, 1, 0,
87-
"{\"source\":\"kustomize\"}");
85+
int64_t mod_id = cbm_gbuf_upsert_node(ctx->gbuf, "Module", k8s_basename(rel_path), mod_qn,
86+
rel_path, 1, 0, "{\"source\":\"kustomize\"}");
8887
free(mod_qn);
8988

9089
if (mod_id <= 0) {
@@ -220,9 +219,8 @@ int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files,
220219
CBMLanguage lang = files[i].language;
221220
const char *base = k8s_basename(rel);
222221

223-
CBMFileResult *cached = (ctx->result_cache && ctx->result_cache[i])
224-
? ctx->result_cache[i]
225-
: NULL;
222+
CBMFileResult *cached =
223+
(ctx->result_cache && ctx->result_cache[i]) ? ctx->result_cache[i] : NULL;
226224

227225
if (cbm_is_kustomize_file(base)) {
228226
handle_kustomize(ctx, path, rel, cached);

src/pipeline/pipeline.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ int cbm_pipeline_run(cbm_pipeline_t *p) {
520520

521521
cbm_clock_gettime(CLOCK_MONOTONIC, &t);
522522
rc = cbm_pipeline_pass_k8s(&ctx, files, file_count);
523-
if (rc != 0) { /* log warning, continue */ }
523+
if (rc != 0) { /* log warning, continue */
524+
}
524525
cbm_log_info("pass.timing", "pass", "k8s", "elapsed_ms", itoa_buf((int)elapsed_ms(t)));
525526
if (check_cancel(p)) {
526527
rc = -1;

0 commit comments

Comments
 (0)