@samitouri / QOS-React-2 / commits / c402d8de76

[eslint-plugin] Fall back to context.getSourceCode()

Older versions of eslint use the deprecated method, so add a fallback in the event a modern version of eslint isn't available

Lauren Tan committed Jun 15, 2023 at 12:52 UTC c402d8de7667dc71d36a4768b7b0ca4d032e6778
1 file changed +3 -1
compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts
+3 -1
@@ -23,7 +23,9 @@ const rule: Rule.RuleModule = {
23 },
24 },
25 create(context: Rule.RuleContext) {
26 - const babelAST = parser.parse(context.sourceCode.text);
26 + // Compat with older versions of eslint
27 + const sourceCode = context.sourceCode?.text ?? context.getSourceCode().text;
28 + const babelAST = parser.parse(sourceCode);
29 if (babelAST != null) {
30 traverse(babelAST, {
31 Program(prog) {