Skip to content

Commit ba9c08e

Browse files
committed
add eslint config for the playground JavaScript
Flat config (eslint.config.mjs) plus a minimal package.json exposing an "npm run lint" script. Declares the browser, third-party (xterm) and build-generated globals the playground relies on so no-undef stays useful. node_modules is gitignored.
1 parent 1e41046 commit ba9c08e

4 files changed

Lines changed: 1105 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/public/
22
/static/syntax-*
33
/static/wasm/
4+
/node_modules/

eslint.config.mjs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)