Prettier-vscode: Run eslint --fix AFTER prettier on save

Created on 25 Mar 2020  路  4Comments  路  Source: prettier/prettier-vscode

Describe the solution you'd like
Due to company constraints, I'd like to run eslint --fix AFTER this extension runs Prettier.

_Now that the prettier eslint integration is deprecated, is there a recommended way to do this_? It looks like this has been brought up in the past: https://github.com/prettier/prettier-vscode/issues/14

Describe alternatives you've considered
I'm using this configuration, however it runs eslint FIRST & then Prettier:

"editor.codeActionsOnSave": {
    "source.fixAll": true,
    "source.fixAll.eslint": true
  },
locked

Most helpful comment

The march VS Code update allows specifying an array to order codeActionsOnSave: https://code.visualstudio.com/updates/v1_44#_explicit-ordering-for-code-actions-on-save

So this and https://github.com/prettier/prettier-vscode/issues/870#issuecomment-571163060 gave me an idea for an extension, what if we could run 'Format Document' as a codeActionOnSave?

Checkout https://github.com/rohit-gohri/vscode-format-code-action/

This registers a custom codeAction: source.fixAll.format, which we can use instead of formatOnSave. It'll use whatever default formatter you have setup.

I'm running eslint after prettier with these settings:

  "editor.formatOnSave": false,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.codeActionsOnSave": [
    "source.fixAll.format",
    "source.fixAll.eslint"
  ]

and these extensions:

[
    "esbenp.prettier-vscode",
    "dbaeumer.vscode-eslint",
    "rohit-gohri.format-code-action"
]

I hope this helps anyone coming here.

Might help in #716 and https://github.com/microsoft/vscode/issues/87096 too

All 4 comments

Unfortunately, this is not possible. The order of operations is controlled by VS Code and formatting is not exposed as a code action. There are multiple issues in vscode about this and hopefully they will resolve soon. One example is here: https://github.com/microsoft/vscode/issues/90220

The march VS Code update allows specifying an array to order codeActionsOnSave: https://code.visualstudio.com/updates/v1_44#_explicit-ordering-for-code-actions-on-save

The march VS Code update allows specifying an array to order codeActionsOnSave: https://code.visualstudio.com/updates/v1_44#_explicit-ordering-for-code-actions-on-save

So this and https://github.com/prettier/prettier-vscode/issues/870#issuecomment-571163060 gave me an idea for an extension, what if we could run 'Format Document' as a codeActionOnSave?

Checkout https://github.com/rohit-gohri/vscode-format-code-action/

This registers a custom codeAction: source.fixAll.format, which we can use instead of formatOnSave. It'll use whatever default formatter you have setup.

I'm running eslint after prettier with these settings:

  "editor.formatOnSave": false,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.codeActionsOnSave": [
    "source.fixAll.format",
    "source.fixAll.eslint"
  ]

and these extensions:

[
    "esbenp.prettier-vscode",
    "dbaeumer.vscode-eslint",
    "rohit-gohri.format-code-action"
]

I hope this helps anyone coming here.

Might help in #716 and https://github.com/microsoft/vscode/issues/87096 too

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Connorelsea picture Connorelsea  路  4Comments

FlorianWendelborn picture FlorianWendelborn  路  3Comments

bluemoehre picture bluemoehre  路  3Comments

vesper8 picture vesper8  路  3Comments

PetrykowskiM picture PetrykowskiM  路  3Comments