Skip to content

Commit

Permalink
Lint more redundant activation events (microsoft#173186)
Browse files Browse the repository at this point in the history
* `onWalkthrough`
* `onTerminalQuickFixRequest`
* `onTerminalProfile`
* `onRenderer`
  • Loading branch information
joyceerhl authored Feb 2, 2023
1 parent 8922a50 commit b424430
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion extensions/extension-editing/src/extensionLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const allowedBadgeProviders: string[] = (product.extensionAllowedBadgeProviders
const allowedBadgeProvidersRegex: RegExp[] = (product.extensionAllowedBadgeProvidersRegex || []).map((r: string) => new RegExp(r));
const extensionEnabledApiProposals: Record<string, string[]> = product.extensionEnabledApiProposals ?? {};
const reservedImplicitActivationEventPrefixes = ['onNotebookSerializer:'];
const redundantImplicitActivationEventPrefixes = ['onLanguage:', 'onView:', 'onAuthenticationRequest:', 'onCommand:', 'onCustomEditor:'];
const redundantImplicitActivationEventPrefixes = ['onLanguage:', 'onView:', 'onAuthenticationRequest:', 'onCommand:', 'onCustomEditor:', 'onTerminalProfile:', 'onRenderer:', 'onTerminalQuickFixRequest:', 'onWalkthrough:'];

function isTrustedSVGSource(uri: Uri): boolean {
return allowedBadgeProviders.includes(uri.authority.toLowerCase()) || allowedBadgeProvidersRegex.some(r => r.test(uri.toString()));
Expand Down Expand Up @@ -453,5 +453,41 @@ function parseImplicitActivationEvents(tree: JsonNode): Set<string> {
});
});

// walkthroughs
const walkthroughs = findNodeAtLocation(tree, ['contributes', 'walkthroughs']);
walkthroughs?.children?.forEach(child => {
const id = findNodeAtLocation(child, ['id']);
if (id && id.type === 'string') {
activationEvents.add(`onWalkthrough:${id.value}`);
}
});

// notebookRenderers
const notebookRenderers = findNodeAtLocation(tree, ['contributes', 'notebookRenderer']);
notebookRenderers?.children?.forEach(child => {
const id = findNodeAtLocation(child, ['id']);
if (id && id.type === 'string') {
activationEvents.add(`onRenderer:${id.value}`);
}
});

// terminalProfiles
const terminalProfiles = findNodeAtLocation(tree, ['contributes', 'terminal', 'profiles']);
terminalProfiles?.children?.forEach(child => {
const id = findNodeAtLocation(child, ['id']);
if (id && id.type === 'string') {
activationEvents.add(`onTerminalProfile:${id.value}`);
}
});

// terminalQuickFixes
const terminalQuickFixes = findNodeAtLocation(tree, ['contributes', 'terminal', 'quickFixes']);
terminalQuickFixes?.children?.forEach(child => {
const id = findNodeAtLocation(child, ['id']);
if (id && id.type === 'string') {
activationEvents.add(`onTerminalQuickFixRequest:${id.value}`);
}
});

return activationEvents;
}

0 comments on commit b424430

Please sign in to comment.