{"record":{"id":"1a18724082b589e7","repo":"Automattic/harper","slug":"unexpected-lint-kind-lintkindkey","errorCode":null,"errorMessage":"Unexpected lint kind: ${lintKindKey}","messagePattern":"Unexpected lint kind: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/lint-framework/src/lint/lintKindColor.ts","lineNumber":38,"sourceCode":"\tRedundancy: '#4682B4', // Steel blue\n\tRegionalism: '#C061CB', // Vibrant purple\n\tRepetition: '#00A67C', // Green-cyan\n\tSpelling: '#EE4266', // Pink-red\n\tStyle: '#FFD23F', // Yellow\n\tTypo: '#FF6B35', // Vibrant orange-red\n\tUsage: '#1E90FF', // Dodger blue\n\tWordChoice: '#228B22', // Forest green\n\tWordOrder: '#4D4DFF', // Royal blue\n} as const satisfies Record<LintKind, string>;\n\n// Export the array of all lint kind names\nexport const LINT_KINDS = Object.keys(LINT_KIND_COLORS) as LintKind[];\n\n// The main function that uses the map\nexport function lintKindColor(lintKindKey: string): string {\n\tconst color = LINT_KIND_COLORS[lintKindKey as LintKind];\n\tif (!color) {\n\t\tthrow new Error(`Unexpected lint kind: ${lintKindKey}`);\n\t}\n\treturn color;\n}\n\nexport function lintKindTextColor(lintKindKeyOrColor: string): 'black' | 'white' {\n\tconst color = LINT_KIND_COLORS[lintKindKeyOrColor as LintKind] ?? lintKindKeyOrColor;\n\treturn getContrastingTextColor(color);\n}\n","sourceCodeStart":20,"sourceCodeEnd":47,"githubUrl":"https://github.com/Automattic/harper/blob/5fe7d5ab76492d83f3ecdbc3f1da83c75dcb6f83/packages/lint-framework/src/lint/lintKindColor.ts#L20-L47","documentation":"lintKindColor() maps a lint kind string to a UI color via the LINT_KIND_COLORS lookup table. Any key not present in the table throws, because an unmapped kind would produce broken/unstyled UI rather than a sensible fallback.","triggerScenarios":"Calling lintKindColor(kind) (directly or via color/boxEl/suggestions/styleTag/SuggestionBox) with a kind string not in LINT_KIND_COLORS — e.g. a typo like 'grammer', a newly added harper-core lint kind that the frontend map lacks, or user-supplied rule kinds.","commonSituations":"Harper core added a new lint kind and the web package's color map is out of date; rendering lints from a custom rule with a nonstandard kind; misspelling a kind name in custom UI code.","solutions":["Use a key from LINT_KINDS (exported list of valid kinds) instead of a hand-typed string.","Add the missing kind to LINT_KIND_COLORS if it is a new harper-core lint kind.","Check lint.kind at runtime before calling, or fall back to a default color for unknown kinds."],"exampleFix":"// before\nconst c = lintKindColor(lint.kind); // throws for unknown kinds\n// after\nconst c = LINT_KINDS.includes(lint.kind) ? lintKindColor(lint.kind) : '#888888';","handlingStrategy":"validation","validationCode":"import { LINT_KINDS } from './lintKindColor';\nconst color = LINT_KINDS.includes(kind as any) ? lintKindColor(kind) : DEFAULT_COLOR;","typeGuard":"function isLintKind(k: string): k is LintKind {\n  return LINT_KINDS.includes(k as LintKind);\n}","tryCatchPattern":"let color: string;\ntry {\n  color = lintKindColor(lint.kind);\n} catch {\n  color = '#808080'; // fallback for unknown/new kinds\n}","preventionTips":["Always derive kind strings from LINT_KINDS or harper-core exports, never hand-type them.","When harper-core adds a lint kind, update LINT_KIND_COLORS in the same PR.","Keep a fallback color path in rendering code so new kinds degrade gracefully."],"tags":["javascript","typescript","configuration","ui"],"backgroundTag":"invalid-enum-value","analyzedSha":"5fe7d5ab76492d83f3ecdbc3f1da83c75dcb6f83","analyzedAt":"2026-09-06T11:34:38.610Z","contentChangedAt":"2026-09-06T11:34:38.610Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}