Skip to content

Commit

Permalink
Merge 8d22577 into 4859ec7
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalre committed Feb 11, 2023
2 parents 4859ec7 + 8d22577 commit d52f69f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 26 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 6.4.0 - February 11, 2023
* (refs [#51](https://github.com/pascalre/vscode-yaml-sort/issues/51)) Add support for sorting arrays
* Add setting `sortArrays`
* Update dependencies to latest versions

## 6.3.0 - February 6, 2023
* (refs [#27](https://github.com/pascalre/vscode-yaml-sort/issues/36)) Add support for octal values
* Update dependencies to latest versions
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This extension contributes the following settings:
| `notifySuccess` | When `true`, will notify on successfully performed tasks. | `true` |
| `quotingType` | Strings will be quoted using this quoting style. If you specify single quotes, double quotes will still be used for non-printable characters. | `'` |
| `schema` | Schema to use. Possible values are `HOMEASSISTANT_SCHEMA`, `CLOUDFORMATION_SCHEMA`, `CORE_SCHEMA`, `DEFAULT_SCHEMA`, `FAILSAFE_SCHEMA`, `JSON_SCHEMA`. | `DEFAULT_SCHEMA` |
| `sortArrays` | "When `true`, will sort arrays | `false` |
| `sortOnSave` | When `0`, will sort files when saving document. When `1`, `2` or `3`, will use customSortKeywords. Set to negative value to disable sortOnSave. Only works in combination with `editor.formatOnSave` set to `true`. | `0` |
| `useAsFormatter` | When `true`, will enable default YAML formatter (requires restart). | `false` |
| `useCustomSortRecursively` | When `true`, will use the custom sort keywords recursively on a file, when using custom sort. | `false` |
Expand Down
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@
],
"description": "Schema to use"
},
"vscode-yaml-sort.sortArrays": {
"type": "boolean",
"default": false,
"description": "When `true`, will sort arrays"
},
"vscode-yaml-sort.sortOnSave": {
"type": "number",
"default": 0,
Expand Down Expand Up @@ -247,18 +252,18 @@
},
"devDependencies": {
"@types/mocha": "10.0.1",
"@types/node": "^18.11.19",
"@types/node": "^18.13.0",
"@types/sinon": "^10.0.13",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"coveralls": "3.1.1",
"dependency-cruiser": "^12.5.0",
"eslint": "^8.32.0",
"dependency-cruiser": "^12.7.1",
"eslint": "^8.34.0",
"jsdoc": "4.0.0",
"mocha": "^10.2.0",
"nyc": "15.1.0",
"sinon": "^15.0.1",
"sonarqube-scanner": "^3.0.0",
"sonarqube-scanner": "^3.0.1",
"ts-node": "10.9.1",
"typescript": "^4.9.5",
"typescript-require": "0.3.0"
Expand Down
1 change: 1 addition & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class Settings {
notifySuccess = this.getBoolean("notifySuccess")
quotingType = this.getQuotingType()
schema = this.getSchema()
sortArrays = this.getBoolean("sortArrays")
sortOnSave = this.getNumber("sortOnSave")
useCustomSortRecursively = this.getBoolean("useCustomSortRecursively")
useLeadingDashes = this.getBoolean("useLeadingDashes")
Expand Down
11 changes: 7 additions & 4 deletions src/util/yaml-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Severity, VsCodeAdapter } from "../adapter/vs-code-adapter"
import { ProcessorController } from "../controller/processor-controller"
import { ErrorUtil } from "./error-util"

const sortNestedArrays = (obj: unknown) => {
const sortArrays = (obj: unknown) => {
if (!obj || typeof obj !== 'object') {
return
} else if (Array.isArray(obj)) {
Expand All @@ -17,7 +17,7 @@ const sortNestedArrays = (obj: unknown) => {
if (Array.isArray(object)) {
Object.entries(object).sort()
}
sortNestedArrays(object)
sortArrays(object)
}
})
}
Expand Down Expand Up @@ -60,9 +60,12 @@ export class YamlUtil {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const doc = this.jsyamladapter.load(unsortedYamlWithoutTabs) as any
sortNestedArrays(doc)
let sortedYaml = ""

if (this.settings.sortArrays) {
sortArrays(doc)
}

let sortedYaml = ""
if (customSort > 0 && !this.settings.useCustomSortRecursively) {
const keywords = this.settings.getCustomSortKeywords(customSort)

Expand Down

0 comments on commit d52f69f

Please sign in to comment.