Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cb2361e

Browse filesBrowse files
committed
update rules for flat config
1 parent dd7aef3 commit cb2361e
Copy full SHA for cb2361e

File tree

Expand file treeCollapse file tree

6 files changed

+33
-11
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+33
-11
lines changed

‎lib/rules/async-currenttarget.js

Copy file name to clipboardExpand all lines: lib/rules/async-currenttarget.js
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ module.exports = {
1010

1111
create(context) {
1212
const scopeDidWait = new WeakSet()
13-
13+
const sourceCode = context.sourceCode ?? context.getSourceCode()
14+
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({

‎lib/rules/async-preventdefault.js

Copy file name to clipboardExpand all lines: lib/rules/async-preventdefault.js
+4-3Lines changed: 4 additions & 3 deletions
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({

‎lib/rules/filenames-match-regex.js

Copy file name to clipboardExpand all lines: lib/rules/filenames-match-regex.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ module.exports = {
2929
const defaultRegexp = /^[a-z0-9-]+(.[a-z0-9-]+)?$/
3030
const conventionRegexp = context.options[0] ? new RegExp(context.options[0]) : defaultRegexp
3131
const ignoreExporting = context.options[1] ? context.options[1] : false
32-
32+
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)

‎lib/rules/no-useless-passive.js

Copy file name to clipboardExpand all lines: lib/rules/no-useless-passive.js
+1-1Lines changed: 1 addition & 1 deletion
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.`,

‎test-examples/flat/eslint.config.mjs

Copy file name to clipboardExpand all lines: test-examples/flat/eslint.config.mjs
+3-1Lines changed: 3 additions & 1 deletion
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
]

‎test-examples/flat/src/getAttribute.js

Copy file name to clipboardExpand all lines: test-examples/flat/src/getAttribute.js
+18Lines changed: 18 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.