# core/selectors/block.selector.ts

> 29 lines of code and 6 definitions.

Tree: GovLab Quality
Language: typescript
Layer: application
Canonical: https://banes-lab.com/anatomy/quality#file-quality-core-selectors-block-selector-ts
Source text: https://banes-lab.com/source/quality/core/selectors/block.selector.ts.txt

Listed in [core/selectors](https://banes-lab.com/api/source/quality/core/selectors.md), before [core/selectors/catalog.selector.ts](https://banes-lab.com/source/quality/core/selectors/catalog.selector.ts.md).

## Definitions

- `excluded` (lexical_declaration, line 22, exported)
- `filterBlockExcluded` (lexical_declaration, line 7, exported)
- `rangesOf` (lexical_declaration, line 16, exported)
- `cache` (lexical_declaration, line 15, exported)
- `key` (lexical_declaration, line 17, exported)
- `resolved` (lexical_declaration, line 18, exported)

## Contained in

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

## Uses

- [core/converters/filename.converter.ts](https://banes-lab.com/source/quality/core/converters/filename.converter.ts.md)

## Used by

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

## Linked from

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

## Source

```typescript
import type { LineRange } from "#types/edit.types";
import type { OxlintBlockExclusion } from "#types/config.types";
import type { PlacedFinding } from "#types/finding.types";
import { forwardSlashed } from "#core/converters/filename.converter";
import { functionRangesIn } from "#core/visitors/block.visitor";

export const filterBlockExcluded = function filterBlockExcluded<T extends PlacedFinding>(
    findings: T[],
    exclusions: readonly OxlintBlockExclusion[],
    root: string,
): T[] {
    if (exclusions.length === 0) {
        return findings;
    }
    const cache = new Map<string, LineRange[]>();
    const rangesOf = (exclusion: OxlintBlockExclusion): LineRange[] => {
        const key = `${exclusion.file}|${exclusion.functions.join(",")}`;
        const resolved = cache.get(key) ?? functionRangesIn(root, exclusion.file, new Set(exclusion.functions));
        cache.set(key, resolved);
        return resolved;
    };
    const excluded = (finding: PlacedFinding): boolean =>
        exclusions.some(
            (exclusion) =>
                finding.ruleId === exclusion.rule &&
                forwardSlashed(finding.file).endsWith(forwardSlashed(exclusion.file)) &&
                rangesOf(exclusion).some((range) => finding.line >= range.start && finding.line <= range.end),
        );
    return findings.filter((finding) => !excluded(finding));
};
```
