CLI Lint
Wire any command-line linter into VS Code's Problems panel, in the spirit of
nvim-lint: a linter is just a command, how to feed it
the buffer, and how to parse what it prints. No language server required.
| nvim-lint |
CLI Lint |
lint.linters_by_ft |
cliLint.lintersByLanguage |
lint.linters.<name> |
cliLint.linters.<name> |
cmd, args, stdin |
command, args, stdin |
stream, ignore_exitcode |
stream, ignoreExitCode |
parser = from_pattern(...) |
parser: { "type": "regex", ... } |
| custom JSON parser function |
parser: { "type": "json", ... } |
try_lint() in an autocmd |
cliLint.runOn + "CLI Lint: Lint Current File" |
Quick start
Built-in definitions exist for shellcheck, ruff, hadolint and yamllint. Enable them per
language (the keys are VS Code language IDs):
// settings.json
"cliLint.lintersByLanguage": {
"shellscript": ["shellcheck"],
"python": ["ruff"],
"dockerfile": ["hadolint"],
"yaml": ["yamllint"]
},
"cliLint.runOn": ["open", "save", "change"]
Defining a linter
"cliLint.linters": {
"mylint": {
"command": "mylint",
"args": ["--format", "gcc", "${file}"],
"stdin": false, // true: pipe the buffer to stdin (lints unsaved changes)
"stream": "stdout", // "stdout" | "stderr" | "both"
"ignoreExitCode": true, // don't report non-zero exit + no output as a failure
"cwd": "${workspaceFolder}",
"env": { "NO_COLOR": "1" },
"timeoutMs": 10000,
"parser": {
"type": "regex",
"pattern": "^(?<file>[^:]+):(?<line>\\d+):(?<column>\\d+): (?<severity>\\w+): (?<message>.*)$"
}
}
},
"cliLint.lintersByLanguage": { "c": ["mylint"] }
Commands are spawned directly, without a shell. On Windows, tools installed as .cmd shims
(e.g. via npm) need their full name, such as eslint.cmd.
Variables
args, cwd and env values support ${file}, ${fileBasename}, ${fileBasenameNoExtension},
${fileDirname}, ${fileExtname}, ${relativeFile}, ${workspaceFolder} and ${env:NAME}.
If an argument references a variable that isn't available (e.g. ${file} for an untitled
buffer), that linter is skipped for that document.
Parsers
Both parsers produce the same fields: line, column, endLine, endColumn, severity,
message, code, file. Only message is required. Without line, the diagnostic goes on the
first line. Without column, the whole line is underlined. Without an end, the word at
the start position is underlined.
Common options:
severityMap: the tool's severity values mapped to error / warning / info / hint.
Built-in mappings already handle error, warning, warn, info, note, hint and style
(case-insensitive).
defaultSeverity: used when there is no severity or it isn't recognized (default warning).
lineBase / columnBase: index of the first line or column in the tool's output (default 1).
End columns are treated as exclusive.
When a diagnostic has a file that resolves to a different file than the one being linted,
it is dropped. -, stdin and <stdin> count as the current file.
regex: a JavaScript regular expression with named groups, matched across the whole output
(flags defaults to gm).
json: root is a path to the array of diagnostics (empty means the output itself), and
fields maps each field to a path within an item. Paths use dots or brackets (location.row,
pos[0]), and * fans out over every element. Set jsonLines: true for one JSON object per
line. A field mapped to "" is ignored. Unmapped fields default to their own name.
ESLint, for example:
"eslint": {
"command": "npx",
"args": ["eslint", "--format", "json", "--stdin", "--stdin-filename", "${file}"],
"stdin": true,
"ignoreExitCode": true,
"parser": {
"type": "json",
"root": "*.messages",
"fields": { "code": "ruleId" },
"severityMap": { "1": "warning", "2": "error" }
}
}
Overriding built-ins
An entry in cliLint.linters with the same name as a built-in is shallow-merged over it:
"cliLint.linters": {
"shellcheck": { "args": ["--format=json1", "--severity=warning", "-"] }
}
Behavior
- Each linter gets its own diagnostic collection, and
source is set to the linter name.
- A new run for the same document and linter kills the previous one.
change runs are debounced (cliLint.debounceMs) and only run stdin linters, because
file-based linters would read stale content from disk.
- Missing executables, timeouts, unparseable output and failed runs are logged to the
CLI Lint output channel. Each one triggers a single notification per session. Set the
channel's log level to Debug to see every command line.
- The extension is disabled in untrusted workspaces, because workspace settings could
otherwise make it run arbitrary commands.
Development
npm install
npm test # compile + unit tests (parsers, substitution, process runner)
npm run test:integration # runs the extension in an isolated VS Code instance
The integration test starts VS Code with a throwaway profile and extensions directory, so it
doesn't touch your setup. It uses VSCODE_EXECUTABLE if set. Otherwise it uses the installed
macOS app, or downloads VSCODE_VERSION (default stable) into .vscode-test/.
Releasing
Releases are published by .github/workflows/release.yml when a
v*.*.* tag is pushed. It runs the tests, checks that the tag matches package.json, publishes
the same .vsix to the VS Code Marketplace and Open VSX, then creates a GitHub release with the
.vsix attached.
# update CHANGELOG.md first
npm version patch # or minor / major: bumps package.json, commits, tags
git push --follow-tags
The Marketplace supports only major.minor.patch versions (no -beta.1 suffixes), and a
version can never be reused, even after it is unpublished.
One-time setup
Neither registry needs a long-lived token in CI. Both use GitHub OIDC trusted publishing,
restricted to this repository, release.yml, and the release environment.
- VS Code Marketplace: go to https://marketplace.visualstudio.com/manage, open the
RoginFarrer publisher, then Trusted Publishing → Create. Use owner roginfarrer,
repository vscode-linter, workflow release.yml, environment release.
- Open VSX: sign in at https://open-vsx.org with GitHub, link an eclipse.org account, and
sign the Publisher Agreement. Then create the namespace and a token:
npx ovsx create-namespace RoginFarrer -p <token>
Open VSX only allows trusted publishing once the extension exists there, so add the token
as an OVSX_PAT secret on the release environment for the first release.
After that release, register a trusted publisher on https://open-vsx.org/user-settings/trusted-publishers
with the same repository, workflow, and environment values. Then delete the OVSX_PAT
secret and revoke the token.
- GitHub (optional): under Settings → Environments → release, add required reviewers
or restrict it to
v* tags so a release needs approval before it publishes.
Press F5 in VS Code to launch an Extension Development Host. Run npm run package to
build a .vsix (uses @vscode/vsce via npx), then install it with
code --install-extension cli-lint-0.1.0.vsix.