stylelint 14.9.1

This commit is contained in:
tophf 2022-08-06 23:19:49 +03:00
parent 2d21bb1dd6
commit 7a5569e9d5
7 changed files with 1105 additions and 76 deletions

View File

@ -2,9 +2,7 @@
'use strict'; 'use strict';
(() => { (() => {
const hasCurlyBraceError = warning => let sugarss = false;
warning.text === 'Unnecessary curly bracket (CssSyntaxError)';
let sugarssFallback;
/** @namespace EditorWorker */ /** @namespace EditorWorker */
createWorkerApi({ createWorkerApi({
@ -65,26 +63,33 @@
}, },
async stylelint(opts) { async stylelint(opts) {
// Removing an unused API that spits a warning in Chrome console due to stylelint's isBuffer
delete self.SharedArrayBuffer;
require(['/vendor/stylelint-bundle/stylelint-bundle.min']); /* global stylelint */ require(['/vendor/stylelint-bundle/stylelint-bundle.min']); /* global stylelint */
try { // Stylus-lang allows a trailing ";" but sugarss doesn't, so we monkeypatch it
let res; stylelint.SugarSSParser.prototype.checkSemicolon = tt => {
let pass = 0; while (tt.length && tt[tt.length - 1][0] === ';') tt.pop();
/* sugarss is used for stylus-lang by default, };
but it fails on normal css syntax so we retry in css mode. */ for (const pass of opts.mode === 'stylus' ? [sugarss, !sugarss] : [-1]) {
const isSugarSS = opts.syntax === 'sugarss'; /* We try sugarss (for indented stylus-lang), then css mode, switching them on failure,
if (sugarssFallback && isSugarSS) opts.syntax = sugarssFallback; * so that the succeeding syntax will be used next time first. */
while ( opts.config.customSyntax = !pass ? 'sugarss' : '';
++pass <= 2 && try {
(res = (await stylelint.lint(opts)).results[0]) && const res = await stylelint.createLinter(opts)._lintSource(opts);
isSugarSS && res.warnings.some(hasCurlyBraceError) if (pass !== -1) sugarss = pass;
) sugarssFallback = opts.syntax = 'css'; return collectStylelintResults(res, opts);
delete res._postcssResult; // huge and unused } catch (e) {
return res; const fatal = pass === -1 ||
} catch (e) { !pass && !/^CssSyntaxError:.+?Unnecessary curly bracket/.test(e.stack) ||
delete e.postcssNode; // huge, unused, non-transferable pass && !/^CssSyntaxError:.+?Unknown word[\s\S]*?\.decl\s/.test(e.stack);
throw e; if (fatal) {
return [{
from: {line: e.line - 1, ch: e.column - 1},
to: {line: e.line - 1, ch: e.column - 1},
message: e.reason,
severity: 'error',
rule: e.name,
}];
}
}
} }
}, },
}); });
@ -139,4 +144,33 @@
return options; return options;
}, },
}; };
function collectStylelintResults({messages}, {mode}) {
/* We hide nonfatal "//" warnings since we lint with sugarss without applying @preprocessor.
* We can't easily pre-remove "//" comments which may be inside strings, comments, url(), etc.
* And even if we did, it'd be wrong to hide potential bugs in stylus-lang like #1460 */
const slashCommentAllowed = mode === 'stylus' || mode === 'text/x-less';
const res = [];
for (const m of messages) {
if (/deprecation|invalidOption/.test(m.stylelintType)) {
continue;
}
const {rule} = m;
const msg = m.text.replace(/^Unexpected\s+/, '').replace(` (${rule})`, '');
if (slashCommentAllowed && (
rule === 'no-invalid-double-slash-comments' ||
rule === 'property-no-unknown' && msg.includes('"//"')
)) {
continue;
}
res.push({
from: {line: m.line - 1, ch: m.column - 1},
to: {line: m.endLine - 1, ch: m.endColumn - 1},
message: msg[0].toUpperCase() + msg.slice(1),
severity: m.severity,
rule,
});
}
return res;
}
})(); })();

View File

@ -202,32 +202,7 @@ linterMan.DEFAULTS = {
getConfig: config => ({ getConfig: config => ({
rules: Object.assign({}, DEFAULTS.stylelint.rules, config && config.rules), rules: Object.assign({}, DEFAULTS.stylelint.rules, config && config.rules),
}), }),
async lint(code, config, mode) { lint: (code, config, mode) => worker.stylelint({code, config, mode}),
const raw = await worker.stylelint({code, config});
if (!raw) {
return [];
}
// Hiding the errors about "//" comments as we're preprocessing only when saving/applying
// and we can't just pre-remove the comments since "//" may be inside a string token
const slashCommentAllowed = mode === 'text/x-less' || mode === 'stylus';
const res = [];
for (const w of raw.warnings) {
const msg = w.text.match(/^(?:Unexpected\s+)?(.*?)\s*\([^()]+\)$|$/)[1] || w.text;
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;
},
}, },
}; };

