stylelint 14.9.1
This commit is contained in:
parent
2d21bb1dd6
commit
7a5569e9d5
|
@ -2,9 +2,7 @@
|
|||
'use strict';
|
||||
|
||||
(() => {
|
||||
const hasCurlyBraceError = warning =>
|
||||
warning.text === 'Unnecessary curly bracket (CssSyntaxError)';
|
||||
let sugarssFallback;
|
||||
let sugarss = false;
|
||||
|
||||
/** @namespace EditorWorker */
|
||||
createWorkerApi({
|
||||
|
@ -65,26 +63,33 @@
|
|||
},
|
||||
|
||||
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 */
|
||||
try {
|
||||
let res;
|
||||
let pass = 0;
|
||||
/* sugarss is used for stylus-lang by default,
|
||||
but it fails on normal css syntax so we retry in css mode. */
|
||||
const isSugarSS = opts.syntax === 'sugarss';
|
||||
if (sugarssFallback && isSugarSS) opts.syntax = sugarssFallback;
|
||||
while (
|
||||
++pass <= 2 &&
|
||||
(res = (await stylelint.lint(opts)).results[0]) &&
|
||||
isSugarSS && res.warnings.some(hasCurlyBraceError)
|
||||
) sugarssFallback = opts.syntax = 'css';
|
||||
delete res._postcssResult; // huge and unused
|
||||
return res;
|
||||
} catch (e) {
|
||||
delete e.postcssNode; // huge, unused, non-transferable
|
||||
throw e;
|
||||
// Stylus-lang allows a trailing ";" but sugarss doesn't, so we monkeypatch it
|
||||
stylelint.SugarSSParser.prototype.checkSemicolon = tt => {
|
||||
while (tt.length && tt[tt.length - 1][0] === ';') tt.pop();
|
||||
};
|
||||
for (const pass of opts.mode === 'stylus' ? [sugarss, !sugarss] : [-1]) {
|
||||
/* We try sugarss (for indented stylus-lang), then css mode, switching them on failure,
|
||||
* so that the succeeding syntax will be used next time first. */
|
||||
opts.config.customSyntax = !pass ? 'sugarss' : '';
|
||||
try {
|
||||
const res = await stylelint.createLinter(opts)._lintSource(opts);
|
||||
if (pass !== -1) sugarss = pass;
|
||||
return collectStylelintResults(res, opts);
|
||||
} catch (e) {
|
||||
const fatal = pass === -1 ||
|
||||
!pass && !/^CssSyntaxError:.+?Unnecessary curly bracket/.test(e.stack) ||
|
||||
pass && !/^CssSyntaxError:.+?Unknown word[\s\S]*?\.decl\s/.test(e.stack);
|
||||
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;
|
||||
},
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -202,32 +202,7 @@ linterMan.DEFAULTS = {
|
|||
getConfig: config => ({
|
||||
rules: Object.assign({}, DEFAULTS.stylelint.rules, config && config.rules),
|
||||
}),
|
||||
async lint(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;
|
||||
},
|
||||
lint: (code, config, mode) => worker.stylelint({code, config, mode}),
|
||||
},
|
||||
};
|
||||
|
||||
|
|
14
package-lock.json
generated
14
package-lock.json
generated
|
@ -15,7 +15,7 @@
|
|||
"jsonlint": "^1.6.3",
|
||||
"less-bundle": "github:openstyles/less-bundle#v0.1.0",
|
||||
"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",
|
||||
"usercss-meta": "^0.12.0",
|
||||
"webext-launch-web-auth-flow": "^0.1.1"
|
||||
|
@ -6524,9 +6524,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/stylelint-bundle": {
|
||||
"version": "14.2.0",
|
||||
"resolved": "https://registry.npmjs.org/stylelint-bundle/-/stylelint-bundle-14.2.0.tgz",
|
||||
"integrity": "sha512-Jy5D1G3wj06nkgI95/myTAk2LCLsot/L37k/9cS0kzHnonkOFGHfl6Ktcuq0B0VIYIVzCp3FccKoBiYfZSvI/g==",
|
||||
"version": "14.9.1-fixup",
|
||||
"resolved": "https://registry.npmjs.org/stylelint-bundle/-/stylelint-bundle-14.9.1-fixup.tgz",
|
||||
"integrity": "sha512-4qT6eMQpUxWD/EEEpBifGbQYLexpDDpuOe+47tnwVyvpgliOqlnsSs0Epeo6ydUD6jhkeaHurVJnAjU17bgdtw==",
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
|
@ -12626,9 +12626,9 @@
|
|||
}
|
||||
},
|
||||
"stylelint-bundle": {
|
||||
"version": "14.2.0",
|
||||
"resolved": "https://registry.npmjs.org/stylelint-bundle/-/stylelint-bundle-14.2.0.tgz",
|
||||
"integrity": "sha512-Jy5D1G3wj06nkgI95/myTAk2LCLsot/L37k/9cS0kzHnonkOFGHfl6Ktcuq0B0VIYIVzCp3FccKoBiYfZSvI/g=="
|
||||
"version": "14.9.1-fixup",
|
||||
"resolved": "https://registry.npmjs.org/stylelint-bundle/-/stylelint-bundle-14.9.1-fixup.tgz",
|
||||
"integrity": "sha512-4qT6eMQpUxWD/EEEpBifGbQYLexpDDpuOe+47tnwVyvpgliOqlnsSs0Epeo6ydUD6jhkeaHurVJnAjU17bgdtw=="
|
||||
},
|
||||
"stylus": {
|
||||
"version": "0.58.1",
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
"jsonlint": "^1.6.3",
|
||||
"less-bundle": "github:openstyles/less-bundle#v0.1.0",
|
||||
"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",
|
||||
"usercss-meta": "^0.12.0",
|
||||
"webext-launch-web-auth-flow": "^0.1.1"
|
||||
|
|
1052
vendor/stylelint-bundle/LICENSE
vendored
1052
vendor/stylelint-bundle/LICENSE
vendored
File diff suppressed because one or more lines are too long
4
vendor/stylelint-bundle/README.md
vendored
4
vendor/stylelint-bundle/README.md
vendored
|
@ -1,7 +1,7 @@
|
|||
## stylelint-bundle v14.2.0
|
||||
## stylelint-bundle v14.9.1-fixup
|
||||
|
||||
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):
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user