quick-lint-js

quick-lint-js finds bugs in JavaScript programs.

This page documents the quick-lint-js command-line interface (CLI).

Table of Contents

Name

quick-lint-js - find bugs in JavaScript programs

Synopsis

quick-lint-js [--output-format=format] [<options>] file [file…​]
quick-lint-js --lsp-server [<options>]

Description

quick-lint-js reads JavaScript files and reports syntax errors and other bugs.

This command has two modes:

quick-lint-js [<options>] file [file…​]

Batch mode (default). Check the given files, and report errors to the terminal (standard error). --output-format can be used to customize how errors look.

quick-lint-js --lsp-server

LSP server mode. Start a Language Server Protocol server, communicating using standard input and standard output. Use this mode to integrate with code editors supporting LSP.

Options

--output-format=format

Customize how errors are printed. format is one of the following:

  • gnu-like (default): a human-readable format similar to GCC.

  • vim-qflist-json: machine-readable JSON which can be given to Vim’s setqflist function.

Incompatible with --lsp-server.

--vim-file-bufnr=number

Set the bufnr property for errors printed with the --output-format=vim-qflist-json option.

--vim-file-bufnr applies only to the next input file given in the command line. Therefore, if multiple input files are given, --vim-file-bufnr can be specified multiple times.

--config-file=file

Read configuration options from file and apply them to input files which are given later in the command line. See the config docs for the format of configuration files.

If --config-file is given twice, then the file for the first --config-file option applies only to the input files between the two --config-file options, and the file for the second --config-file option apples only to the input files after the second --config-file option. See the Example section for an example.

If --config-file is not given, an empty configuration file is assumed.

Incompatible with --lsp-server.

--exit-fail-on=errors

Cause quick-lint-js to exit with a non-zero exit code if any of the discovered errors is listed in errors.

See the Error lists section for a description of the format for errors.

Incompatible with --lsp-server.

--stdin

Read standard input as a JavaScript file.

Incompatible with --lsp-server.

--lsp
--lsp-server

Run quick-lint-js in LSP server mode. Use this mode to integrate with code editors supporting LSP. An editor can send LSP requests and notifications to quick-lint-js via standard input, and receive LSP responses and notifications from standard output.

Incompatible with --output-format.

--dump-config

Print quick-lint-js' configuration and exit. This option is not yet implemented.

-h
--help

Print a help message and exit.

The output format is not intended to be machine-parsable and may change in the future.

-v
--version

Print version information and exit.

The output format is not intended to be machine-parsable and may change in the future.

Error lists

Some options, such as --exit-fail-on, accept an error list. An error list is a comma-separated list of error code predicates and error category predicates.

An error lists can contain any number of include, exclude, and default predicates. An include predicate is a '+' followed by the name of an error code or error category. An exclude predicate is a '-' followed by the name of an error code or error category. An default predicate is the name of an error code or error category with no sigil.

An error list containing only include and exclude predicates modifies a default set of error codes. The default set is decided by the option, but is often the set of all error codes. An error list containing at least one default predicate empties the set of error codes, then treats the default predicates as if they were include predicates.

The order of predicates within an error list does not matter. Included predicates are processed first, adding to the set of error codes. Excluded predicates are processed second, removing from the set of error codes.

Error codes have the form E000, where 000 is three decimal digits (0-9).

The following error categories are supported:

all

All error codes.

Example error lists:

E102,E110

Only error codes E102 and E110, excluding all other error codes.

-E102

The default set of error codes, except for error code E102.

+E102

The default set of error codes, and also error code E102.

all,-E102

All error codes, except for error code E102.

E100,-E100,+E200

Only error code E200, excluding all other error codes.

+E200,-E100,E100

Only error code E200, excluding all other error codes.

Exit status

0

Batch mode: Linting succeeded with no errors or warnings.

LSP server mode: The LSP client requested that the server shut down. This exit status may change in the future.

non-0

Batch mode: Linting failed with at least one error or warning, or at least one file could not be opened and read.

The specific status code may change in the future.

Environment

LC_ALL
LC_MESSAGES

Change the language used for error and warning messages. For example, set LC_ALL=en to see messages written in United States English.

Example

To lint a file called lib/index.js, writing error messages to the terminal:

$ quick-lint-js lib/index.js
lib/index.js:1:20: error: variable used before declaration: language [E058]
lib/index.js:2:7: note: variable declared here [E058]
lib/index.js:3:1: error: assignment to const variable [E003]
lib/index.js:1:7: note: const variable declared here [E003]
lib/index.js:5:25: warning: use of undeclared variable: ocupation [E057]

To lint three files, writing machine-readable messages to /tmp/vim-qflist.json:

$ quick-lint-js --output-format=vim-qflist-json \
    --vim-bufnr=3 lib/pizza-dough.js \
    --vim-bufnr=4 lib/pizza-sauce.js \
    --vim-bufnr=6 lib/pineapple.js \
    >/tmp/vim-qflist.json

Errors for lib/pizza-dough.js will include "bufnr":3 in the output and errors for lib/pineapple.js will include "bufnr":6.

To lint a file called bad.js, but don’t fail on use-of-undeclared-variable errors:

$ quick-lint-js --exit-fail-on=-E057 bad.js
bad.js:5:25: warning: use of undeclared variable: $ [E057]
$ echo $?
0

To lint source files with a strict configuration file and lint test files with a lax configuration file:

$ quick-lint-js \
    --config-file strict-quick-lint-js.config src/index.js src/helpers.js \
    --config-file lax-quick-lint-js.config test/test-app.js