Fix/formatting#6
Conversation
| } | ||
| }); | ||
|
|
||
| /** Expand tabs to spaces for visual-column comparisons (tabSize=8). */ |
There was a problem hiding this comment.
You mix different commenting styles.
- /** Comment */
- /* Comment */
/**
- Comment
*/
I would decide for one and stick to it.
There was a problem hiding this comment.
Also, I would not document default values like tabsize = 8 in the function comment. It just duplicates the info from the next line and it increases the effort to keep things in sync.
There was a problem hiding this comment.
🤦 -> unified and removed info about size
| }); | ||
|
|
||
| /** Expand tabs to spaces for visual-column comparisons (tabSize=8). */ | ||
| function expandTabs(s: string, tabSize = 8): string { |
There was a problem hiding this comment.
Use words for variables; it makes the code easier to read.
| function expandTabs(s: string, tabSize = 8): string { | |
| function expandTabs(line: string, tabSize = 8): string { |
There was a problem hiding this comment.
it's not the line, it's characters, so changed to chars
| assert.ok(!result.includes('"yellow: status"'), 'Colon in string should not have space added'); | ||
| }); | ||
|
|
||
| test('Should handle whitespace-separated arrays', async () => { |
There was a problem hiding this comment.
The name of the test is not descriptive. What does "handle" mean? I don't know what this test is doing by just reading the name.
Alternative: "Should not split whitespace-separated arrays into new lines"
| assert.ok(!result.match(/brightness-levels.*\n.*0\n.*1\n.*2/), 'Should not split digits'); | ||
| }); | ||
|
|
||
| test('Should handle macro function calls in arrays', async () => { |
There was a problem hiding this comment.
Same here. Rename the test.
| assert.ok(!result.match(/P\s+D\s+O\s+_\s+F/), 'Should not split macro name into characters'); | ||
| }); | ||
|
|
||
| test('Should handle long pinctrl macros', async () => { |
There was a problem hiding this comment.
Same here. Rename the test.
| // Block comment should be preserved | ||
| assert.ok(result.includes('M.2 reference clock selection'), 'Block comment should be preserved'); |
There was a problem hiding this comment.
I would move this check before the other check so that it aligns with the name of the test (preserve block comment AND keep alignment)
There was a problem hiding this comment.
moved to top of this function
| return processed.join(''); | ||
| }).join('\n'); | ||
|
|
||
| // Normalize node references and addresses |
There was a problem hiding this comment.
In the long-term, it probably makes sense to split each regex replacement into its own function. Regex expressions are hard to read/understand, and having them separated into their own functions makes them also testable.
There was a problem hiding this comment.
I know, but there is lot regex-based function, so I wanted to keep them some-how grouped
| const hasCommas = this.hasSignificantCommas(trimmed); | ||
|
|
||
| if (!hasCommas) { | ||
| return trimmed.trim() ? [trimmed] : []; | ||
| } |
There was a problem hiding this comment.
| const hasCommas = this.hasSignificantCommas(trimmed); | |
| if (!hasCommas) { | |
| return trimmed.trim() ? [trimmed] : []; | |
| } | |
| if (!this.hasSignificantCommas(trimmed)) { | |
| return trimmed.trim() ? [trimmed] : []; | |
| } |
| * Check if a value string has significant commas (not inside parentheses or brackets) | ||
| * @param val The value string to check | ||
| * @returns True if there are commas that separate values | ||
| */ |
There was a problem hiding this comment.
Explain a bit more what a significat commas is. It would make sense to give examples in the description.
| * @param col Target column for alignment | ||
| * @returns String of tabs and/or spaces to reach the target column | ||
| */ | ||
| private alignmentForColumn(col: number): string { |
There was a problem hiding this comment.
Use verb-based function names consistently.
- normalize...
- format...
- calculate...
Here, use align... or use the already used format...
I would also recommend ordering the functions alphabetically.
There was a problem hiding this comment.
ok, function renamed, but I wanted to keep the order based on usage not on name
There was a problem hiding this comment.
Pull request overview
This PR addresses several DTS formatter issues: preserving colons inside quoted string values (e.g. "yellow:status"), generalizing multi-line property formatting so whitespace-separated cell arrays (such as fsl,pins lists) align consistently and don't get split character-wise, distinguishing commas that act as value separators from commas nested inside (...) or <...>, and adding spaces-mode handling for values that originally contained tabs. It also unifies JSDoc-style helper comments in tests to single-line comments and adds significant test coverage for the new behavior.
Changes:
- Skip label-colon normalization inside quoted strings in
normalizeInputand split node-reference/address normalization into a separate step. - Add
hasSignificantCommasand a whitespace-separated multi-line branch informatMultiLineProperty, plus a newformatWhitespaceSeparatedLineshelper andcalculateAlignmentForColumnutility; also force spaces-mode values containing tabs to multi-line formatting. - Replace
/**doc helpers with line comments in test files and add extensive new tests for strings-with-colons, brightness-levels arrays, PDO macros, andfsl,pinstab/spaces alignment.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/formatter.ts | Per-line label normalization that skips quoted strings; new whitespace-separated multi-line value handling with column alignment; spaces-mode fall-through when values contain tabs. |
| src/test/formatter.test.ts | New expandTabs helper, renamed existing test labels, and large new test suites covering string colons, PDO macros, iomuxc macros, and fsl,pins alignment in tab and spaces modes. |
| src/test/diagnostics.test.ts | Converts a JSDoc helper comment to a line comment (no behavior change). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix multiple formatting issues:
label = "yellow:status";have been split