dprint / dprint-plugin-prettier Goto Github PK
View Code? Open in Web Editor NEWPrettier wrapper plugin for dprint.
License: Other
Prettier wrapper plugin for dprint.
License: Other
As title. Perhaps a cron job should run daily that checks this.
It seems like all .svelte
files cause dprint to fail with Uncaught ReferenceError: Buffer is not defined
. Full error:
Error formatting /workspaces/template/src/App.svelte. Message: Uncaught ReferenceError: Buffer is not defined
at dprint:prettier.js:51811:36
at String.replace (<anonymous>)
at snipTagContent (dprint:prettier.js:51807:37)
at snipScriptAndStyleTagContent (dprint:prettier.js:51791:31)
at Object.preprocess (dprint:prettier.js:53266:20)
at Object.m [as parse] (dprint:prettier.js:3311:47)
at b (dprint:prettier.js:3858:43)
at D (dprint:prettier.js:3923:194)
at dprint:prettier.js:11460:136
at Object.format (dprint:prettier.js:11465:20)
This is the result of running dprint fmt
on https://github.com/sveltejs/template with this minimal configuration:
{
"prettier": {},
"includes": [
"**/*.svelte"
],
"excludes": [
"**/node_modules"
],
"plugins": [
"https://plugins.dprint.dev/prettier-0.7.0.json@4e846f43b32981258cef5095b3d732522947592e090ef52333801f9d6e8adb33"
]
}
But the exact same error seems to appear with any svelte files and with other dprint configurations.
It appears this was a regression in 0.6.0
- older versions of dprint with 0.5.1
(and earlier) work fine, so I'd guess the rewrite to deno_core
in #14 caused some issue with at least this plugin (I haven't tested astro to see if it's affected too)
So as soon as you add "plugin.jsDoc": true to the config all multiline comments get joined to have 100% width.
Is that intended?
I tried to counter it with proseWrap but that did not change anything. What if I want to preserve linebreaks?
prettier-plugin-organize-imports
is a plugin that automatically runs tsserver's "organize imports" after prettier runs. This transforms the code (reordering imports and perhaps removing them), which goes beyond prettier's standard scope. I can see someone not wanting to do this, so possibly this should be configurable as to whether this runs or not, if this issue is accepted.
Hi,
I am possibly not understanding the use case of this plugin correctly but,
When I am using the plugin to format the code base, to write so to speak, it doesn't do that. Am I doing something wrong here?
Running the command dprint check
will only log the found required changes in the console and than error out - no changes to the code base are made.
I am running:
This is my dprint.json
:
{ "includes": ["src/**/*.{js,jsx,json,md,tsx,ts}"], "excludes": ["/node_modules, /build, /dist, /.git, /public"], "prettier": { "trailingComma": "es5", "tabWidth": 2, "semi": false, "singleQuote": true }, "plugins": [ "https://plugins.dprint.dev/prettier-0.10.0.json@ca9a97de84cbb2cd60534eb72c0455f3ca8704743917569ace70499136cf5c9c" ] }
This is a follow up for #11. Even with the "why this plugin exists" section in the README, my working assumption (like the OP in #11) was:
dprint will format most files, but prettier will format the files that dprint doesn't support (e.g: svelte)
The note on precedence in the plugin docs is helpful, but I read it separated with time from when I was using this plugin and didn't immediately put two and two together.
Even if I'm not using plugins that overlap in functionality, it's insightful to just know the soup to nuts of how Dprint works. I think the quote in #11 captures that:
Dprint's CLI has no clue about how to format any kind of file. The plugins do that. So if you use the prettier plugin then it will format using prettier. If you use another plugin like dprint-plugin-typescript in addition to dprint-plugin-prettier, then you can get it formatting JavaScript and TypeScript code with dprint-plugin-typescript by putting the url for dprint-plugin-typescript before dprint-plugin-prettier's url in the plugins array of the configuration file.
I'd consider including a version of this quote not only in this plugin, but also in the main Dprint README.
Please, add prettier-plugin-astro
Right now it will throw an error on every format if the config is wrong.
Prettier doesn't have built-in support for XML files, nor does dprint have any plugins to support it.
It would be nice to have an XML plugin pre-installed with the plugin set as its a common occurrence to come across XML files in a dev env.
If I leave the typescript settings empty but add "singleQuote": true to the prettier config in the dprint.json the default typescript double quote will overrule the prettier settings every time.
I would like to format a Rust file with Rustfmt but have the contents of a macro (html!
in this case) be formatted with prettier.
This is required because Rustfmt doesn't touch anything inside a macro invocation - those tokens are ignored. html!
has a syntax very similar to that to HTML so Prettier can be used for format it's contents.
Is this possible to achieve? If so, how? If not, would it be possible/feasible to add support for this?
after running dprint config add prettier
I see dprint attempt to download the plugin (twice), which looks as follows
finally I get the following error:
Error resolving plugin https://plugins.dprint.dev/prettier-0.30.0.json: Error starting /home/adrian/.cache/dprint/cache/plugins/dprint-plugin-prettier/0.30.0/x86_64/dprint-plugin-prettier with args [--parent-pid 740234 --init]. No such file or directory (os error 2)
also:
> ls -al /home/adrian/.cache/dprint/cache/plugins/dprint-plugin-prettier/0.30.0/
total 8
drwxr-xr-x 2 adrian users 4096 Dec 15 17:14 .
drwxr-xr-x 3 adrian users 4096 Dec 15 17:00 ..
OS: NixOs
linux kernel version: 6.5.13
Add support to nice package.json sorting using either one of those:
dprintrc.json
{
"$schema": "https://dprint.dev/schemas/v0.json",
"projectType": "educational",
"prettier": {
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"printWidth": 100,
"bracketSpacing": true,
"arrowParens": "always"
},
"incremental": true,
"includes": ["**/*.{.vue,ts,js}"],
"excludes": ["**/node_modules", "**/*-lock.json"],
"plugins": [
"https://plugins.dprint.dev/prettier-0.2.1.exe-plugin@c051918d0c4cf082b5ccdf92e89af3dcb2859e18f75073ba16dda6366e493a03"
]
}
drpint
command is not respecting my "prettier"
section of the config file. Am I missing something?
Hello,
I'm trying to get dprint to work with prettier using the prettier-plugin-svelte
. Is this supported?
I confirmed I can format fine with the local prettier installed in the project, but dprint says no files were found with the given plugins.
➜ something dprint fmt src/routes/index.svelte
No files found to format with the specified plugins. You may want to try using `dprint output-file-paths` to see which files it's finding.
Waiting on dprint/dprint#283
Can you please add prettier-plugin-tailwindcss
to this package? Thanks!
If I had control over the formatting settings on all the projects I work on, I'd give them all the same settings and copy those settings to the prettier
section in dprint.json
.
(Or even just use dprint's native formatting.)
However, I don't.
How can I ensure that dprint-plugin-prettier
always uses the specific .prettierrc
file that is relevant to whatever file that it is formatting at the time?
The plugin URLs listed in the releases page are throwing 404 errors.
Running dprint check
just hangs forever.
Screenshot of dev tools for:
https://plugins.dprint.dev/prettier-0.17.0.json@5e42cbabab9906ad32ffe1aa67f15824b1c39408840f0afeaddc495dd362e177
As I have issues with configuration (see #39) I can't get it to respect the .prettierrc
config.
Is it meant to use it?
This plugins.dprint.dev page can’t be foundNo web page was found for the web address: https://plugins.dprint.dev/prettier-0.24.0.json@9a57d0d8e440ad90d07a503166af47e7a6a886abd46767933f9c279f72468596
HTTP ERROR 404
Please add support for prettier-plugin-jsdoc
https://www.npmjs.com/package/prettier-plugin-jsdoc
https://github.com/hosseinmd/prettier-plugin-jsdoc
dprint 0.41.0
dprint.json
:
{
"typescript": {
"quoteStyle": "preferSingle",
"semiColons": "asi"
},
"prettier": {
"printWidth": 100,
"semi": false,
"singleQuote": true,
"trailingComma": "all",
"vueIndentScriptAndStyle": true
},
"excludes": [
"**/node_modules",
"**/*-lock.json",
"./dist",
"./target",
"./src/shared/api/openapi",
"./playwright-report"
],
"plugins": [
"https://plugins.dprint.dev/prettier-0.27.0.json@3557a62b4507c55a47d8cde0683195b14d13c41dda66d0f0b0e111aed107e2fe",
"https://plugins.dprint.dev/typescript-0.87.1.wasm",
"https://plugins.dprint.dev/json-0.17.4.wasm",
"https://plugins.dprint.dev/markdown-0.16.1.wasm",
"https://plugins.dprint.dev/dockerfile-0.3.0.wasm"
]
}
Run: dprint fmt --incremental=false --verbose
WARNING: Formatting is slow for C:\[path_to_project]\test\jest\coverage\coverage-final.json
[VERBOSE] CPU usage: 19%
[VERBOSE] CPU usage: 27%
[VERBOSE] Low CPU. Increasing parallelism.
[VERBOSE] CPU usage: 27%
[VERBOSE] Low CPU. Increasing parallelism.
[dprint-plugin-prettier]
<--- Last few GCs --->
[24236:000002543EDB8110] 17592 ms: Scavenge 1389.4 (1413.5) -> 1388.1 (1417.8) MB, 1.85 / 0.00 ms (average mu = 0.284, current mu = 0.255) allocation failure;
[24236:000002543EDB8110] 17599 ms: Scavenge 1391.9 (1418.0) -> 1389.8 (1418.5) MB, 2.42 / 0.00 ms (average mu = 0.284, current mu = 0.255) allocation failure;
[24236:000002543EDB8110] 17604 ms: Scavenge 1392.2 (1418.5) -> 1391.1 (1419.8) MB, 3.57 / 0.00 ms (average mu = 0.284, current mu = 0.255) allocation failure;
Error reading stdout message: failed to fill whole buffer
<--- JS stacktrace --->
#
# Fatal JavaScript out of memory: Ineffective mark-compacts near heap limit
#
[dprint]
[VERBOSE] CPU usage: 18%
[VERBOSE] CPU usage: 5%
[VERBOSE] CPU usage: 3%
[VERBOSE] CPU usage: 2%
[VERBOSE] CPU usage: 2%
[VERBOSE] CPU usage: 4%
...
Hi.
The plugin fails in the ubuntu-22.04
CI but works locally.
jobs:
code_quality:
name: Code quality
runs-on: ubuntu-22.04
steps:
- name: Checkout source code
uses: actions/checkout@v4
- uses: taiki-e/install-action@dprint
- name: Show version information
shell: bash
run: |
dprint --version
- name: Ensure `fmt` has been run
run: dprint check
Run dprint --version
dprint 0.41.0
2s
Run dprint check
dprint check
shell: /usr/bin/bash -e {0}
Compiling https://plugins.dprint.dev/markdown-0.16.2.wasm
Compiling https://plugins.dprint.dev/toml-0.5.4.wasm
Error resolving plugin https://plugins.dprint.dev/prettier-0.27.0.json: Unsupported CPU architecture: x86_64 (linux-musl)
Error: Process completed with exit code 12.
But it works locally.
Fedora Linux 38 (Workstation Edition)
🙊 dprint --version
dprint 0.41.0
In dprint 0.39.1 and config with prettier-0.26.6, dprint config update
updates the config, but dprint check
and dprint fmt
fails after updated
[dprint-plugin-prettier]
Shutting down due to error: failed to fill whole buffer
Error resolving plugin https://plugins.dprint.dev/prettier-0.27.0.json: Failed plugin schema verification. This may indicate you are using an old version of the dprint CLI or plugin and should upgrade.: The plugin schema version was 5, but expected 4.
In dprint 0.40.0 and config with prettier-0.26.6, dprint config update
failed with handling old plugins messages
[dprint-plugin-prettier]
Shutting down due to error: Error reading message from stdin.
Shutting down due to error: Error reading message from stdin.
Error resolving plugin https://plugins.dprint.dev/prettier-0.26.6.json: Failed plugin schema verification. This may indicate you are using an old version of the dprint CLI or plugin and should upgrade.: The plugin schema version was 4, but expected 5.
In this case, I should first update the config with dprint 0.39.1 and then immediately upgrade dprint to 0.40.0. Is this an intended migration flow?
I feel a bit silly, I found this plugin b/c it helped me use dprint with svelte & astro.
But I'm wondering what does this plugin actually do? If it runs prettier, won't that make the speed benefits of dprint useless?
As title.
I tried to dprint-plugin-prettier with svelte, and got an error for svelte 5 syntax.
The latest prettier-plugin-svelte works fine for the svelte 5 syntax. And I installed the latest prettier-plugin-svelte in my node project.
idk how to solve this problem
The below Astro file will fail to format with this error, however formatting it with prettier
using prettier-plugin-astro
directly parses the file successfully.
Message: ParseError: (0 , $029a36b82dce9f90$var$import__2.default) is not a function
at $72712c1d1f727ace$var$error (dprint:prettier.js:150:17)
at $8edc5f76a317f62c$var$Parser.error (dprint:prettier.js:415:56)
at $8edc5f76a317f62c$var$Parser.acorn_error (dprint:prettier.js:409:14)
at $029a36b82dce9f90$var$read_expression (dprint:prettier.js:6519:16)
at $dd20ca6627ece4f3$var$mustache (dprint:prettier.js:9673:80)
at new $8edc5f76a317f62c$var$Parser (dprint:prettier.js:382:57)
at Object.$8edc5f76a317f62c$var$parse (dprint:prettier.js:491:20)
at Object.$65e641842dbfc372$var$parse [as parse] (dprint:prettier.js:84132:71)
at Object.h [as parse] (dprint:prettier.js:67890:36)
at N (dprint:prettier.js:68555:51)
Had 1 error(s) formatting.
---
---
<html lang="en">
<body>
{[1, 2, 3].map((n) => <div>{n}</div>)}
</body>
</html>
It is worth noting that the following file parses successfully unlike the above file.
---
---
<html lang="en">
<body>
{[1, 2, 3].map((n) => n)}
</body>
</html>
The latest dprint 0.40 adds functionality that makes this possible. Essentially, I would like to add prettier plugins, which are available at urls.
{
"prettier": {
"plugins": [
"https://prettier.dprint.dev/astro-0.11.0.js",
"https://prettier.dprint.dev/svelte-3.0.3.js"
]
},
"plugins": [
"https://plugins.dprint.dev/prettier-0.26.6.json@0118376786f37496e41bb19dbcfd1e7214e2dc859a55035c5e54d1107b4c9c57"
]
}
dprint config update
After process plugin schema v4 is done, this plugin should be rewritten using deno_core and format files in parallel.
Hello, would like to know if you are open to a PR for accepting the prettier-plugin-solidity integration?
I'm currently trying to migrate a project to dprint but due to a specific problem with formating in the dprint ts plugin I was trying to make dprint use prettier instead (just to be faster)
The problem is that our project is using a really outdated version of prettier (1.18.2) and upgrading it will change a lot of files (more files than if I were to use the ts plugin)
I was assuming that the prettier plugin would use the one from my package json, but that's not true, it takes the version from here right?
Would be nice to have the prettier version info available at the release notes and/or a way to choose a specific version of prettier (although not doing that forces people to upgrade prettier... which is good)
I installed dprint
with cargo
, and configured my project with dprint init
. I tried to use this Prettier plugin but it fails with the following message:
> dprint check
[dprint-plugin-prettier]
Catastrophic error sending response. At point of no recovery: Error: EBADF: bad file descriptor, write
Error: EBADF: bad file descriptor, write
[dprint]
Error getting plugin from cache. Forgetting from cache and retrying. Message: There was a problem checking the plugin schema version. This may indicate you are using an old version of the dprint CLI or plugin and should upgrade. failed to fill whole buffer
[dprint-plugin-prettier]
Catastrophic error sending response. At point of no recovery: Error: EBADF: bad file descriptor, write
Error: EBADF: bad file descriptor, write
Error resolving plugin https://plugins.dprint.dev/prettier-0.2.0.exe-plugin: There was a problem checking the plugin schema version. This may indicate you are using an old version of the dprint CLI or plugin and should upgrade. failed to fill whole buffer
{
"$schema": "https://dprint.dev/schemas/v0.json",
"projectType": "educational",
"incremental": true,
"typescript": {},
"json": {},
"markdown": {},
"includes": ["**/*.{vue,ts,tsx,js,jsx,json,md}"],
"excludes": ["**/node_modules", "**/*-lock.json"],
"plugins": [
"https://plugins.dprint.dev/typescript-0.40.3.wasm",
"https://plugins.dprint.dev/json-0.8.0.wasm",
"https://plugins.dprint.dev/markdown-0.5.1.wasm",
"https://plugins.dprint.dev/prettier-0.2.0.exe-plugin@5fc84274198107b5464477803eea335ab3c978738ff40058294b105d2e32d5ae"
],
"prettier": {
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"printWidth": 100,
"bracketSpacing": true,
"arrowParens": "always"
}
}
Hello, could you advise if #17 works with other prettier overrides, or is it only for singleQuote
?
I tried to do the indentWidth
but it is not picking it up.
[dprint-plugin-prettier]
Error reading stdout message: failed to fill whole buffer
log
WARNING: Formatting is slow for some file x10
system
fedora:39
pnpm: 8.14.0
node: 20.10.0
First will be #64
Looking at #12 (comment) and 478d477, it looks like the way to implement a new plugin is:
plugins
Is this correct? If so, given a plugin that can run in a browser, could you allow a plugin array to be configured in dprint.json
, and use await import('prettier-plugin-name')
or some other form of dynamic require to install user configured (and user-installed) plugins? I think this would require at least node 14 for top-level await, but 12 has just gone end-of-life.
I ask this because while it would be feasible for you to add everyone's plugins one by one, that seems like potentially a lot of overhead (and version increments) compared with having configuration available for a user to do it themselves.
As title. This should be rewritten to run in Node.js and give people the ability to specify any plugin.
The current way that bundles and runs in deno_core is too much of a pain to make work with prettier 3.0.
Luckily, this is how it previously was about a year ago anyway, so I can just revert most of the code.
Thanks for making this -- it's a lot faster than prettier straight.
Unfortunately I can't port my config over. Prettier supports automatically reading config from a .editorconfig
file, and I'm using that to use single quotes in .ts
files and double quotes elsewhere (e.g. SCSS)
[*]
quote_type = double
[*.ts]
quote_type = single
Could you make it possible to specify prettier config for extensions individually? For example, something like:
{
"prettier": {
"singleQuote": false,
"ts.singleQuote": true
}
}
would translate the above (although there might be a better design).
Would it be possible to add prettier version information to automatic release notes in GitHub? You can access this information by opening commits, but it would be really nice if I could already see this on GitHub homepage feed. :)
The way I'm testing this is in the TypeScript repo:
$ git clone [email protected]:microsoft/TypeScript.git
$ cd TypeScript
$ npm ci
$ npx dprint fmt --incremental=false
Sometimes, I get random errors and have to Ctrl-C:
$ npx dprint fmt --incremental=false
$ npx dprint fmt --incremental=false
$ npx dprint fmt --incremental=false
$ npx dprint fmt --incremental=false
[dprint-plugin-prettier]
malloc(): unaligned tcache chunk detected
Error reading stdout message: failed to fill whole buffer
^C
$ npx dprint fmt --incremental=false
$ npx dprint fmt --incremental=false
$ npx dprint fmt --incremental=false
$ npx dprint fmt --incremental=false
[dprint-plugin-prettier]
free(): double free detected in tcache 2
Error reading stdout message: failed to fill whole buffer
^C
I'm holding everything back at 0.27; the problem does not seem to be related to the dprint CLI version.
I have the config:
{
"typescript": {
"quoteStyle": "preferSingle"
},
"json": {},
"markdown": {},
"toml": {},
"dockerfile": {},
"includes": [
"**/*.{vue, ts,tsx,js,jsx,cjs,mjs,json,md,toml,dockerfile}"
],
"prettier": {
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all",
"overrides": [
{
"files": "*.vue",
"options": {
"vueIndentScriptAndStyle": true
}
}
]
},
"excludes": [
"**/node_modules",
"**/*-lock.json",
"./dist"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.74.0.wasm",
"https://plugins.dprint.dev/json-0.15.6.wasm",
"https://plugins.dprint.dev/markdown-0.14.1.wasm",
"https://plugins.dprint.dev/toml-0.5.4.wasm",
"https://plugins.dprint.dev/dockerfile-0.3.0.wasm",
"https://plugins.dprint.dev/prettier-0.15.0.json@ff80be22d9d596d17a1ca0767e2cbdddd518cf7d23773045ab90d12dfc63f5d5"
]
}
I have the component:
<template>
<div />
</template>
<script setup lang="ts">
import { computed } from 'vue';
</script>
I expect that after formatting, the indentation of the script section will be preserved, but it disappears:
<template>
<div />
</template>
<script setup lang="ts">
import { computed } from 'vue';
</script>
That is, the overrides property is ignored.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.