{"id":20336,"library":"prettier-plugin-apex","title":"Prettier Apex","description":"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.","status":"active","version":"2.2.6","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","apex","prettier","typescript"],"install":[{"cmd":"npm install prettier-plugin-apex","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-apex","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-apex","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; required runtime for the plugin to work","package":"prettier","optional":false}],"imports":[{"note":"Prettier is ESM-only since v3; use dynamic import or ES module syntax.","wrong":"const prettier = require('prettier');","symbol":"default","correct":"import prettier from 'prettier';"},{"note":"Plugin is ESM-only; use ES import syntax.","wrong":"const prettierPluginApex = require('prettier-plugin-apex');","symbol":"plugin","correct":"import * as prettierPluginApex from 'prettier-plugin-apex';"},{"note":"Plugin does not export its own types; use Prettier's Options type.","wrong":"import { Options } from 'prettier-plugin-apex';","symbol":"Options","correct":"import type { Options } from 'prettier';"}],"quickstart":{"code":"import prettier from 'prettier';\nimport * as prettierPluginApex from 'prettier-plugin-apex';\n\nconst code = `public class MyClass { public static void test() { System.debug('hello'); } }`;\n\nprettier.format(code, {\n  parser: 'apex',\n  plugins: [prettierPluginApex],\n  apexInsertFinalNewline: true,\n}).then(result => console.log(result));\n// Output:\n// public class MyClass {\n//   public static void test() {\n//     System.debug('hello');\n//   }\n// }\n","lang":"typescript","description":"Formats a simple Apex class using Prettier with the Apex plugin."},"warnings":[{"fix":"Update Prettier to ^3.0.0.","message":"Plugin requires Prettier v3 or higher. Prettier v2 is not supported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use 'apexInsertFinalNewline' instead.","message":"Option 'apexUseStandardClassSemicolons' is deprecated in v2.0.0.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"No official support; contributions welcome.","message":"Plugin does not format Apex test methods differently in class bodies.","severity":"gotcha","affected_versions":"all"},{"fix":"Keep 'semicolons: true' for Apex code.","message":"Plugin is sensitive to Prettier's 'semicolons' option; setting 'semicolons: false' may produce invalid Apex.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install prettier-plugin-apex --save-dev' and ensure Prettier v3 is installed.","cause":"Plugin not installed or missing dependencies.","error":"Cannot find module 'prettier-plugin-apex'"},{"fix":"Specify full path to plugin in plugins array: `plugins: ['./node_modules/prettier-plugin-apex/dist/index.mjs']`","cause":"Plugin is not resolved correctly in Prettier configuration.","error":"Error: Cannot find module 'prettier-plugin-apex' from ..."},{"fix":"Ensure Prettier v3 is used and plugin is in plugins array.","cause":"Plugin not properly loaded or Prettier version incompatible.","error":"Error: Unknown parser: 'apex'"},{"fix":"Use dynamic import: `const prettier = await import('prettier');`","cause":"Using require() instead of import with ESM-only Prettier v3.","error":"TypeError: prettier.format is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}