Skip to content

CLI

Flint’s CLI comes as part of the flint npm package. You can run it with npx or an equivalent:

Terminal window
npx flint

Whether to ignore any existing cache data on disk. This will cause a full re-lint of all linted files.

Terminal window
npx flint --cache-ignore

Enables auto-fixing β€œfixes” from rule reports.

Terminal window
npx flint --fix

Rule reports may include safe β€œfixer” changes that show how to fix source code. Adding --fix will instruct Flint to continuously re-run (up to 10 times), fixing code and re-linting files.

Enables auto-fixing any number of specific β€œsuggestions” from rule reports.

Terminal window
npx flint --fix-suggestions cspell:addWordToWords

Unlike --fix, --fix-suggestions requires passing in explicit names of suggestions to apply. Suggestion names are comprised of the rule name, and a suggestion ID, all joined by :.

Prints a help text dialog that explains options and links to this website.

Terminal window
npx flint --help

Whether to run Flint with an interactive β€œone file at a time” viewer.

Terminal window
npx flint --interactive

Flint’s interactive CLI view can be controlled by using the arrow keys printed in the output:

πŸ“Œ Displaying Flint reports in --interactive mode (file 1 of 2).
[<] previous file [>] next file [q] quit
β•­./example.ts
β”‚
β”‚ [forInArrays] For-in loops over arrays have surprising behavior that often leads to bugs.
β”‚
β”‚ 6:1 β”‚ for (const i in ["a", "b", "c"]) {
β”‚ β”‚ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
β”‚
β”‚ A for-in loop (`for (const i in o)`) iterates over all enumerable properties of an object, including those that are not array indices.
β”‚ This can lead to unexpected behavior when used with arrays, as it may include properties that are not part of the array's numeric indices.
β”‚ It also returns the index key (`i`) as a string, which is not the expected numeric type for array indices.
β”‚
β”‚ Suggestion: Use a construct more suited for arrays, such as a for-of loop (`for (const i of o)`).
β”‚ β†’ flint.fyi/rules/ts/forInArrays
β”‚
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
βœ– Found 3 reports across 2 files.

Which β€œpresenter” to output results using: brief (default) or detailed.

Terminal window
npx flint

The brief presenter shows a terse output with just file locations, primary report messages, and report IDs.

Linting with flint.config.ts...
/Users/josh/repos/flint/packages/cli/src/presenters/getPresenterFactory.ts
6:1 For-in loops over arrays have surprising behavior that often leads to bugs. forInArrays
βœ– Found 1 report across 1 file.

The detailed presenter shows a rich formatted output containing full report messages and syntax locations.

Linting with flint.config.ts...
β•­./packages/cli/src/presenters/getPresenterFactory.ts
β”‚
β”‚ [forInArrays] For-in loops over arrays have surprising behavior that often leads to bugs.
β”‚
β”‚ 6:1 β”‚ for (const i in ["a", "b", "c"]) {
β”‚ β”‚ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
β”‚
β”‚ A for-in loop (`for (const i in o)`) iterates over all enumerable properties of an object, including those that are not array indices.
β”‚ This can lead to unexpected behavior when used with arrays, as it may include properties that are not part of the array's numeric indices.
β”‚ It also returns the index key (`i`) as a string, which is not the expected numeric type for array indices.
β”‚
β”‚ Suggestion: Use a construct more suited for arrays, such as a for-of loop (`for (const i of o)`).
β”‚ β†’ flint.fyi/rules/forInArrays
β”‚
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
βœ– Found 1 report across 1 file.

Whether to skip reporting language β€œdiagnostics” after linting.

Terminal window
npx flint --skip-diagnostics

Language plugins such as are able to report additional checks from the languages after linting. For example, Flint’s core TypeScript plugin reports TypeScript type errors (effectively running tsc --noEmit) by re-using the TypeScript type services used in linting.

--skip-diagnostics can be used to disable those checks. You may wish to do this for performance and/or if you run tools like tsc separately from Flint.

Prints the current package version of Flint.

Terminal window
npx flint --version

Whether to keep the linting process running, re-linting files as they change.

Terminal window
npx flint --watch

Flint’s --watch mode is similar to the watch mode in other developer tools CLIs such as tsc --watch, tsdown --watch, and vitest --watch. It will lint files once on startup, then again whenever any linted files are changed on disk.

Made with ❀️‍πŸ”₯ in Boston by Josh Goldberg and contributors.