14
package-lock.json generated
View File

@ -15,7 +15,7 @@
"jsonlint": "^1.6.3", "jsonlint": "^1.6.3",
"less-bundle": "github:openstyles/less-bundle#v0.1.0", "less-bundle": "github:openstyles/less-bundle#v0.1.0",
"lz-string-unsafe": "^1.4.4-fork-1", "lz-string-unsafe": "^1.4.4-fork-1",
"stylelint-bundle": "^14.2.0", "stylelint-bundle": "14.9.1-fixup",
"stylus-lang-bundle": "^0.58.1", "stylus-lang-bundle": "^0.58.1",
"usercss-meta": "^0.12.0", "usercss-meta": "^0.12.0",
"webext-launch-web-auth-flow": "^0.1.1" "webext-launch-web-auth-flow": "^0.1.1"
@ -6524,9 +6524,9 @@
} }
}, },
"node_modules/stylelint-bundle": { "node_modules/stylelint-bundle": {
"version": "14.2.0", "version": "14.9.1-fixup",
"resolved": "https://registry.npmjs.org/stylelint-bundle/-/stylelint-bundle-14.2.0.tgz", "resolved": "https://registry.npmjs.org/stylelint-bundle/-/stylelint-bundle-14.9.1-fixup.tgz",
"integrity": "sha512-Jy5D1G3wj06nkgI95/myTAk2LCLsot/L37k/9cS0kzHnonkOFGHfl6Ktcuq0B0VIYIVzCp3FccKoBiYfZSvI/g==", "integrity": "sha512-4qT6eMQpUxWD/EEEpBifGbQYLexpDDpuOe+47tnwVyvpgliOqlnsSs0Epeo6ydUD6jhkeaHurVJnAjU17bgdtw==",
"engines": { "engines": {
"node": ">= 10" "node": ">= 10"
} }
@ -12626,9 +12626,9 @@
} }
}, },
"stylelint-bundle": { "stylelint-bundle": {
"version": "14.2.0", "version": "14.9.1-fixup",
"resolved": "https://registry.npmjs.org/stylelint-bundle/-/stylelint-bundle-14.2.0.tgz", "resolved": "https://registry.npmjs.org/stylelint-bundle/-/stylelint-bundle-14.9.1-fixup.tgz",
"integrity": "sha512-Jy5D1G3wj06nkgI95/myTAk2LCLsot/L37k/9cS0kzHnonkOFGHfl6Ktcuq0B0VIYIVzCp3FccKoBiYfZSvI/g==" "integrity": "sha512-4qT6eMQpUxWD/EEEpBifGbQYLexpDDpuOe+47tnwVyvpgliOqlnsSs0Epeo6ydUD6jhkeaHurVJnAjU17bgdtw=="
}, },
"stylus": { "stylus": {
"version": "0.58.1", "version": "0.58.1",

View File

@ -15,7 +15,7 @@
"jsonlint": "^1.6.3", "jsonlint": "^1.6.3",
"less-bundle": "github:openstyles/less-bundle#v0.1.0", "less-bundle": "github:openstyles/less-bundle#v0.1.0",
"lz-string-unsafe": "^1.4.4-fork-1", "lz-string-unsafe": "^1.4.4-fork-1",
"stylelint-bundle": "^14.2.0", "stylelint-bundle": "^14.9.1-fixup",
"stylus-lang-bundle": "^0.58.1", "stylus-lang-bundle": "^0.58.1",
"usercss-meta": "^0.12.0", "usercss-meta": "^0.12.0",
"webext-launch-web-auth-flow": "^0.1.1" "webext-launch-web-auth-flow": "^0.1.1"

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
## stylelint-bundle v14.2.0 ## stylelint-bundle v14.9.1-fixup
Files downloaded from URL: Files downloaded from URL:
* LICENSE: https://github.com/stylelint/stylelint/raw/14.2.0/LICENSE * LICENSE: https://github.com/stylelint/stylelint/raw/14.9.1-fixup/LICENSE
Files copied from NPM (node_modules): Files copied from NPM (node_modules):

File diff suppressed because one or more lines are too long