How to use the stylelint.utils function in stylelint

To help you get started, we’ve selected a few stylelint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gitlabhq / gitlabhq / scripts / frontend / stylelint / stylelint-duplicate-selectors.js View on Github external
const stylelint = require('stylelint');
const utils = require('./stylelint-utils');

const ruleName = 'stylelint-gitlab/duplicate-selectors';

const messages = stylelint.utils.ruleMessages(ruleName, {
  expected: (selector1, selector2) => {
    return `"${selector1}" and "${selector2}" have the same properties.`;
  },
});

module.exports = stylelint.createPlugin(ruleName, (enabled) => {
  if (!enabled) {
    return;
  }

  // eslint-disable-next-line consistent-return
  return (root, result) => {
    const selectorGroups = {};
    utils.createPropertiesHashmap(root, result, ruleName, messages, selectorGroups, true);
  };
});
github csstree / stylelint-validator / index.js View on Github external
var match = syntax.matchProperty(decl.prop, value);
            var error = match.error;
            if (error) {
                var message = error.rawMessage || error.message || error;

                // ignore errors except those which make sense
                if (error.name !== 'SyntaxMatchError' &&
                    error.name !== 'SyntaxReferenceError') {
                    return;
                }

                if (message === 'Mismatch') {
                    message = messages.invalid(decl.prop);
                }

                stylelint.utils.report({
                    message: message,
                    node: decl,
                    result: result,
                    ruleName: ruleName
                });
            }
        });
    }
github gitlabhq / gitlabhq / scripts / frontend / stylelint / stylelint-utility-classes.js View on Github external
const stylelint = require('stylelint');
const utils = require('./stylelint-utils');
const utilityClasses = require('./utility-classes-map.js');

const ruleName = 'stylelint-gitlab/utility-classes';

const messages = stylelint.utils.ruleMessages(ruleName, {
  expected: (selector1, selector2) => {
    return `"${selector1}" has the same properties as our BS4 utility class "${selector2}" so please use that instead.`;
  },
});

module.exports = stylelint.createPlugin(ruleName, (enabled) => {
  if (!enabled) {
    return;
  }

  // eslint-disable-next-line consistent-return
  return (root, result) => {
    utils.createPropertiesHashmap(root, result, ruleName, messages, utilityClasses, false);
  };
});
github hudochenkov / stylelint-order / rules / order / checkOrder.js View on Github external
Boolean(d.expectedPosition)
		);

		if (
			priorSpecifiedNodeData &&
			priorSpecifiedNodeData.expectedPosition &&
			priorSpecifiedNodeData.expectedPosition > secondNodeData.expectedPosition
		) {
			if (sharedInfo.isFixEnabled) {
				sharedInfo.shouldFix = true;

				// Don't go further, fix will be applied
				return;
			}

			stylelint.utils.report({
				message: sharedInfo.messages.expected(
					secondNodeData.description,
					priorSpecifiedNodeData.description
				),
				node: secondNodeData.node,
				result: sharedInfo.result,
				ruleName: sharedInfo.ruleName,
			});

			return true; // avoid logging another warning
		}
	}

	if (firstNodeIsUnspecified && secondNodeIsUnspecified) {
		return true;
	}
github kaliberjs / build / library / stylelint-plugins / kaliber.js View on Github external
function report(node, message, index) {
        const id = getId(node, message, index)
        if (reported[id]) return
        else reported[id] = true
        if (!node.source) stylelint.utils.report({
          message: `A generated node (${getNodeId(node)}) caused a problem\n  ${node.toString().split('\n').join('\n  ')}\n${message}`,
          node: node.parent, result, ruleName
        })
        else stylelint.utils.report({ message, index, node, result, ruleName })
      }
    }
github hudochenkov / stylelint-order / rules / properties-alphabetical-order / index.js View on Github external
const stylelint = require('stylelint');
const _ = require('lodash');
const postcss = require('postcss');
const postcssSorting = require('postcss-sorting');
const checkAlphabeticalOrder = require('../checkAlphabeticalOrder');
const utils = require('../../utils');

const ruleName = utils.namespace('properties-alphabetical-order');

const messages = stylelint.utils.ruleMessages(ruleName, {
	expected: (first, second) => `Expected ${first} to come before ${second}`,
});

function rule(actual, options, context) {
	context = context || {};

	return function(root, result) {
		const validOptions = stylelint.utils.validateOptions(
			result,
			ruleName,
			{
				actual,
				possible: _.isBoolean,
			},
			{
				actual: options,
github kristerkari / stylelint-declaration-block-no-ignored-properties / index.js View on Github external
const matchesStringOrRegExp = require("./utils/matchesStringOrRegExp");
const postcss = require("postcss");
const stylelint = require("stylelint");
const report = stylelint.utils.report;
const ruleMessages = stylelint.utils.ruleMessages;
const validateOptions = stylelint.utils.validateOptions;

const ruleName = "plugin/declaration-block-no-ignored-properties";

const messages = ruleMessages(ruleName, {
  rejected: (ignore, cause) => `Unexpected "${ignore}" with "${cause}"`
});

const ignored = [
  {
    property: "display",
    value: "inline",
    ignoredProperties: [
      "width",
      "min-width",
github ierhyna / stylelint-no-indistinguishable-colors / lib / index.js View on Github external
const colorguard = require("colorguard");
const Result = require("postcss/lib/result");
const stylelint = require("stylelint");
const isValidHex = require("stylelint/lib/utils/isValidHex");

const ruleName = "plugin/stylelint-no-indistinguishable-colors";
const messages = stylelint.utils.ruleMessages(ruleName, {
  rejected: (a, b) => `Unexpected indistinguishable colors "${a}" and "${b}".`
});

module.exports = stylelint.createPlugin(
  ruleName,
  (primaryOption, secondaryOptions) => (postcssRoot, postcssResult) => {
    const validOptions = stylelint.utils.validateOptions(
      postcssResult,
      ruleName,
      {
        actual: primaryOption,
        possible: [true, false]
      },
      {
        optional: true,
        actual: secondaryOptions,
github davidtheclark / stylelint-statement-max-nesting-depth / index.js View on Github external
function checkStatement(statement) {
      const depth = nestingDepth(statement);
      if (depth > max) {
        stylelint.utils.report({
          ruleName: ruleName,
          result: result,
          node: statement,
          message: messages.rejected
        });
      }
    }
  };
github constverum / stylelint-config-rational-order / plugin / index.js View on Github external
(enabled, options, context) => (postcssRoot, postcssResult) => {
    const validOptions = stylelint.utils.validateOptions(
      postcssResult,
      ruleName,
      {
        actual: enabled,
        possible: [true, false],
      },
      {
        actual: options,
        optional: true,
        possible: {
          'border-in-box-model': [true, false],
          'empty-line-between-groups': [true, false],
        },
      },
    );
    if (!enabled || !validOptions) {