pawnfmt

package module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 2 Imported by: 0

README

pawnfmt

A fast, deterministic formatter for Pawn (SA-MP / open.mp) source: .pwn and .inc files.

With no paths, pawnfmt discovers the nearest Pawn project and formats it. Explicit files and stdin remain project-independent.

Install

Download a prebuilt binary from GitHub Releases. Release archives are built for Linux, macOS, and Windows on amd64 and arm64.

If you already have Go installed, you can also install from source:

go install github.com/pawnkit/pawnfmt/cmd/pawnfmt@latest

Use a version tag instead of latest when you want reproducible CI builds:

go install github.com/pawnkit/pawnfmt/cmd/pawnfmt@<tag>

Usage

Format files in place:

pawnfmt --write gamemodes includes

Check formatting without changing files:

pawnfmt --check gamemodes includes

Print a diff:

pawnfmt --diff script.pwn

Editor and CI integration

Call pawnfmt directly from your editor or CI:

pawnfmt --check gamemodes includes

For Git hooks, choose the hook manager that fits your project:

Lefthook:

pre-commit:
  jobs:
    - run: pawnfmt --write {staged_files}
      glob: "*.{pwn,inc}"
      stage_fixed: true

prek:

repos:
  - repo: local
    hooks:
      - id: pawnfmt
        name: pawnfmt
        entry: pawnfmt --write
        language: system
        files: \.(pwn|inc)$

pre-commit:

- repo: https://github.com/pawnkit/pawnfmt
  rev: <tag>
  hooks:
    - id: pawnfmt

A plain Git hook also works if you do not want a hook manager:

#!/bin/sh
pawnfmt --check gamemodes includes

Save it as .git/hooks/pre-commit and make it executable.

Configuration

Create a commented config with every default:

pawnfmt --init-config

See the configuration reference for discovery, inheritance, EditorConfig, and available options. Development and less common CLI behavior are covered in project notes.

Go package

Tools can format source without running the CLI:

formatted, err := pawnfmt.Format(source, pawnfmt.Options{TabSize: 4})

The zero options use pawnfmt's defaults. Set UseTabs to use tab indentation.

Contributing

Formatting reports with a short input and expected output are especially useful. See CONTRIBUTING.md.

Documentation

Overview

Package pawnfmt exposes Pawn source formatting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(source []byte, opts Options) ([]byte, error)

Format formats a complete Pawn source file.

Types

type Options

type Options struct {
	TabSize int
	UseTabs bool
}

Options controls library formatting.

Directories

Path Synopsis
cmd
corpus-report command
Command corpus-report runs the formatter against the real-world corpus and reports results.
Command corpus-report runs the formatter against the real-world corpus and reports results.
pawnfmt command
Command pawnfmt is a Pawn (SA-MP/open.mp) source code formatter.
Command pawnfmt is a Pawn (SA-MP/open.mp) source code formatter.
internal
bench
Package bench generates synthetic Pawn sources for benchmarking.
Package bench generates synthetic Pawn sources for benchmarking.
check
Package check runs formatter correctness checks used by the corpus report.
Package check runs formatter correctness checks used by the corpus report.
config
Package config defines pawnfmt's configuration schema, defaults, and loading.
Package config defines pawnfmt's configuration schema, defaults, and loading.
doc
Package doc implements a Wadler/Prettier-style pretty-printing IR.
Package doc implements a Wadler/Prettier-style pretty-printing IR.
format
Package format renders a parsed Pawn source file to formatted output.
Package format renders a parsed Pawn source file to formatted output.
printer
Package printer renders a doc.
Package printer renders a doc.
trivia
Package trivia scans source lines for blank/comment/directive/disabled-region info.
Package trivia scans source lines for blank/comment/directive/disabled-region info.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL