Skip to content

Commit 3be1ff7

Browse files
committed
Made typescript/strict-boolean-expressions even stricter
1 parent 98d78ea commit 3be1ff7

File tree

13 files changed

+46
-37
lines changed

13 files changed

+46
-37
lines changed

.oxlintrc.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@
9898
"typescript/prefer-nullish-coalescing": "error",
9999
// currently in oxlint's nursery (=under development)
100100
"typescript/prefer-optional-chain": "error",
101-
"typescript/strict-boolean-expressions": "error",
101+
"typescript/strict-boolean-expressions": [
102+
"error",
103+
{
104+
"allowString": false,
105+
"allowNumber": false,
106+
"allowNullableObject": false
107+
}
108+
],
102109
"typescript/triple-slash-reference": "error",
103110
// all import related rules
104111
"import/no-duplicates": "error",

packages/client/src/common/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { WebSocketUrlParams, WebSocketUrlString } from './commonTypes.js';
77

88
export const createUrl = (config: WebSocketUrlParams | WebSocketUrlString) => {
99
let buildUrl = '';
10-
if ((config as WebSocketUrlString).url) {
10+
if (Object.hasOwn(config, 'url')) {
1111
const options = config as WebSocketUrlString;
1212
if (!options.url.startsWith('ws://') && !options.url.startsWith('wss://')) {
1313
throw new Error(`This is not a proper websocket url: ${options.url}`);
@@ -25,7 +25,7 @@ export const createUrl = (config: WebSocketUrlParams | WebSocketUrlString) => {
2525
if (options.path !== undefined) {
2626
buildUrl += `/${options.path}`;
2727
}
28-
if (options.extraParams) {
28+
if (options.extraParams !== undefined) {
2929
const url = new URL(buildUrl);
3030

3131
for (const [key, value] of Object.entries(options.extraParams)) {

packages/client/src/editorApp/editorApp.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class EditorApp {
138138
}
139139

140140
const languageDef = this.config.languageDef;
141-
if (languageDef) {
141+
if (languageDef !== undefined) {
142142
// register own language first
143143
monaco.languages.register(languageDef.languageExtensionConfig);
144144

@@ -151,11 +151,11 @@ export class EditorApp {
151151
}
152152

153153
// apply monarch definitions
154-
if (languageDef.monarchLanguage) {
154+
if (languageDef.monarchLanguage !== undefined) {
155155
monaco.languages.setMonarchTokensProvider(languageDef.languageExtensionConfig.id, languageDef.monarchLanguage);
156156
}
157157

158-
if (languageDef.theme) {
158+
if (languageDef.theme !== undefined) {
159159
monaco.editor.defineTheme(languageDef.theme.name, languageDef.theme.data);
160160
monaco.editor.setTheme(languageDef.theme.name);
161161
}
@@ -343,11 +343,11 @@ export class EditorApp {
343343
disposingResolve = resolve;
344344
});
345345

346-
if (this.editor) {
346+
if (this.editor !== undefined) {
347347
this.editor.dispose();
348348
this.editor = undefined;
349349
}
350-
if (this.diffEditor) {
350+
if (this.diffEditor !== undefined) {
351351
this.diffEditor.dispose();
352352
this.diffEditor = undefined;
353353
}

packages/client/src/vscode/apiWrapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export class MonacoVscodeApiWrapper {
261261
}
262262

263263
const extensions = this.apiConfig.extensions;
264-
if (this.apiConfig.extensions) {
264+
if (this.apiConfig.extensions !== undefined && this.apiConfig.extensions.length > 0) {
265265
const allPromises: Array<Promise<void>> = [];
266266
const extensionIds: string[] = [];
267267
getBuiltinExtensions().forEach((ext) => {
@@ -281,7 +281,7 @@ export class MonacoVscodeApiWrapper {
281281
const manifest = extensionConfig.config as IExtensionManifest;
282282
const extRegResult = registerExtension(manifest, ExtensionHostKind.LocalProcess);
283283
this.extensionRegisterResults.set(manifest.name, extRegResult);
284-
if (extensionConfig.filesOrContents && Object.hasOwn(extRegResult, 'registerFileUrl')) {
284+
if (extensionConfig.filesOrContents !== undefined && Object.hasOwn(extRegResult, 'registerFileUrl')) {
285285
for (const entry of extensionConfig.filesOrContents) {
286286
this.disposableStore.add(extRegResult.registerFileUrl(entry[0], encodeStringOrUrlToDataUrl(entry[1])));
287287
}

packages/client/src/vscode/locales.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const locales = Object.keys(localeLoader);
120120
export const initLocaleLoader = async (locale = new URLSearchParams(window.location.search).get('locale'), logger?: ILogger) => {
121121
if (locale !== null) {
122122
const loader = localeLoader[locale];
123-
if (loader) {
123+
if (loader !== undefined) {
124124
await loader();
125125
} else {
126126
logger?.error(`Unknown locale ${locale}`);

packages/client/src/wrapper/lcwrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class LanguageClientWrapper {
112112
}
113113

114114
protected async initMessageTransportWorker(lccOptions: WorkerConfigOptionsDirect | WorkerConfigOptionsParams, resolve: () => void, reject: (reason?: unknown) => void) {
115-
if (!this.worker) {
115+
if (this.worker === undefined) {
116116
if (lccOptions.$type === 'WorkerConfig') {
117117
const workerConfig = lccOptions as WorkerConfigOptionsParams;
118118
this.worker = new Worker(workerConfig.url.href, {

packages/examples/src/clangd/worker/clangd-server.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class ClangdInteractionWorker implements ComRouter {
109109
while (!loadingComplete) {
110110
const { done, value } = await wasmReader.read();
111111
loadingComplete = done;
112-
if (value) {
112+
if (value !== undefined) {
113113
chunks.push(value);
114114
}
115115
}
@@ -276,7 +276,7 @@ export class ClangdInteractionWorker implements ComRouter {
276276
* @param readOrWrite Whether to read or write the filesystem
277277
*/
278278
private syncFS(readOrWrite: boolean) {
279-
if (!this.emscriptenFS) throw new Error('Emscripten FS is not available! Aborting ...');
279+
if (this.emscriptenFS === undefined) throw new Error('Emscripten FS is not available! Aborting ...');
280280

281281
this.emscriptenFS.syncfs(readOrWrite, (err) => {
282282
if (err !== null) {
@@ -287,7 +287,7 @@ export class ClangdInteractionWorker implements ComRouter {
287287
}
288288

289289
private async updateWorkerFilesystem(requiredResurces: RequiredResources) {
290-
if (!this.emscriptenFS) throw new Error('Emscripten FS is not available! Aborting ...');
290+
if (this.emscriptenFS === undefined) throw new Error('Emscripten FS is not available! Aborting ...');
291291

292292
const t0 = performance.now();
293293
console.log('Updating Worker FS');
@@ -310,7 +310,7 @@ export class ClangdInteractionWorker implements ComRouter {
310310
* Loads workspace files separately or the compressed workspace from a zip archive
311311
*/
312312
private async loadWorkspaceFiles() {
313-
if (!this.emscriptenFS) throw new Error('Emscripten FS is not available! Aborting ...');
313+
if (this.emscriptenFS === undefined) throw new Error('Emscripten FS is not available! Aborting ...');
314314

315315
// setup & prepare the filesystem
316316
this.emscriptenFS.mkdir(WORKSPACE_PATH);
@@ -365,7 +365,7 @@ export class ClangdInteractionWorker implements ComRouter {
365365
}
366366

367367
private async processInputFiles(files: Record<string, () => Promise<unknown>>, dirReplacer: string) {
368-
if (!this.emscriptenFS) throw new Error('Emscripten FS is not available! Aborting ...');
368+
if (this.emscriptenFS === undefined) throw new Error('Emscripten FS is not available! Aborting ...');
369369

370370
const dirsToCreate = new Set<string>();
371371
const filesToUse: Record<string, () => Promise<unknown>> = {};
@@ -428,8 +428,8 @@ export class ClangdInteractionWorker implements ComRouter {
428428
}
429429

430430
private async updateRemoteFilesystem() {
431-
if (!this.emscriptenFS) throw new Error('Emscripten FS is not available! Aborting ...');
432-
if (!this.fsMessagePort) throw new Error('MessagePort is not available! Aborting ...');
431+
if (this.emscriptenFS === undefined) throw new Error('Emscripten FS is not available! Aborting ...');
432+
if (this.fsMessagePort === undefined) throw new Error('MessagePort is not available! Aborting ...');
433433

434434
const t0 = performance.now();
435435

packages/examples/src/clangd/worker/json_stream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class JsonStream {
3333
}
3434
this.#rawText.push(charCode);
3535
if (this.#inString) {
36-
if (this.#inEscape) {
36+
if (this.#inEscape > 0) {
3737
if (charCode === 75) {
3838
// \uxxxx
3939
this.#inEscape += 4;

packages/examples/src/common/node/server-commons.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const upgradeWsServer = (runconfig: LanguageServerRunConfig,
7777
config.wss.handleUpgrade(request, socket, head, webSocket => {
7878
const socket: IWebSocket = {
7979
send: content => webSocket.send(content, error => {
80-
if (error) {
80+
if (error !== undefined) {
8181
throw error;
8282
}
8383
}),

packages/examples/src/json/server/json-server.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ export class JsonServer {
105105

106106
protected getFoldingRanges(params: FoldingRangeParams): FoldingRange[] {
107107
const document = this.documents.get(params.textDocument.uri);
108-
if (!document) {
108+
if (document === undefined) {
109109
return [];
110110
}
111111
return this.jsonService.getFoldingRanges(document);
112112
}
113113

114114
protected findDocumentColors(params: DocumentColorParams): Thenable<ColorInformation[]> {
115115
const document = this.documents.get(params.textDocument.uri);
116-
if (!document) {
116+
if (document === undefined) {
117117
return Promise.resolve([]);
118118
}
119119
const jsonDocument = this.getJSONDocument(document);
@@ -122,7 +122,7 @@ export class JsonServer {
122122

123123
protected getColorPresentations(params: ColorPresentationParams): ColorPresentation[] {
124124
const document = this.documents.get(params.textDocument.uri);
125-
if (!document) {
125+
if (document === undefined) {
126126
return [];
127127
}
128128
const jsonDocument = this.getJSONDocument(document);
@@ -131,7 +131,7 @@ export class JsonServer {
131131

132132
protected codeAction(params: CodeActionParams): Command[] {
133133
const document = this.documents.get(params.textDocument.uri);
134-
if (!document) {
134+
if (document === undefined) {
135135
return [];
136136
}
137137
return [{
@@ -147,12 +147,12 @@ export class JsonServer {
147147

148148
protected format(params: DocumentRangeFormattingParams): TextEdit[] {
149149
const document = this.documents.get(params.textDocument.uri);
150-
return document ? this.jsonService.format(document, params.range, params.options) : [];
150+
return document === undefined ? [] : this.jsonService.format(document, params.range, params.options);
151151
}
152152

153153
protected findDocumentSymbols(params: DocumentSymbolParams): SymbolInformation[] {
154154
const document = this.documents.get(params.textDocument.uri);
155-
if (!document) {
155+
if (document === undefined) {
156156
return [];
157157
}
158158
const jsonDocument = this.getJSONDocument(document);
@@ -161,10 +161,10 @@ export class JsonServer {
161161

162162
// oxlint-disable-next-line @typescript-eslint/no-explicit-any
163163
protected async executeCommand(params: ExecuteCommandParams): Promise<any> {
164-
if (params.command === 'json.documentUpper' && params.arguments) {
164+
if (params.command === 'json.documentUpper' && params.arguments !== undefined) {
165165
const versionedTextDocumentIdentifier = params.arguments[0];
166166
const document = this.documents.get(versionedTextDocumentIdentifier.uri);
167-
if (document) {
167+
if (document !== undefined) {
168168
await this.connection.workspace.applyEdit({
169169
documentChanges: [{
170170
textDocument: versionedTextDocumentIdentifier,
@@ -183,7 +183,7 @@ export class JsonServer {
183183

184184
protected hover(params: TextDocumentPositionParams): Thenable<Hover | null> {
185185
const document = this.documents.get(params.textDocument.uri);
186-
if (!document) {
186+
if (document === undefined) {
187187
return Promise.resolve(null);
188188
}
189189
const jsonDocument = this.getJSONDocument(document);
@@ -227,7 +227,7 @@ export class JsonServer {
227227

228228
protected completion(params: TextDocumentPositionParams): Thenable<CompletionList | null> {
229229
const document = this.documents.get(params.textDocument.uri);
230-
if (!document) {
230+
if (document === undefined) {
231231
return Promise.resolve(null);
232232
}
233233
const jsonDocument = this.getJSONDocument(document);

0 commit comments

Comments
 (0)