Registry / devops / eslint-plugin-eslint-env-restore

eslint-plugin-eslint-env-restore

JSON →
library1.0.1jsnpmunverified

Restores `/* eslint-env */` comment functionality removed in ESLint v9+. ESLint v9 dropped support for inline `/* eslint-env */` comments that dynamically set globals per file. This plugin re-enables that behavior for ESLint v9+ by providing a processor (`eslint-env-restore/js`) that automatically declares the corresponding global variables. It simplifies migration from ESLint v8 to v9 where environment comments are heavily used. The package is at version 1.0.1, stable, with no frequent releases expected. Compared to manually listing globals in config, this plugin is a drop-in solution for legacy codebases. It requires the `no-unused-vars` rule to use `{ vars: 'local' }` to avoid false positives. Does not support environments that are not built into ESLint.

npm install eslint-plugin-eslint-env-restore
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-ESLI
E
eslint-plugin-eslint-env-restore
devopsjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugin (default)
import eslintEnvRestorePlugin from 'eslint-plugin-eslint-env-restore'
const eslintEnvRestorePlugin = require('eslint-plugin-eslint-env-restore')
Plugin provides a default export; use ESM import for TypeScript or ESM projects.
processor 'eslint-env-restore/js'
processor: 'eslint-env-restore/js'
processor: 'js'
Processor name must include the plugin prefix; just 'js' will not resolve.
FlatConfig usage with plugins array
const eslintEnvRestorePlugin = require('eslint-plugin-eslint-env-restore'); module.exports = [{ plugins: { 'eslint-env-restore': eslintEnvRestorePlugin }, processor: 'eslint-env-restore/js', rules: { 'no-unused-vars': ['error', { vars: 'local' }] } }]
module.exports = [{ plugins: { 'eslint-env-restore': eslintEnvRestorePlugin }, rules: { 'no-unused-vars': 'warn' } }]
Must set `vars: 'local'` in no-unused-vars rule to avoid false positives on globals.

Configures the plugin with flat config and demonstrates an eslint-env mocha comment so that Mocha globals are recognized.

// .eslintrc.cjs const eslintEnvRestorePlugin = require('eslint-plugin-eslint-env-restore'); module.exports = [ { plugins: { 'eslint-env-restore': eslintEnvRestorePlugin }, processor: 'eslint-env-restore/js', rules: { 'no-unused-vars': ['error', { vars: 'local' }] } } ]; // example.js /* eslint-env mocha */ describe('my suite', () => { it('should work', () => { // mocha globals like 'describe' and 'it' are recognized }); });
Debug
Known issues
breakingPlugin only works with ESLint v9+ flat config. Not compatible with legacy eslintrc format.
fix
Migrate to flat config (eslint.config.js/cjs or eslint.config.mjs).
affects: >=1.0.0
gotchaMust set `no-unused-vars` rule with `vars: 'local'` to avoid '... is defined but never used' errors for globals added by the processor.
fix
Set `'no-unused-vars': ['error', { vars: 'local' }]` in your flat config.
affects: >=1.0.0
gotchaThe plugin processor only applies to .js files by default. If your files have other extensions (e.g., .mjs, .cjs, .ts), you need to apply the processor to those extensions explicitly (e.g., using `files: ['**/*.js', '**/*.mjs']`).
fix
Specify `files: ['**/*.js', '**/*.mjs', '**/*.cjs']` in the config object.
affects: >=1.0.0
gotchaEnvironments not built into ESLint (e.g., custom environment plugins) are not supported; the plugin only recognizes built-in ESLint environments.
fix
Manually declare globals for custom environments via `globals` config.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Failed to load plugin 'eslint-env-restore': Cannot find module 'eslint-plugin-eslint-env-restore'
Package not installed or not in node_modules.
fix
Run `npm install -D eslint-plugin-eslint-env-restore`
Configuration for rule "no-unused-vars" is invalid: "vars" must be "local" or "all"
The `no-unused-vars` rule must have `{ vars: 'local' }` set.
fix
Change `'no-unused-vars': ['error', { vars: 'local' }]`
TypeError: Invalid processor: 'js'. Use 'plugin/processor' format.
Processor name must be prefixed with plugin name.
fix
Use `processor: 'eslint-env-restore/js'`
Error: The environment 'mocha' is unknown. Use '/* eslint-env mocha */' comment but environment not recognized.
Plugin processor not applied; environment comment is being ignored by ESLint v9.
fix
Ensure the plugin is added to plugins and processor is set to 'eslint-env-restore/js'.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
eslintrequiredPeer dependency; plugin works only with ESLint v9+
Agent activity
9 hits · last 30 days
node
9
Resources
eslint-plugin-eslint-env-restore — npm install eslint-plugin-eslint-env-restore · libregistry