Skip to content

tools/nxstyle: fix most of the incompatibilities with the coding standard - #19555

Open
raiden00pl wants to merge 8 commits into
apache:masterfrom
raiden00pl:nxstyle_fixes
Open

tools/nxstyle: fix most of the incompatibilities with the coding standard#19555
raiden00pl wants to merge 8 commits into
apache:masterfrom
raiden00pl:nxstyle_fixes

Conversation

@raiden00pl

Copy link
Copy Markdown
Member

Summary

This PR fixes a lot of gaps in the nxstyle tool. Unfortunately, the codebase contains many inconsistencies with the coding standard. Fixing everything might mess up git history a bit, so I'm not sure if it's worth it.

For now I only fixed nxstyle.c, sched, audio and net

Impact

better compatibility with nuttx coding style.

This solves some of the issues related to nxstyle, but I didn't check which ones: https://github.com/apache/nuttx/issues?q=is%3Aissue%20state%3Aopen%20nxstyle

Testing

Output from /tools/nxstyle_sweep.sh that checks all files:

nxstyle-errors.txt:  101060 diagnostics                    
nxstyle-files.txt: 2690 files

Checked 17165 files, 2690 failed

@github-actions github-actions Bot added Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Area: Audio labels Jul 27, 2026
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

arduino-mega2560

  • flash: .text +108 B (+0.2%, 64,394 B / 262,144 B, total: 25% used)

esp32-devkitc

  • ROM: .flash.text +80 B (+0.1%, 124,476 B / 4,194,272 B, total: 3% used)
  • irom0_0_seg: .flash.text +80 B (+0.1%, 88,680 B / 3,342,304 B, total: 3% used)

hifive1-revb

  • flash: .text +68 B (+0.1%, 83,376 B / 4,194,304 B, total: 2% used)

mirtoo

  • kseg0_progmem: .text +132 B (+0.2%, 67,008 B / 131,072 B, total: 51% used)

rx65n-rsk2mb

  • ROM: .text +64 B (+0.1%, 86,496 B / 2,097,152 B, total: 4% used)

s698pm-dkit

  • Code: .text +240 B (+0.1%, 363,648 B)

stm32-nucleo-f103rb

  • flash: .text +76 B (+0.2%, 34,116 B / 131,072 B, total: 26% used)
    No memory changes detected for:
  • qemu-armv8a
  • qemu-intel64

jerpelea
jerpelea previously approved these changes Jul 28, 2026
@acassis

acassis commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

@raiden00pl please fix conflict

@raiden00pl

Copy link
Copy Markdown
Member Author

I'll be adding changes to nxstyle in separate PRs. I'm still unsure whether to fix all the nxstyle upstream issues, or leave it for the future and fix it step by step.

jerpelea
jerpelea previously approved these changes Aug 21, 2026
Only lines beginning with a C keyword were checked, so an assignment or
a call could sit at any column.

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
@JianyuWang0623

JianyuWang0623 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

While debugging a CI failure on an unrelated PR (apache/nuttx-apps#3751), I found a false positive in the Bad left brace alignment check that the regression-introducing commit bdeb262b8d3 ("tools/nxstyle: indent code against its enclosing brace, not modulo 4") added, and confirmed this PR already fixes it.

Root cause: the exemption for a macro-that-takes-a-block (e.g. list_for_every_entry(...)) only compares against prevcodeindent (the indentation of the previous line):

else if (prevlastcode == ')' && indent == prevcodeindent + 2)
  {
  }

When the macro call wraps its arguments onto a continuation line, prevcodeindent becomes the indentation of that continuation line instead of the line where the macro call started, so the exemption never matches and the brace is flagged.

Minimal repro (built master's tools/nxstyle.c as of this comment, nxstyle repro.c):

void add_ready(FAR struct action_manager_s *am,
                FAR struct action_s *ready)
{
  list_for_every_entry(&am->ready_actions, ready, struct action_s,
                        ready_node)
    {
      do_something(ready);
    }
}
$ ./nxstyle repro.c
repro.c:19:4: error: Bad left brace alignment

This isn't an isolated case — the same false positive currently fires on existing, unmodified code such as drivers/vhost/vhost.c on master.

I confirmed this branch (nxstyle_fixes) already resolves it. The relevant change extends the exemption with a second alternative, stmt_lineindent + 2, which covers the continuation-line case:

else if (prevlastcode == ')' &&
         (indent == prevcodeindent + 2 ||
          indent == stmt_lineindent + 2))
  {
  }
$ ./nxstyle repro.c   # built from this branch
$ echo $?
0

Given the scope of this PR is large and it currently has merge conflicts against master, would it be worth splitting out just the nxstyle.c fix (or at least this specific brace-alignment exemption) into its own smaller PR so the regression can be addressed independently? Happy to help if useful.

cederom
cederom previously approved these changes Aug 24, 2026

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @raiden00pl looks like this one is really important and welcome as it fixes CI checks in PRs that does not touch the impacted parts :-)

The brace was compared against the line before it rather than the line
the statement began on, so a macro broken over two lines was reported.

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
The fixed list of type names holds neither uint64_t nor any NuttX
typedef, so declarations using them went unchecked.

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
The standard asks for a blank line between the local declarations at the
head of a function and the code.  A declaration is recognised by its
shape, since no list of type names can be complete.

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
…races

Alternatives selected by conditional compilation share the braces that
follow, and a branch may hold statements before reaching its condition.

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
fix nxstyle errors for sched

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
fix nxstyle errors for audio

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
fix nxstyle errors for net

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
@raiden00pl

Copy link
Copy Markdown
Member Author

@JianyuWang0623 the fix for this should be in 7ead748

I created PR for this commit: #19955 but first #19934 must be merged

@raiden00pl
raiden00pl dismissed stale reviews from cederom and jerpelea via f50b1ad August 24, 2026 16:40
@cederom

cederom commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

@JianyuWang0623 the fix for this should be in 7ead748

I created PR for this commit: #19955 but first #19934 must be merged

#19934 is now merged :-)

@raiden00pl
raiden00pl marked this pull request as ready for review August 24, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Audio Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants