mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 21:54:47 +08:00
- 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>
46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
const normalizeRuleSettings = require('../normalizeRuleSettings');
|
|
const Result = require('postcss/lib/result');
|
|
const rules = require('../rules');
|
|
|
|
/**
|
|
* Useful for third-party code (e.g. plugins) to run a PostCSS Root
|
|
* against a specific rule and do something with the warnings
|
|
* @param {{
|
|
ruleName: string,
|
|
ruleSettings: import('stylelint').StylelintConfigRuleSettings,
|
|
root: import('postcss').Root,
|
|
}} options
|
|
* @param {Function} callback
|
|
* @returns {void}
|
|
*/
|
|
module.exports = function (options, callback) {
|
|
if (!options)
|
|
throw new Error(
|
|
"checkAgainstRule requires an options object with 'ruleName', 'ruleSettings', and 'root' properties",
|
|
);
|
|
|
|
if (!callback) throw new Error('checkAgainstRule requires a callback');
|
|
|
|
if (!options.ruleName) throw new Error("checkAgainstRule requires a 'ruleName' option");
|
|
|
|
if (!Object.keys(rules).includes(options.ruleName))
|
|
throw new Error(`Rule '${options.ruleName}' does not exist`);
|
|
|
|
if (!options.ruleSettings) throw new Error("checkAgainstRule requires a 'ruleSettings' option");
|
|
|
|
if (!options.root) throw new Error("checkAgainstRule requires a 'root' option");
|
|
|
|
const settings = normalizeRuleSettings(options.ruleSettings, options.ruleName);
|
|
|
|
if (!settings) {
|
|
return;
|
|
}
|
|
|
|
const tmpPostcssResult = new Result();
|
|
|
|
rules[options.ruleName](settings[0], settings[1], {})(options.root, tmpPostcssResult);
|
|
tmpPostcssResult.warnings().forEach(callback);
|
|
};
|