This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 7d65bf6ddef tools/nxstyle: Detect left brace not on separate line
inside functions.
7d65bf6ddef is described below
commit 7d65bf6ddef934250f7caf819103109aa90e9346
Author: Evan Rusackas <[email protected]>
AuthorDate: Thu Oct 15 13:49:30 2026 +0100
tools/nxstyle: Detect left brace not on separate line inside functions.
nxstyle's "Left bracket not on separate line" check only fired when
`!bfunctions` (i.e. outside the Private/Public Functions section of the
file). Inside a function body, `dnest` is already nonzero by the time a
declaration's own opening brace is reached (set as soon as the line's
leading type keyword is matched), so the check's `dnest == 0` escape
hatch silently disabled the rule for every local declaration.
The dnest > 0 escape was only ever meant to exempt a nested initializer
brace, e.g. `{ 1, 2 },` inside an array of structs, from needing its own
line. It should never have exempted the very first, outer brace of a
declaration's initializer just because that declaration happened to be
local to a function. Removed the escape for this check so local and
global declarations are held to the same rule.
Confirmed no regressions with a before/after nxstyle run over every
tracked .c/.h file in the tree (18,004 files): identical diagnostics
except for 44 newly-caught, genuine instances of this exact violation
(one of them drivers/sensors/nau7802.c:127, the file originally flagged
in #16367). None of nxstyle's other checks changed output.
Fixes #16246.
Fixes #16367.
Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Evan Rusackas <[email protected]>
---
tools/nxstyle.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index e84ef7ac1be..a8f681f84dd 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -3109,16 +3109,20 @@ int main(int argc, char **argv, char **envp)
{
if (n > indent)
{
- /* REVISIT: dnest is always > 0 here if bfunctions ==
- * false.
+ /* A left brace must always be on its own line,
+ * whether it opens a compound statement at file
+ * scope or inside a function body. dnest > 0
+ * only means that a nested initializer brace
+ * (e.g. "{ 1, 2 }," within an array of structs)
+ * is in progress starting at column 'indent';
+ * it must not excuse the opening brace of the
+ * declaration itself from this rule just
+ * because that declaration happens to be local
+ * to a function.
*/
- if (dnest == 0 || !bfunctions ||
- lineno == rbrace_lineno)
- {
- ERROR("Left bracket not on separate line",
lineno,
- n);
- }
+ ERROR("Left bracket not on separate line", lineno,
+ n);
}
else if (line[n + 1] != '\n')
{