@@ -76,13 +76,12 @@ 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
- const scope =
84
- ( context . sourceCode || context . getSourceCode ( ) ) . getScope ?. ( node ) ||
85
- context . getScope ( ) ; // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
84
+ const scope = sourceCode . getScope ?. ( node ) || context . getScope ( ) ; // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
86
85
const staticValue = getStaticValue ( node , scope ) ;
87
86
if ( ! staticValue ) {
88
87
// If we can't find a static value, assume it's a real fix value.
@@ -100,7 +99,7 @@ module.exports = {
100
99
101
100
return {
102
101
Program ( ast ) {
103
- const sourceCode = context . sourceCode || context . getSourceCode ( ) ;
102
+ const sourceCode = context . sourceCode || context . getSourceCode ( ) ; // TODO: just use context.sourceCode when dropping eslint < v9
104
103
contextIdentifiers = utils . getContextIdentifiers (
105
104
sourceCode . scopeManager ,
106
105
ast
@@ -150,7 +149,8 @@ module.exports = {
150
149
// Ensure the current (arrow) fixer function returned a fix.
151
150
'ArrowFunctionExpression:exit' ( node ) {
152
151
if ( funcInfo . shouldCheck ) {
153
- const loc = context . getSourceCode ( ) . getTokenBefore ( node . body ) . loc ; // Show violation on arrow (=>).
152
+ const sourceCode = context . sourceCode || context . getSourceCode ( ) ;
153
+ const loc = sourceCode . getTokenBefore ( node . body ) . loc ; // Show violation on arrow (=>).
154
154
if ( node . expression ) {
155
155
// When the return is implied (no curly braces around the body), we have to check the single body node directly.
156
156
if ( ! isFix ( node . body ) ) {
0 commit comments