Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reporter placement check in config files. Closes #84 #91

Merged
merged 1 commit into from
May 29, 2024
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 @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- CodeLens: `JsonReporter`
- CodeLens: `MarkdownReporter`
- CodeLens: `PlainTextReporter`
- Config diagnostic: Show warning if plugins follow a reporter in the plugins array

### Changed:

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The following sections describe the features that the extension contributes to V
- Check for missing `configSection` property in plugin instance for plugins that require configuration
- Check for missing `configSection` when defined in plugin instance
- Check that schema matches installed version of Dev Proxy
- Check that reporters are placed after plugins

### Code Actions

Expand Down
40 changes: 40 additions & 0 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,46 @@ export const updateDiagnostics = (
);
}

// check if we have any plugins that contain the name reporter in the plugins node
const reporterIndex = pluginNodes.findIndex((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 (reporterIndex !== -1) {
// check if we have any more plugins after the reporter plugin
const pluginsAfterReporter = pluginNodes.slice(reporterIndex + 1);
// if we do, add a warning to the reporter plugin stating that it should be the last plugin
if (pluginsAfterReporter.length > 0) {
// check if there are any plugins after the reporter plugin that are not reporters
const pluginAfterReporter = pluginsAfterReporter.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 there are, add a warning to the reporter plugin
if (pluginAfterReporter) {
const diagnostic = new vscode.Diagnostic(
getRangeFromASTNode(pluginNodes[reporterIndex]),
'Reporters should be placed after other plugins.',
vscode.DiagnosticSeverity.Warning
);
diagnostics.push(diagnostic);
}
}
}

// does the plugin have a config section?
pluginNodes.forEach((pluginNode: parse.ObjectNode) => {
const pluginNameNode = getASTNode(
Expand Down