Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change no-console to error, only for ext files #352

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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