dprint / dprint-plugin-exec Goto Github PK
View Code? Open in Web Editor NEWFormatting plugin for dprint that formats code via other formatting CLI tools.
License: MIT License
Formatting plugin for dprint that formats code via other formatting CLI tools.
License: MIT License
The command in the config here (#23 (comment)):
"exec": {
"associations": [
"**/*.{sh,bash}",
"**/package.json"
],
"prettier-package-json.associations": "**/package.json",
"prettier-package-json": "node_modules/.bin/prettier-package-json"
},
...has files prettier-package-json
, prettier-package-json.cmd
and prettier-package-json.ps1
, but doesn't work on Windows:
Error formatting V:\scratch-npm\package.json. Message: Cannot start formatter process: %1 is not a valid Win32 application. (os error 193)
...unless the .cmd
extension is provided. It should work cross platform and not require this extension.
Right now it splits based on spaces:
dprint-plugin-exec/src/configuration.rs
Lines 102 to 106 in d6b0a78
But it should take into account quotes.
Some formatter tools like black
from Python have no option for printing to the stdout. There should be an option so that those tools can directly write to the file without warnings.
This is too verbose:
"exec": {
"associations": [
"**/*.{sh,bash}",
"**/package.json"
],
"prettier-package-json.associations": "**/package.json",
"prettier-package-json": "node_modules/.bin/prettier-package-json --write",
"prettier-package-json.stdin": false
}
It should allow for something along these lines now that dprint supports it:
"exec": {
"associations": [
"**/*.{sh,bash}",
"**/package.json"
],
"prettier-package-json": {
"associations": "**/package.json",
"command": "node_modules/.bin/prettier-package-json --write",
"stdin": false
}
}
I'm trying to format with xo
using this plugin, but it seems like xo
is never being called.
Minimal config:
{
"excludes": ["**/node_modules"],
"plugins": [
"https://plugins.dprint.dev/typescript-0.87.1.wasm",
"https://plugins.dprint.dev/exec-0.4.3.json@42343548b8022c99b1d750be6b894fe6b6c7ee25f72ae9f9082226dd2e515072"
],
"exec": {
"commands": [{
"command": "xo --fix --stdin --stdin-filename={{file_path}}",
"exts": ["js", "jsx", "ts", "tsx"]
}]
}
}
Minimal repro: https://github.com/tommy-mitchell/dprint-repro-exec-xo
I broke the last release on mac. There should be some way to test this in integration. No, I didn't break the build. I was just accidentally running an old release that was broken.
As title.
Not a big deal, but I think we could replace handlebars with a few string replaces or a custom function that handles it.
$ cargo bloat --release --crates
File .text Size Crate
12.9% 43.4% 367.8KiB std
7.6% 25.5% 216.2KiB handlebars
3.5% 11.8% 99.7KiB tokio
1.6% 5.5% 46.8KiB dprint_plugin_exec
1.3% 4.2% 35.8KiB serde_json
0.8% 2.6% 21.7KiB dprint_core
0.5% 1.7% 14.2KiB parking_lot
0.3% 1.1% 9.5KiB serde
0.2% 0.8% 6.9KiB pest
0.2% 0.7% 6.1KiB num_cpus
0.1% 0.4% 3.5KiB anyhow
0.1% 0.3% 2.5KiB parking_lot_core
0.1% 0.2% 1.9KiB [Unknown]
0.1% 0.2% 1.5KiB signal_hook_registry
0.0% 0.2% 1.3KiB once_cell
0.0% 0.1% 1.2KiB splitty
0.0% 0.1% 1.1KiB memchr
0.0% 0.0% 430B smallvec
0.0% 0.0% 310B mio
29.6% 100.0% 848.1KiB .text section size, the file size is 2.8MiB
After:
$ cargo bloat --release --crates
File .text Size Crate
13.1% 58.2% 324.5KiB std
4.0% 17.8% 99.4KiB tokio
1.5% 6.5% 36.2KiB dprint_plugin_exec
0.9% 4.2% 23.4KiB serde_json
0.9% 4.0% 22.4KiB dprint_core
0.6% 2.5% 14.2KiB parking_lot
0.4% 1.7% 9.5KiB serde
0.2% 1.1% 6.1KiB num_cpus
0.1% 0.6% 3.5KiB anyhow
0.1% 0.4% 2.5KiB parking_lot_core
0.1% 0.3% 1.9KiB [Unknown]
0.1% 0.3% 1.6KiB signal_hook_registry
0.1% 0.2% 1.3KiB once_cell
0.0% 0.2% 1.2KiB splitty
0.0% 0.2% 1.1KiB memchr
0.0% 0.1% 430B smallvec
0.0% 0.1% 310B mio
22.4% 100.0% 557.1KiB .text section size, the file size is 2.4MiB
Version: 0.34.5
I'm running prettier-package-json with the exec plugin. The associated files are formatted just fine but dprint exits with the error:
The original file text was greater than 100 characters, but the formatted text was empty. Perhaps dprint-plugin-exec has been misconfigured?
Entire config file attached, but heres exec:
"exec": {
"associations": [
"**/*.{sh,bash}",
"**/package.json"
],
"prettier-package-json.associations": "**/package.json",
"prettier-package-json": "node_modules/.bin/prettier-package-json --write",
}
Got something wrong with the config or a bug?
Given the recent versions, I am forced to use dprint-plugin-exec
for formatting the rust files. However, I have noticed ~3 times a slow down in my project. It seems that passing individual files to rustfmt is much slower than letting it handle multiple files at the same time in parallel.
I must not understand the exec configuration correctly, because I get this error when I have a file that matches the exec associations globs.
$ dprint fmt package.json
Error creating plugin dprint-plugin-exec. Message: data did not match any variant of untagged enum ConfigKeyValue at line 1 column 183
Had 1 error(s) formatting.
{
"$schema": "https://dprint.dev/schemas/v0.json",
"lineWidth": 120,
"indentWidth": 2,
"includes": [
"**/*.{ts,tsx,js,jsx,cjs,mjs}",
"**/*.{json,md,toml}",
"**/*.dockerfile",
"**/Dockerfile",
"**/package.json",
"**/*.{bash,sh}"
],
"excludes": [
"**/node_modules",
"**/*-lock.{json,yaml}",
"__package_previews__",
".eslintcache",
".jest-cache",
".moon/cache",
".next/",
".parcel-cache",
".store",
"**/build",
"**/coverage",
"**/storybook-static",
"**/vendored"
],
"typescript": {
"associations": ["**/*.{ts,tsx,js,jsx,cjs,mjs}"],
"binaryExpression.operatorPosition": "sameLine",
"memberExpression.linePerExpression": true,
"preferSingleLine": true,
"quoteStyle": "preferSingle"
},
"json": {
"associations": ["**/*.{json,jsonc}", "!**/package.json"]
},
"exec": {
"associations": ["**/package.json", "**/*.{bash,sh}"],
"prettier-package-json": "node_modules/.bin/prettier-package-json --write {{file_path}}",
"prettier-package-json.associations": ["**/package.json"],
"shfmt": "shfmt --write --simplify --filename {{file_path}} -i 2 -bn -ci -sr -kp -",
"shfmt.associations": "**/*.{bash,sh}"
},
"plugins": [
"https://plugins.dprint.dev/exec-0.3.1.json@9351b67ec7a6b58a69201c2834cba38cb3d191080aefc6422fb1320f03c8fc4d",
"https://plugins.dprint.dev/typescript-0.78.0.wasm",
"https://plugins.dprint.dev/json-0.16.0.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.13.0.json@dc5d12b7c1bf1a4683eff317c2c87350e75a5a3dfcc127f3d5628931bfb534b1"
]
}
What am I doing wrong?
Right now it is limited to one configured binary.
It seems dprint lsp
doesn't format using commands provided in exec section. dprint fmt
works for exec commands though. I use the following global configuration, which i reference when starting an lsp or using fmt using --config path
argument. I am using neovim and I make sure that an lsp client is attached to current buffer, which is connected to dprint lsp, filetypes like markdown and json etc are formatted by dprint lsp fine but perl files aren't which are mentioned in commands exts
field, as seen below.
{
"typescript": {
},
"json": {
},
"markdown": {
"lineWidth": 67,
"textWrap": "always"
},
"toml": {
},
"dockerfile": {
},
"exec": {
"commands": [
{
"command": "perltidy -l 67 -i 2",
"exts": ["pl", "pm"]
}
]
},
"excludes": [
"**/node_modules",
"**/*-lock.json"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.88.10.wasm",
"https://plugins.dprint.dev/json-0.19.1.wasm",
"https://plugins.dprint.dev/markdown-0.16.3.wasm",
"https://plugins.dprint.dev/toml-0.6.0.wasm",
"https://plugins.dprint.dev/dockerfile-0.3.0.wasm",
"https://plugins.dprint.dev/prettier-0.35.0.json@0df49c4d878bb1051af2fa1d1f69ba6400f4b78633f49baa1f38954a6fd32b40",
"https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7"
]
}
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.