[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
This commit is contained in:
Lauren Tan
2023-06-15 12:52:57 -04:00
parent c416fb16ca
commit c402d8de76
@@ -23,7 +23,9 @@ const rule: Rule.RuleModule = {
},
},
create(context: Rule.RuleContext) {
const babelAST = parser.parse(context.sourceCode.text);
// Compat with older versions of eslint
const sourceCode = context.sourceCode?.text ?? context.getSourceCode().text;
const babelAST = parser.parse(sourceCode);
if (babelAST != null) {
traverse(babelAST, {
Program(prog) {