0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-11-08 11:57:30 -05:00

Fix a number of strictNullChecks-related issues (#35795)

In preparation to work on enabling
https://www.typescriptlang.org/tsconfig/#strictNullChecks, I fixed all
the issues outside of `web_src` that came up when the option was
enabled. There was also one lint issue in web_src that apparently only
came up with the option enabled, so I fixed that as well.

`isTruthy` is introduced because Typescript has a bug regarding
`filter(Boolean)` which they are seemingly unwilling to fix.

---------

Signed-off-by: silverwind <me@silverwind.io>
This commit is contained in:
silverwind
2025-11-03 21:17:06 +01:00
committed by GitHub
parent aa7ec64a54
commit 37208fef7e
8 changed files with 32 additions and 15 deletions

View File

@@ -37,7 +37,7 @@ export default {
'./{build,models,modules,routers,services}/**/*.go', './{build,models,modules,routers,services}/**/*.go',
'./templates/**/*.tmpl', './templates/**/*.tmpl',
'./web_src/js/**/*.{ts,js,vue}', './web_src/js/**/*.{ts,js,vue}',
].filter(Boolean), ].filter(Boolean as unknown as <T>(x: T | boolean) => x is T),
blocklist: [ blocklist: [
// classes that don't work without CSS variables from "@tailwind base" which we don't use // classes that don't work without CSS variables from "@tailwind base" which we don't use
'transform', 'shadow', 'ring', 'blur', 'grayscale', 'invert', '!invert', 'filter', '!filter', 'transform', 'shadow', 'ring', 'blur', 'grayscale', 'invert', '!invert', 'filter', '!filter',

View File

@@ -33,15 +33,15 @@ export async function login_user(browser: Browser, workerInfo: WorkerInfo, user:
} }
export async function load_logged_in_context(browser: Browser, workerInfo: WorkerInfo, user: string) { export async function load_logged_in_context(browser: Browser, workerInfo: WorkerInfo, user: string) {
let context;
try { try {
context = await browser.newContext({storageState: `${ARTIFACTS_PATH}/state-${user}-${workerInfo.workerIndex}.json`}); return await browser.newContext({storageState: `${ARTIFACTS_PATH}/state-${user}-${workerInfo.workerIndex}.json`});
} catch (err) { } catch (err) {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT') {
throw new Error(`Could not find state for '${user}'. Did you call login_user(browser, workerInfo, '${user}') in test.beforeAll()?`); throw new Error(`Could not find state for '${user}'. Did you call login_user(browser, workerInfo, '${user}') in test.beforeAll()?`);
} else {
throw err;
} }
} }
return context;
} }
export async function save_visual(page: Page) { export async function save_visual(page: Page) {

View File

@@ -47,6 +47,10 @@ function processAssetsSvgFiles(pattern: string, opts: Opts = {}) {
return glob(pattern).map((path) => processAssetsSvgFile(path, opts)); return glob(pattern).map((path) => processAssetsSvgFile(path, opts));
} }
function lowercaseKeys(obj: Record<string, any>) {
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key.toLowerCase(), value]));
}
async function processMaterialFileIcons() { async function processMaterialFileIcons() {
const paths = glob('node_modules/material-icon-theme/icons/*.svg'); const paths = glob('node_modules/material-icon-theme/icons/*.svg');
const svgSymbols: Record<string, string> = {}; const svgSymbols: Record<string, string> = {};
@@ -76,18 +80,30 @@ async function processMaterialFileIcons() {
// * https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers // * https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers
// * https://github.com/microsoft/vscode/tree/1.98.0/extensions // * https://github.com/microsoft/vscode/tree/1.98.0/extensions
delete iconRules.iconDefinitions; delete iconRules.iconDefinitions;
for (const [k, v] of Object.entries(iconRules.fileNames)) iconRules.fileNames[k.toLowerCase()] = v;
for (const [k, v] of Object.entries(iconRules.folderNames)) iconRules.folderNames[k.toLowerCase()] = v; if (iconRules.fileNames) {
for (const [k, v] of Object.entries(iconRules.fileExtensions)) iconRules.fileExtensions[k.toLowerCase()] = v; iconRules.fileNames = lowercaseKeys(iconRules.fileNames);
}
if (iconRules.folderNames) {
iconRules.folderNames = lowercaseKeys(iconRules.folderNames);
}
if (iconRules.fileExtensions) {
iconRules.fileExtensions = lowercaseKeys(iconRules.fileExtensions);
}
// Use VSCode's "Language ID" mapping from its extensions // Use VSCode's "Language ID" mapping from its extensions
for (const [_, langIdExtMap] of Object.entries(vscodeExtensions)) { for (const [_, langIdExtMap] of Object.entries(vscodeExtensions)) {
for (const [langId, names] of Object.entries(langIdExtMap)) { for (const [langId, names] of Object.entries(langIdExtMap)) {
for (const name of names) { for (const name of names) {
const nameLower = name.toLowerCase(); const nameLower = name.toLowerCase();
if (nameLower[0] === '.') { if (nameLower[0] === '.') {
iconRules.fileExtensions[nameLower.substring(1)] ??= langId; if (iconRules.fileExtensions) {
iconRules.fileExtensions[nameLower.substring(1)] ??= langId;
}
} else { } else {
iconRules.fileNames[nameLower] ??= langId; if (iconRules.fileNames) {
iconRules.fileNames[nameLower] ??= langId;
}
} }
} }
} }

View File

@@ -40,6 +40,7 @@
"strictBindCallApply": true, "strictBindCallApply": true,
"strictBuiltinIteratorReturn": true, "strictBuiltinIteratorReturn": true,
"strictFunctionTypes": true, "strictFunctionTypes": true,
"strictNullChecks": false,
"stripInternal": true, "stripInternal": true,
"verbatimModuleSyntax": true, "verbatimModuleSyntax": true,
"types": [ "types": [

View File

@@ -261,7 +261,7 @@ export function initRepoPullRequestReview() {
if (commentDiv) { if (commentDiv) {
// get the name of the parent id // get the name of the parent id
const groupID = commentDiv.closest('div[id^="code-comments-"]')?.getAttribute('id'); const groupID = commentDiv.closest('div[id^="code-comments-"]')?.getAttribute('id');
if (groupID && groupID.startsWith('code-comments-')) { if (groupID?.startsWith('code-comments-')) {
const id = groupID.slice(14); const id = groupID.slice(14);
const ancestorDiffBox = commentDiv.closest<HTMLElement>('.diff-file-box'); const ancestorDiffBox = commentDiv.closest<HTMLElement>('.diff-file-box');

View File

@@ -101,7 +101,7 @@ function initRepoSettingsBranches() {
// show the `Matched` mark for the status checks that match the pattern // show the `Matched` mark for the status checks that match the pattern
const markMatchedStatusChecks = () => { const markMatchedStatusChecks = () => {
const patterns = (document.querySelector<HTMLTextAreaElement>('#status_check_contexts').value || '').split(/[\r\n]+/); const patterns = (document.querySelector<HTMLTextAreaElement>('#status_check_contexts').value || '').split(/[\r\n]+/);
const validPatterns = patterns.map((item) => item.trim()).filter(Boolean); const validPatterns = patterns.map((item) => item.trim()).filter(Boolean as unknown as <T>(x: T | boolean) => x is T);
const marks = document.querySelectorAll('.status-check-matched-mark'); const marks = document.querySelectorAll('.status-check-matched-mark');
for (const el of marks) { for (const el of marks) {

View File

@@ -181,7 +181,7 @@ export function svg(name: SvgName, size = 16, classNames?: string | string[]): s
svgNode.setAttribute('width', String(size)); svgNode.setAttribute('width', String(size));
svgNode.setAttribute('height', String(size)); svgNode.setAttribute('height', String(size));
} }
if (className) svgNode.classList.add(...className.split(/\s+/).filter(Boolean)); if (className) svgNode.classList.add(...className.split(/\s+/).filter(Boolean as unknown as <T>(x: T | boolean) => x is T));
return serializeXml(svgNode); return serializeXml(svgNode);
} }

View File

@@ -30,7 +30,7 @@ const isProduction = env.NODE_ENV !== 'development';
// false - all disabled // false - all disabled
let sourceMaps; let sourceMaps;
if ('ENABLE_SOURCEMAP' in env) { if ('ENABLE_SOURCEMAP' in env) {
sourceMaps = ['true', 'false'].includes(env.ENABLE_SOURCEMAP) ? env.ENABLE_SOURCEMAP : 'reduced'; sourceMaps = ['true', 'false'].includes(env.ENABLE_SOURCEMAP || '') ? env.ENABLE_SOURCEMAP : 'reduced';
} else { } else {
sourceMaps = isProduction ? 'reduced' : 'true'; sourceMaps = isProduction ? 'reduced' : 'true';
} }
@@ -95,7 +95,7 @@ export default {
path: fileURLToPath(new URL('public/assets', import.meta.url)), path: fileURLToPath(new URL('public/assets', import.meta.url)),
filename: () => 'js/[name].js', filename: () => 'js/[name].js',
chunkFilename: ({chunk}) => { chunkFilename: ({chunk}) => {
const language = (/monaco.*languages?_.+?_(.+?)_/.exec(String(chunk.id)) || [])[1]; const language = (/monaco.*languages?_.+?_(.+?)_/.exec(String(chunk?.id)) || [])[1];
return `js/${language ? `monaco-language-${language.toLowerCase()}` : `[name]`}.[contenthash:8].js`; return `js/${language ? `monaco-language-${language.toLowerCase()}` : `[name]`}.[contenthash:8].js`;
}, },
}, },
@@ -270,7 +270,7 @@ export default {
excludeAssets: [ excludeAssets: [
/^js\/monaco-language-.+\.js$/, /^js\/monaco-language-.+\.js$/,
!isProduction && /^licenses.txt$/, !isProduction && /^licenses.txt$/,
].filter(Boolean), ].filter(Boolean as unknown as <T>(x: T | boolean) => x is T),
groupAssetsByChunk: false, groupAssetsByChunk: false,
groupAssetsByEmitStatus: false, groupAssetsByEmitStatus: false,
groupAssetsByInfo: false, groupAssetsByInfo: false,