diff --git a/BUILD.bazel b/BUILD.bazel index 05c9c473d53..41cd2dbffd3 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -33,6 +33,7 @@ mongo_js_library( deps = [ ":node_modules/@eslint/eslintrc", ":node_modules/@eslint/js", + ":node_modules/eslint-plugin-mocha-no-only", ":node_modules/eslint-plugin-mongodb", ":node_modules/globals", "//src/mongo/shell/debugger/vscode:eslint", diff --git a/eslint.config.mjs b/eslint.config.mjs index 4eaf5c941c5..e5dd8bb57bf 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,5 +1,6 @@ import {FlatCompat} from "@eslint/eslintrc"; import js from "@eslint/js"; +import mocha_no_only_plugin from "eslint-plugin-mocha-no-only"; import {default as mongodb_plugin} from "eslint-plugin-mongodb"; import globals from "globals"; import path from "node:path"; @@ -318,14 +319,15 @@ export default [ }, plugins: { + mochaNoOnly: mocha_no_only_plugin, mongodb: mongodb_plugin, }, rules: { + "mochaNoOnly/mocha-no-only": 2, // TODO SERVER-99571 : enable mongodb/* rules. "mongodb/no-print-fn": 0, "mongodb/no-printing-tojson": 0, - "no-prototype-builtins": 0, "no-useless-escape": 0, "no-irregular-whitespace": 0, diff --git a/jstests/libs/mochalite.js b/jstests/libs/mochalite.js index 42e3a233b3a..94c31083d5d 100644 --- a/jstests/libs/mochalite.js +++ b/jstests/libs/mochalite.js @@ -1,3 +1,4 @@ +/* eslint-disable mochaNoOnly/mocha-no-only */ /** * Simple test framework for running tests in JS files. * diff --git a/jstests/noPassthrough/shell/js/mochalite_only.js b/jstests/noPassthrough/shell/js/mochalite_only.js index c27461a8671..bb62dd3e495 100644 --- a/jstests/noPassthrough/shell/js/mochalite_only.js +++ b/jstests/noPassthrough/shell/js/mochalite_only.js @@ -1,3 +1,4 @@ +/* eslint-disable mochaNoOnly/mocha-no-only -- this file tests the .only() feature of mochalite itself */ import {after, afterEach, before, beforeEach, describe, it} from "jstests/libs/mochalite.js"; const log = []; diff --git a/jstests/noPassthrough/shell/js/mochalite_skip.js b/jstests/noPassthrough/shell/js/mochalite_skip.js index dfcf2e02a6e..a792d2b8229 100644 --- a/jstests/noPassthrough/shell/js/mochalite_skip.js +++ b/jstests/noPassthrough/shell/js/mochalite_skip.js @@ -26,7 +26,7 @@ describe("describe", () => { beforeEach(die); afterEach(die); after(die); - it.only("test5", die); + it.only("test5", die); // eslint-disable-line mochaNoOnly/mocha-no-only }); }); diff --git a/jstests/sharding/set_user_write_block_mode.js b/jstests/sharding/set_user_write_block_mode.js index f66f5a05555..e06410dce71 100644 --- a/jstests/sharding/set_user_write_block_mode.js +++ b/jstests/sharding/set_user_write_block_mode.js @@ -22,7 +22,7 @@ import {removeShard} from "jstests/sharding/libs/remove_shard_util.js"; import {ShardedIndexUtil} from "jstests/sharding/libs/sharded_index_util.js"; import {after, afterEach, before, beforeEach, describe, it} from "jstests/libs/mochalite.js"; -describe.only("setUserWriteBlockMode on replicaset", function () { +describe("setUserWriteBlockMode on replicaset", function () { before(() => { this.is_83 = () => { const admin = this.rs.getPrimary().getDB("admin"); diff --git a/package.json b/package.json index 94e8e78cb64..c87877f90ec 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@eslint/js": "^9", "eslint": "9.19.0", "eslint-formatter-unix": "^8.40.0", + "eslint-plugin-mocha-no-only": "^1.2.0", "globals": "14.0.0", "prettier": "3.4.2" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 50070537b90..95b818495a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,6 +24,9 @@ devDependencies: eslint-formatter-unix: specifier: ^8.40.0 version: 8.40.0 + eslint-plugin-mocha-no-only: + specifier: ^1.2.0 + version: 1.2.0 globals: specifier: 14.0.0 version: 14.0.0 @@ -245,6 +248,13 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true + /eslint-plugin-mocha-no-only@1.2.0: + resolution: {integrity: sha512-sgOilWiikVmYysUvt9q7oUMBYuv/Tka8lQH3766DNxOVqJAKwmP7QqmGYVBiVmqGnn5CDYAo3WWT0F8qw5BDMQ==} + engines: {node: '>=0.10.0'} + dependencies: + requireindex: 1.1.0 + dev: true + /eslint-scope@8.2.0: resolution: {integrity: sha512-PHlWUfG6lvPc3yvP5A4PNyBL1W8fkDUccmI21JUu/+GKZBoH/W5u6usENXUrWFRsyoW5ACUjFGgAFQp5gUlb/A==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -551,6 +561,11 @@ packages: engines: {node: '>=6'} dev: true + /requireindex@1.1.0: + resolution: {integrity: sha512-LBnkqsDE7BZKvqylbmn7lTIVdpx4K/QCduRATpO5R+wtPmky/a8pN1bO2D6wXppn1497AJF9mNjqAXr6bdl9jg==} + engines: {node: '>=0.10.5'} + dev: true + /resolve-from@4.0.0: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} engines: {node: '>=4'}