Update linter packages
- Updates stylelint to 13.8.0
- Updates ESLint to 7.14.0
- Updates @typescript-eslint to 4.9.0
DISABLE_THIRD_PARTY_CHECK=NPM update
R=jacktfranklin@chromium.org
Change-Id: I207e204607ede782710e042c17d6510c7f696905
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2566806
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
diff --git a/node_modules/stylelint/lib/getPostcssResult.js b/node_modules/stylelint/lib/getPostcssResult.js
index a4ccf6e..a38476b 100644
--- a/node_modules/stylelint/lib/getPostcssResult.js
+++ b/node_modules/stylelint/lib/getPostcssResult.js
@@ -5,16 +5,19 @@
const postcss = require('postcss');
const syntaxes = require('./syntaxes');
+/** @typedef {import('postcss').Result} Result */
+/** @typedef {import('postcss').Syntax} Syntax */
+/** @typedef {import('stylelint').CustomSyntax} CustomSyntax */
+/** @typedef {import('stylelint').GetPostcssOptions} GetPostcssOptions */
/** @typedef {import('stylelint').StylelintInternalApi} StylelintInternalApi */
-/** @typedef {{parse: any, stringify: any}} Syntax */
const postcssProcessor = postcss();
/**
* @param {StylelintInternalApi} stylelint
- * @param {import('stylelint').GetPostcssOptions} options
+ * @param {GetPostcssOptions} options
*
- * @returns {Promise<import('postcss').Result>}
+ * @returns {Promise<Result>}
*/
module.exports = function (stylelint, options = {}) {
const cached = options.filePath ? stylelint._postcssResultCache.get(options.filePath) : undefined;
@@ -40,25 +43,7 @@
let syntax = null;
if (stylelint._options.customSyntax) {
- try {
- // TODO TYPES determine which type has customSyntax
- const customSyntax = /** @type {any} */ require(stylelint._options.customSyntax);
-
- /*
- * PostCSS allows for syntaxes that only contain a parser, however,
- * it then expects the syntax to be set as the `parser` option rather than `syntax`.
- */
- if (!customSyntax.parse) {
- syntax = {
- parse: customSyntax,
- stringify: postcss.stringify,
- };
- } else {
- syntax = customSyntax;
- }
- } catch (e) {
- throw new Error(`Cannot resolve custom syntax module ${stylelint._options.customSyntax}`);
- }
+ syntax = getCustomSyntax(stylelint._options.customSyntax);
} else if (stylelint._options.syntax) {
if (stylelint._options.syntax === 'css') {
syntax = cssSyntax(stylelint);
@@ -78,10 +63,15 @@
} else if (!(options.codeProcessors && options.codeProcessors.length)) {
const autoSyntax = require('postcss-syntax');
+ // TODO: investigate why lazy import HTML syntax causes
+ // JS files with the word "html" to throw TypeError
+ // https://github.com/stylelint/stylelint/issues/4793
+ const { html, ...rest } = syntaxes;
+
syntax = autoSyntax({
css: cssSyntax(stylelint),
jsx: syntaxes['css-in-js'],
- ...syntaxes,
+ ...rest,
});
}
@@ -121,6 +111,51 @@
};
/**
+ * @param {CustomSyntax} customSyntax
+ * @returns {Syntax}
+ */
+function getCustomSyntax(customSyntax) {
+ let resolved;
+
+ if (typeof customSyntax === 'string') {
+ try {
+ resolved = require(customSyntax);
+ } catch (error) {
+ throw new Error(
+ `Cannot resolve custom syntax module ${customSyntax}. Check that module ${customSyntax} is available and spelled correctly.`,
+ );
+ }
+
+ /*
+ * PostCSS allows for syntaxes that only contain a parser, however,
+ * it then expects the syntax to be set as the `parse` option.
+ */
+ if (!resolved.parse) {
+ resolved = {
+ parse: resolved,
+ stringify: postcss.stringify,
+ };
+ }
+
+ return resolved;
+ }
+
+ if (typeof customSyntax === 'object') {
+ if (typeof customSyntax.parse === 'function') {
+ resolved = { ...customSyntax };
+ } else {
+ throw new Error(
+ `An object provided to the "customSyntax" option must have a "parse" property. Ensure the "parse" property exists and its value is a function.`,
+ );
+ }
+
+ return resolved;
+ }
+
+ throw new Error(`Custom syntax must be a string or a Syntax object`);
+}
+
+/**
* @param {string} filePath
* @returns {Promise<string>}
*/