Skip to content

Commit 9b934cb

Browse files
authored
Add curly rule to ESLint configuration (#2189)
1 parent cf21d7e commit 9b934cb

File tree

10 files changed

+96
-37
lines changed

10 files changed

+96
-37
lines changed

deploy/createTypesPackages.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ const go = async () => {
134134

135135
// Migrate in the template files
136136
for (const templateFile of fs.readdirSync(templateDir)) {
137-
if (templateFile.startsWith(".")) continue;
137+
if (templateFile.startsWith(".")) {
138+
continue;
139+
}
138140

139141
const templatedFile = new URL(templateFile, templateDir);
140142
fs.copyFileSync(templatedFile, new URL(templateFile, packagePath));
@@ -242,15 +244,21 @@ function prependAutoImports(pkg, packagePath) {
242244
const groups = new Map();
243245
for (const file of pkg.files) {
244246
let files = groups.get(file.group);
245-
if (!files) groups.set(file.group, (files = []));
247+
if (!files) {
248+
groups.set(file.group, (files = []));
249+
}
246250
files.push(file);
247251
}
248252
for (const files of groups.values()) {
249253
const indexFile = files.find((file) => file.index);
250-
if (!indexFile) continue;
254+
if (!indexFile) {
255+
continue;
256+
}
251257

252258
const index = new URL(indexFile.to, packagePath);
253-
if (!fs.existsSync(index)) continue;
259+
if (!fs.existsSync(index)) {
260+
continue;
261+
}
254262

255263
const toPrepend = files
256264
.filter((f) => !!f.autoImport)
@@ -270,8 +278,12 @@ function prependAutoImports(pkg, packagePath) {
270278
* @param {URL} to
271279
*/
272280
function relativeUrl(from, to) {
273-
if (from.origin !== to.origin) return to.toString();
274-
if (!from.pathname.endsWith("/")) from = new URL("./", from);
281+
if (from.origin !== to.origin) {
282+
return to.toString();
283+
}
284+
if (!from.pathname.endsWith("/")) {
285+
from = new URL("./", from);
286+
}
275287
const relative = path.posix.relative(from.pathname, to.pathname);
276288
return path.isAbsolute(relative) ||
277289
relative.startsWith("../") ||

deploy/deployChangedPackages.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ for (const dirName of fs.readdirSync(generatedDir)) {
6464
`${pkgJSON.name}@${olderVersion}/${filemap.to}`,
6565
);
6666
console.log(` - ${file}`);
67-
if (oldFile !== generatedDTSContent)
67+
if (oldFile !== generatedDTSContent) {
6868
printUnifiedDiff(oldFile, generatedDTSContent);
69+
}
6970

7071
const title = `## \`${file}\``;
7172
const notes = generateChangelogFrom(oldFile, generatedDTSContent);

deploy/migrate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import { join } from "path";
1010
const maybeTSWorkingDir = [process.argv[2], "../TypeScript", "TypeScript"];
1111
const tscWD = maybeTSWorkingDir.find((wd) => existsSync(wd));
1212

13-
if (!tscWD)
13+
if (!tscWD) {
1414
throw new Error(
1515
"Could not find a TypeScript clone to put the generated files in.",
1616
);
17+
}
1718

1819
const generatedFiles = readdirSync("generated");
1920
const filesToSend = generatedFiles.filter(

deploy/versionChangelog.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ const go = () => {
1717
// We'll need to map back from the filename in the npm package to the
1818
// generated file in baselines inside the git tag
1919
const thisPackageMeta = packages.find((p) => p.name === name);
20-
if (!thisPackageMeta)
20+
if (!thisPackageMeta) {
2121
throw new Error(`Could not find ${name} in ${packages.map((p) => p.name)}`);
22+
}
2223

2324
for (const file of thisPackageMeta.files) {
2425
const filename = `baselines/${basename(file.from)}`;

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default typescriptEslint.config(
2222
"@typescript-eslint/no-explicit-any": 0,
2323
"@typescript-eslint/no-non-null-assertion": 0,
2424
"@typescript-eslint/no-var-requires": 0,
25+
"curly": ["error", "all"],
2526
},
2627
},
2728
);

src/build.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ async function emitDom() {
141141

142142
for (const [key, target] of Object.entries(namespaces)) {
143143
const descObject = descriptions.interfaces.interface[key];
144-
if (!descObject) continue;
144+
if (!descObject) {
145+
continue;
146+
}
145147

146148
merge(target, descObject, { optional: true });
147149
}
@@ -183,7 +185,9 @@ async function emitDom() {
183185
webidl.interfaces!.interface[partial.name] ||
184186
webidl.mixins!.mixin[partial.name];
185187
if (base) {
186-
if (base.exposed) resolveExposure(partial, base.exposed);
188+
if (base.exposed) {
189+
resolveExposure(partial, base.exposed);
190+
}
187191
merge(base.constants, partial.constants, { shallow: true });
188192
merge(base.methods, partial.methods, { shallow: true });
189193
merge(base.properties, partial.properties, { shallow: true });
@@ -192,7 +196,9 @@ async function emitDom() {
192196
for (const partial of w.partialMixins) {
193197
const base = webidl.mixins!.mixin[partial.name];
194198
if (base) {
195-
if (base.exposed) resolveExposure(partial, base.exposed);
199+
if (base.exposed) {
200+
resolveExposure(partial, base.exposed);
201+
}
196202
merge(base.constants, partial.constants, { shallow: true });
197203
merge(base.methods, partial.methods, { shallow: true });
198204
merge(base.properties, partial.properties, { shallow: true });
@@ -207,7 +213,9 @@ async function emitDom() {
207213
for (const partial of w.partialNamespaces) {
208214
const base = webidl.namespaces?.find((n) => n.name === partial.name);
209215
if (base) {
210-
if (base.exposed) resolveExposure(partial, base.exposed);
216+
if (base.exposed) {
217+
resolveExposure(partial, base.exposed);
218+
}
211219
merge(base.methods, partial.methods, { shallow: true });
212220
merge(base.properties, partial.properties, { shallow: true });
213221
}
@@ -351,7 +359,9 @@ async function emitDom() {
351359
return filterByNull(obj, template);
352360

353361
function filterByNull(obj: any, template: any) {
354-
if (!template) return obj;
362+
if (!template) {
363+
return obj;
364+
}
355365
const filtered = Array.isArray(obj) ? obj.slice(0) : { ...obj };
356366
for (const k in template) {
357367
if (!obj[k]) {

src/build/emitter.ts

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,11 @@ export function emitWebIdl(
288288

289289
function getExtendList(iName: string): string[] {
290290
const i = allInterfacesMap[iName];
291-
if (!i || !i.extends || i.extends === "Object") return [];
292-
else return getExtendList(i.extends).concat(i.extends);
291+
if (!i || !i.extends || i.extends === "Object") {
292+
return [];
293+
} else {
294+
return getExtendList(i.extends).concat(i.extends);
295+
}
293296
}
294297

295298
function getImplementList(iName: string) {
@@ -377,8 +380,9 @@ export function emitWebIdl(
377380
if (obj.overrideType) {
378381
return obj.nullable ? makeNullable(obj.overrideType) : obj.overrideType;
379382
}
380-
if (!obj.type)
383+
if (!obj.type) {
381384
throw new Error("Missing 'type' field in " + JSON.stringify(obj));
385+
}
382386
let type = convertDomTypeToTsTypeWorker(obj, forReturn);
383387
if (type === "Promise<undefined>") {
384388
type = "Promise<void>";
@@ -501,7 +505,9 @@ export function emitWebIdl(
501505
return objDomType;
502506
}
503507
// Name of a type alias. Just return itself
504-
if (allTypedefsMap[objDomType]) return objDomType;
508+
if (allTypedefsMap[objDomType]) {
509+
return objDomType;
510+
}
505511

506512
throw new Error("Unknown DOM type: " + objDomType);
507513
}
@@ -522,9 +528,15 @@ export function emitWebIdl(
522528
function nameWithForwardedTypes(i: Browser.Interface) {
523529
const typeParameters = i.typeParameters;
524530

525-
if (i.overrideThis) return i.overrideThis;
526-
if (!typeParameters) return i.name;
527-
if (!typeParameters.length) return i.name;
531+
if (i.overrideThis) {
532+
return i.overrideThis;
533+
}
534+
if (!typeParameters) {
535+
return i.name;
536+
}
537+
if (!typeParameters.length) {
538+
return i.name;
539+
}
528540

529541
return `${i.name}<${typeParameters.map((t) => t.name)}>`;
530542
}
@@ -971,7 +983,9 @@ export function emitWebIdl(
971983
comments.push("Available only in secure contexts.");
972984
}
973985
if (entity.mdnUrl) {
974-
if (comments.length > 0) comments.push("");
986+
if (comments.length > 0) {
987+
comments.push("");
988+
}
975989
comments.push(`[MDN Reference](${entity.mdnUrl})`);
976990
}
977991

@@ -1384,30 +1398,34 @@ export function emitWebIdl(
13841398
mTypes.length === 0 &&
13851399
amTypes.length === 1 &&
13861400
pTypes.length === 0
1387-
)
1401+
) {
13881402
return amTypes[0] === sig.type;
1403+
}
13891404
if (
13901405
mTypes.length === 1 &&
13911406
amTypes.length === 1 &&
13921407
pTypes.length === 0
1393-
)
1408+
) {
13941409
return mTypes[0] === amTypes[0] && amTypes[0] === sig.type;
1410+
}
13951411
if (
13961412
mTypes.length === 0 &&
13971413
amTypes.length === 1 &&
13981414
pTypes.length === 1
1399-
)
1415+
) {
14001416
return amTypes[0] === pTypes[0] && amTypes[0] === sig.type;
1417+
}
14011418
if (
14021419
mTypes.length === 1 &&
14031420
amTypes.length === 1 &&
14041421
pTypes.length === 1
1405-
)
1422+
) {
14061423
return (
14071424
mTypes[0] === amTypes[0] &&
14081425
amTypes[0] === pTypes[0] &&
14091426
amTypes[0] === sig.type
14101427
);
1428+
}
14111429
}
14121430
}
14131431
}
@@ -1674,7 +1692,9 @@ export function emitWebIdl(
16741692
}
16751693

16761694
function emitSelfIterator(i: Browser.Interface) {
1677-
if (!compilerBehavior.useIteratorObject) return;
1695+
if (!compilerBehavior.useIteratorObject) {
1696+
return;
1697+
}
16781698
const async = i.iterator?.kind === "async_iterable";
16791699
const name = getName(i);
16801700
const iteratorBaseType = `${async ? "Async" : ""}IteratorObject`;
@@ -1770,10 +1790,13 @@ export function emitWebIdl(
17701790
isIndexedPropertyGetter,
17711791
);
17721792

1773-
if (anonymousGetter) return anonymousGetter;
1774-
else if (i.methods)
1793+
if (anonymousGetter) {
1794+
return anonymousGetter;
1795+
} else if (i.methods) {
17751796
return mapToArray(i.methods.method).find(isIndexedPropertyGetter);
1776-
else return undefined;
1797+
} else {
1798+
return undefined;
1799+
}
17771800
}
17781801

17791802
function getIteratorSubtypes() {

src/build/expose.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,27 @@ export function getExposedTypes(
9595
filtered.typedefs!.typedef = exposed;
9696
}
9797

98-
if (webidl.callbackFunctions)
98+
if (webidl.callbackFunctions) {
9999
filtered.callbackFunctions!.callbackFunction = filterProperties(
100100
webidl.callbackFunctions!.callbackFunction,
101101
isKnownName,
102102
);
103-
if (webidl.callbackInterfaces)
103+
}
104+
if (webidl.callbackInterfaces) {
104105
filtered.callbackInterfaces!.interface = filterProperties(
105106
webidl.callbackInterfaces!.interface,
106107
isKnownName,
107108
);
108-
if (webidl.dictionaries)
109+
}
110+
if (webidl.dictionaries) {
109111
filtered.dictionaries!.dictionary = filterProperties(
110112
webidl.dictionaries.dictionary,
111113
isKnownName,
112114
);
113-
if (webidl.enums)
115+
}
116+
if (webidl.enums) {
114117
filtered.enums!.enum = filterProperties(webidl.enums.enum, isKnownName);
118+
}
115119

116120
for (const unvisited of forceKnownTypesLogged.unvisitedValues()) {
117121
console.warn(`${unvisited} is redundant in knownTypes.json (${target})`);

src/build/mdn-comments.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ async function walkDirectory(dir: URL): Promise<URL[]> {
4747

4848
for (const entry of entries) {
4949
if (entry.isDirectory()) {
50-
if (entry.name === parentDirName) continue;
50+
if (entry.name === parentDirName) {
51+
continue;
52+
}
5153
const subDir = new URL(`${entry.name}/`, dir);
5254
results = results.concat(await walkDirectory(subDir));
5355
} else if (entry.isFile() && entry.name === "index.md") {
@@ -139,7 +141,9 @@ export async function generateDescriptions(): Promise<{
139141
const content = await fs.readFile(fileURL, "utf-8");
140142
const slug = extractSlug(content);
141143
const generatedPath = generatePath(content);
142-
if (!slug.length || !generatedPath) return;
144+
if (!slug.length || !generatedPath) {
145+
return;
146+
}
143147

144148
const summary = extractSummary(content);
145149
insertComment(results, slug, summary, generatedPath);

src/build/patches.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ function handleTyped(type: Node): Typed {
5656
}
5757

5858
function handleTypeParameters(value: Value) {
59-
if (!value) return {};
59+
if (!value) {
60+
return {};
61+
}
6062
return {
6163
typeParameters: [
6264
{

0 commit comments

Comments
 (0)