home / skills / aidotnet / moyucode / code-formatter

code-formatter skill

/skills/tools/code-formatter

This skill formats code across languages using industry-standard tools, ensuring consistent style and faster collaboration.

npx playbooks add skill aidotnet/moyucode --skill code-formatter

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
1012 B
---
name: code-formatter
description: 格式化源代码文件,支持Python、JavaScript、JSON等语言,使用行业标准格式化工具。
metadata:
  short-description: 格式化源代码
source:
  repository: https://github.com/psf/black
  license: MIT
---

# Code Formatter Tool

## Description
Format source code files using industry-standard formatters like Black for Python, with support for multiple languages.

## Trigger
- `/format` command
- User needs to format code
- User wants consistent code style

## Usage

```bash
# Format Python file
python scripts/code_formatter.py file.py

# Format with specific line length
python scripts/code_formatter.py file.py --line-length 100

# Format JSON
python scripts/code_formatter.py config.json

# Check without modifying
python scripts/code_formatter.py file.py --check

# Format directory
python scripts/code_formatter.py ./src/ --recursive
```

## Tags
`format`, `code`, `python`, `black`, `style`

## Compatibility
- Codex: ✅
- Claude Code: ✅

Overview

This skill formats source code files using industry-standard formatters to enforce consistent style across projects. It supports multiple languages including Python, JavaScript, and JSON and exposes command-style triggers for file, directory, and check-only operations. The goal is predictable, tool-backed formatting to reduce style debates and pre-commit failures.

How this skill works

The skill runs appropriate formatters (for example Black for Python) against specified files or directories, with options for line length and recursive traversal. It can operate in-place or in a check-only mode that reports formatting differences without modifying files. The implementation maps file types to their recommended formatter and applies configurable flags passed by the user.

When to use it

  • Before committing code to keep diffs small and consistent
  • As part of a CI pipeline to enforce style automatically
  • When onboarding new contributors to align code style
  • Before code review to focus reviewers on logic rather than formatting
  • When normalizing mixed or legacy codebases for refactoring

Best practices

  • Run the formatter from a pre-commit hook or CI job to catch issues early
  • Use the check-only mode in automated tests to prevent unformatted code from merging
  • Keep formatter configuration (line length, excludes) in the repo so everyone shares the same settings
  • Limit manual style changes in reviews; prefer reformatting with the tool to avoid churn
  • Run formatting on the whole project periodically when adopting or updating rules

Example use cases

  • Format a single Python file: code-formatter file.py (or using /format in chat)
  • Check formatting in CI: run the tool with --check to fail builds on style issues
  • Format an entire source directory recursively to standardize style across many files
  • Format JSON config files to ensure consistent spacing and ordering before commits
  • Customize line length for a file or project with a --line-length flag

FAQ

Which languages are supported?

Common languages like Python, JavaScript, and JSON are supported; the skill selects the appropriate formatter per file type.

Can I run the tool without changing files?

Yes. A check-only mode reports differences without modifying files, useful for CI and pre-review checks.