Skip to content

Commit c246fe2

Browse files
committed
fix: improve type safety and clarity
- Added some code comments for clarity. - Improved type safety on a few variables, including the `config` in the `Configuration::setLanguageConfigDefinitions` method and the `event` of the `onDidChangeConfiguration` API in the `activate` method in extension.ts.
1 parent a3a2b90 commit c246fe2

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/configuration.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export class Configuration {
379379
this.languageConfigFilePaths.forEach((paths, langId) => {
380380
// Loop through the paths array...
381381
paths.forEach((filepath) => {
382-
let config = utils.readJsonFile(filepath);
382+
let config = utils.readJsonFile(filepath) as vscode.LanguageConfiguration;
383383

384384
// If the config JSON has more than 0 keys (ie. not empty)
385385
if (Object.keys(config).length > 0) {
@@ -514,7 +514,8 @@ export class Configuration {
514514
* @returns {string[]} An array of language ID strings.
515515
*/
516516
private getMultiLineLanguages(key: "supportedLanguages" | "customSupportedLanguages"): string[] {
517-
return this.multiLineBlocksMap.get(key);
517+
// The non-null assertion operator (!) ensures that the key is never undefined.
518+
return this.multiLineBlocksMap.get(key)!;
518519
}
519520

520521
/**
@@ -524,7 +525,8 @@ export class Configuration {
524525
* @returns {Map<string, string>} The Map of the languages and styles.
525526
*/
526527
private getSingleLineLanguages(key: "supportedLanguages" | "customSupportedLanguages"): Map<string, string> {
527-
return this.singleLineBlocksMap.get(key);
528+
// The non-null assertion operator (!) ensures that the key is never undefined.
529+
return this.singleLineBlocksMap.get(key)!;
528530
}
529531

530532
/**
@@ -1028,6 +1030,7 @@ export class Configuration {
10281030
rules.forEach((rule) => {
10291031
if (rule.action && "indent" in rule.action) {
10301032
// Convert JSON format to API format
1033+
// Usage of the `any` type is necessary here because `rule.action`
10311034
const indentValue = (rule.action as any).indent;
10321035
delete (rule.action as any).indent;
10331036

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function activate(context: vscode.ExtensionContext) {
3232
* When the configuration/user settings are changed, set the extension
3333
* to reflect the settings and output a message to the user.
3434
*/
35-
vscode.workspace.onDidChangeConfiguration((event: any) => {
35+
vscode.workspace.onDidChangeConfiguration((event: vscode.ConfigurationChangeEvent) => {
3636
// TODO: Work on automatically updating the languages instead of making the user reload the extension.
3737

3838
/**

src/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ export function mergeArraysBy<T>(primaryArray: T[], secondaryArray: T[], key: ke
219219
// Start with primary array (avoids side effects)
220220
const merged = [...primary];
221221

222-
// Add items from secondary array that don't exist in primary,
223-
// removing any duplicates.
222+
// Add items from secondary array that don't exist in primary, removing any duplicates.
224223
secondary.forEach((item) => {
225224
// Test all items in the merged array to check if the value of the key
226225
// already exists in the merged array.

0 commit comments

Comments
 (0)