How to use the stylelint.utils.ruleMessages 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 kristerkari / stylelint-scss / src / rules / comment-no-loud / index.js View on Github external
import { utils } from "stylelint";
import { namespace } from "../../utils";

export const ruleName = namespace("comment-no-loud");

export const messages = utils.ruleMessages(ruleName, {
  expected: "Expected // for comments instead of /*"
});

function rule(primary) {
  return (root, result) => {
    const validOptions = utils.validateOptions(result, ruleName, {
      actual: primary
    });

    if (!validOptions) {
      return;
    }

    root.walkComments(comment => {
      if (isLoudComment(comment)) {
        utils.report({
github kristerkari / stylelint-scss / src / rules / dollar-variable-default / index.js View on Github external
import { utils } from "stylelint";
import { namespace, optionsHaveIgnored } from "../../utils";

export const ruleName = namespace("dollar-variable-default");

export const messages = utils.ruleMessages(ruleName, {
  expected: variable => `Expected !default flag for "${variable}"`
});

export default function(primaryOption, secondaryOptions) {
  return (root, result) => {
    const validOptions = utils.validateOptions(
      result,
      ruleName,
      {
        actual: primaryOption
      },
      {
        actual: secondaryOptions,
        possible: {
          ignore: ["local"]
        },
github NervJS / taro / packages / stylelint-taro-rn / src / rules / css-property-no-unknown / index.js View on Github external
import { allCSS2RNProps } from "react-native-known-styling-properties";
import { utils } from "stylelint";
import {
  isCustomProperty,
  isExportBlock,
  isStandardSyntaxDeclaration,
  isStandardSyntaxProperty,
  isString,
  kebabCase,
  namespace,
  optionsMatches
} from "../../utils";

export const ruleName = namespace("css-property-no-unknown");

export const messages = utils.ruleMessages(ruleName, {
  rejected: property => `无效的 React Native 样式属性 "${property}"`
});

const props = allCSS2RNProps.map(kebabCase);

export default function(actual, options) {
  return function(root, result) {
    const validOptions = utils.validateOptions(
      result,
      ruleName,
      {
        actual
      },
      {
        actual: options,
        possible: {
github kristerkari / stylelint-scss / src / rules / dollar-variable-pattern / index.js View on Github external
import isRegExp from "lodash.isregexp";
import isString from "lodash.isstring";
import { utils } from "stylelint";
import { namespace, optionsHaveIgnored } from "../../utils";

export const ruleName = namespace("dollar-variable-pattern");

export const messages = utils.ruleMessages(ruleName, {
  expected: "Expected $ variable name to match specified pattern"
});

export default function(pattern, options) {
  return (root, result) => {
    const validOptions = utils.validateOptions(
      result,
      ruleName,
      {
        actual: pattern,
        possible: [isRegExp, isString]
      },
      {
        actual: options,
        possible: {
          ignore: ["local", "global"]
github kristerkari / stylelint-scss / src / rules / at-each-key-value-single-line / index.js View on Github external
import { utils } from "stylelint";
import { namespace } from "../../utils";

export const ruleName = namespace("at-each-key-value-single-line");

export const messages = utils.ruleMessages(ruleName, {
  expected:
    "Use @each $key, $value in $map syntax instead of $value: map-get($map, $key)"
});

export default function(primary) {
  return (root, result) => {
    const validOptions = utils.validateOptions(result, ruleName, {
      actual: primary
    });

    if (!validOptions) {
      return;
    }

    root.walkAtRules("each", rule => {
      const parts = separateEachParams(rule.params);
github kristerkari / stylelint-scss / src / rules / at-import-partial-extension-blacklist / index.js View on Github external
import isRegExp from "lodash.isregexp";
import isString from "lodash.isstring";
import { utils } from "stylelint";
import { namespace } from "../../utils";
import nodeJsPath from "path";

export const ruleName = namespace("at-import-partial-extension-blacklist");

export const messages = utils.ruleMessages(ruleName, {
  rejected: ext => `Unexpected extension ".${ext}" in imported partial name`
});

export default function(blacklistOption) {
  const blacklist = [].concat(blacklistOption);

  return (root, result) => {
    const validOptions = utils.validateOptions(result, ruleName, {
      actual: blacklistOption,
      possible: [isString, isRegExp]
    });

    if (!validOptions) {
      return;
    }
github kristerkari / stylelint-scss / src / rules / dollar-variable-colon-space-before / index.js View on Github external
import { namespace, whitespaceChecker } from "../../utils";
import { utils } from "stylelint";
import { variableColonSpaceChecker } from "../dollar-variable-colon-space-after";

export const ruleName = namespace("dollar-variable-colon-space-before");

export const messages = utils.ruleMessages(ruleName, {
  expectedBefore: () => 'Expected single space before ":"',
  rejectedBefore: () => 'Unexpected whitespace before ":"'
});

export default function(expectation, _, context) {
  const checker = whitespaceChecker("space", expectation, messages);

  return (root, result) => {
    const validOptions = utils.validateOptions(result, ruleName, {
      actual: expectation,
      possible: ["always", "never"]
    });

    if (!validOptions) {
      return;
    }
github kristerkari / stylelint-scss / src / rules / at-else-closing-brace-newline-after / index.js View on Github external
import { namespace } from "../../utils";
import { utils } from "stylelint";
import isBoolean from "lodash.isboolean";

export const ruleName = namespace("at-else-closing-brace-newline-after");

export const messages = utils.ruleMessages(ruleName, {
  expected: 'Expected newline after "}" of @else statement',
  rejected: 'Unexpected newline after "}" of @else statement'
});

import { sassConditionalBraceNLAfterChecker } from "../at-if-closing-brace-newline-after";

export default function(expectation, options, context) {
  return (root, result) => {
    const validOptions = utils.validateOptions(
      result,
      ruleName,
      {
        actual: expectation,
        possible: ["always-last-in-chain"]
      },
      {
github kristerkari / stylelint-scss / src / rules / operator-no-newline-after / index.js View on Github external
import { utils } from "stylelint";
import { eachRoot, namespace, isWhitespace } from "../../utils";

export const ruleName = namespace("operator-no-newline-after");

export const messages = utils.ruleMessages(ruleName, {
  rejected: operator => `Unexpected newline after "${operator}"`
});

import { calculationOperatorSpaceChecker } from "../operator-no-unspaced";

/**
 * The checker function: whether there is a newline before THAT operator.
 */
function checkNewlineBefore({
  string,
  globalIndex,
  startIndex,
  endIndex,
  node,
  result
}) {
github kristerkari / stylelint-scss / src / rules / at-mixin-argumentless-call-parentheses / index.js View on Github external
import { utils } from "stylelint";
import { namespace } from "../../utils";

export const ruleName = namespace("at-mixin-argumentless-call-parentheses");

export const messages = utils.ruleMessages(ruleName, {
  expected: mixin => `Expected parentheses in mixin "${mixin}" call`,
  rejected: mixin =>
    `Unexpected parentheses in argumentless mixin "${mixin}" call`
});

export default function(value, _, context) {
  return (root, result) => {
    const validOptions = utils.validateOptions(result, ruleName, {
      actual: value,
      possible: ["always", "never"]
    });

    if (!validOptions) {
      return;
    }