volarjs / services

MIT License
137 stars 29 forks source link

Prettier plugin adds newline at top of files #26

Closed Hawxy closed 1 year ago

Hawxy commented 1 year ago

Hello, Per the title, I noticed that the prettier plugin adds a newline at the top of files. Could we get an option to disable this? It's not standard behavior for prettier.

Thanks

johnsoncodehk commented 1 year ago

Can you try to downgrade @volar-plugins/prettier version?

patarapolw commented 1 year ago

@johnsoncodehk I am not sure if the fixes in the line 69-74 can now be removed?

https://github.com/volarjs/plugins/blob/44317449f6a62fa80fab647611118a1af162cd13/packages/prettier/src/index.ts#L69

Anyway, I can't build and test due to errors in packages/pug/src/index.ts and packages/typescript/src/**/*. Not sure how to build only one package.

johnsoncodehk commented 1 year ago

@patarapolw Currently it cannot be removed, otherwise, there will be problems with formatting in SFC. But it should be removed, I'll see how to refactor the implementation.

You can run npx tsc -b -p packages/prettier/tsconfig.build.json. I will update the related setup.

johnsoncodehk commented 1 year ago

Please try updating Volar to 1.1.0 and updating @volar-plugins/prettier to 1.2.0.

Hawxy commented 1 year ago

@johnsoncodehk Hmmm, v1.2.0 fixes the newline issue but now component props get split across a few lines instead of stacking:

image

johnsoncodehk commented 1 year ago

I guess this is the expected behavior of prettier, @patarapolw what do you think?

Hawxy commented 1 year ago

It isn't, the original is the correct output. Here's a replica in the prettier sandbox.

johnsoncodehk commented 1 year ago

Can you show your volar.config.js?

The code of the plugin is simple, maybe you can see if it enlightens you: https://github.com/volarjs/plugins/blob/master/packages/prettier/src/index.ts

Hawxy commented 1 year ago

Ah, it seems that the import changed, I was using const { volarPrettierPlugin } = require('@volar-plugins/prettier');, I updated it to const volarPrettierPlugin = require('@volar-plugins/prettier'); and we're back in action.

braincomb commented 1 year ago

@johnsoncodehk

I have exact same issue as @Hawxy showed in the screenshot above where props stopped being stacked vertically after the update.

I am also using the new volar-service-prettier package name and config, here's what I have:

Volar extension 1.8.2

package.json:

{
  "devDependencies": {
    "volar-service-prettier": "^0.0.8"
  }
}

volar.config.js:

module.exports = {
  plugins: [
    require("volar-service-prettier").default({
      languages: ["html", "css", "scss", "typescript", "javascript"],
      html: {
        breakContentsFromTags: false,
      },
      ignoreIdeOptions: true,
    }),
  ],
};

Any ideas?

I downgraded back to my original setup with @volar-plugins/prettier@1.1.5 and Volar 1.0.24 and it's back to the expected behavior.