Skip to content

Plugins

The core indentier package handles JavaScript and TypeScript natively. All other languages are supported through plugin packages.

PluginLanguagesExtensionsRuby modeDeclaration
(core)JavaScript / TypeScript.js .cjs .mjs .jsx .ts .cts .mts .tsxlet end=null;
@indentier/plugin-rustRust.rsconst end:()=();
@indentier/plugin-goGo.govar end any=nil
@indentier/plugin-cC / C++.c .h .cpp .hppvoid*end=0;
@indentier/plugin-phpPHP.php$end=null;
@indentier/plugin-javaJava.java
@indentier/plugin-csC#.cs
@indentier/plugin-cssCSS / SCSS / Less.css .scss .less
Terminal window
# install the plugin alongside indentier
npm i -D @indentier/plugin-rust @indentier/plugin-go
# then declare it in your config
.indentierrc.json
{
"plugins": ["@indentier/plugin-rust", "@indentier/plugin-go"]
}

The CLI loads plugins automatically from the config. When using the API, call loadPlugins() manually:

import { format, loadPlugins, getPlugin } from 'indentier'
await loadPlugins(['@indentier/plugin-rust'])
const plugin = getPlugin('.rs')
const output = format(source, options, '.rs', plugin)

A plugin is a plain object that implements the IndentierPlugin interface:

import type { IndentierPlugin } from 'indentier'
const plugin: IndentierPlugin = {
// File extensions this plugin handles (lowercase, with leading dot)
extensions: ['.rs'],
// Whether ruby mode is meaningful for this language
rubyCompatible: true,
// Declaration injected at the top of the file in ruby mode
declarationTemplate: 'const end:()=();',
// (optional) Custom end-statement body. Defaults to variableName.
getEndStatement: (variableName) => variableName,
// (optional) Where to splice the declaration line.
// Receives the parsed lines array; return the insertion index.
// Default: 0 (very top of file). Example below: insert after the first `<?` line.
declarationInsertIndex: (lines) => {
for (let i = 0; i < lines.length; i++) {
if (lines[i].body.trimStart().startsWith('<?')) return i + 1
}
return 0
},
}
export default plugin

Publish as @indentier/plugin-<name> or any package name and add it to plugins in your config.