# core/adapters/tool.clj-kondo.adapter.ts

> 31 lines of code and 13 definitions.

Tree: GovLab Quality
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/quality#file-quality-core-adapters-tool-clj-kondo-adapter-ts
Source text: https://banes-lab.com/source/quality/core/adapters/tool.clj-kondo.adapter.ts.txt

Listed in [core/adapters](https://banes-lab.com/api/source/quality/core/adapters.md), after [core/adapters/tool.clippy.adapter.ts](https://banes-lab.com/source/quality/core/adapters/tool.clippy.adapter.ts.md) and before [core/adapters/tool.credo.adapter.ts](https://banes-lab.com/source/quality/core/adapters/tool.credo.adapter.ts.md).

## Definitions

- `runCljKondo` (lexical_declaration, line 19)
- `TOOL` (lexical_declaration, line 12)
- `DEFAULTS` (lexical_declaration, line 13)
- `FINDINGS_WARNING_EXIT` (lexical_declaration, line 14)
- `FINDINGS_ERROR_EXIT` (lexical_declaration, line 15)
- `OK_STATUSES` (lexical_declaration, line 16)
- `JSON_FORMAT_CONFIG` (lexical_declaration, line 17)
- `{ command, config }` (lexical_declaration, line 20)
- `{ bin, prefix }` (lexical_declaration, line 21)
- `advisory` (lexical_declaration, line 22)
- `spec` (lexical_declaration, line 23)
- `consumerConfig` (lexical_declaration, line 29)
- `args` (lexical_declaration, line 30)

## Contained in

- [core/adapters](https://banes-lab.com/anatomy/quality/folder-quality-core-adapters.md)

## Uses

- [core/adapters/tool.adapter.ts](https://banes-lab.com/source/quality/core/adapters/tool.adapter.ts.md)

## Linked from

- [core/adapters](https://banes-lab.com/anatomy/quality/folder-quality-core-adapters.md)

## Source

```typescript
import { commandHint, toolErrorBecause } from "#configuration/strings/tool.strings";
import { messageScan, scanTool } from "#core/adapters/tool.adapter";
import type { RunResult } from "#types/finding.types";
import type { RunnerContext } from "#types/tool.types";
import { commandOf } from "#core/lexers/invocation.lexer";
import { defineTool } from "#core/registries/tool.registry";
import { exitDetail } from "#core/selectors/failure.selector";
import { parseCljKondoOutput } from "#core/parsers/tool.clj-kondo.parser";
import { quietGatingAdvisory } from "#core/factories/tool.factory";
import { toolSetting } from "#core/resolvers/tool.resolver";

const TOOL = "clj-kondo";
const DEFAULTS = { command: TOOL, config: "" };
const FINDINGS_WARNING_EXIT = 2;
const FINDINGS_ERROR_EXIT = 3;
const OK_STATUSES: ReadonlySet<number> = new Set([0, FINDINGS_WARNING_EXIT, FINDINGS_ERROR_EXIT]);
const JSON_FORMAT_CONFIG = "{:output {:format :json}}";

const runCljKondo = async function runCljKondo(context: RunnerContext): Promise<RunResult> {
    const { command, config } = await toolSetting(context.root, TOOL, DEFAULTS);
    const { bin, prefix } = commandOf(command, TOOL);
    const advisory = quietGatingAdvisory(context, TOOL, commandHint(TOOL, bin));
    const spec = messageScan(
        advisory,
        OK_STATUSES,
        (result) => parseCljKondoOutput(result.stdout, context.ecosystem),
        (exit) => toolErrorBecause(TOOL, exit.status, "a malformed EDN config", exitDetail(exit)),
    );
    const consumerConfig = config.length > 0 ? ["--config", config] : [];
    const args = [...prefix, "--lint", ...context.paths, ...consumerConfig, "--config", JSON_FORMAT_CONFIG];
    return scanTool(advisory, { args, bin, cwd: context.root }, spec);
};

defineTool({ ecosystems: ["clojure"], run: runCljKondo, tool: TOOL });
```
