#Problems with formatting

29 messages · Page 1 of 1 (latest)

stable ridge
#

Howdy. Prettier doesn't seem to be running on my .astro files no matter what. I even chatted to the AI to try see if I'm missing something: https://discord.com/channels/830184174198718474/1141297472925351988

But it runs everywhere else, but my .astro files, wondering if anyone has been stuck like this?

As someone with dyslexia and ADHD clean and formatted code is the best way I can work, and I love Astro, but the problems I'm facing is making it near impossible to be able to just focus on my code.

Thanks in advance

#

Should have also mentioned I'm using VSCode Insiders on Mac (Apple Silicon)

frigid root
#

Are you formatting in the editor or in the CLI?

#

If you're formatting in the editor, you can simply format using the Astro extension without needing to install anything in your project

stable ridge
#

I've attempted both methods, neither with success. running npx prettier --write . formats everything except .astro files lol.

Pressing cmd shift P and running a format with Astro doesn't change anything regarding formatting

frigid root
#

Can you share your Prettier config?

stable ridge
#

.prettierrc

{
      "trailingComma": "none",
      "tabWidth": 6,
      "semi": true,
      "singleQuote": false,
      "htmlWhitespaceSensitivity": "ignore",
      "printWidth": 9
}
frigid root
#

You don't have the plugin specified

stable ridge
#

Ah, how can I do this?

frigid root
#

plugins: ['prettier-plugin-astro'],

stable ridge
#

this isn't for the .prettierrc file but something different, right? Not sure where to find

Then add the plugin to your Prettier configuration:
Because the formatting is a bit different to the .prettierrc

frigid root
#

The guide assumes an ESM .js config, since those are the most common nowadays, but the format is similar for other formats

#

For a .prettierrc, which I believe can either be JSON or YAML, it'd look like

"plugins": ["prettier-plugin-astro"]

or, in YAML,

plugins:
  - prettier-plugin-astro
stable ridge
#

so I've added to my .prettierrc like such:

{
      "plugins": ["prettier-plugin-astro"],
      "trailingComma": "none",
      "tabWidth": 6,
      "semi": true,
      "singleQuote": false,
      "htmlWhitespaceSensitivity": "ignore",
      "printWidth": 999999999
}

to no avail sadly. Would you happen to have an example of this "ESM" file you speak of? Didn't realise I was using a less-common solution

frigid root
#

I think in Prettier 3 there's a bug where if you just do prettier --write . it doesn't take into account file types added by plugins

#

So you'd need to do something like prettier --write **/*.astro for it to work, not sure

stable ridge
#

ah yeah I had to do npx prettier --write **/*.astro thanks for that. A perfect workflow would be for it auto do it on save like how prettier usually works, any ideas on how I could achieve that?

frigid root
#

If you scroll a bit there's a "JS(ESM)" example of a basic config

frigid root
#

If you're using Astro's, it should work by default

stable ridge
#

Thanks Erika, I'm going to mess around with this until I get something that works. Thanks again

frigid root
#

No problems, don't hesitate if you need any further help!

stable ridge
frigid root
#

In the command palette you can find these options:

#

The first one opens the settings file, the second one opens a UI to edit said settings file