dprint-vscode icon indicating copy to clipboard operation
dprint-vscode copied to clipboard

Configure default formatter for TypeScript React

Open zamber opened this issue 3 years ago • 1 comments

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:

image

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:

image

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"
    ]
}

zamber avatar Dec 07 '22 21:12 zamber

OK, I see where the issue is. If I open the file from source control and I get an absolute path like this: image 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. image

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

zamber avatar Dec 08 '22 07:12 zamber