diff --git a/edit/lint-codemirror-helper.js b/edit/lint-codemirror-helper.js index 3959f11e..6106ca1c 100644 --- a/edit/lint-codemirror-helper.js +++ b/edit/lint-codemirror-helper.js @@ -2,7 +2,7 @@ 'use strict'; CodeMirror.registerHelper('lint', 'csslint', code => - window.CSSLint && CSSLint.verify(code, deepCopy(linterConfig.getCurrent('csslint'))) + CSSLint.verify(code, deepCopy(linterConfig.getCurrent('csslint'))) .messages.map(message => ({ from: CodeMirror.Pos(message.line - 1, message.col - 1), to: CodeMirror.Pos(message.line - 1, message.col), @@ -13,7 +13,7 @@ CodeMirror.registerHelper('lint', 'csslint', code => ); CodeMirror.registerHelper('lint', 'stylelint', code => - window.stylelint && stylelint.lint({ + stylelint.lint({ code, config: deepCopy(linterConfig.getCurrent('stylelint')), }).then(({results}) => { diff --git a/edit/lint.js b/edit/lint.js index 7a0893df..9be438f2 100644 --- a/edit/lint.js +++ b/edit/lint.js @@ -509,28 +509,37 @@ function setupLinterPopup(config) { } function loadLinterAssets(name = prefs.get('editor.linter')) { - const scripts = []; - if (name === 'csslint' && !window.CSSLint) { - scripts.push( - '/vendor-overwrites/csslint/csslint-worker.js', - '/edit/lint-defaults-csslint.js' - ); - } else if (name === 'stylelint' && !window.stylelint) { - scripts.push( - loadScript([ + if (!name) { + return Promise.resolve(); + } + return loadLibrary().then(loadAddon); + + function loadLibrary() { + if (name === 'csslint' && !window.CSSLint) { + return loadScript([ + '/vendor-overwrites/csslint/csslint-worker.js', + '/edit/lint-defaults-csslint.js' + ]); + } + if (name === 'stylelint' && !window.stylelint) { + return loadScript([ '/vendor-overwrites/stylelint/stylelint-bundle.min.js', '/edit/lint-defaults-stylelint.js' - ]).then(() => (window.stylelint = require('stylelint'))) - ); + ]).then(() => (window.stylelint = require('stylelint'))); + } + return Promise.resolve(); } - if (name && !$('script[src$="/vendor/codemirror/addon/lint/lint.js"]')) { - scripts.push( + + function loadAddon() { + if ($('script[src$="/vendor/codemirror/addon/lint/lint.js"]')) { + return Promise.resolve(); + } + return loadScript([ '/vendor/codemirror/addon/lint/lint.css', '/msgbox/msgbox.css', '/vendor/codemirror/addon/lint/lint.js', '/edit/lint-codemirror-helper.js', '/msgbox/msgbox.js' - ); + ]); } - return loadScript(scripts); }