Skip to content
Merged
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
43 changes: 22 additions & 21 deletions configs/eslint-config-mongosh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,28 +13,30 @@ const tempRules = {
'mocha/max-top-level-suites': 1,
'mocha/no-sibling-hooks': 1,

// this would disallow our locale files' filenames like de_DE.ts
'filename-rules/match': 1,

'no-useless-escape': 1,
'no-undef': 1,
'no-prototype-builtins': 1,
'no-async-promise-executor': 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 = {
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,
'@typescript-eslint/consistent-type-imports': 1,
// TODO(MONGOSH-1586): re-enable this rule
'@typescript-eslint/unbound-method': 1,
'@typescript-eslint/no-implied-eval': 1,
'@typescript-eslint/no-unused-vars': 1,
'@typescript-eslint/prefer-regexp-exec': 1,
// TODO(MONGOSH-1587): re-enable this rule
'@typescript-eslint/ban-types': 1,
};

Expand All @@ -52,46 +53,46 @@ module.exports = {
...common.jsOverrides,
rules: {
...common.jsRules,
...tempRules,
...extraJSRules,
},
},
{
...common.jsxOverrides,
rules: {
...common.jsxRules,
...tempRules,
...extraJSRules,
},
},
{
...common.tsOverrides,
rules: {
...common.tsRules,
...tempRules,
...tempTypescriptRules,
...extraJSRules,
...extraTypescriptRules,
},
},
{
...common.tsxOverrides,
rules: {
...common.tsxRules,
...tempRules,
...tempTypescriptRules,
...extraJSRules,
...extraTypescriptRules,
},
},
{
...common.testOverrides,
rules: {
...common.testRules,
...tempRules,
...extraJSRules,
},
},
{
...common.testOverrides,
files: ['**/*.spec.ts', '**/*.spec.tsx', '**/*.test.tsx', '**/*.test.ts'],
rules: {
...common.testRules,
...tempRules,
...tempTypescriptRules,
...extraJSRules,
...extraTypescriptRules,
},
},
],
Expand Down
3 changes: 2 additions & 1 deletion packages/build/src/download-center/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions packages/build/src/homebrew/generate-formula.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;

Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions packages/build/src/homebrew/generate-formula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/cli-repl/src/crypt-library-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function getCryptLibraryPaths(
): Promise<CryptLibraryPathResult> {
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');
Expand Down
1 change: 1 addition & 0 deletions packages/cli-repl/src/mongosh-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
this.started = true;
const { repl } = this.runtimeState();
Expand Down
1 change: 1 addition & 0 deletions packages/cli-repl/test/fixtures/load/hello1.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/* eslint-disable no-undef */
print('hello one');
1 change: 1 addition & 0 deletions packages/cli-repl/test/fixtures/load/hello2.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/* eslint-disable no-undef */
print('hello two');
1 change: 1 addition & 0 deletions packages/cli-repl/test/fixtures/load/insertintotest.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* eslint-disable no-undef */
insertTestCollection = db.getSiblingDB('test').getCollection('insertTest' + ((Math.random() * 100000) | 0));
print('Inserted:', insertTestCollection.insertOne({}).insertedId)
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/* eslint-disable no-undef */
print(`isInteractive=${isInteractive()}`)
1 change: 0 additions & 1 deletion packages/e2e-tests/test/e2e-fle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { once } from 'events';
import { serialize } from 'v8';
import { inspect } from 'util';
import path from 'path';
import os from 'os';

describe('FLE tests', function () {
const testServer = startTestServer('e2e-fle', {
Expand Down
6 changes: 4 additions & 2 deletions packages/e2e-tests/test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,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);
});
Expand Down Expand Up @@ -695,6 +695,7 @@ 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: [
Expand All @@ -704,6 +705,7 @@ describe('e2e', function () {
]
}
});`);
/* eslint-enable no-useless-escape */
const result = await shell.executeLine(`db.contacts.insertOne({
email: "test@mongodb.com", status: "Unknown"
});`);
Expand All @@ -716,7 +718,7 @@ describe('e2e', function () {
validator: {
$and: [
{ phone: { $type: "string" } },
{ email: { $regex: /@mongodb\.com$/ } },
{ email: { $regex: /@mongodb.com$/ } },
{ status: { $in: [ "Unknown", "Incomplete" ] } }
]
}
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-tests/test/fixtures/exampleplayground.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-tests/test/fixtures/load/long-sleep.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
console.log('Long sleep');
(async() => {
await sleep(1_000_000);
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/test/repl-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const fakeExternalEditor = async ({
if (${JSON.stringify(flags ?? '')}) {
assert.deepStrictEqual((${JSON.stringify(
flags
)}).split(/\s+/), process.argv.slice(2, -1));
)}).split(/\\s+/), process.argv.slice(2, -1));
}

await writeFile(tmpDoc, ${JSON.stringify(output)}, { mode: 0o600 });
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -155,7 +155,7 @@ export class Editor {
return false;
}

const regex = /^([^!"#%&'()*+,\-/\[\]\\^`{|}~]+)$/;
const regex = /^([^!"#%&'()*+,\-/[\]\\^`{|}~]+)$/;
return regex.test(code);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/src/translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/logging/src/analytics-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class Queue<T> {
* (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();
}
Expand Down
1 change: 1 addition & 0 deletions packages/logging/src/setup-logger-and-telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really wish these rules would understand underscore-prefixed names or at least some kind of pattern for avoiding false positives 🙂

const { uri: _uri, ...argsWithoutUri } = args;
const params = {
session_id: logId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function spawnChildFromSource(
_stdout: StdioNull | StdioPipe = 'inherit',
_stderr: StdioNull | StdioPipe = 'inherit'
): Promise<ChildProcess> {
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
const readyToken = Date.now().toString(32);

const childProcess = spawn(process.execPath, {
Expand All @@ -34,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) => {
reject(err);
});
return;
}

// eslint-disable-next-line prefer-const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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/
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
2 changes: 2 additions & 0 deletions packages/shell-api/src/collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion packages/shell-api/src/field-level-encryption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
makeFakeHTTPConnection,
fakeAWSHandlers,
} from '../../../testing/fake-kms';
import { inspect } from 'util';
import Collection from './collection';
import { dummyOptions } from './helpers.spec';

Expand Down
Loading