Skip to content

Commit 4e5b7fa

Browse files
authored
chore(eslint-config): update typescript-eslint to latest (#7010)
1 parent b8c76b1 commit 4e5b7fa

File tree

13 files changed

+394
-250
lines changed

13 files changed

+394
-250
lines changed

.github/workflows/update-eslint.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ jobs:
3838
3939
- name: Bump eslint
4040
run: |
41-
npm i --save eslint@8 -w @mongodb-js/eslint-config-compass
41+
npm i --save --workspace @mongodb-js/eslint-config-compass \
42+
eslint@8 \
43+
@typescript-eslint/eslint-plugin@latest \
44+
@typescript-eslint/parser@latest
4245
4346
- name: Create Pull Request
4447
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5

configs/eslint-config-compass/index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ const extraTsRules = {
1515
'error',
1616
{ fixMixedExportsWithInlineTypeSpecifier: false },
1717
],
18+
'@typescript-eslint/prefer-promise-reject-errors': 'off',
19+
'@typescript-eslint/only-throw-error': 'off',
20+
21+
// TODO: a lot new hits with latest typescript-eslint, we should gradually
22+
// clean those out and re-enable the rules
23+
'@typescript-eslint/no-explicit-any': 'warn',
24+
'@typescript-eslint/no-base-to-string': 'warn',
25+
'@typescript-eslint/no-require-imports': 'warn',
26+
'@typescript-eslint/no-unused-vars': [
27+
'error',
28+
{
29+
caughtErrors: 'none', // should be `'all'`
30+
},
31+
],
32+
'@typescript-eslint/no-unused-expressions': 'off', // replace with eslint-plugin-chai-friendly
33+
'@typescript-eslint/no-redundant-type-constituents': 'warn',
34+
'@typescript-eslint/unbound-method': 'warn',
35+
'@typescript-eslint/no-duplicate-type-constituents': 'warn',
36+
'@typescript-eslint/no-unsafe-declaration-merging': 'warn',
37+
'@typescript-eslint/no-floating-promises': 'warn',
38+
'@typescript-eslint/no-unsafe-enum-comparison': 'warn',
39+
'@typescript-eslint/no-misused-promises': 'warn',
40+
'@typescript-eslint/no-duplicate-enum-values': 'warn',
1841
};
1942

2043
const tsRules = {
@@ -50,7 +73,7 @@ const commonTestOverrides = {
5073
{
5174
patterns: [
5275
{
53-
group: '@testing-library/*',
76+
group: ['@testing-library/*'],
5477
message: 'Use @mongodb-js/testing-library-compass instead',
5578
allowTypeImports: false,
5679
},

configs/eslint-config-compass/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"@babel/eslint-parser": "^7.14.3",
1919
"@mongodb-js/eslint-config-devtools": "^0.9.9",
2020
"@mongodb-js/eslint-plugin-compass": "^1.2.9",
21-
"@typescript-eslint/eslint-plugin": "^5.59.0",
22-
"@typescript-eslint/parser": "^5.59.0",
21+
"@typescript-eslint/eslint-plugin": "^8.34.0",
22+
"@typescript-eslint/parser": "^8.34.0",
2323
"eslint": "^8.57.1",
2424
"eslint-config-prettier": "^8.3.0",
2525
"eslint-plugin-filename-rules": "^1.2.0",

configs/eslint-config-compass/plugin.js

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,51 @@ function restrictedProviderImport(servicePkg) {
1010
};
1111
}
1212

13+
// node built-ins with meaningful polyfills in web environment
14+
const allowedNodeJSBuiltinModules = ['assert', 'stream', 'events'];
15+
1316
module.exports = {
1417
...baseConfig,
1518
rules: {
1619
...baseConfig.rules,
1720
'no-restricted-imports': 'off',
1821
'@typescript-eslint/no-restricted-imports': [
1922
'error',
20-
restrictedProviderImport('@mongodb-js/compass-logging'),
21-
restrictedProviderImport('@mongodb-js/compass-telemetry'),
22-
restrictedProviderImport('@mongodb-js/compass-app-stores'),
23-
restrictedProviderImport('@mongodb-js/my-queries-storage'),
24-
restrictedProviderImport('@mongodb-js/atlas-service'),
25-
restrictedProviderImport('compass-preferences-model'),
26-
{
27-
paths: require('module').builtinModules,
28-
message: 'Using Node.js built-in modules in plugins is not allowed.',
29-
allowTypeImports: false,
30-
},
3123
{
32-
paths: ['electron', '@electron/remote'],
33-
message: 'Using electron modules in plugins is not allowed.',
34-
allowTypeImports: false,
24+
paths: [
25+
restrictedProviderImport('@mongodb-js/compass-logging'),
26+
restrictedProviderImport('@mongodb-js/compass-telemetry'),
27+
restrictedProviderImport('@mongodb-js/compass-app-stores'),
28+
restrictedProviderImport('@mongodb-js/my-queries-storage'),
29+
restrictedProviderImport('@mongodb-js/atlas-service'),
30+
restrictedProviderImport('compass-preferences-model'),
31+
...require('module')
32+
.builtinModules.filter((module) => {
33+
return (
34+
!module.startsWith('_') &&
35+
!allowedNodeJSBuiltinModules.includes(module)
36+
);
37+
})
38+
.flatMap((name) => {
39+
const config = {
40+
message:
41+
'Using Node.js built-in modules in plugins is not allowed.',
42+
allowTypeImports: true,
43+
};
44+
45+
return [
46+
{ name, ...config },
47+
{ name: `node:${name}`, ...config },
48+
];
49+
}),
50+
...['electron', '@electron/remote'].map((name) => {
51+
return {
52+
name,
53+
message: 'Using electron modules in plugins is not allowed.',
54+
allowTypeImports: false,
55+
};
56+
}),
57+
],
3558
},
3659
],
3760
},

0 commit comments

Comments
 (0)