Skip to content

codeActionsOnSave { "source.fixAll": "explicit" } breaks JSON file formatting in prettier-vscode > v12 #3977

@plasticrake

Description

@plasticrake

Preflight Checklist

Issue Summary

Formatting JSON files on save stopped working in prettier-vscode v12 in a project with:

  "editor.codeActionsOnSave": {
    "source.fixAll": "explicit"
  }

(This came from expo template project defaults: https://github.com/expo/expo-template-default/blob/main/.vscode/settings.json)

The JSON file would be formatted, but not correctly (it was using spaces instead of tabs for example). And it would stay "dirty" and not actually save. There were no errors I could find anywhere. Strangely, package.json did not have this issue, but normal JSON files did.

Formatting manually with "Format Document With" is working, so the workaround was to do that, then "Save Without Formatting".
The only options I have with "Format Document With" are "Prettier" and "JSON Language Features", and choosing either option would format with tabs! So not sure why it was being formatted with spaces on save. I disabled the eslint vscode extension while testing and made no difference.

Removing source.fixAll": "explicit" or setting it to source.fixAll.prettier": "explicit" or downgrading to v11 would fix this.

Reproduction Repository

https://github.com/plasticrake/prettier-issue

Steps to Reproduce

  1. Clone Repo
  2. Open in VS Code
  3. Open example.json
  4. Save

Expected Behavior

example.json to be formatted and saved with tabs:

{
	"description": "This is an example JSON file and it should use tabs",
	"key": "value",
	"version": "1.0"
}

Actual Behavior

example.json is formatted incorrect (spaces) and is NOT saved (it stays dirty):

{
    "description": "This is an example JSON file and it should use tabs",
    "key": "value",
    "version": "1.0"
}

Operating System

macOS

IDE

VSCode

IDE Version

1.113.0

Prettier Extension Version

12.4.0

Prettier Version

3.81.

Prettier Extension Logs

["INFO" - 2:02:37 PM] Using config file at /Users/patrick/Code/tmp/prettier-issue/.prettierrc
["INFO" - 2:02:37 PM] EditorConfig support is enabled, checking for .editorconfig files
["INFO" - 2:02:37 PM] Resolved config:
{
  "useTabs": true,
  "tabWidth": 2,
  "endOfLine": "lf"
}
["INFO" - 2:02:39 PM] Formatting file:///Users/patrick/Code/tmp/prettier-issue/example.json
["INFO" - 2:02:39 PM] Using config file at /Users/patrick/Code/tmp/prettier-issue/.prettierrc
["INFO" - 2:02:39 PM] EditorConfig support is enabled, checking for .editorconfig files
["INFO" - 2:02:39 PM] Resolved config:
{
  "useTabs": true,
  "tabWidth": 2,
  "endOfLine": "lf"
}
["INFO" - 2:02:39 PM] PrettierInstance:
{
  "version": "3.8.1",
  "prettierModule": {
    "__debug": {},
    "util": {},
    "doc": {
      "builders": {
        "line": {
          "type": "line"
        },
        "softline": {
          "type": "line",
          "soft": true
        },
        "hardline": [
          {
            "type": "line",
            "hard": true
          },
          {
            "type": "break-parent"
          }
        ],
        "literalline": [
          {
            "type": "line",
            "hard": true,
            "literal": true
          },
          {
            "type": "break-parent"
          }
        ],
        "lineSuffixBoundary": {
          "type": "line-suffix-boundary"
        },
        "cursor": {
          "type": "cursor"
        },
        "breakParent": {
          "type": "break-parent"
        },
        "trim": {
          "type": "trim"
        },
        "hardlineWithoutBreakParent": {
          "type": "line",
          "hard": true
        },
        "literallineWithoutBreakParent": {
          "type": "line",
          "hard": true,
          "literal": true
        }
      },
      "printer": {},
      "utils": {}
    },
    "version": "3.8.1"
  },
  "modulePath": "/Users/patrick/Code/tmp/prettier-issue/node_modules/prettier"
}
["WARN" - 2:02:39 PM] Unable to resolve ignore path: .prettierignore for /Users/patrick/Code/tmp/prettier-issue/example.json
["INFO" - 2:02:39 PM] Resolved plugins:
[]
["INFO" - 2:02:39 PM] File Info:
{
  "ignored": false,
  "inferredParser": "json"
}
["INFO" - 2:02:39 PM] Using local configuration (VS Code configuration will not be used)
["INFO" - 2:02:39 PM] Prettier Options:
{
  "filepath": "/Users/patrick/Code/tmp/prettier-issue/example.json",
  "parser": "json",
  "useTabs": true,
  "tabWidth": 2,
  "endOfLine": "lf"
}
["INFO" - 2:02:39 PM] Formatting completed in 40ms.

Prettier Configuration

{ "useTabs": true }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage-pendingAwaiting initial triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions