Skip to content

Commit 091f44e

Browse files
author
Matt Wilkinson
authored
docs: File extension named processor deprecation (#17362)
1 parent 1a2f966 commit 091f44e

3 files changed

Lines changed: 85 additions & 0 deletions

File tree

docs/src/extend/custom-processors.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ See [Specify a Processor](../use/configure/plugins#specify-a-processor) in the P
139139

140140
## File Extension-named Processor
141141

142+
::: warning
143+
This feature is deprecated and only works in eslintrc-style configuration files. Flat config files do not automatically apply processors; you need to explicitly set the `processor` property.
144+
:::
145+
142146
If a custom processor name starts with `.`, ESLint handles the processor as a **file extension-named processor**. ESLint applies the processor to files with that filename extension automatically. Users don't need to specify the file extension-named processors in their config files.
143147

144148
For example:

docs/src/extend/plugins.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Plugin environments can define the following objects:
8989

9090
### Processors in Plugins
9191

92+
::: warning
93+
File extension-named processors are deprecated and only work in eslintrc-style configuration files. Flat config files do not automatically apply processors; you need to explicitly set the `processor` property.
94+
:::
95+
9296
You can add processors to plugins by including the processor functions in the `processors` key. For more information on defining custom processors, refer to [Custom Processors](custom-processors).
9397

9498
```js

docs/src/use/configure/migration-guide.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,83 @@ export default [
114114
];
115115
```
116116

117+
### Processors
118+
119+
In eslintrc files, processors had to be defined in a plugin, and then referenced by name in the configuration. Processors beginning with a dot indicated a [file extension-named processor](../../extend/custom-processors#file-extension-named-processor) which ESLint would automatically configure for that file extension.
120+
121+
In flat config files, processors can still be referenced from plugins by their name, but they can now also be inserted directly into the configuration. Processors will _never_ be automatically configured, and must be explicitly set in the configuration.
122+
123+
As an example with a custom plugin with processors:
124+
125+
```javascript
126+
// node_modules/eslint-plugin-someplugin/index.js
127+
module.exports = {
128+
processors: {
129+
".md": {
130+
preprocess() {},
131+
postprocess() {}
132+
},
133+
"someProcessor": {
134+
preprocess() {},
135+
postprocess() {}
136+
}
137+
}
138+
};
139+
```
140+
141+
In eslintrc, you would configure as follows:
142+
143+
```javascript
144+
// .eslintrc.js
145+
module.exports = {
146+
plugins: ["someplugin"],
147+
processor: "someplugin/someProcessor"
148+
};
149+
```
150+
151+
ESLint would also automatically add the equivalent of the following:
152+
153+
```javascript
154+
{
155+
overrides: [{
156+
files: ["**/*.md"],
157+
processor: "someplugin/.md"
158+
}]
159+
}
160+
```
161+
162+
In flat config, the following are all valid ways to express the same:
163+
164+
```javascript
165+
// eslint.config.js
166+
import somePlugin from "eslint-plugin-someplugin";
167+
168+
export default [
169+
{
170+
plugins: { somePlugin },
171+
processor: "somePlugin/someProcessor"
172+
},
173+
{
174+
plugins: { somePlugin },
175+
// We can embed the processor object in the config directly
176+
processor: somePlugin.processors.someProcessor
177+
},
178+
{
179+
// We don't need the plugin to be present in the config to use the processor directly
180+
processor: somePlugin.processors.someProcessor
181+
}
182+
];
183+
```
184+
185+
Note that because the `.md` processor is _not_ automatically added by flat config, you also need to specify an extra configuration element:
186+
187+
```javascript
188+
{
189+
files: ["**/*.md"],
190+
processor: somePlugin.processors[".md"]
191+
}
192+
```
193+
117194
### Glob-Based Configs
118195

119196
By default, eslintrc files lint all files (except those covered by `.eslintignore`) in the directory in which they’re placed and its child directories. If you want to have different configurations for different file glob patterns, you can specify them in the `overrides` property.

0 commit comments

Comments
 (0)