Registry / devops / prettier-plugin-kotlin

prettier-plugin-kotlin

JSON →
library2.1.0jsnpmunverified

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.

npm install prettier-plugin-kotlin
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-KO
P
prettier-plugin-kotlin
devopsjavascriptv2.1.0
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 plugin registration
prettier.config.js -> module.exports = { plugins: ['prettier-plugin-kotlin'] }
import prettierPluginKotlin from 'prettier-plugin-kotlin'
Prettier automatically discovers plugins named 'prettier-plugin-*' in node_modules. No explicit import needed unless you pass plugins array manually (ESM compatible).
require (CommonJS)
const prettier = require('prettier'); const code = prettier.format('fun main() {}', { parser: 'kotlin', plugins: [require('prettier-plugin-kotlin')] })
const prettierPluginKotlin = require('prettier-plugin-kotlin'); prettierPluginKotlin.format(code)
Do not call the plugin directly. Pass it as a plugin to prettier.format(). The plugin does not expose its own format function.
ESM (type: module)
import prettier from 'prettier'; const code = await prettier.format('fun main() {}', { parser: 'kotlin', plugins: ['prettier-plugin-kotlin'] })
import * as prettier from 'prettier'
Prettier v3+ is ESM-only. Use dynamic import or top-level await. The plugin string is auto-resolved.

Demonstrates formatting a simple Kotlin function with Prettier using the Kotlin plugin in ESM mode.

// Ensure prettier and prettier-plugin-kotlin are installed // npm install prettier prettier-plugin-kotlin import prettier from 'prettier'; const code = `fun main(args: Array<String>) { println("Hello, World!") }`; const formatted = await prettier.format(code, { parser: 'kotlin', plugins: ['prettier-plugin-kotlin'], tabWidth: 2, semi: false }); console.log(formatted); // Expected output: // fun main(args: Array<String>) { // println("Hello, World!") // }
Debug
Known issues
breakingv2.0.0 replaced the JavaScript-based printer with a Kotlin-based one (kastree Writer). Output may differ significantly from v1.x.
fix
Reformat all Kotlin files with the new plugin version. Review diff of formatted files for regressions.
affects: >=2.0.0
gotchaParser (kotato) is alpha; may fail on complex Kotlin syntax (e.g., inline classes, contracts, multi-file inference).
fix
For production, use kotlinc or ktlint. Only use this plugin for experimental or simple projects.
affects: >=1.0.0
gotchaVSCode Prettier extension may not auto-detect the plugin for Kotlin files; formatOnSave may not work despite manual formatting succeeding.
fix
Restart VSCode after installing plugin. Set 'prettier.requireConfig': false if needed. See https://github.com/prettier/prettier-vscode/issues/395
affects: >=1.0.0
deprecatedv1.x plugin used a different printer; upgrade to v2.x for current support.
fix
Update to version 2.1.0: npm install prettier-plugin-kotlin@latest
affects: <2.0.0
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-kotlin'
Plugin not installed or not in node_modules.
fix
Run 'npm install --dev prettier prettier-plugin-kotlin' in your project root.
Error: Cannot parse file. Unsupported syntax: ...
The kotato parser does not support all Kotlin syntax or the file contains errors.
fix
Simplify the code or fix syntax errors. For advanced features, use ktlint instead.
Cannot read properties of undefined (reading 'type')
Plugin is outdated or Prettier version mismatch.
fix
Update both prettier and prettier-plugin-kotlin to latest: npm install prettier@latest prettier-plugin-kotlin@latest
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
prettierrequiredpeer dependency; plugin relies on Prettier to load and invoke it
Agent activity
8 hits · last 30 days
node
8
Resources
prettier-plugin-kotlin — npm install prettier-plugin-kotlin · libregistry