Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 52 additions & 0 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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
)
);
}
}
}