File tree 2 files changed +28
-9
lines changed
2 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -139,15 +139,26 @@ function getRuleExportsESM(ast, scopeManager) {
139
139
possibleNodes . push ( specifier . local ) ;
140
140
}
141
141
if ( statement . declaration ) {
142
- if ( statement . declaration . type === 'VariableDeclaration' ) {
143
- for ( const declarator of statement . declaration . declarations ) {
144
- if ( declarator . init ) {
145
- possibleNodes . push ( declarator . init ) ;
146
- }
147
- }
148
- } else {
149
- possibleNodes . push ( statement . declaration ) ;
150
- }
142
+ let nodes = [ ] ;
143
+
144
+ nodes =
145
+ statement . declaration . type === 'VariableDeclaration'
146
+ ? statement . declaration . declarations . map (
147
+ ( declarator ) => declarator . init
148
+ )
149
+ : [ statement . declaration ] ;
150
+
151
+ // named exports like `export const rule = { ... };`
152
+ // skip if it's function-style to avoid false positives
153
+ // refs: https://github.com/eslint-community/eslint-plugin-eslint-plugin/issues/450
154
+ possibleNodes . push (
155
+ ...nodes . filter (
156
+ ( node ) =>
157
+ node &&
158
+ node . type !== 'FunctionDeclaration' &&
159
+ node . type !== 'FunctionExpression'
160
+ )
161
+ ) ;
151
162
}
152
163
break ;
153
164
}
Original file line number Diff line number Diff line change @@ -86,6 +86,14 @@ describe('utils', () => {
86
86
'export default function () { return {}; }' ,
87
87
'export default function (foo, bar) { return {}; }' ,
88
88
89
+ // named export of functions
90
+ // refs: https://github.com/eslint-community/eslint-plugin-eslint-plugin/issues/450
91
+ 'export function foo(options) { return {}; }' ,
92
+ 'export async function foo(options) { return {}; }' ,
93
+ 'export const foo = function (options) { return {}; }' ,
94
+ 'export function foo(options) { return; }' ,
95
+ 'export function foo({opt1, opt2}) { return {}; }' ,
96
+
89
97
// Incorrect TypeScript helper structure:
90
98
'export default foo()({ create() {}, meta: {} });' ,
91
99
'export default foo().bar({ create() {}, meta: {} });' ,
You can’t perform that action at this time.
0 commit comments