From a540849460ebf828099bca84fdb6fc189a5bf0e5 Mon Sep 17 00:00:00 2001 From: Garry Trinder Date: Tue, 25 Feb 2025 16:47:37 +0000 Subject: [PATCH 1/2] Add diagnostics for summary plugin usage without a reporter. Closes #177 Closes #177 --- CHANGELOG.md | 1 + README.md | 1 + src/diagnostics.ts | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df487f7..be27e02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Snippets: `devproxy-rewrite` - Dev Proxy rewrite - Snippets: `devproxy-plugin-rewrite-file` - RewritePlugin rewrites file - Snippets: `devproxy-plugin-rewrite-file-schema` - RewritePlugin rewrites file schema +- Diagnostics: Show warning if config contains a summary plugin without a reporter ### Changed: diff --git a/README.md b/README.md index fb2e2d6..71226e9 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ The following sections describe the features that the extension contributes to V - Check that at least one plugin is enabled - Check that a plugin can be configured with a configSection - Check for configSections that are not used in plugins +- Check for reporter plugin when a summary plugin is used ### Editor Actions diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 3142640..2aceb5c 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -106,6 +106,7 @@ const checkPlugins = (pluginsNode: parse.PropertyNode | undefined, diagnostics: checkAtLeastOneEnabledPlugin(pluginNodes, diagnostics, pluginsNode); warnOnReporterPosition(pluginNodes, diagnostics); validatePluginConfigurations(pluginNodes, diagnostics, documentNode); + checkForSummaryPluginWithoutReporter(pluginNodes, diagnostics); } }; @@ -290,3 +291,38 @@ const getObjectNodeFromDocument = (document: vscode.TextDocument): parse.ObjectN return parse(document.getText()) as parse.ObjectNode; }; +function checkForSummaryPluginWithoutReporter(pluginNodes: parse.ObjectNode[], diagnostics: vscode.Diagnostic[]) { + const summaryPluginNames = ['ExecutionSummaryPlugin', 'UrlDiscoveryPlugin']; + + const summaryPlugin = pluginNodes.find((pluginNode: parse.ObjectNode) => { + const pluginNameNode = getASTNode( + pluginNode.children, + 'Identifier', + 'name' + ); + const pluginName = (pluginNameNode?.value as parse.LiteralNode) + .value as string; + return summaryPluginNames.includes(pluginName); + }); + if (summaryPlugin) { + const reporterPlugin = pluginNodes.find((pluginNode: parse.ObjectNode) => { + const pluginNameNode = getASTNode( + pluginNode.children, + 'Identifier', + 'name' + ); + const pluginName = (pluginNameNode?.value as parse.LiteralNode) + .value as string; + return pluginName.toLowerCase().includes('reporter'); + }); + if (!reporterPlugin) { + diagnostics.push( + new vscode.Diagnostic( + getRangeFromASTNode(summaryPlugin), + `Summary plugins should be used with a reporter plugin.`, + vscode.DiagnosticSeverity.Warning + ) + ); + } + } +} \ No newline at end of file From 5bf5396d05b4818baf322616f06536272d4ef90e Mon Sep 17 00:00:00 2001 From: Garry Trinder Date: Tue, 25 Feb 2025 16:55:01 +0000 Subject: [PATCH 2/2] Enhance summary plugin diagnostics to check for enabled state. --- src/diagnostics.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 2aceb5c..472c15f 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -302,8 +302,16 @@ function checkForSummaryPluginWithoutReporter(pluginNodes: parse.ObjectNode[], d ); const pluginName = (pluginNameNode?.value as parse.LiteralNode) .value as string; - return summaryPluginNames.includes(pluginName); + const enabledNode = getASTNode( + pluginNode.children, + 'Identifier', + 'enabled' + ); + const isEnabled = (enabledNode?.value as parse.LiteralNode) + .value as boolean; + return summaryPluginNames.includes(pluginName) && isEnabled; }); + if (summaryPlugin) { const reporterPlugin = pluginNodes.find((pluginNode: parse.ObjectNode) => { const pluginNameNode = getASTNode( @@ -313,8 +321,16 @@ function checkForSummaryPluginWithoutReporter(pluginNodes: parse.ObjectNode[], d ); const pluginName = (pluginNameNode?.value as parse.LiteralNode) .value as string; - return pluginName.toLowerCase().includes('reporter'); + const enabledNode = getASTNode( + pluginNode.children, + 'Identifier', + 'enabled' + ); + const isEnabled = (enabledNode?.value as parse.LiteralNode) + .value as boolean; + return pluginName.toLowerCase().includes('reporter') && isEnabled; }); + if (!reporterPlugin) { diagnostics.push( new vscode.Diagnostic(