npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

go-prettier-format

v0.1.3

Published

Prettier plugin for Go, powered by WASM.

Downloads

24

Readme

Prettier Plugin for Go (using WASM)

npm version License: MIT

This is a Prettier v3 plugin for the Go programming language. It formats Go code using the official go/format package, which is compiled to WebAssembly (WASM) to run in a Node.js environment.

Background

As web developers, we love the consistent code style that Prettier brings to our projects. However, when working on projects that involve Go - for instance, a Go backend with a JavaScript frontend, or writing Go code in a web-based editor - the ability to format Go code with the same familiar tool was missing.

This project was born out of the desire to have a single, unified formatting toolchain. Instead of relying on external gofmt binaries, which can be brittle to manage in a Node.js-based development environment, this plugin leverages the power of WebAssembly. We compile Go's own formatting tools into a WASM module, allowing you to format Go code directly within your JavaScript-based tools, ensuring speed, portability, and consistency.

Installation

First, install Prettier (v3 or later) and this plugin from NPM:

npm install --save-dev prettier go-prettier-format

The plugin comes with a pre-compiled WASM module, so you don't need to have Go installed on your machine to use it.

Usage

Command Line

You can run Prettier from the command line to format your Go files:

# Format a specific file
npx prettier --write your-file.go

# Format all .go files in the project
npx prettier --write "**/*.go"

Note: For cross-platform compatibility in npm scripts, it's recommended to use single quotes: '**/*.go'.

package.json Script

For convenience, you can add a script to your package.json:

{
  "scripts": {
    "format": "prettier --write '**/*.go'"
  }
}

Editor Integration

Once installed, Prettier-compatible editors (like VS Code with the Prettier extension) should automatically pick up the plugin and use it to format .go files on save.

For Contributors

Interested in contributing? Here's how to get set up for development.

Development Setup

Option 1: Local Development (Requires Go + Node.js)

You will need to have Go (1.21+) and Node.js (18+) installed on your machine.

  1. Clone the repository and install dependencies:

    git clone https://github.com/gitdog01/go-prettier-format.git
    cd go-prettier-format
    npm install
  2. Build the WASM module:

    npm run build:wasm

Option 2: Docker Development (No Local Go/Node.js Required)

If you prefer not to install Go and Node.js locally, you can use Docker:

  1. Clone the repository:

    git clone https://github.com/gitdog01/go-prettier-format.git
    cd go-prettier-format
  2. Build using Docker:

    # Build the project
    docker build -t go-prettier-format .
        
    # Run tests
    docker run --rm go-prettier-format
        
    # Extract built artifacts (optional)
    docker run --rm -v $(pwd):/output go-prettier-format sh -c "cp go.wasm /output/ && cp -r dist /output/"
  3. Development with Docker Compose (recommended):

    # Build the project
    docker-compose run --rm build
        
    # Run tests
    docker-compose run --rm test
        
    # Development mode (build + test)
    docker-compose run --rm dev

Docker Quick Start

If you just want to try the plugin without installing Go or Node.js:

# Clone and test
git clone https://github.com/gitdog01/go-prettier-format.git
cd go-prettier-format
docker-compose run --rm test

Testing the Plugin

This repository comes with a set of test files to verify the plugin's functionality.

To run the tests:

npm test

This command will:

  • Build the latest version of the plugin from source.
  • Create a test_result directory.
  • Copy the sample files from the tests/ directory into it.
  • Run the Prettier formatter on the files inside test_result/.

You can then compare the original files in tests/ with the formatted files in test_result/ to see the plugin in action. For example, tests/messy.txt will be cleaned up, while tests/error.txt (which contains a syntax error) will remain untouched.

Note: The test files use a .txt extension to prevent editors from automatically formatting them. The test script tells Prettier to treat these .txt files as Go code.

Publishing to NPM

This package is configured to build automatically before publishing.

  1. Update the version number in package.json using npm version <patch|minor|major>.
  2. Run npm publish.

The prepublishOnly script will handle building the Wasm and JavaScript bundles before the package is uploaded to the registry.

How it Works

  1. The core formatting logic from Go's standard library (go/format) is compiled into a WebAssembly (.wasm) file.
  2. The wasm_exec.js script provided by Go is used to load and run the WASM module in Node.js.
  3. This Prettier plugin loads the WASM module and exposes the Go formatting function to Prettier's printing process.
  4. When Prettier processes a .go file, this plugin passes the code to the WASM module, which formats it and returns the result.

This approach ensures that the formatting is identical to what gofmt would produce, without needing a Go installation on the machine running the formatter.