-
Notifications
You must be signed in to change notification settings - Fork 39
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
fix: infer EventEmitter extensions from API #259
Changes from all commits
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
DocumentationBlock, | ||
DetailedFunctionType, | ||
DocumentationTag, | ||
ParsedDocumentationResult, | ||
} from '@electron/docs-parser'; | ||
import _ from 'lodash'; | ||
import d from 'debug'; | ||
|
@@ -257,34 +258,30 @@ export const paramify = (paramName: string) => { | |
} | ||
return paramName; | ||
}; | ||
// TODO: Infer through electron-docs-linter/parser | ||
export const isEmitter = (module: Pick<ModuleDocumentationContainer, 'name'>) => { | ||
const nonEventEmitters = [ | ||
'menuitem', | ||
'nativeimage', | ||
'shell', | ||
'browserview', | ||
'webrequest', | ||
'crashreporter', | ||
'dock', | ||
'commandline', | ||
'browserwindowproxy', | ||
'clipboard', | ||
'contenttracing', | ||
'desktopcapturer', | ||
'dialog', | ||
'globalshortcut', | ||
'powersaveblocker', | ||
'touchbar', | ||
'touchbarbutton', | ||
'net', | ||
'netlog', | ||
'protocol', | ||
'contextbridge', | ||
'webframe', | ||
'messagechannelmain', | ||
]; | ||
return !nonEventEmitters.includes(module.name.toLowerCase()); | ||
export const isEmitter = (doc: ParsedDocumentationResult[0]) => { | ||
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. nit: can we make this type cleaner by giving 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 do that, but |
||
// Is a module, has events, is an eventemitter | ||
if (doc.type === 'Module' && doc.events.length) { | ||
return true; | ||
} | ||
|
||
// Is a class, has instance events, is an eventemitter | ||
if (doc.type === 'Class' && doc.instanceEvents.length) { | ||
return true; | ||
} | ||
|
||
// Implements the on and removeListener methods normally means | ||
// it's an EventEmitter wrapper like ipcMain or ipcRenderer | ||
const relevantMethods = | ||
doc.type === 'Class' ? doc.instanceMethods : doc.type === 'Module' ? doc.methods : []; | ||
if ( | ||
relevantMethods.find(m => m.name === 'on') && | ||
relevantMethods.find(m => m.name === 'removeListener') | ||
) { | ||
return true; | ||
} | ||
|
||
// Structure and Elements are not eventemitters, so bail here | ||
return false; | ||
}; | ||
export const isPrimitive = (type: string) => { | ||
const primitives = ['boolean', 'number', 'any', 'string', 'void', 'unknown']; | ||
|
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.
@MarshallOfSound, was this debug code that got left in accidentally? Seeing the output on
e/e
now.