/** * The linter earns its place on the rules a compiler will not give: the ones * about intent. Types belong to `tsc --strict` and `svelte-check`; formatting * belongs to nobody. * * Two house rules live here: * - CLAUDE.md §7 "never swallow an error": `no-empty` with no empty catch. * - CLAUDE.md §7 "the engine is pure — enforced by a lint rule": the block * scoped to packages/engine/src below. `packages/engine/test/purity-lint.test.ts` * proves each ban fires, because a guard only ever seen not firing is untested. */ import js from '@eslint/js'; import ts from 'typescript-eslint'; import svelte from 'eslint-plugin-svelte'; import svelteParser from 'svelte-eslint-parser'; import globals from 'globals'; const CLOCK = 'Time is a parameter (`now: number`). A clock in the engine makes replaying the event log non-deterministic.'; const DICE = 'Randomness is a parameter (`rng: () => number`) so a replay gives byte-identical derived state.'; const IO = 'The engine performs no I/O. It returns values; packages/storage, packages/sync and the app do the rest.'; const ZONE = 'The time zone is a parameter. The app reads the device zone; the engine never does.'; const UTC_DAY = 'That is the UTC day. Days come from engine/src/time/localDay.ts and nowhere else (CLAUDE.md §7).'; export default [ { ignores: [ '**/dist/**', '**/dist-tauri/**', 'apps/rosea-tauri/src-tauri/gen/**', 'apps/rosea-tauri/src-tauri/target/**', '**/node_modules/**', '**/.turbo/**', '**/generated/**', '**/playwright-report/**', '**/test-results/**', // Other sessions' git worktrees live under .claude/worktrees/: separate checkouts, // linted in their own place, never from here (with Rust build output inside). '.claude/**', '**/target/**', // Fabrica's records of `fabrica tests run` (git-ignored): its own reporter, not Rosea's code. '.fabrica/runs/**' ] }, js.configs.recommended, ...ts.configs.recommended, ...svelte.configs['flat/recommended'], { languageOptions: { ecmaVersion: 2023, sourceType: 'module', globals: { ...globals.browser, ...globals.node } }, rules: { 'no-empty': ['error', { allowEmptyCatch: false }], eqeqeq: ['error', 'always', { null: 'ignore' }], '@typescript-eslint/no-unused-vars': [ 'error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrors: 'none' } ] } }, { files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'], languageOptions: { parser: svelteParser, parserOptions: { parser: ts.parser }, // The build-time shell constant (apps/rosea/vite.config.ts), read in App.svelte only. globals: { __ROSEA_SHELL__: 'readonly' } } }, { // THE ENGINE IS PURE. Scoped to src/: tests may read clocks to build fixtures. files: ['packages/engine/src/**/*.ts'], rules: { 'no-restricted-globals': [ 'error', { name: 'fetch', message: IO }, { name: 'XMLHttpRequest', message: IO }, { name: 'WebSocket', message: IO }, { name: 'localStorage', message: IO }, { name: 'sessionStorage', message: IO }, { name: 'indexedDB', message: IO }, { name: 'document', message: IO }, { name: 'window', message: IO }, { name: 'globalThis', message: IO }, { name: 'navigator', message: IO }, { name: 'crypto', message: DICE }, { name: 'performance', message: CLOCK }, { name: 'setTimeout', message: CLOCK }, { name: 'setInterval', message: CLOCK }, { name: 'requestAnimationFrame', message: CLOCK }, { name: 'process', message: IO } ], 'no-restricted-properties': [ 'error', { object: 'Date', property: 'now', message: CLOCK }, { object: 'Math', property: 'random', message: DICE }, { property: 'resolvedOptions', message: ZONE } ], 'no-restricted-syntax': [ 'error', { selector: "NewExpression[callee.name='Date'][arguments.length=0]", message: CLOCK }, { selector: "CallExpression[callee.name='Date']", message: CLOCK }, { selector: "CallExpression[callee.property.name='slice'][callee.object.callee.property.name='toISOString']", message: UTC_DAY }, { selector: 'ImportDeclaration[source.value=/^node:/]', message: IO }, { selector: 'ImportExpression', message: IO } ] } }, { files: ['**/test/**', '**/*.test.ts', '**/*.spec.ts', 'scripts/**', 'e2e/**'], rules: { '@typescript-eslint/no-unused-expressions': 'off' } } ];