prettier-plugin-aiken
v0.2.1
Published
A Prettier plugin for Aiken language
Downloads
3
Readme
Prettier Plugin Aiken
A Prettier plugin for the Aiken smart contract language.
Overview
This plugin integrates Aiken's built-in formatter (aiken fmt) with Prettier, allowing you to format Aiken smart contract code using Prettier's workflow and editor integrations.
Features
- 🎯 Format
.akfiles using Aiken's official formatter - 🔧 Seamless integration with Prettier
- ⚡ Works with popular editors (VS Code, Vim, etc.)
- 🔄 Supports Prettier's CLI and API
Installation
Prerequisites
Make sure you have Aiken installed on your system:
# Install Aiken (if not already installed)
curl -sSfL https://install.aiken-lang.org | bashInstall the Plugin
# Using npm
npm install --save-dev prettier prettier-plugin-aiken
# Using pnpm
pnpm add -D prettier prettier-plugin-aiken
# Using yarn
yarn add --dev prettier prettier-plugin-aikenUsage
CLI
Format a single file:
npx prettier --write validator.akFormat all Aiken files in your project:
npx prettier --write "**/*.ak"Configuration
Add to your package.json:
{
"prettier": {
"plugins": ["prettier-plugin-aiken"]
}
}Or create a .prettierrc.js:
module.exports = {
plugins: ["prettier-plugin-aiken"]
};VS Code Integration
- Install the Prettier extension
- Add this plugin to your project dependencies
- Configure Prettier as your default formatter for
.akfiles
Add to your VS Code settings.json:
{
"[aiken]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
}How it Works
This plugin acts as a bridge between Prettier and Aiken's built-in formatter:
- Prettier detects
.akfiles using this plugin - The plugin passes the file content to
aiken fmt --stdin - Returns the formatted code back to Prettier
Requirements
- Node.js >= 14
- Aiken CLI tool installed and available in PATH
- Prettier (peer dependency)
Example
Before formatting:
validator my_validator{
pub fn spend(datum: Data,redeemer: Data,context: ScriptContext) -> Bool {
let Spend(output_reference) = context.purpose
True
}
}After formatting:
validator my_validator {
pub fn spend(datum: Data, redeemer: Data, context: ScriptContext) -> Bool {
let Spend(output_reference) = context.purpose
True
}
}Configuration
Setting up Aiken Binary Path
The plugin will automatically try to find your Aiken binary in the following order:
- Environment Variable:
AIKEN_BIN(recommended for custom installations) - PATH: Using
which aikencommand - Default Location:
~/.aiken/bin/aiken(standard installation path)
Using Environment Variable
If you have Aiken installed in a custom location, set the AIKEN_BIN environment variable:
# In your shell profile (.bashrc, .zshrc, etc.)
export AIKEN_BIN="/path/to/your/aiken/binary"
# Or set it per project in .env file
AIKEN_BIN="/usr/local/bin/aiken"For VS Code Users
Add the environment variable to your VS Code settings:
{
"terminal.integrated.env.osx": {
"AIKEN_BIN": "/path/to/your/aiken/binary"
},
"terminal.integrated.env.linux": {
"AIKEN_BIN": "/path/to/your/aiken/binary"
},
"terminal.integrated.env.windows": {
"AIKEN_BIN": "C:\\path\\to\\your\\aiken\\binary.exe"
}
}Troubleshooting
"aiken command not found"
Make sure Aiken is installed and available in your PATH:
aiken --versionIf not installed, follow the Aiken installation instructions.
Custom Aiken Installation
If you installed Aiken in a custom location, make sure to set the AIKEN_BIN environment variable as described in the Configuration section above.
Plugin not working in VS Code
- Ensure the plugin is installed in your project (not globally)
- Restart VS Code after installing the plugin
- Check that Prettier is configured as the default formatter for
.akfiles
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development
- Clone the repository
- Install dependencies:
npm install - Make your changes
- Test with a sample Aiken project
License
Related Projects
Changelog
See CHANGELOG.md for release history.
