import { defineConfig } from 'vite-plus' /** * Repo-wide toolchain config, ported from the submodule's own `vite.config.ts` so a contributor * moving between the two repositories meets the same ruleset. * * Lint only. There is deliberately no `run.tasks` block here: Vite+ creates a task for every * package from a workspace-root task definition, including the root package itself, and the root * has no sources for one to act on. Per-package tasks live in each package's own `vite.config.ts`. */ export default defineConfig({ check: { // The tree has never been formatted with oxfmt, so `vp check` would report every file. `vp fmt` // still works if invoked directly. fmt: false, }, lint: { categories: { correctness: 'error', suspicious: 'error', }, plugins: ['typescript', 'unicorn', 'oxc', 'import'], options: { // Type-aware linting is intentionally off, as upstream. `tsc` is what enforces type safety // here: `pnpm types:scripts` for the deploy tooling and `pnpm build` for the packages. typeAware: false, }, env: { es2024: true, }, rules: { // False positives: gatekeepers import `.txt` files as bundled text assets, which the import // resolver reports as "no default export". 'import/default': 'off', // Side-effect imports are used deliberately (the `cloudflare:workers` runtime registration). 'import/no-unassigned-import': 'off', // Comment-only reference modules are kept intentionally (`src/types.d.ts`). 'unicorn/no-empty-file': 'off', // Conflicts with the convention of prefixing intentionally-unused bindings with `_`. 'no-underscore-dangle': 'off', // Do not require churny `_` prefixes on unused callback/interface parameters or catch // bindings, but still flag unused imports and local variables. 'no-unused-vars': [ 'error', { args: 'none', caughtErrors: 'none', varsIgnorePattern: '^_', ignoreRestSiblings: true, }, ], // Genuine improvements, but churny for an initial rollout. Visible as warnings. 'no-shadow': 'warn', 'typescript/no-this-alias': 'warn', 'typescript/no-extraneous-class': 'warn', 'unicorn/consistent-function-scoping': 'warn', }, ignorePatterns: [ // The submodule lints itself, with its own config, its own plugins (including the local // `gadgets/prefer-jsdoc` rule this file does not load) and its own per-directory overrides. // Linting it from here would report findings nobody in this repository can fix. 'cloudflare-os/**', '**/dist/**', '**/generated/**', '**/*.gen.ts', '**/node_modules/**', '**/.wrangler/**', '**/worker-configuration.d.ts', ], overrides: [ { // Cloudflare Workers backends: worker/service-worker global scope. files: ['packages/*/src/**/*.ts'], env: { serviceworker: true, es2024: true, }, }, { files: ['**/*.test.ts', '**/vitest.config.ts', 'packages/*/__tests__/**/*.ts'], plugins: ['typescript', 'unicorn', 'oxc', 'import', 'vitest'], env: { vitest: true, es2024: true, }, }, { files: ['scripts/**/*.ts'], env: { node: true, es2024: true, }, }, { // `scripts/` tests run under `node --test`, not vitest, so they must not pick up the vitest // override above (which would supply vitest globals and drop `env: node`). Ordered last so // it wins over that entry. files: ['scripts/**/*.test.ts'], plugins: ['typescript', 'unicorn', 'oxc', 'import'], env: { node: true, es2024: true, }, }, ], }, })