{"id":19473,"library":"eslint-compat-utils","title":"eslint-compat-utils","description":"Provides a backward-compatible API for ESLint custom rules that works with both ESLint v9 (flat config) and older ESLint versions (v6–v8). Current stable version is 0.6.5, released in 2024. The package is experimental but actively maintained with monthly patches. Key differentiator: it offers polyfills for new ESLint APIs (like getSourceCode, getScope, RuleTester shims) so rule authors can write modern code without dropping support for older ESLint installations. Ships TypeScript definitions.","status":"active","version":"0.6.5","language":"javascript","source_language":"en","source_url":"https://github.com/ota-meshi/eslint-compat-utils","tags":["javascript","eslint","typescript"],"install":[{"cmd":"npm install eslint-compat-utils","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-compat-utils","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-compat-utils","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; requires eslint >=6.0.0","package":"eslint","optional":false}],"imports":[{"note":"Package does not ship native ESM; use CJS require or configure bundler to handle CJS. ESM support is planned but not yet implemented. Always use require().","wrong":"import { getSourceCode } from 'eslint-compat-utils'","symbol":"getSourceCode","correct":"const { getSourceCode } = require('eslint-compat-utils')"},{"note":"No default export; import named exports only.","wrong":"const getCwd = require('eslint-compat-utils').default","symbol":"getCwd","correct":"const { getCwd } = require('eslint-compat-utils')"},{"note":"Same as above — CJS only for now.","wrong":"import { getFilename } from 'eslint-compat-utils'","symbol":"getFilename","correct":"const { getFilename } = require('eslint-compat-utils')"}],"quickstart":{"code":"// eslint rule using eslint-compat-utils\nconst { getSourceCode, getFilename } = require('eslint-compat-utils');\n\nmodule.exports = {\n  meta: {\n    type: 'suggestion',\n    docs: {\n      description: 'disallow use of process.env',\n    },\n    fixable: null,\n    schema: [],\n  },\n  create(context) {\n    const sourceCode = getSourceCode(context);\n    const filename = getFilename(context);\n    return {\n      MemberExpression(node) {\n        if (\n          node.object.type === 'Identifier' &&\n          node.object.name === 'process' &&\n          node.property.type === 'Identifier' &&\n          node.property.name === 'env'\n        ) {\n          context.report({\n            node,\n            message: 'Unexpected use of process.env in {{filename}}.',\n            data: { filename },\n          });\n        }\n      },\n    };\n  },\n};","lang":"javascript","description":"Shows an ESLint rule that uses getSourceCode and getFilename from eslint-compat-utils to remain compatible with ESLint v6–v9."},"warnings":[{"fix":"Pin to exact version or use stable alternatives like eslint-plugin-eslint-comments.","message":"Package is still experimental; API may change in minor versions.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Test rules against target ESLint versions; consider using try-catch for fallback.","message":"getScope() and other modern source code methods may behave differently or throw on older ESLint versions.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Use CommonJS require() or set up bundler to handle CJS.","message":"No ESM support – using import instead of require results in TypeError.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Prefer getFilename() if physical filename is not critical.","message":"getPhysicalFilename may return incorrect values for ESLint <7.28.0.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm install eslint-compat-utils --save-dev","cause":"Package not installed or missing from node_modules.","error":"Cannot find module 'eslint-compat-utils'"},{"fix":"Change to: const { getSourceCode } = require('eslint-compat-utils');","cause":"Trying to import ESM style with 'import', but package exports CJS only.","error":"TypeError: eslint_compat_utils_1.getSourceCode is not a function"},{"fix":"Upgrade eslint to >=6.0.0 and <10.0.0.","cause":"ESLint version is below 6.0.0 or above supported range.","error":"Error: eslint-compat-utils is not compatible with eslint version x.x.x"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}