From 213ee59feb8bbacae546c3e609841bedb0cfd5a8 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 23 Nov 2023 00:21:36 +0900 Subject: [PATCH] Improve code examples in README Prefer ESM, considering Stylelint 16.0.0. --- README.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ffeffcf..ce0c8e7 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ Add the preset to your `jest.config.js` or `jest` field in `package.json`: } ``` +### Adjust setup globally + Optionally, you can avoid specifying `plugins` in every schema by defining your own setup file to configure the `testRule`/`testRuleConfigs` functions. This is useful if you have many tests. There are two additional steps to do this: @@ -29,9 +31,12 @@ This is useful if you have many tests. There are two additional steps to do this ```js const { getTestRule, getTestRuleConfigs } = require("jest-preset-stylelint"); + const myPlugin = require("./my-plugin.js"); + + const plugins = [myPlugin]; - global.testRule = getTestRule({ plugins: ["./"] }); - global.testRuleConfigs = getTestRuleConfigs({ plugins: ["./"] }); + global.testRule = getTestRule({ plugins }); + global.testRuleConfigs = getTestRuleConfigs({ plugins }); ``` 2. Add `jest.setup.js` to your `jest.config.js` or `jest` field in `package.json`: @@ -39,7 +44,7 @@ This is useful if you have many tests. There are two additional steps to do this ```json { "preset": "jest-preset-stylelint", - "setupFiles": ["jest.setup.js"] + "setupFiles": ["/jest.setup.js"] } ``` @@ -57,10 +62,16 @@ For example, we can test a plugin that enforces and autofixes kebab-case class s ```js // my-plugin.test.js -const { messages, ruleName } = require("."); +import myPlugin from "./my-plugin.js"; + +const plugins = [myPlugin]; +const { + ruleName, + rule: { messages } +} = myPlugin; testRule({ - plugins: ["."], + plugins, ruleName, config: [true, { type: "kebab" }], fix: true, @@ -120,7 +131,7 @@ For example: ```js testRuleConfigs({ - plugins: ["."], + plugins, ruleName, accept: [