Skip to content

Commit

Permalink
Change no-console to error, only for ext files
Browse files Browse the repository at this point in the history
  • Loading branch information
toasted-nutbread committed Dec 10, 2023
1 parent 7cea3d9 commit 0f51fac
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"no-case-declarations": "error",
"no-const-assign": "error",
"no-constant-condition": "off",
"no-console": "warn",
"no-global-assign": "error",
"no-param-reassign": "off",
"no-prototype-builtins": "error",
Expand Down Expand Up @@ -558,6 +557,14 @@
]
}
},
{
"files": [
"ext/**/*.js"
],
"rules": {
"no-console": "error"
}
},
{
"files": [
"ext/js/core.js",
Expand Down
2 changes: 2 additions & 0 deletions ext/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,15 @@ export class Logger extends EventDispatcher {
}
message += '\n\nIssues can be reported at https://github.com/themoeway/yomitan/issues';

/* eslint-disable no-console */
switch (level) {
case 'info': console.info(message); break;
case 'debug': console.debug(message); break;
case 'warn': console.warn(message); break;
case 'error': console.error(message); break;
default: console.log(message); break;
}
/* eslint-enable no-console */

this.trigger('log', {error, level, context});
}
Expand Down
1 change: 1 addition & 0 deletions ext/js/debug/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class Timer {
Timer.current = this.parent;
if (this.parent === null) {
if (!skip) {
// eslint-disable-next-line no-console
console.log(this.toString());
}
} else {
Expand Down
1 change: 1 addition & 0 deletions ext/js/display/display-anki.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ export class DisplayAnki {
const content = this._display.displayGenerator.createAnkiNoteErrorsNotificationContent(displayErrors);
for (const node of content.querySelectorAll('.anki-note-error-log-link')) {
/** @type {EventListenerCollection} */ (this._errorNotificationEventListeners).addEventListener(node, 'click', () => {
// eslint-disable-next-line no-console
console.log({ankiNoteErrors: errors});
}, false);
}
Expand Down
1 change: 1 addition & 0 deletions ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,7 @@ export class Display extends EventDispatcher {
}
}

// eslint-disable-next-line no-console
console.log(result);
}

Expand Down
1 change: 1 addition & 0 deletions ext/js/dom/sandbox/css-style-applier.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class CssStyleApplier {
try {
rawData = await this._fetchJsonAsset(this._styleDataUrl);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
const styleData = this._styleData;
Expand Down
1 change: 1 addition & 0 deletions ext/js/pages/settings/anki-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export class AnkiController {
/** */
_onAnkiErrorLogLinkClick() {
if (this._ankiError === null) { return; }
// eslint-disable-next-line no-console
console.log({error: this._ankiError});
}

Expand Down
6 changes: 6 additions & 0 deletions ext/js/pages/settings/backup-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,14 @@ export class BackupController {
* @param {{totalRows: number, completedRows: number, done: boolean}} details
*/
_databaseExportProgressCallback({totalRows, completedRows, done}) {
// eslint-disable-next-line no-console
console.log(`Progress: ${completedRows} of ${totalRows} rows completed`);
const messageContainer = /** @type {HTMLElement} */ (document.querySelector('#db-ops-progress-report'));
messageContainer.style.display = 'block';
messageContainer.textContent = `Export Progress: ${completedRows} of ${totalRows} rows completed`;

if (done) {
// eslint-disable-next-line no-console
console.log('Done exporting.');
messageContainer.style.display = 'none';
}
Expand Down Expand Up @@ -600,6 +602,7 @@ export class BackupController {
const blob = new Blob([data], {type: 'application/json'});
this._saveBlob(blob, fileName);
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
this._databaseExportImportErrorMessage('Errors encountered while exporting. Please try again. Restart the browser if it continues to fail.');
} finally {
Expand All @@ -614,13 +617,15 @@ export class BackupController {
* @param {{totalRows: number, completedRows: number, done: boolean}} details
*/
_databaseImportProgressCallback({totalRows, completedRows, done}) {
// eslint-disable-next-line no-console
console.log(`Progress: ${completedRows} of ${totalRows} rows completed`);
const messageContainer = /** @type {HTMLElement} */ (document.querySelector('#db-ops-progress-report'));
messageContainer.style.display = 'block';
messageContainer.style.color = '#4169e1';
messageContainer.textContent = `Import Progress: ${completedRows} of ${totalRows} rows completed`;

if (done) {
// eslint-disable-next-line no-console
console.log('Done importing.');
messageContainer.style.color = '#006633';
messageContainer.textContent = 'Done importing. You will need to re-enable the dictionaries and refresh afterward. If you run into issues, please restart the browser. If it continues to fail, reinstall Yomitan and import dictionaries one-by-one.';
Expand Down Expand Up @@ -668,6 +673,7 @@ export class BackupController {
this._settingsExportDatabaseToken = token;
await this._importDatabase(this._dictionariesDatabaseName, file);
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
const messageContainer = /** @type {HTMLElement} */ (document.querySelector('#db-ops-progress-report'));
messageContainer.style.color = 'red';
Expand Down

0 comments on commit 0f51fac

Please sign in to comment.