This page is dedicated to some technical details.
- Console options for
check
command- How to disable some checks
- How to enable all checks
- How to enable only certain checks
- How to exclude some files and folders from checking
- How to exclude some files and folders from reports
- How to disable file checking without changing the launch command
- How to exclude the
vendor
folder - How to define a list of file extensions to be interpreted as PHP extensions
- How to set regexp for unused variables
- How to output all errors to a file
- How to output all errors to a
json
file - How to fix some errors in automatic mode
- How to make a check critical
- How to change the cache directory
- How to disable caching
- How to use PHP 7
- How to use strict-mixed mode
- Hard level options
- Other commands
A full launch command line is
noverify check --option1=xxx --option2=yyy ... [folder_or_file] [folder_or_file] ...
When no options are specified, their default values are used.
When no folders and files are specified, the current directory .
is assumed.
To see all the options, run the following command:
noverify check help
Below we will discuss the main options.
It looks like this:
noverify check --exclude-checks='undefined, arraySyntax' ./
Now there will be no undefined
and arraySyntax
errors in the output.
It looks like this:
noverify check --allow-all-checks ./
NoVerify has checks that are disabled by default, you can enable them with the --allow-all-checks
flag.
It looks like this:
noverify check --allow-checks='undefined, arraySyntax' ./
Now the output will only contain undefined
and arraySyntax
errors.
It looks like this:
noverify check --index-only-files='./tests' ./
The --index-only-files
option sets paths that won't be analyzed, they will be just indexed (from there the definitions of functions and classes for type inference will be taken).
It looks like this:
noverify check --exclude='./src/1.php' ./
The exclude
flag accepts a regular expression based on which to exclude files or folders.
Unlike --index-only-files
, excluded files will be analyzed and errors may be found for them, but they will not be shown.
Use this flag if you do not want to see errors for some files or directories and it is convenient to use a regular expression to express the name.
It looks like this:
<?php
/** @linter disable */
function f() {
...
}
...
It is necessary to add the comment /** @linter disable */
to the file.
However, to prevent developers from doing this permanently, there is the --allow-disable
flag, which determines the files in which this annotation can be used.
It looks like this:
noverify check --allow-disable="dev_*" ./src
The flag sets a regular expression to determine which files are allowed.
This is usually needed if you use NoVerify in a pipeline, where changing launch commands many times in a row is not effective, but you need to give the ability to disable the linter for certain files.
It looks like this:
noverify check --ignore-vendor ./src
By default, if NoVerify finds a vendor
folder, then it includes it in the index to correctly deduce types and not give errors for undefined classes and functions.
If you need to disable this behavior, then use the --ignore-vendor
flag.
It looks like this:
noverify check --php-extensions='php, phtml' ./src
By default, NoVerify analyzes the following extensions: php, inc, php5, phtml
.
It looks like this:
noverify check --unused-var-regex='^_*' ./src
By default, the regexp is ^_$
.
Sometimes variables are not used for some reason, for this they can be called $_
, in which case NoVerify will not give a warning. However, perhaps you want NoVerify to ignore the $_name
variables too, for example, then you need to specify the regular expression $_*
.
It looks like this:
noverify check --output='reports.txt' ./src
All errors will be written to the reports.txt
file.
It looks like this:
noverify check --output-json --output='reports.json' ./src
All errors will be written to the reports.json
file.
It looks like this:
noverify check --fix ./src
All errors that NoVerify can fix will be fixed.
If you want to fix only certain errors, then specify the --allow-checks
flag. See How to enable only certain checks
It looks like this:
noverify check --critical='redundantCast' ./src
Now the appearance of the redundantCast
error will cause NoVerify to exit with non-zero status.
By default, not all errors lead to a non-zero status, that is, if there are only redundantCast
errors in reports, then NoVerify will exit with a zero status, since the redundantCast
check is not critical.
If you need to make some check critical, then use the --critical flag
, which accepts a comma-separated list of checks.
It looks like this:
noverify check --cache-dir='./cache' ./src
By default, the directory is $TMPDIR/noverify
.
The cache is used to reduce the time it takes to collect information about function classes, etc. during the next launches.
It looks like this:
noverify check --disable-cache ./src
It looks like this:
noverify check --php7 ./src
By default, all code is parsed as 8.1, however, some projects use names that have become reserved in PHP 8, so they need to be parsed as PHP 7.
It looks like this:
noverify check --strict-mixed ./src
By default, if a method is called using a variable with the mixed
or object
type (or property fetched), then the linter does not give a warning about an undefined method or property.
// noverify check ./src
function f($a) {
$a->foo(); // ok
$a->boo; // ok
}
// noverify check --strict-mixed ./src
function f1($a) {
$a->foo(); // error: undefined method 'foo'
$a->boo; // error: undefined property 'boo'
}
Next are the options for which you need to read the articles attached to them to understand how to use them.
Dynamic rules are a way to add new checks to NoVerify without having to write Go code. Such rules are written in PHP.
Read more in the article Dynamic rules.
Baseline mode is necessary if you have a large codebase on which NoVerify finds a huge number of errors. Of course, it is impossible to fix them right away, so you need a way to ignore all found errors and analyze only errors found after.
Read more in the article Baseline mode.
Another way to use NoVerify for a large codebase, if NoVerify finds a large number of errors, is to run the linter only on new code. This mode uses git
.
The changes are taken from the comparison with the previous commit, excluding changes made to master
branch that is fetched to ORIGIN_MASTER
.
Read more in the article Diff mode.
Shows a list of checks performed by NoVerify.
Shows the version of NoVerify.