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 <benmmeadors@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
This commit is contained in:
co-authored by
GitHub
Ben Meadors
Copilot Autofix powered by AI
Jonathan Bennett
parent
d8884125b6
commit
de545462b0
+68
-1
@@ -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<path>.+):(?P<line>\d+):(?P<col>\d+):(?P<severity>\w+):(?P<message>.+):(?P<code>[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
|
||||
|
||||
Executable
+37
@@ -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
|
||||
# <path>:<line>:<col>:<severity>:<message>:<code>
|
||||
# which trunk parses via parse_regex. Always exits 0; findings go to stdout.
|
||||
#
|
||||
# Usage: lint-ifdef-complexity.sh <file> [<file> ...]
|
||||
# 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
|
||||
}
|
||||
}
|
||||
' "$@"
|
||||
Reference in New Issue
Block a user