diff --git a/docs/src/extend/custom-processors.md b/docs/src/extend/custom-processors.md index 697d052e6556..a47271e2e9e6 100644 --- a/docs/src/extend/custom-processors.md +++ b/docs/src/extend/custom-processors.md @@ -139,6 +139,10 @@ See [Specify a Processor](../use/configure/plugins#specify-a-processor) in the P ## File Extension-named Processor +::: warning +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. +::: + 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. For example: diff --git a/docs/src/extend/plugins.md b/docs/src/extend/plugins.md index 70bc3ee7c746..b7a9af5b3891 100644 --- a/docs/src/extend/plugins.md +++ b/docs/src/extend/plugins.md @@ -89,6 +89,10 @@ Plugin environments can define the following objects: ### Processors in Plugins +::: warning +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. +::: + 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). ```js diff --git a/docs/src/use/configure/migration-guide.md b/docs/src/use/configure/migration-guide.md index 4791dc7c5d0e..db35b6722540 100644 --- a/docs/src/use/configure/migration-guide.md +++ b/docs/src/use/configure/migration-guide.md @@ -27,7 +27,6 @@ To use flat config with ESLint v8, place a `eslint.config.js` file in the root o While the configuration file format has changed from eslintrc to flat config, the following has stayed the same: * Syntax for configuring rules -* Syntax for configuring processors * The CLI, except for the flag changes noted in [CLI Flag Changes](#cli-flag-changes). * Global variables are configured the same way, but on a different property (see [Configuring Language Options](#configuring-language-options)). @@ -114,6 +113,98 @@ export default [ ]; ``` +### Processors + +In eslintrc files, processors had to be defined in a plugin, and then referenced by name in the configuration. Processors with a name in the special form `.xxx` were also automatically configured for any files with the extension `xxx`. + +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. + +As an example with a custom plugin with processors: + +```javascript +// node_modules/eslint-plugin-someplugin/index.js +module.exports = { + processors: { + ".md": { + preprocess() {}, + postprocess() {} + }, + "someProcessor": { + preprocess() {}, + postprocess() {} + } + } +}; +``` + +In eslintrc, you would configure as follows: + +```javascript +// .eslintrc.js +module.exports = { + plugins: ["someplugin"], + processor: "someplugin/someProcessor" +}; +``` + +ESLint would also automatically add the equivalent of the following: + +```javascript +{ + overrides: [{ + files: ["**/*.md"], + processor: "someplugin/.md" + }] +} +``` + +In flat config, the following are all valid ways to express the same: + +```javascript +// eslint.config.js +import somePlugin from "eslint-plugin-someplugin"; + +export default [ + { + plugins: { somePlugin }, + processor: "somePlugin/someProcessor" + }, + { + plugins: { somePlugin }, + // We can embed the processor object in the config directly + processor: somePlugin.processors.someProcessor + }, + { + // We don't need the plugin to be present in the config to use the processor directly + processor: somePlugin.processors.someProcessor + } +]; +``` + +Note that because the `.md` processor is _not_ automatically added by flat config, you also need to specify an extra configuration element: + +```javascript +{ + files: ["**/*.md"], + processor: somePlugin.processors[".md"] +} +``` + +In flat config, you can even directly embed custom processors without an associated plugin: + +```javascript +// eslint.config.js + +export default [ + { + processor: { + preprocess() {}, + postprocess() {} + } + } +]; +``` + ### Glob-Based Configs 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.