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..472c15f 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,54 @@ 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; + 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( + pluginNode.children, + 'Identifier', + 'name' + ); + const pluginName = (pluginNameNode?.value as parse.LiteralNode) + .value as string; + 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( + getRangeFromASTNode(summaryPlugin), + `Summary plugins should be used with a reporter plugin.`, + vscode.DiagnosticSeverity.Warning + ) + ); + } + } +} \ No newline at end of file