summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-14 22:26:29 -0500
committerGitHub <noreply@github.com>2024-02-15 03:26:29 +0000
commit6bf7b0055765c4f2011c9614753d6714dc09be65 (patch)
tree0e782ae66556eaa61a34d9f32d77c831b2443ce5 /test
parent7a4096240ce4faf70a785d047945388baa0daab3 (diff)
Eslint rule updates (#673)
* Install unicorn * Add rules * Fix issues * Install sonarjs * Set up rules * Fix issues * Install eslint-plugin-import and fix import extensions * Simplify permitted error names
Diffstat (limited to 'test')
-rw-r--r--test/css-json.test.js2
-rw-r--r--test/data/html/js/html-test-utilities.js4
-rw-r--r--test/dictionary-data-validate.test.js10
-rw-r--r--test/document-util.test.js5
-rw-r--r--test/dom-text-scanner.test.js10
-rw-r--r--test/fixtures/anki-template-renderer-test.js1
-rw-r--r--test/fixtures/translator-test.js1
-rw-r--r--test/json.test.js10
-rw-r--r--test/playwright/global.setup.js4
-rw-r--r--test/playwright/global.teardown.js2
-rw-r--r--test/playwright/integration.spec.js4
-rw-r--r--test/playwright/visual.spec.js2
12 files changed, 30 insertions, 25 deletions
diff --git a/test/css-json.test.js b/test/css-json.test.js
index b64419c3..87d24d6c 100644
--- a/test/css-json.test.js
+++ b/test/css-json.test.js
@@ -18,7 +18,7 @@
import fs from 'fs';
import {describe, expect, test} from 'vitest';
-import {formatRulesJson, generateRules, getTargets} from '../dev/generate-css-json';
+import {formatRulesJson, generateRules, getTargets} from '../dev/generate-css-json.js';
/** */
function main() {
diff --git a/test/data/html/js/html-test-utilities.js b/test/data/html/js/html-test-utilities.js
index b72b7fca..c3382456 100644
--- a/test/data/html/js/html-test-utilities.js
+++ b/test/data/html/js/html-test-utilities.js
@@ -16,6 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+/**
+ * This is a static class because this file is not imported as a module.
+ */
+// eslint-disable-next-line unicorn/no-static-only-class
class HtmlTestUtilities {
/**
* @param {Element} element
diff --git a/test/dictionary-data-validate.test.js b/test/dictionary-data-validate.test.js
index 4c96cdb0..b09e4ae0 100644
--- a/test/dictionary-data-validate.test.js
+++ b/test/dictionary-data-validate.test.js
@@ -48,11 +48,11 @@ describe('Dictionary validation', () => {
describe.each(testCases)('Test dictionary $name', ({name, valid}) => {
it(`should be ${valid ? 'valid' : 'invalid'}`, async ({expect}) => {
const archive = createTestDictionaryArchive(name);
- if (valid) {
- await expect(dictionaryValidate.validateDictionary(null, archive, schemas)).resolves.not.toThrow();
- } else {
- await expect(dictionaryValidate.validateDictionary(null, archive, schemas)).rejects.toThrow();
- }
+ await (
+ valid ?
+ expect(dictionaryValidate.validateDictionary(null, archive, schemas)).resolves.not.toThrow() :
+ expect(dictionaryValidate.validateDictionary(null, archive, schemas)).rejects.toThrow()
+ );
});
});
});
diff --git a/test/document-util.test.js b/test/document-util.test.js
index 18a5d42c..c2b2edca 100644
--- a/test/document-util.test.js
+++ b/test/document-util.test.js
@@ -159,12 +159,13 @@ describe('Document utility tests', () => {
expect(!!imposter).toStrictEqual(!!hasImposter);
const range = document.createRange();
- range.setStart(/** @type {Node} */ (imposter ? imposter : startNode), startOffset);
- range.setEnd(/** @type {Node} */ (imposter ? imposter : startNode), endOffset);
+ range.setStart(/** @type {Node} */ (imposter ?? startNode), startOffset);
+ range.setEnd(/** @type {Node} */ (imposter ?? startNode), endOffset);
// Override getClientRects to return a rect guaranteed to contain (x, y)
range.getClientRects = () => {
/** @type {import('test/document-types').PseudoDOMRectList} */
+ // eslint-disable-next-line sonarjs/prefer-immediate-return
const domRectList = Object.assign(
[new DOMRect(x - 1, y - 1, 2, 2)],
{
diff --git a/test/dom-text-scanner.test.js b/test/dom-text-scanner.test.js
index e86d2980..1ec7cab7 100644
--- a/test/dom-text-scanner.test.js
+++ b/test/dom-text-scanner.test.js
@@ -34,7 +34,7 @@ function querySelectorTextNode(element, selector) {
let textIndex = -1;
const match = /::text$|::nth-text\((\d+)\)$/.exec(selector);
if (match !== null) {
- textIndex = (match[1] ? parseInt(match[1], 10) - 1 : 0);
+ textIndex = (match[1] ? Number.parseInt(match[1], 10) - 1 : 0);
selector = selector.substring(0, selector.length - match[0].length);
}
const result = element.querySelector(selector);
@@ -67,13 +67,11 @@ function getComputedFontSizeInPixels(window, getComputedStyle, element) {
if (element.nodeType === window.Node.ELEMENT_NODE) {
const fontSize = getComputedStyle(/** @type {Element} */ (element)).fontSize;
if (fontSize.endsWith('px')) {
- const value = parseFloat(fontSize.substring(0, fontSize.length - 2));
- return value;
+ return Number.parseFloat(fontSize.substring(0, fontSize.length - 2));
}
}
}
- const defaultFontSize = 14;
- return defaultFontSize;
+ return 14; // Default font size
}
/**
@@ -92,7 +90,7 @@ function createAbsoluteGetComputedStyle(window) {
if (typeof result === 'string') {
result = result.replace(/([-+]?\d(?:\.\d)?(?:[eE][-+]?\d+)?)em/g, (g0, g1) => {
const fontSize = getComputedFontSizeInPixels(window, getComputedStyleOld, element);
- return `${parseFloat(g1) * fontSize}px`;
+ return `${Number.parseFloat(g1) * fontSize}px`;
});
}
return result;
diff --git a/test/fixtures/anki-template-renderer-test.js b/test/fixtures/anki-template-renderer-test.js
index de447126..635e0b7d 100644
--- a/test/fixtures/anki-template-renderer-test.js
+++ b/test/fixtures/anki-template-renderer-test.js
@@ -30,6 +30,7 @@ export async function createAnkiTemplateRendererTest() {
const ankiTemplateRenderer = new AnkiTemplateRenderer();
await ankiTemplateRenderer.prepare();
/** @type {import('vitest').TestAPI<{window: import('jsdom').DOMWindow, ankiTemplateRenderer: AnkiTemplateRenderer}>} */
+ // eslint-disable-next-line sonarjs/prefer-immediate-return
const result = test.extend({
window: async ({window}, use) => { await use(window); },
ankiTemplateRenderer: async ({window}, use) => {
diff --git a/test/fixtures/translator-test.js b/test/fixtures/translator-test.js
index a4c65b88..f39d832b 100644
--- a/test/fixtures/translator-test.js
+++ b/test/fixtures/translator-test.js
@@ -81,6 +81,7 @@ export async function createTranslatorTest(htmlFilePath, dictionaryDirectory, di
const test = createDomTest(htmlFilePath);
const translator = await createTranslatorContext(dictionaryDirectory, dictionaryName);
/** @type {import('vitest').TestAPI<{window: import('jsdom').DOMWindow, translator: Translator}>} */
+ // eslint-disable-next-line sonarjs/prefer-immediate-return
const result = test.extend({
window: async ({window}, use) => { await use(window); },
// eslint-disable-next-line no-empty-pattern
diff --git a/test/json.test.js b/test/json.test.js
index 0689913a..aa12dc09 100644
--- a/test/json.test.js
+++ b/test/json.test.js
@@ -110,11 +110,11 @@ describe.concurrent('JSON validation', () => {
const existingJsonFiles = getAllFiles(rootDir, (path, isDirectory) => {
const fileNameNormalized = normalizePathDirectorySeparators(path);
- if (isDirectory) {
- return !ignoreDirectories.has(fileNameNormalized);
- } else {
- return /\.json$/i.test(fileNameNormalized);
- }
+ return (
+ isDirectory ?
+ !ignoreDirectories.has(fileNameNormalized) :
+ /\.json$/i.test(fileNameNormalized)
+ );
});
/** @type {Set<string>} */
const existingJsonFileSet = new Set();
diff --git a/test/playwright/global.setup.js b/test/playwright/global.setup.js
index 8c2f8b50..63452397 100644
--- a/test/playwright/global.setup.js
+++ b/test/playwright/global.setup.js
@@ -18,8 +18,8 @@
import {test as setup} from '@playwright/test';
import fs from 'fs';
import path from 'path';
-import {ManifestUtil} from '../../dev/manifest-util';
-import {root} from './playwright-util';
+import {ManifestUtil} from '../../dev/manifest-util.js';
+import {root} from './playwright-util.js';
const manifestPath = path.join(root, 'ext/manifest.json');
const copyManifestPath = path.join(root, 'ext/manifest-old.json');
diff --git a/test/playwright/global.teardown.js b/test/playwright/global.teardown.js
index f3d8897f..e747e5fd 100644
--- a/test/playwright/global.teardown.js
+++ b/test/playwright/global.teardown.js
@@ -18,7 +18,7 @@
import {test as teardown} from '@playwright/test';
import fs from 'fs';
import path from 'path';
-import {root} from './playwright-util';
+import {root} from './playwright-util.js';
const manifestPath = path.join(root, 'ext/manifest.json');
const copyManifestPath = path.join(root, 'ext/manifest-old.json');
diff --git a/test/playwright/integration.spec.js b/test/playwright/integration.spec.js
index bdcfddf0..170714a1 100644
--- a/test/playwright/integration.spec.js
+++ b/test/playwright/integration.spec.js
@@ -16,7 +16,7 @@
*/
import path from 'path';
-import {createDictionaryArchive} from '../../dev/util';
+import {createDictionaryArchive} from '../../dev/util.js';
import {
expect,
expectedAddNoteBody,
@@ -26,7 +26,7 @@ import {
root,
test,
writeToClipboardFromPage
-} from './playwright-util';
+} from './playwright-util.js';
test.beforeEach(async ({context}) => {
// Wait for the on-install welcome.html tab to load, which becomes the foreground tab
diff --git a/test/playwright/visual.spec.js b/test/playwright/visual.spec.js
index cc2a50d0..fc8bb8df 100644
--- a/test/playwright/visual.spec.js
+++ b/test/playwright/visual.spec.js
@@ -17,7 +17,7 @@
import path from 'path';
import {pathToFileURL} from 'url';
-import {expect, root, test} from './playwright-util';
+import {expect, root, test} from './playwright-util.js';
test.beforeEach(async ({context}) => {
// Wait for the on-install welcome.html tab to load, which becomes the foreground tab