Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: add `LintKind` colours to the Playwright HTML report (#1481)
Andrew Dunbarcd534b6cc4e4
diff --git a/packages/chrome-plugin/src/lintKindColor.ts b/packages/chrome-plugin/src/lintKindColor.tsindex 76fc36f84..da0bf84b8 100644--- a/packages/chrome-plugin/src/lintKindColor.ts+++ b/packages/chrome-plugin/src/lintKindColor.ts@@ -1,28 +1,29 @@+// First, define the color map as a constant+const LINT_KIND_COLORS = {+ Capitalization: '#540D6E', // Deep purple+ Enhancement: '#0EAD69', // Green+ Formatting: '#7D3C98', // Amethyst purple+ Miscellaneous: '#3BCEAC', // Turquoise+ Punctuation: '#D4850F', // Dark orange+ Readability: '#2E8B57', // Sea green+ Regionalism: '#C061CB', // Vibrant purple+ Repetition: '#00A67C', // Green-cyan+ Spelling: '#EE4266', // Pink-red+ Style: '#FFD23F', // Yellow+ WordChoice: '#228B22', // Forest green+} as const;++// Export the type for the lint kind keys+export type LintKind = keyof typeof LINT_KIND_COLORS;++// 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 mapexport default function lintKindColor(lintKindKey: string): string {- switch (lintKindKey) {- case 'Capitalization':- return '#540D6E'; // Deep purple- case 'Enhancement':- return '#0EAD69'; // Green- case 'Formatting':- return '#7D3C98'; // Amethyst purple- case 'Miscellaneous':- return '#3BCEAC'; // Turquoise- case 'Punctuation':- return '#D4850F'; // Dark orange- case 'Readability':- return '#2E8B57'; // Sea green- case 'Regionalism':- return '#C061CB'; // Vibrant purple- case 'Repetition':- return '#00A67C'; // Green-cyan- case 'Spelling':- return '#EE4266'; // Pink-red- case 'Style':- return '#FFD23F'; // Yellow- case 'WordChoice':- return '#228B22'; // Forest green- default:- throw new Error(`Unexpected lint kind: ${lintKindKey}`);+ const color = LINT_KIND_COLORS[lintKindKey as LintKind];+ if (!color) {+ throw new Error(`Unexpected lint kind: ${lintKindKey}`);}+ return color;}diff --git a/packages/chrome-plugin/tests/lint-kinds.spec.ts b/packages/chrome-plugin/tests/lint-kinds.spec.tsnew file mode 100644index 000000000..af9d58a31--- /dev/null+++ b/packages/chrome-plugin/tests/lint-kinds.spec.ts@@ -0,0 +1,55 @@+import { expect, test } from '@playwright/test';+import lintKindColor, { LINT_KINDS } from '../src/lintKindColor';++test('display lint kind colors', async ({ page }, testInfo) => {+ // Generate color boxes for each lint kind+ const colorBoxes = LINT_KINDS.map((kind) => {+ const color = lintKindColor(kind);+ return `<div class="color-box" style="background-color: ${color}">${kind}</div>`;+ }).join('\n');++ const htmlContent = `+ <!DOCTYPE html>+ <html>+ <head>+ <title>Lint Kind Colors</title>+ <style>+ body {+ font-family: Arial, sans-serif;+ padding: 20px;+ background: #f5f5f5;+ }+ h1 {+ color: #333;+ margin-top: 0;+ }+ .container {+ display: flex;+ flex-wrap: wrap;+ gap: 10px;+ margin-top: 20px;+ }+ .color-box {+ padding: 10px 20px;+ border-radius: 4px;+ color: white;+ font-weight: bold;+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);+ }+ </style>+ </head>+ <body>+ <h1>Lint Kind Colors</h1>+ <div class="container">+ ${colorBoxes}+ </div>+ </body>+ </html>+ `;++ // Attach the HTML report+ await testInfo.attach('lint-colors.html', {+ body: htmlContent,+ contentType: 'text/html',+ });+});diff --git a/packages/web/src/lib/lintKindColor.ts b/packages/web/src/lib/lintKindColor.tsindex 76fc36f84..da0bf84b8 100644--- a/packages/web/src/lib/lintKindColor.ts+++ b/packages/web/src/lib/lintKindColor.ts@@ -1,28 +1,29 @@+// First, define the color map as a constant+const LINT_KIND_COLORS = {+ Capitalization: '#540D6E', // Deep purple+ Enhancement: '#0EAD69', // Green+ Formatting: '#7D3C98', // Amethyst purple+ Miscellaneous: '#3BCEAC', // Turquoise+ Punctuation: '#D4850F', // Dark orange+ Readability: '#2E8B57', // Sea green+ Regionalism: '#C061CB', // Vibrant purple+ Repetition: '#00A67C', // Green-cyan+ Spelling: '#EE4266', // Pink-red+ Style: '#FFD23F', // Yellow+ WordChoice: '#228B22', // Forest green+} as const;++// Export the type for the lint kind keys+export type LintKind = keyof typeof LINT_KIND_COLORS;++// 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 mapexport default function lintKindColor(lintKindKey: string): string {- switch (lintKindKey) {- case 'Capitalization':- return '#540D6E'; // Deep purple- case 'Enhancement':- return '#0EAD69'; // Green- case 'Formatting':- return '#7D3C98'; // Amethyst purple- case 'Miscellaneous':- return '#3BCEAC'; // Turquoise- case 'Punctuation':- return '#D4850F'; // Dark orange- case 'Readability':- return '#2E8B57'; // Sea green- case 'Regionalism':- return '#C061CB'; // Vibrant purple- case 'Repetition':- return '#00A67C'; // Green-cyan- case 'Spelling':- return '#EE4266'; // Pink-red- case 'Style':- return '#FFD23F'; // Yellow- case 'WordChoice':- return '#228B22'; // Forest green- default:- throw new Error(`Unexpected lint kind: ${lintKindKey}`);+ const color = LINT_KIND_COLORS[lintKindKey as LintKind];+ if (!color) {+ throw new Error(`Unexpected lint kind: ${lintKindKey}`);}+ return color;}