Nette Code Checker
Code Checker checks your source files for formal flaws such as an invisible BOM, control characters, broken encoding, or invalid syntax of PHP, Latte, NEON and JSON files, and can fix them automatically.
Installation
Install it globally via Composer:
composer global require nette/code-checker
Make sure your global Composer bin directory is in your
$PATH. The code-checker command is then available from anywhere, on any operating system.
Alternatively, install it as a standalone project:
composer create-project nette/code-checker
It requires PHP 8.2 or higher.
Usage
By default, Code Checker runs in read-only mode and only reports the problems it finds:
code-checker
To actually repair the files, add --fix. Back up your files first, or run it on a clean working tree so you can
review the changes afterwards with git diff:
code-checker --fix
You can limit the scan to specific paths (repeat -d for each of them), skip files, or run faster syntax-only
checks:
code-checker -d src -d tests --ignore "temp/*"
code-checker --only-syntax
In read-only mode the tool exits with code 0 when everything is fine and 1 when it finds any error or
fixable issue, so it fits nicely into CI pipelines.
Full list of options:
Usage: php code-checker [options]
Options:
-d <path>... Folder or file to scan (default: current directory)
-i, --ignore <mask>... Files to ignore
-f, --fix Fixes files
-l, --eol Convert newline characters
--only-syntax Check only syntax
--no-progress Do not show progress dots
--version Show version
-h, --help Print this help
What Code Checker Does
- checks the syntax of Latte templates and
.php,.neonand.jsonfiles - removes the BOM
- verifies that files are valid UTF-8
- checks for control characters
- converts indentation with spaces to tabs in CSS, LESS, JS, TS and JSON files and works out the indentation width on its own (a file with inconsistent indentation is only reported and left untouched)
- checks that YAML files are indented with spaces
- removes trailing whitespace and blank lines at the end of files
- normalizes line endings to the system default (with the
-lparameter)