From b1a7f1e000032627dfa7d5a9f17e9aaad1fd43cd Mon Sep 17 00:00:00 2001 From: Chris Miceli Date: Fri, 27 Sep 2024 12:10:54 -0500 Subject: [PATCH] Format all JS (#1340) The original commit missed subdirectories. --- .prettierignore | 1 + SETUP/tests/jsTests/addprooferTests.js | 34 +- SETUP/tests/jsTests/ajaxTests.js | 77 +-- SETUP/tests/jsTests/characterValidation.js | 5 +- SETUP/tests/jsTests/dp_proofTests.js | 86 +-- SETUP/tests/jsTests/formatPreviewTests.js | 60 +-- SETUP/tests/jsTests/hieroTests.js | 34 +- SETUP/tests/jsTests/jsUnit.js | 17 +- SETUP/tests/jsTests/splitControlTests.js | 35 +- SETUP/tests/jsTests/srchrepTests.js | 138 +++-- .../manual_web/split_test/switchable_split.js | 9 +- .../split_test/vertical_horizontal_split.js | 4 +- eslint.config.js | 26 +- package.json | 4 +- tools/project_manager/handle_bad_page.js | 4 +- tools/project_manager/projectmgr.js | 8 +- .../show_all_good_word_suggestions.js | 2 +- tools/project_manager/show_word_context.js | 14 +- tools/proofers/character_selector.js | 58 +- tools/proofers/dp_proof.js | 111 ++-- tools/proofers/dp_scroll.js | 4 +- tools/proofers/hiero/hiero.js | 10 +- tools/proofers/preview.js | 497 +++++++++--------- tools/proofers/previewControl.js | 83 ++- tools/proofers/process_diacritcal_markup.js | 28 +- tools/proofers/proof_image.js | 2 +- tools/proofers/proof_validate.js | 24 +- tools/proofers/srchrep.js | 22 +- tools/proofers/text_data_processor.js | 30 +- tools/proofers/toolbox.js | 8 +- tools/proofers/wordcheck.js | 32 +- 31 files changed, 722 insertions(+), 745 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000000..ad4d625fc4 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +pinc/3rdparty/**/*.js \ No newline at end of file diff --git a/SETUP/tests/jsTests/addprooferTests.js b/SETUP/tests/jsTests/addprooferTests.js index 541bcc9801..491bc743bf 100644 --- a/SETUP/tests/jsTests/addprooferTests.js +++ b/SETUP/tests/jsTests/addprooferTests.js @@ -1,7 +1,7 @@ /* global $ QUnit AddProofer */ QUnit.module("addproofer tests", { - beforeEach: function() { + beforeEach: function () { $(document.body).append(` @@ -21,34 +21,24 @@ QUnit.module("addproofer tests", {
`); }, - afterEach: function() { - $('#add-proofer-table').remove(); + afterEach: function () { + $("#add-proofer-table").remove(); }, }); -QUnit.test("Referrer details hidden if other not selected", function(assert) { +QUnit.test("Referrer details hidden if other not selected", function (assert) { var addProofer = new AddProofer(); - assert.ok( - $('#referrer_details').is(':visible'), - 'Referrer details should be visible before form init.'); + assert.ok($("#referrer_details").is(":visible"), "Referrer details should be visible before form init."); addProofer.initForm(); - assert.notOk( - $('#referrer_details').is(':visible'), - 'Referrer details should be hidden after form init.'); + assert.notOk($("#referrer_details").is(":visible"), "Referrer details should be hidden after form init."); }); -QUnit.test("Referrer details visible if other selected", function(assert) { +QUnit.test("Referrer details visible if other selected", function (assert) { var addProofer = new AddProofer(); - assert.ok( - $('#referrer_details').is(':visible'), - 'Referrer details should be visible before form init.'); + assert.ok($("#referrer_details").is(":visible"), "Referrer details should be visible before form init."); addProofer.initForm(); - assert.notOk( - $('#referrer_details').is(':visible'), - 'Referrer details should be hidden after form init.'); - document.querySelector('select[name=referrer]').value = 'other'; - document.querySelector('select[name=referrer]').dispatchEvent(new Event('change')); - assert.ok( - $('#referrer_details').is(':visible'), - 'Referrer details should be visible after other selection.'); + assert.notOk($("#referrer_details").is(":visible"), "Referrer details should be hidden after form init."); + document.querySelector("select[name=referrer]").value = "other"; + document.querySelector("select[name=referrer]").dispatchEvent(new Event("change")); + assert.ok($("#referrer_details").is(":visible"), "Referrer details should be visible after other selection."); }); diff --git a/SETUP/tests/jsTests/ajaxTests.js b/SETUP/tests/jsTests/ajaxTests.js index 0e9a95c155..de9e2ff60d 100644 --- a/SETUP/tests/jsTests/ajaxTests.js +++ b/SETUP/tests/jsTests/ajaxTests.js @@ -3,58 +3,62 @@ let codeUrl = "https://www.dummy.org"; -QUnit.module("Ajax test", function() { - +QUnit.module("Ajax test", function () { QUnit.test("Return correct data", function (assert) { function fetchPromise() { - const blob = new Blob([JSON.stringify({key: "value"})], {type : 'application/json'}); - const init = {status: 200, headers: {'content-type': 'application/json'}}; + const blob = new Blob([JSON.stringify({ key: "value" })], { type: "application/json" }); + const init = { status: 200, headers: { "content-type": "application/json" } }; return Promise.resolve(new Response(blob, init)); } - return ajax("GET", "myUrl", {}, {}, fetchPromise) - .then(function(data) { - assert.deepEqual(data, {key: "value"}); - }); + return ajax("GET", "myUrl", {}, {}, fetchPromise).then(function (data) { + assert.deepEqual(data, { key: "value" }); + }); }); QUnit.test("Wrong type of data", function (assert) { function fetchPromise() { - const blob = new Blob([JSON.stringify("mydata")], {type : 'application/json'}); - const init = {status: 200, headers: {'content-type': 'text/html'}}; + const blob = new Blob([JSON.stringify("mydata")], { type: "application/json" }); + const init = { status: 200, headers: { "content-type": "text/html" } }; return Promise.resolve(new Response(blob, init)); } - return ajax("GET", "myUrl", {}, {}, fetchPromise) - .then(function() {}, function(data) { - assert.deepEqual(data, {error: "Incorrect response type", code: AJAX_ERROR_CODES.INCORRECT_RESPONSE_TYPE}); - }); + return ajax("GET", "myUrl", {}, {}, fetchPromise).then( + function () {}, + function (data) { + assert.deepEqual(data, { error: "Incorrect response type", code: AJAX_ERROR_CODES.INCORRECT_RESPONSE_TYPE }); + }, + ); }); QUnit.test("Status 404", function (assert) { function fetchPromise() { - const blob = new Blob([JSON.stringify({error: "not found"})], {type : 'application/json'}); - const init = {status: 404, headers: {'content-type': 'application/json'}}; + const blob = new Blob([JSON.stringify({ error: "not found" })], { type: "application/json" }); + const init = { status: 404, headers: { "content-type": "application/json" } }; return Promise.resolve(new Response(blob, init)); } - return ajax("GET", "myUrl", {}, {}, fetchPromise) - .then(function() {}, function(data) { + return ajax("GET", "myUrl", {}, {}, fetchPromise).then( + function () {}, + function (data) { assert.strictEqual(data.error, "not found"); - }); + }, + ); }); QUnit.test("Unknown error", function (assert) { function fetchPromise() { - const blob = new Blob([JSON.stringify("")], {type : 'application/json'}); - const init = {status: 404, headers: {'content-type': 'application/json'}}; + const blob = new Blob([JSON.stringify("")], { type: "application/json" }); + const init = { status: 404, headers: { "content-type": "application/json" } }; return Promise.resolve(new Response(blob, init)); } - return ajax("GET", "myUrl", {}, {}, fetchPromise) - .then(function() {}, function(data) { - assert.deepEqual(data, {error: "Unknown error", code: AJAX_ERROR_CODES.UNKNOWN_ERROR}); - }); + return ajax("GET", "myUrl", {}, {}, fetchPromise).then( + function () {}, + function (data) { + assert.deepEqual(data, { error: "Unknown error", code: AJAX_ERROR_CODES.UNKNOWN_ERROR }); + }, + ); }); QUnit.test("Network error", function (assert) { @@ -62,26 +66,27 @@ QUnit.module("Ajax test", function() { return Promise.reject(); } - return ajax("GET", "myUrl", {}, {}, fetchPromise) - .then(function() {}, function(data) { - assert.deepEqual(data, {error: "Network error", code: AJAX_ERROR_CODES.NETWORK_ERROR}); - }); + return ajax("GET", "myUrl", {}, {}, fetchPromise).then( + function () {}, + function (data) { + assert.deepEqual(data, { error: "Network error", code: AJAX_ERROR_CODES.NETWORK_ERROR }); + }, + ); }); QUnit.test("Check sent data", function (assert) { function fetchPromise(url, options) { assert.strictEqual(url.href, "https://www.dummy.org/api/index.php?url=myUrl&querykey=queryvalue"); assert.strictEqual(options.method, "POST"); - assert.strictEqual(options.headers['Content-Type'], 'application/json'); + assert.strictEqual(options.headers["Content-Type"], "application/json"); assert.strictEqual(options.headers["X-API-KEY"], "SESSION"); - assert.strictEqual(options.headers.Accept, 'application/json'); - assert.strictEqual(options.body, "{\"datakey\":\"datavalue\"}"); - const blob = new Blob([JSON.stringify("mydata")], {type : 'application/json'}); - const init = {status: 200, headers: {'content-type': 'application/json'}}; + assert.strictEqual(options.headers.Accept, "application/json"); + assert.strictEqual(options.body, '{"datakey":"datavalue"}'); + const blob = new Blob([JSON.stringify("mydata")], { type: "application/json" }); + const init = { status: 200, headers: { "content-type": "application/json" } }; return Promise.resolve(new Response(blob, init)); } - return ajax("POST", "myUrl", {querykey: "queryvalue"}, {datakey: "datavalue"}, fetchPromise) - .then(); + return ajax("POST", "myUrl", { querykey: "queryvalue" }, { datakey: "datavalue" }, fetchPromise).then(); }); }); diff --git a/SETUP/tests/jsTests/characterValidation.js b/SETUP/tests/jsTests/characterValidation.js index d068a3419e..ac9f2f308e 100644 --- a/SETUP/tests/jsTests/characterValidation.js +++ b/SETUP/tests/jsTests/characterValidation.js @@ -3,8 +3,7 @@ var validCharacterPattern; -QUnit.module("Character validation test", function() { - +QUnit.module("Character validation test", function () { let basicLatin = "^(?:[\n\r -~¡-¬®-ÿŒœŠšŽžŸƒ‹›])$"; QUnit.test("In basic latin basic latin character is valid", function (assert) { @@ -53,6 +52,6 @@ QUnit.module("Character validation test", function() { assert.strictEqual(testText("\u{13000}"), true); assert.strictEqual(testText("𓀂"), true); assert.strictEqual(testText("𓀁"), true); - assert.strictEqual(testText("𓀉"),false); + assert.strictEqual(testText("𓀉"), false); }); }); diff --git a/SETUP/tests/jsTests/dp_proofTests.js b/SETUP/tests/jsTests/dp_proofTests.js index a2d02af965..5a975666d3 100644 --- a/SETUP/tests/jsTests/dp_proofTests.js +++ b/SETUP/tests/jsTests/dp_proofTests.js @@ -1,33 +1,33 @@ /* global QUnit surroundSelection submitForm */ -QUnit.module("dp_proof tests", function(hooks) { +QUnit.module("dp_proof tests", function (hooks) { let setTestText = (text, start, end) => { window.docRef = { editform: { // eslint-disable-next-line camelcase - text_data: document.createElement('textarea'), - } + text_data: document.createElement("textarea"), + }, }; window.docRef.editform.text_data.value = text; - window.docRef.editform.text_data.setSelectionRange(start, end, 'forward'); + window.docRef.editform.text_data.setSelectionRange(start, end, "forward"); }; - hooks.beforeEach(function() { + hooks.beforeEach(function () { window.inFace = 0; }); - hooks.afterEach(function() { + hooks.afterEach(function () { delete window.docRef; delete window.inFace; }); QUnit.test("submitForm prevents double submit", function (assert) { const done = assert.async(); - const form = document.createElement('form'); - const submitButton = document.createElement('input'); + const form = document.createElement("form"); + const submitButton = document.createElement("input"); let submitCount = 0; - submitButton.type = 'submit'; - form.addEventListener('submit', (event) => { + submitButton.type = "submit"; + form.addEventListener("submit", (event) => { event.preventDefault(); submitForm(event.target); submitCount++; @@ -49,68 +49,68 @@ QUnit.module("dp_proof tests", function(hooks) { }); QUnit.test("surroundSelection surrounds selection", function (assert) { - setTestText('hello', 0, 5); - surroundSelection('', ''); - assert.strictEqual(window.docRef.editform.text_data.value, "hello", 'surrouned text with '); + setTestText("hello", 0, 5); + surroundSelection("", ""); + assert.strictEqual(window.docRef.editform.text_data.value, "hello", "surrouned text with "); }); QUnit.test("surroundSelection surrounds selection", function (assert) { - setTestText('hello', 0, 5); - surroundSelection('', ''); - assert.strictEqual(window.docRef.editform.text_data.value, "hello", 'surrouned text with '); + setTestText("hello", 0, 5); + surroundSelection("", ""); + assert.strictEqual(window.docRef.editform.text_data.value, "hello", "surrouned text with "); }); QUnit.test("surroundSelection with [** without selection", function (assert) { - setTestText('hello', 0, 0); - surroundSelection('[** ', ']'); - assert.strictEqual(window.docRef.editform.text_data.value, "[** ]hello", 'inserts [**'); + setTestText("hello", 0, 0); + surroundSelection("[** ", "]"); + assert.strictEqual(window.docRef.editform.text_data.value, "[** ]hello", "inserts [**"); }); QUnit.test("surroundSelection with [** duplicates selection for typos", function (assert) { - setTestText('hello', 0, 5); - surroundSelection('[** ', ']'); - assert.strictEqual(window.docRef.editform.text_data.value, "hello[** hello]", 'surrouned text with [**'); + setTestText("hello", 0, 5); + surroundSelection("[** ", "]"); + assert.strictEqual(window.docRef.editform.text_data.value, "hello[** hello]", "surrouned text with [**"); }); QUnit.test("surroundSelection with [Illustration: with selection", function (assert) { - setTestText('hello', 0, 5); - surroundSelection('[Illustration: ', ']'); - assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration: hello]", 'surrouned text with [Illustration: '); + setTestText("hello", 0, 5); + surroundSelection("[Illustration: ", "]"); + assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration: hello]", "surrouned text with [Illustration: "); }); QUnit.test("surroundSelection with [Illustration: without selection", function (assert) { - setTestText('hello', 0, 0); - surroundSelection('[Illustration: ', ']'); - assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration]hello", 'inserts text with [Illustration '); + setTestText("hello", 0, 0); + surroundSelection("[Illustration: ", "]"); + assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration]hello", "inserts text with [Illustration "); }); QUnit.test("surroundSelection with [Illustration: without selection", function (assert) { - setTestText('hello', 0, 0); - surroundSelection('[Illustration: ', ']'); - assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration]hello", 'inserts text with [Illustration '); + setTestText("hello", 0, 0); + surroundSelection("[Illustration: ", "]"); + assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration]hello", "inserts text with [Illustration "); }); QUnit.test("surroundSelection with [Footnote #: without selection", function (assert) { - setTestText('hello', 0, 0); - surroundSelection('[Footnote #: ', ']'); - assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote]hello", 'inserts text with [Footnote]'); + setTestText("hello", 0, 0); + surroundSelection("[Footnote #: ", "]"); + assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote]hello", "inserts text with [Footnote]"); }); QUnit.test("surroundSelection with [Footnote #: with selection", function (assert) { - setTestText('hello', 0, 5); - surroundSelection('[Footnote #: ', ']'); - assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote: hello]", 'surrounds text with [Footnote: ]'); + setTestText("hello", 0, 5); + surroundSelection("[Footnote #: ", "]"); + assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote: hello]", "surrounds text with [Footnote: ]"); }); QUnit.test("surroundSelection with [Footnote #: with selection and identifier", function (assert) { - setTestText('a hello', 0, 7); - surroundSelection('[Footnote #: ', ']'); - assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote a: hello]", 'surrounds text with [Footnote: ]'); + setTestText("a hello", 0, 7); + surroundSelection("[Footnote #: ", "]"); + assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote a: hello]", "surrounds text with [Footnote: ]"); }); QUnit.test("surroundSelection with [Footnote #: with selection and identifier", function (assert) { - setTestText('1 hello', 0, 7); - surroundSelection('[Footnote #: ', ']'); - assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote 1: hello]", 'surrounds text with [Footnote: ]'); + setTestText("1 hello", 0, 7); + surroundSelection("[Footnote #: ", "]"); + assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote 1: hello]", "surrounds text with [Footnote: ]"); }); }); diff --git a/SETUP/tests/jsTests/formatPreviewTests.js b/SETUP/tests/jsTests/formatPreviewTests.js index 3da0305543..70161a3a46 100644 --- a/SETUP/tests/jsTests/formatPreviewTests.js +++ b/SETUP/tests/jsTests/formatPreviewTests.js @@ -1,6 +1,6 @@ /* global QUnit analyse processExMath findClose makePreview defaultStyles */ -QUnit.module("Format preview test", function() { +QUnit.module("Format preview test", function () { let configuration = { suppress: {}, allowUnderline: false, @@ -12,18 +12,18 @@ QUnit.module("Format preview test", function() { }; let allowCharBeforeStartConfig = { - suppress: {charBeforeStart: true}, + suppress: { charBeforeStart: true }, allowUnderline: false, }; let noSideNoteBlankConfig = { - suppress: {sideNoteBlank: true}, + suppress: { sideNoteBlank: true }, allowUnderline: false, }; let mathConfig = { suppress: {}, - allowMathPreview: true + allowMathPreview: true, }; let text; @@ -32,9 +32,9 @@ QUnit.module("Format preview test", function() { // assert issue exists and start, length, type, code and subText correct function issueTest(assert, index, start, length, code, type, subText = "") { // put code as message in first one - let issueExists = (issArray.length > index); + let issueExists = issArray.length > index; assert.ok(issueExists, code); - if(issueExists) { + if (issueExists) { let issue = issArray[index]; assert.strictEqual(issue.code, code); assert.strictEqual(issue.start, start); @@ -560,8 +560,7 @@ QUnit.module("Format preview test", function() { }); QUnit.test("Rewrap continuation paragraph", function (assert) { - let text = -`abcd`; + let text = `abcd`; let preview = makePreview(text, false, true, defaultStyles, getMessage); assert.strictEqual(preview.ok, true); assert.strictEqual(preview.issues, 0); @@ -570,8 +569,7 @@ QUnit.module("Format preview test", function() { }); QUnit.test("Rewrap new paragraph", function (assert) { - let text = -` + let text = ` abcd`; let preview = makePreview(text, false, true, defaultStyles, getMessage); assert.strictEqual(preview.ok, true); @@ -581,8 +579,7 @@ abcd`; }); QUnit.test("Rewrap no-wrap block with 4 blank lines", function (assert) { - let text = -`/* + let text = `/* @@ -597,8 +594,7 @@ EDIBLE FIGS }); QUnit.test("Rewrap no-wrap block preceeded by 4 blank lines", function (assert) { - let text = -` + let text = ` @@ -615,8 +611,7 @@ abc }); QUnit.test("Rewrap continuation block quote", function (assert) { - let text = -`/# + let text = `/# abc #/`; let preview = makePreview(text, false, true, defaultStyles, getMessage); @@ -627,8 +622,7 @@ abc }); QUnit.test("Rewrap continuation block quote with new paragraph", function (assert) { - let text = -`/# + let text = `/# abc #/`; @@ -640,8 +634,7 @@ abc }); QUnit.test("Rewrap new block quote with paragraph", function (assert) { - let text = -` + let text = ` /# abc #/`; @@ -653,8 +646,7 @@ abc }); QUnit.test("Rewrap no-wrap in block quote with no blank line before no-wrap", function (assert) { - let text = -` + let text = ` /# /* bqnw @@ -666,15 +658,16 @@ bq assert.strictEqual(preview.ok, true); assert.strictEqual(preview.issues, 0); assert.strictEqual(preview.possIss, 0); - assert.strictEqual(preview.txtout, + assert.strictEqual( + preview.txtout, `
bqnw
bq -
`); +`, + ); }); QUnit.test("Rewrap no-wrap in block quote with a blank line before no-wrap", function (assert) { - let text = -` + let text = ` /# /* @@ -687,15 +680,16 @@ bq assert.strictEqual(preview.ok, true); assert.strictEqual(preview.issues, 0); assert.strictEqual(preview.possIss, 0); - assert.strictEqual(preview.txtout, + assert.strictEqual( + preview.txtout, `
bqnw
bq -
`); +`, + ); }); QUnit.test("Rewrap block quote in block quote", function (assert) { - let text = -` + let text = ` /# bq @@ -709,10 +703,12 @@ bq assert.strictEqual(preview.ok, true); assert.strictEqual(preview.issues, 0); assert.strictEqual(preview.possIss, 0); - assert.strictEqual(preview.txtout, + assert.strictEqual( + preview.txtout, `
bq
bqbq
bq -
`); +`, + ); }); }); diff --git a/SETUP/tests/jsTests/hieroTests.js b/SETUP/tests/jsTests/hieroTests.js index 8deaf05d17..896ba5eb68 100644 --- a/SETUP/tests/jsTests/hieroTests.js +++ b/SETUP/tests/jsTests/hieroTests.js @@ -1,38 +1,38 @@ /* global QUnit add */ -QUnit.module("Hiero tests", function(hooks) { +QUnit.module("Hiero tests", function (hooks) { let hierobox; - hooks.beforeEach(function() { - hierobox = document.createElement('textarea'); - hierobox.name = 'hierobox'; + hooks.beforeEach(function () { + hierobox = document.createElement("textarea"); + hierobox.name = "hierobox"; document.body.appendChild(hierobox); }); - hooks.afterEach(function() { + hooks.afterEach(function () { document.body.removeChild(hierobox); }); QUnit.test("adds separator for last character numeric", function (assert) { - hierobox.value = '9'; - add('glyph'); - assert.strictEqual(hierobox.value, '9-glyph', '- separator inserted for numbers'); + hierobox.value = "9"; + add("glyph"); + assert.strictEqual(hierobox.value, "9-glyph", "- separator inserted for numbers"); }); QUnit.test("adds separator for last character upper case", function (assert) { - hierobox.value = 'PGDP'; - add('glyph'); - assert.strictEqual(hierobox.value, 'PGDP-glyph', '- separator inserted for upper case'); + hierobox.value = "PGDP"; + add("glyph"); + assert.strictEqual(hierobox.value, "PGDP-glyph", "- separator inserted for upper case"); }); QUnit.test("adds separator for last character lower case", function (assert) { - hierobox.value = 'pgdp'; - add('glyph'); - assert.strictEqual(hierobox.value, 'pgdp-glyph', '- separator inserted for lower case'); + hierobox.value = "pgdp"; + add("glyph"); + assert.strictEqual(hierobox.value, "pgdp-glyph", "- separator inserted for lower case"); }); QUnit.test("does not add separator for last character symbol", function (assert) { - hierobox.value = '[pgdp]'; - add('glyph'); - assert.strictEqual(hierobox.value, '[pgdp]glyph', '- separator not inserted for symbol'); + hierobox.value = "[pgdp]"; + add("glyph"); + assert.strictEqual(hierobox.value, "[pgdp]glyph", "- separator not inserted for symbol"); }); }); diff --git a/SETUP/tests/jsTests/jsUnit.js b/SETUP/tests/jsTests/jsUnit.js index 99334d9cbb..6fb6f1ca23 100644 --- a/SETUP/tests/jsTests/jsUnit.js +++ b/SETUP/tests/jsTests/jsUnit.js @@ -1,21 +1,18 @@ /* global process require */ -const {Builder, Browser, By, until} = require('selenium-webdriver'); -const firefox = require('selenium-webdriver/firefox'); +const { Builder, Browser, By, until } = require("selenium-webdriver"); +const firefox = require("selenium-webdriver/firefox"); (async function example() { var options = new firefox.Options(); options.addArguments("-headless"); - let driver = new Builder() - .forBrowser(Browser.FIREFOX) - .setFirefoxOptions(options) - .build(); + let driver = new Builder().forBrowser(Browser.FIREFOX).setFirefoxOptions(options).build(); let succeeded = false; try { await driver.get(`file:///${process.cwd()}/SETUP/tests/jsTests/qunit.html`); - await driver.wait(until.elementLocated(By.className('passed')), 10000); - var passed = parseInt(await (await driver.findElement(By.className('passed'))).getText(), 10); - var total = parseInt(await (await driver.findElement(By.className('total'))).getText(), 10); - var failed = parseInt(await (await driver.findElement(By.className('failed'))).getText(), 10); + await driver.wait(until.elementLocated(By.className("passed")), 10000); + var passed = parseInt(await (await driver.findElement(By.className("passed"))).getText(), 10); + var total = parseInt(await (await driver.findElement(By.className("total"))).getText(), 10); + var failed = parseInt(await (await driver.findElement(By.className("failed"))).getText(), 10); console.log(`${passed} assertions of ${total} passed, ${failed} failed.`); succeeded = passed === total && failed === 0; } catch (e) { diff --git a/SETUP/tests/jsTests/splitControlTests.js b/SETUP/tests/jsTests/splitControlTests.js index 4d7e04459c..1a2fdab9da 100644 --- a/SETUP/tests/jsTests/splitControlTests.js +++ b/SETUP/tests/jsTests/splitControlTests.js @@ -1,7 +1,7 @@ /* global $ QUnit splitControl */ QUnit.module("splitControl tests", { - beforeEach: function() { + beforeEach: function () { $(document.body).append(`
@@ -12,40 +12,37 @@ QUnit.module("splitControl tests", {
`); }, - afterEach: function() { - $('#split-test').remove(); + afterEach: function () { + $("#split-test").remove(); }, }); -QUnit.test("splitter defaults config values", function(assert) { +QUnit.test("splitter defaults config values", function (assert) { let mainSplit = splitControl("#container"); mainSplit.reLayout(); - const dragBar = $($('#container div').get(1)); - assert.strictEqual(dragBar.css('cursor'), 'ew-resize', 'verify drag bar has east west resize for vertical split'); - assert.strictEqual(dragBar.css('background-color'), 'rgb(169, 169, 169)', 'verify drag bar has darkgray background'); + const dragBar = $($("#container div").get(1)); + assert.strictEqual(dragBar.css("cursor"), "ew-resize", "verify drag bar has east west resize for vertical split"); + assert.strictEqual(dragBar.css("background-color"), "rgb(169, 169, 169)", "verify drag bar has darkgray background"); }); -QUnit.test("vertical split test draws east west drag bar", function(assert) { - let mainSplit = splitControl("#container", {splitVertical: true}); +QUnit.test("vertical split test draws east west drag bar", function (assert) { + let mainSplit = splitControl("#container", { splitVertical: true }); mainSplit.reLayout(); - assert.strictEqual($($('#container div').get(1)) - .css('cursor'), 'ew-resize', 'verify drag bar has east west resize for vertical split'); + assert.strictEqual($($("#container div").get(1)).css("cursor"), "ew-resize", "verify drag bar has east west resize for vertical split"); }); -QUnit.test("horizontal split test draws north south drag bar", function(assert) { - let mainSplit = splitControl("#container", {splitVertical: false}); +QUnit.test("horizontal split test draws north south drag bar", function (assert) { + let mainSplit = splitControl("#container", { splitVertical: false }); mainSplit.reLayout(); - assert.strictEqual($($('#container div').get(1)) - .css('cursor'), 'ns-resize', 'verify drag bar has north south resize for horizontal split'); + assert.strictEqual($($("#container div").get(1)).css("cursor"), "ns-resize", "verify drag bar has north south resize for horizontal split"); }); -QUnit.test("drag bar color is customizable", function(assert) { - let mainSplit = splitControl("#container", {dragBarColor: 'rebeccapurple'}); +QUnit.test("drag bar color is customizable", function (assert) { + let mainSplit = splitControl("#container", { dragBarColor: "rebeccapurple" }); mainSplit.reLayout(); - assert.strictEqual($($('#container div').get(1)) - .css('background-color'), 'rgb(102, 51, 153)', 'verify drag bar has custom color'); + assert.strictEqual($($("#container div").get(1)).css("background-color"), "rgb(102, 51, 153)", "verify drag bar has custom color"); }); diff --git a/SETUP/tests/jsTests/srchrepTests.js b/SETUP/tests/jsTests/srchrepTests.js index f71be6fa98..2340d00629 100644 --- a/SETUP/tests/jsTests/srchrepTests.js +++ b/SETUP/tests/jsTests/srchrepTests.js @@ -1,12 +1,20 @@ /* global $ QUnit srchrep */ let originalOpener = opener; -QUnit.module("srchrep tests", hooks => { - const setTextValue = value => { - // eslint-disable-next-line camelcase - window.opener = { parent: { docRef: { editform: { text_data: { - value, - } } } } }; +QUnit.module("srchrep tests", (hooks) => { + const setTextValue = (value) => { + window.opener = { + parent: { + docRef: { + editform: { + // eslint-disable-next-line camelcase + text_data: { + value, + }, + }, + }, + }, + }; }; hooks.beforeEach(() => { @@ -20,99 +28,83 @@ QUnit.module("srchrep tests", hooks => { }); hooks.afterEach(() => { - $('#srchrep-form').remove(); + $("#srchrep-form").remove(); window.opener = originalOpener; }); - QUnit.test("replaces all instances", function(assert) { - setTextValue('value.'); - $('#search').val('value.'); - $('#replace').val('value.'); + QUnit.test("replaces all instances", function (assert) { + setTextValue("value."); + $("#search").val("value."); + $("#replace").val("value."); srchrep.doReplace(); - assert.strictEqual( - window.opener.parent.docRef.editform.text_data.value, - 'value.', - 'Search replace replaces all instances.'); - assert.notOk($('#undo').prop('disabled'), 'Undo should be enabled.'); + assert.strictEqual(window.opener.parent.docRef.editform.text_data.value, "value.", "Search replace replaces all instances."); + assert.notOk($("#undo").prop("disabled"), "Undo should be enabled."); }); - QUnit.test("replaces -- instances", function(assert) { - setTextValue('brave -- new.'); - $('#search').val('--'); - $('#replace').val('-'); + QUnit.test("replaces -- instances", function (assert) { + setTextValue("brave -- new."); + $("#search").val("--"); + $("#replace").val("-"); srchrep.doReplace(); - assert.strictEqual( - window.opener.parent.docRef.editform.text_data.value, - 'brave - new.', - 'Search replace replaces all instances.'); - assert.notOk($('#undo').prop('disabled'), 'Undo should be enabled.'); + assert.strictEqual(window.opener.parent.docRef.editform.text_data.value, "brave - new.", "Search replace replaces all instances."); + assert.notOk($("#undo").prop("disabled"), "Undo should be enabled."); }); - QUnit.test("replaces with $ correctly", function(assert) { - setTextValue('brave -- new.'); - $('#search').val('--'); - $('#replace').val('$'); + QUnit.test("replaces with $ correctly", function (assert) { + setTextValue("brave -- new."); + $("#search").val("--"); + $("#replace").val("$"); srchrep.doReplace(); - assert.strictEqual( - window.opener.parent.docRef.editform.text_data.value, - 'brave $ new.', - 'Search replace replaces all instances.'); - assert.notOk($('#undo').prop('disabled'), 'Undo should be enabled.'); + assert.strictEqual(window.opener.parent.docRef.editform.text_data.value, "brave $ new.", "Search replace replaces all instances."); + assert.notOk($("#undo").prop("disabled"), "Undo should be enabled."); }); - QUnit.test("replaces with regular expression groups correctly", function(assert) { - setTextValue('brave -- new.'); - $('#search').val('(brave) -- (new)'); - $('#replace').val('$2 __ $1'); - $('#is_regex').prop('checked', true); + QUnit.test("replaces with regular expression groups correctly", function (assert) { + setTextValue("brave -- new."); + $("#search").val("(brave) -- (new)"); + $("#replace").val("$2 __ $1"); + $("#is_regex").prop("checked", true); srchrep.doReplace(); - assert.strictEqual( - window.opener.parent.docRef.editform.text_data.value, - 'new __ brave.', - 'Search replace replaces all instances.'); - assert.notOk($('#undo').prop('disabled'), 'Undo should be enabled.'); + assert.strictEqual(window.opener.parent.docRef.editform.text_data.value, "new __ brave.", "Search replace replaces all instances."); + assert.notOk($("#undo").prop("disabled"), "Undo should be enabled."); }); - QUnit.test("supports regular expressions", function(assert) { - setTextValue('Example search text.'); - $('#search').val('s.*ch'); - $('#replace').val(''); - $('#is_regex').prop('checked', true); + QUnit.test("supports regular expressions", function (assert) { + setTextValue("Example search text."); + $("#search").val("s.*ch"); + $("#replace").val(""); + $("#is_regex").prop("checked", true); srchrep.doReplace(); assert.strictEqual( window.opener.parent.docRef.editform.text_data.value, - 'Example text.', - 'Search replace replaces all instances with regular expressions.'); - assert.notOk($('#undo').prop('disabled'), 'Undo should be enabled.'); + "Example text.", + "Search replace replaces all instances with regular expressions.", + ); + assert.notOk($("#undo").prop("disabled"), "Undo should be enabled."); }); - QUnit.test("restore saved text undoes replace", function(assert) { - setTextValue('Example search text.'); - $('#search').val('search'); - $('#replace').val('sch'); + QUnit.test("restore saved text undoes replace", function (assert) { + setTextValue("Example search text."); + $("#search").val("search"); + $("#replace").val("sch"); srchrep.doReplace(); - assert.strictEqual( - window.opener.parent.docRef.editform.text_data.value, - 'Example sch text.', - 'Search replace replaces all instances.'); - assert.notOk($('#undo').prop('disabled'), 'Undo should be enabled.'); + assert.strictEqual(window.opener.parent.docRef.editform.text_data.value, "Example sch text.", "Search replace replaces all instances."); + assert.notOk($("#undo").prop("disabled"), "Undo should be enabled."); srchrep.restoreSavedText(); - assert.strictEqual( - window.opener.parent.docRef.editform.text_data.value, - 'Example search text.', - 'undo restores original text.'); - assert.ok($('#undo').prop('disabled'), 'Undo should be enabled.'); + assert.strictEqual(window.opener.parent.docRef.editform.text_data.value, "Example search text.", "undo restores original text."); + assert.ok($("#undo").prop("disabled"), "Undo should be enabled."); }); - QUnit.test("supports \\n for newlines as replace value", function(assert) { - setTextValue('Example search -- and replace search text value.'); - $('#search').val('search'); - $('#replace').val('s\\n'); + QUnit.test("supports \\n for newlines as replace value", function (assert) { + setTextValue("Example search -- and replace search text value."); + $("#search").val("search"); + $("#replace").val("s\\n"); srchrep.doReplace(); assert.strictEqual( window.opener.parent.docRef.editform.text_data.value, - 'Example s\r\n -- and replace s\r\n text value.', - 'Search replace replaces all instances with regular expressions.'); - assert.notOk($('#undo').prop('disabled'), 'Undo should be enabled.'); + "Example s\r\n -- and replace s\r\n text value.", + "Search replace replaces all instances with regular expressions.", + ); + assert.notOk($("#undo").prop("disabled"), "Undo should be enabled."); }); }); diff --git a/SETUP/tests/manual_web/split_test/switchable_split.js b/SETUP/tests/manual_web/split_test/switchable_split.js index 4dff323a18..2b1c678ff9 100644 --- a/SETUP/tests/manual_web/split_test/switchable_split.js +++ b/SETUP/tests/manual_web/split_test/switchable_split.js @@ -1,9 +1,8 @@ /* global $ splitControl */ $(function () { - function appendControlButton(controlDiv, theSplit, splitVert) { - let vSwitchButton = $("", {type: 'button', value: 'Switch to Vertical Split'}); - let hSwitchButton = $("", {type: 'button', value: 'Switch to Horizontal Split'}); + let vSwitchButton = $("", { type: "button", value: "Switch to Vertical Split" }); + let hSwitchButton = $("", { type: "button", value: "Switch to Horizontal Split" }); function setSplitControls(splitVertical) { if (splitVertical) { @@ -34,7 +33,7 @@ $(function () { } function appendIndicator(controlDiv, theSplit) { - let indicator = $("", {readonly: 'true'}); + let indicator = $("", { readonly: "true" }); $(controlDiv).append(indicator); theSplit.onDragEnd.add(function (percent) { indicator.val(percent); @@ -42,7 +41,7 @@ $(function () { } let initialSplitVertical = false; - let mainSplit = splitControl("#container", {splitVertical: initialSplitVertical}); + let mainSplit = splitControl("#container", { splitVertical: initialSplitVertical }); window.addEventListener("resize", mainSplit.reLayout); appendControlButton("#control-div", mainSplit, initialSplitVertical); appendIndicator("#control-div", mainSplit); diff --git a/SETUP/tests/manual_web/split_test/vertical_horizontal_split.js b/SETUP/tests/manual_web/split_test/vertical_horizontal_split.js index c539803e18..89fa259254 100644 --- a/SETUP/tests/manual_web/split_test/vertical_horizontal_split.js +++ b/SETUP/tests/manual_web/split_test/vertical_horizontal_split.js @@ -1,7 +1,7 @@ /* global $ splitControl */ $(function () { - let mainSplit = splitControl("#top-container", {dragBarColor: "green"}); - let subSplit = splitControl("#sub-container", {splitVertical: false, dragBarSize: 10, dragBarColor: "blue"}); + let mainSplit = splitControl("#top-container", { dragBarColor: "green" }); + let subSplit = splitControl("#sub-container", { splitVertical: false, dragBarSize: 10, dragBarColor: "blue" }); mainSplit.onResize.add(subSplit.reLayout); window.addEventListener("resize", mainSplit.reLayout); mainSplit.reLayout(); diff --git a/eslint.config.js b/eslint.config.js index e4bf8b7d6a..257e8c428a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -3,19 +3,19 @@ const pluginJs = require("@eslint/js"); const eslintConfigPrettier = require("eslint-config-prettier"); module.exports = [ - { files: ["**/*.js"] }, - { ignores: ["pinc/3rdparty", "**/vendor", "eslint.config.js"] }, - { - languageOptions: { - globals: globals.browser, - sourceType: "script", - }, + { files: ["**/*.js"] }, + { ignores: ["pinc/3rdparty", "**/vendor", "eslint.config.js"] }, + { + languageOptions: { + globals: globals.browser, + sourceType: "script", + }, - rules: { - "no-use-before-define": "error", - camelcase: "warn", + rules: { + "no-use-before-define": "error", + camelcase: "warn", + }, }, - }, - pluginJs.configs.recommended, - eslintConfigPrettier , + pluginJs.configs.recommended, + eslintConfigPrettier, ]; diff --git a/package.json b/package.json index 57d7038d52..fcfd75d09d 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "scripts": { "lint": "eslint --max-warnings=0", "lint-fix": "eslint --fix", - "format-check": "prettier */**.js --check", - "format": "prettier */**.js --write", + "format-check": "prettier '**/*.js' --check", + "format": "prettier '**/*.js' --write", "test": "node ./SETUP/tests/jsTests/jsUnit.js" }, "repository": { diff --git a/tools/project_manager/handle_bad_page.js b/tools/project_manager/handle_bad_page.js index fba8b526f4..8925c50851 100644 --- a/tools/project_manager/handle_bad_page.js +++ b/tools/project_manager/handle_bad_page.js @@ -3,8 +3,8 @@ window.addEventListener("DOMContentLoaded", () => { const updateTextButton = document.getElementById("update_text"); if (updateTextButton) { - updateTextButton.addEventListener("click", function(event) { - if(!validateText()) { + updateTextButton.addEventListener("click", function (event) { + if (!validateText()) { event.preventDefault(); } }); diff --git a/tools/project_manager/projectmgr.js b/tools/project_manager/projectmgr.js index 20fd165d07..62cb1f3293 100644 --- a/tools/project_manager/projectmgr.js +++ b/tools/project_manager/projectmgr.js @@ -6,10 +6,10 @@ window.addEventListener("DOMContentLoaded", () => { const timeSpan = document.getElementById("server-time"); const dateTimeFormat = new Intl.DateTimeFormat(userLanguage, { timeZone: serverTimezone, - hourCycle: 'h23', - hour: '2-digit', - minute: '2-digit', - weekday: 'short' + hourCycle: "h23", + hour: "2-digit", + minute: "2-digit", + weekday: "short", }); function showTime() { diff --git a/tools/project_manager/show_all_good_word_suggestions.js b/tools/project_manager/show_all_good_word_suggestions.js index 8672c0f957..63e1e8020e 100644 --- a/tools/project_manager/show_all_good_word_suggestions.js +++ b/tools/project_manager/show_all_good_word_suggestions.js @@ -1,6 +1,6 @@ /*global splitControl */ -window.addEventListener('DOMContentLoaded', function() { +window.addEventListener("DOMContentLoaded", function () { let mainSplit = splitControl("#suggestions_container", { splitVertical: true, splitPercent: 40, diff --git a/tools/project_manager/show_word_context.js b/tools/project_manager/show_word_context.js index 3aa5ac8ce3..4d831f71db 100644 --- a/tools/project_manager/show_word_context.js +++ b/tools/project_manager/show_word_context.js @@ -1,17 +1,17 @@ /*global splitControl pageBrowse showWordContext proofIntData */ -window.addEventListener("DOMContentLoaded", function() { +window.addEventListener("DOMContentLoaded", function () { let storageKeyLayout = showWordContext.storageKey + "-layout"; let layout; try { layout = JSON.parse(localStorage.getItem(storageKeyLayout)); - } catch(error) { // eslint-disable-line no-unused-vars + } catch { layout = null; } - if(!layout || !layout.splitDirection || !layout.splitPercent) { - layout = {splitPercent: 30, splitDirection: "horizontal"}; + if (!layout || !layout.splitDirection || !layout.splitPercent) { + layout = { splitPercent: 30, splitDirection: "horizontal" }; } - let splitVertical = (layout.splitDirection === "vertical"); + let splitVertical = layout.splitDirection === "vertical"; function saveLayout() { localStorage.setItem(storageKeyLayout, JSON.stringify(layout)); @@ -21,7 +21,7 @@ window.addEventListener("DOMContentLoaded", function() { let mainSplit = splitControl("#show_word_context_container", { splitVertical: splitVertical, - splitPercent: layout.splitPercent + splitPercent: layout.splitPercent, }); window.addEventListener("resize", mainSplit.reLayout); mainSplit.reLayout(); @@ -65,7 +65,7 @@ window.addEventListener("DOMContentLoaded", function() { } } - document.querySelectorAll(".page-select").forEach(pageSelect => { + document.querySelectorAll(".page-select").forEach((pageSelect) => { pageSelect.addEventListener("click", function () { showImage(this.dataset.value); }); diff --git a/tools/proofers/character_selector.js b/tools/proofers/character_selector.js index e289fb80c3..b77ae28207 100644 --- a/tools/proofers/character_selector.js +++ b/tools/proofers/character_selector.js @@ -33,22 +33,22 @@ $(function () { if (mruString) { mru = JSON.parse(mruString); } - if(!Array.isArray(mru)) { + if (!Array.isArray(mru)) { // this should only happen during development changes mru = []; } var pickerChars = {}; - $('.picker').each(function() { + $(".picker").each(function () { pickerChars[$(this).text()] = true; }); // filter out invalid characters - mru = mru.filter(function(mruCharacter) { + mru = mru.filter(function (mruCharacter) { return pickerChars[mruCharacter.character] === true; }); - window.addEventListener('beforeunload', function() { + window.addEventListener("beforeunload", function () { localStorage.setItem(storageKey, JSON.stringify(mru)); }); @@ -58,26 +58,22 @@ $(function () { function setAlign(element, title) { // to ensure the accents for Greek capital letters are visible, add a text indent. // see also similar code in pinc/CharacterSelector.inc - if(title.startsWith("GREEK CAPITAL") && (title.includes("OXIA") || title.includes("VARIA"))) { - element.style.textIndent = '0.35em'; + if (title.startsWith("GREEK CAPITAL") && (title.includes("OXIA") || title.includes("VARIA"))) { + element.style.textIndent = "0.35em"; } else { - element.style.textIndent = '0'; + element.style.textIndent = "0"; } } function drawRow(mruRow) { // it is not necessary to escape the character or title - var row = $('
').addClass('table-row'); - mruRow.forEach(function(element) { - let mruButton = $('