Skip to content

Commit

Permalink
update rules for flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
gracepark committed Jan 6, 2025
1 parent dd7aef3 commit cb2361e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
9 changes: 5 additions & 4 deletions lib/rules/async-currenttarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ module.exports = {

create(context) {
const scopeDidWait = new WeakSet()

const sourceCode = context.sourceCode ?? context.getSourceCode()

Check failure on line 14 in lib/rules/async-currenttarget.js

View workflow job for this annotation

GitHub Actions / build (20)

Delete `····`

Check failure on line 14 in lib/rules/async-currenttarget.js

View workflow job for this annotation

GitHub Actions / build (22)

Delete `····`
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({
Expand Down
7 changes: 4 additions & 3 deletions lib/rules/async-preventdefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/filenames-match-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 32 in lib/rules/filenames-match-regex.js

View workflow job for this annotation

GitHub Actions / build (20)

Delete `····`

Check failure on line 32 in lib/rules/filenames-match-regex.js

View workflow job for this annotation

GitHub Actions / build (22)

Delete `····`
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)
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-useless-passive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand Down
4 changes: 3 additions & 1 deletion test-examples/flat/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
]
18 changes: 18 additions & 0 deletions test-examples/flat/src/getAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
// ...
})

0 comments on commit cb2361e

Please sign in to comment.