Skip to main content

Installation

Requirements​

  • PHP 8.5+
  • Extensions: dom, libxml, simplexml

Install​

git clone https://github.com/php/docbook-cs.git
cd docbook-cs

Quick start​

# Copy the dist config and run from the cloned repo
cp docbookcs.xml.dist docbookcs.xml

# Check only your current changes (diff against the branch point)
bin/docbook-cs

# Scan the whole tree
bin/docbook-cs .

Without arguments, DocbookCS checks the Git diff from the upstream branch point through the working tree. Pass a path (such as .) to scan full files or directories instead.

Scope​

The inspection scope is derived from the input. By default, only the given diff or the full contents of the given paths are checked. With --wide, every selected file is checked as a whole and referenced SYSTEM XML files are recursively included.

Input--wideFull file(s)ReferencesMeaning
nonenononodiff against branch point
noneyesyesyeschanged files and all referenced XML
<path>noyesnofull file or directory
<path>yesyesyesfull file or directory plus referenced XML
piped diffnononopiped diff scope
piped diffyesyesyespiped diff files and referenced XML

Paths cannot be combined with piped diff input.

Options​

OptionDescription
--config=<file>Path to configuration file (default: docbookcs.xml)
--report=<format>Output format: console (default), checkstyle, json
--fixAutomatically fix violations when fixers exist (experimental)
--wideCheck whole selected files and recursively include referenced XML files
--perfCollect and report per-sniff timing
--colorsForce ANSI color output
--no-colorsDisable ANSI color output
-q, --quietSuppress progress output
-v, --versionShow version and exit
-h, --helpShow help and exit

The --diff flag from earlier versions was removed: diff mode is now the default, and piped diffs are detected automatically.

Exit codes​

CodeMeaning
0No violations found
1One or more violations found
2Runtime error (bad config, unreadable file, etc.)

With --fix, the exit code reflects the violations remaining after fixing: a run that fixes everything exits 0.