-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [explicit-function-return-type] add allowIIFEs option #6237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dd7e799
3f8a981
a242fb7
75a520d
28f2a6a
0739ae5
d3e168c
47cf0c5
a6fba09
9c7da1b
10f64e0
7affa5b
2657eb6
0af3c21
1c702dc
f18a367
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -595,6 +595,132 @@ const x: Bar<Foo> = arg1 => arg2 => arg1 + arg2; | |
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
let foo = function (): number { | ||
return 1; | ||
}; | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
const foo = (function () { | ||
return 1; | ||
})(); | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
const foo = (() => { | ||
return 1; | ||
})(); | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
const foo = ((arg: number): number => { | ||
return arg; | ||
})(0); | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
const foo = (() => (() => 'foo')())(); | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
let foo = (() => (): string => { | ||
return 'foo'; | ||
})()(); | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
let foo = (() => (): string => { | ||
return 'foo'; | ||
})(); | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
allowHigherOrderFunctions: false, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
let foo = (() => (): string => { | ||
return 'foo'; | ||
})()(); | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
allowHigherOrderFunctions: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
let foo = (() => (): void => {})()(); | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
let foo = (() => (() => {})())(); | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
}, | ||
], | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
|
@@ -1477,5 +1603,93 @@ class Foo { | |
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
const foo = (function () { | ||
return 'foo'; | ||
})(); | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: false, | ||
}, | ||
], | ||
errors: [ | ||
{ | ||
messageId: 'missingReturnType', | ||
line: 2, | ||
endLine: 2, | ||
column: 14, | ||
endColumn: 25, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
const foo = (function () { | ||
return () => { | ||
return 1; | ||
}; | ||
})(); | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
}, | ||
], | ||
errors: [ | ||
{ | ||
messageId: 'missingReturnType', | ||
line: 3, | ||
endLine: 3, | ||
column: 10, | ||
endColumn: 15, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
let foo = function () { | ||
return 'foo'; | ||
}; | ||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
}, | ||
], | ||
errors: [ | ||
{ | ||
messageId: 'missingReturnType', | ||
line: 2, | ||
endLine: 2, | ||
column: 11, | ||
endColumn: 22, | ||
}, | ||
], | ||
}, | ||
{ | ||
filename: 'test.ts', | ||
code: ` | ||
let foo = (() => () => {})()(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JoshuaKGoldberg const foo = (() => () => "foo")()(); // error
const bar = (() => (() => "foo")())(); // pass Should both cases be passed when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yeonjuan The first one IMO is not an "IIFE" by definition— There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would agree with that assessment. |
||
`, | ||
options: [ | ||
{ | ||
allowIIFEs: true, | ||
}, | ||
], | ||
errors: [ | ||
{ | ||
messageId: 'missingReturnType', | ||
line: 2, | ||
endLine: 2, | ||
column: 18, | ||
endColumn: 23, | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a bit more test coverage:
(() => () => {})()()
)