fix showLintHelp dialog

This commit is contained in:
tophf 2021-02-07 00:17:52 +03:00
parent 94cf673f68
commit 1746235d0d

View File

@ -17,13 +17,10 @@
let popup; let popup;
linterMan.showLintConfig = async () => { linterMan.showLintConfig = async () => {
linter = $('#editor.linter').value; linter = await getLinter();
if (!linter) { if (!linter) {
return; return;
} }
if (!RULES[linter]) {
linterMan.worker.getRules(linter).then(res => (RULES[linter] = res));
}
await require([ await require([
'/vendor/codemirror/mode/javascript/javascript', '/vendor/codemirror/mode/javascript/javascript',
'/vendor/codemirror/addon/lint/json-lint', '/vendor/codemirror/addon/lint/json-lint',
@ -66,16 +63,14 @@
}; };
linterMan.showLintHelp = async () => { linterMan.showLintHelp = async () => {
// FIXME: implement a linterChooser? const linter = await getLinter();
const linter = $('#editor.linter').value;
const baseUrl = linter === 'stylelint' const baseUrl = linter === 'stylelint'
? 'https://stylelint.io/user-guide/rules/' ? 'https://stylelint.io/user-guide/rules/'
// some CSSLint rules do not have a url : '';
: 'https://github.com/CSSLint/csslint/issues/535';
let headerLink, template; let headerLink, template;
if (linter === 'csslint') { if (linter === 'csslint') {
headerLink = $createLink('https://github.com/CSSLint/csslint/wiki/Rules', 'CSSLint'); headerLink = $createLink('https://github.com/CSSLint/csslint/wiki/Rules', 'CSSLint');
template = ({rule: ruleID}) => { template = ruleID => {
const rule = RULES.csslint.find(rule => rule.id === ruleID); const rule = RULES.csslint.find(rule => rule.id === ruleID);
return rule && return rule &&
$create('li', [ $create('li', [
@ -107,6 +102,14 @@
return depth; return depth;
} }
async function getLinter() {
const val = $('#editor.linter').value;
if (val && !RULES[val]) {
RULES[val] = await linterMan.worker.getRules(val);
}
return val;
}
function hint(cm) { function hint(cm) {
const rules = RULES[linter]; const rules = RULES[linter];
let ruleIds, options; let ruleIds, options;