Part V — The Modern Experience Layer · Chapter 30 · Lesson 2 of 2
Formatter, linter, codemods and scaffolding
Style drift is a tax on every review. PeaLang gives you AST-based formatting, linting and codemods that you can run from the CLI or call from a program.
The formatter
pea fmt . # format in place
pea fmt --check . # CI gate, non-zero exit on diff
PeaFormatter and format_source_ast format from the syntax tree when parsing succeeds, with a token-based fallback otherwise. stats.FormatConfig.load(root) reads .peafmt.toml or the "formatter" section of pea.json; the knobs are indent_size, max_line_length, trailing_comma, brace_style, space_around_operators and newline_at_eof.
The linter and codemods
let issues = analysis.lint_source_ast(source)
let cleaned = analysis.codemod_remove_unused_imports(source)
let renamed = analysis.codemod_rename_variable(source, "old", "new")
let styled = analysis.codemod_fix_naming(source)
The AST linter flags long functions, high cyclomatic complexity, naming issues, unreachable code after return/throw, long lines, trailing whitespace and TODO/FIXME markers. Codemods apply the mechanical fixes in bulk. These names are available from analysis and stats; no import statement is needed.
Project scaffolding
pea init myproj --template webapp
pea templates # analysis, api, automation, cli, data,
# default, etl, interop, library, polyglot, webapp
Eleven templates: the list above. They create a manifest and starter source; library, webapp and api also create tests, and library adds a README and LICENSE. Pick the closest template and delete what you don't need.
Metrics and dependency checks
let metrics = analysis.code_metrics(source) # lines, functions, variables
let report = analysis.dependency_check("pea.json") # missing dependency paths
let fixes = analysis.suggest_fix(message, source) # textual fix hints
code_metrics reports counts and comment ratio; dependency_check validates dependency specs and paths in pea.json; suggest_fix returns fix suggestions for an error message. For a combined report, use analysis.diagnose_source(source).
Where the tools live
- Core modules:
pealang/formatter.py,pealang/lsp.py,pealang/devx.pyandpealang/project.py; VS Code integration undereditors/vscode/. - Full treatment: Chapter 25 — Language Internals and Contribution.
Guided practice
- Run
pea fmt --check .on an old project; read the diff before accepting it. - Scaffold a new project with
pea init --template analysis; delete one thing you understand and re-run the tests. - Run the linter, apply one codemod, and verify tests still pass — that is the whole loop.