Quick Start
Getting started with gptlint
is easy and should only take a few minutes to set up with a new codebase.
Prerequisites
node >= 18
Install
npm i -D gptlint
We recommended installing gptlint
as a dev dependency just like eslint
.
OpenAI
GPTLint defaults to using the OpenAI API, so you’ll need to sign up for an OpenAI API key. Add your OPENAI_API_KEY
as an environment variable or store it in a .env
file in your project’s root.
GPTLint supports local LLMs and other providers, so if you don’t want to use OpenAI, see this guide.
Dry Run
npx gptlint --help
By default, gptlint
uses **/*.{js,ts,jsx,tsx,cjs,mjs}
to match source files. .gitignore
will be respected, and optionally .gptlintignore
as well if it exists.
Now let’s try running gptlint
with the --dry-run
flag:
npx gptlint --dry-run
The --dry-run
flag is very useful for estimating how much it would cost to run the linter for real.
Since LLM costs can add up quickly for large codebases,
it’s always a good idea to make sure you understand the projected costs before
running gptlint
on a new project.
If you want to try out gptlint
without worrying about the cost, you can run gptlint
on a single source file like this:
npx gptlint --dry-run src/utils.ts
If you’re ever not sure about what will be run, you can use the --print-config
flag to view all of the resolved rules, settings, and source files that will be processed:
npx gptlint --print-config
If there are source files being picked up by gptlint
that you’d like to ignore, you can add glob patterns to a .gptlintignore
file at the root of your project to ignore them.
Real Run
Oooooohhhh now comes the fun part! Let’s run gptlint
for real and see what it finds…
npx gptlint
Depending on the size of your codebase, this could take anywhere from a few seconds to a few minutes. It’ll display a summary of the linter tasks as it runs.
Once it completes, you should see something resembling this output:
This example output comes from running gptlint
fresh on it’s own codebase with
caching disabled. It cost a total of $0.83 USD and made 351 LLM calls
to OpenAI, with the vast majority of them using gpt-4o-mini
.
More than likely, you’ll see some lint errors that you should consider addressing. Just keep in mind that since gptlint
isn’t 100% accurate (like a human code reviewer), it’s possible for gptlint
to report false positives and miss false negatives, but we’re working hard to improve the accuracy of the core linting engine and built-in rules over time.
For more details on how to interpret the output, see usage and our faq. Check out the built-in rules to see what gptlint
can enforce out of the box.