# core/adapters/tool.checkstyle.adapter.ts

> 30 lines of code and 7 definitions.

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

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

## Definitions

- `runCheckstyle` (lexical_declaration, line 16)
- `TOOL` (lexical_declaration, line 13)
- `DEFAULTS` (lexical_declaration, line 14)
- `{ command, config }` (lexical_declaration, line 17)
- `{ bin, prefix }` (lexical_declaration, line 18)
- `advisory` (lexical_declaration, line 19)
- `spec` (lexical_declaration, line 20)

## 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, toolErrorMessage } 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 { SUCCESS_STATUSES } from "#configuration/constants/tool.constants";
import { commandOf } from "#core/lexers/invocation.lexer";
import { defineTool } from "#core/registries/tool.registry";
import { exitDetail } from "#core/selectors/failure.selector";
import { parseSarifReport } from "#core/parsers/report.parser";
import { quietGatingAdvisory } from "#core/factories/tool.factory";
import { toolSetting } from "#core/resolvers/tool.resolver";

const TOOL = "checkstyle";
const DEFAULTS = { command: "java -jar checkstyle.jar", config: "/google_checks.xml" };

const runCheckstyle = async function runCheckstyle(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,
        SUCCESS_STATUSES,
        (result) => parseSarifReport(result.stdout, context.ecosystem, TOOL),
        (exit) => toolErrorMessage(TOOL, exit.status, exitDetail(exit)),
    );
    return scanTool(
        advisory,
        { args: [...prefix, "-c", config, "-f", "sarif", ...context.paths], bin, cwd: context.root },
        spec,
    );
};

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