Skip to content

Commit 0654efb

Browse files
committed
[INTERNAL] lib/processors/jsdoc: fix eslint errors
Cherry-picked from SAP/openui5@9bac0e385.
1 parent af0ba7e commit 0654efb

File tree

6 files changed

+348
-421
lines changed

6 files changed

+348
-421
lines changed

lib/processors/jsdoc/lib/createIndexFiles.js

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
3939
log.info("Using custom fs");
4040
}
4141
if (returnOutputFiles) {
42-
log.info("Returning output files instead of writing to fs.")
42+
log.info("Returning output files instead of writing to fs.");
4343
}
4444
log.info("");
4545

4646
// Deprecated, Experimental and Since collections
47-
let oListCollection = {
47+
const oListCollection = {
4848
deprecated: {
4949
noVersion: {
5050
apis: []
@@ -63,13 +63,11 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
6363
fs.readFile(file, 'utf8', function (err, data) {
6464
if (err) {
6565
reject(err);
66-
} else {
66+
} else if (data.trim() === "") {
6767
// Handle empty files scenario
68-
if (data.trim() === "") {
69-
resolve({});
70-
} else {
71-
resolve(JSON.parse(String(data)));
72-
}
68+
resolve({});
69+
} else {
70+
resolve(JSON.parse(String(data)));
7371
}
7472
});
7573
});
@@ -102,20 +100,20 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
102100
* Returns a promise that resolves with an array of symbols.
103101
*/
104102
function createSymbolSummaryForLib(lib) {
105-
let file = path.join(unpackedTestresourcesRoot, lib.replace(/\./g, "/"), "designtime/api.json");
103+
const file = path.join(unpackedTestresourcesRoot, lib.replace(/\./g, "/"), "designtime/api.json");
106104

107105
return readJSONFile(file).then(function (apijson) {
108106
if (!apijson.hasOwnProperty("symbols") || !Array.isArray(apijson.symbols)) {
109107
// Ignore libraries with invalid api.json content like empty object or non-array "symbols" property.
110108
return [];
111109
}
112-
return apijson.symbols.map(symbol => {
113-
let oReturn = {
110+
return apijson.symbols.map((symbol) => {
111+
const oReturn = {
114112
name: symbol.name,
115113
kind: symbol.kind,
116114
visibility: symbol.visibility,
117-
extends: symbol.extends,
118-
implements: symbol.implements,
115+
"extends": symbol.extends,
116+
"implements": symbol.implements,
119117
lib: lib
120118
};
121119
// We add deprecated member only when the control is deprecated to keep file size at check
@@ -132,7 +130,7 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
132130
collectLists(symbol);
133131
return oReturn;
134132
});
135-
})
133+
});
136134
}
137135

138136
/*
@@ -146,7 +144,7 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
146144
const sText = oDataType !== "since" ? oEntityObject[oDataType].text : oEntityObject.description;
147145
const oData = {
148146
control: sSymbolName,
149-
text: sText || undefined,
147+
text: sText || undefined,
150148
type: sObjectType,
151149
"static": !!oEntityObject.static,
152150
visibility: oEntityObject.visibility
@@ -159,7 +157,7 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
159157

160158
if (sSince && sSince !== "undefined" /* Sometimes sSince comes as string "undefined" */) {
161159
// take only major and minor versions
162-
let sVersion = sSince.split(".").slice(0, 2).join(".");
160+
const sVersion = sSince.split(".").slice(0, 2).join(".");
163161

164162
oData.since = sSince;
165163

@@ -190,7 +188,7 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
190188
}
191189

192190
// Methods
193-
oSymbol.methods && oSymbol.methods.forEach(oMethod => {
191+
oSymbol.methods?.forEach((oMethod) => {
194192
if (oMethod.deprecated) {
195193
addData("deprecated", oMethod, "methods", oSymbol.name);
196194
}
@@ -205,7 +203,7 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
205203
});
206204

207205
// Events
208-
oSymbol.events && oSymbol.events.forEach(oEvent => {
206+
oSymbol.events?.forEach((oEvent) => {
209207
if (oEvent.deprecated) {
210208
addData("deprecated", oEvent, "events", oSymbol.name);
211209
}
@@ -229,24 +227,24 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
229227
}
230228

231229
function expandHierarchyInfo(symbols) {
232-
let byName = new Map();
233-
symbols.forEach(symbol => {
230+
const byName = new Map();
231+
symbols.forEach((symbol) => {
234232
byName.set(symbol.name, symbol);
235233
});
236-
symbols.forEach(symbol => {
237-
let parent = symbol.extends && byName.get(symbol.extends);
234+
symbols.forEach((symbol) => {
235+
const parent = symbol.extends && byName.get(symbol.extends);
238236
if (parent) {
239-
parent.extendedBy = parent.extendedBy ||  [];
237+
parent.extendedBy = parent.extendedBy || [];
240238
parent.extendedBy.push({
241239
name: symbol.name,
242240
visibility: symbol.visibility
243241
});
244242
}
245243
if (symbol.implements) {
246-
symbol.implements.forEach(intfName => {
247-
let intf = byName.get(intfName);
244+
symbol.implements.forEach((intfName) => {
245+
const intf = byName.get(intfName);
248246
if (intf) {
249-
intf.implementedBy = intf.implementedBy ||  [];
247+
intf.implementedBy = intf.implementedBy || [];
250248
intf.implementedBy.push({
251249
name: symbol.name,
252250
visibility: symbol.visibility
@@ -259,23 +257,23 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
259257
}
260258

261259
function convertListToTree(symbols) {
262-
let aTree = [];
260+
const aTree = [];
263261

264262
// Filter out excluded libraries
265263
symbols = symbols.filter(({lib}) => ["sap.ui.documentation"].indexOf(lib) === -1);
266264

267265
// Create treeName and displayName
268-
symbols.forEach(oSymbol => {
266+
symbols.forEach((oSymbol) => {
269267
oSymbol.treeName = oSymbol.name.replace(/^module:/, "").replace(/\//g, ".");
270268
oSymbol.displayName = oSymbol.treeName.split(".").pop();
271269
});
272270

273271
// Create missing - virtual namespaces
274-
symbols.forEach(oSymbol => {
272+
symbols.forEach((oSymbol) => {
275273
oSymbol.treeName.split(".").forEach((sPart, i, a) => {
276-
let sName = a.slice(0, (i + 1)).join(".");
274+
const sName = a.slice(0, (i + 1)).join(".");
277275

278-
if (!symbols.find(o => o.treeName === sName)) {
276+
if (!symbols.find((o) => o.treeName === sName)) {
279277
symbols.push({
280278
name: sName,
281279
treeName: sName,
@@ -289,13 +287,12 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
289287
});
290288

291289
// Discover parents
292-
symbols.forEach(oSymbol => {
293-
let aParent = oSymbol.treeName.split("."),
294-
sParent;
290+
symbols.forEach((oSymbol) => {
291+
const aParent = oSymbol.treeName.split(".");
295292

296293
// Extract parent name
297294
aParent.pop();
298-
sParent = aParent.join(".");
295+
const sParent = aParent.join(".");
299296

300297
// Mark parent
301298
if (symbols.find(({treeName}) => treeName === sParent)) {
@@ -305,20 +302,20 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
305302

306303
// Sort the list before building the tree
307304
symbols.sort((a, b) => {
308-
let sA = a.treeName.toUpperCase(),
305+
const sA = a.treeName.toUpperCase(),
309306
sB = b.treeName.toUpperCase();
310307

311-
if (sA < sB) return -1;
312-
if (sA > sB) return 1;
308+
if (sA < sB) {return -1;}
309+
if (sA > sB) {return 1;}
313310
return 0;
314311
});
315312

316313
// Build tree
317-
symbols.forEach(oSymbol => {
314+
symbols.forEach((oSymbol) => {
318315
if (oSymbol.parent) {
319-
let oParent = symbols.find(({treeName}) => treeName === oSymbol.parent);
316+
const oParent = symbols.find(({treeName}) => treeName === oSymbol.parent);
320317

321-
if (!oParent.nodes) oParent.nodes = [];
318+
if (!oParent.nodes) {oParent.nodes = [];}
322319
oParent.nodes.push(oSymbol);
323320
} else {
324321
aTree.push(oSymbol);
@@ -327,13 +324,13 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
327324

328325
// Custom sort first level tree items - "sap" namespace should be on top
329326
aTree.sort((a, b) => {
330-
let sA = a.displayName.toUpperCase(),
327+
const sA = a.displayName.toUpperCase(),
331328
sB = b.displayName.toUpperCase();
332329

333-
if (sA === "SAP") return -1;
334-
if (sB === "SAP") return 1;
335-
if (sA < sB) return -1;
336-
if (sA > sB) return 1;
330+
if (sA === "SAP") {return -1;}
331+
if (sB === "SAP") {return 1;}
332+
if (sA < sB) {return -1;}
333+
if (sA > sB) {return 1;}
337334

338335
return 0;
339336
});
@@ -349,10 +346,10 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
349346
delete oSymbol.treeName;
350347
delete oSymbol.parent;
351348
if (oSymbol.nodes) {
352-
oSymbol.nodes.forEach(o => cleanTree(o));
349+
oSymbol.nodes.forEach((o) => cleanTree(o));
353350
}
354351
}
355-
aTree.forEach(o => cleanTree(o));
352+
aTree.forEach((o) => cleanTree(o));
356353

357354
return aTree;
358355
}
@@ -401,7 +398,7 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
401398
propagateFlags(oSymbol, { bAllContentDeprecated: true });
402399
} else {
403400
// 3. If all children are deprecated, then the parent is marked as content-deprecated
404-
oSymbol.bAllContentDeprecated = !!oSymbol.nodes && oSymbol.nodes.every(node => node.bAllContentDeprecated);
401+
oSymbol.bAllContentDeprecated = !!oSymbol.nodes && oSymbol.nodes.every((node) => node.bAllContentDeprecated);
405402
}
406403
}
407404

@@ -413,9 +410,9 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
413410
function propagateFlags(oSymbol, oFlags) {
414411
Object.assign(oSymbol, oFlags);
415412
if (oSymbol.nodes) {
416-
oSymbol.nodes.forEach(node => {
413+
oSymbol.nodes.forEach((node) => {
417414
propagateFlags(node, oFlags);
418-
})
415+
});
419416
}
420417
}
421418

@@ -424,11 +421,11 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
424421
const filesToReturn = {};
425422

426423
var p = readJSONFile(versionInfoFile)
427-
.then(versionInfo => {
424+
.then((versionInfo) => {
428425
version = versionInfo.version;
429426
return Promise.all(
430427
versionInfo.libraries.map(
431-
lib => createSymbolSummaryForLib(lib.name).catch(err => {
428+
(lib) => createSymbolSummaryForLib(lib.name).catch((err) => {
432429
// ignore 'file not found' errors as some libs don't have an api.json (themes, server libs)
433430
if (err.code === 'ENOENT') {
434431
return [];
@@ -441,8 +438,8 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
441438
.then(deepMerge)
442439
.then(expandHierarchyInfo)
443440
.then(convertListToTree)
444-
.then(symbols => {
445-
let result = {
441+
.then((symbols) => {
442+
const result = {
446443
"$schema-ref": "http://schemas.sap.com/sapui5/designtime/api-index.json/1.0",
447444
version: version,
448445
library: "*",
@@ -456,13 +453,13 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
456453
})
457454
.then(() => {
458455
/* Lists - modify and cleanup */
459-
let sortList = function (oList) {
456+
const sortList = function (oList) {
460457
/* Sorting since records */
461-
let aKeys = Object.keys(oList),
458+
const aKeys = Object.keys(oList),
462459
oSorted = {};
463460

464461
aKeys.sort((a, b) => {
465-
let aA = a.split("."),
462+
const aA = a.split("."),
466463
aB = b.split(".");
467464

468465
if (a === "noVersion") {
@@ -478,7 +475,7 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
478475
b = [aB[0], ('0' + aB[1]).slice(-2)].join("");
479476

480477
// Sort descending
481-
return parseInt(b, 10) - parseInt(a, 10);
478+
return parseInt(b) - parseInt(a);
482479
});
483480

484481
aKeys.forEach((sKey) => {
@@ -529,8 +526,8 @@ function createIndexFiles(versionInfoFile, unpackedTestresourcesRoot, targetFile
529526
]);
530527
}
531528
})
532-
.catch(err => {
533-
log.error("**** failed to create API index for libraries:", err)
529+
.catch((err) => {
530+
log.error("**** failed to create API index for libraries:", err);
534531
throw err;
535532
});
536533

0 commit comments

Comments
 (0)