1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00

Chore: Implement eslint rule no-unused-expressions (#11533)

This commit is contained in:
Laurent Cozic 2024-12-18 14:30:05 +01:00 committed by GitHub
parent 482c9e9aab
commit 3cba4ec82c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 37 additions and 19 deletions

View File

@ -31,6 +31,7 @@ packages/app-cli/tests/tmp
packages/app-clipper/content_scripts/JSDOMParser.js
packages/app-clipper/content_scripts/Readability-readerable.js
packages/app-clipper/content_scripts/Readability.js
packages/app-clipper/content_scripts/clipperUtils.js
packages/app-clipper/dist
packages/app-clipper/icons
packages/app-clipper/popup/build

View File

@ -87,6 +87,7 @@ module.exports = {
allowEmptyReject: true,
}],
'no-throw-literal': ['error'],
'no-unused-expressions': ['error'],
// This rule should not be enabled since it matters in what order
// imports are done, in particular in relation to the shim.setReact

View File

@ -38,7 +38,7 @@ function countElements(text: string, wordSetter: Function, characterSetter: Func
characterSetter(counter.all);
characterNoSpaceSetter(counter.characters);
});
text === '' ? lineSetter(0) : lineSetter(text.split('\n').length);
lineSetter(text === '' ? 0 : text.split('\n').length);
}
function formatReadTime(readTimeMinutes: number) {

View File

@ -117,7 +117,7 @@ export const startRecording = (vosk: Vosk, options: StartOptions): VoiceTypingSe
eventHandler.remove();
}
vosk.cleanup(),
vosk.cleanup();
state_ = State.Idle;

View File

