Created
September 1, 2022 10:12
-
-
Save CagriAldemir/598d5a142e176c21d3c26c7b090e3b2f to your computer and use it in GitHub Desktop.
VSCode Dual Document Format (Prettier + ESLint)
This file contains 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
[ | |
{ | |
"key": "alt+cmd+l", | |
"command": "-editor.action.formatDocument", | |
"when": "config.workspaceKeybindings.dualDocumentFormat.enabled && editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly" | |
}, | |
{ | |
"key": "alt+cmd+l", | |
"command": "workbench.action.tasks.runTask", | |
"args": "format-prettier-eslint", | |
"when": "config.workspaceKeybindings.dualDocumentFormat.enabled && editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly" | |
} | |
] |
This file contains 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
{ | |
"workspaceKeybindings.dualDocumentFormat.enabled": true | |
} |
This file contains 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
{ | |
"version": "2.0.0", | |
"tasks": [ | |
{ | |
"label": "format-prettier", | |
"command": "${command:prettier.forceFormatDocument}" | |
}, | |
{ | |
"label": "format-eslint", | |
"command": "${command:eslint.executeAutofix}" | |
}, | |
{ | |
"label": "format-prettier-eslint", | |
"dependsOrder": "sequence", | |
"dependsOn": ["format-prettier", "format-eslint"] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
VSCode Dual Document Format (Prettier + ESLint)
This config reformats the code first with Prettier, then with ESLint.
How does it work?
The first of the two tasks in the
tasks.json
file formats the code with Prettier, and the second formats the code with ESLint. The third task runs the first two tasks sequentially.The first of the shortcuts in the
keybindings.json
file removes the normal format document shortcut, and the second assigns the third task mentioned above to the same shortcut. Theconfig.workspaceKeybindings.dualDocumentFormat.enabled
rule, which is the first of the rules found in the shortcuts, controls the state in which these shortcuts will work. Other rules are those that are already in this shortcut.When we add the config found in the
settings.json
file to the.vscode/settings.json
file in the workspace we want, the dual format operation starts.