# core/producers/tool.clang-tidy.producer.ts

> 48 lines of code and 16 definitions.

Tree: GovLab Quality
Language: typescript
Layer: application
Canonical: https://banes-lab.com/anatomy/quality#file-quality-core-producers-tool-clang-tidy-producer-ts
Source text: https://banes-lab.com/source/quality/core/producers/tool.clang-tidy.producer.ts.txt

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

## Definitions

- `produce` (lexical_declaration, line 40)
- `TOOL` (lexical_declaration, line 8)
- `VERSION` (lexical_declaration, line 9)
- `SOURCE` (lexical_declaration, line 10)
- `DOCS` (lexical_declaration, line 12)
- `DOC` (lexical_declaration, line 13)
- `LT` (lexical_declaration, line 14)
- `parseLine` (lexical_declaration, line 16)
- `at` (lexical_declaration, line 17)
- `lt` (lexical_declaration, line 18)
- `name` (lexical_declaration, line 19)
- `pathStart` (lexical_declaration, line 23)
- `pathEnd` (lexical_declaration, line 24)
- `docPath` (lexical_declaration, line 25)
- `parsed` (lexical_declaration, line 41)
- `rules` (lexical_declaration, line 42)

## Contained in

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

## Uses

- [core/aggregators/catalog.aggregator.ts](https://banes-lab.com/source/quality/core/aggregators/catalog.aggregator.ts.md)

## Linked from

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

## Source

```typescript
import type { CatalogProduct, CatalogRule } from "#types/catalog.types";
import { byRuleId } from "#core/comparators/rule.comparator";
import { defineProducer } from "#core/registries/producer.registry";
import { distinctRules } from "#core/selectors/catalog.selector";
import { remoteText } from "#core/adapters/remote.adapter";
import { tallyBy } from "#core/aggregators/catalog.aggregator";

const TOOL = "clang-tidy";
const VERSION = "llvm-main";
const SOURCE =
    "https://raw.githubusercontent.com/llvm/llvm-project/main/clang-tools-extra/docs/clang-tidy/checks/list.rst";
const DOCS = "https://clang.llvm.org/extra/clang-tidy/checks";
const DOC = ":doc:`";
const LT = " <";

const parseLine = function parseLine(line: string): CatalogRule | null {
    const at = line.indexOf(DOC);
    const lt = at === -1 ? -1 : line.indexOf(LT, at + DOC.length);
    const name = lt === -1 ? "" : line.slice(at + DOC.length, lt).trim();
    if (name === "") {
        return null;
    }
    const pathStart = lt + LT.length;
    const pathEnd = line.indexOf(">", pathStart);
    const docPath = pathEnd > pathStart ? line.slice(pathStart, pathEnd) : name;
    return {
        canonical: null,
        category: name.includes("-") ? name.slice(0, name.indexOf("-")) : name,
        description: null,
        ecosystem: "cpp",
        fixable: line.includes('"Yes"'),
        name,
        ruleId: name,
        tool: TOOL,
        toolVersion: VERSION,
        url: `${DOCS}/${docPath}.html`,
    };
};

const produce = async function produce(): Promise<CatalogProduct[]> {
    const parsed = ((await remoteText(SOURCE)) ?? "").split("\n").map(parseLine);
    const rules = distinctRules(parsed.filter((rule): rule is CatalogRule => rule !== null)).toSorted(byRuleId);
    return [
        {
            rules,
            source: TOOL,
            summary: { byCategory: tallyBy(rules, "category"), tool: TOOL, toolVersion: VERSION, total: rules.length },
        },
    ];
};

defineProducer({ name: TOOL, produce, refresh: "manual" });
```
