From 218db3cb0626667fec85d8f8724fab7aa5d98f04 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Tue, 29 Aug 2023 15:46:22 +0100 Subject: [PATCH 01/14] bring back no-undef --- configs/eslint-config-mongosh/index.js | 1 - packages/cli-repl/test/fixtures/load/hello1.js | 1 + packages/cli-repl/test/fixtures/load/hello2.js | 1 + packages/cli-repl/test/fixtures/load/insertintotest.js | 1 + packages/cli-repl/test/fixtures/load/printisinteractive.js | 1 + packages/e2e-tests/test/fixtures/exampleplayground.js | 1 + packages/e2e-tests/test/fixtures/load/long-sleep.js | 1 + 7 files changed, 6 insertions(+), 1 deletion(-) diff --git a/configs/eslint-config-mongosh/index.js b/configs/eslint-config-mongosh/index.js index b0f6e0a54a..7b48caffe7 100644 --- a/configs/eslint-config-mongosh/index.js +++ b/configs/eslint-config-mongosh/index.js @@ -19,7 +19,6 @@ const tempRules = { 'filename-rules/match': 1, 'no-useless-escape': 1, - 'no-undef': 1, 'no-prototype-builtins': 1, 'no-async-promise-executor': 1, 'no-case-declarations': 1, diff --git a/packages/cli-repl/test/fixtures/load/hello1.js b/packages/cli-repl/test/fixtures/load/hello1.js index 78f0eacd0d..d347e3549c 100644 --- a/packages/cli-repl/test/fixtures/load/hello1.js +++ b/packages/cli-repl/test/fixtures/load/hello1.js @@ -1 +1,2 @@ +/* eslint-disable no-undef */ print('hello one'); diff --git a/packages/cli-repl/test/fixtures/load/hello2.js b/packages/cli-repl/test/fixtures/load/hello2.js index 9798355f30..b2be3b6594 100644 --- a/packages/cli-repl/test/fixtures/load/hello2.js +++ b/packages/cli-repl/test/fixtures/load/hello2.js @@ -1 +1,2 @@ +/* eslint-disable no-undef */ print('hello two'); diff --git a/packages/cli-repl/test/fixtures/load/insertintotest.js b/packages/cli-repl/test/fixtures/load/insertintotest.js index bd5b6c1fdb..4ce8d98834 100644 --- a/packages/cli-repl/test/fixtures/load/insertintotest.js +++ b/packages/cli-repl/test/fixtures/load/insertintotest.js @@ -1,2 +1,3 @@ +/* eslint-disable no-undef */ insertTestCollection = db.getSiblingDB('test').getCollection('insertTest' + ((Math.random() * 100000) | 0)); print('Inserted:', insertTestCollection.insertOne({}).insertedId) diff --git a/packages/cli-repl/test/fixtures/load/printisinteractive.js b/packages/cli-repl/test/fixtures/load/printisinteractive.js index de855f19d1..259a9cd87e 100644 --- a/packages/cli-repl/test/fixtures/load/printisinteractive.js +++ b/packages/cli-repl/test/fixtures/load/printisinteractive.js @@ -1 +1,2 @@ +/* eslint-disable no-undef */ print(`isInteractive=${isInteractive()}`) diff --git a/packages/e2e-tests/test/fixtures/exampleplayground.js b/packages/e2e-tests/test/fixtures/exampleplayground.js index bc2ca335c5..6bcb8aa7b0 100644 --- a/packages/e2e-tests/test/fixtures/exampleplayground.js +++ b/packages/e2e-tests/test/fixtures/exampleplayground.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ // MongoDB Playground // To disable this template go to Settings | MongoDB | Use Default Template For Playground. // Make sure you are connected to enable completions and to be able to run a playground. diff --git a/packages/e2e-tests/test/fixtures/load/long-sleep.js b/packages/e2e-tests/test/fixtures/load/long-sleep.js index d0a830c4bf..d3e6f576ee 100644 --- a/packages/e2e-tests/test/fixtures/load/long-sleep.js +++ b/packages/e2e-tests/test/fixtures/load/long-sleep.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ console.log('Long sleep'); (async() => { await sleep(1_000_000); From 674178d7644c018b7734329b55bf1f8896d6a085 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Tue, 29 Aug 2023 16:17:38 +0100 Subject: [PATCH 02/14] remove rule that only required one override --- configs/eslint-config-mongosh/index.js | 1 - .../node-runtime-worker-thread/src/spawn-child-from-source.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/eslint-config-mongosh/index.js b/configs/eslint-config-mongosh/index.js index 7b48caffe7..0651078385 100644 --- a/configs/eslint-config-mongosh/index.js +++ b/configs/eslint-config-mongosh/index.js @@ -20,7 +20,6 @@ const tempRules = { 'no-useless-escape': 1, 'no-prototype-builtins': 1, - 'no-async-promise-executor': 1, 'no-case-declarations': 1, }; diff --git a/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts b/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts index 6edbb9ba95..35f00b43a8 100644 --- a/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts +++ b/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts @@ -25,6 +25,7 @@ export default function spawnChildFromSource( _stdout: StdioNull | StdioPipe = 'inherit', _stderr: StdioNull | StdioPipe = 'inherit' ): Promise { + // eslint-disable-next-line no-async-promise-executor return new Promise(async (resolve, reject) => { const readyToken = Date.now().toString(32); From 1b2a433fa21afa7feb3150ac8d79b5f21bf5e1f1 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Tue, 29 Aug 2023 16:29:20 +0100 Subject: [PATCH 03/14] bring back no-useless-escape --- configs/eslint-config-mongosh/index.js | 1 - packages/build/src/homebrew/generate-formula.spec.ts | 8 ++++---- packages/build/src/homebrew/generate-formula.ts | 8 ++++---- packages/e2e-tests/test/e2e.spec.ts | 6 +++--- packages/e2e-tests/test/repl-helpers.ts | 1 + packages/editor/src/editor.ts | 4 ++-- .../node-runtime-worker-thread/src/worker-runtime.spec.ts | 4 ++-- packages/node-runtime-worker-thread/src/worker-runtime.ts | 2 +- packages/shell-api/src/helpers.ts | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/configs/eslint-config-mongosh/index.js b/configs/eslint-config-mongosh/index.js index 0651078385..15b93ee387 100644 --- a/configs/eslint-config-mongosh/index.js +++ b/configs/eslint-config-mongosh/index.js @@ -18,7 +18,6 @@ const tempRules = { 'filename-rules/match': 1, - 'no-useless-escape': 1, 'no-prototype-builtins': 1, 'no-case-declarations': 1, }; diff --git a/packages/build/src/homebrew/generate-formula.spec.ts b/packages/build/src/homebrew/generate-formula.spec.ts index 9f87038918..5005791ac4 100644 --- a/packages/build/src/homebrew/generate-formula.spec.ts +++ b/packages/build/src/homebrew/generate-formula.spec.ts @@ -29,8 +29,8 @@ class Mongosh < Formula end test do - assert_match "ECONNREFUSED 0.0.0.0:1", shell_output("#{bin}/mongosh \"mongodb://0.0.0.0:1\" 2>&1", 1) - assert_match "#ok#", shell_output("#{bin}/mongosh --nodb --eval \"print('#ok#')\"") + assert_match "ECONNREFUSED 0.0.0.0:1", shell_output("#{bin}/mongosh \\"mongodb://0.0.0.0:1\\" 2>&1", 1) + assert_match "#ok#", shell_output("#{bin}/mongosh --nodb --eval \\"print('#ok#')\\"") end end`; @@ -75,8 +75,8 @@ class Mongosh < Formula end test do - assert_match "ECONNREFUSED 0.0.0.0:1", shell_output("#{bin}/mongosh \"mongodb://0.0.0.0:1\" 2>&1", 1) - assert_match "#ok#", shell_output("#{bin}/mongosh --nodb --eval \"print('#ok#')\"") + assert_match "ECONNREFUSED 0.0.0.0:1", shell_output("#{bin}/mongosh \\"mongodb://0.0.0.0:1\\" 2>&1", 1) + assert_match "#ok#", shell_output("#{bin}/mongosh --nodb --eval \\"print('#ok#')\\"") end end`; expect( diff --git a/packages/build/src/homebrew/generate-formula.ts b/packages/build/src/homebrew/generate-formula.ts index 5c03f28a64..7671dd116c 100644 --- a/packages/build/src/homebrew/generate-formula.ts +++ b/packages/build/src/homebrew/generate-formula.ts @@ -11,8 +11,8 @@ export async function generateUpdatedFormula( 'master' ); - const urlMatch = /url \"([^"]+)\"/g.exec(currentFormula.content); - const shaMatch = /sha256 \"([^"]+)\"/g.exec(currentFormula.content); + const urlMatch = /url "([^"]+)"/g.exec(currentFormula.content); + const shaMatch = /sha256 "([^"]+)"/g.exec(currentFormula.content); if (!urlMatch || !shaMatch) { throw new Error( @@ -45,9 +45,9 @@ export async function generateUpdatedFormula( } let newFormula = currentFormula.content; - newFormula = newFormula.replace(/url \"([^"]+)\"/g, `url "${newUrl}"`); + newFormula = newFormula.replace(/url "([^"]+)"/g, `url "${newUrl}"`); newFormula = newFormula.replace( - /sha256 \"([^"]+)\"/g, + /sha256 "([^"]+)"/g, `sha256 "${context.sha}"` ); return newFormula; diff --git a/packages/e2e-tests/test/e2e.spec.ts b/packages/e2e-tests/test/e2e.spec.ts index 7bcaead83f..4043e37cfe 100644 --- a/packages/e2e-tests/test/e2e.spec.ts +++ b/packages/e2e-tests/test/e2e.spec.ts @@ -455,7 +455,7 @@ describe('e2e', function () { } });`); - expect(result).to.match(/Violations\:/); + expect(result).to.match(/Violations:/); // Two duplicated ids expect(result).to.match(/ids: \[\s+ObjectId.+?\s+?ObjectId.+?\s+\]/m); }); @@ -700,7 +700,7 @@ describe('e2e', function () { validator: { $and: [ { phone: { $type: "string" } }, - { email: { $regex: /@mongodb\.com$/ } }, + { email: { $regex: /@mongodb.com$/ } }, { status: { $in: [ "Unknown", "Incomplete" ] } } ] } @@ -717,7 +717,7 @@ describe('e2e', function () { validator: { $and: [ { phone: { $type: "string" } }, - { email: { $regex: /@mongodb\.com$/ } }, + { email: { $regex: /@mongodb.com$/ } }, { status: { $in: [ "Unknown", "Incomplete" ] } } ] } diff --git a/packages/e2e-tests/test/repl-helpers.ts b/packages/e2e-tests/test/repl-helpers.ts index f64d03300f..72d3305a66 100644 --- a/packages/e2e-tests/test/repl-helpers.ts +++ b/packages/e2e-tests/test/repl-helpers.ts @@ -89,6 +89,7 @@ const fakeExternalEditor = async ({ if (${JSON.stringify(flags ?? '')}) { assert.deepStrictEqual((${JSON.stringify( flags + // eslint-disable-next-line no-useless-escape )}).split(/\s+/), process.argv.slice(2, -1)); } diff --git a/packages/editor/src/editor.ts b/packages/editor/src/editor.ts index 796fa6b949..8c08159363 100644 --- a/packages/editor/src/editor.ts +++ b/packages/editor/src/editor.ts @@ -146,7 +146,7 @@ export class Editor { } _isVscodeApp(cmd: string): boolean { - const regex = /^(.*)[\/\\]?[cC]ode(.exe)?(\s(.*))?$/; + const regex = /^(.*)[/\\]?[cC]ode(.exe)?(\s(.*))?$/; return regex.test(cmd); } @@ -155,7 +155,7 @@ export class Editor { return false; } - const regex = /^([^!"#%&'()*+,\-/\[\]\\^`{|}~]+)$/; + const regex = /^([^!"#%&'()*+,\-/[\]\\^`{|}~]+)$/; return regex.test(code); } diff --git a/packages/node-runtime-worker-thread/src/worker-runtime.spec.ts b/packages/node-runtime-worker-thread/src/worker-runtime.spec.ts index 4974b26439..6a16c84fbc 100644 --- a/packages/node-runtime-worker-thread/src/worker-runtime.spec.ts +++ b/packages/node-runtime-worker-thread/src/worker-runtime.spec.ts @@ -91,7 +91,7 @@ describe('worker', function () { expect(err).to.be.instanceof(Error); expect(err) .to.have.property('message') - .match(/Can\'t call evaluate before shell runtime is initiated/); + .match(/Can't call evaluate before shell runtime is initiated/); }); describe('evaluate', function () { @@ -455,7 +455,7 @@ describe('worker', function () { expect(err) .to.have.property('message') .match( - /Can\'t run another evaluation while the previous is not finished/ + /Can't run another evaluation while the previous is not finished/ ); }); }); diff --git a/packages/node-runtime-worker-thread/src/worker-runtime.ts b/packages/node-runtime-worker-thread/src/worker-runtime.ts index 107a478535..9e12acfcb1 100644 --- a/packages/node-runtime-worker-thread/src/worker-runtime.ts +++ b/packages/node-runtime-worker-thread/src/worker-runtime.ts @@ -38,7 +38,7 @@ const evaluationLock = new Lock(); function ensureRuntime(methodName: string): Runtime { if (!runtime) { throw new Error( - `Can\'t call ${methodName} before shell runtime is initiated` + `Can't call ${methodName} before shell runtime is initiated` ); } diff --git a/packages/shell-api/src/helpers.ts b/packages/shell-api/src/helpers.ts index 160fe65830..cc555c861b 100644 --- a/packages/shell-api/src/helpers.ts +++ b/packages/shell-api/src/helpers.ts @@ -485,7 +485,7 @@ export async function getPrintableShardStatus( result.databases = await Promise.all( databases.map(async (db) => { const escapeRegex = (string: string): string => { - return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); }; const colls = await ( await configDB From 313ee94deb3d21df26f8bb3ead3bd7f082f65211 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 30 Aug 2023 09:14:44 +0100 Subject: [PATCH 04/14] add comment --- configs/eslint-config-mongosh/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/eslint-config-mongosh/index.js b/configs/eslint-config-mongosh/index.js index 15b93ee387..9b36e57630 100644 --- a/configs/eslint-config-mongosh/index.js +++ b/configs/eslint-config-mongosh/index.js @@ -16,6 +16,7 @@ const tempRules = { 'mocha/no-sibling-hooks': 1, 'mocha/no-nested-tests': 1, + // this would disallow our locale files' filenames like de_DE.ts 'filename-rules/match': 1, 'no-prototype-builtins': 1, From 26bcd4e59ace16bed133407445fd50fc6379ae90 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 30 Aug 2023 09:21:29 +0100 Subject: [PATCH 05/14] re-enable no-prototype-builtins --- configs/eslint-config-mongosh/index.js | 1 - packages/i18n/src/translator.ts | 2 +- packages/shell-api/src/helpers.ts | 5 ++++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/configs/eslint-config-mongosh/index.js b/configs/eslint-config-mongosh/index.js index 9b36e57630..c22f6ebc9b 100644 --- a/configs/eslint-config-mongosh/index.js +++ b/configs/eslint-config-mongosh/index.js @@ -19,7 +19,6 @@ const tempRules = { // this would disallow our locale files' filenames like de_DE.ts 'filename-rules/match': 1, - 'no-prototype-builtins': 1, 'no-case-declarations': 1, }; diff --git a/packages/i18n/src/translator.ts b/packages/i18n/src/translator.ts index edc5fa24ae..3fa0cf9594 100644 --- a/packages/i18n/src/translator.ts +++ b/packages/i18n/src/translator.ts @@ -66,7 +66,7 @@ class Translator { * @param {string} locale - The locale. */ setLocale(locale: string): void { - if (MAPPINGS.hasOwnProperty(locale)) { + if (Object.prototype.hasOwnProperty.call(MAPPINGS, locale)) { this.locale = locale; this.catalog = MAPPINGS[locale]; } else { diff --git a/packages/shell-api/src/helpers.ts b/packages/shell-api/src/helpers.ts index cc555c861b..314b39495a 100644 --- a/packages/shell-api/src/helpers.ts +++ b/packages/shell-api/src/helpers.ts @@ -323,7 +323,10 @@ export async function getPrintableShardStatus( (async (): Promise => { // Output the balancer window const settings = await settingsColl.findOne({ _id: 'balancer' }); - if (settings !== null && settings.hasOwnProperty('activeWindow')) { + if ( + settings !== null && + Object.prototype.hasOwnProperty.call(settings, 'activeWindow') + ) { const balSettings = settings.activeWindow; balancerRes[ 'Balancer active window is set between' From 41ce32066575900eed31e0008e2f831f011b4a4f Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 30 Aug 2023 09:44:24 +0100 Subject: [PATCH 06/14] re-enable @typescript-eslint/consistent-type-imports --- configs/eslint-config-mongosh/index.js | 19 ++++++++++--------- .../build/src/download-center/config.spec.ts | 3 ++- packages/cli-repl/src/crypt-library-paths.ts | 1 + packages/e2e-tests/test/e2e-tls.spec.ts | 2 +- .../src/all-fle-types.ts | 1 + 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/configs/eslint-config-mongosh/index.js b/configs/eslint-config-mongosh/index.js index 2c0cb89dab..29eb06c1ad 100644 --- a/configs/eslint-config-mongosh/index.js +++ b/configs/eslint-config-mongosh/index.js @@ -3,8 +3,7 @@ const shared = require('@mongodb-js/eslint-config-devtools'); const common = require('@mongodb-js/eslint-config-devtools/common'); -// TODO(MONGOSH-1508) we need to turn these back into errors (and fix them) or ticket them -const tempRules = { +const extraJSRules = { 'jsx-a11y/no-autofocus': 1, 'jsx-a11y/click-events-have-key-events': 1, 'jsx-a11y/no-static-element-interactions': 1, @@ -17,18 +16,20 @@ const tempRules = { // this would disallow our locale files' filenames like de_DE.ts 'filename-rules/match': 1, + // TODO(MONGOSH-1580): re-enable this rule 'no-case-declarations': 1, }; // TODO(MONGOSH-1508) we need to turn these back into errors (and fix them) or ticket them const tempTypescriptRules = { + // this rule causes many false positives, so we leave it to just warn '@typescript-eslint/no-unnecessary-type-assertion': 1, + '@typescript-eslint/restrict-plus-operands': 1, '@typescript-eslint/no-var-requires': 1, '@typescript-eslint/restrict-template-expressions': 1, '@typescript-eslint/no-empty-function': 1, '@typescript-eslint/no-misused-promises': 1, - '@typescript-eslint/consistent-type-imports': 1, '@typescript-eslint/unbound-method': 1, '@typescript-eslint/no-implied-eval': 1, '@typescript-eslint/no-unused-vars': 1, @@ -49,21 +50,21 @@ module.exports = { ...common.jsOverrides, rules: { ...common.jsRules, - ...tempRules, + ...extraJSRules, }, }, { ...common.jsxOverrides, rules: { ...common.jsxRules, - ...tempRules, + ...extraJSRules, }, }, { ...common.tsOverrides, rules: { ...common.tsRules, - ...tempRules, + ...extraJSRules, ...tempTypescriptRules, }, }, @@ -71,7 +72,7 @@ module.exports = { ...common.tsxOverrides, rules: { ...common.tsxRules, - ...tempRules, + ...extraJSRules, ...tempTypescriptRules, }, }, @@ -79,7 +80,7 @@ module.exports = { ...common.testOverrides, rules: { ...common.testRules, - ...tempRules, + ...extraJSRules, }, }, { @@ -87,7 +88,7 @@ module.exports = { files: ['**/*.spec.ts', '**/*.spec.tsx', '**/*.test.tsx', '**/*.test.ts'], rules: { ...common.testRules, - ...tempRules, + ...extraJSRules, ...tempTypescriptRules, }, }, diff --git a/packages/build/src/download-center/config.spec.ts b/packages/build/src/download-center/config.spec.ts index 0daa70b0c8..ac039c01f5 100644 --- a/packages/build/src/download-center/config.spec.ts +++ b/packages/build/src/download-center/config.spec.ts @@ -10,7 +10,8 @@ import { createAndPublishDownloadCenterConfig, createJsonFeedEntry, } from './config'; -import { Server as HTTPServer, createServer as createHTTPServer } from 'http'; +import { createServer as createHTTPServer } from 'http'; +import type { Server as HTTPServer } from 'http'; import { once } from 'events'; import path from 'path'; import fetch from 'node-fetch'; diff --git a/packages/cli-repl/src/crypt-library-paths.ts b/packages/cli-repl/src/crypt-library-paths.ts index 565b48b4cc..e63ede71be 100644 --- a/packages/cli-repl/src/crypt-library-paths.ts +++ b/packages/cli-repl/src/crypt-library-paths.ts @@ -24,6 +24,7 @@ export async function getCryptLibraryPaths( ): Promise { const execPath = pretendProcessExecPathForTesting ?? process.execPath; + // eslint-disable-next-line @typescript-eslint/consistent-type-imports let getCryptSharedLibraryVersion: typeof import('mongodb-crypt-library-version'); try { getCryptSharedLibraryVersion = require('mongodb-crypt-library-version'); diff --git a/packages/e2e-tests/test/e2e-tls.spec.ts b/packages/e2e-tests/test/e2e-tls.spec.ts index 753076d61c..1ef41c255e 100644 --- a/packages/e2e-tests/test/e2e-tls.spec.ts +++ b/packages/e2e-tests/test/e2e-tls.spec.ts @@ -4,8 +4,8 @@ import path from 'path'; import { skipIfEnvServerVersion, startTestServer, - MongodSetup, } from '../../../testing/integration-testing-hooks'; +import type { MongodSetup } from '../../../testing/integration-testing-hooks'; import { useTmpdir, setTemporaryHomeDirectory, diff --git a/packages/service-provider-core/src/all-fle-types.ts b/packages/service-provider-core/src/all-fle-types.ts index d1ae9f1f08..8a41ca1fb5 100644 --- a/packages/service-provider-core/src/all-fle-types.ts +++ b/packages/service-provider-core/src/all-fle-types.ts @@ -14,4 +14,5 @@ export type { KMSProviders, } from 'mongodb-client-encryption'; +// eslint-disable-next-line @typescript-eslint/consistent-type-imports export type FLE = typeof import('mongodb-client-encryption'); From 382b4e274d11731d72fa824c68e2167bdbf67b8c Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 30 Aug 2023 10:03:41 +0100 Subject: [PATCH 07/14] re-enable @typescript-eslint/no-unused-vars --- configs/eslint-config-mongosh/index.js | 2 -- packages/cli-repl/src/mongosh-repl.ts | 1 + packages/logging/src/analytics-helpers.ts | 4 ++-- packages/logging/src/setup-logger-and-telemetry.ts | 1 + packages/service-provider-core/src/textencoder-polyfill.ts | 1 + packages/shell-api/src/collection.spec.ts | 2 ++ packages/shell-api/src/integration.spec.ts | 1 - packages/shell-api/src/mongo.ts | 2 ++ 8 files changed, 9 insertions(+), 5 deletions(-) diff --git a/configs/eslint-config-mongosh/index.js b/configs/eslint-config-mongosh/index.js index 29eb06c1ad..c24d206458 100644 --- a/configs/eslint-config-mongosh/index.js +++ b/configs/eslint-config-mongosh/index.js @@ -31,8 +31,6 @@ const tempTypescriptRules = { '@typescript-eslint/no-empty-function': 1, '@typescript-eslint/no-misused-promises': 1, '@typescript-eslint/unbound-method': 1, - '@typescript-eslint/no-implied-eval': 1, - '@typescript-eslint/no-unused-vars': 1, '@typescript-eslint/prefer-regexp-exec': 1, '@typescript-eslint/ban-types': 1, }; diff --git a/packages/cli-repl/src/mongosh-repl.ts b/packages/cli-repl/src/mongosh-repl.ts index 282e9f7840..939799dc2d 100644 --- a/packages/cli-repl/src/mongosh-repl.ts +++ b/packages/cli-repl/src/mongosh-repl.ts @@ -485,6 +485,7 @@ class MongoshNodeRepl implements EvaluationListener { * * @param _initializationToken A value obtained by calling {@link MongoshNodeRepl.initialize}. */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars async startRepl(_initializationToken: InitializationToken): Promise { this.started = true; const { repl } = this.runtimeState(); diff --git a/packages/logging/src/analytics-helpers.ts b/packages/logging/src/analytics-helpers.ts index 31e30a2008..13102ab82a 100644 --- a/packages/logging/src/analytics-helpers.ts +++ b/packages/logging/src/analytics-helpers.ts @@ -79,8 +79,8 @@ class Queue { * (e.g. because we are running without an API key). */ export class NoopAnalytics implements MongoshAnalytics { - identify(_info: any): void {} - track(_info: any): void {} + identify(): void {} + track(): void {} flush(cb: () => void) { cb(); } diff --git a/packages/logging/src/setup-logger-and-telemetry.ts b/packages/logging/src/setup-logger-and-telemetry.ts index 3a99373abb..2c3c8499c9 100644 --- a/packages/logging/src/setup-logger-and-telemetry.ts +++ b/packages/logging/src/setup-logger-and-telemetry.ts @@ -113,6 +113,7 @@ export function setupLoggerAndTelemetry( bus.on('mongosh:connect', function (args: ConnectEvent) { const connectionUri = redactURICredentials(args.uri); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { uri: _uri, ...argsWithoutUri } = args; const params = { session_id: logId, diff --git a/packages/service-provider-core/src/textencoder-polyfill.ts b/packages/service-provider-core/src/textencoder-polyfill.ts index 34616d91fa..ac80254f5f 100644 --- a/packages/service-provider-core/src/textencoder-polyfill.ts +++ b/packages/service-provider-core/src/textencoder-polyfill.ts @@ -10,6 +10,7 @@ if ( // @ts-ignore typeof TextEncoder !== 'function' ) { + // eslint-disable-next-line @typescript-eslint/no-implied-eval Object.assign(Function('return this')(), textEncodingPolyfill()); } diff --git a/packages/shell-api/src/collection.spec.ts b/packages/shell-api/src/collection.spec.ts index 5afcbc45d3..810d19e50e 100644 --- a/packages/shell-api/src/collection.spec.ts +++ b/packages/shell-api/src/collection.spec.ts @@ -1553,12 +1553,14 @@ describe('Collection', function () { }); it('not returned when no args', async function () { const result = await collection.stats(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { indexDetails, ...expectedResultWithoutIndexDetails } = expectedResult; expect(result).to.deep.equal(expectedResultWithoutIndexDetails); }); it('not returned when options indexDetails: false', async function () { const result = await collection.stats({ indexDetails: false }); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { indexDetails, ...expectedResultWithoutIndexDetails } = expectedResult; expect(result).to.deep.equal(expectedResultWithoutIndexDetails); diff --git a/packages/shell-api/src/integration.spec.ts b/packages/shell-api/src/integration.spec.ts index 45fc75af4c..0053e01ebe 100644 --- a/packages/shell-api/src/integration.spec.ts +++ b/packages/shell-api/src/integration.spec.ts @@ -5,7 +5,6 @@ import type Cursor from './cursor'; import Explainable from './explainable'; import type Database from './database'; import type Collection from './collection'; -import type AggregationCursor from './aggregation-cursor'; import { startTestServer, skipIfServerVersion, diff --git a/packages/shell-api/src/mongo.ts b/packages/shell-api/src/mongo.ts index de3a8a7070..9a8dddefbf 100644 --- a/packages/shell-api/src/mongo.ts +++ b/packages/shell-api/src/mongo.ts @@ -675,6 +675,7 @@ export default class Mongo extends ShellApiClass { 'maxCommitTimeMS', ] as const; function assertAllTransactionOptionsUsed( + // eslint-disable-next-line @typescript-eslint/no-unused-vars _options: (typeof allTransactionOptions)[number] ) { // These typechecks might look weird, but will tell us if we are missing @@ -693,6 +694,7 @@ export default class Mongo extends ShellApiClass { const allSessionOptions = ['causalConsistency', 'snapshot'] as const; function assertAllSessionOptionsUsed( + // eslint-disable-next-line @typescript-eslint/no-unused-vars _options: (typeof allSessionOptions)[number] | 'defaultTransactionOptions' ) {} assertAllSessionOptionsUsed('' as keyof ClientSessionOptions); From 37db0326b53720edf0ccba0a2b4a5c7a1cccafdf Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 30 Aug 2023 10:07:55 +0100 Subject: [PATCH 08/14] re-enable @typescript-eslint/prefer-regexp-exec --- configs/eslint-config-mongosh/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/configs/eslint-config-mongosh/index.js b/configs/eslint-config-mongosh/index.js index c24d206458..8329a6368b 100644 --- a/configs/eslint-config-mongosh/index.js +++ b/configs/eslint-config-mongosh/index.js @@ -31,7 +31,6 @@ const tempTypescriptRules = { '@typescript-eslint/no-empty-function': 1, '@typescript-eslint/no-misused-promises': 1, '@typescript-eslint/unbound-method': 1, - '@typescript-eslint/prefer-regexp-exec': 1, '@typescript-eslint/ban-types': 1, }; From 698363dad6d5743092509eee317932689ce85456 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 30 Aug 2023 10:26:13 +0100 Subject: [PATCH 09/14] ticket the remaining eslint warnings that should be errors --- configs/eslint-config-mongosh/index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/configs/eslint-config-mongosh/index.js b/configs/eslint-config-mongosh/index.js index 8329a6368b..71301c52f4 100644 --- a/configs/eslint-config-mongosh/index.js +++ b/configs/eslint-config-mongosh/index.js @@ -20,17 +20,23 @@ const extraJSRules = { 'no-case-declarations': 1, }; -// TODO(MONGOSH-1508) we need to turn these back into errors (and fix them) or ticket them -const tempTypescriptRules = { +const extraTypescriptRules = { // this rule causes many false positives, so we leave it to just warn '@typescript-eslint/no-unnecessary-type-assertion': 1, + // TODO(MONGOSH-1581): re-enable this rule '@typescript-eslint/restrict-plus-operands': 1, + // TODO(MONGOSH-1582): re-enable this rule '@typescript-eslint/no-var-requires': 1, + // TODO(MONGOSH-1583): re-enable this rule '@typescript-eslint/restrict-template-expressions': 1, + // TODO(MONGOSH-1584): re-enable this rule '@typescript-eslint/no-empty-function': 1, + // TODO(MONGOSH-1585): re-enable this rule '@typescript-eslint/no-misused-promises': 1, + // TODO(MONGOSH-1586): re-enable this rule '@typescript-eslint/unbound-method': 1, + // TODO(MONGOSH-1587): re-enable this rule '@typescript-eslint/ban-types': 1, }; @@ -62,7 +68,7 @@ module.exports = { rules: { ...common.tsRules, ...extraJSRules, - ...tempTypescriptRules, + ...extraTypescriptRules, }, }, { @@ -70,7 +76,7 @@ module.exports = { rules: { ...common.tsxRules, ...extraJSRules, - ...tempTypescriptRules, + ...extraTypescriptRules, }, }, { @@ -86,7 +92,7 @@ module.exports = { rules: { ...common.testRules, ...extraJSRules, - ...tempTypescriptRules, + ...extraTypescriptRules, }, }, ], From 2387c3d1d89628e7534f5c9ab90b9a201daae422 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 30 Aug 2023 11:25:33 +0100 Subject: [PATCH 10/14] rather just disable no-useless-escape --- packages/e2e-tests/test/e2e.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/e2e-tests/test/e2e.spec.ts b/packages/e2e-tests/test/e2e.spec.ts index e433f1f58e..262df66ea1 100644 --- a/packages/e2e-tests/test/e2e.spec.ts +++ b/packages/e2e-tests/test/e2e.spec.ts @@ -696,15 +696,17 @@ describe('e2e', function () { skipIfServerVersion(testServer, '<= 4.4'); it('displays errInfo to the user', async function () { + /* eslint-disable no-useless-escape */ await shell.executeLine(`db.createCollection('contacts', { validator: { $and: [ { phone: { $type: "string" } }, - { email: { $regex: /@mongodb.com$/ } }, + { email: { $regex: /@mongodb\.com$/ } }, { status: { $in: [ "Unknown", "Incomplete" ] } } ] } });`); + /* eslint-enable no-useless-escape */ const result = await shell.executeLine(`db.contacts.insertOne({ email: "test@mongodb.com", status: "Unknown" });`); From 24f71c0a9099f48fc49d037351e950c99ba762ee Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 30 Aug 2023 11:32:11 +0100 Subject: [PATCH 11/14] remove async promise executor --- .../src/spawn-child-from-source.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts b/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts index 35f00b43a8..93216542b4 100644 --- a/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts +++ b/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts @@ -25,8 +25,7 @@ export default function spawnChildFromSource( _stdout: StdioNull | StdioPipe = 'inherit', _stderr: StdioNull | StdioPipe = 'inherit' ): Promise { - // eslint-disable-next-line no-async-promise-executor - return new Promise(async (resolve, reject) => { + return new Promise((resolve, reject) => { const readyToken = Date.now().toString(32); const childProcess = spawn(process.execPath, { @@ -35,11 +34,16 @@ export default function spawnChildFromSource( }); if (!childProcess.stdin) { - await kill(childProcess); - - return reject( - new Error("Can't write src to the spawned process, missing stdin") - ); + kill(childProcess) + .then(() => { + reject( + new Error("Can't write src to the spawned process, missing stdin") + ); + }) + .catch((err: any) => { + throw err; + }); + return; } // eslint-disable-next-line prefer-const From 272e94190fdf16cc71cdb86be88657a2a02a26c2 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 30 Aug 2023 12:12:10 +0100 Subject: [PATCH 12/14] reject rather --- .../node-runtime-worker-thread/src/spawn-child-from-source.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts b/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts index 93216542b4..5d35128f5d 100644 --- a/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts +++ b/packages/node-runtime-worker-thread/src/spawn-child-from-source.ts @@ -41,7 +41,7 @@ export default function spawnChildFromSource( ); }) .catch((err: any) => { - throw err; + reject(err); }); return; } From 45d9b9cc70829b6d76863f7531567a89681ebc09 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Thu, 31 Aug 2023 11:09:29 +0100 Subject: [PATCH 13/14] not a false positive --- packages/e2e-tests/test/repl-helpers.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/e2e-tests/test/repl-helpers.ts b/packages/e2e-tests/test/repl-helpers.ts index 72d3305a66..f34932c2cf 100644 --- a/packages/e2e-tests/test/repl-helpers.ts +++ b/packages/e2e-tests/test/repl-helpers.ts @@ -89,8 +89,7 @@ const fakeExternalEditor = async ({ if (${JSON.stringify(flags ?? '')}) { assert.deepStrictEqual((${JSON.stringify( flags - // eslint-disable-next-line no-useless-escape - )}).split(/\s+/), process.argv.slice(2, -1)); + )}).split(/\\s+/), process.argv.slice(2, -1)); } await writeFile(tmpDoc, ${JSON.stringify(output)}, { mode: 0o600 }); From 72b65609e26bb24bfe74e86dff63ae17a9a6838b Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Mon, 4 Sep 2023 16:19:58 +0100 Subject: [PATCH 14/14] fix new lint errors after merge --- packages/shell-api/src/field-level-encryption.spec.ts | 1 - packages/shell-api/src/field-level-encryption.ts | 3 +-- packages/shell-api/src/session.ts | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/shell-api/src/field-level-encryption.spec.ts b/packages/shell-api/src/field-level-encryption.spec.ts index 5e78da1c82..0e99cecbb4 100644 --- a/packages/shell-api/src/field-level-encryption.spec.ts +++ b/packages/shell-api/src/field-level-encryption.spec.ts @@ -36,7 +36,6 @@ import { makeFakeHTTPConnection, fakeAWSHandlers, } from '../../../testing/fake-kms'; -import { inspect } from 'util'; import Collection from './collection'; import { dummyOptions } from './helpers.spec'; diff --git a/packages/shell-api/src/field-level-encryption.ts b/packages/shell-api/src/field-level-encryption.ts index 9f827eab19..4ca9924944 100644 --- a/packages/shell-api/src/field-level-encryption.ts +++ b/packages/shell-api/src/field-level-encryption.ts @@ -23,7 +23,7 @@ import type Collection from './collection'; import Cursor from './cursor'; import type { DeleteResult } from './result'; import { assertArgsDefinedType, assertKeysDefined } from './helpers'; -import { asPrintable, shellApiType } from './enums'; +import { asPrintable } from './enums'; import { redactURICredentials } from '@mongosh/history'; import type Mongo from './mongo'; import { @@ -31,7 +31,6 @@ import { MongoshInvalidInputError, MongoshRuntimeError, } from '@mongosh/errors'; -import type ShellInstanceState from './shell-instance-state'; import type { CreateEncryptedCollectionOptions } from '@mongosh/service-provider-core'; export type ClientSideFieldLevelEncryptionKmsProvider = Omit< diff --git a/packages/shell-api/src/session.ts b/packages/shell-api/src/session.ts index 843ac7bb83..cdae162d54 100644 --- a/packages/shell-api/src/session.ts +++ b/packages/shell-api/src/session.ts @@ -5,7 +5,6 @@ import { ShellApiWithMongoClass, } from './decorators'; import type { - Document, ClientSessionOptions, ClientSession, TransactionOptions,