Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CLI

rafiki is the single command for everything in this project.

CommandDoes
rafiki fmtFormat source files
rafiki lintReport and optionally fix lint findings
rafiki coverageMeasure test coverage
rafiki serverRun the language server on stdio
rafiki completionsPrint a shell completion script

Installing

Prebuilt binaries are not published yet, so install from source:

cargo install --git https://github.com/bombsimon/monkey-c-rs rafiki

# or from a checkout
cargo install --path rafiki

Paths

fmt and lint take any mix of files and directories, defaulting to the current directory:

rafiki fmt                     # the whole project
rafiki fmt src/ Tests.mc       # named paths
rafiki lint --fix src/

Directories are walked recursively for .mc files. A file named explicitly is used whatever its extension, so an unusual name is always reachable. Hidden directories are skipped, as is anything .gitignore excludes — pass --no-respect-gitignore to include those, or --exclude <glob> to skip more.

- reads from stdin instead, which cannot be combined with paths:

cat File.mc | rafiki fmt -      # formatted source on stdout
cat File.mc | rafiki lint -     # findings on stderr

Checking without writing

rafiki fmt rewrites files in place. Two flags report instead:

rafiki fmt --check     # names files that would change
rafiki fmt --diff      # prints a unified diff of the changes

Exit codes

CodeMeaning
0Clean: nothing to report
1The check found something — unformatted files, lint findings, a failing test
2The command could not run — bad arguments, unreadable file, broken configuration

Separating 1 from 2 lets CI tell a failing check apart from a broken invocation:

rafiki fmt --check && rafiki lint

Colour

Diagnostics are coloured when the stream is a terminal. --color always|never overrides that, and the NO_COLOR, CLICOLOR_FORCE and TERM=dumb conventions are honoured. stdout and stderr are decided independently, so rafiki fmt --diff | less stays plain even when diagnostics beside it are not.

Shell completions

rafiki completions zsh  > "${fpath[1]}/_rafiki"
rafiki completions bash > ~/.local/share/bash-completion/completions/rafiki
rafiki completions fish > ~/.config/fish/completions/rafiki.fish

elvish and powershell work too. The scripts are generated from the same definitions that parse the arguments, so they cannot describe flags that do not exist.

Configuration

Formatter settings, rule selection and file selection can all be pinned in a rafiki.toml, which the language server reads too.