Skip to content

chore(eslint-config): replace no-unused-expressions with chai-friendly version COMPASS-9459 #7018

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

Merged
merged 1 commit into from
Jun 16, 2025
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
6 changes: 4 additions & 2 deletions configs/eslint-config-compass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const path = require('path');
const shared = require('@mongodb-js/eslint-config-devtools');
const common = require('@mongodb-js/eslint-config-devtools/common');
const chaiFriendly = require('eslint-plugin-chai-friendly');

const extraTsRules = {
// Newly converted plugins use `any` quite a lot, we can't enable the rule,
Expand All @@ -15,6 +16,8 @@ const extraTsRules = {
'error',
{ fixMixedExportsWithInlineTypeSpecifier: false },
],
// We use chai outside of tests, hence applying these rules to all ts files
...chaiFriendly.configs.recommended.rules,
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/only-throw-error': 'off',

Expand All @@ -29,7 +32,6 @@ const extraTsRules = {
caughtErrors: 'none', // should be `'all'`
},
],
'@typescript-eslint/no-unused-expressions': 'off', // replace with eslint-plugin-chai-friendly
'@typescript-eslint/no-redundant-type-constituents': 'warn',
'@typescript-eslint/unbound-method': 'warn',
'@typescript-eslint/no-duplicate-type-constituents': 'warn',
Expand Down Expand Up @@ -107,7 +109,7 @@ const testTsOverrides = {
};

module.exports = {
plugins: [...shared.plugins, '@mongodb-js/compass'],
plugins: [...shared.plugins, '@mongodb-js/compass', 'chai-friendly'],
rules: {
...shared.rules,
'@mongodb-js/compass/no-leafygreen-outside-compass-components': 'error',
Expand Down
1 change: 1 addition & 0 deletions configs/eslint-config-compass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@typescript-eslint/parser": "^8.34.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-chai-friendly": "^1.1.0",
"eslint-plugin-filename-rules": "^1.2.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-mocha": "^8.0.0",
Expand Down
63 changes: 42 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function DropdownMenuButton<Action extends string>({
data-testid={dataTestId ? `${dataTestId}-show-actions` : undefined}
onClick={(evt) => {
evt.stopPropagation();
onClick && onClick(evt);
onClick?.(evt);
}}
rightGlyph={<Icon glyph={'CaretDown'} />}
title={buttonText}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function ItemActionMenu<Action extends string>({
}
onClick={(evt) => {
evt.stopPropagation();
onClick && onClick(evt);
onClick?.(evt);
}}
className={iconClassName}
style={iconStyle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ export const HadronElement: React.FunctionComponent<{
} = useHadronElement(element);

const toggleExpanded = () => {
expanded ? collapse() : expand();
if (expanded) {
collapse();
} else {
expand();
}
};

const lineNumberMinWidth = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ const ExplainTree: React.FunctionComponent<ExplainTreeProps> = ({
<ExplainTreeStage
detailsOpen={detailsOpen === key}
onToggleDetailsClick={() => {
detailsOpen === key
? setDetailsOpen(null)
: setDetailsOpen(key);
setDetailsOpen(detailsOpen === key ? null : key);
}}
{...node}
totalExecTimeMS={root.curStageExecTimeMS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,11 @@ function GenerativeAIInput({
}
handleSubmit(aiPromptText);
} else if (evt.key === 'Escape') {
isFetching ? onCancelRequest() : onClose();
if (isFetching) {
onCancelRequest();
} else {
onClose();
}
}
},
[aiPromptText, onClose, handleSubmit, isFetching, onCancelRequest]
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-global-writes/src/store/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe('GlobalWritesStore Store', function () {

afterEach(() => {
sinon.restore();
clock && clock.restore();
clock?.restore();
});

it('sets the initial state', function () {
Expand Down
9 changes: 5 additions & 4 deletions packages/compass-import-export/src/modules/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,11 @@ export const runExport = ({
projection: createProjectionFromSchemaFields(
Object.values(fieldsToExport)
.filter((field) => {
field.selected
? fieldsIncludedCount++
: fieldsExcludedCount++;

if (field.selected) {
fieldsIncludedCount++;
} else {
fieldsExcludedCount++;
}
return field.selected;
})
.map((field) => field.path)
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-user-data/src/semaphore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Semaphore {
this.currentCount--;
if (this.queue.length > 0) {
const next = this.queue.shift();
next && next();
next?.();
}
}
}
4 changes: 3 additions & 1 deletion packages/compass-utils/src/cancellable-promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export async function raceWithAbort<T>(
try {
return await Promise.race([pendingPromise, promise]);
} finally {
abortListener && signal.removeEventListener('abort', abortListener);
if (abortListener) {
signal.removeEventListener('abort', abortListener);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/compass-web/src/entrypoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ const CompassWeb = ({

const telemetryOptions = useRef<TelemetryServiceOptions>({
sendTrack: (event: string, properties: Record<string, any> | undefined) => {
onTrackRef.current && void onTrackRef.current(event, properties || {});
void onTrackRef.current?.(event, properties || {});
},
logger,
preferences: preferencesAccess.current,
Expand Down
43 changes: 23 additions & 20 deletions packages/compass/src/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,29 @@ function quitItem(
label: label,
accelerator: 'CmdOrCtrl+Q',
click() {
!compassApp.preferences.getPreferences().enableShowDialogOnQuit
? electronApp.quit()
: void dialog
.showMessageBox({
type: 'warning',
title: `Quit ${electronApp.getName()}`,
icon: COMPASS_ICON,
message: 'Are you sure you want to quit?',
buttons: ['Quit', 'Cancel'],
checkboxLabel: 'Do not ask me again',
})
.then((result) => {
if (result.response === 0) {
if (result.checkboxChecked)
void compassApp.preferences.savePreferences({
enableShowDialogOnQuit: false,
});
electronApp.quit();
}
});
if (!compassApp.preferences.getPreferences().enableShowDialogOnQuit) {
electronApp.quit();
return;
}

void dialog
.showMessageBox({
type: 'warning',
title: `Quit ${electronApp.getName()}`,
icon: COMPASS_ICON,
message: 'Are you sure you want to quit?',
buttons: ['Quit', 'Cancel'],
checkboxLabel: 'Do not ask me again',
})
.then((result) => {
if (result.response === 0) {
if (result.checkboxChecked)
void compassApp.preferences.savePreferences({
enableShowDialogOnQuit: false,
});
electronApp.quit();
}
});
},
};
}
Expand Down
Loading