Skip to content

Commit 97431f8

Browse files
authored
docs: replace --rulesdir with a virtual plugin in custom rules docs (#21452)
1 parent 6e3f988 commit 97431f8

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

‎docs/src/extend/custom-rules.md‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -991,13 +991,39 @@ While you can give a custom rule any name you'd like, the core rules have naming
991991
992992
## Runtime Rules
993993
994-
The thing that makes ESLint different from other linters is the ability to define custom rules at runtime. This is perfect for rules that are specific to your project or company and wouldn't make sense for ESLint to ship with or be included in a plugin. Just write your rules and include them at runtime.
994+
You can include custom rules directly in your configuration file. This is perfect for rules that are specific to your project or company and that wouldn't make sense to ship with ESLint or to publish as a plugin.
995995
996-
Runtime rules are written in the same format as all other rules. Create your rule as you would any other and then follow these steps:
996+
These rules are written in the same format as all other rules. Create your rule as you would any other and then follow these steps:
997997
998-
1. Place all of your runtime rules in the same directory (e.g., `eslint_rules`).
999-
2. Create a [configuration file](../use/configure/) and specify your rule ID error level under the `rules` key. Your rule will not run unless it has a value of `"warn"` or `"error"` in the configuration file.
1000-
3. Run the [command line interface](../use/command-line-interface) using the `--rulesdir` option to specify the location of your runtime rules.
998+
1. Import your rule into your [configuration file](../use/configure/configuration-files#configuration-file).
999+
2. Define a [virtual plugin](../use/configure/plugins#configure-a-virtual-plugin) under the `plugins` key and add your rule to its `rules` object.
1000+
3. Specify the severity for your rule under the `rules` key, using the plugin namespace as a prefix for the rule ID (for example, `local/my-rule`). Your rule will not run unless its severity is `"warn"` or `"error"`.
1001+
1002+
For example, if your rule is in `rules/my-rule.js`, your configuration file would look like this:
1003+
1004+
```js
1005+
// eslint.config.js
1006+
import { defineConfig } from "eslint/config";
1007+
import myRule from "./rules/my-rule.js";
1008+
1009+
export default defineConfig([
1010+
{
1011+
// define the plugin
1012+
plugins: {
1013+
local: {
1014+
rules: {
1015+
"my-rule": myRule,
1016+
},
1017+
},
1018+
},
1019+
1020+
// configure the rule
1021+
rules: {
1022+
"local/my-rule": "error",
1023+
},
1024+
},
1025+
]);
1026+
```
10011027
10021028
## Profile Rule Performance
10031029

0 commit comments

Comments
 (0)