eslint-plugin-chai-friendly icon indicating copy to clipboard operation
eslint-plugin-chai-friendly copied to clipboard

`context.getAncestors is not a function` with eslint 9.0.0

Open jpzwarte opened this issue 10 months ago • 6 comments

Oops! Something went wrong! :(

ESLint: 9.0.0

TypeError: context.getAncestors is not a function
Occurred while linting /accordion/src/accordion.spec.ts:37
Rule: "chai-friendly/no-unused-expressions"
    at ExpressionStatement (/Users/jzwartepoorte/Projects/components/node_modules/eslint-plugin-chai-friendly/lib/rules/no-unused-expressions.js:262:50)

Works fine with eslint 8.57.0

Uses version 0.7.4 of the plugin.

jpzwarte avatar Apr 15 '24 08:04 jpzwarte

Hi @jpzwarte! Will look into eslint 9 compatibility this week

ihordiachenko avatar Apr 21 '24 22:04 ihordiachenko

Just encountered this. Is there a workaround?

Oops! Something went wrong! :(

ESLint: 9.1.1

TypeError: context.getAncestors is not a function
Occurred while linting [...]/test/common-helpers.ts:240
Rule: "chai-friendly/no-unused-expressions"
    at ExpressionStatement ([...]/test/node_modules/eslint-plugin-chai-friendly/lib/rules/no-unused-expressions.js:262:50)
    at ruleErrorHandler ([...]/test/node_modules/eslint/lib/linter/linter.js:1115:48)
    at [...]/test/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit ([...]/test/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector ([...]/test/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors ([...]/test/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode ([...]/test/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at runRules ([...]/test/node_modules/eslint/lib/linter/linter.js:1154:40)
    at Linter._verifyWithFlatConfigArrayAndWithoutProcessors ([...]/test/node_modules/eslint/lib/linter/linter.js:1880:31)

crfrolik avatar Apr 24 '24 20:04 crfrolik

@ihordiachenko

https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/ gives a code example for updating context.getAncestors() so that it is compatible with ESLint >= 9.0.0 and earlier versions.

MikeMcC399 avatar May 04 '24 16:05 MikeMcC399

@crfrolik

Just encountered this. Is there a workaround?

Oops! Something went wrong! :(

ESLint: 9.1.1

TypeError: context.getAncestors is not a function

ESLint published the Blog post Introducing ESLint Compatibility Utilities yesterday announcing a new utility @eslint/compat to work around compatibility issues like this.

MikeMcC399 avatar May 10 '24 07:05 MikeMcC399

@ihordiachenko

Would you like a PR to fix this issue or are you already planning to do it yourself?

MikeMcC399 avatar May 12 '24 14:05 MikeMcC399

@ihordiachenko

  • I went ahead and submitted PR https://github.com/ihordiachenko/eslint-plugin-chai-friendly/pull/33 to resolve this issue.

MikeMcC399 avatar May 13 '24 11:05 MikeMcC399

@MikeMcC399 released in [email protected]

ihordiachenko avatar May 23 '24 12:05 ihordiachenko

@ihordiachenko

released in [email protected]

Thank you very much! I am just testing with Cypress and ESLint v9 flat configuration and it all looks good! 👍🏻

MikeMcC399 avatar May 23 '24 15:05 MikeMcC399