Skip to content

Commit ae70e44

Browse files
committed
Add warning diagnostic when a configSection exists but is not connected to a plugin. Closes #173
1 parent 801f73c commit ae70e44

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

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

1718
### Changed:
1819

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ The following sections describe the features that the extension contributes to V
3737
- Check that reporters are placed after plugins
3838
- Check that at least one plugin is enabled
3939
- Check that a plugin can be configured with a configSection
40+
- Check for configSections that are not used in plugins
4041

4142
### Editor Actions
4243

src/diagnostics.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const updateConfigFileDiagnostics = (
1919

2020
checkSchemaCompatibility(documentNode, devProxyInstall, diagnostics);
2121
checkPlugins(pluginsNode, diagnostics, documentNode);
22+
checkConfigSection(documentNode, diagnostics);
2223

2324
collection.set(document.uri, diagnostics);
2425
};
@@ -41,6 +42,40 @@ export const updateFileDiagnostics = (
4142
collection.set(document.uri, diagnostics);
4243
};
4344

45+
const checkConfigSection = (documentNode: parse.ObjectNode, diagnostics: vscode.Diagnostic[]) => {
46+
const objects = documentNode.children.filter((node) => node.type === 'Property' && (node as parse.PropertyNode).value.type === 'Object');
47+
48+
objects.forEach((object) => {
49+
const objectNode = object as parse.PropertyNode;
50+
const objectName = objectNode.key.value as string;
51+
const pluginNodes = getPluginsNode(documentNode);
52+
53+
if (pluginNodes && pluginNodes.value.type === 'Array') {
54+
const plugins = (pluginNodes.value as parse.ArrayNode).children as parse.ObjectNode[];
55+
const matchFound = plugins.some((plugin) => {
56+
const configSectionNode = getASTNode(
57+
plugin.children,
58+
'Identifier',
59+
'configSection'
60+
);
61+
return configSectionNode && (configSectionNode.value as parse.LiteralNode).value === objectName;
62+
});
63+
64+
if (matchFound) {
65+
return;
66+
}
67+
}
68+
69+
const diagnostic = new vscode.Diagnostic(
70+
getRangeFromASTNode(objectNode),
71+
`Config section '${objectName}' does not correspond to any plugin. Remove it or add a plugin with a matching configSection.`,
72+
vscode.DiagnosticSeverity.Warning
73+
);
74+
diagnostic.code = 'invalidConfigSection';
75+
diagnostics.push(diagnostic);
76+
});
77+
};
78+
4479
const checkSchemaCompatibility = (documentNode: parse.ObjectNode, devProxyInstall: DevProxyInstall, diagnostics: vscode.Diagnostic[]) => {
4580
const schemaNode = getASTNode(documentNode.children, 'Identifier', '$schema');
4681
if (schemaNode) {

0 commit comments

Comments
 (0)