Giter Site home page Giter Site logo

dprint-plugin-prettier's Introduction

dprint

CI Homebrew

Monorepo for dprint—a pluggable and configurable code formatting platform.

Links

Plugins

Notes

This repo is under active early development.

  1. The interface between the CLI and plugins might change often. You may need to keep updating to the latest version of both the CLI and plugins (the CLI will let you know what to do).
    • An upgrade path will be outlined in the release notes when this occurs.
  2. I do a lot of this development in my spare time. Please consider sponsoring if you are a commercial company using this.

dprint-plugin-prettier's People

Contributors

aminya avatar dprintbot avatar dsherret avatar joscha avatar oplik0 avatar rubixdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dprint-plugin-prettier's Issues

Support file extension-specific configuration

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).

Allow plugins to be configured from outside the package without developer intervention

Looking at #12 (comment) and 478d477, it looks like the way to implement a new plugin is:

  • confirm that it can run in a browser
  • install it as a dependency
  • import it in messageProcessor (now main.ts)
  • add it to 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.

Fails to run on linux

Problem

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

Environment

  • dprint version: 0.11.1
  • config file:
{
  "$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"
  }
}

dprint fails to add the plugin to cache on nixos

after running dprint config add prettier I see dprint attempt to download the plugin (twice), which looks as follows

Screenshot_20231215_171317

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

dprint check - Doesn't format?

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:

  • "dprint": "^0.30.3",

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" ] }

Document precedence in the README

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.

Bug: Doesn't work "overrides" property for vue

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.

What is this plugin for?

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?

Add prettier/plugin-xml as a default plugin

Plugin

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.

New plugin system

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"
  ]
}
  1. These scripts run sandboxed and do not have access to the file system or network.
  2. They are automatically upgraded when someone runs dprint config update
  3. No need to specify file extensions or associations. The plugin will provide it.
  4. Probably each plugin needs to be a single bundled javascript file in order to reduce the complexity.

prettier-plugin-svelte is not latest

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 upgrade path of dprint-plugin-prettier from 0.26.6 to 0.27.0 requires both dprint 0.39.1 and 0.40.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?

Which prettier version is being used and how can I choose a specific one?

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)

Q: "plugin.jsDoc": true and multiline comments

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-svelte

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.

Not respecting "pretter" config's

My 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"
  ]
}

Problem

drpint command is not respecting my "prettier" section of the config file. Am I missing something?

Parse Error on Astro File

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>

Unsupported CPU architecture: x86_64 (linux-musl)

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

Rewrite to run in Node.js and ability to specify any plugin

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.

Plugin: prettier-plugin-organize-imports

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.

Error on formating

[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

Rewrite using deno_core

After process plugin schema v4 is done, this plugin should be rewritten using deno_core and format files in parallel.

Formatting part of a Rust file with a prettier

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?

Use relevant `.prettierrc` from each project

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?

Fatal JavaScript out of memory: Ineffective mark-compacts near heap limit

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%
...

Breaks on svelte files with `Uncaught ReferenceError: Buffer is not defined`

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)

Random errors in versions 0.28.x and above

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.