prettier-plugin-wgsl

raw JSON →
0.1.9 verified Sat Apr 25 auth: no javascript

A Prettier plugin that formats WGSL (WebGPU Shading Language) files. Version 0.1.9 is the latest stable release. It uses Chevrotain for parsing and is inspired by prettier-plugin-glsl. Works with Prettier >=3.0.0 and ships TypeScript types. As WGSL is still evolving, this plugin may lag behind spec changes. It is the primary option for formatting WGSL code in WebGPU projects.

error Cannot find module 'prettier-plugin-wgsl'
cause The plugin is not installed or not in node_modules.
fix
Run npm install --save-dev prettier-plugin-wgsl
error Couldn't resolve parser 'wgsl'
cause Prettier is older than 3.0.0 or plugin not loaded.
fix
Update Prettier to >=3.0.0 and add plugin to plugins config.
error Uncaught SyntaxError: Unexpected token
cause WGSL syntax not supported by the plugin version.
fix
Update the plugin to latest version or report the issue on GitHub.
gotcha Ensure Prettier version is >=3.0.0; older versions are incompatible.
fix Upgrade Prettier to 3.0.0 or later.
gotcha The plugin may not support all WGSL syntax if the language spec has been updated after the plugin release.
fix Check the plugin's GitHub repository for updates or open an issue.
gotcha The plugin must be listed in the 'plugins' array of Prettier config; simply installing is not enough.
fix Add 'prettier-plugin-wgsl' to your Prettier configuration plugins array.
npm install prettier-plugin-wgsl
yarn add prettier-plugin-wgsl
pnpm add prettier-plugin-wgsl

Shows how to install and configure the plugin, then format a WGSL file via CLI.

// Install: npm install --save-dev prettier prettier-plugin-wgsl
// Add to .prettierrc:
{
  "plugins": ["prettier-plugin-wgsl"],
  "semi": true
}
// Format a file:
// npx prettier --write shader.wgsl