Skip to content

Commit 1b65401

Browse files
authored
Merge pull request #596 from github/update-flat-config-rules
Update rules for flat config
2 parents 64e6389 + 75978c8 commit 1b65401

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

Diff for: lib/rules/async-currenttarget.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ module.exports = {
1010

1111
create(context) {
1212
const scopeDidWait = new WeakSet()
13+
const sourceCode = context.sourceCode ?? context.getSourceCode()
1314

1415
return {
15-
AwaitExpression() {
16-
scopeDidWait.add(context.getScope())
16+
AwaitExpression(node) {
17+
scopeDidWait.add(sourceCode.getScope ? sourceCode.getScope(node) : context.getScope())
1718
},
1819
MemberExpression(node) {
1920
if (node.property && node.property.name === 'currentTarget') {
20-
let scope = context.getScope()
21+
let scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope()
2122
while (scope) {
2223
if (scopeDidWait.has(scope)) {
2324
context.report({

Diff for: lib/rules/async-preventdefault.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ module.exports = {
1010

1111
create(context) {
1212
const scopeDidWait = new WeakSet()
13+
const sourceCode = context.sourceCode ?? context.getSourceCode()
1314

1415
return {
15-
AwaitExpression() {
16-
scopeDidWait.add(context.getScope())
16+
AwaitExpression(node) {
17+
scopeDidWait.add(sourceCode.getScope ? sourceCode.getScope(node) : context.getScope())
1718
},
1819
CallExpression(node) {
1920
if (node.callee.property && node.callee.property.name === 'preventDefault') {
20-
let scope = context.getScope()
21+
let scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope()
2122
while (scope) {
2223
if (scopeDidWait.has(scope)) {
2324
context.report({

Diff for: lib/rules/filenames-match-regex.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232

3333
return {
3434
Program(node) {
35-
const filename = context.getFilename()
35+
const filename = context.filename ?? context.getFilename()
3636
const absoluteFilename = path.resolve(filename)
3737
const parsed = parseFilename(absoluteFilename)
3838
const shouldIgnore = isIgnoredFilename(filename)

Diff for: lib/rules/no-useless-passive.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232
if (i === -1) return
3333
const passiveProp = options.properties[i]
3434
const l = options.properties.length
35-
const source = context.getSourceCode()
35+
const source = context.sourceCode ?? context.getSourceCode()
3636
context.report({
3737
node: passiveProp,
3838
message: `"${name.value}" event listener is not cancellable and so \`passive: true\` does nothing.`,

Diff for: test-examples/flat/eslint.config.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export default [
1313
'github/no-then': 'error',
1414
'github/no-blur': 'error',
1515
'github/async-preventdefault': 'error',
16-
'github/filenames-match-regex': ['error', '^([a-z0-9]+)([A-Z][a-z0-9]+)*$'],
16+
'github/async-currenttarget': 'error',
17+
'github/no-useless-passive': 'error',
18+
'github/filenames-match-regex': 'error',
1719
},
1820
},
1921
]

Diff for: test-examples/flat/src/getAttribute.js

+18
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@ document.addEventListener('click', async function (event) {
1212

1313
event.preventDefault()
1414
})
15+
16+
window.addEventListener(
17+
'scroll',
18+
() => {
19+
console.log('Scroll event fired!')
20+
},
21+
{passive: true},
22+
)
23+
24+
document.addEventListener('click', async function (event) {
25+
// event.currentTarget will be an HTMLElement
26+
const url = event.currentTarget.getAttribute('data-url')
27+
const data = await fetch(url)
28+
29+
// But now, event.currentTarget will be null
30+
const text = event.currentTarget.getAttribute('data-text')
31+
// ...
32+
})

0 commit comments

Comments
 (0)