plugin-activation-args
Ensure JupyterLab plugin activate arguments match the order and count of requires and optional tokens.
Why
Mismatched activation signatures can lead to runtime bugs and subtle plugin initialization failures. This rule enforces a consistent, predictable contract.
Rule details
This rule reports the following errors:
mismatchedOrder— arguments are in the wrong order (requires type-aware checking)incorrectType— an argument's type annotation does not match its token (requires type-aware checking)appNotFirst— first argument name is not one of the allowed names (e.g.app)invalidAppType— first argument type is not compatible withJupyterFrontEndwrongArgumentCount— argument count does not match1 + requires.length + optional.lengthmissingArgument— a token fromrequires/optionalhas no corresponding argumentextraArgument— an argument has no corresponding token inrequires/optionalserviceManagerFirstArgNotNull—ServiceManagerPluginfirst argument is notnulloptionalNotNullable— an argument for anoptionaltoken is missing| nullor| undefined
Incorrect
const plugin: JupyterFrontEndPlugin<void> = {
id: 'test-plugin',
requires: [INotebookTracker, IRenderMimeRegistry],
activate: (tracker: INotebookTracker, app: JupyterFrontEnd) => {
console.log('Activated');
}
};
Correct
const plugin: JupyterFrontEndPlugin<void> = {
id: 'test-plugin',
requires: [INotebookTracker, IRenderMimeRegistry],
optional: [ITranslator],
activate: (
app: JupyterFrontEnd,
tracker: INotebookTracker,
renderMime: IRenderMimeRegistry,
translator: ITranslator | null
) => {
console.log('Activated');
}
};
Type-aware checking
The two errors marked (requires type-aware checking) above need TypeScript type information to work reliably. Without it, those checks are skipped and the errors will go unreported. You may also see unresolvableTokenType warnings frequently.
Strongly recommended: configure
parserOptions.projectorprojectServicein your ESLint setup to enable full type-aware checking.
Options
{
"allowedFirstArgumentNames": ["app", "_app", "_"]
}
Use this option to permit your team’s preferred name for the first activate argument.