Skip to content

Commit

Permalink
update eslint to 9.*, and redo a couple things that are required to s…
Browse files Browse the repository at this point in the history
…upport it
  • Loading branch information
djahandarie committed Dec 28, 2024
1 parent 00bf5fc commit e276ddd
Show file tree
Hide file tree
Showing 15 changed files with 11,925 additions and 9,643 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

735 changes: 0 additions & 735 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The generated `ext/manfiest.json` should not be committed.
Linting rules are defined for a few types of files, and validation is performed as part of the standard tests
run by `npm test` and the continuous integration process.

- [.eslintrc.json](.eslintrc.json) rules are used for JavaScript files.
- [eslint.config.js](eslint.config.js) rules are used for JavaScript files.
- [.stylelintrc.json](.stylelintrc.json) rules are used for CSS files.
- [.htmlvalidate.json](.htmlvalidate.json) rules are used for HTML files.

Expand Down
128 changes: 96 additions & 32 deletions dev/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,102 @@
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"api-map": ["../types/ext/api-map"],
"anki-templates": ["../types/ext/anki-templates"],
"anki-templates-internal": ["../types/ext/anki-templates-internal"],
"cache-map": ["../types/ext/cache-map"],
"core": ["../types/ext/core"],
"css-style-applier": ["../types/ext/css-style-applier"],
"database": ["../types/ext/database"],
"dictionary": ["../types/ext/dictionary"],
"dictionary-data": ["../types/ext/dictionary-data"],
"dictionary-data-util": ["../types/ext/dictionary-data-util"],
"dictionary-database": ["../types/ext/dictionary-database"],
"dictionary-importer": ["../types/ext/dictionary-importer"],
"dictionary-importer-media-loader": ["../types/ext/dictionary-importer-media-loader"],
"dynamic-property": ["../types/ext/dynamic-property"],
"error": ["../types/ext/error"],
"event-listener-collection": ["../types/ext/event-listener-collection"],
"japanese-util": ["../types/ext/japanese-util"],
"language": ["../types/ext/language"],
"language-descriptors": ["../types/ext/language-descriptors"],
"CJK-util": ["../types/ext/CJK-util"],
"ext/json-schema": ["../types/ext/json-schema"],
"language-transformer": ["../types/ext/language-transformer"],
"language-transformer-internal": ["../types/ext/language-transformer-internal"],
"log": ["../types/ext/log"],
"settings": ["../types/ext/settings"],
"structured-content": ["../types/ext/structured-content"],
"translator": ["../types/ext/translator"],
"translation": ["../types/ext/translation"],
"translation-internal": ["../types/ext/translation-internal"],
"dev/*": ["../types/dev/*"],
"rollup/parseAst": ["../types/other/rollup-parse-ast"],
"chai": ["../node_modules/@vitest/expect/dist/chai.d.cts"]
"api-map": [
"../types/ext/api-map"
],
"anki-templates": [
"../types/ext/anki-templates"
],
"anki-templates-internal": [
"../types/ext/anki-templates-internal"
],
"cache-map": [
"../types/ext/cache-map"
],
"core": [
"../types/ext/core"
],
"css-style-applier": [
"../types/ext/css-style-applier"
],
"database": [
"../types/ext/database"
],
"dictionary": [
"../types/ext/dictionary"
],
"dictionary-data": [
"../types/ext/dictionary-data"
],
"dictionary-data-util": [
"../types/ext/dictionary-data-util"
],
"dictionary-database": [
"../types/ext/dictionary-database"
],
"dictionary-importer": [
"../types/ext/dictionary-importer"
],
"dictionary-importer-media-loader": [
"../types/ext/dictionary-importer-media-loader"
],
"dynamic-property": [
"../types/ext/dynamic-property"
],
"error": [
"../types/ext/error"
],
"event-listener-collection": [
"../types/ext/event-listener-collection"
],
"japanese-util": [
"../types/ext/japanese-util"
],
"language": [
"../types/ext/language"
],
"language-descriptors": [
"../types/ext/language-descriptors"
],
"CJK-util": [
"../types/ext/CJK-util"
],
"ext/json-schema": [
"../types/ext/json-schema"
],
"language-transformer": [
"../types/ext/language-transformer"
],
"language-transformer-internal": [
"../types/ext/language-transformer-internal"
],
"log": [
"../types/ext/log"
],
"settings": [
"../types/ext/settings"
],
"structured-content": [
"../types/ext/structured-content"
],
"translator": [
"../types/ext/translator"
],
"translation": [
"../types/ext/translation"
],
"translation-internal": [
"../types/ext/translation-internal"
],
"dev/*": [
"../types/dev/*"
],
"rollup/parseAst": [
"../types/other/rollup-parse-ast"
],
"chai": [
"../node_modules/@vitest/expect/dist/chai.d.cts"
]
},
"types": [
"node",
Expand Down
1 change: 0 additions & 1 deletion ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export class Backend {
this._translator = new Translator(this._dictionaryDatabase);
/** @type {ClipboardReader|ClipboardReaderProxy} */
this._clipboardReader = new ClipboardReader(
// eslint-disable-next-line no-undef
(typeof document === 'object' && document !== null ? document : null),
'#clipboard-paste-target',
'#clipboard-rich-content-paste-target',
Expand Down
2 changes: 1 addition & 1 deletion ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ export class OptionsUtil {
const terminationCharacters = profile.options.sentenceParsing.terminationCharacters;
const newAdditions = [];
for (const character of additions) {
if (terminationCharacters.findIndex((value) => (value.character1 === character && value.character2 === null)) < 0) {
if (!terminationCharacters.some((value) => (value.character1 === character && value.character2 === null))) {
newAdditions.push(character);
}
}
Expand Down
2 changes: 0 additions & 2 deletions ext/js/dictionary/dictionary-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,12 @@ export class DictionaryDatabase {
// The second branch can eventually be changed to use ImageDecoder when we are okay with dropping support for Firefox <133
// The branches can be unified entirely when Firefox implements support for transferring VideoFrames cross-process in postMessage
if ('serviceWorker' in navigator) { // this is just a check for chrome, we don't actually use service worker functionality here
// eslint-disable-next-line no-undef
const imageDecoder = new ImageDecoder({type: m.mediaType, data: m.content});
await imageDecoder.decode().then((decodedImageResult) => {
source.postMessage({action: 'drawDecodedImageToCanvases', params: {decodedImage: decodedImageResult.image, canvasIndexes: m.canvasIndexes, generation: m.generation}}, [decodedImageResult.image]);
});
} else {
const image = new Blob([m.content], {type: m.mediaType});
// eslint-disable-next-line no-undef
await createImageBitmap(image, {resizeWidth: m.canvasWidth, resizeHeight: m.canvasHeight, resizeQuality: 'high'}).then((decodedImage) => {
// we need to do a dumb hack where we convert this ImageBitmap to an ImageData by drawing it to a temporary canvas, because Firefox doesn't support transferring ImageBitmaps cross-process
const canvas = new OffscreenCanvas(decodedImage.width, decodedImage.height);
Expand Down
2 changes: 0 additions & 2 deletions ext/js/pages/permissions-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ await Application.main(true, async (application) => {
/** @type {HTMLInputElement} */
const permissionCheckbox2 = querySelectorNotNull(document, '#permission-checkbox-allow-file-url-access');
/** @type {HTMLInputElement[]} */
// This collection is actually used, not sure why this eslint-disable is needed.
// eslint-disable-next-line sonarjs/no-unused-collection
const permissionsCheckboxes = [permissionCheckbox1, permissionCheckbox2];

const permissions = await Promise.all([
Expand Down
4 changes: 3 additions & 1 deletion ext/js/pages/settings/dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,9 @@ export class DictionaryController {
const dictionaries = this._dictionaries;
if (dictionaries === null) { return; }

this._dictionaryEntries.map((dictionaryEntry) => dictionaryEntry.cleanup());
for (const dictionaryEntry of this._dictionaryEntries) {
dictionaryEntry.cleanup();
}

const dictionaryOptionsArray = options.dictionaries;
for (let i = 0; i < dictionaryOptionsArray.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion ext/js/pages/settings/profile-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ export class ProfileController {
let i = 0;
while (true) {
const newName = `${prefix}${space}${index}${suffix}`;
if (i++ >= maxUniqueAttempts || profiles.findIndex((profile) => profile.name === newName) < 0) {
if (i++ >= maxUniqueAttempts || !profiles.some((profile) => profile.name === newName)) {
return newName;
}
if (typeof index !== 'number') {
Expand Down
4 changes: 2 additions & 2 deletions ext/js/pages/settings/recommended-settings-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ export class RecommendedSettingsController {
}
void this._settingsController.modifyProfileSettings(modifications).then(
(results) => {
results.map((result) => {
for (const result of results) {
if (Object.hasOwn(result, 'error')) {
log.error(new Error(`Failed to apply recommended setting: ${JSON.stringify(result)}`));
}
});
}
},
);
void this._settingsController.refresh();
Expand Down
Loading

0 comments on commit e276ddd

Please sign in to comment.