Skip to content

Commit 1678158

Browse files
authored
chore(eslint-config): replace no-unused-expressions with chai-friendly version COMPASS-9459 (#7018)
chore(eslint-config): replace no-unused-expressions with chai-friendly version
1 parent 73a4f0d commit 1678158

File tree

14 files changed

+94
-58
lines changed

14 files changed

+94
-58
lines changed

configs/eslint-config-compass/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const path = require('path');
44
const shared = require('@mongodb-js/eslint-config-devtools');
55
const common = require('@mongodb-js/eslint-config-devtools/common');
6+
const chaiFriendly = require('eslint-plugin-chai-friendly');
67

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

@@ -28,7 +31,6 @@ const extraTsRules = {
2831
caughtErrors: 'none', // should be `'all'`
2932
},
3033
],
31-
'@typescript-eslint/no-unused-expressions': 'off', // replace with eslint-plugin-chai-friendly
3234
'@typescript-eslint/no-redundant-type-constituents': 'warn',
3335
'@typescript-eslint/unbound-method': 'warn',
3436
'@typescript-eslint/no-duplicate-type-constituents': 'warn',
@@ -105,7 +107,7 @@ const testTsOverrides = {
105107
};
106108

107109
module.exports = {
108-
plugins: [...shared.plugins, '@mongodb-js/compass'],
110+
plugins: [...shared.plugins, '@mongodb-js/compass', 'chai-friendly'],
109111
rules: {
110112
...shared.rules,
111113
'@mongodb-js/compass/no-leafygreen-outside-compass-components': 'error',

configs/eslint-config-compass/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@typescript-eslint/parser": "^8.34.0",
2323
"eslint": "^8.57.1",
2424
"eslint-config-prettier": "^8.3.0",
25+
"eslint-plugin-chai-friendly": "^1.1.0",
2526
"eslint-plugin-filename-rules": "^1.2.0",
2627
"eslint-plugin-jsx-a11y": "^6.10.2",
2728
"eslint-plugin-mocha": "^8.0.0",

package-lock.json

Lines changed: 42 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-components/src/components/actions/dropdown-menu-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export function DropdownMenuButton<Action extends string>({
9090
data-testid={dataTestId ? `${dataTestId}-show-actions` : undefined}
9191
onClick={(evt) => {
9292
evt.stopPropagation();
93-
onClick && onClick(evt);
93+
onClick?.(evt);
9494
}}
9595
rightGlyph={<Icon glyph={'CaretDown'} />}
9696
title={buttonText}

packages/compass-components/src/components/actions/item-action-menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function ItemActionMenu<Action extends string>({
124124
}
125125
onClick={(evt) => {
126126
evt.stopPropagation();
127-
onClick && onClick(evt);
127+
onClick?.(evt);
128128
}}
129129
className={iconClassName}
130130
style={iconStyle}

packages/compass-components/src/components/document-list/element.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,11 @@ export const HadronElement: React.FunctionComponent<{
448448
} = useHadronElement(element);
449449

450450
const toggleExpanded = () => {
451-
expanded ? collapse() : expand();
451+
if (expanded) {
452+
collapse();
453+
} else {
454+
expand();
455+
}
452456
};
453457

454458
const lineNumberMinWidth = useMemo(() => {

packages/compass-explain-plan/src/components/explain-tree/explain-tree.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ const ExplainTree: React.FunctionComponent<ExplainTreeProps> = ({
112112
<ExplainTreeStage
113113
detailsOpen={detailsOpen === key}
114114
onToggleDetailsClick={() => {
115-
detailsOpen === key
116-
? setDetailsOpen(null)
117-
: setDetailsOpen(key);
115+
setDetailsOpen(detailsOpen === key ? null : key);
118116
}}
119117
{...node}
120118
totalExecTimeMS={root.curStageExecTimeMS}

packages/compass-generative-ai/src/components/generative-ai-input.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,11 @@ function GenerativeAIInput({
366366
}
367367
handleSubmit(aiPromptText);
368368
} else if (evt.key === 'Escape') {
369-
isFetching ? onCancelRequest() : onClose();
369+
if (isFetching) {
370+
onCancelRequest();
371+
} else {
372+
onClose();
373+
}
370374
}
371375
},
372376
[aiPromptText, onClose, handleSubmit, isFetching, onCancelRequest]

packages/compass-global-writes/src/store/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ describe('GlobalWritesStore Store', function () {
225225

226226
afterEach(() => {
227227
sinon.restore();
228-
clock && clock.restore();
228+
clock?.restore();
229229
});
230230

231231
it('sets the initial state', function () {

packages/compass-import-export/src/modules/export.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,11 @@ export const runExport = ({
411411
projection: createProjectionFromSchemaFields(
412412
Object.values(fieldsToExport)
413413
.filter((field) => {
414-
field.selected
415-
? fieldsIncludedCount++
416-
: fieldsExcludedCount++;
417-
414+
if (field.selected) {
415+
fieldsIncludedCount++;
416+
} else {
417+
fieldsExcludedCount++;
418+
}
418419
return field.selected;
419420
})
420421
.map((field) => field.path)

packages/compass-user-data/src/semaphore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class Semaphore {
2121
this.currentCount--;
2222
if (this.queue.length > 0) {
2323
const next = this.queue.shift();
24-
next && next();
24+
next?.();
2525
}
2626
}
2727
}

packages/compass-utils/src/cancellable-promise.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export async function raceWithAbort<T>(
5353
try {
5454
return await Promise.race([pendingPromise, promise]);
5555
} finally {
56-
abortListener && signal.removeEventListener('abort', abortListener);
56+
if (abortListener) {
57+
signal.removeEventListener('abort', abortListener);
58+
}
5759
}
5860
}
5961

packages/compass-web/src/entrypoint.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ const CompassWeb = ({
288288

289289
const telemetryOptions = useRef<TelemetryServiceOptions>({
290290
sendTrack: (event: string, properties: Record<string, any> | undefined) => {
291-
onTrackRef.current && void onTrackRef.current(event, properties || {});
291+
void onTrackRef.current?.(event, properties || {});
292292
},
293293
logger,
294294
preferences: preferencesAccess.current,

packages/compass/src/main/menu.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,29 @@ function quitItem(
3939
label: label,
4040
accelerator: 'CmdOrCtrl+Q',
4141
click() {
42-
!compassApp.preferences.getPreferences().enableShowDialogOnQuit
43-
? electronApp.quit()
44-
: void dialog
45-
.showMessageBox({
46-
type: 'warning',
47-
title: `Quit ${electronApp.getName()}`,
48-
icon: COMPASS_ICON,
49-
message: 'Are you sure you want to quit?',
50-
buttons: ['Quit', 'Cancel'],
51-
checkboxLabel: 'Do not ask me again',
52-
})
53-
.then((result) => {
54-
if (result.response === 0) {
55-
if (result.checkboxChecked)
56-
void compassApp.preferences.savePreferences({
57-
enableShowDialogOnQuit: false,
58-
});
59-
electronApp.quit();
60-
}
61-
});
42+
if (!compassApp.preferences.getPreferences().enableShowDialogOnQuit) {
43+
electronApp.quit();
44+
return;
45+
}
46+
47+
void dialog
48+
.showMessageBox({
49+
type: 'warning',
50+
title: `Quit ${electronApp.getName()}`,
51+
icon: COMPASS_ICON,
52+
message: 'Are you sure you want to quit?',
53+
buttons: ['Quit', 'Cancel'],
54+
checkboxLabel: 'Do not ask me again',
55+
})
56+
.then((result) => {
57+
if (result.response === 0) {
58+
if (result.checkboxChecked)
59+
void compassApp.preferences.savePreferences({
60+
enableShowDialogOnQuit: false,
61+
});
62+
electronApp.quit();
63+
}
64+
});
6265
},
6366
};
6467
}

0 commit comments

Comments
 (0)