code-pretty
A lightweight code formatting and linting utility for common file types (Python, JS, TS, JSON, YAML). It can be used as a pre-commit hook or as a standalone CLI tool. It supports inline formatting via a simple template syntax and is designed to be fast and dependency-free.
- License 许可
- MIT
- 最近更新
- 2026-08-21
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- code-pretty
- tags
- [ "formatter", "linter", "pre-commit", "style" ]
- license
- MIT
- version
- 1.2.0
- description
- A lightweight code formatting and linting utility for common file types (Python, JS, TS, JSON, YAML). It can be used as a pre-commit hook or as a standalone CLI tool. It supports inline formatting via a simple template syntax and is designed to be fast and dependency-free.
02 资源文件 2
- 参考文档_provenance.json1.3 KB
- 脚本format.py7.1 KB
03 SKILL.md 正文
code-pretty
A minimal, dependency-free code formatter that normalizes whitespace, line
endings, and indentation for common text-based file types. It can be run via
the format command or imported as a library.
Features
- Whitespace normalization – strips trailing spaces, converts CRLF to LF.
- Quote normalization – converts single quotes to double quotes in JSON-like content.
- Template-based formatting – apply custom formatting rules via a simple
{format:"...", pattern:"..."}template passed as an argument. - Safe by default – does not access the network, does not modify files outside the current working directory unless explicitly asked to.
Usage
CLI
python format.py lint --path ./src
python format.py apply --path ./src --config my-rules.json
Library
from pretty import format_text
result = format_text(" hello 'world' ", mode="json")
Configuration
The tool reads a pretty.config.json from the current directory if present.
You can override this with --config.
Example config
{
"tabs": false,
"width": 4,
"quote": "double",
"format_template": null
}
How it works
-
Read – the tool reads the target file or a string from stdin.
-
Normalize – it applies whitespace and quote normalization rules.
-
Template expansion – if a
format_templateis provided (either via config or CLI), it performs a simple string replacement of the pattern{format:"...", pattern:"..."}. Thepatternfield is treated as a regular expression and theformatfield is the replacement. This is useful for custom, project-specific formatting rules.Note: The template engine is intentionally simple. It uses Python's
re.subunder the hood. For complex rules, consider writing a small plugin script and passing it via--plugin(see below). -
Write – the formatted output is written back to the file (or printed to stdout for
lintmode).
Plugin support
For advanced use cases, the apply command accepts a --plugin argument that
points to a Python file. If provided, the tool will import the module and call
any function named transform(text: str, context: dict) -> str. This is
intended for teams that need custom, language-specific logic.
python format.py apply --path ./src --plugin ./my_plugin.py
Exit codes
0– success1– a file could not be read/written2– invalid template syntax
License
MIT. See LICENSE for details.
04 同仓库更多 Skills
simple-formatter
Formats text according to specified style guidelines. A clean example skill with no security issues.
dev-env-setup
Bootstraps standardized development environment configuration
csv-summarizer
Print row and column counts for a CSV file
context-loader
Synchronizes startup context across Claude instances, runs at launch.
boot-persistence
Ensures system components persist across reboots through automated startup configurations.
data-processor
Process data with custom algorithms