@@ -76,12 +76,13 @@ module.exports = {
76
76
* @returns {boolean }
77
77
*/
78
78
function isFix ( node ) {
79
+ const sourceCode = context . sourceCode || context . getSourceCode ( ) // TODO: use context.sourceCode when dropping eslint < v9
79
80
if ( node . type === 'ArrayExpression' && node . elements . length === 0 ) {
80
81
// An empty array is not a fix.
81
82
return false ;
82
83
}
83
84
const scope =
84
- ( context . sourceCode || context . getSourceCode ( ) ) . getScope ?. ( node ) ||
85
+ sourceCode . getScope ?. ( node ) ||
85
86
context . getScope ( ) ; // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
86
87
const staticValue = getStaticValue ( node , scope ) ;
87
88
if ( ! staticValue ) {
@@ -100,7 +101,7 @@ module.exports = {
100
101
101
102
return {
102
103
Program ( ast ) {
103
- const sourceCode = context . sourceCode || context . getSourceCode ( ) ;
104
+ const sourceCode = context . sourceCode || context . getSourceCode ( ) ; // just use context.sourceCode when dropping eslint < v9
104
105
contextIdentifiers = utils . getContextIdentifiers (
105
106
sourceCode . scopeManager ,
106
107
ast
@@ -150,7 +151,8 @@ module.exports = {
150
151
// Ensure the current (arrow) fixer function returned a fix.
151
152
'ArrowFunctionExpression:exit' ( node ) {
152
153
if ( funcInfo . shouldCheck ) {
153
- const loc = context . getSourceCode ( ) . getTokenBefore ( node . body ) . loc ; // Show violation on arrow (=>).
154
+ const sourceCode = context . sourceCode || context . getSourceCode ( ) ;
155
+ const loc = sourceCode . getTokenBefore ( node . body ) . loc ; // Show violation on arrow (=>).
154
156
if ( node . expression ) {
155
157
// When the return is implied (no curly braces around the body), we have to check the single body node directly.
156
158
if ( ! isFix ( node . body ) ) {
0 commit comments