# test.govlab/quality/core/parsers/tool.swiftlint.parser.test.ts

> 51 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-quality-core-parsers-tool-swiftlint-parser-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/quality/core/parsers/tool.swiftlint.parser.test.ts.txt

Listed in [test.govlab/quality/core/parsers](https://banes-lab.com/api/source/testing/test.govlab/quality/core/parsers.md), after [test.govlab/quality/core/parsers/tool.stylua.parser.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/parsers/tool.stylua.parser.test.ts.md) and before [test.govlab/quality/core/parsers/tool.tflint.parser.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/parsers/tool.tflint.parser.test.ts.md).

## Contained in

- [test.govlab/quality/core/parsers](https://banes-lab.com/anatomy/testing/folder-testing-test-govlab-quality-core-parsers.md)

## Source

```typescript
import { describe, expect, it } from "vitest";
import { parseSwiftlintOutput } from "@govlab/quality/core/parsers/tool.swiftlint.parser.ts";

const EXPECTED_COUNT = 2;

const RECORDED = JSON.stringify([
    {
        character: 16,
        file: "govlab-governance/polyglot/swift/Bad.swift",
        line: 2,
        reason: "Force casts should be avoided.",
        rule_id: "force_cast",
        severity: "Error",
        type: "Force Cast",
    },
    {
        character: 1,
        file: "govlab-governance/polyglot/swift/Bad.swift",
        line: 5,
        reason: "Lines should not have trailing whitespace.",
        rule_id: "trailing_whitespace",
        severity: "Warning",
    },
]);

describe("parseSwiftlintOutput", () => {
    it("maps each violation to a gating (advisory:false) finding keyed by rule_id, severity mapped", () => {
        const findings = parseSwiftlintOutput(RECORDED, "swift");
        expect(findings).toHaveLength(EXPECTED_COUNT);
        expect(findings[0]).toMatchObject({
            advisory: false,
            column: 16,
            ecosystem: "swift",
            file: "govlab-governance/polyglot/swift/Bad.swift",
            line: 2,
            message: "Force casts should be avoided.",
            ruleId: "force_cast",
            severity: "error",
            tool: "swiftlint",
        });
        expect(findings[1]).toMatchObject({
            advisory: false,
            line: 5,
            ruleId: "trailing_whitespace",
            severity: "error",
        });
    });

    it("returns [] on empty, empty-array, or non-array/non-JSON output", () => {
        expect(parseSwiftlintOutput("", "swift")).toEqual([]);
        expect(parseSwiftlintOutput("[]", "swift")).toEqual([]);
        expect(parseSwiftlintOutput('{"not":"an array"}', "swift")).toEqual([]);
        expect(parseSwiftlintOutput("not json", "swift")).toEqual([]);
    });
});
```
