diff --git a/lib/rules/async-currenttarget.js b/lib/rules/async-currenttarget.js index 0b5dff95..9828e17d 100644 --- a/lib/rules/async-currenttarget.js +++ b/lib/rules/async-currenttarget.js @@ -10,14 +10,15 @@ module.exports = { create(context) { const scopeDidWait = new WeakSet() - + const sourceCode = context.sourceCode ?? context.getSourceCode() + return { - AwaitExpression() { - scopeDidWait.add(context.getScope()) + AwaitExpression(node) { + scopeDidWait.add(sourceCode.getScope ? sourceCode.getScope(node) : context.getScope()) }, MemberExpression(node) { if (node.property && node.property.name === 'currentTarget') { - let scope = context.getScope() + let scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope() while (scope) { if (scopeDidWait.has(scope)) { context.report({ diff --git a/lib/rules/async-preventdefault.js b/lib/rules/async-preventdefault.js index 33bd34b2..f4154bf0 100644 --- a/lib/rules/async-preventdefault.js +++ b/lib/rules/async-preventdefault.js @@ -10,14 +10,15 @@ module.exports = { create(context) { const scopeDidWait = new WeakSet() + const sourceCode = context.sourceCode ?? context.getSourceCode() return { - AwaitExpression() { - scopeDidWait.add(context.getScope()) + AwaitExpression(node) { + scopeDidWait.add(sourceCode.getScope ? sourceCode.getScope(node) : context.getScope()) }, CallExpression(node) { if (node.callee.property && node.callee.property.name === 'preventDefault') { - let scope = context.getScope() + let scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope() while (scope) { if (scopeDidWait.has(scope)) { context.report({ diff --git a/lib/rules/filenames-match-regex.js b/lib/rules/filenames-match-regex.js index f50952c5..8e3ea341 100644 --- a/lib/rules/filenames-match-regex.js +++ b/lib/rules/filenames-match-regex.js @@ -29,10 +29,10 @@ module.exports = { const defaultRegexp = /^[a-z0-9-]+(.[a-z0-9-]+)?$/ const conventionRegexp = context.options[0] ? new RegExp(context.options[0]) : defaultRegexp const ignoreExporting = context.options[1] ? context.options[1] : false - + return { Program(node) { - const filename = context.getFilename() + const filename = context.filename ?? context.getFilename() const absoluteFilename = path.resolve(filename) const parsed = parseFilename(absoluteFilename) const shouldIgnore = isIgnoredFilename(filename) diff --git a/lib/rules/no-useless-passive.js b/lib/rules/no-useless-passive.js index 5e771884..e472b5b8 100644 --- a/lib/rules/no-useless-passive.js +++ b/lib/rules/no-useless-passive.js @@ -32,7 +32,7 @@ module.exports = { if (i === -1) return const passiveProp = options.properties[i] const l = options.properties.length - const source = context.getSourceCode() + const source = context.sourceCode ?? context.getSourceCode() context.report({ node: passiveProp, message: `"${name.value}" event listener is not cancellable and so \`passive: true\` does nothing.`, diff --git a/test-examples/flat/eslint.config.mjs b/test-examples/flat/eslint.config.mjs index 0ff163c1..d6b1cefa 100644 --- a/test-examples/flat/eslint.config.mjs +++ b/test-examples/flat/eslint.config.mjs @@ -13,7 +13,9 @@ export default [ 'github/no-then': 'error', 'github/no-blur': 'error', 'github/async-preventdefault': 'error', - 'github/filenames-match-regex': ['error', '^([a-z0-9]+)([A-Z][a-z0-9]+)*$'], + 'github/async-currenttarget': 'error', + 'github/no-useless-passive': 'error', + 'github/filenames-match-regex': 'error', }, }, ] diff --git a/test-examples/flat/src/getAttribute.js b/test-examples/flat/src/getAttribute.js index bccff298..d708c404 100644 --- a/test-examples/flat/src/getAttribute.js +++ b/test-examples/flat/src/getAttribute.js @@ -12,3 +12,21 @@ document.addEventListener('click', async function (event) { event.preventDefault() }) + +window.addEventListener( + 'scroll', + () => { + console.log('Scroll event fired!') + }, + {passive: true}, +) + +document.addEventListener('click', async function (event) { + // event.currentTarget will be an HTMLElement + const url = event.currentTarget.getAttribute('data-url') + const data = await fetch(url) + + // But now, event.currentTarget will be null + const text = event.currentTarget.getAttribute('data-text') + // ... +})