Skip to content

Commit

Permalink
Add tests making sure linter integrate with program diagnostics (#2208)
Browse files Browse the repository at this point in the history
Those tests were missing and because the rule tester runs outside of the
program flow you can't test diagnostics in there. So adding those tests
to make sure this work when integrated
  • Loading branch information
timotheeguerin authored Jul 25, 2023
1 parent 656fda2 commit 8c8ab58
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/compiler",
"comment": "",
"type": "none"
}
],
"packageName": "@typespec/compiler"
}
39 changes: 39 additions & 0 deletions packages/compiler/test/core/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,43 @@ describe("compiler: linter", () => {
expectDiagnosticEmpty(linter.lint());
});
});

describe("(integration) loading in program", () => {
async function diagnoseReal(code: string) {
const host = await createTestHost();
host.addTypeSpecFile("main.tsp", code);
host.addTypeSpecFile(
"node_modules/my-lib/package.json",
JSON.stringify({ name: "my-lib", main: "index.js" })
);
host.addJsFile("node_modules/my-lib/index.js", {
$lib: createTypeSpecLibrary({
name: "my-lib",
diagnostics: {},
linter: { rules: [noModelFoo] },
}),
});

return await host.diagnose("main.tsp", {
linterRuleSet: {
enable: { "my-lib/no-model-foo": true },
},
});
}

it("emit diagnostic when rule report", async () => {
const diagnostics = await diagnoseReal(`
model Foo {}`);

expectDiagnostics(diagnostics, { code: "my-lib/no-model-foo" });
});

it("doesn't emit diagnostic when suppressed", async () => {
const diagnostics = await diagnoseReal(`
#suppress "my-lib/no-model-foo"
model Foo {}`);

expectDiagnosticEmpty(diagnostics);
});
});
});

0 comments on commit 8c8ab58

Please sign in to comment.