Sha256: 26d53dd579a40d77a724722809463e01a1a116f623759cfc93368bca38412a49

Contents?: true

Size: 1.43 KB

Versions: 23

Compression:

Stored size: 1.43 KB

Contents

'use strict';

const normalizeRuleSettings = require('../normalizeRuleSettings');
const requireRule = require('../requireRule');
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: Object,
	}} 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 (!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();

	requireRule(options.ruleName)(settings[0], settings[1], {})(options.root, tmpPostcssResult);
	tmpPostcssResult.warnings().forEach(callback);
};

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
trusty-cms-5.0.7 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-5.0.6 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-5.0.5 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-5.0.4 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-5.0.3 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-5.0.2 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-5.0.1 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.3.5 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-5.0.0 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.3.4 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.3.3 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.3.2 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.3.1 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.3 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.2.3 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.2.2 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.2.1 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.2 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.1.9 node_modules/stylelint/lib/utils/checkAgainstRule.js
trusty-cms-4.1.8 node_modules/stylelint/lib/utils/checkAgainstRule.js