### Install stylelint-test-rule-node Source: https://github.com/stylelint/stylelint-test-rule-node/blob/main/README.md Installs the stylelint-test-rule-node package and stylelint as development dependencies. This is the first step to using the rule tester. ```shell npm install stylelint-test-rule-node stylelint --save-dev ``` -------------------------------- ### Test a Stylelint plugin with testRule and autofix Source: https://github.com/stylelint/stylelint-test-rule-node/blob/main/README.md Shows how to test a custom Stylelint plugin using `testRule`. This example includes passing the plugin, rule name, configuration, enabling autofix (`fix: true`), and defining `accept` and `reject` cases with expected autofixed output and detailed warning information. ```javascript // my-plugin.test.js import { testRule } from "stylelint-test-rule-node"; import myPlugin from "./my-plugin.js"; const plugins = [myPlugin]; const { ruleName, rule: { messages } } = myPlugin; testRule({ plugins, ruleName, config: [true, { type: "kebab" }], fix: true, accept: [ { code: ".class {}", description: "simple class selector" }, { code: ".my-class {}", description: "kebab class selector" } ], reject: [ { code: ".myClass {}", fixed: ".my-class {}", description: "camel case class selector", message: messages.expected(), line: 1, column: 1, endLine: 1, endColumn: 8 }, { code: ".MyClass,\n.MyOtherClass {}", fixed: ".my-class,\n.my-other-class {}", description: "two pascal class selectors in a selector list", warnings: [ { message: messages.expected(), line: 1, column: 1, endLine: 1, endColumn: 8 }, { message: messages.expected(), line: 2, column: 1, endLine: 2, endColumn: 13 } ] } ] }); ``` -------------------------------- ### Test a Stylelint rule with testRule Source: https://github.com/stylelint/stylelint-test-rule-node/blob/main/README.md Demonstrates how to use the `testRule` function to test a Stylelint rule. It includes configurations for `ruleName`, `config`, and arrays of `accept` and `reject` test cases, specifying expected code, messages, and autofix results. ```javascript // block-no-empty.test.js import { testRule } from "stylelint-test-rule-node"; testRule({ ruleName: "block-no-empty", config: true, accept: [ { code: "a { color: red }" } ], reject: [ { code: "a {}", message: "Unexpected empty block (block-no-empty)" } ] }); ``` -------------------------------- ### Test invalid Stylelint rule configurations Source: https://github.com/stylelint/stylelint-test-rule-node/blob/main/README.md Illustrates the use of `testRuleConfigs` to verify that a Stylelint rule correctly rejects invalid configuration options. It defines `accept` and `reject` cases with different `config` values, including strings and regular expressions. ```javascript import { testRuleConfigs } from "stylelint-test-rule-node"; testRuleConfigs({ plugins, ruleName, accept: [ { config: "valid" } ], reject: [ { config: "invalid" }, { config: [/invalid/], description: "regex is not allowed" } ] }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.