Skip to content

chore(eslint-config): update eslint to 8 #6833

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 7 additions & 1 deletion configs/eslint-config-compass/bin/eslint.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/usr/bin/env node
'use strict';
require('eslint/bin/eslint.js');
const path = require('path');
const eslintPkgJson = require('eslint/package.json');
const eslintBinPath = path.resolve(
path.dirname(require.resolve('eslint/package.json')),
eslintPkgJson.bin.eslint
);
require(eslintBinPath);
20 changes: 19 additions & 1 deletion configs/eslint-config-compass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ const extraTsRules = {
'error',
{ fixMixedExportsWithInlineTypeSpecifier: false },
],

// TODO: turn those back on
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-duplicate-type-constituents': 'off',
'@typescript-eslint/only-throw-error': 'off',
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
'@typescript-eslint/no-misused-promises': 'off',
};

const tsRules = {
Expand Down Expand Up @@ -50,13 +62,19 @@ const commonTestOverrides = {
{
patterns: [
{
group: '@testing-library/*',
group: ['@testing-library/*'],
message: 'Use @mongodb-js/testing-library-compass instead',
allowTypeImports: false,
},
],
},
],
// Due do chai triggering these rules erroneously in a lot of cases
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'off',

// TODO: turn these back on
'mocha/consistent-spacing-between-blocks': 'off',
};

const testJsOverrides = {
Expand Down
13 changes: 6 additions & 7 deletions configs/eslint-config-compass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
],
"dependencies": {
"@babel/core": "^7.21.4",
"@babel/eslint-parser": "^7.14.3",
"@mongodb-js/eslint-config-devtools": "^0.9.9",
"@babel/eslint-parser": "^7.27.0",
"@mongodb-js/eslint-config-devtools": "^0.9.10",
"@mongodb-js/eslint-plugin-compass": "^1.2.6",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^8.28.0",
"@typescript-eslint/parser": "^8.28.0",
"eslint": "^8.57.1",
"eslint-plugin-filename-rules": "^1.2.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0"
},
Expand Down
51 changes: 37 additions & 14 deletions configs/eslint-config-compass/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,51 @@ function restrictedProviderImport(servicePkg) {
};
}

// node built-ins with meaningful polyfills in web environment
const allowedNodeJSBuiltinModules = ['stream', 'events', 'crypto'];

module.exports = {
...baseConfig,
rules: {
...baseConfig.rules,
'no-restricted-imports': 'off',
'@typescript-eslint/no-restricted-imports': [
'error',
restrictedProviderImport('@mongodb-js/compass-logging'),
restrictedProviderImport('@mongodb-js/compass-telemetry'),
restrictedProviderImport('@mongodb-js/compass-app-stores'),
restrictedProviderImport('@mongodb-js/my-queries-storage'),
restrictedProviderImport('@mongodb-js/atlas-service'),
restrictedProviderImport('compass-preferences-model'),
{
paths: require('module').builtinModules,
message: 'Using Node.js built-in modules in plugins is not allowed.',
allowTypeImports: false,
},
{
paths: ['electron', '@electron/remote'],
message: 'Using electron modules in plugins is not allowed.',
allowTypeImports: false,
paths: [
restrictedProviderImport('@mongodb-js/compass-logging'),
restrictedProviderImport('@mongodb-js/compass-telemetry'),
restrictedProviderImport('@mongodb-js/compass-app-stores'),
restrictedProviderImport('@mongodb-js/my-queries-storage'),
restrictedProviderImport('@mongodb-js/atlas-service'),
restrictedProviderImport('compass-preferences-model'),
...require('module')
.builtinModules.filter((module) => {
return (
!module.startsWith('_') &&
!allowedNodeJSBuiltinModules.includes(module)
);
})
.flatMap((name) => {
const config = {
message:
'Using Node.js built-in modules in plugins is not allowed.',
allowTypeImports: true,
};

return [
{ name, ...config },
{ name: `node:${name}`, ...config },
];
}),
...['electron', '@electron/remote'].map((name) => {
return {
name,
message: 'Using electron modules in plugins is not allowed.',
allowTypeImports: false,
};
}),
],
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion configs/eslint-plugin-compass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@mongodb-js/mocha-config-compass": "^1.6.6",
"@mongodb-js/prettier-config-compass": "^1.2.6",
"depcheck": "^1.4.1",
"eslint": "^7.25.0",
"eslint": "^8.57.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion configs/webpack-config-compass/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export function createElectronRendererConfig(
export function createWebConfig(args: Partial<ConfigArgs>): WebpackConfig {
const opts = webpackArgsWithDefaults(args, { target: 'web' });

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { peerDependencies } = require(path.join(opts.cwd, 'package.json')) as {
peerDependencies: Record<string, string>;
};
Expand Down
4 changes: 2 additions & 2 deletions configs/webpack-config-compass/src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isServe } from './args';
import chalk from 'chalk';

function isLatestBrowserslist() {
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const browserslistVersion = require('browserslist/package.json').version;
const command = `npm view browserslist version --json`;
const latestBrowserslistVersion = JSON.parse(
Expand All @@ -18,7 +18,7 @@ function isLatestBrowserslist() {
}

const electronVersion = (() => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const [maj, min] = require('electron/package.json').version.split(
'.'
) as string[];
Expand Down
4 changes: 2 additions & 2 deletions configs/webpack-config-compass/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function entriesToHtml(
fs.statSync(maybeTemplatePath);
template = maybeTemplatePath;
break;
} catch (e) {
} catch {
// ignore and use default template, electron renderer entry will need
// at least some kind of html page provided one way or the other
}
Expand All @@ -62,7 +62,7 @@ export function camelCase(str: string): string {
}

export function getLibraryNameFromCwd(cwd: string): string {
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { name, productName } = require(path.join(cwd, 'package.json')) as {
name: string;
productName: string;
Expand Down
Loading