Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitcb2361e

Browse files
committed
update rules for flat config
1 parentdd7aef3 commitcb2361e

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

‎lib/rules/async-currenttarget.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ module.exports = {
1010

1111
create(context){
1212
constscopeDidWait=newWeakSet()
13-
13+
constsourceCode=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-
letscope=context.getScope()
21+
letscope=sourceCode.getScope ?sourceCode.getScope(node) :context.getScope()
2122
while(scope){
2223
if(scopeDidWait.has(scope)){
2324
context.report({

‎lib/rules/async-preventdefault.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ module.exports = {
1010

1111
create(context){
1212
constscopeDidWait=newWeakSet()
13+
constsourceCode=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-
letscope=context.getScope()
21+
letscope=sourceCode.getScope ?sourceCode.getScope(node) :context.getScope()
2122
while(scope){
2223
if(scopeDidWait.has(scope)){
2324
context.report({

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ module.exports = {
2929
constdefaultRegexp=/^[a-z0-9-]+(.[a-z0-9-]+)?$/
3030
constconventionRegexp=context.options[0] ?newRegExp(context.options[0]) :defaultRegexp
3131
constignoreExporting=context.options[1] ?context.options[1] :false
32-
32+
3333
return{
3434
Program(node){
35-
constfilename=context.getFilename()
35+
constfilename=context.filename??context.getFilename()
3636
constabsoluteFilename=path.resolve(filename)
3737
constparsed=parseFilename(absoluteFilename)
3838
constshouldIgnore=isIgnoredFilename(filename)

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

Lines 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
constpassiveProp=options.properties[i]
3434
constl=options.properties.length
35-
constsource=context.getSourceCode()
35+
constsource=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

Lines 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

Lines 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',asyncfunction(event){
25+
// event.currentTarget will be an HTMLElement
26+
consturl=event.currentTarget.getAttribute('data-url')
27+
constdata=awaitfetch(url)
28+
29+
// But now, event.currentTarget will be null
30+
consttext=event.currentTarget.getAttribute('data-text')
31+
// ...
32+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp