From de545462b0d118c36a61254344fa7a335c4ceb74 Mon Sep 17 00:00:00 2001 From: Tom <116762865+NomDeTom@users.noreply.github.com> Date: Tue, 30 Jun 2026 18:44:02 +0100 Subject: [PATCH] Cleanup (#10801) * emdash begone * too many defines * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * even trunk doesn't like trunk.yaml --------- Co-authored-by: Ben Meadors Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jonathan Bennett --- .trunk/trunk.yaml | 69 +++++++++++++++++++++++++++++++++++- bin/lint-ifdef-complexity.sh | 37 +++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100755 bin/lint-ifdef-complexity.sh diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 88b0f51d4..421282dff 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -7,7 +7,68 @@ plugins: ref: v1.10.0 uri: https://github.com/trunk-io/plugins lint: + # Custom file set + formatter that rewrites Unicode em-dash (U+2014, UTF-8 + # bytes e2 80 94) and en-dash (U+2013, UTF-8 bytes e2 80 93) to an ASCII + # hyphen. The sed pattern matches the byte sequences under LC_ALL=C rather + # than literal characters on purpose, so the rule survives editors/hooks + # that themselves strip Unicode dashes. These dashes only ever appear in + # comments and log/error strings (LLM-authored prose), never in code, so + # the rewrite is purely cosmetic. Runs under `trunk fmt`; enforced by + # `trunk check` and the trunk-fmt-pre-commit action. + files: + - name: ascii-dash-targets + extensions: + - c + - cc + - cpp + - h + - hpp + - ino + - md + - py + - sh + - yaml + - yml + - json + - toml + - ini + - name: cpp-sources + extensions: + - c + - cc + - cpp + - cxx + - h + - hh + - hpp + - hxx + - ino + definitions: + - name: ascii-dash + files: [ascii-dash-targets] + commands: + - name: format + output: rewrite + formatter: true + run: env LC_ALL=C sed -e 's/\xe2\x80\x94/-/g' -e 's/\xe2\x80\x93/-/g' ${target} + success_codes: [0] + # Flags preprocessor conditionals that contain too many defined() terms + # (e.g. the 13-driver display chains in main.cpp). The compiler has no + # warning for this; the fix is an umbrella feature macro (HAS_TFT / + # HAS_SCREEN, already in src/configuration.h). Tune the limit via + # MAX_DEFINED in bin/lint-ifdef-complexity.sh (default 5 -> warns at 6+). + - name: too-many-defined + files: [cpp-sources] + commands: + - name: lint + output: regex + parse_regex: (?P.+):(?P\d+):(?P\d+):(?P\w+):(?P.+):(?P[a-z-]+) + run: bin/lint-ifdef-complexity.sh ${target} + success_codes: [0] + read_output_from: stdout enabled: + - ascii-dash@SYSTEM + - too-many-defined@SYSTEM - checkov@3.2.529 - renovate@43.150.0 - prettier@3.8.3 @@ -36,11 +97,17 @@ lint: - bin/** # Fake-NodeDB fixture JSONL files contain deterministic synthetic # public_key_hex (64-char hex) values that gitleaks misidentifies as - # generic-api-key. These are not secrets — they're test fixtures + # generic-api-key. These are not secrets - they're test fixtures # produced by bin/gen-fake-nodedb-seed.py with a fixed RNG seed. - linters: [gitleaks] paths: - test/fixtures/nodedb/seed_v25_*.jsonl + # The UA font's em/en dashes live only in trailing comments documenting + # each glyph's codepoint (e.g. "8212=:2549"); rewriting them would make + # those docs inaccurate. Glyph byte data is unaffected either way. + - linters: [ascii-dash] + paths: + - src/graphics/fonts/** runtimes: enabled: - python@3.14.4 diff --git a/bin/lint-ifdef-complexity.sh b/bin/lint-ifdef-complexity.sh new file mode 100755 index 000000000..b42c7d068 --- /dev/null +++ b/bin/lint-ifdef-complexity.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# lint-ifdef-complexity.sh - flag preprocessor conditionals that OR together +# too many defined() terms (e.g. long display-driver chains in main.cpp). +# +# Such chains should be replaced by a single umbrella feature macro computed +# once in a central header (this repo already has HAS_TFT / HAS_SCREEN in +# src/configuration.h). The compiler has no warning for this, so we lint it. +# +# Emits one line per offending logical #if/#elif in the format +# ::::: +# which trunk parses via parse_regex. Always exits 0; findings go to stdout. +# +# Usage: lint-ifdef-complexity.sh [ ...] +# Tune the limit with MAX_DEFINED (default 5 → warns at 6+ terms). + +set -euo pipefail + +MAX_DEFINED="${MAX_DEFINED:-5}" + +awk -v max="${MAX_DEFINED}" ' + # Start of a #if / #elif (but not #ifdef / #ifndef, which carry one term). + /^[[:space:]]*#[[:space:]]*(if|elif)([[:space:](]|$)/ { + startln = FNR + logical = $0 + # Splice backslash line-continuations into one logical line. + while (logical ~ /\\[[:space:]]*$/ && (getline nxt) > 0) { + sub(/\\[[:space:]]*$/, "", logical) + logical = logical " " nxt + } + tmp = logical + n = gsub(/defined/, "", tmp) # gsub returns the match count + if (n > max) { + printf "%s:%d:1:warning:preprocessor conditional ORs %d defined() terms (limit %d); replace the driver list with an umbrella feature macro such as HAS_TFT or HAS_SCREEN:too-many-defined\n", \ + FILENAME, startln, n, max + } + } +' "$@"