strip stylelint warnings for // comments with @preprocessor
This commit is contained in:
parent
a81e1b8ac3
commit
6d7bd650e9
|
@ -10,9 +10,11 @@ workerUtil.createAPI({
|
||||||
return CSSLint.verify(code, config).messages
|
return CSSLint.verify(code, config).messages
|
||||||
.map(m => Object.assign(m, {rule: {id: m.rule.id}}));
|
.map(m => Object.assign(m, {rule: {id: m.rule.id}}));
|
||||||
},
|
},
|
||||||
stylelint: (code, config) => {
|
stylelint: async (code, config) => {
|
||||||
loadScript('/vendor/stylelint-bundle/stylelint-bundle.min.js');
|
loadScript('/vendor/stylelint-bundle/stylelint-bundle.min.js');
|
||||||
return require('stylelint').lint({code, config});
|
const {results: [res]} = await require('stylelint').lint({code, config});
|
||||||
|
delete res._postcssResult; // huge and unused
|
||||||
|
return res;
|
||||||
},
|
},
|
||||||
metalint: code => {
|
metalint: code => {
|
||||||
loadScript(
|
loadScript(
|
||||||
|
|
|
@ -20,19 +20,31 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function stylelint(text, config) {
|
async function stylelint(text, config, mode) {
|
||||||
return editorWorker.stylelint(text, config)
|
const raw = await editorWorker.stylelint(text, config);
|
||||||
.then(({results}) => !results[0] ? [] :
|
if (!raw) {
|
||||||
results[0].warnings.map(({line, column: ch, text, severity}) => ({
|
return [];
|
||||||
from: {line: line - 1, ch: ch - 1},
|
}
|
||||||
to: {line: line - 1, ch},
|
// Hiding the errors about "//" comments as we're preprocessing only when saving/applying
|
||||||
message: text
|
// and we can't just pre-remove the comments since "//" may be inside a string token or whatever
|
||||||
.replace('Unexpected ', '')
|
const slashCommentAllowed = mode === 'text/x-less' || mode === 'stylus';
|
||||||
.replace(/^./, firstLetter => firstLetter.toUpperCase())
|
const res = [];
|
||||||
.replace(/\s*\([^(]+\)$/, ''), // strip the rule,
|
for (const w of raw.warnings) {
|
||||||
rule: text.replace(/^.*?\s*\(([^(]+)\)$/, '$1'),
|
const msg = w.text.match(/^(?:Unexpected\s+)?(.*?)\s*\([^()]+\)$|$/)[1] || w.text;
|
||||||
severity,
|
if (!slashCommentAllowed || !(
|
||||||
})));
|
w.rule === 'no-invalid-double-slash-comments' ||
|
||||||
|
w.rule === 'property-no-unknown' && msg.includes('"//"')
|
||||||
|
)) {
|
||||||
|
res.push({
|
||||||
|
from: {line: w.line - 1, ch: w.column - 1},
|
||||||
|
to: {line: w.line - 1, ch: w.column},
|
||||||
|
message: msg.slice(0, 1).toUpperCase() + msg.slice(1),
|
||||||
|
severity: w.severity,
|
||||||
|
rule: w.rule,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
function csslint(text, config) {
|
function csslint(text, config) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user