Skip to content

Commit

Permalink
fix(rosetta): diagnostics from infused snippets were not ignored (#3282)
Browse files Browse the repository at this point in the history
Recently we implemented the `infused` metadata that turns `strict=false`
and `loose=true` for the specific snippet. However we still output the
diagnostics along with other snippets (with `isError=true`). One thing we
could do is make these diagnostics `isError=false`, but I argue that we
want to ignore these diagnostics entirely. They aren't actually diagnostics;
we will find them in the cache and they do compile.

---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
kaizencc authored Dec 23, 2021
1 parent 2c8c647 commit ad7f6a4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/jsii-rosetta/lib/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export class Translator {
}),
);

this.#diagnostics.push(...translator.diagnostics);
if (snip.parameters?.infused === undefined) {
this.#diagnostics.push(...translator.diagnostics);
}

return TranslatedSnippet.fromSchema({
translations: {
Expand Down
43 changes: 40 additions & 3 deletions packages/jsii-rosetta/test/commands/extract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ test('infused examples skip loose mode', async () => {
try {
const cacheToFile = path.join(otherAssembly.moduleDirectory, 'test.tabl.json');

// Without exampleMetadata infused=true, expect an error
// Without exampleMetadata infused, expect an error
await expect(
extract.extractSnippets([otherAssembly.moduleDirectory], {
cacheToFile,
Expand All @@ -465,8 +465,7 @@ test('infused examples skip loose mode', async () => {
).rejects.toThrowError(/Sample uses literate source/);

// Add infused=true to metadata and update assembly
otherAssembly.assembly.types!['my_assembly.ClassA'].docs!.custom!.exampleMetadata =
'lit=integ.test.ts infused=true';
otherAssembly.assembly.types!['my_assembly.ClassA'].docs!.custom!.exampleMetadata = 'lit=integ.test.ts infused';
await otherAssembly.updateAssembly();

// Expect same function call to succeed now
Expand All @@ -484,6 +483,44 @@ test('infused examples skip loose mode', async () => {
}
});

test('infused examples have no diagnostics', async () => {
const otherAssembly = await TestJsiiModule.fromSource(
{
'index.ts': `
/**
* ClassA
*
* @exampleMetadata infused
* @example x
*/
export class ClassA {
public someMethod() {
}
}
`,
},
{
name: 'my_assembly',
jsii: {
...DUMMY_JSII_CONFIG,
},
},
);
try {
const cacheToFile = path.join(otherAssembly.moduleDirectory, 'test.tabl.json');

const results = await extract.extractSnippets([otherAssembly.moduleDirectory], {
cacheToFile,
includeCompilerDiagnostics: true,
loose: false,
});

expect(results.diagnostics).toEqual([]);
} finally {
await otherAssembly.cleanup();
}
});

class MockTranslator extends RosettaTranslator {
public constructor(opts: RosettaTranslatorOptions, translatorFn: jest.Mock) {
super(opts);
Expand Down

0 comments on commit ad7f6a4

Please sign in to comment.