|
| 1 | +// Flat ESLint config for the playground's browser-side JavaScript. |
| 2 | +// |
| 3 | +// These files run in the browser (no bundler, no module system) and lean on a |
| 4 | +// handful of globals provided by the page or by third-party scripts loaded via |
| 5 | +// <script> tags (xterm.js, the WASI shim) and by build-generated files |
| 6 | +// (/wasm/commands.js, /wasm/version.js). They are declared below so that |
| 7 | +// no-undef stays useful without flagging those. |
| 8 | +// |
| 9 | +// Run locally with: npm run lint (or: npx eslint static/js) |
| 10 | +import js from "@eslint/js"; |
| 11 | + |
| 12 | +export default [ |
| 13 | + js.configs.recommended, |
| 14 | + { |
| 15 | + // Shared settings for every playground script. |
| 16 | + files: ["static/js/**/*.js"], |
| 17 | + languageOptions: { |
| 18 | + ecmaVersion: 2022, |
| 19 | + sourceType: "script", |
| 20 | + globals: { |
| 21 | + // Browser environment |
| 22 | + window: "readonly", |
| 23 | + document: "readonly", |
| 24 | + navigator: "readonly", |
| 25 | + location: "readonly", |
| 26 | + console: "readonly", |
| 27 | + fetch: "readonly", |
| 28 | + setTimeout: "readonly", |
| 29 | + clearTimeout: "readonly", |
| 30 | + URL: "readonly", |
| 31 | + URLSearchParams: "readonly", |
| 32 | + CustomEvent: "readonly", |
| 33 | + TextEncoder: "readonly", |
| 34 | + TextDecoder: "readonly", |
| 35 | + WebAssembly: "readonly", |
| 36 | + SharedArrayBuffer: "readonly", |
| 37 | + // Third-party globals loaded via <script> on the playground page |
| 38 | + Terminal: "readonly", |
| 39 | + FitAddon: "readonly", |
| 40 | + WebLinksAddon: "readonly", |
| 41 | + // Generated at build time and injected before these scripts: command |
| 42 | + // list from /wasm/commands.js, locale and version strings from |
| 43 | + // /wasm/version.js. Absent in local dev (the code guards with typeof). |
| 44 | + WASM_COMMANDS: "readonly", |
| 45 | + WASM_LOCALES: "readonly", |
| 46 | + UUTILS_WASM_VERSION: "readonly", |
| 47 | + UUTILS_GREP_VERSION: "readonly", |
| 48 | + UUTILS_FINDUTILS_VERSION: "readonly", |
| 49 | + UUTILS_DIFFUTILS_VERSION: "readonly", |
| 50 | + UUTILS_SED_VERSION: "readonly", |
| 51 | + SITE_VERSION: "readonly", |
| 52 | + }, |
| 53 | + }, |
| 54 | + rules: { |
| 55 | + "no-unused-vars": ["error", { argsIgnorePattern: "^_" }], |
| 56 | + }, |
| 57 | + }, |
| 58 | + { |
| 59 | + // playground.js drives the page and calls into the terminal API that |
| 60 | + // wasm-terminal.js exposes on `window` (loaded as a separate <script>). |
| 61 | + // These live here rather than in the shared block so they don't clash with |
| 62 | + // their own definitions in wasm-terminal.js (no-redeclare). |
| 63 | + files: ["static/js/playground.js"], |
| 64 | + languageOptions: { |
| 65 | + globals: { |
| 66 | + initPlayground: "readonly", |
| 67 | + runInTerminal: "readonly", |
| 68 | + loadProgram: "readonly", |
| 69 | + isProgramLoaded: "readonly", |
| 70 | + programSize: "readonly", |
| 71 | + uutilsPrograms: "readonly", |
| 72 | + getLastCommand: "readonly", |
| 73 | + setLocale: "readonly", |
| 74 | + uutilsExecute: "readonly", |
| 75 | + }, |
| 76 | + }, |
| 77 | + }, |
| 78 | +]; |
0 commit comments