Skip to content

Commit 367ad79

Browse files
Reconfigure ESLint to work well with prettier (#957)
* Reconfigure eslint to work with prettier Add a proper eslint configuration using extensions for svelte, typescript, and prettier. This should ensure eslint does not mess with prettier's settings while still enabling high-quality linting. Remove the outdated .eslintrc.cjs in favor of eslint.config.js. * Apply eslint auto-fixes. Mainly converting let to const, and var to let. * Add block scope to cases in src/lib/video/index.ts This change corrects video/index.ts to comply with `no-case-declarations`. `getEmbeddedVideoUrl` was using `let` and `const` declarations inside cases without an appropriate block scope on each case. As a result of this sloppiness, reused variable names were falling through suspiciously. This change adds a block scope to each case, and makes any local `pattern` and `match` variables const. * Split bkk.chapters expectation into two tests. Satisfy eslint by breaking up the expect on bkk.chapters in convert/tests/sab/convertConfigSAB.test.ts to a separate 0-check and undefined-check. Jest also notes that using toBeDefined() is better than a raw undefined check. https://jestjs.io/docs/expect#tobedefined * ESLint ignore require import in tailwind config. Tell eslint to ignore the require import rule for tailwind's configuration. Require seems to be a standard import mechanism for tailwind: https://v2.tailwindcss.com/docs/configuration#plugins * Create block scope around case in contents/[id]/+page.svelte. * Fix toBeDefined() function call in worker-messenger test. Function wasn't being called, lol. * Fix toBeDefined() call in search data test. Function wasn't being called, lol. * Make results const in searchDictionary. `dab-search-worker.ts`'s `searchDictionary()` did not assign to `results` after it was set. Declare `results` as `const`. * Replace calls to hasOwnProperty. Instead of calling hasOwnProperty off of an object directly, use `Object.property` to make the call. This avoids potential subtle problems, explained in this link: https://eslint.org/docs/latest/rules/no-prototype-builtins#rule-details * Satisfy ESLint with comment in lib/data/scripture.js. Doesn't like empty blocks, as they may be confusing. * Remove empty object types from CatalogData. Replace empty object types (`{}`) with `object`. This prevents random values from being inserted into the interface. Could be a BREAKING CHANGE! * Change sourceMp3 to a const in lib/data/audio.ts. Previously used `var`. * Add block around darwin case in example/index.js. Other OS's had blocks, not sure why MacOS missed out. * Add block around case in BottomNavigationBar. BottomNavigationBar's `handleclick()` used a `let` binding inside a case. Refactor to add a block around the case. * Replace ugly one-line comparision in Sidebar. Sidebar was using a bash-style `and` shortcut instead of a proper `if`. Fix it. * Disable `svelte/no-dupe-style-properties` as it is very noisy. * Disable eslint each-block warnings. Don't warn about missing keys in each-blocks. * Fix useless moustaches. Remove brackets surrounding literal values. * Disable svelte/no-unused-svelte-ignore eslint rule. This rule triggers a warning on statements that eslint does not use, but the svelte LSP does use. * Silence spurious goto warnings. Several `goto` statements are used without reference to `{base}` because they use a parameter instead of a literal url. Silence `eslint` warnings on those in particular. * Fix font-family misspelling in FontList.svelte. A link element attempted to set the font-family style attribute, but misspelled it as "font-famly". Correct spelling. * Apply prettier changes. * Add `curly` rule to eslint, fix errors. Add the `curly` rule to enforce use of braces in if-statements. Then run `eslint . --fix` to correct all violations, and `prettier --write .` to reformat. * Disable eslint for @html in about page. * Ignore/resolve remaining eslint errors. * Ignore extracted CI projects folder --------- Co-authored-by: Judah Sotomayor <judah.sotomayor@pm.me>
1 parent 62aa25a commit 367ad79

74 files changed

Lines changed: 2496 additions & 2160 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.cjs

Lines changed: 0 additions & 41 deletions
This file was deleted.

convert/convertAbout.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ export function convertAbout(dataDir: string, verbose: number) {
1212
const srcFile = path.join(dataDir, 'about.partial.html');
1313
const dstFile = path.join('src/gen-assets', 'about.partial.html');
1414
copyFile(srcFile, dstFile, function (err: any) {
15-
if (err) throw err;
16-
if (verbose) console.log(`copied ${srcFile} to ${dstFile}`);
15+
if (err) {
16+
throw err;
17+
}
18+
if (verbose) {
19+
console.log(`copied ${srcFile} to ${dstFile}`);
20+
}
1721
});
1822
}
1923
export class ConvertAbout extends Task {

convert/convertBadges.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ export async function convertBadges(
3030
if (existsSync(srcFile)) {
3131
foundLanguages.push(language);
3232
copyFile(srcFile, dstFile, function (err: any) {
33-
if (err) throw err;
34-
if (verbose) console.log(`copied ${srcFile} to ${dstFile}`);
33+
if (err) {
34+
throw err;
35+
}
36+
if (verbose) {
37+
console.log(`copied ${srcFile} to ${dstFile}`);
38+
}
3539
});
3640
}
3741
}

convert/convertBooks.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function handleNoCaptionFigures(
180180
const parts = figContent.split('|');
181181

182182
// Extract the image caption
183-
let imageCaption = parts[0];
183+
const imageCaption = parts[0];
184184

185185
// Check if the image caption is missing
186186
if (!imageCaption) {
@@ -302,7 +302,7 @@ function moveFigureToNextNonVerseMarker(
302302
const eol = text.includes('\r\n') ? '\r\n' : '\n';
303303

304304
const lines = text.split(/\r?\n/);
305-
for (let line of lines) {
305+
for (const line of lines) {
306306
// Add any figures that were carried over from the previous lines
307307
if (carryOverFigures.length > 0) {
308308
if (!line.startsWith('\\v ') && !line.startsWith('\\fig')) {
@@ -445,10 +445,11 @@ export async function convertBooks(
445445
);
446446
}
447447
usedLangs.add(context.lang);
448-
if (verbose)
448+
if (verbose) {
449449
console.log(
450450
'converting collection: ' + collection.id + ' to docSet: ' + context.docSet
451451
);
452+
}
452453
/**array of promises of Proskomma mutations*/
453454
const inputFiles = await fs.promises.readdir(
454455
path.join(context.dataDir, 'books', context.bcId)
@@ -503,7 +504,7 @@ export async function convertBooks(
503504
convertScriptureBook(pk, context, book, bcGlossary, docs, inputFiles);
504505
}
505506
if (book.bookTabs) {
506-
for (const bookTab of book.bookTabs?.tabs) {
507+
for (const bookTab of book.bookTabs.tabs) {
507508
convertScriptureBook(
508509
pk,
509510
context,
@@ -523,14 +524,18 @@ export async function convertBooks(
523524
continue;
524525
}
525526
}
526-
if (verbose) console.time('convert ' + collection.id);
527+
if (verbose) {
528+
console.time('convert ' + collection.id);
529+
}
527530
//wait for documents to finish being added to Proskomma
528531
await Promise.all(docs);
529532
if (ignoredBooks.length > 0) {
530533
process.stdout.write(` -- Not Supported: ${ignoredBooks.join(' ')}`);
531534
}
532535
process.stdout.write('\n');
533-
if (verbose) console.timeEnd('convert ' + collection.id);
536+
if (verbose) {
537+
console.timeEnd('convert ' + collection.id);
538+
}
534539
//start freezing process and map promise to docSet name
535540

536541
const frozen = freeze(pk);
@@ -556,7 +561,9 @@ export async function convertBooks(
556561
JSON.stringify(transformCatalogEntry(entry, quizzes, htmlBooks))
557562
);
558563
});
559-
if (verbose) console.time('freeze');
564+
if (verbose) {
565+
console.time('freeze');
566+
}
560567
//write frozen archives for import
561568
//const vals = await Promise.all(freezer.values());
562569
//write frozen archives
@@ -583,7 +590,9 @@ export async function convertBooks(
583590
return s;
584591
})()}]`
585592
);
586-
if (verbose) console.timeEnd('freeze');
593+
if (verbose) {
594+
console.timeEnd('freeze');
595+
}
587596
return {
588597
files,
589598
taskName: 'ConvertBooks'
@@ -789,7 +798,9 @@ function convertScriptureBook(
789798
const id = bookTab ? book.id + bookTab.bookTabID : book.id; //Book tab ID is derived from the book ID because book tabs don't have distinct IDs.
790799
function processBookContent(resolve: () => void, err: any, content: string) {
791800
//process.stdout.write(`processBookContent: bookId:${book.id}, error:${err}\n`);
792-
if (err) throw err;
801+
if (err) {
802+
throw err;
803+
}
793804
content = applyFilters(content, usfmFilterFunctions, context.bcId, id, context);
794805
if (bookTab) {
795806
//The book tab ID in the sfm file gets cut off, which results in it having the same ID as the book. Generate a new ID based on the book ID and book tab ID.
@@ -860,7 +871,9 @@ function convertScriptureBook(
860871
const filenameWithoutExt = basename(file, ext).normalize('NFC');
861872

862873
// Check if the filename starts with baseFilename
863-
if (!filenameWithoutExt.startsWith(baseFilename)) return false;
874+
if (!filenameWithoutExt.startsWith(baseFilename)) {
875+
return false;
876+
}
864877

865878
// Get the part after baseFilename
866879
const suffix = filenameWithoutExt.slice(baseFilename.length);
@@ -933,17 +946,25 @@ export class ConvertBooks extends Task {
933946
* recursively deep-compares two objects based on properties passed in include.
934947
*/
935948
function deepCompareObjects(obj1: any, obj2: any, include: Set<string> = new Set()): boolean {
936-
if (typeof obj1 !== typeof obj2) return false;
949+
if (typeof obj1 !== typeof obj2) {
950+
return false;
951+
}
937952
if (typeof obj1 === 'object') {
938953
if (Array.isArray(obj1)) {
939-
if (obj1.length !== obj2.length) return false;
954+
if (obj1.length !== obj2.length) {
955+
return false;
956+
}
940957
for (let i = 0; i < obj1.length; i++) {
941-
if (!deepCompareObjects(obj1[i], obj2[i])) return false;
958+
if (!deepCompareObjects(obj1[i], obj2[i])) {
959+
return false;
960+
}
942961
}
943962
} else {
944963
for (const k in obj1) {
945964
if (include.has(k)) {
946-
if (!deepCompareObjects(obj1[k], obj2[k])) return false;
965+
if (!deepCompareObjects(obj1[k], obj2[k])) {
966+
return false;
967+
}
947968
}
948969
}
949970
}

0 commit comments

Comments
 (0)