ESLint v9 compatibility
Currently, using [email protected], eslint-plugin-deprecation fails with the following error:
An unexpected error occurred:
TypeError: context.getAncestors is not a function
Occurred while linting /Users/k/p/project/eslint.config.js:1
Rule: "deprecation/deprecation"
at getParent (/Users/k/p/project/node_modules/eslint-plugin-deprecation/dist/rules/deprecation.js:86:31)
at isDeclaration (/Users/k/p/project/node_modules/eslint-plugin-deprecation/dist/rules/deprecation.js:94:20)
at identifierRule (/Users/k/p/project/node_modules/eslint-plugin-deprecation/dist/rules/deprecation.js:60:13)
at ruleErrorHandler (/Users/k/p/project/node_modules/eslint/lib/linter/linter.js:1059:28)
at /Users/k/p/project/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Users/k/p/project/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Users/k/p/project/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
at NodeEventGenerator.applySelectors (/Users/k/p/project/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
at NodeEventGenerator.enterNode (/Users/k/p/project/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
It looks like there's a blog post about preparing rules for ESLint v9 here:
- https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/
From a quick look, it appears that context.sourceCode.getAncestors(node) should be used instead.
@karlhorky thanks for testing it with eslint v9!
Indeed there are some BC that have to be addressed in order to support v9.
If you like you are welcome to create a PR to fix this piece of code but it should be done in backwards compatible way just like they show in example, so we can keep supporting all previous eslint versions.
Also if you decide to make a PR it would be necessary to update CI workflows to test this rule against both eslint v8 and v9, just like we already do with previous versions. But if you are not comfortable doing it no worries, I can adjust it on your PR as well 😊
Did some initial work on the v9 support but in general it's not possible to use it due to upstream dependencies not supporting it yet.
typescript-eslint are at least preparing for it now, but this lib may need to also upgrade @typescript-eslint/utils to 7.x first.
https://typescript-eslint.io/blog/announcing-typescript-eslint-v7/
They are dropping support for older typescript, node and eslint versions in that major (but otherwise it is unchanged). I look into adding support here for 6.x and 7.x at the same time, but I'm not sure that can work nicely without being a breaking change, due to how npm resolution works. As long as this library itself wants to support older eslint and node versions than typescript-eslint 7.x I'm not sure we can just add 7.x to the list of supported versions next to 6.x?
Another data point: I'm upgrading my [email protected] config to use "flat config" and the @ts-check flags this plugin being incorrectly typed.
How is work going forward? This is blocking us from upgrading to eslint v9 and we cant already upgrade eslint-plugin-vitest >=0.5 due to this
I'm seeing the following problem after upgrading to eslint 9:
ESLint: 9.2.0
Error: Error while loading rule 'deprecation/deprecation': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser. Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward "parserOptions.project" to @typescript-eslint/parser.
My config looks like this:
const eslintJs = require('@eslint/js');
const eslintTs = require('typescript-eslint');
const pluginDeprecation = require('eslint-plugin-deprecation');
const config = {
languageOptions: {
parser: eslintTs.parser,
parserOptions: {
project: 'tsconfig.lint.json'
}
},
plugins: {
deprecation: pluginDeprecation,
'@typescript-eslint': eslintTs.plugin
},
rules: {
'deprecation/deprecation': 'error'
}
}
module.exports = eslintTs.config(
eslintJs.configs.recommended,
...eslintTs.configs.strictTypeChecked,
...eslintTs.configs.stylisticTypeChecked,
config
);
Am I doing it wrong or is this a compatibility issue?
@ej612 In my case, it was due to having the rules active for JS files. Disabling type-aware rules in my JS files solved the problem.
To then get it working with ESLint 9, I had to use @eslint/compat's fixupPluginRules function.
This is what the final config looked like:
import { fixupPluginRules } from "@eslint/compat";
import deprecationPlugin from "eslint-plugin-deprecation";
import tseslint from "typescript-eslint";
export default [
{
plugins: {
["@typescript-eslint"]: tseslint.plugin,
["deprecation"]: fixupPluginRules(deprecationPlugin),
},
languageOptions: {
parserOptions: {
project: true,
},
},
},
{
files: ["**/*.js"],
// Don't typecheck JS files
extends: [tseslint.configs.disableTypeChecked],
// Disable type-aware rules
rules: {
"deprecation/deprecation": "off",
},
},
];
@ej612 In my case, it was due to having the rules active for JS files. Disabling type-aware rules in my JS files solved the problem.
To then get it working with ESLint 9, I had to use
@eslint/compat'sfixupPluginRulesfunction.This is what the final config looked like:
import { fixupPluginRules } from "@eslint/compat"; import deprecationPlugin from "eslint-plugin-deprecation"; import tseslint from "typescript-eslint"; export default [ { plugins: { ["@typescript-eslint"]: tseslint.plugin, ["deprecation"]: fixupPluginRules(deprecationPlugin), }, languageOptions: { parserOptions: { project: true, }, }, }, { files: ["**/*.js"], // Don't typecheck JS files extends: [tseslint.configs.disableTypeChecked], // Disable type-aware rules rules: { "deprecation/deprecation": "off", }, }, ];
this worked for me, thanks!
Hi, typescript-eslint released v8 yesterday with full eslint v9 support, is there something to be done to move this forward?
Thanks!
Workaround (switch from eslint-plugin-deprecation to @typescript-eslint/no-deprecated)
Cross-posting my comment in PR #79 for visibility:
For anyone wanting a rule like the one included in eslint-plugin-deprecation with support for ESLint v9, you can also consider switching to the typescript-eslint rule @typescript-eslint/no-deprecated, which was released recently in [email protected]:
- Docs: https://typescript-eslint.io/rules/no-deprecated/
- Issue: https://github.com/typescript-eslint/typescript-eslint/issues/8988
- PR: https://github.com/typescript-eslint/typescript-eslint/pull/9783
Diff:
-import deprecation from 'eslint-plugin-deprecation';
// ...
plugins: {
'eslint-comments': eslintComments,
- deprecation: fixupPluginRules(
- /** @type {import("eslint").ESLint.Plugin} */ (
- /** @type {unknown} */ (deprecation)
- ),
- ),
},
// ...
rules: {
- // Warn about usage of deprecated APIs
- // https://github.com/gund/eslint-plugin-deprecation
- 'deprecation/deprecation': 'warn',
+ // Warn about usage of deprecated APIs
+ // https://typescript-eslint.io/rules/no-deprecated/
+ '@typescript-eslint/no-deprecated': 'warn',
Caveat: In my first testing, it felt like it may be slower than eslint-plugin-deprecation.
Push! Would really love to update to v9 as well! Hope you are making progress on the PR and release soon 👀
Hey folks, sorry for a delay.
This rule has been migrated to typescript-eslint project and is now maintained there. The docs for the new rule can be found here.
It also supports ESlint v9.
This repo is going to be archived and no longer maintained going forward.
Cheers!