Skip to content

Commit

Permalink
Make it work, kinda
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Mar 5, 2024
1 parent 45960b8 commit 2fcc7fa
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/eslint-plugin/src/rules/expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand All @@ -168,18 +168,18 @@ function getSettings(context: Parameters<(typeof rule)["create"]>[0]): Settings
}
}

const extraTsconfigs = (dt as Record<string, unknown>).extraTsconfigs ?? undefined;
if (extraTsconfigs !== undefined && !Array.isArray(extraTsconfigs)) {
throw new Error("Invalid extraTsconfigs");
const tsconfigs = (dt as Record<string, unknown>).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<ts.Program, Map<VersionAndTsconfig, ts.Program>>();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
types/expect-tsconfigs/expect-tests.ts
4:16 error [email protected]: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: [email protected]:tsconfig.no-dom.json compile error:
!!! : Cannot find name 'HTMLElement'.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
types/expect-tsconfigs/index.d.ts
1:23 error [email protected]: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: [email protected]:tsconfig.no-dom.json compile error:
!!! : Cannot find name 'HTMLElement'.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"settings": {
"dt": {
"versionsToTest": [{ "versionName": "x.y", "path": "typescript" }],
"tsconfigs": ["tsconfig.dom.json", "tsconfig.no-dom.json"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line @definitelytyped/no-relative-import-in-test
import * as expect from "./";

const element: HTMLElement = expect.element;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line @definitelytyped/no-relative-import-in-test
import * as expect from "./";

const element: HTMLElement = expect.element;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const element: HTMLElement;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@types/expect",
"version": "2.0.9999",
"owners": []
}
Original file line number Diff line number Diff line change
@@ -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"
]
}
Original file line number Diff line number Diff line change
@@ -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"
]
}
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit 2fcc7fa

Please sign in to comment.