use $element in showLintHelp
This commit is contained in:
parent
76eb3f7e28
commit
81e6720341
55
edit/lint.js
55
edit/lint.js
|
@ -299,37 +299,50 @@ function toggleLintReport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function showLintHelp() {
|
function showLintHelp() {
|
||||||
const makeLink = (url, txt) => `<a target="_blank" href="${url}">${txt}</a>`;
|
const makeLink = (href, textContent) => $element({
|
||||||
|
tag: 'a',
|
||||||
|
target: '_blank',
|
||||||
|
href,
|
||||||
|
textContent,
|
||||||
|
});
|
||||||
const linter = prefs.get('editor.linter');
|
const linter = prefs.get('editor.linter');
|
||||||
const url = 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
|
// some CSSLint rules do not have a url
|
||||||
: 'https://github.com/CSSLint/csslint/issues/535';
|
: 'https://github.com/CSSLint/csslint/issues/535';
|
||||||
const rules = [];
|
let headerLink, template;
|
||||||
let template;
|
|
||||||
let list = '<ul class="rules">';
|
|
||||||
let header = '';
|
|
||||||
if (linter === 'csslint') {
|
if (linter === 'csslint') {
|
||||||
const CSSLintRules = CSSLint.getRules();
|
const CSSLintRules = CSSLint.getRules();
|
||||||
const findCSSLintRule = id => CSSLintRules.find(rule => rule.id === id);
|
headerLink = makeLink('https://github.com/CSSLint/csslint/wiki/Rules-by-ID', 'CSSLint');
|
||||||
header = t('linterIssuesHelp', makeLink('https://github.com/CSSLint/csslint/wiki/Rules-by-ID', 'CSSLint'));
|
|
||||||
template = ruleID => {
|
template = ruleID => {
|
||||||
const rule = findCSSLintRule(ruleID);
|
const rule = CSSLintRules.find(rule => rule.id === ruleID);
|
||||||
return rule ? `<li><b>${makeLink(rule.url || url, rule.name)}</b><br>${rule.desc}</li>` : '';
|
return rule &&
|
||||||
|
$element({tag: 'li', appendChild: [
|
||||||
|
$element({tag: 'b', appendChild: makeLink(rule.url || baseUrl, rule.name)}),
|
||||||
|
$element({tag: 'br'}),
|
||||||
|
rule.desc,
|
||||||
|
]});
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
header = t('linterIssuesHelp', makeLink(url, 'stylelint'));
|
headerLink = makeLink(baseUrl, 'stylelint');
|
||||||
template = rule => `<li>${makeLink(url + rule, rule)}</li>`;
|
template = rule =>
|
||||||
}
|
$element({
|
||||||
// Only show rules with issues in the popup
|
tag: 'li',
|
||||||
$$('#lint td[role="severity"]').forEach(el => {
|
appendChild: makeLink(baseUrl + rule, rule),
|
||||||
const rule = el.dataset.rule;
|
|
||||||
if (!rules.includes(rule)) {
|
|
||||||
list += template(rule);
|
|
||||||
rules.push(rule);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return showHelp(t('linterIssues'), header + list + '</ul>');
|
}
|
||||||
|
const header = t('linterIssuesHelp', '\x01').split('\x01');
|
||||||
|
const activeRules = new Set($$('#lint td[role="severity"]').map(el => el.dataset.rule));
|
||||||
|
return showHelp(t('linterIssues'),
|
||||||
|
$element({appendChild: [
|
||||||
|
header[0], headerLink, header[1],
|
||||||
|
$element({
|
||||||
|
tag: 'ul',
|
||||||
|
className: 'rules',
|
||||||
|
appendChild: [...activeRules.values()].map(template),
|
||||||
|
}),
|
||||||
|
]})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showLinterErrorMessage(title, contents) {
|
function showLinterErrorMessage(title, contents) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user