From 41c13912f09ed1b5b811b73c7e2036829bbb6507 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 25 Aug 2025 12:23:11 +0200 Subject: [PATCH 1/7] chore: adds eslint rule to restrict import from config file --- eslint-rules/no-config-imports.js | 81 ++++++++++++++++++++++++++ eslint-rules/no-config-imports.test.js | 79 +++++++++++++++++++++++++ eslint.config.js | 32 ++++++++++ package.json | 2 +- vitest.config.ts | 7 +++ 5 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 eslint-rules/no-config-imports.js create mode 100644 eslint-rules/no-config-imports.test.js diff --git a/eslint-rules/no-config-imports.js b/eslint-rules/no-config-imports.js new file mode 100644 index 000000000..9bd45ecd0 --- /dev/null +++ b/eslint-rules/no-config-imports.js @@ -0,0 +1,81 @@ +import path from "path"; + +// Ref: https://eslint.org/docs/latest/extend/custom-rules +export default { + meta: { + type: "problem", + docs: { + description: + "Disallows value imports from config.ts, with a few exceptions, to enforce dependency injection of the config.", + recommended: true, + }, + fixable: null, + schema: [ + { + type: "object", + properties: { + configFilePath: { + type: "string", + description: "Path (relative to root of the project) to the config file to restrict.", + }, + allowedFiles: { + type: "array", + items: { type: "string" }, + description: + "List of file paths (relative to root of the project) that are allowed to import value exports from config.ts.", + }, + }, + required: ["configFilePath"], + }, + ], + messages: { + noConfigImports: + "Value imports from config.ts are not allowed. Use dependency injection instead. Only type imports are permitted.", + }, + }, + create(context) { + const options = context.options[0] || {}; + const configFilePath = path.resolve(options.configFilePath); + const allowedFiles = options.allowedFiles || []; + + const currentFilePath = path.resolve(context.getFilename()); + + const isCurrentFileAllowedToImport = allowedFiles.some((allowedFile) => { + const resolvedAllowedFile = path.resolve(allowedFile); + return currentFilePath === resolvedAllowedFile; + }); + + if (isCurrentFileAllowedToImport) { + return {}; + } + + return { + ImportDeclaration(node) { + const importPath = node.source.value; + + // If the path is not relative, very likely its targeting a + // node_module so we skip it. And also if the entire import is + // marked with a type keyword. + if (typeof importPath !== "string" || !importPath.startsWith(".") || node.importKind === "type") { + return; + } + + const currentDir = path.dirname(currentFilePath); + const resolvedImportPath = path.resolve(currentDir, importPath); + + if (resolvedImportPath === configFilePath) { + const hasValueImportFromConfig = node.specifiers.some((specifier) => { + return specifier.importKind !== "type"; + }); + + if (hasValueImportFromConfig) { + context.report({ + node, + messageId: "noConfigImports", + }); + } + } + }, + }; + }, +}; diff --git a/eslint-rules/no-config-imports.test.js b/eslint-rules/no-config-imports.test.js new file mode 100644 index 000000000..a50509792 --- /dev/null +++ b/eslint-rules/no-config-imports.test.js @@ -0,0 +1,79 @@ +import path from "path"; +import { RuleTester } from "eslint"; +import { describe, it } from "vitest"; +import tsParser from "@typescript-eslint/parser"; +import rule from "./no-config-imports.js"; + +const ROOT = process.cwd(); +const resolve = (p) => path.resolve(ROOT, p); +const CONFIG_FILE_PATH = resolve("src/common/config.js"); +const ALLOWED_CONFIG_VALUE_IMPORT_FILES = [resolve("src/index.ts"), resolve("src/resources/common/config.ts")]; + +const ruleTester = new RuleTester({ + languageOptions: { + parser: tsParser, + parserOptions: { ecmaVersion: 2022, sourceType: "module" }, + }, +}); + +describe("no-config-imports", () => { + it("should not report any violations", () => { + ruleTester.run("no-config-imports", rule, { + valid: [ + { + filename: resolve("src/some/module.ts"), + code: 'import type { UserConfig } from "../common/config.js";\n', + options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], + }, + { + filename: resolve("src/some/module.ts"), + code: 'import { something } from "../common/logger.js";\n', + options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], + }, + { + filename: resolve("src/some/module.ts"), + code: 'import type * as Cfg from "../common/config.js";\n', + options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], + }, + { + filename: ALLOWED_CONFIG_VALUE_IMPORT_FILES[1], + code: 'import { driverOptions } from "../common/config.js";\n', + options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], + }, + ], + invalid: [], + }); + }); + + it("should report rule violations", () => { + ruleTester.run("no-config-imports", rule, { + valid: [], + invalid: [ + { + filename: resolve("src/another/module.ts"), + code: 'import { driverOptions } from "../common/config.js";\n', + options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], + errors: [{ messageId: "noConfigImports" }], + }, + { + filename: resolve("src/another/module.ts"), + code: 'import configDefault from "../common/config.js";\n', + options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], + errors: [{ messageId: "noConfigImports" }], + }, + { + filename: resolve("src/another/module.ts"), + code: 'import * as cfg from "../common/config.js";\n', + options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], + errors: [{ messageId: "noConfigImports" }], + }, + { + filename: resolve("src/another/module.ts"), + code: 'import { type UserConfig, driverOptions } from "../common/config.js";\n', + options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], + errors: [{ messageId: "noConfigImports" }], + }, + ], + }); + }); +}); diff --git a/eslint.config.js b/eslint.config.js index f6755d129..0e941929e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,14 +1,26 @@ +import path from "path"; import { defineConfig, globalIgnores } from "eslint/config"; import js from "@eslint/js"; import globals from "globals"; import tseslint from "typescript-eslint"; import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended"; import vitestPlugin from "@vitest/eslint-plugin"; +import noConfigImports from "./eslint-rules/no-config-imports.js"; const testFiles = ["tests/**/*.test.ts", "tests/**/*.ts"]; const files = [...testFiles, "src/**/*.ts", "scripts/**/*.ts"]; +// Files that are allowed to import value exports from config.ts +const allowedConfigValueImportFiles = [ + // Main entry point that injects the config + "src/index.ts", + // Config resource definition that works with the some config values + "src/resources/common/config.ts", +]; + +const configFilePath = path.resolve(import.meta.dirname, "src/common/config.js"); + export default defineConfig([ { files, plugins: { js }, extends: ["js/recommended"] }, { files, languageOptions: { globals: globals.node } }, @@ -62,6 +74,25 @@ export default defineConfig([ "@typescript-eslint/explicit-function-return-type": "error", }, }, + { + files: ["src/**/*.ts"], + plugins: { + "no-config-imports": { + rules: { + "no-config-imports": noConfigImports, + }, + }, + }, + rules: { + "no-config-imports/no-config-imports": [ + "error", + { + configFilePath, + allowedFiles: allowedConfigValueImportFiles, + }, + ], + }, + }, globalIgnores([ "node_modules", "dist", @@ -72,6 +103,7 @@ export default defineConfig([ "vitest.config.ts", "src/types/*.d.ts", "tests/integration/fixtures/", + "eslint-rules", ]), eslintPluginPrettierRecommended, ]); diff --git a/package.json b/package.json index c5927d242..e943a8277 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "fix:lint": "eslint . --fix", "reformat": "prettier --write .", "generate": "./scripts/generate.sh", - "test": "vitest --project unit-and-integration --coverage", + "test": "vitest --project eslint-rules --project unit-and-integration --coverage", "pretest:accuracy": "npm run build", "test:accuracy": "sh ./scripts/accuracy/runAccuracyTests.sh" }, diff --git a/vitest.config.ts b/vitest.config.ts index 239650acb..e434fb5de 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -36,6 +36,13 @@ export default defineConfig({ include: ["**/accuracy/*.test.ts"], }, }, + { + extends: true, + test: { + name: "eslint-rules", + include: ["eslint-rules/*.test.js"] + } + } ], }, }); From c28045e7f57ff8c6dfaa27c91f8da9f024637f0d Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 25 Aug 2025 12:06:13 +0200 Subject: [PATCH 2/7] chore: refactor Transport implementations to accept driverOptions --- src/index.ts | 7 +++++-- src/transports/base.ts | 26 ++++++++++++++------------ src/transports/stdio.ts | 8 ++++---- src/transports/streamableHttp.ts | 8 ++++---- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/index.ts b/src/index.ts index 29f525dc3..31f393461 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,7 +36,7 @@ function enableFipsIfRequested(): void { enableFipsIfRequested(); import { ConsoleLogger, LogId } from "./common/logger.js"; -import { config } from "./common/config.js"; +import { config, driverOptions } from "./common/config.js"; import crypto from "crypto"; import { packageInfo } from "./common/packageInfo.js"; import { StdioRunner } from "./transports/stdio.js"; @@ -49,7 +49,10 @@ async function main(): Promise { assertHelpMode(); assertVersionMode(); - const transportRunner = config.transport === "stdio" ? new StdioRunner(config) : new StreamableHttpRunner(config); + const transportRunner = + config.transport === "stdio" + ? new StdioRunner(config, driverOptions) + : new StreamableHttpRunner(config, driverOptions); const shutdown = (): void => { transportRunner.logger.info({ id: LogId.serverCloseRequested, diff --git a/src/transports/base.ts b/src/transports/base.ts index f58fbf2ed..17a0ff5e7 100644 --- a/src/transports/base.ts +++ b/src/transports/base.ts @@ -1,5 +1,4 @@ -import type { UserConfig } from "../common/config.js"; -import { driverOptions } from "../common/config.js"; +import type { DriverOptions, UserConfig } from "../common/config.js"; import { packageInfo } from "../common/packageInfo.js"; import { Server } from "../server.js"; import { Session } from "../common/session.js"; @@ -15,7 +14,10 @@ export abstract class TransportRunnerBase { public logger: LoggerBase; public deviceId: DeviceId; - protected constructor(protected readonly userConfig: UserConfig) { + protected constructor( + protected readonly userConfig: UserConfig, + private readonly driverOptions: DriverOptions + ) { const loggers: LoggerBase[] = []; if (this.userConfig.loggers.includes("stderr")) { loggers.push(new ConsoleLogger()); @@ -35,37 +37,37 @@ export abstract class TransportRunnerBase { this.deviceId = DeviceId.create(this.logger); } - protected setupServer(userConfig: UserConfig): Server { + protected setupServer(): Server { const mcpServer = new McpServer({ name: packageInfo.mcpServerName, version: packageInfo.version, }); const loggers = [this.logger]; - if (userConfig.loggers.includes("mcp")) { + if (this.userConfig.loggers.includes("mcp")) { loggers.push(new McpLogger(mcpServer)); } const logger = new CompositeLogger(...loggers); - const exportsManager = ExportsManager.init(userConfig, logger); - const connectionManager = new ConnectionManager(userConfig, driverOptions, logger, this.deviceId); + const exportsManager = ExportsManager.init(this.userConfig, logger); + const connectionManager = new ConnectionManager(this.userConfig, this.driverOptions, logger, this.deviceId); const session = new Session({ - apiBaseUrl: userConfig.apiBaseUrl, - apiClientId: userConfig.apiClientId, - apiClientSecret: userConfig.apiClientSecret, + apiBaseUrl: this.userConfig.apiBaseUrl, + apiClientId: this.userConfig.apiClientId, + apiClientSecret: this.userConfig.apiClientSecret, logger, exportsManager, connectionManager, }); - const telemetry = Telemetry.create(session, userConfig, this.deviceId); + const telemetry = Telemetry.create(session, this.userConfig, this.deviceId); return new Server({ mcpServer, session, telemetry, - userConfig, + userConfig: this.userConfig, }); } diff --git a/src/transports/stdio.ts b/src/transports/stdio.ts index 3668c4ee8..d0619da6c 100644 --- a/src/transports/stdio.ts +++ b/src/transports/stdio.ts @@ -5,7 +5,7 @@ import type { JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js"; import { JSONRPCMessageSchema } from "@modelcontextprotocol/sdk/types.js"; import { EJSON } from "bson"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; -import type { UserConfig } from "../common/config.js"; +import type { DriverOptions, UserConfig } from "../common/config.js"; // This is almost a copy of ReadBuffer from @modelcontextprotocol/sdk // but it uses EJSON.parse instead of JSON.parse to handle BSON types @@ -54,13 +54,13 @@ export function createStdioTransport(): StdioServerTransport { export class StdioRunner extends TransportRunnerBase { private server: Server | undefined; - constructor(userConfig: UserConfig) { - super(userConfig); + constructor(userConfig: UserConfig, driverOptions: DriverOptions) { + super(userConfig, driverOptions); } async start(): Promise { try { - this.server = this.setupServer(this.userConfig); + this.server = this.setupServer(); const transport = createStdioTransport(); diff --git a/src/transports/streamableHttp.ts b/src/transports/streamableHttp.ts index b15a201f2..f50019ef4 100644 --- a/src/transports/streamableHttp.ts +++ b/src/transports/streamableHttp.ts @@ -3,7 +3,7 @@ import type http from "http"; import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js"; import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js"; import { TransportRunnerBase } from "./base.js"; -import type { UserConfig } from "../common/config.js"; +import type { DriverOptions, UserConfig } from "../common/config.js"; import { LogId } from "../common/logger.js"; import { randomUUID } from "crypto"; import { SessionStore } from "../common/sessionStore.js"; @@ -18,8 +18,8 @@ export class StreamableHttpRunner extends TransportRunnerBase { private httpServer: http.Server | undefined; private sessionStore!: SessionStore; - constructor(userConfig: UserConfig) { - super(userConfig); + constructor(userConfig: UserConfig, driverOptions: DriverOptions) { + super(userConfig, driverOptions); } async start(): Promise { @@ -89,7 +89,7 @@ export class StreamableHttpRunner extends TransportRunnerBase { return; } - const server = this.setupServer(this.userConfig); + const server = this.setupServer(); const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: (): string => randomUUID().toString(), onsessioninitialized: (sessionId): void => { From 2c1c3be7d686fd6c501ced31496a96e57012ba9a Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 25 Aug 2025 12:24:19 +0200 Subject: [PATCH 3/7] chore: updated description --- eslint-rules/no-config-imports.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eslint-rules/no-config-imports.js b/eslint-rules/no-config-imports.js index 9bd45ecd0..73a87a077 100644 --- a/eslint-rules/no-config-imports.js +++ b/eslint-rules/no-config-imports.js @@ -16,13 +16,12 @@ export default { properties: { configFilePath: { type: "string", - description: "Path (relative to root of the project) to the config file to restrict.", + description: "Path to the config file to restrict.", }, allowedFiles: { type: "array", items: { type: "string" }, - description: - "List of file paths (relative to root of the project) that are allowed to import value exports from config.ts.", + description: "List of file paths that are allowed to import value exports from config.ts.", }, }, required: ["configFilePath"], From 35f2cd50b6fae47432347a22f0fbb0f7c1ce3178 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 25 Aug 2025 12:27:51 +0200 Subject: [PATCH 4/7] chore: check fixes --- tests/integration/transports/streamableHttp.test.ts | 4 ++-- vitest.config.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integration/transports/streamableHttp.test.ts b/tests/integration/transports/streamableHttp.test.ts index d5b6e0be7..396879b1b 100644 --- a/tests/integration/transports/streamableHttp.test.ts +++ b/tests/integration/transports/streamableHttp.test.ts @@ -2,7 +2,7 @@ import { StreamableHttpRunner } from "../../../src/transports/streamableHttp.js" import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"; import { describe, expect, it, beforeAll, afterAll } from "vitest"; -import { config } from "../../../src/common/config.js"; +import { config, driverOptions } from "../../../src/common/config.js"; describe("StreamableHttpRunner", () => { let runner: StreamableHttpRunner; @@ -14,7 +14,7 @@ describe("StreamableHttpRunner", () => { oldLoggers = config.loggers; config.telemetry = "disabled"; config.loggers = ["stderr"]; - runner = new StreamableHttpRunner(config); + runner = new StreamableHttpRunner(config, driverOptions); await runner.start(); }); diff --git a/vitest.config.ts b/vitest.config.ts index e434fb5de..903a174af 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -40,9 +40,9 @@ export default defineConfig({ extends: true, test: { name: "eslint-rules", - include: ["eslint-rules/*.test.js"] - } - } + include: ["eslint-rules/*.test.js"], + }, + }, ], }, }); From d75862951545eb75dfb049e3a7ec657507814aed Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 25 Aug 2025 13:06:24 +0200 Subject: [PATCH 5/7] chore: add check for options --- eslint-rules/no-config-imports.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/eslint-rules/no-config-imports.js b/eslint-rules/no-config-imports.js index 73a87a077..30f6cde9f 100644 --- a/eslint-rules/no-config-imports.js +++ b/eslint-rules/no-config-imports.js @@ -33,7 +33,12 @@ export default { }, }, create(context) { - const options = context.options[0] || {}; + const options = context.options[0]; + if (!options) { + throw new Error( + "no-config-imports should be configured with an object with at-least 'configFilePath' key." + ); + } const configFilePath = path.resolve(options.configFilePath); const allowedFiles = options.allowedFiles || []; From fdcbcfc080be332975ce06e57facc897aa011793 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 25 Aug 2025 13:08:44 +0200 Subject: [PATCH 6/7] chore: add missing use strict directive --- eslint-rules/no-config-imports.js | 1 + 1 file changed, 1 insertion(+) diff --git a/eslint-rules/no-config-imports.js b/eslint-rules/no-config-imports.js index 30f6cde9f..39d2a5bac 100644 --- a/eslint-rules/no-config-imports.js +++ b/eslint-rules/no-config-imports.js @@ -1,3 +1,4 @@ +"use strict"; import path from "path"; // Ref: https://eslint.org/docs/latest/extend/custom-rules From 6aac510a4d3b4fa4866bfeb8580d5f8864e186b1 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 25 Aug 2025 16:34:18 +0200 Subject: [PATCH 7/7] chore: make no-config-imports rule tied to config itself --- eslint-rules/no-config-imports.js | 39 ++++++++------------------ eslint-rules/no-config-imports.test.js | 12 +------- eslint.config.js | 18 +----------- 3 files changed, 14 insertions(+), 55 deletions(-) diff --git a/eslint-rules/no-config-imports.js b/eslint-rules/no-config-imports.js index 39d2a5bac..908dd5ae7 100644 --- a/eslint-rules/no-config-imports.js +++ b/eslint-rules/no-config-imports.js @@ -1,6 +1,17 @@ "use strict"; import path from "path"; +// The file from which we wish to discourage importing values +const configFilePath = path.resolve(import.meta.dirname, "../src/common/config.js"); + +// Files that are allowed to import value exports from config.ts +const allowedConfigValueImportFiles = [ + // Main entry point that injects the config + "src/index.ts", + // Config resource definition that works with the some config values + "src/resources/common/config.ts", +]; + // Ref: https://eslint.org/docs/latest/extend/custom-rules export default { meta: { @@ -11,41 +22,15 @@ export default { recommended: true, }, fixable: null, - schema: [ - { - type: "object", - properties: { - configFilePath: { - type: "string", - description: "Path to the config file to restrict.", - }, - allowedFiles: { - type: "array", - items: { type: "string" }, - description: "List of file paths that are allowed to import value exports from config.ts.", - }, - }, - required: ["configFilePath"], - }, - ], messages: { noConfigImports: "Value imports from config.ts are not allowed. Use dependency injection instead. Only type imports are permitted.", }, }, create(context) { - const options = context.options[0]; - if (!options) { - throw new Error( - "no-config-imports should be configured with an object with at-least 'configFilePath' key." - ); - } - const configFilePath = path.resolve(options.configFilePath); - const allowedFiles = options.allowedFiles || []; - const currentFilePath = path.resolve(context.getFilename()); - const isCurrentFileAllowedToImport = allowedFiles.some((allowedFile) => { + const isCurrentFileAllowedToImport = allowedConfigValueImportFiles.some((allowedFile) => { const resolvedAllowedFile = path.resolve(allowedFile); return currentFilePath === resolvedAllowedFile; }); diff --git a/eslint-rules/no-config-imports.test.js b/eslint-rules/no-config-imports.test.js index a50509792..d94e952db 100644 --- a/eslint-rules/no-config-imports.test.js +++ b/eslint-rules/no-config-imports.test.js @@ -6,8 +6,6 @@ import rule from "./no-config-imports.js"; const ROOT = process.cwd(); const resolve = (p) => path.resolve(ROOT, p); -const CONFIG_FILE_PATH = resolve("src/common/config.js"); -const ALLOWED_CONFIG_VALUE_IMPORT_FILES = [resolve("src/index.ts"), resolve("src/resources/common/config.ts")]; const ruleTester = new RuleTester({ languageOptions: { @@ -23,22 +21,18 @@ describe("no-config-imports", () => { { filename: resolve("src/some/module.ts"), code: 'import type { UserConfig } from "../common/config.js";\n', - options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], }, { filename: resolve("src/some/module.ts"), code: 'import { something } from "../common/logger.js";\n', - options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], }, { filename: resolve("src/some/module.ts"), code: 'import type * as Cfg from "../common/config.js";\n', - options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], }, { - filename: ALLOWED_CONFIG_VALUE_IMPORT_FILES[1], + filename: resolve("src/index.ts"), code: 'import { driverOptions } from "../common/config.js";\n', - options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], }, ], invalid: [], @@ -52,25 +46,21 @@ describe("no-config-imports", () => { { filename: resolve("src/another/module.ts"), code: 'import { driverOptions } from "../common/config.js";\n', - options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], errors: [{ messageId: "noConfigImports" }], }, { filename: resolve("src/another/module.ts"), code: 'import configDefault from "../common/config.js";\n', - options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], errors: [{ messageId: "noConfigImports" }], }, { filename: resolve("src/another/module.ts"), code: 'import * as cfg from "../common/config.js";\n', - options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], errors: [{ messageId: "noConfigImports" }], }, { filename: resolve("src/another/module.ts"), code: 'import { type UserConfig, driverOptions } from "../common/config.js";\n', - options: [{ configFilePath: CONFIG_FILE_PATH, allowedFiles: ALLOWED_CONFIG_VALUE_IMPORT_FILES }], errors: [{ messageId: "noConfigImports" }], }, ], diff --git a/eslint.config.js b/eslint.config.js index 0e941929e..ce643a09c 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -11,16 +11,6 @@ const testFiles = ["tests/**/*.test.ts", "tests/**/*.ts"]; const files = [...testFiles, "src/**/*.ts", "scripts/**/*.ts"]; -// Files that are allowed to import value exports from config.ts -const allowedConfigValueImportFiles = [ - // Main entry point that injects the config - "src/index.ts", - // Config resource definition that works with the some config values - "src/resources/common/config.ts", -]; - -const configFilePath = path.resolve(import.meta.dirname, "src/common/config.js"); - export default defineConfig([ { files, plugins: { js }, extends: ["js/recommended"] }, { files, languageOptions: { globals: globals.node } }, @@ -84,13 +74,7 @@ export default defineConfig([ }, }, rules: { - "no-config-imports/no-config-imports": [ - "error", - { - configFilePath, - allowedFiles: allowedConfigValueImportFiles, - }, - ], + "no-config-imports/no-config-imports": "error", }, }, globalIgnores([