Skip to content

nvs check

nvs check <file> finds the errors in a program and runs nothing.

It checks the file and every file that the program loads through require and autoload. When there is no error, it prints no errors and the exit status is 0. When there are errors, it prints every one of them and the exit status is 1. Nothing runs, so the command is safe to use from an editor, a commit hook or a build server.

You can also check one class file that a program loads through autoload. The command finds that program in the project folder and uses its autoload lines, so the result is the same as for the whole program. nvs check <folder> checks every file in the folder once, even when many programs load it.

Each error has a code, a message, and the file, line and column. A code is E and four digits for an error, and W for a warning. A code never changes, so you can search for it.

--autoload-map prints the autoload rules as the compiler resolved them, in place of no errors. Use it to check an autoload declaration without a run.

Examples

Check before you commit

<?nvs
// Shows a file that `nvs check` accepts. `nvs check 01-check-before-you-commit.nvs` prints `no errors`.
// The command runs nothing, so a team can run it before every commit.
// If a line passed a string to `addItem`, the check would print error `E0401` and exit with status 1.
class Cart
{
public int $total = 0;
public function addItem(int $price): void
{
$this->total = $this->total + $price;
}
}
Cart $cart = new Cart();
$cart->addItem(1200);
$cart->addItem(350);
// This prints `1550` when you run the file.
echo $cart->total, "\n";
Output
1550