SERVER-126414 Add linter rule to prevent jstests from committing .only() with mochalite (#53658)

GitOrigin-RevId: 20ac742fc5a46d154ac488967480fd9d1cc7efb1
This commit is contained in:
Jada Lilleboe 2026-05-13 10:52:32 -04:00 committed by MongoDB Bot
parent da7af1bad1
commit a9d8aa322d
8 changed files with 24 additions and 3 deletions

View File

@ -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",

View File

@ -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,

View File

@ -1,3 +1,4 @@
/* eslint-disable mochaNoOnly/mocha-no-only */
/**
* Simple test framework for running tests in JS files.
*

View File

@ -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 = [];

View File

@ -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
});
});

View File

@ -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");

View File

@ -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"
},

15
pnpm-lock.yaml generated
View File

@ -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'}