diff --git a/packages/eslint-plugin/src/rules/expect.ts b/packages/eslint-plugin/src/rules/expect.ts index 48a83ca8db..7053bf73f3 100644 --- a/packages/eslint-plugin/src/rules/expect.ts +++ b/packages/eslint-plugin/src/rules/expect.ts @@ -69,10 +69,10 @@ Then re-run.`, reportDiagnostics = false; } - const tsconfigs = ["tsconfig.json"]; + let tsconfigs: readonly string[] = ["tsconfig.json"]; let reportTsconfigName = false; - if (settings.extraTsconfigs) { - tsconfigs.push(...settings.extraTsconfigs); + if (settings.tsconfigs) { + tsconfigs = settings.tsconfigs; reportTsconfigName = true; } @@ -148,7 +148,7 @@ interface VersionToTest { interface Settings { readonly versionsToTest?: readonly VersionToTest[]; - readonly extraTsconfigs?: readonly string[]; + readonly tsconfigs?: readonly string[]; } function getSettings(context: Parameters<(typeof rule)["create"]>[0]): Settings { @@ -168,18 +168,18 @@ function getSettings(context: Parameters<(typeof rule)["create"]>[0]): Settings } } - const extraTsconfigs = (dt as Record).extraTsconfigs ?? undefined; - if (extraTsconfigs !== undefined && !Array.isArray(extraTsconfigs)) { - throw new Error("Invalid extraTsconfigs"); + const tsconfigs = (dt as Record).tsconfigs ?? undefined; + if (tsconfigs !== undefined && !Array.isArray(tsconfigs)) { + throw new Error("Invalid tsconfigs"); } - for (const tsconfig of extraTsconfigs ?? []) { + for (const tsconfig of tsconfigs ?? []) { if (typeof tsconfig !== "string") { throw new Error("Invalid extra tsconfig"); } } - return { versionsToTest, extraTsconfigs }; + return { versionsToTest, tsconfigs }; } const programCache = new WeakMap>(); diff --git a/packages/eslint-plugin/test/__file_snapshots__/types/expect-tsconfigs/expect-dom-tests.ts.lint b/packages/eslint-plugin/test/__file_snapshots__/types/expect-tsconfigs/expect-dom-tests.ts.lint new file mode 100644 index 0000000000..e49f35d410 --- /dev/null +++ b/packages/eslint-plugin/test/__file_snapshots__/types/expect-tsconfigs/expect-dom-tests.ts.lint @@ -0,0 +1,8 @@ +No errors + +==== types/expect-tsconfigs/expect-dom-tests.ts ==== + + // eslint-disable-next-line @definitelytyped/no-relative-import-in-test + import * as expect from "./"; + + const element: HTMLElement = expect.element; diff --git a/packages/eslint-plugin/test/__file_snapshots__/types/expect-tsconfigs/expect-tests.ts.lint b/packages/eslint-plugin/test/__file_snapshots__/types/expect-tsconfigs/expect-tests.ts.lint new file mode 100644 index 0000000000..195d4a9a38 --- /dev/null +++ b/packages/eslint-plugin/test/__file_snapshots__/types/expect-tsconfigs/expect-tests.ts.lint @@ -0,0 +1,15 @@ +types/expect-tsconfigs/expect-tests.ts + 4:16 error TypeScript@x.y:tsconfig.no-dom.json compile error: +Cannot find name 'HTMLElement' @definitelytyped/expect + +✖ 1 problem (1 error, 0 warnings) + +==== types/expect-tsconfigs/expect-tests.ts ==== + + // eslint-disable-next-line @definitelytyped/no-relative-import-in-test + import * as expect from "./"; + + const element: HTMLElement = expect.element; + ~~~~~~~~~~~ +!!! @definitelytyped/expect: TypeScript@x.y:tsconfig.no-dom.json compile error: +!!! : Cannot find name 'HTMLElement'. diff --git a/packages/eslint-plugin/test/__file_snapshots__/types/expect-tsconfigs/index.d.ts.lint b/packages/eslint-plugin/test/__file_snapshots__/types/expect-tsconfigs/index.d.ts.lint new file mode 100644 index 0000000000..7737511a5d --- /dev/null +++ b/packages/eslint-plugin/test/__file_snapshots__/types/expect-tsconfigs/index.d.ts.lint @@ -0,0 +1,12 @@ +types/expect-tsconfigs/index.d.ts + 1:23 error TypeScript@x.y:tsconfig.no-dom.json compile error: +Cannot find name 'HTMLElement' @definitelytyped/expect + +✖ 1 problem (1 error, 0 warnings) + +==== types/expect-tsconfigs/index.d.ts ==== + + export const element: HTMLElement; + ~~~~~~~~~~~ +!!! @definitelytyped/expect: TypeScript@x.y:tsconfig.no-dom.json compile error: +!!! : Cannot find name 'HTMLElement'. diff --git a/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/.eslintrc.json b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/.eslintrc.json new file mode 100644 index 0000000000..46231e2614 --- /dev/null +++ b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/.eslintrc.json @@ -0,0 +1,8 @@ +{ + "settings": { + "dt": { + "versionsToTest": [{ "versionName": "x.y", "path": "typescript" }], + "tsconfigs": ["tsconfig.dom.json", "tsconfig.no-dom.json"] + } + } +} diff --git a/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/expect-dom-tests.ts b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/expect-dom-tests.ts new file mode 100644 index 0000000000..151b93d909 --- /dev/null +++ b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/expect-dom-tests.ts @@ -0,0 +1,4 @@ +// eslint-disable-next-line @definitelytyped/no-relative-import-in-test +import * as expect from "./"; + +const element: HTMLElement = expect.element; diff --git a/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/expect-tests.ts b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/expect-tests.ts new file mode 100644 index 0000000000..151b93d909 --- /dev/null +++ b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/expect-tests.ts @@ -0,0 +1,4 @@ +// eslint-disable-next-line @definitelytyped/no-relative-import-in-test +import * as expect from "./"; + +const element: HTMLElement = expect.element; diff --git a/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/index.d.ts b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/index.d.ts new file mode 100644 index 0000000000..d5643da83d --- /dev/null +++ b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/index.d.ts @@ -0,0 +1 @@ +export const element: HTMLElement; diff --git a/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/package.json b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/package.json new file mode 100644 index 0000000000..0c26dbf768 --- /dev/null +++ b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/package.json @@ -0,0 +1,5 @@ +{ + "name": "@types/expect", + "version": "2.0.9999", + "owners": [] +} diff --git a/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/tsconfig.dom.json b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/tsconfig.dom.json new file mode 100644 index 0000000000..c89832eae5 --- /dev/null +++ b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/tsconfig.dom.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "expect-dom-tests.ts" + ] +} diff --git a/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/tsconfig.json b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/tsconfig.json new file mode 100644 index 0000000000..a2f256cde2 --- /dev/null +++ b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "expect-tests.ts", + "expect-dom-tests.ts" + ] +} diff --git a/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/tsconfig.no-dom.json b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/tsconfig.no-dom.json new file mode 100644 index 0000000000..e5dfa2b823 --- /dev/null +++ b/packages/eslint-plugin/test/fixtures/types/expect-tsconfigs/tsconfig.no-dom.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "expect-tests.ts" + ] +}