From 80da028aeb7fc9f9676ed7d0c4032c0c041c287c Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 4 Jan 2026 08:18:23 -0600 Subject: [PATCH] Add linting to address #1688 Warn when defining macros on inner scopes, and also point out unused metadata as well. --- src/core/specials.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/specials.c b/src/core/specials.c index 35b06966..94a6e36c 100644 --- a/src/core/specials.c +++ b/src/core/specials.c @@ -464,12 +464,24 @@ static int varleaf( } } +static void check_metadata_lint(JanetCompiler *c, JanetTable *attr_table) { + if (!(c->scope->flags & JANET_SCOPE_TOP) && attr_table && attr_table->count) { + /* A macro is a normal lint, other metadata is a strict lint */ + if (janet_truthy(janet_table_get(attr_table, janet_ckeywordv("macro")))) { + janetc_lintf(c, JANET_C_LINT_NORMAL, "macro tag is ignored in inner scopes"); + } else { + janetc_lintf(c, JANET_C_LINT_STRICT, "unused metadata %j in inner scope", janet_wrap_table(attr_table)); + } + } +} + static JanetSlot janetc_var(JanetFopts opts, int32_t argn, const Janet *argv) { JanetCompiler *c = opts.compiler; JanetTable *attr_table = handleattr(c, "var", argn, argv); if (c->result.status == JANET_COMPILE_ERROR) { return janetc_cslot(janet_wrap_nil()); } + check_metadata_lint(c, attr_table); SlotHeadPair *into = NULL; into = dohead_destructure(c, into, opts, argv[0], argv[argn - 1]); if (c->result.status == JANET_COMPILE_ERROR) { @@ -530,6 +542,7 @@ static JanetSlot janetc_def(JanetFopts opts, int32_t argn, const Janet *argv) { if (c->result.status == JANET_COMPILE_ERROR) { return janetc_cslot(janet_wrap_nil()); } + check_metadata_lint(c, attr_table); opts.flags &= ~JANET_FOPTS_HINT; SlotHeadPair *into = NULL; into = dohead_destructure(c, into, opts, argv[0], argv[argn - 1]);