Skip to content

Commit 02f7808

Browse files
committed
Fix a number of strictNullChecks-related issues
1 parent c3472dd commit 02f7808

File tree

8 files changed

+31
-12
lines changed

8 files changed

+31
-12
lines changed

eslint.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ export default defineConfig([
905905
files: ['tests/e2e/**'],
906906
rules: {
907907
...playwright.configs['flat/recommended'].rules,
908+
'playwright/no-conditional-in-test': [0],
908909
},
909910
},
910911
{

tailwind.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {readFileSync} from 'node:fs';
22
import {env} from 'node:process';
33
import {parse} from 'postcss';
44
import plugin from 'tailwindcss/plugin.js';
5+
import {isTruthy} from './tools/utils.ts';
56
import type {Config} from 'tailwindcss';
67

78
const isProduction = env.NODE_ENV !== 'development';
@@ -37,7 +38,7 @@ export default {
3738
'./{build,models,modules,routers,services}/**/*.go',
3839
'./templates/**/*.tmpl',
3940
'./web_src/js/**/*.{ts,js,vue}',
40-
].filter(Boolean),
41+
].filter(isTruthy),
4142
blocklist: [
4243
// classes that don't work without CSS variables from "@tailwind base" which we don't use
4344
'transform', 'shadow', 'ring', 'blur', 'grayscale', 'invert', '!invert', 'filter', '!filter',
@@ -121,4 +122,4 @@ export default {
121122
});
122123
}),
123124
],
124-
} satisfies Config;
125+
} satisfies Config as Config;

tests/e2e/example.test.e2e.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ test('login', async ({page}, workerInfo) => {
4545

4646
test('logged in user', async ({browser}, workerInfo) => {
4747
const context = await load_logged_in_context(browser, workerInfo, 'user2');
48-
const page = await context.newPage();
48+
if (!context) return;
4949

50+
const page = await context.newPage();
5051
await page.goto('/');
5152

5253
// Make sure we routed to the home page. Else login failed.

tools/generate-svg.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ function processAssetsSvgFiles(pattern: string, opts: Opts = {}) {
4747
return glob(pattern).map((path) => processAssetsSvgFile(path, opts));
4848
}
4949

50+
function lowercaseKeys(obj: Record<string, any> | undefined) {
51+
if (!obj) return obj;
52+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key.toLowerCase(), value]));
53+
}
54+
5055
async function processMaterialFileIcons() {
5156
const paths = glob('node_modules/material-icon-theme/icons/*.svg');
5257
const svgSymbols: Record<string, string> = {};
@@ -76,18 +81,24 @@ async function processMaterialFileIcons() {
7681
// * https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers
7782
// * https://github.com/microsoft/vscode/tree/1.98.0/extensions
7883
delete iconRules.iconDefinitions;
79-
for (const [k, v] of Object.entries(iconRules.fileNames)) iconRules.fileNames[k.toLowerCase()] = v;
80-
for (const [k, v] of Object.entries(iconRules.folderNames)) iconRules.folderNames[k.toLowerCase()] = v;
81-
for (const [k, v] of Object.entries(iconRules.fileExtensions)) iconRules.fileExtensions[k.toLowerCase()] = v;
84+
85+
iconRules.fileNames = lowercaseKeys(iconRules.fileNames);
86+
iconRules.folderNames = lowercaseKeys(iconRules.fileNames);
87+
iconRules.fileExtensions = lowercaseKeys(iconRules.fileNames);
88+
8289
// Use VSCode's "Language ID" mapping from its extensions
8390
for (const [_, langIdExtMap] of Object.entries(vscodeExtensions)) {
8491
for (const [langId, names] of Object.entries(langIdExtMap)) {
8592
for (const name of names) {
8693
const nameLower = name.toLowerCase();
8794
if (nameLower[0] === '.') {
88-
iconRules.fileExtensions[nameLower.substring(1)] ??= langId;
95+
if (iconRules.fileExtensions) {
96+
iconRules.fileExtensions[nameLower.substring(1)] ??= langId;
97+
}
8998
} else {
90-
iconRules.fileNames[nameLower] ??= langId;
99+
if (iconRules.fileNames) {
100+
iconRules.fileNames[nameLower] ??= langId;
101+
}
91102
}
92103
}
93104
}

tools/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function isTruthy<T>(value: T): value is T extends false | '' | 0 | null | undefined ? never : T { // eslint-disable-line unicorn/prefer-native-coercion-functions
2+
return Boolean(value);
3+
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"strictBindCallApply": true,
4141
"strictBuiltinIteratorReturn": true,
4242
"strictFunctionTypes": true,
43+
"strictNullChecks": false,
4344
"stripInternal": true,
4445
"verbatimModuleSyntax": true,
4546
"types": [

web_src/js/features/repo-issue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export function initRepoPullRequestReview() {
261261
if (commentDiv) {
262262
// get the name of the parent id
263263
const groupID = commentDiv.closest('div[id^="code-comments-"]')?.getAttribute('id');
264-
if (groupID && groupID.startsWith('code-comments-')) {
264+
if (groupID?.startsWith('code-comments-')) {
265265
const id = groupID.slice(14);
266266
const ancestorDiffBox = commentDiv.closest<HTMLElement>('.diff-file-box');
267267

webpack.config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {readFileSync, globSync} from 'node:fs';
1212
import {env} from 'node:process';
1313
import tailwindcss from 'tailwindcss';
1414
import tailwindConfig from './tailwind.config.ts';
15+
import {isTruthy} from './tools/utils.ts';
1516

1617
const {EsbuildPlugin} = EsBuildLoader;
1718
const {SourceMapDevToolPlugin, DefinePlugin, EnvironmentPlugin} = webpack;
@@ -30,7 +31,7 @@ const isProduction = env.NODE_ENV !== 'development';
3031
// false - all disabled
3132
let sourceMaps;
3233
if ('ENABLE_SOURCEMAP' in env) {
33-
sourceMaps = ['true', 'false'].includes(env.ENABLE_SOURCEMAP) ? env.ENABLE_SOURCEMAP : 'reduced';
34+
sourceMaps = ['true', 'false'].includes(env.ENABLE_SOURCEMAP || '') ? env.ENABLE_SOURCEMAP : 'reduced';
3435
} else {
3536
sourceMaps = isProduction ? 'reduced' : 'true';
3637
}
@@ -95,7 +96,7 @@ export default {
9596
path: fileURLToPath(new URL('public/assets', import.meta.url)),
9697
filename: () => 'js/[name].js',
9798
chunkFilename: ({chunk}) => {
98-
const language = (/monaco.*languages?_.+?_(.+?)_/.exec(String(chunk.id)) || [])[1];
99+
const language = (/monaco.*languages?_.+?_(.+?)_/.exec(String(chunk?.id)) || [])[1];
99100
return `js/${language ? `monaco-language-${language.toLowerCase()}` : `[name]`}.[contenthash:8].js`;
100101
},
101102
},
@@ -270,7 +271,7 @@ export default {
270271
excludeAssets: [
271272
/^js\/monaco-language-.+\.js$/,
272273
!isProduction && /^licenses.txt$/,
273-
].filter(Boolean),
274+
].filter(isTruthy),
274275
groupAssetsByChunk: false,
275276
groupAssetsByEmitStatus: false,
276277
groupAssetsByInfo: false,

0 commit comments

Comments
 (0)