Skip to content

Commit

Permalink
Chore: Implement eslint rule no-unused-expressions (#11533)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 authored Dec 18, 2024
1 parent 482c9e9 commit 3cba4ec
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/app-desktop/gui/NoteContentPropertiesDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-mobile/services/voiceTyping/vosk.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const startRecording = (vosk: Vosk, options: StartOptions): VoiceTypingSe
eventHandler.remove();
}

vosk.cleanup(),
vosk.cleanup();

state_ = State.Idle;

Expand Down
22 changes: 16 additions & 6 deletions packages/app-mobile/web/serviceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions packages/default-plugins/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion packages/lib/SyncTargetOneDrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/lib/clipperUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions packages/lib/services/e2ee/cryptoTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/services/ocr/OcrService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/services/synchronizer/ItemUploader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/shim-init-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-repo-cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]')
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/routes/index/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/services/TaskService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions packages/tools/update-readme-contributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ interface Contributor {
html_url: string;
}

rootDir;

const readmePath = `${rootDir}/README.md`;
const { insertContentIntoFile } = require('./tool-utils.js');

Expand Down
6 changes: 3 additions & 3 deletions packages/tools/website/processDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3cba4ec

Please sign in to comment.