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

> 27 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-hadolint-adapter-ts
Source text: https://banes-lab.com/source/quality/core/adapters/tool.hadolint.adapter.ts.txt

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

## Definitions

- `runHadolint` (lexical_declaration, line 22)
- `TOOL` (lexical_declaration, line 12)
- `hadolintFlags` (lexical_declaration, line 14, exported)
- `threshold` (lexical_declaration, line 15, exported)
- `flags` (lexical_declaration, line 23)
- `advisory` (lexical_declaration, line 24)
- `spec` (lexical_declaration, line 25)

## 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 { scanTool, standardScan } from "#core/adapters/tool.adapter";
import { stringArrayField, stringField } from "#core/selectors/record.selector";
import { FINDING_STATUSES } from "#configuration/constants/tool.constants";
import type { RunResult } from "#types/finding.types";
import type { RunnerContext } from "#types/tool.types";
import { defineTool } from "#core/registries/tool.registry";
import { gatingAdvisory } from "#core/factories/tool.factory";
import { installHint } from "#configuration/strings/tool.strings";
import { parseHadolintOutput } from "#core/parsers/tool.hadolint.parser";
import { toolSection } from "#core/resolvers/tool.resolver";

const TOOL = "hadolint";

export const hadolintFlags = function hadolintFlags(section: Record<string, unknown>): string[] {
    const threshold = stringField(section, "failureThreshold");
    return [
        ...(threshold.length > 0 ? ["--failure-threshold", threshold] : []),
        ...stringArrayField(section, "ignore").flatMap((rule) => ["--ignore", rule]),
    ];
};

const runHadolint = async function runHadolint(context: RunnerContext): Promise<RunResult> {
    const flags = hadolintFlags(await toolSection(context.root, TOOL));
    const advisory = gatingAdvisory(context, TOOL, installHint(TOOL));
    const spec = standardScan(advisory, FINDING_STATUSES, (result) =>
        parseHadolintOutput(result.stdout, context.ecosystem),
    );
    return scanTool(advisory, { args: ["-f", "json", ...flags, ...context.paths], bin: TOOL, cwd: context.root }, spec);
};

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