prettier-plugin-taskfile
v1.0.1
Published
A Prettier plugin for formatting Taskfile YAML files
Downloads
4
Maintainers
Readme
prettier-plugin-taskfile
A Prettier plugin for formatting Taskfiles according to the Taskfile Style Guide.
Features
This plugin implements all the formatting rules from the Taskfile Style Guide:
- Ordering of main sections:
versionincludesvarsenvtasks
- Consistent indentation: Uses two spaces for indentation
- Proper spacing: Adds empty lines between main sections and between tasks
- Variable naming: Converts variable names to uppercase
- Task naming: Converts task names to kebab-case (e.g.,
do-somethinginstead ofdo_something) - Template formatting: Removes whitespace in template variables (e.g.,
{{.VAR}}instead of{{ .VAR }}) - Namespace preservation: Preserves task namespace separators with colons (e.g.,
docker:build) - YAML formatting: Preserves YAML formatting while applying all style guide rules
- Integration: Works with Prettier's standard YAML formatting
Installation
npm install --save-dev prettier prettier-plugin-taskfile
# or
yarn add --dev prettier prettier-plugin-taskfileUsage
Command Line
# Format a single Taskfile
npx prettier --write Taskfile.yml --plugin=prettier-plugin-taskfile
# Format all Taskfiles in your project
npx prettier --write "**/*Taskfile*.{yml,yaml}" --plugin=prettier-plugin-taskfileConfiguration
Add the plugin to your Prettier configuration (.prettierrc, .prettierrc.json, etc.):
{
"plugins": ["prettier-plugin-taskfile"]
}Editor Integration
This plugin works with all editor integrations that use Prettier. Once installed, it will automatically be used when formatting Taskfiles.
Example
Before (unformatted):
tasks:
build:
cmds:
- echo "Building..."
test_suite:
cmds:
- echo "Testing..."
docker_stuff:
cmds:
- echo "Docker stuff"
env:
NODE_ENV: development
includes:
- ./common.yml
vars:
PROJECT: myproject
lowercase_var: should be uppercase
another_var: value
version: "3"After (formatted):
version: "3"
includes:
- ./common.yml
vars:
PROJECT: myproject
LOWERCASE_VAR: should be uppercase
ANOTHER_VAR: value
env:
NODE_ENV: development
tasks:
build:
cmds:
- echo "Building..."
test-suite:
cmds:
- echo "Testing..."
docker-stuff:
cmds:
- echo "Docker stuff"Notice the following changes:
- Top-level keys are sorted according to the style guide
- Empty lines are added between main sections and between tasks
- Variable names are converted to uppercase (
lowercase_var→LOWERCASE_VAR) - Task names are converted to kebab-case (
test_suite→test-suite) - Two-space indentation is used consistently
License
MIT
