Skip to content

Commit 7ea4ecc

Browse files
docs: Clarifying the Use of Meta Objects (#18697)
* docs: Clarifying the Use of Meta Objects * Update plugin-migration-flat-config.md * specify meta object usage in custom processors * Update custom-processors.md * Update custom-processors.md * Update custom-processors.md * address revie changes * Update docs/src/extend/plugin-migration-flat-config.md Co-authored-by: Milos Djermanovic <[email protected]> * update custom-processors.md --------- Co-authored-by: Milos Djermanovic <[email protected]>
1 parent d3e4b2e commit 7ea4ecc

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

docs/src/extend/custom-processors.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,56 @@ By default, ESLint does not perform autofixes when a custom processor is used, e
140140

141141
You can have both rules and custom processors in a single plugin. You can also have multiple processors in one plugin. To support multiple extensions, add each one to the `processors` element and point them to the same object.
142142

143-
**The `meta` object** helps ESLint cache the processor and provide more friendly debug message. The `meta.name` property should match the processor name and the `meta.version` property should match the npm package version for your processors. The easiest way to accomplish this is by reading this information from your `package.json`.
143+
### How `meta` Objects are Used
144+
145+
The `meta` object helps ESLint cache configurations that use a processor and to provide more friendly debug messages.
146+
147+
#### Plugin `meta` Object
148+
149+
The [plugin `meta` object](plugins#meta-data-in-plugins) provides information about the plugin itself. When a processor is specified using the string format `plugin-name/processor-name`, ESLint automatically uses the plugin `meta` to generate a name for the processor. This is the most common case for processors.
150+
151+
Example:
152+
153+
```js
154+
// eslint.config.js
155+
import example from "eslint-plugin-example";
156+
157+
export default [
158+
{
159+
plugins: {
160+
example
161+
},
162+
processor: "example/processor-name"
163+
},
164+
// ... other configs
165+
];
166+
```
167+
168+
In this example, the processor name is `"example/processor-name"`, and that's the value that will be used for serializing configurations.
169+
170+
#### Processor `meta` Object
171+
172+
Each processor can also specify its own `meta` object. This information is used when the processor object is passed directly to `processor` in a configuration. In that case, ESLint doesn't know which plugin the processor belongs to. The `meta.name` property should match the processor name and the `meta.version` property should match the npm package version for your processors. The easiest way to accomplish this is by reading this information from your `package.json`.
173+
174+
Example:
175+
176+
```js
177+
// eslint.config.js
178+
import example from "eslint-plugin-example";
179+
180+
export default [
181+
{
182+
processor: example.processors["processor-name"]
183+
},
184+
// ... other configs
185+
];
186+
```
187+
188+
In this example, specifying `example.processors["processor-name"]` directly uses the processor's own `meta` object, which must be defined to ensure proper handling when the processor is not referenced through the plugin name.
189+
190+
#### Why Both Meta Objects are Needed
191+
192+
It is recommended that both the plugin and each processor provide their respective meta objects. This ensures that features relying on meta objects, such as `--print-config` and `--cache`, work correctly regardless of how the processor is specified in the configuration.
144193

145194
## Specifying Processor in Config Files
146195

docs/src/extend/plugin-migration-flat-config.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ No changes are necessary for the `rules` key in your plugin. Everything works th
6363

6464
## Migrating Processors for Flat Config
6565

66-
No changes are necessary for the `processors` key in your plugin as long as you aren't using file extension-named processors. If you have any [file extension-named processors](custom-processors-deprecated#file-extension-named-processor), you must update the name to a valid identifier (numbers and letters). File extension-named processors were automatically applied in the old configuration system but are not automatically applied when using flat config. Here is an example of a file extension-named processor:
66+
Each processor should specify a `meta` object. For more information, see the [full documentation](custom-processors).
67+
68+
No other changes are necessary for the `processors` key in your plugin as long as you aren't using file extension-named processors. If you have any [file extension-named processors](custom-processors-deprecated#file-extension-named-processor), you must update the name to a valid identifier (numbers and letters). File extension-named processors were automatically applied in the old configuration system but are not automatically applied when using flat config. Here is an example of a file extension-named processor:
6769

6870
```js
6971
const plugin = {

0 commit comments

Comments
 (0)