@ -207,6 +207,16 @@ if (typeof window === 'undefined') {
quiet: false,
};
const consoleLog = (...args: unknown[]) => {
if (coi.quiet) return;
console.log(...args);
};
const consoleError = (...args: unknown[]) => {
if (coi.quiet) return;
console.error(...args);
};
const n = navigator;
const controlling = n.serviceWorker && n.serviceWorker.controller;
@ -228,7 +238,7 @@ if (typeof window === 'undefined') {
: coi.coepCredentialless(),
});
if (reloadToDegrade) {
!coi.quiet && console.log('Reloading page to degrade COEP.');
consoleLog('Reloading page to degrade COEP.');
window.sessionStorage.setItem('coiReloadedBySelf', 'coepDegrade');
coi.doReload();
}
@ -245,28 +255,28 @@ if (typeof window === 'undefined') {
// if (window.crossOriginIsolated !== false || !coi.shouldRegister()) return;
if (!window.isSecureContext) {
!coi.quiet && console.log('COOP/COEP Service Worker not registered, a secure context is required.');
consoleLog('COOP/COEP Service Worker not registered, a secure context is required.');
return;
}
// In some environments (e.g. Firefox private mode) this won't be available
if (!n.serviceWorker) {
!coi.quiet && console.error('COOP/COEP Service Worker not registered, perhaps due to private mode.');
consoleError('COOP/COEP Service Worker not registered, perhaps due to private mode.');
return;
}
const registration = await n.serviceWorker.register(window.document.currentScript.getAttribute('src'));
!coi.quiet && console.log('COOP/COEP Service Worker registered', registration.scope);
consoleLog('COOP/COEP Service Worker registered', registration.scope);
registration.addEventListener('updatefound', () => {
!coi.quiet && console.log('Reloading page to make use of updated COOP/COEP Service Worker.');
consoleLog('Reloading page to make use of updated COOP/COEP Service Worker.');
window.sessionStorage.setItem('coiReloadedBySelf', 'updatefound');
coi.doReload();
});
// If the registration is active, but it's not controlling the page
if (registration.active && !n.serviceWorker.controller) {
!coi.quiet && console.log('Reloading page to make use of COOP/COEP Service Worker.');
consoleLog('Reloading page to make use of COOP/COEP Service Worker.');
window.sessionStorage.setItem('coiReloadedBySelf', 'notControlling');
coi.doReload();
}

View File

@ -4,6 +4,7 @@ const yargs = require('yargs');
const build = () => {
// eslint-disable-next-line no-unused-expressions -- Old code before rule was applied
yargs
.usage('$0 <cmd> [args]')
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied

View File

@ -108,7 +108,11 @@ export default class SyncTargetOneDrive extends BaseSyncTarget {
if (!accountProperties) {
accountProperties = await api.execAccountPropertiesRequest();
context ? context.accountProperties = accountProperties : context = { accountProperties: accountProperties };
if (context) {
context.accountProperties = accountProperties;
} else {
context = { accountProperties: accountProperties };
}
Setting.setValue(`sync.${this.syncTargetId()}.context`, JSON.stringify(context));
}
api.setAccountProperties(accountProperties);

View File

@ -139,4 +139,5 @@ export function getStyleSheets(doc: Document) {
// Required to run in Firefox with tabs.executeScript. See
// https://stackoverflow.com/a/44774834
// eslint-disable-next-line no-unused-expressions -- Old code before rule was applied
undefined;

View File

@ -113,6 +113,7 @@ export async function testStringPerformance(method: EncryptionMethod, dataSize:
const deserialized = await Note.unserialize(serialized);
const decryptedNote = await Note.decrypt(deserialized);
const tick3 = performance.now();
// eslint-disable-next-line no-unused-expressions -- Old code before rule was applied
(decryptedNote.title === note.title);
encryptTime += tick2 - tick1;
decryptTime += tick3 - tick2;

View File

@ -135,7 +135,7 @@ export default class OcrService {
const result = await this.recognize(language, resource);
toSave.ocr_status = ResourceOcrStatus.Done;
toSave.ocr_text = filterOcrText(result.text);
toSave.ocr_details = Resource.serializeOcrDetails(result.lines),
toSave.ocr_details = Resource.serializeOcrDetails(result.lines);
toSave.ocr_error = '';
} catch (error) {
const errorMessage = typeof error === 'string' ? error : error?.message;

View File

@ -117,7 +117,7 @@ describe('synchronizer/ItemUploader', () => {
expect(callRecorder.length).toBe(0);
await time.msleep(1);
notes[1] = await Note.save({ title: '22' }),
notes[1] = await Note.save({ title: '22' });
await itemUploader.serializeAndUploadItem(Note, BaseItem.systemPath(notes[1]), notes[1]);
expect(callRecorder.length).toBe(1);
}));

View File

@ -465,7 +465,7 @@ function shimInit(options: ShimInitOptions = null) {
} else {
throw new Error('Unsupported method');
}
},
};
shim.imageFromDataUrl = async function(imageDataUrl, filePath, options = null) {
if (options === null) options = {};

View File

@ -302,6 +302,7 @@ async function main() {
selectedCommandArgs = args;
}
// eslint-disable-next-line no-unused-expressions -- Old code before rule was applied
require('yargs')
.scriptName(scriptName)
.usage('$0 <cmd> [args]')

View File

@ -68,7 +68,7 @@ router.get('items', async (_path: SubPath, ctx: AppContext) => {
};
const view: View = defaultView('items', 'Items');
view.content.itemTable = makeTableView(table),
view.content.itemTable = makeTableView(table);
view.content.postUrl = `${config().baseUrl}/items`;
view.cssFiles = ['index/items'];
return view;

View File

@ -65,7 +65,7 @@ describe('TaskService', () => {
const tasks = createDemoTasks();
tasks[0].run = async (_models: Models) => {
taskHasRan = true;
},
};
await service.registerTasks(tasks);
const taskId = tasks[0].id;

View File

@ -8,8 +8,6 @@ interface Contributor {
html_url: string;
}
rootDir;
const readmePath = `${rootDir}/README.md`;
const { insertContentIntoFile } = require('./tool-utils.js');

View File

@ -159,13 +159,13 @@ const processToken = (token: any, output: string[], context: Context): void => {
context.inFence = true;
content.push(`\`\`\`${token.info || ''}\n`);
} else if (type === 'html_block') {
contentProcessed = true,
contentProcessed = true;
content.push(parseHtml(token.content.trim()));
} else if (type === 'html_inline') {
contentProcessed = true,
contentProcessed = true;
content.push(parseHtml(token.content.trim()));
} else if (type === 'code_inline') {
contentProcessed = true,
contentProcessed = true;
content.push(`\`${token.content}\``);
} else if (type === 'code_block') {
contentProcessed = true;