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 @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Diagnostics: Ensure at least one plugin is enabled
- Diagnostics: Information added to pluginName value when plugin can be configured with a configSection
- Diagnostics: Warning added to config sections not connected to a plugin

### Changed:

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The following sections describe the features that the extension contributes to V
- Check that reporters are placed after plugins
- 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

### Editor Actions

Expand Down
35 changes: 35 additions & 0 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const updateConfigFileDiagnostics = (

checkSchemaCompatibility(documentNode, devProxyInstall, diagnostics);
checkPlugins(pluginsNode, diagnostics, documentNode);
checkConfigSection(documentNode, diagnostics);

collection.set(document.uri, diagnostics);
};
Expand All @@ -41,6 +42,40 @@ export const updateFileDiagnostics = (
collection.set(document.uri, diagnostics);
};

const checkConfigSection = (documentNode: parse.ObjectNode, diagnostics: vscode.Diagnostic[]) => {
const objects = documentNode.children.filter((node) => node.type === 'Property' && (node as parse.PropertyNode).value.type === 'Object');

objects.forEach((object) => {
const objectNode = object as parse.PropertyNode;
const objectName = objectNode.key.value as string;
const pluginNodes = getPluginsNode(documentNode);

if (pluginNodes && pluginNodes.value.type === 'Array') {
const plugins = (pluginNodes.value as parse.ArrayNode).children as parse.ObjectNode[];
const matchFound = plugins.some((plugin) => {
const configSectionNode = getASTNode(
plugin.children,
'Identifier',
'configSection'
);
return configSectionNode && (configSectionNode.value as parse.LiteralNode).value === objectName;
});

if (matchFound) {
return;
}
}

const diagnostic = new vscode.Diagnostic(
getRangeFromASTNode(objectNode),
`Config section '${objectName}' does not correspond to any plugin. Remove it or add a plugin with a matching configSection.`,
vscode.DiagnosticSeverity.Warning
);
diagnostic.code = 'invalidConfigSection';
diagnostics.push(diagnostic);
});
};

const checkSchemaCompatibility = (documentNode: parse.ObjectNode, devProxyInstall: DevProxyInstall, diagnostics: vscode.Diagnostic[]) => {
const schemaNode = getASTNode(documentNode.children, 'Identifier', '$schema');
if (schemaNode) {
Expand Down
Loading