diff --git a/deploy/createTypesPackages.js b/deploy/createTypesPackages.js index 98c31dce7..e660a481f 100644 --- a/deploy/createTypesPackages.js +++ b/deploy/createTypesPackages.js @@ -134,7 +134,9 @@ const go = async () => { // Migrate in the template files for (const templateFile of fs.readdirSync(templateDir)) { - if (templateFile.startsWith(".")) continue; + if (templateFile.startsWith(".")) { + continue; + } const templatedFile = new URL(templateFile, templateDir); fs.copyFileSync(templatedFile, new URL(templateFile, packagePath)); @@ -242,15 +244,21 @@ function prependAutoImports(pkg, packagePath) { const groups = new Map(); for (const file of pkg.files) { let files = groups.get(file.group); - if (!files) groups.set(file.group, (files = [])); + if (!files) { + groups.set(file.group, (files = [])); + } files.push(file); } for (const files of groups.values()) { const indexFile = files.find((file) => file.index); - if (!indexFile) continue; + if (!indexFile) { + continue; + } const index = new URL(indexFile.to, packagePath); - if (!fs.existsSync(index)) continue; + if (!fs.existsSync(index)) { + continue; + } const toPrepend = files .filter((f) => !!f.autoImport) @@ -270,8 +278,12 @@ function prependAutoImports(pkg, packagePath) { * @param {URL} to */ function relativeUrl(from, to) { - if (from.origin !== to.origin) return to.toString(); - if (!from.pathname.endsWith("/")) from = new URL("./", from); + if (from.origin !== to.origin) { + return to.toString(); + } + if (!from.pathname.endsWith("/")) { + from = new URL("./", from); + } const relative = path.posix.relative(from.pathname, to.pathname); return path.isAbsolute(relative) || relative.startsWith("../") || diff --git a/deploy/deployChangedPackages.js b/deploy/deployChangedPackages.js index 5bb3d1c12..851cd59a2 100644 --- a/deploy/deployChangedPackages.js +++ b/deploy/deployChangedPackages.js @@ -64,8 +64,9 @@ for (const dirName of fs.readdirSync(generatedDir)) { `${pkgJSON.name}@${olderVersion}/${filemap.to}`, ); console.log(` - ${file}`); - if (oldFile !== generatedDTSContent) + if (oldFile !== generatedDTSContent) { printUnifiedDiff(oldFile, generatedDTSContent); + } const title = `## \`${file}\``; const notes = generateChangelogFrom(oldFile, generatedDTSContent); diff --git a/deploy/migrate.js b/deploy/migrate.js index 048eda0b4..5a8a30148 100644 --- a/deploy/migrate.js +++ b/deploy/migrate.js @@ -10,10 +10,11 @@ import { join } from "path"; const maybeTSWorkingDir = [process.argv[2], "../TypeScript", "TypeScript"]; const tscWD = maybeTSWorkingDir.find((wd) => existsSync(wd)); -if (!tscWD) +if (!tscWD) { throw new Error( "Could not find a TypeScript clone to put the generated files in.", ); +} const generatedFiles = readdirSync("generated"); const filesToSend = generatedFiles.filter( diff --git a/deploy/versionChangelog.js b/deploy/versionChangelog.js index fc120d82d..c481af071 100644 --- a/deploy/versionChangelog.js +++ b/deploy/versionChangelog.js @@ -17,8 +17,9 @@ const go = () => { // We'll need to map back from the filename in the npm package to the // generated file in baselines inside the git tag const thisPackageMeta = packages.find((p) => p.name === name); - if (!thisPackageMeta) + if (!thisPackageMeta) { throw new Error(`Could not find ${name} in ${packages.map((p) => p.name)}`); + } for (const file of thisPackageMeta.files) { const filename = `baselines/${basename(file.from)}`; diff --git a/eslint.config.mjs b/eslint.config.mjs index 70f31bd73..c73969b73 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -22,6 +22,7 @@ export default typescriptEslint.config( "@typescript-eslint/no-explicit-any": 0, "@typescript-eslint/no-non-null-assertion": 0, "@typescript-eslint/no-var-requires": 0, + "curly": ["error", "all"], }, }, ); diff --git a/src/build.ts b/src/build.ts index 953647004..f22b8fe82 100644 --- a/src/build.ts +++ b/src/build.ts @@ -141,7 +141,9 @@ async function emitDom() { for (const [key, target] of Object.entries(namespaces)) { const descObject = descriptions.interfaces.interface[key]; - if (!descObject) continue; + if (!descObject) { + continue; + } merge(target, descObject, { optional: true }); } @@ -183,7 +185,9 @@ async function emitDom() { webidl.interfaces!.interface[partial.name] || webidl.mixins!.mixin[partial.name]; if (base) { - if (base.exposed) resolveExposure(partial, base.exposed); + if (base.exposed) { + resolveExposure(partial, base.exposed); + } merge(base.constants, partial.constants, { shallow: true }); merge(base.methods, partial.methods, { shallow: true }); merge(base.properties, partial.properties, { shallow: true }); @@ -192,7 +196,9 @@ async function emitDom() { for (const partial of w.partialMixins) { const base = webidl.mixins!.mixin[partial.name]; if (base) { - if (base.exposed) resolveExposure(partial, base.exposed); + if (base.exposed) { + resolveExposure(partial, base.exposed); + } merge(base.constants, partial.constants, { shallow: true }); merge(base.methods, partial.methods, { shallow: true }); merge(base.properties, partial.properties, { shallow: true }); @@ -207,7 +213,9 @@ async function emitDom() { for (const partial of w.partialNamespaces) { const base = webidl.namespaces?.find((n) => n.name === partial.name); if (base) { - if (base.exposed) resolveExposure(partial, base.exposed); + if (base.exposed) { + resolveExposure(partial, base.exposed); + } merge(base.methods, partial.methods, { shallow: true }); merge(base.properties, partial.properties, { shallow: true }); } @@ -351,7 +359,9 @@ async function emitDom() { return filterByNull(obj, template); function filterByNull(obj: any, template: any) { - if (!template) return obj; + if (!template) { + return obj; + } const filtered = Array.isArray(obj) ? obj.slice(0) : { ...obj }; for (const k in template) { if (!obj[k]) { diff --git a/src/build/emitter.ts b/src/build/emitter.ts index c68ce4ebc..000a4fe7f 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -288,8 +288,11 @@ export function emitWebIdl( function getExtendList(iName: string): string[] { const i = allInterfacesMap[iName]; - if (!i || !i.extends || i.extends === "Object") return []; - else return getExtendList(i.extends).concat(i.extends); + if (!i || !i.extends || i.extends === "Object") { + return []; + } else { + return getExtendList(i.extends).concat(i.extends); + } } function getImplementList(iName: string) { @@ -377,8 +380,9 @@ export function emitWebIdl( if (obj.overrideType) { return obj.nullable ? makeNullable(obj.overrideType) : obj.overrideType; } - if (!obj.type) + if (!obj.type) { throw new Error("Missing 'type' field in " + JSON.stringify(obj)); + } let type = convertDomTypeToTsTypeWorker(obj, forReturn); if (type === "Promise") { type = "Promise"; @@ -501,7 +505,9 @@ export function emitWebIdl( return objDomType; } // Name of a type alias. Just return itself - if (allTypedefsMap[objDomType]) return objDomType; + if (allTypedefsMap[objDomType]) { + return objDomType; + } throw new Error("Unknown DOM type: " + objDomType); } @@ -522,9 +528,15 @@ export function emitWebIdl( function nameWithForwardedTypes(i: Browser.Interface) { const typeParameters = i.typeParameters; - if (i.overrideThis) return i.overrideThis; - if (!typeParameters) return i.name; - if (!typeParameters.length) return i.name; + if (i.overrideThis) { + return i.overrideThis; + } + if (!typeParameters) { + return i.name; + } + if (!typeParameters.length) { + return i.name; + } return `${i.name}<${typeParameters.map((t) => t.name)}>`; } @@ -971,7 +983,9 @@ export function emitWebIdl( comments.push("Available only in secure contexts."); } if (entity.mdnUrl) { - if (comments.length > 0) comments.push(""); + if (comments.length > 0) { + comments.push(""); + } comments.push(`[MDN Reference](${entity.mdnUrl})`); } @@ -1384,30 +1398,34 @@ export function emitWebIdl( mTypes.length === 0 && amTypes.length === 1 && pTypes.length === 0 - ) + ) { return amTypes[0] === sig.type; + } if ( mTypes.length === 1 && amTypes.length === 1 && pTypes.length === 0 - ) + ) { return mTypes[0] === amTypes[0] && amTypes[0] === sig.type; + } if ( mTypes.length === 0 && amTypes.length === 1 && pTypes.length === 1 - ) + ) { return amTypes[0] === pTypes[0] && amTypes[0] === sig.type; + } if ( mTypes.length === 1 && amTypes.length === 1 && pTypes.length === 1 - ) + ) { return ( mTypes[0] === amTypes[0] && amTypes[0] === pTypes[0] && amTypes[0] === sig.type ); + } } } } @@ -1674,7 +1692,9 @@ export function emitWebIdl( } function emitSelfIterator(i: Browser.Interface) { - if (!compilerBehavior.useIteratorObject) return; + if (!compilerBehavior.useIteratorObject) { + return; + } const async = i.iterator?.kind === "async_iterable"; const name = getName(i); const iteratorBaseType = `${async ? "Async" : ""}IteratorObject`; @@ -1770,10 +1790,13 @@ export function emitWebIdl( isIndexedPropertyGetter, ); - if (anonymousGetter) return anonymousGetter; - else if (i.methods) + if (anonymousGetter) { + return anonymousGetter; + } else if (i.methods) { return mapToArray(i.methods.method).find(isIndexedPropertyGetter); - else return undefined; + } else { + return undefined; + } } function getIteratorSubtypes() { diff --git a/src/build/expose.ts b/src/build/expose.ts index 0031d256c..f2a6098bf 100644 --- a/src/build/expose.ts +++ b/src/build/expose.ts @@ -95,23 +95,27 @@ export function getExposedTypes( filtered.typedefs!.typedef = exposed; } - if (webidl.callbackFunctions) + if (webidl.callbackFunctions) { filtered.callbackFunctions!.callbackFunction = filterProperties( webidl.callbackFunctions!.callbackFunction, isKnownName, ); - if (webidl.callbackInterfaces) + } + if (webidl.callbackInterfaces) { filtered.callbackInterfaces!.interface = filterProperties( webidl.callbackInterfaces!.interface, isKnownName, ); - if (webidl.dictionaries) + } + if (webidl.dictionaries) { filtered.dictionaries!.dictionary = filterProperties( webidl.dictionaries.dictionary, isKnownName, ); - if (webidl.enums) + } + if (webidl.enums) { filtered.enums!.enum = filterProperties(webidl.enums.enum, isKnownName); + } for (const unvisited of forceKnownTypesLogged.unvisitedValues()) { console.warn(`${unvisited} is redundant in knownTypes.json (${target})`); diff --git a/src/build/mdn-comments.ts b/src/build/mdn-comments.ts index db8b0ed01..991e54128 100644 --- a/src/build/mdn-comments.ts +++ b/src/build/mdn-comments.ts @@ -47,7 +47,9 @@ async function walkDirectory(dir: URL): Promise { for (const entry of entries) { if (entry.isDirectory()) { - if (entry.name === parentDirName) continue; + if (entry.name === parentDirName) { + continue; + } const subDir = new URL(`${entry.name}/`, dir); results = results.concat(await walkDirectory(subDir)); } else if (entry.isFile() && entry.name === "index.md") { @@ -139,7 +141,9 @@ export async function generateDescriptions(): Promise<{ const content = await fs.readFile(fileURL, "utf-8"); const slug = extractSlug(content); const generatedPath = generatePath(content); - if (!slug.length || !generatedPath) return; + if (!slug.length || !generatedPath) { + return; + } const summary = extractSummary(content); insertComment(results, slug, summary, generatedPath); diff --git a/src/build/patches.ts b/src/build/patches.ts index 6bf60fa05..c9b2683dc 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -56,7 +56,9 @@ function handleTyped(type: Node): Typed { } function handleTypeParameters(value: Value) { - if (!value) return {}; + if (!value) { + return {}; + } return { typeParameters: [ {