Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d0009b3
refactor: split the sources into a core and a vscode layer
pascalre Nov 20, 2026
eec5872
refactor(settings): read settings without the VS Code API
pascalre Nov 20, 2026
ab54172
refactor(core): throw errors instead of reporting them to the user
pascalre Nov 20, 2026
00bab42
refactor: name modules after their purpose instead of util
pascalre Nov 20, 2026
2e64aa6
test: run the core's unit tests without VS Code
pascalre Nov 20, 2026
71fc6ce
fix(commands): apply edits to the command's document and await them
pascalre Nov 20, 2026
9300580
fix(sort): accept a whole document that ends with a colon
pascalre Nov 20, 2026
f5fd1ce
fix(comments): keep inline comments of values with apostrophes
pascalre Nov 20, 2026
e8b9421
fix(sort): dump custom sort keywords with js-yaml
pascalre Nov 20, 2026
993d834
fix(spacing): add empty lines before restoring hidden values
pascalre Nov 20, 2026
885268a
fix(selection): keep empty lines of an indented selection empty
pascalre Nov 20, 2026
87b8e92
fix(files): skip dependencies and unchanged files in directory sort
pascalre Nov 20, 2026
751a580
fix(octal): keep octal values with comments and in lists
pascalre Nov 20, 2026
3a7ddde
fix(tabs): only replace tabs in the indentation
pascalre Nov 20, 2026
04e1e35
fix(test): print why the integration tests could not run
pascalre Nov 20, 2026
707ae98
fix(comments): find a comment's key by its name, not as a substring
pascalre Nov 20, 2026
3b2504c
docs(changelog): describe the editor command fixes and the new layers
pascalre Nov 20, 2026
5899f33
refactor(comments): move comment recognition into yaml-comment
pascalre Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .dependency-cruiser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
/** @type {import('dependency-cruiser').IConfiguration} */
module.exports = {
forbidden: [
/* architecture of this extension: */
{
name: 'core-independent-of-vscode',
severity: 'error',
comment:
'The core contains the yaml logic and must run without VS Code, so it can be unit tested in plain node ' +
'and reused. Talk to VS Code from src/vscode instead and pass the values into the core.',
from: { path: '^src/core' },
to: { path: '^node_modules/@types/vscode/|^src/vscode/|^src/extension' }
},
{
name: 'unit-tests-independent-of-vscode',
severity: 'error',
comment:
'Unit tests run in plain node (npm run test:unit). Tests that need VS Code belong to src/test/integration.',
from: { path: '^src/test/unit' },
to: { path: '^node_modules/@types/vscode/|^src/vscode/|^src/extension' }
},
/* rules from the 'recommended' preset: */
{
name: 'no-circular',
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
node-version: ${{env.NODE_VERSION}}

- name: install
run: |
npm install
npm install -g yarn
npm install -g vsce
run: npm ci

Check warning on line 28 in .github/workflows/action.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Omitting "--ignore-scripts" allows lifecycle scripts to run during package installation.

See more on https://sonarcloud.io/project/issues?id=pascalre_vscode-yaml-sort&issues=AaH5ZXb3fwzYga3HI1vP&open=AaH5ZXb3fwzYga3HI1vP&pullRequest=330

- name: lint
run: npm run lint

- name: static code analysis
run: npm run code-analysis

- name: unit tests
run: npm run test:unit

- name: test
uses: GabrielBB/xvfb-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
"--extensionTestsPath=${workspaceFolder}/out/test/integration/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## Unreleased
🐛 Bugfixes
* Command `Format YAML` with a selection formats the whole document. Before, it replaced the selected lines with the formatted document, so the rest of the document appeared twice. The editor commands apply their changes to the document they were run on and show the success message only after VS Code applied them. Running a command without an open editor shows a hint instead of an internal error
* Keep a comment at its key when sorting changes the key's value, e.g. removes its quotes. Before, the comment could move to another key that contains the key's name, like `data` for `a`
* Keep tabs inside values, e.g. in a quoted string. Only tabs in the indentation are replaced with spaces
* Keep the leading zero of octal values like `0755` that are followed by a comment or are items of a list. Before, they became `755`
* Command `Recursively sort YAML files` skips the folders `node_modules` and `.git`, so it no longer rewrites the yaml files of installed dependencies. Files that are already sorted are no longer written, and a file is processed once even if its extension is configured twice
* Sorting an indented selection no longer adds trailing whitespaces to its empty lines
* Setting `emptyLinesUntilLevel` no longer adds empty lines inside block scalars (`key: |`), which changed their value, and no longer separates a comment from the key below it
* Custom sort writes the keywords like every other key: a keyword that needs quotes is quoted (before, `'a: b': 1` became the invalid `a: b: 1`), a value containing a colon stays on the line of its keyword instead of moving to the next line, and the result no longer ends with an extra line break when every key is a keyword
* Keep a document that only contains an empty mapping (`{}`) when sorting or formatting. Before, it became an empty document
* Keep the inline comment of a value that contains an apostrophe (`key: it's # comment`) or an escaped quote (`key: "a \" b" # comment`). Before, the comment was dropped while sorting
* Sorting a whole document whose last key has no value (e.g. `key:`) no longer fails with "YAML selection is invalid". This check now only applies to selections
* The editor commands (sort, custom sort, format, validate) are only offered in the command palette for yaml files. The condition was declared at a place VS Code ignores
* (refs [#65](https://github.com/pascalre/vscode-yaml-sort/issues/65)) Formatting via "Format Document" or on save no longer shows "Yaml formatted successfully", once per document. The command `Format YAML` shows it once after the changes were applied
* Command `Recursively sort YAML files` now sorts files with several documents, works without an open editor and is only offered for folders in the explorer. A file that cannot be sorted is reported and left unchanged. Files are now also found on Windows paths
Expand Down Expand Up @@ -30,6 +41,8 @@
* The extension is only activated when a yaml file is opened or one of its commands is run, instead of on every start of VS Code
📦 Dependencies
* Move `@types/js-yaml` and `@vscode/test-electron` to `devDependencies`, so they are no longer shipped with the extension
🏗️ Internal
* The sources are split into `src/core` (yaml logic, no VS Code API) and `src/vscode` (commands, formatter, notifications). The core reports problems by throwing errors, the vscode layer shows them. `npm run code-analysis` enforces the split, and `npm run test:unit` runs the core's tests in plain node within seconds

# 6.6.4 - Feb 9, 2026
📦 Dependencies
Expand Down
16 changes: 14 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ When opening an issue, describe your issue as clear as possible. If useful, prov
## Workflow
This project uses the [GitHub Flow](https://docs.github.com/en/get-started/quickstart/github-flow).

### Architecture
The sources are split into two layers:

| Folder | Content | May use the VS Code API |
| --- | --- | --- |
| `src/core` | Sorting, formatting and validating yaml: settings, documents, processors, js-yaml | no |
| `src/vscode` | Commands, formatter, notifications, reading the configuration | yes |

`src/extension.ts` registers the commands and the formatter. The core reports problems by throwing errors, the
vscode layer shows them to the user. `npm run code-analysis` fails if the core or a unit test imports VS Code.

### Testing & Linting
The following commands support you at developing good code:
* `npm run code-analysis`: Run the static code analysis
* `npm run test`: Run the tests
* `npm run code-analysis`: Run the static code analysis, including the layer rules above
* `npm run test:unit`: Run the unit tests of the core in plain node, which takes a few seconds
* `npm run test`: Run all tests, including the integration tests in `src/test/integration`, inside VS Code
* `npm run lint`: Run the linter

### Commit changes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This extension contributes the following commands:
| `Custom Sort 2` | Same as `Custom Sort 1` |
| `Custom Sort 3` | Same as `Custom Sort 1` |
| `Format Document` | Formats a yaml document without sorting it. Also possible using the shortcut (⇧⌥F on Mac). |
| `Recursively sort YAML files` | Sorts all `.yaml` and `.yml` files in a directory and all its subdirectories, including files with several documents. Run it from the context menu of a folder in the explorer. A newline at the end of a file will be retained. |
| `Recursively sort YAML files` | Sorts all `.yaml` and `.yml` files in a directory and all its subdirectories, including files with several documents. Run it from the context menu of a folder in the explorer. A newline at the end of a file will be retained. Files in `node_modules` and `.git` are skipped, files that are already sorted are not rewritten. |
| `Sort YAML` | Sorts a given YAML. You can either sort the whole YAML document or sort only a selection of the text. |
| `Validate YAML` | Validates a given YAML. |

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@
"pretest": "npm run compile",
"sonar": "node sonar-project.js",
"test": "node ./out/test/runTest.js",
"pretest:unit": "npm run compile",
"test:unit": "mocha --ui tdd \"out/test/unit/**/*.test.js\"",
"vscode:prepublish": "npm run compile",
"watch": "tsc -watch -p ./"
},
Expand Down
87 changes: 0 additions & 87 deletions src/adapter/vs-code-adapter.ts

This file was deleted.

75 changes: 0 additions & 75 deletions src/controller/controller.ts

This file was deleted.

50 changes: 0 additions & 50 deletions src/controller/file-sorter.ts

This file was deleted.

Loading
Loading