Skip to content

Commit

Permalink
Stricter typescript configuration (#358)
Browse files Browse the repository at this point in the history
This commit makes the TypeScript configuration stricter by enabling the
`strict` setting. This implies that the `alwaysStrict` setting is
implicitely enabled and no longer needs to be mentioned explicitly.

This required three fixes:
* in `icons.ts`, `SPECIFIC_RULE_CLASS_ICONS` needed an explicit type
* in `bazel_query.ts`, `execOptions` needed an explicit type
* All usages of `blaze_query.Target` had to be replaced by `ITarget`.
  This was necessary, because `queryResult.target` is of type
  `ITarget[]` not `Target` and `bazel_{package,target}_tree_item.ts`
  would not have compiled otherwise.

The `strictNullChecks` setting is explicitly opted-out. There are 117
violations against those stricter null checks, and to make the reviews
easier, I plan to only enable fix those in a separate commit.

I also removed the `allowJs` setting. Not sure why this was ever set. It
doesn't seem to be required anymore.
  • Loading branch information
vogelsgesang authored Mar 26, 2024
1 parent a7bb6ff commit 8028ab4
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/bazel/bazel_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class BazelQuery extends BazelCommand {
]);
}
return new Promise((resolve, reject) => {
const execOptions = {
const execOptions: child_process.ExecFileOptionsWithBufferEncoding = {
cwd: this.workingDirectory,
// A null encoding causes the callback below to receive binary data as a
// Buffer instead of text data as strings.
Expand Down
2 changes: 1 addition & 1 deletion src/buildifier/buildifier_format_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class BuildifierFormatProvider
),
];
return edits;
} catch (err) {
} catch (err: any) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
vscode.window.showErrorMessage(`${err}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/workspace-tree/bazel_package_tree_item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class BazelPackageTreeItem
ignoresErrors: true,
sortByRuleName: true,
});
const targets = queryResult.target.map((target: blaze_query.Target) => {
const targets = queryResult.target.map((target: blaze_query.ITarget) => {
return new BazelTargetTreeItem(this.workspaceInfo, target);
});
return (this.directSubpackages as IBazelTreeItem[]).concat(targets);
Expand Down
2 changes: 1 addition & 1 deletion src/workspace-tree/bazel_target_tree_item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class BazelTargetTreeItem
*/
constructor(
private readonly workspaceInfo: BazelWorkspaceInfo,
private readonly target: blaze_query.Target,
private readonly target: blaze_query.ITarget,
) {}

public mightHaveChildren(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/workspace-tree/bazel_workspace_folder_tree_item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class BazelWorkspaceFolderTreeItem implements IBazelTreeItem {
ignoresErrors: true,
sortByRuleName: true,
});
const targets = queryResult.target.map((target: blaze_query.Target) => {
const targets = queryResult.target.map((target: blaze_query.ITarget) => {
return new BazelTargetTreeItem(this.workspaceInfo, target);
});

Expand Down
6 changes: 3 additions & 3 deletions src/workspace-tree/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { blaze_query } from "../protos";
* application/extension/framework targets are shown with folder-like icons
* because those bundles are conceptually folders.
*/
const SPECIFIC_RULE_CLASS_ICONS = {
const SPECIFIC_RULE_CLASS_ICONS: Record<string, string> = {
android_binary: "android_binary",
apple_bundle_import: "resource_bundle",
apple_resource_bundle: "resource_bundle",
Expand Down Expand Up @@ -59,10 +59,10 @@ const SPECIFIC_RULE_CLASS_ICONS = {
* @param rule The {@code QueriedRule} representing the build target.
*/
export function getBazelRuleIcon(
target: blaze_query.Target,
target: blaze_query.ITarget,
): string | vscode.ThemeIcon {
const ruleClass = target.rule.ruleClass;
let iconName = SPECIFIC_RULE_CLASS_ICONS[ruleClass] as string;
let iconName = SPECIFIC_RULE_CLASS_ICONS[ruleClass];
if (!iconName) {
if (ruleClass.endsWith("_binary")) {
iconName = "binary";
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
],
"sourceMap": true,
"rootDir": ".",
"alwaysStrict": true,
"allowJs": true
"strict": true,
"strictNullChecks": false
},
"exclude": [
"node_modules",
Expand Down

0 comments on commit 8028ab4

Please sign in to comment.