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)

0 commit comments

Comments
 (0)