Skip to content

Commit e4575c2

Browse files
committed
Add reporter placement check in config files. Closes #84
1 parent 7f09072 commit e4575c2

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- CodeLens: `JsonReporter`
1616
- CodeLens: `MarkdownReporter`
1717
- CodeLens: `PlainTextReporter`
18+
- Config diagnostic: Show warning if plugins follow a reporter in the plugins array
1819

1920
### Changed:
2021

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The following sections describe the features that the extension contributes to V
1818
- Check for missing `configSection` property in plugin instance for plugins that require configuration
1919
- Check for missing `configSection` when defined in plugin instance
2020
- Check that schema matches installed version of Dev Proxy
21+
- Check that reporters are placed after plugins
2122

2223
### Code Actions
2324

src/diagnostics.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,46 @@ export const updateDiagnostics = (
5656
);
5757
}
5858

59+
// check if we have any plugins that contain the name reporter in the plugins node
60+
const reporterIndex = pluginNodes.findIndex((pluginNode: parse.ObjectNode) => {
61+
const pluginNameNode = getASTNode(
62+
pluginNode.children,
63+
'Identifier',
64+
'name'
65+
);
66+
const pluginName = (pluginNameNode?.value as parse.LiteralNode)
67+
.value as string;
68+
return pluginName.toLowerCase().includes('reporter');
69+
});
70+
71+
if (reporterIndex !== -1) {
72+
// check if we have any more plugins after the reporter plugin
73+
const pluginsAfterReporter = pluginNodes.slice(reporterIndex + 1);
74+
// if we do, add a warning to the reporter plugin stating that it should be the last plugin
75+
if (pluginsAfterReporter.length > 0) {
76+
// check if there are any plugins after the reporter plugin that are not reporters
77+
const pluginAfterReporter = pluginsAfterReporter.find((pluginNode: parse.ObjectNode) => {
78+
const pluginNameNode = getASTNode(
79+
pluginNode.children,
80+
'Identifier',
81+
'name'
82+
);
83+
const pluginName = (pluginNameNode?.value as parse.LiteralNode)
84+
.value as string;
85+
return !pluginName.toLowerCase().includes('reporter');
86+
});
87+
// if there are, add a warning to the reporter plugin
88+
if (pluginAfterReporter) {
89+
const diagnostic = new vscode.Diagnostic(
90+
getRangeFromASTNode(pluginNodes[reporterIndex]),
91+
'Reporters should be placed after other plugins.',
92+
vscode.DiagnosticSeverity.Warning
93+
);
94+
diagnostics.push(diagnostic);
95+
}
96+
}
97+
}
98+
5999
// does the plugin have a config section?
60100
pluginNodes.forEach((pluginNode: parse.ObjectNode) => {
61101
const pluginNameNode = getASTNode(

0 commit comments

Comments
 (0)