{"id":20383,"library":"prettier-plugin-kotlin","title":"Prettier Kotlin Plugin","description":"Prettier plugin for Kotlin language formatting. v2.1.0 (latest) ditched the original JS-based printer in favor of kastree's Kotlin Writer, a significant breaking change from v1.x. The parser (kotato) is alpha-stage, based on kastree, and can parse most Kotlin code but has performance issues. Release cadence is irregular with long gaps. Key differentiator: integrates Kotlin formatting into Prettier's ecosystem, allowing uniform code style across JS/TS/CSS/Kotlin projects. Lacks stable and full Kotlin grammar support; not recommended for production.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/Angry-Potato/prettier-plugin-kotlin","tags":["javascript","kotlin","prettier","plugin","ast","parse","format"],"install":[{"cmd":"npm install prettier-plugin-kotlin","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-kotlin","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-kotlin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin relies on Prettier to load and invoke it","package":"prettier","optional":false}],"imports":[{"note":"Prettier automatically discovers plugins named 'prettier-plugin-*' in node_modules. No explicit import needed unless you pass plugins array manually (ESM compatible).","wrong":"import prettierPluginKotlin from 'prettier-plugin-kotlin'","symbol":"default plugin registration","correct":"prettier.config.js -> module.exports = { plugins: ['prettier-plugin-kotlin'] }"},{"note":"Do not call the plugin directly. Pass it as a plugin to prettier.format(). The plugin does not expose its own format function.","wrong":"const prettierPluginKotlin = require('prettier-plugin-kotlin'); prettierPluginKotlin.format(code)","symbol":"require (CommonJS)","correct":"const prettier = require('prettier'); const code = prettier.format('fun main() {}', { parser: 'kotlin', plugins: [require('prettier-plugin-kotlin')] })"},{"note":"Prettier v3+ is ESM-only. Use dynamic import or top-level await. The plugin string is auto-resolved.","wrong":"import * as prettier from 'prettier'","symbol":"ESM (type: module)","correct":"import prettier from 'prettier'; const code = await prettier.format('fun main() {}', { parser: 'kotlin', plugins: ['prettier-plugin-kotlin'] })"}],"quickstart":{"code":"// Ensure prettier and prettier-plugin-kotlin are installed\n// npm install prettier prettier-plugin-kotlin\n\nimport prettier from 'prettier';\n\nconst code = `fun main(args: Array<String>) { println(\"Hello, World!\") }`;\n\nconst formatted = await prettier.format(code, {\n  parser: 'kotlin',\n  plugins: ['prettier-plugin-kotlin'],\n  tabWidth: 2,\n  semi: false\n});\n\nconsole.log(formatted);\n// Expected output:\n// fun main(args: Array<String>) {\n//   println(\"Hello, World!\")\n// }","lang":"typescript","description":"Demonstrates formatting a simple Kotlin function with Prettier using the Kotlin plugin in ESM mode."},"warnings":[{"fix":"Reformat all Kotlin files with the new plugin version. Review diff of formatted files for regressions.","message":"v2.0.0 replaced the JavaScript-based printer with a Kotlin-based one (kastree Writer). Output may differ significantly from v1.x.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"For production, use kotlinc or ktlint. Only use this plugin for experimental or simple projects.","message":"Parser (kotato) is alpha; may fail on complex Kotlin syntax (e.g., inline classes, contracts, multi-file inference).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Restart VSCode after installing plugin. Set 'prettier.requireConfig': false if needed. See https://github.com/prettier/prettier-vscode/issues/395","message":"VSCode Prettier extension may not auto-detect the plugin for Kotlin files; formatOnSave may not work despite manual formatting succeeding.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update to version 2.1.0: npm install prettier-plugin-kotlin@latest","message":"v1.x plugin used a different printer; upgrade to v2.x for current support.","severity":"deprecated","affected_versions":"<2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install --dev prettier prettier-plugin-kotlin' in your project root.","cause":"Plugin not installed or not in node_modules.","error":"Cannot find module 'prettier-plugin-kotlin'"},{"fix":"Simplify the code or fix syntax errors. For advanced features, use ktlint instead.","cause":"The kotato parser does not support all Kotlin syntax or the file contains errors.","error":"Error: Cannot parse file. Unsupported syntax: ..."},{"fix":"Update both prettier and prettier-plugin-kotlin to latest: npm install prettier@latest prettier-plugin-kotlin@latest","cause":"Plugin is outdated or Prettier version mismatch.","error":"Cannot read properties of undefined (reading 'type')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}