Automattic/harper · error · Error

Unexpected lint kind: ${lintKindKey}

Error message

Unexpected lint kind: ${lintKindKey}

What it means

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.

Source

Thrown at packages/lint-framework/src/lint/lintKindColor.ts:38

	Redundancy: '#4682B4', // Steel blue
	Regionalism: '#C061CB', // Vibrant purple
	Repetition: '#00A67C', // Green-cyan
	Spelling: '#EE4266', // Pink-red
	Style: '#FFD23F', // Yellow
	Typo: '#FF6B35', // Vibrant orange-red
	Usage: '#1E90FF', // Dodger blue
	WordChoice: '#228B22', // Forest green
	WordOrder: '#4D4DFF', // Royal blue
} as const satisfies Record<LintKind, string>;

// Export the array of all lint kind names
export const LINT_KINDS = Object.keys(LINT_KIND_COLORS) as LintKind[];

// The main function that uses the map
export function lintKindColor(lintKindKey: string): string {
	const color = LINT_KIND_COLORS[lintKindKey as LintKind];
	if (!color) {
		throw new Error(`Unexpected lint kind: ${lintKindKey}`);
	}
	return color;
}

export function lintKindTextColor(lintKindKeyOrColor: string): 'black' | 'white' {
	const color = LINT_KIND_COLORS[lintKindKeyOrColor as LintKind] ?? lintKindKeyOrColor;
	return getContrastingTextColor(color);
}

View on GitHub (pinned to 5fe7d5ab76)

Solutions

  1. Use a key from LINT_KINDS (exported list of valid kinds) instead of a hand-typed string.
  2. Add the missing kind to LINT_KIND_COLORS if it is a new harper-core lint kind.
  3. Check lint.kind at runtime before calling, or fall back to a default color for unknown kinds.

Example fix

// before
const c = lintKindColor(lint.kind); // throws for unknown kinds
// after
const c = LINT_KINDS.includes(lint.kind) ? lintKindColor(lint.kind) : '#888888';
Defensive patterns

Strategy: validation

Validate before calling

import { LINT_KINDS } from './lintKindColor';
const color = LINT_KINDS.includes(kind as any) ? lintKindColor(kind) : DEFAULT_COLOR;

Type guard

function isLintKind(k: string): k is LintKind {
  return LINT_KINDS.includes(k as LintKind);
}

Try / catch

let color: string;
try {
  color = lintKindColor(lint.kind);
} catch {
  color = '#808080'; // fallback for unknown/new kinds
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of Automattic/harper@5fe7d5ab76 (2026-09-06). Data as JSON: /api/errors/1a18724082b589e7. Report an issue: GitHub.