Skip to content
Myr

markers.ts

This file

Path

packages/gate/src/markers.ts

101 lines · 2.7 KiB · TypeScript

Last changed by

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–72why, one step back
1import type { Policy } from "@repo/protocol/domain/policy";
2import type { RepoPath } from "@repo/protocol/ids";3import { Option, Order } from "effect";45import type { PushFacts } from "./facts.ts";67export interface Marker {8 readonly text: string;9 readonly family:10 | "test"11 | "lint"12 | "types"13 | "effect"14 | "coverage"15 | "python"16 | "rust"17 | "go";18}1920export const defaultMarkers: readonly Marker[] = [21 { family: "test", text: ".skip(" },22 { family: "test", text: ".only(" },23 { family: "test", text: ".todo(" },24 { family: "lint", text: "eslint-disable" },25 { family: "lint", text: "oxlint-disable" },26 { family: "lint", text: "biome-ignore" },27 { family: "types", text: "@ts-ignore" },28 { family: "types", text: "@ts-expect-error" },29 { family: "types", text: "@ts-nocheck" },30 { family: "effect", text: "@effect-diagnostics" },31 { family: "python", text: "# noqa" },32 { family: "python", text: "# type: ignore" },33 { family: "rust", text: "#[allow(" },34 { family: "go", text: "//nolint" },35 { family: "coverage", text: "istanbul ignore" },36 { family: "coverage", text: "c8 ignore" },37];3839export const markersOf = (policy: Policy): readonly string[] => [40 ...new Set([41 ...defaultMarkers.map((marker) => marker.text),42 ...policy.weakening.markers,43 ]),44];4546export interface MarkerHit {47 readonly path: RepoPath;48 readonly line: number;49 readonly marker: string;50 readonly reason: Option.Option<string>;51}5253const REASON_MARK = /\s--(?=\s|$)/u;5455const CLOSER = /\s*(?:\*\/|-->)\s*$/u;5657const reasonIn = (rest: string): Option.Option<string> => {58 const mark = REASON_MARK.exec(rest);5960 if (mark === null) {61 return Option.none();62 }6364 const reason = rest65 .slice(mark.index + mark[0].length)66 .replace(CLOSER, "")67 .trim();6869 return reason === "" ? Option.none() : Option.some(reason);70};7172/**

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

lines 73–74why, one step back
73 * A marker is plain text: it is found in any file, a README included; a
74 * project decides by adding to or trimming its list.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 75–101why, one step back
75 */
76export const scanMarkers = (77 lines: PushFacts["addedLines"],78 markers: readonly string[]79): readonly MarkerHit[] =>80 [...lines]81 .toSorted(([one], [other]) => Order.String(one, other))82 .flatMap(([path, each]) =>83 each84 .toSorted((one, other) => one.line - other.line)85 .flatMap(({ line, text }) =>86 markers.flatMap((marker) => {87 const index = text.indexOf(marker);8889 return index === -190 ? []91 : [92 {93 line,94 marker,95 path,96 reason: reasonIn(text.slice(index + marker.length)),97 },98 ];99 })100 )101 );