Repository navigation
fix: keep delimiters and directives with their documents, make recursive sort reliable - #326
Merged
Merged
Conversation
The delimiters were collected separately from the documents and later assigned by position. getDelimiters() already added the leading `---` that setLeadingDashes() added again, so several documents without a leading delimiter started with `---\n---` (an additional empty document). With a leading `--- # first`, the comments shifted to the next document and the last one was lost. Directives like `%YAML 1.2` were never handled: validateYaml() loaded them as a document of their own and failed, so the directive handling in the transformer was unreachable. Replace splitYaml() and getDelimiters() with splitDocuments(), which keeps every delimiter with its own document and returns the directives separately. The transformer joins the documents again, adds a leading delimiter only if needed, keeps the one of a selection as it is and keeps empty documents. Remove the unused splitYaml(), getDelimiters() and removeLeadingLineBreakOfFirstElement() with their tests; the splitYaml() tests are ported to splitDocuments(). Remove the directive test of the extension suite: it did not await the command, so it compared the unchanged test file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jdb5is9YsMnteaxHryN26M
"Recursively sort YAML files" went through the Controller, whose constructor throws without an active text editor, so the command failed when no file was open. Run from the command palette, it got no uri and crashed. Each file was sorted as a single document, so every file with several documents failed. The directory was interpolated into the glob pattern, where a backslash of a windows path is an escape character. Move the command into the new controller module file-sorter: it sorts each file with sortDocuments(), reports a file that cannot be sorted and continues with the next one, and asks for a folder when no uri is given. FileUtil now only finds the files and passes the directory as glob's cwd. The command is hidden from the command palette and only offered for folders in the explorer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jdb5is9YsMnteaxHryN26M
YamlUtil.formatYaml() showed "Yaml formatted successfully" itself, once per document. The formatter uses it too, so "Format Document" and format on save showed one notification per document, although 5.5.0 stopped notifications for the formatter (refs #65). Remove the message from formatYaml() and show it in the command, once, after the edits were applied. YamlUtil no longer depends on the VS Code adapter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jdb5is9YsMnteaxHryN26M
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 25 |
| Duplication | -2 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What changed
958f9ae)New
splitDocuments()inyaml-text.tssplits a text into documents, each with its own delimiter line, and returns directives (%YAML …,%TAG …) separately. The transformer joins the documents again, adds a leading---only if needed, keeps the delimiter of a selection as it is and keeps empty documents.JsYamlAdapter.validateYaml()uses the same split. Removed the unusedsplitYaml(),getDelimiters()andremoveLeadingLineBreakOfFirstElement().0c88b32)New controller module
file-sorter.ts: sorts each file withsortDocuments(), reports a file that cannot be sorted and continues with the next one, asks for a folder when no uri is given.FileUtilnow only finds files and passes the directory as glob'scwd. Inpackage.jsonthe command is hidden from the command palette and only offered for folders in the explorer.0e3e73b, refs No need to send notification when used as a formatter #65)"Yaml formatted successfully" moved from
YamlUtil.formatYaml()into theFormat YAMLcommand.Why
getDelimiters()added the leading---thatsetLeadingDashes()added again, so several documents without a leading delimiter started with---\n---, which is an additional empty document. With a leading--- # first, the comments shifted to the next document and the last one was lost.validateYaml()loaded%YAML 1.2as a document of its own and failed, so the directive handling was unreachable. This also affected theValidate YAMLcommand.Controller, whose constructor throws without an active editor. From the command palette it got no uri and crashed. Each file was sorted as a single document, so every file with several documents failed. The directory was part of the glob pattern, where a backslash of a Windows path is an escape character.formatYaml()showed its message once per document, also for "Format Document" and format on save, although 5.5.0 stopped notifications for the formatter (No need to send notification when used as a formatter #65).Behavior changes
--- # commentis kept as it is (withuseLeadingDashes: true).Recursively sort YAML filesis no longer listed in the command palette and only appears on folders in the explorer.Testing
document-transformer.test.ts: single leading delimiter, delimiters with comments, empty documents, directives (with and withoutuseLeadingDashes), formatting several documents, no notification fromformatDocuments()file-sorter.test.ts: file with several documents, invalid file stays unchanged (plus the movedsortFiletests)yaml-text.test.ts:splitDocuments(), including the cases ported from the formersplitYaml()testsgetDelimiters(): 7,splitYaml(): 5, ported) and the extension test "should remove yaml metadata tags", which did not await the command and therefore only compared the unchanged test file.tsc,eslint, dependency-cruiser (no violations), 168 tests via mocha. The affected Electron tests were reproduced with the real test files and give the expected results.🤖 Generated with Claude Code
https://claude.ai/code/session_01Jdb5is9YsMnteaxHryN26M