Switch to double quotes and reformat codebase with Biome

This commit is contained in:
Mohamed Boudra
2026-03-21 20:22:15 +07:00
parent ab40786882
commit f6579dbeb4
805 changed files with 38132 additions and 40175 deletions
+49 -49
View File
@@ -1,65 +1,65 @@
import { describe, it, expect } from 'vitest'
import { darkHighlightColors, lightHighlightColors } from '../colors.js'
import type { HighlightStyle } from '../types.js'
import { describe, it, expect } from "vitest";
import { darkHighlightColors, lightHighlightColors } from "../colors.js";
import type { HighlightStyle } from "../types.js";
const allStyles: HighlightStyle[] = [
'keyword',
'comment',
'string',
'number',
'literal',
'function',
'definition',
'class',
'type',
'tag',
'attribute',
'property',
'variable',
'operator',
'punctuation',
'regexp',
'escape',
'meta',
'heading',
'link',
]
"keyword",
"comment",
"string",
"number",
"literal",
"function",
"definition",
"class",
"type",
"tag",
"attribute",
"property",
"variable",
"operator",
"punctuation",
"regexp",
"escape",
"meta",
"heading",
"link",
];
describe('darkHighlightColors', () => {
it('covers all HighlightStyle values', () => {
describe("darkHighlightColors", () => {
it("covers all HighlightStyle values", () => {
for (const style of allStyles) {
expect(darkHighlightColors[style]).toBeDefined()
expect(typeof darkHighlightColors[style]).toBe('string')
expect(darkHighlightColors[style]).toBeDefined();
expect(typeof darkHighlightColors[style]).toBe("string");
}
})
});
it('has valid hex color values', () => {
it("has valid hex color values", () => {
for (const style of allStyles) {
expect(darkHighlightColors[style]).toMatch(/^#[0-9a-fA-F]{6}$/)
expect(darkHighlightColors[style]).toMatch(/^#[0-9a-fA-F]{6}$/);
}
})
})
});
});
describe('lightHighlightColors', () => {
it('covers all HighlightStyle values', () => {
describe("lightHighlightColors", () => {
it("covers all HighlightStyle values", () => {
for (const style of allStyles) {
expect(lightHighlightColors[style]).toBeDefined()
expect(typeof lightHighlightColors[style]).toBe('string')
expect(lightHighlightColors[style]).toBeDefined();
expect(typeof lightHighlightColors[style]).toBe("string");
}
})
});
it('has valid hex color values', () => {
it("has valid hex color values", () => {
for (const style of allStyles) {
expect(lightHighlightColors[style]).toMatch(/^#[0-9a-fA-F]{6}$/)
expect(lightHighlightColors[style]).toMatch(/^#[0-9a-fA-F]{6}$/);
}
})
})
});
});
describe('color map completeness', () => {
it('dark and light maps have the same keys', () => {
const darkKeys = Object.keys(darkHighlightColors).sort()
const lightKeys = Object.keys(lightHighlightColors).sort()
describe("color map completeness", () => {
it("dark and light maps have the same keys", () => {
const darkKeys = Object.keys(darkHighlightColors).sort();
const lightKeys = Object.keys(lightHighlightColors).sort();
expect(darkKeys).toEqual(lightKeys)
})
})
expect(darkKeys).toEqual(lightKeys);
});
});
@@ -1,125 +1,125 @@
import { describe, it, expect } from 'vitest'
import { highlightCode, highlightLine } from '../highlighter.js'
import { describe, it, expect } from "vitest";
import { highlightCode, highlightLine } from "../highlighter.js";
describe('highlightCode', () => {
it('highlights JavaScript code with correct token styles', () => {
const code = 'const x = 42;'
const result = highlightCode(code, 'test.js')
describe("highlightCode", () => {
it("highlights JavaScript code with correct token styles", () => {
const code = "const x = 42;";
const result = highlightCode(code, "test.js");
expect(result).toHaveLength(1)
const tokens = result[0]
expect(tokens.length).toBeGreaterThan(1)
expect(result).toHaveLength(1);
const tokens = result[0];
expect(tokens.length).toBeGreaterThan(1);
const keywordToken = tokens.find((t) => t.text === 'const')
expect(keywordToken?.style).toBe('keyword')
const keywordToken = tokens.find((t) => t.text === "const");
expect(keywordToken?.style).toBe("keyword");
const numberToken = tokens.find((t) => t.text === '42')
expect(numberToken?.style).toBe('number')
})
const numberToken = tokens.find((t) => t.text === "42");
expect(numberToken?.style).toBe("number");
});
it('highlights Python code', () => {
const code = 'def hello():\n print("world")'
const result = highlightCode(code, 'test.py')
it("highlights Python code", () => {
const code = 'def hello():\n print("world")';
const result = highlightCode(code, "test.py");
expect(result).toHaveLength(2)
expect(result).toHaveLength(2);
const defToken = result[0].find((t) => t.text === 'def')
expect(defToken?.style).toBe('keyword')
const defToken = result[0].find((t) => t.text === "def");
expect(defToken?.style).toBe("keyword");
const stringToken = result[1].find((t) => t.text.includes('world'))
expect(stringToken?.style).toBe('string')
})
const stringToken = result[1].find((t) => t.text.includes("world"));
expect(stringToken?.style).toBe("string");
});
it('highlights TSX code with correct dialect', () => {
const code = 'const el = <div className="test">hello</div>;'
const result = highlightCode(code, 'test.tsx')
it("highlights TSX code with correct dialect", () => {
const code = 'const el = <div className="test">hello</div>;';
const result = highlightCode(code, "test.tsx");
expect(result).toHaveLength(1)
const tokens = result[0]
expect(result).toHaveLength(1);
const tokens = result[0];
const constToken = tokens.find((t) => t.text === 'const')
expect(constToken?.style).toBe('keyword')
const constToken = tokens.find((t) => t.text === "const");
expect(constToken?.style).toBe("keyword");
const tagToken = tokens.find((t) => t.text === 'div')
expect(tagToken).toBeDefined()
})
const tagToken = tokens.find((t) => t.text === "div");
expect(tagToken).toBeDefined();
});
it('returns unhighlighted tokens for unsupported extensions', () => {
const code = 'hello world\nsecond line'
const result = highlightCode(code, 'test.xyz')
it("returns unhighlighted tokens for unsupported extensions", () => {
const code = "hello world\nsecond line";
const result = highlightCode(code, "test.xyz");
expect(result).toHaveLength(2)
expect(result[0]).toEqual([{ text: 'hello world', style: null }])
expect(result[1]).toEqual([{ text: 'second line', style: null }])
})
expect(result).toHaveLength(2);
expect(result[0]).toEqual([{ text: "hello world", style: null }]);
expect(result[1]).toEqual([{ text: "second line", style: null }]);
});
it('splits multi-line code into separate line arrays', () => {
const code = 'line1\nline2\nline3'
const result = highlightCode(code, 'test.txt')
it("splits multi-line code into separate line arrays", () => {
const code = "line1\nline2\nline3";
const result = highlightCode(code, "test.txt");
expect(result).toHaveLength(3)
})
expect(result).toHaveLength(3);
});
it('handles empty lines', () => {
const code = 'const a = 1;\n\nconst b = 2;'
const result = highlightCode(code, 'test.js')
it("handles empty lines", () => {
const code = "const a = 1;\n\nconst b = 2;";
const result = highlightCode(code, "test.js");
expect(result).toHaveLength(3)
expect(result[1]).toEqual([{ text: '', style: null }])
})
expect(result).toHaveLength(3);
expect(result[1]).toEqual([{ text: "", style: null }]);
});
it('returns a single empty line for empty input', () => {
expect(highlightCode('', 'test.ts')).toEqual([[{ text: '', style: null }]])
})
it("returns a single empty line for empty input", () => {
expect(highlightCode("", "test.ts")).toEqual([[{ text: "", style: null }]]);
});
it('returns valid HighlightStyle values for all tokens', () => {
it("returns valid HighlightStyle values for all tokens", () => {
const validStyles = new Set([
'keyword',
'comment',
'string',
'number',
'literal',
'function',
'definition',
'class',
'type',
'tag',
'attribute',
'property',
'variable',
'operator',
'punctuation',
'regexp',
'escape',
'meta',
'heading',
'link',
"keyword",
"comment",
"string",
"number",
"literal",
"function",
"definition",
"class",
"type",
"tag",
"attribute",
"property",
"variable",
"operator",
"punctuation",
"regexp",
"escape",
"meta",
"heading",
"link",
null,
])
]);
const code = '// comment\nconst x: number = 42;\nfunction foo() { return "bar"; }'
const result = highlightCode(code, 'test.ts')
const code = '// comment\nconst x: number = 42;\nfunction foo() { return "bar"; }';
const result = highlightCode(code, "test.ts");
for (const line of result) {
for (const token of line) {
expect(validStyles.has(token.style)).toBe(true)
expect(validStyles.has(token.style)).toBe(true);
}
}
})
})
});
});
describe('highlightLine', () => {
it('highlights a single line', () => {
const tokens = highlightLine('const x = 1;', 'test.js')
describe("highlightLine", () => {
it("highlights a single line", () => {
const tokens = highlightLine("const x = 1;", "test.js");
expect(tokens.length).toBeGreaterThan(1)
const keywordToken = tokens.find((t) => t.text === 'const')
expect(keywordToken?.style).toBe('keyword')
})
expect(tokens.length).toBeGreaterThan(1);
const keywordToken = tokens.find((t) => t.text === "const");
expect(keywordToken?.style).toBe("keyword");
});
it('returns unhighlighted token for unsupported files', () => {
const tokens = highlightLine('hello', 'test.xyz')
it("returns unhighlighted token for unsupported files", () => {
const tokens = highlightLine("hello", "test.xyz");
expect(tokens).toEqual([{ text: 'hello', style: null }])
})
})
expect(tokens).toEqual([{ text: "hello", style: null }]);
});
});
@@ -1,74 +1,74 @@
import { describe, it, expect } from 'vitest'
import { isLanguageSupported, getSupportedExtensions, getParserForFile } from '../parsers.js'
import { describe, it, expect } from "vitest";
import { isLanguageSupported, getSupportedExtensions, getParserForFile } from "../parsers.js";
describe('isLanguageSupported', () => {
it('returns true for supported file extensions', () => {
expect(isLanguageSupported('test.js')).toBe(true)
expect(isLanguageSupported('test.ts')).toBe(true)
expect(isLanguageSupported('test.tsx')).toBe(true)
expect(isLanguageSupported('test.py')).toBe(true)
expect(isLanguageSupported('test.go')).toBe(true)
expect(isLanguageSupported('test.rs')).toBe(true)
expect(isLanguageSupported('test.json')).toBe(true)
expect(isLanguageSupported('test.css')).toBe(true)
expect(isLanguageSupported('test.html')).toBe(true)
expect(isLanguageSupported('test.java')).toBe(true)
expect(isLanguageSupported('test.ex')).toBe(true)
})
describe("isLanguageSupported", () => {
it("returns true for supported file extensions", () => {
expect(isLanguageSupported("test.js")).toBe(true);
expect(isLanguageSupported("test.ts")).toBe(true);
expect(isLanguageSupported("test.tsx")).toBe(true);
expect(isLanguageSupported("test.py")).toBe(true);
expect(isLanguageSupported("test.go")).toBe(true);
expect(isLanguageSupported("test.rs")).toBe(true);
expect(isLanguageSupported("test.json")).toBe(true);
expect(isLanguageSupported("test.css")).toBe(true);
expect(isLanguageSupported("test.html")).toBe(true);
expect(isLanguageSupported("test.java")).toBe(true);
expect(isLanguageSupported("test.ex")).toBe(true);
});
it('returns false for unsupported file extensions', () => {
expect(isLanguageSupported('test.xyz')).toBe(false)
expect(isLanguageSupported('test.txt')).toBe(false)
expect(isLanguageSupported('test.csv')).toBe(false)
})
it("returns false for unsupported file extensions", () => {
expect(isLanguageSupported("test.xyz")).toBe(false);
expect(isLanguageSupported("test.txt")).toBe(false);
expect(isLanguageSupported("test.csv")).toBe(false);
});
it('returns false for files without extensions', () => {
expect(isLanguageSupported('Makefile')).toBe(false)
})
it("returns false for files without extensions", () => {
expect(isLanguageSupported("Makefile")).toBe(false);
});
it('handles nested paths', () => {
expect(isLanguageSupported('src/utils/test.ts')).toBe(true)
expect(isLanguageSupported('deep/nested/path/file.py')).toBe(true)
})
})
it("handles nested paths", () => {
expect(isLanguageSupported("src/utils/test.ts")).toBe(true);
expect(isLanguageSupported("deep/nested/path/file.py")).toBe(true);
});
});
describe('getSupportedExtensions', () => {
it('returns an array of extension strings', () => {
const extensions = getSupportedExtensions()
describe("getSupportedExtensions", () => {
it("returns an array of extension strings", () => {
const extensions = getSupportedExtensions();
expect(Array.isArray(extensions)).toBe(true)
expect(extensions.length).toBeGreaterThan(0)
})
expect(Array.isArray(extensions)).toBe(true);
expect(extensions.length).toBeGreaterThan(0);
});
it('includes common extensions', () => {
const extensions = getSupportedExtensions()
it("includes common extensions", () => {
const extensions = getSupportedExtensions();
expect(extensions).toContain('js')
expect(extensions).toContain('ts')
expect(extensions).toContain('tsx')
expect(extensions).toContain('py')
expect(extensions).toContain('go')
expect(extensions).toContain('rs')
expect(extensions).toContain('json')
})
})
expect(extensions).toContain("js");
expect(extensions).toContain("ts");
expect(extensions).toContain("tsx");
expect(extensions).toContain("py");
expect(extensions).toContain("go");
expect(extensions).toContain("rs");
expect(extensions).toContain("json");
});
});
describe('getParserForFile', () => {
it('returns a parser for supported files', () => {
expect(getParserForFile('test.js')).not.toBeNull()
expect(getParserForFile('test.py')).not.toBeNull()
})
describe("getParserForFile", () => {
it("returns a parser for supported files", () => {
expect(getParserForFile("test.js")).not.toBeNull();
expect(getParserForFile("test.py")).not.toBeNull();
});
it('returns null for unsupported files', () => {
expect(getParserForFile('test.xyz')).toBeNull()
})
it("returns null for unsupported files", () => {
expect(getParserForFile("test.xyz")).toBeNull();
});
it('returns null for files without extension', () => {
expect(getParserForFile('noext')).toBeNull()
})
it("returns null for files without extension", () => {
expect(getParserForFile("noext")).toBeNull();
});
it('is case-insensitive for extensions', () => {
expect(getParserForFile('test.JS')).not.toBeNull()
expect(getParserForFile('test.Py')).not.toBeNull()
})
})
it("is case-insensitive for extensions", () => {
expect(getParserForFile("test.JS")).not.toBeNull();
expect(getParserForFile("test.Py")).not.toBeNull();
});
});