Skip to content

Commit 12f3162

Browse files
authored
Add diagnostics for summary plugin usage without a reporter. Closes #177 (#201)
1 parent c3f029b commit 12f3162

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Snippets: `devproxy-rewrite` - Dev Proxy rewrite
1515
- Snippets: `devproxy-plugin-rewrite-file` - RewritePlugin rewrites file
1616
- Snippets: `devproxy-plugin-rewrite-file-schema` - RewritePlugin rewrites file schema
17+
- Diagnostics: Show warning if config contains a summary plugin without a reporter
1718

1819
### Changed:
1920

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The following sections describe the features that the extension contributes to V
3838
- Check that at least one plugin is enabled
3939
- Check that a plugin can be configured with a configSection
4040
- Check for configSections that are not used in plugins
41+
- Check for reporter plugin when a summary plugin is used
4142

4243
### Editor Actions
4344

src/diagnostics.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const checkPlugins = (pluginsNode: parse.PropertyNode | undefined, diagnostics:
106106
checkAtLeastOneEnabledPlugin(pluginNodes, diagnostics, pluginsNode);
107107
warnOnReporterPosition(pluginNodes, diagnostics);
108108
validatePluginConfigurations(pluginNodes, diagnostics, documentNode);
109+
checkForSummaryPluginWithoutReporter(pluginNodes, diagnostics);
109110
}
110111
};
111112

@@ -290,3 +291,54 @@ const getObjectNodeFromDocument = (document: vscode.TextDocument): parse.ObjectN
290291
return parse(document.getText()) as parse.ObjectNode;
291292
};
292293

294+
function checkForSummaryPluginWithoutReporter(pluginNodes: parse.ObjectNode[], diagnostics: vscode.Diagnostic[]) {
295+
const summaryPluginNames = ['ExecutionSummaryPlugin', 'UrlDiscoveryPlugin'];
296+
297+
const summaryPlugin = pluginNodes.find((pluginNode: parse.ObjectNode) => {
298+
const pluginNameNode = getASTNode(
299+
pluginNode.children,
300+
'Identifier',
301+
'name'
302+
);
303+
const pluginName = (pluginNameNode?.value as parse.LiteralNode)
304+
.value as string;
305+
const enabledNode = getASTNode(
306+
pluginNode.children,
307+
'Identifier',
308+
'enabled'
309+
);
310+
const isEnabled = (enabledNode?.value as parse.LiteralNode)
311+
.value as boolean;
312+
return summaryPluginNames.includes(pluginName) && isEnabled;
313+
});
314+
315+
if (summaryPlugin) {
316+
const reporterPlugin = pluginNodes.find((pluginNode: parse.ObjectNode) => {
317+
const pluginNameNode = getASTNode(
318+
pluginNode.children,
319+
'Identifier',
320+
'name'
321+
);
322+
const pluginName = (pluginNameNode?.value as parse.LiteralNode)
323+
.value as string;
324+
const enabledNode = getASTNode(
325+
pluginNode.children,
326+
'Identifier',
327+
'enabled'
328+
);
329+
const isEnabled = (enabledNode?.value as parse.LiteralNode)
330+
.value as boolean;
331+
return pluginName.toLowerCase().includes('reporter') && isEnabled;
332+
});
333+
334+
if (!reporterPlugin) {
335+
diagnostics.push(
336+
new vscode.Diagnostic(
337+
getRangeFromASTNode(summaryPlugin),
338+
`Summary plugins should be used with a reporter plugin.`,
339+
vscode.DiagnosticSeverity.Warning
340+
)
341+
);
342+
}
343+
}
344+
}

0 commit comments

Comments
 (0)