Skip to content

Commit

Permalink
Merge 5a5c8e6 into 88a4780
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalre committed Jun 21, 2023
2 parents 88a4780 + 5a5c8e6 commit bd814db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sonarlint.connectedMode.project": {
"connectionId": "pascalre",
"projectKey": "pascalre_vscode-yaml-sort"
}
}
2 changes: 1 addition & 1 deletion src/test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ async function main() {
}
}

main()
main().then().catch()
14 changes: 12 additions & 2 deletions src/util/yaml-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@ const sortArrays = (obj: unknown) => {
if (!obj || typeof obj !== "object") {
return
} else if (Array.isArray(obj)) {
obj.sort()
obj.sort((a, b) => compareObjects(a, b))
}
Object.keys(obj).forEach(key => {
const object = obj[key as keyof unknown]
if (typeof object === "object") {
if (Array.isArray(object)) {
Object.entries(object).sort()
Object.entries(object).sort((a, b) => compareObjects(a, b))
}
sortArrays(object)
}
})
}

export function compareObjects(a: object, b: object) {
if (a > b) {
return 1
}
if (a < b) {
return -1
}
return 0
}

export class YamlUtil {
settings: Settings
jsyamladapter: JsYamlAdapter
Expand Down

0 comments on commit bd814db

Please sign in to comment.