Nette Documentation Preview

syntax
Nette Code Checker
******************

.[perex]
[Code Checker |https://github.com/nette/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, JSON and YAML files, and can fix them automatically.


Installation
============

Install it globally via Composer:

```shell
composer global require nette/code-checker
```

Make sure your global Composer `bin` directory is in [your `$PATH` |https://getcomposer.org/doc/03-cli.md#global]. The `code-checker` command is then available from anywhere, on any operating system.

Alternatively, install it as a standalone project:

```shell
composer create-project nette/code-checker
```

It requires PHP 8.0 or higher.


Usage
=====

By default, Code Checker runs in read-only mode and only reports the problems it finds:

```shell
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`:

```shell
code-checker --fix
```

You can limit the scan to a specific path, skip files, or run faster syntax-only checks:

```shell
code-checker -d src --ignore "temp/*"
code-checker --only-syntax
```

In read-only mode the tool exits with code `0` when everything is fine and `1` when any problem is found, so it fits nicely into CI pipelines.

Full list of options:

```
Usage: code-checker [options]

Options:
	-d <path>             Folder or file to scan (default: current directory)
	-i | --ignore <mask>  Files to ignore
	-f | --fix            Fix the files
	-l | --eol            Normalize line endings to the system default
	--only-syntax         Check syntax only (faster)
	--no-progress         Do not show progress dots
	--version             Show version
```


What Code Checker Does
======================

- checks the syntax of [Latte |latte:] templates and `.php`, `.neon` and `.json` files
- removes the [BOM |nette:glossary#BOM]
- verifies that files are valid UTF-8
- checks for [control characters |nette:glossary#Control Characters]
- detects malformed phpDoc comments (e.g. `/* @var` instead of `/** @var`)
- enforces tabs for indentation in PHP, CSS, JS and TS files, and spaces in YAML
- removes trailing whitespace and blank lines at the end of files
- normalizes line endings to the system default (with the `-l` parameter)

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, JSON and YAML 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.0 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 a specific path, skip files, or run faster syntax-only checks:

code-checker -d src --ignore "temp/*"
code-checker --only-syntax

In read-only mode the tool exits with code 0 when everything is fine and 1 when any problem is found, so it fits nicely into CI pipelines.

Full list of options:

Usage: code-checker [options]

Options:
	-d <path>             Folder or file to scan (default: current directory)
	-i | --ignore <mask>  Files to ignore
	-f | --fix            Fix the files
	-l | --eol            Normalize line endings to the system default
	--only-syntax         Check syntax only (faster)
	--no-progress         Do not show progress dots
	--version             Show version

What Code Checker Does

  • checks the syntax of Latte templates and .php, .neon and .json files
  • removes the BOM
  • verifies that files are valid UTF-8
  • checks for control characters
  • detects malformed phpDoc comments (e.g. /* @var instead of /** @var)
  • enforces tabs for indentation in PHP, CSS, JS and TS files, and spaces in YAML
  • removes trailing whitespace and blank lines at the end of files
  • normalizes line endings to the system default (with the -l parameter)