dprint-vscode
dprint-vscode copied to clipboard
Configure default formatter for TypeScript React
On 0.33.0 with 0.13.5, I'm trying to setup formatting on-save and got this when running format document by hand from the command palette:

workspace settings.json
{
"editor.defaultFormatter": "dprint.dprint",
"editor.formatOnSave": true,
"editor.trimAutoWhitespace": true,
"eslint.format.enable": false,
"eslint.trace.server": "messages",
"[javascript]": {
"editor.defaultFormatter": "dprint.dprint",
"editor.formatOnSave": true
},
"[javascriptreact]": {
"editor.defaultFormatter": "dprint.dprint",
"editor.formatOnSave": true
},
"[typescript]": {
"editor.defaultFormatter": "dprint.dprint",
"editor.formatOnSave": true
},
"[typescriptreact]": {
"editor.defaultFormatter": "dprint.dprint",
"editor.formatOnSave": true
},
"dprint.verbose": true
}
I disabled formatting for JS and TS in user settings.json. It seems to format json:

dprint.json
{
"indentWidth": 4,
"useTabs": false,
"typescript": {
"lineWidth": 120,
"quoteStyle": "preferSingle",
"jsx.quoteStyle": "preferDouble",
"quoteProps": "asNeeded"
},
"includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs}", "**/*.{json}"],
"excludes": [
"**/node_modules",
"packages/",
"__tests__/fixtures/*.json",
"__mocks__/*.json",
"**/*.fixture.json",
"**/*.fixtures.json"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.78.0.wasm",
"https://plugins.dprint.dev/json-0.16.0.wasm"
]
}
OK, I see where the issue is. If I open the file from source control and I get an absolute path like this:
then dprint formatting fails even of the path is the same as the workspace path (and especially then).
If I open the file from the VS Code explorer then everything is fine and the formatter works.

Not sure if this is a regression to the fix done in 0.13.5, I literally set up dprint yesterday.