DoCode / vscode-remove-final-newlines

A Visual Studio Code extension that removes final new lines on save
MIT License
2 stars 1 forks source link

Compatibility with Prettier #7

Open zachthedev opened 6 months ago

zachthedev commented 6 months ago

I Downloaded this with the hopes that this would work in conjunction with Prettier to remove the final newlines that it adds. There is no configuration for Prettier to disable the newlines, so I figured this may be an easy route through an extension.

Are you aware of any ability to specify the priority for the order of extensions during a save? Right now, Remove Final Newlines runs followed by Prettier.

DoCode commented 6 months ago

Ok, i understand. I'll look into this and make some tests with Prettier ASAP!

DoCode commented 6 months ago

With this config on reformat code and/or file save, the Prettier runs, and then the final new line is removed:

{
. . .
  "files.insertFinalNewline": false,
  "files.removeFinalNewlines": true,
  "files.trimFinalNewlines": false,
  "files.trimTrailingWhitespace": true,
. . .
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.tabSize": 2
  },
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.tabSize": 2
  },
  "[markdown]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.tabSize": 4,
    "editor.wordWrap": "off",
    "files.insertFinalNewline": true,
    "files.removeFinalNewlines": false,
    "files.trimFinalNewlines": true,
    "files.trimTrailingWhitespace": false
  },
. . .
}
zachthedev commented 6 months ago

@DoCode Thanks for looking into it! I just gave that a go and it did not work for me. I added the file-specific config that you listed but that didn't change anything for me since prettier was already set as the global editor default. Here is some relevant things from my settings.json

  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnPaste": false,
  "editor.formatOnSave": true,
  "editor.formatOnType": false,
  "files.insertFinalNewline": false,
  "files.removeFinalNewlines": true,
  "files.trimFinalNewlines": false,
  "files.trimTrailingWhitespace": true,

Prettier Info: Name: Prettier - Code formatter Id: esbenp.prettier-vscode Description: Code formatter using prettier Version: 10.4.0 Publisher: Prettier VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode