Registry / devops / prettier-plugin-apex

prettier-plugin-apex

JSON →
library2.2.6jsnpmunverified

A plugin for Prettier that formats Salesforce Apex code. Current stable version is 2.2.6, maintained by the Salesforce developer community. It supports all Apex syntax including triggers, classes, and anonymous blocks. Release cadence is irregular but active. Key differentiators: it is the only actively maintained Prettier plugin for Apex, integrates seamlessly with Prettier's CLI and APIs, and supports modern Apex features like lambda expressions and enhanced loops.

npm install prettier-plugin-apex
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-AP
P
prettier-plugin-apex
devopsjavascriptv2.2.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import prettier from 'prettier';
const prettier = require('prettier');
Prettier is ESM-only since v3; use dynamic import or ES module syntax.
plugin
import * as prettierPluginApex from 'prettier-plugin-apex';
const prettierPluginApex = require('prettier-plugin-apex');
Plugin is ESM-only; use ES import syntax.
Options
import type { Options } from 'prettier';
import { Options } from 'prettier-plugin-apex';
Plugin does not export its own types; use Prettier's Options type.

Formats a simple Apex class using Prettier with the Apex plugin.

import prettier from 'prettier'; import * as prettierPluginApex from 'prettier-plugin-apex'; const code = `public class MyClass { public static void test() { System.debug('hello'); } }`; prettier.format(code, { parser: 'apex', plugins: [prettierPluginApex], apexInsertFinalNewline: true, }).then(result => console.log(result)); // Output: // public class MyClass { // public static void test() { // System.debug('hello'); // } // }
Debug
Known issues
breakingPlugin requires Prettier v3 or higher. Prettier v2 is not supported.
fix
Update Prettier to ^3.0.0.
affects: >=2.0.0
deprecatedOption 'apexUseStandardClassSemicolons' is deprecated in v2.0.0.
fix
Use 'apexInsertFinalNewline' instead.
affects: >=2.0.0
gotchaPlugin does not format Apex test methods differently in class bodies.
fix
No official support; contributions welcome.
affects: all
gotchaPlugin is sensitive to Prettier's 'semicolons' option; setting 'semicolons: false' may produce invalid Apex.
fix
Keep 'semicolons: true' for Apex code.
affects: all
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-apex'
Plugin not installed or missing dependencies.
fix
Run 'npm install prettier-plugin-apex --save-dev' and ensure Prettier v3 is installed.
Error: Cannot find module 'prettier-plugin-apex' from ...
Plugin is not resolved correctly in Prettier configuration.
fix
Specify full path to plugin in plugins array: `plugins: ['./node_modules/prettier-plugin-apex/dist/index.mjs']`
Error: Unknown parser: 'apex'
Plugin not properly loaded or Prettier version incompatible.
fix
Ensure Prettier v3 is used and plugin is in plugins array.
TypeError: prettier.format is not a function
Using require() instead of import with ESM-only Prettier v3.
fix
Use dynamic import: `const prettier = await import('prettier');`
Upgrade
Version history
2.2.6latest on npm
Audit
Dependencies
prettierrequiredpeer dependency; required runtime for the plugin to work
Agent activity
3 hits · last 30 days
node
3
Resources
prettier-plugin-apex — npm install prettier-plugin-apex · libregistry