Skip to content

Feat/formatting#3

Merged
andy9a9 merged 4 commits intomainfrom
feat/formatting
Jan 7, 2026
Merged

Feat/formatting#3
andy9a9 merged 4 commits intomainfrom
feat/formatting

Conversation

@andy9a9
Copy link
Copy Markdown
Owner

@andy9a9 andy9a9 commented Oct 25, 2025

  • extend extension by formatting feature
    • use 80 chars as a default line length
      • show warnings for longer lines with comments
    • 8 tabs or 8 spaces
  • format whole document only
    • maybe add range support in the future
    • try to use Linux DeviceTree standard for indents, comments, arrays, ...
      • tested on common setup, but there could be some issues for sure due to lack of tested variants :)
  • add formatting unit-tests

@andy9a9 andy9a9 requested a review from mkessler001 October 25, 2025 18:09
@andy9a9
Copy link
Copy Markdown
Owner Author

andy9a9 commented Oct 25, 2025

Local OSX tests are ok:

DeviceTree Extension Test Suite
    ✔ Extension should be present
    ✔ Extension should activate
    Language Support Tests
      ✔ DeviceTree language should be registered
      ✔ DeviceTree files should be recognized
    Formatter Tests
      ✔ formats input.dts with tabs
      ✔ formats input.dts with spaces
  6 passing (39ms)

Windows has to be evaluated ...

// EDIT: fixed by enforcing line endings to LF

@andy9a9 andy9a9 force-pushed the feat/formatting branch 2 times, most recently from c1c5196 to 065a9b2 Compare November 4, 2025 09:24
Copy link
Copy Markdown
Collaborator

@mkessler001 mkessler001 left a comment

Choose a reason for hiding this comment

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

I added some comments.
Another thing that came to my mind: wouldn't it be possible to show warnings BEFORE a file is formatted?

Comment thread src/dts.ts Outdated
Comment thread src/formatter.ts
Comment thread src/dts.ts Outdated
Comment thread src/test/extension.test.ts Outdated
@andy9a9 andy9a9 force-pushed the feat/formatting branch 2 times, most recently from f310d60 to 7a71194 Compare November 15, 2025 13:19
@andy9a9 andy9a9 requested a review from mkessler001 November 15, 2025 13:22
Comment thread src/test/diagnostics.test.ts
Comment thread src/test/diagnostics.test.ts
Comment thread src/test/formatter.test.ts
@mkessler001
Copy link
Copy Markdown
Collaborator

One last thing before we merge this: Should the comment block at the end of a line also be considered for its length?
Let's say we specify the max. line length with 80, and we have the following line:

	pinctrl_ctrl_sleep_moci: ctrlsleepmocigrp {
		fsl,pins =
			<MX8MP_IOMUXC_SAI3_RXC__GPIO4_IO29		0x1c4>;	/* SODIMM 256 */
	}

The semicolon is in character position 79, and the space is in position 80. However, the diagnosis shows a warning as the line exceeds 80 characters (current 97). Is that valid?

@andy9a9
Copy link
Copy Markdown
Owner Author

andy9a9 commented Jan 3, 2026

	pinctrl_ctrl_sleep_moci: ctrlsleepmocigrp {
		fsl,pins =
			<MX8MP_IOMUXC_SAI3_RXC__GPIO4_IO29		0x1c4>;	/* SODIMM 256 */
	}

The semicolon is in character position 79, and the space is in position 80. However, the diagnosis shows a warning as the line exceeds 80 characters (current 97). Is that valid?

I think so it's correct, because...

/dts-v1/;

/ {
<tab8><tab8>pinctrl_ctrl_sleep_moci: ctrlsleepmocigrp { // line length: 8 + 8 + 23 + 1 +1 + 16 + 1 + = 59 (60)
<tab8><tab8>fsl,pins = // line length: 8 + 8 + 8 + 1 + 1 = 26 (27)
<tab8><tab8><tab8><MX8MP_IOMUXC_SAI3_RXC__GPIO4_IO29<tab6><tab8>0x1c4>;<tab1>/* SODIMM 256 */ // line length: 8 + 8 + 8 + 1 + 33 + 6 + 8 + 5 + 1 + 1 + 1 + 16 = 96 (97)
<tab8>} // line length: 8 + 1 = 9 (10)
};

So I would say yes, diagnostic is showing the correct number :). And of course if you change it to spaces, then the number is re-calculated correctly.

So are we ready?

@andy9a9 andy9a9 merged commit 9909814 into main Jan 7, 2026
5 checks passed
@andy9a9 andy9a9 deleted the feat/formatting branch January 7, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants