Skip to content

Commit a749897

Browse files
committed
refactor(fmt): use prettier all the way
1 parent b33cdf7 commit a749897

File tree

18 files changed

+1074
-565
lines changed

18 files changed

+1074
-565
lines changed

astro.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { defineConfig } from 'astro/config';
1+
import { defineConfig } from "astro/config";
22

33
export default defineConfig({
44
vite: {
55
// Ensure Tone.js works correctly with Vite bundling
66
optimizeDeps: {
7-
include: ['tone'],
7+
include: ["tone"],
88
},
99
},
1010
});

bun.lock

Lines changed: 412 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"dependencies": {
3+
"@astrojs/check": "^0.9.6",
34
"@codemirror/lang-javascript": "^6.2.4",
45
"@codemirror/lang-python": "^6.2.1",
56
"@codemirror/lang-rust": "^6.0.2",
@@ -20,12 +21,19 @@
2021
"build": "astro build",
2122
"preview": "astro preview",
2223
"astro": "astro",
24+
"check": "astro check",
2325
"format": "prettier --write --plugin-search-dir=. ."
2426
},
2527
"devDependencies": {
26-
"@types/bun": "latest"
28+
"@types/bun": "latest",
29+
"@typescript-eslint/eslint-plugin": "^8.54.0",
30+
"@typescript-eslint/parser": "^8.54.0",
31+
"eslint": "^9.39.2",
32+
"eslint-plugin-astro": "^1.5.0",
33+
"prettier": "^3.8.1",
34+
"prettier-plugin-astro": "^0.14.1"
2735
},
2836
"peerDependencies": {
29-
"typescript": "^5"
37+
"typescript": "^5.9.3"
3038
}
3139
}

src/scripts/editor.ts

Lines changed: 92 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
1-
import { EditorView, keymap, lineNumbers, highlightActiveLine, highlightActiveLineGutter } from '@codemirror/view';
2-
import { EditorState, Compartment } from '@codemirror/state';
3-
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
4-
import { bracketMatching, indentOnInput, foldGutter, foldKeymap } from '@codemirror/language';
5-
import { closeBrackets, closeBracketsKeymap } from '@codemirror/autocomplete';
6-
import { vim, Vim } from '@replit/codemirror-vim';
7-
8-
import { themeRegistry, getTheme, getDefaultTheme, type McTheme } from './themes/index';
9-
import { languageRegistry, getLanguage, detectPattern, type McLanguage } from './languages/index';
10-
import { getPreset } from './presets/index';
11-
import { initAudio, setMusicConfig, playKeySound, playBackspace, playMelodyNote, playPatternSound, isAudioInitialized, setVolume, getVolume } from './music';
1+
import {
2+
EditorView,
3+
keymap,
4+
lineNumbers,
5+
highlightActiveLine,
6+
highlightActiveLineGutter,
7+
} from "@codemirror/view";
8+
import { EditorState, Compartment } from "@codemirror/state";
9+
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
10+
import {
11+
bracketMatching,
12+
indentOnInput,
13+
foldGutter,
14+
foldKeymap,
15+
} from "@codemirror/language";
16+
import { closeBrackets, closeBracketsKeymap } from "@codemirror/autocomplete";
17+
import { vim, Vim } from "@replit/codemirror-vim";
18+
19+
import {
20+
themeRegistry,
21+
getTheme,
22+
getDefaultTheme,
23+
type McTheme,
24+
} from "./themes/index";
25+
import {
26+
languageRegistry,
27+
getLanguage,
28+
detectPattern,
29+
type McLanguage,
30+
} from "./languages/index";
31+
import { getPreset } from "./presets/index";
32+
import {
33+
initAudio,
34+
setMusicConfig,
35+
playKeySound,
36+
playBackspace,
37+
playMelodyNote,
38+
playPatternSound,
39+
isAudioInitialized,
40+
setVolume,
41+
getVolume,
42+
} from "./music";
1243

1344
let editorView: EditorView | null = null;
1445
let currentTheme: McTheme;
@@ -19,20 +50,20 @@ const themeCompartment = new Compartment();
1950
const languageCompartment = new Compartment();
2051
const vimCompartment = new Compartment();
2152

22-
let lastCode = '';
53+
let lastCode = "";
2354
let keystrokeCount = 0;
2455

2556
// Language to filename mapping
2657
const languageFileNames: Record<string, string> = {
27-
javascript: 'main.js',
28-
python: 'main.py',
29-
rust: 'main.rs',
30-
zig: 'main.zig',
58+
javascript: "main.js",
59+
python: "main.py",
60+
rust: "main.rs",
61+
zig: "main.zig",
3162
};
3263

3364
export async function initEditor(container: HTMLElement): Promise<EditorView> {
3465
// Set defaults based on system preference
35-
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
66+
const isDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
3667
currentTheme = getDefaultTheme(isDark);
3768
currentLanguage = languageRegistry[0];
3869

@@ -72,7 +103,7 @@ export async function initEditor(container: HTMLElement): Promise<EditorView> {
72103
handleKeystroke(event.key);
73104

74105
// Enable vim mode with Ctrl + [
75-
if (!vimEnabled && event.key === '[' && event.ctrlKey) {
106+
if (!vimEnabled && event.key === "[" && event.ctrlKey) {
76107
event.preventDefault();
77108
enableVim();
78109
}
@@ -91,7 +122,7 @@ export async function initEditor(container: HTMLElement): Promise<EditorView> {
91122

92123
// Initialize statusline
93124
updateStatuslineFile(currentLanguage.id, currentLanguage.name);
94-
updateStatuslineMode('edit');
125+
updateStatuslineMode("edit");
95126
updateStatuslinePosition(editorView);
96127

97128
// Set up vim mode change listener
@@ -102,27 +133,27 @@ export async function initEditor(container: HTMLElement): Promise<EditorView> {
102133

103134
function applyThemeColors(theme: McTheme): void {
104135
const root = document.documentElement;
105-
root.style.setProperty('--bg-primary', theme.colors.bgPrimary);
106-
root.style.setProperty('--bg-secondary', theme.colors.bgSecondary);
107-
root.style.setProperty('--text-primary', theme.colors.textPrimary);
108-
root.style.setProperty('--text-secondary', theme.colors.textSecondary);
109-
root.style.setProperty('--accent', theme.colors.accent);
110-
root.style.setProperty('--border', theme.colors.border);
136+
root.style.setProperty("--bg-primary", theme.colors.bgPrimary);
137+
root.style.setProperty("--bg-secondary", theme.colors.bgSecondary);
138+
root.style.setProperty("--text-primary", theme.colors.textPrimary);
139+
root.style.setProperty("--text-secondary", theme.colors.textSecondary);
140+
root.style.setProperty("--accent", theme.colors.accent);
141+
root.style.setProperty("--border", theme.colors.border);
111142
}
112143

113144
async function handleKeystroke(key: string): Promise<void> {
114145
if (!isAudioInitialized()) {
115146
await initAudio();
116147
setMusicConfig(currentTheme.music);
117148
// Update audio indicator
118-
const indicator = document.getElementById('audio-indicator');
149+
const indicator = document.getElementById("audio-indicator");
119150
if (indicator) {
120-
indicator.classList.add('active');
121-
indicator.title = 'Audio active';
151+
indicator.classList.add("active");
152+
indicator.title = "Audio active";
122153
}
123154
}
124155

125-
const isBackspace = key === 'Backspace' || key === 'Delete';
156+
const isBackspace = key === "Backspace" || key === "Delete";
126157

127158
if (isBackspace) {
128159
playBackspace();
@@ -151,7 +182,11 @@ function handleCodeChange(code: string): void {
151182
hasConditional: patterns.hasConditional && !lastPatterns.hasConditional,
152183
};
153184

154-
if (newPatterns.hasFunction || newPatterns.hasLoop || newPatterns.hasConditional) {
185+
if (
186+
newPatterns.hasFunction ||
187+
newPatterns.hasLoop ||
188+
newPatterns.hasConditional
189+
) {
155190
playPatternSound(newPatterns);
156191
}
157192

@@ -207,7 +242,7 @@ export function toggleVim(): boolean {
207242
});
208243

209244
// Update statusline mode
210-
updateStatuslineMode(vimEnabled ? 'normal' : 'edit');
245+
updateStatuslineMode(vimEnabled ? "normal" : "edit");
211246

212247
return vimEnabled;
213248
}
@@ -221,13 +256,13 @@ function enableVim(): void {
221256
});
222257

223258
// Update statusline mode
224-
updateStatuslineMode('normal');
259+
updateStatuslineMode("normal");
225260

226261
// Sync the toggle button in settings
227-
const vimToggle = document.getElementById('vim-toggle');
262+
const vimToggle = document.getElementById("vim-toggle");
228263
if (vimToggle) {
229-
vimToggle.setAttribute('aria-pressed', 'true');
230-
vimToggle.classList.add('active');
264+
vimToggle.setAttribute("aria-pressed", "true");
265+
vimToggle.classList.add("active");
231266
}
232267
}
233268

@@ -253,36 +288,42 @@ function updateStatuslinePosition(view: EditorView): void {
253288
const line = view.state.doc.lineAt(pos);
254289
const col = pos - line.from + 1;
255290

256-
const positionEl = document.getElementById('statusline-position');
291+
const positionEl = document.getElementById("statusline-position");
257292
if (positionEl) {
258293
positionEl.textContent = `${line.number}:${col}`;
259294
}
260295
}
261296

262297
export function updateStatuslineMode(mode: string): void {
263-
const modeEl = document.getElementById('statusline-mode');
298+
const modeEl = document.getElementById("statusline-mode");
264299
if (!modeEl) return;
265300

266301
// Remove all mode classes
267-
modeEl.classList.remove('mode-normal', 'mode-insert', 'mode-edit');
302+
modeEl.classList.remove("mode-normal", "mode-insert", "mode-edit");
268303

269304
// Only normal and insert modes supported
270305
const modeMap: Record<string, { class: string; text: string }> = {
271-
normal: { class: 'mode-normal', text: 'NORMAL' },
272-
insert: { class: 'mode-insert', text: 'INSERT' },
306+
normal: { class: "mode-normal", text: "NORMAL" },
307+
insert: { class: "mode-insert", text: "INSERT" },
273308
};
274309

275-
const modeInfo = modeMap[mode.toLowerCase()] || { class: 'mode-edit', text: mode.toUpperCase() };
310+
const modeInfo = modeMap[mode.toLowerCase()] || {
311+
class: "mode-edit",
312+
text: mode.toUpperCase(),
313+
};
276314
modeEl.classList.add(modeInfo.class);
277315
modeEl.textContent = modeInfo.text;
278316
}
279317

280-
export function updateStatuslineFile(languageId: string, languageName: string): void {
318+
export function updateStatuslineFile(
319+
languageId: string,
320+
languageName: string,
321+
): void {
281322
const fileName = languageFileNames[languageId] || `main.${languageId}`;
282323

283-
const bufferNameEl = document.getElementById('buffer-name');
284-
const fileEl = document.getElementById('statusline-file');
285-
const langEl = document.getElementById('statusline-language');
324+
const bufferNameEl = document.getElementById("buffer-name");
325+
const fileEl = document.getElementById("statusline-file");
326+
const langEl = document.getElementById("statusline-language");
286327

287328
if (bufferNameEl) bufferNameEl.textContent = fileName;
288329
if (fileEl) fileEl.textContent = fileName;
@@ -300,13 +341,13 @@ function setupVimModeListener(): void {
300341
vimListenerSetup = true;
301342

302343
// Disable visual, replace, and command modes - keep only normal and insert
303-
Vim.unmap('v', 'normal');
304-
Vim.unmap('V', 'normal');
305-
Vim.unmap('<C-v>', 'normal');
306-
Vim.unmap('R', 'normal');
307-
Vim.unmap(':', 'normal');
344+
Vim.unmap("v", "normal");
345+
Vim.unmap("V", "normal");
346+
Vim.unmap("<C-v>", "normal");
347+
Vim.unmap("R", "normal");
348+
Vim.unmap(":", "normal");
308349

309-
Vim.on('vim-mode-change', (e: { mode: string; subMode?: string }) => {
350+
Vim.on("vim-mode-change", (e: { mode: string; subMode?: string }) => {
310351
if (!vimEnabled) return;
311352
updateStatuslineMode(e.mode);
312353
});

src/scripts/languages/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Extension } from '@codemirror/state';
1+
import type { Extension } from "@codemirror/state";
22

33
export interface McLanguagePatterns {
44
function: RegExp;
@@ -22,10 +22,13 @@ export function registerLanguage(language: McLanguage): void {
2222
}
2323

2424
export function getLanguage(id: string): McLanguage | undefined {
25-
return languageRegistry.find(l => l.id === id);
25+
return languageRegistry.find((l) => l.id === id);
2626
}
2727

28-
export function detectPattern(code: string, language: McLanguage): {
28+
export function detectPattern(
29+
code: string,
30+
language: McLanguage,
31+
): {
2932
hasFunction: boolean;
3033
hasLoop: boolean;
3134
hasConditional: boolean;
@@ -42,11 +45,11 @@ export function detectPattern(code: string, language: McLanguage): {
4245
}
4346

4447
// Import and register languages
45-
import { javascriptLanguage } from './javascript';
46-
import { pythonLanguage } from './python';
47-
import { rustLanguage } from './rust';
48-
import { zigLanguage } from './zig';
49-
import { nixLanguage } from './nix';
48+
import { javascriptLanguage } from "./javascript";
49+
import { pythonLanguage } from "./python";
50+
import { rustLanguage } from "./rust";
51+
import { zigLanguage } from "./zig";
52+
import { nixLanguage } from "./nix";
5053

5154
registerLanguage(javascriptLanguage);
5255
registerLanguage(pythonLanguage);

src/scripts/languages/javascript.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import type { McLanguage } from './index';
1+
import type { McLanguage } from "./index";
22

33
export const javascriptLanguage: McLanguage = {
4-
id: 'javascript',
5-
name: 'JavaScript',
4+
id: "javascript",
5+
name: "JavaScript",
66
syntax: async () => {
7-
const { javascript } = await import('@codemirror/lang-javascript');
7+
const { javascript } = await import("@codemirror/lang-javascript");
88
return javascript({ jsx: true, typescript: true });
99
},
1010
patterns: {
11-
function: /\b(function|const\s+\w+\s*=\s*(?:async\s*)?\(|=>\s*{?|\bclass\b)/,
11+
function:
12+
/\b(function|const\s+\w+\s*=\s*(?:async\s*)?\(|=>\s*{?|\bclass\b)/,
1213
loop: /\b(for|while|do)\s*\(/,
1314
conditional: /\b(if|else|switch|case|\?.*:)/,
1415
string: /(['"`])(?:(?!\1)[^\\]|\\.)*\1/,

src/scripts/languages/nix.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type { McLanguage } from '.';
2-
1+
import type { McLanguage } from ".";
32

43
export const nixLanguage: McLanguage = {
5-
id: 'nix',
6-
name: 'Nix',
4+
id: "nix",
5+
name: "Nix",
76
syntax: async () => {
8-
const { nix } = await import('@replit/codemirror-lang-nix');
7+
const { nix } = await import("@replit/codemirror-lang-nix");
98
return nix();
109
},
1110
patterns: {
@@ -16,4 +15,3 @@ export const nixLanguage: McLanguage = {
1615
comment: /#.*$|\/\*[\s\S]*?\*\//m,
1716
},
1817
};
19-

src/scripts/languages/python.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { McLanguage } from './index';
1+
import type { McLanguage } from "./index";
22

33
export const pythonLanguage: McLanguage = {
4-
id: 'python',
5-
name: 'Python',
4+
id: "python",
5+
name: "Python",
66
syntax: async () => {
7-
const { python } = await import('@codemirror/lang-python');
7+
const { python } = await import("@codemirror/lang-python");
88
return python();
99
},
1010
patterns: {

0 commit comments

Comments
 (0)