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