Skip to content

Commit 065e868

Browse files
johann-sonntagbauerCompuIves
authored andcommitted
fix vim mode switch (codesandbox#129)
* fix vim mode switch ugly hack to work around eslint dependency which redefines the require instance on window this breaks the monaco loader.js the following workaround can be removed after migration to monaco (vim mode) is done * fix eslint overriding window.require reference
1 parent 5dc3e9e commit 065e868

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/app/utils/codemirror/eslint-lint.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,15 @@ export function fix(source: string) {
354354
}
355355

356356
export default (async function initialize() {
357-
if (!window.eslint && linter === null) {
357+
// ugly hack to work around eslint dependency which redefines the require instance on window
358+
// this breaks the monaco loader.js
359+
// the following workaround can be removed after migration to monaco (vim mode) is done
360+
const origRequire = window.require;
361+
if (
362+
!window.eslint &&
363+
linter === null &&
364+
!document.querySelector("script[src='/static/js/eslint.4.1.0.min.js']")
365+
) {
358366
// Add eslint as script
359367
const script = document.createElement('script');
360368
const src = '/static/js/eslint.4.1.0.min.js';
@@ -369,6 +377,8 @@ export default (async function initialize() {
369377
await delay(100);
370378
}
371379

380+
window.require = origRequire;
381+
372382
linter = new window.eslint();
373383
linter.defineRules(allRules);
374384
CodeMirror.registerHelper('lint', 'javascript', validator);

0 commit comments

Comments
 (0)