Skip to content

Commit

Permalink
Reinstate glint-expect-error (and other directives) for tsc and TS Pl…
Browse files Browse the repository at this point in the history
…ugin using Vue's approach (#799)
  • Loading branch information
machty authored Mar 3, 2025
1 parent 0e0d936 commit 469c15e
Show file tree
Hide file tree
Showing 17 changed files with 1,695 additions and 788 deletions.
16 changes: 13 additions & 3 deletions packages/core/__tests__/cli/build-watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('CLI: watched build mode typechecking', () => {
await watch.terminate();
});

test.skip('reports on errors introduced after removing a glint-nocheck directive', async () => {
test('reports on errors introduced after removing a glint-nocheck directive', async () => {
let code = stripIndent`
import '@glint/environment-ember-template-imports';
import Component from '@glimmer/component';
Expand Down Expand Up @@ -460,7 +460,12 @@ describe('CLI: watched build mode typechecking', () => {
stripped.indexOf('index.gts'),
stripped.lastIndexOf(`~~~${os.EOL}`) + 3,
);
expect(error).toMatchInlineSnapshot(`""`);
expect(error).toMatchInlineSnapshot(`
"index.gts:15:5 - error TS2554: Expected 0 arguments, but got 1.
15 <A @foo="bar" />
~~~~~~~~~~~~~~~~"
`);

await pauseForTSBuffering();

Expand Down Expand Up @@ -488,7 +493,12 @@ describe('CLI: watched build mode typechecking', () => {
stripped.indexOf('index.gts'),
stripped.lastIndexOf(`~~~${os.EOL}`) + 3,
);
expect(error).toMatchInlineSnapshot(`""`);
expect(error).toMatchInlineSnapshot(`
"index.gts:3:28 - error TS2554: Expected 0 arguments, but got 1.
3 const A = <template>Hello! <C @foo="bar" /></template>;
~~~~~~~~~~~~~~~~"
`);

await pauseForTSBuffering();

Expand Down
2 changes: 1 addition & 1 deletion packages/core/__tests__/cli/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ describe('CLI: single-pass build mode typechecking', () => {
});
});

describe.skip('for a type error covered by `@glint-nocheck`', () => {
describe('for a type error covered by `@glint-nocheck`', () => {
beforeEach(async () => {
let aCode = stripIndent`
import C from '@glint-test/c';
Expand Down
110 changes: 110 additions & 0 deletions packages/core/__tests__/cli/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,116 @@ describe('CLI: single-pass typechecking', () => {
`);
});

test('ignores @glint-ignored errors', async () => {
let code = stripIndent`
import Component from '@glimmer/component';
type ApplicationArgs = {
version: string;
};
export default class Application extends Component<{ Args: ApplicationArgs }> {
private startupTime = new Date().toISOString();
<template>
Welcome to app v{{@version}}.
{{! @glint-ignore 'unknown property' }}
The current time is {{this.startupTimeError}}.
{{! @glint-ignore 'if this were expect-error this would be an unused expect-error' }}
The current time is {{this.startupTime}}.
</template>
}
`;

project.write('index.gts', code);

let checkResult = await project.check({ reject: false });

expect(checkResult.exitCode).toBe(0);

expect(stripAnsi(checkResult.stdout)).toMatchInlineSnapshot(`
""
`);
});

test('reports unused @glint-expect-error', async () => {
let code = stripIndent`
import Component from '@glimmer/component';
type ApplicationArgs = {
version: string;
};
export default class Application extends Component<{ Args: ApplicationArgs }> {
private startupTime = new Date().toISOString();
<template>
Welcome to app v{{@version}}.
{{! @glint-expect-error 'no error here' }}
The current time is {{this.startupTime}}.
</template>
}
`;

project.write('index.gts', code);

let checkResult = await project.check({ reject: false });

expect(checkResult.exitCode).not.toBe(0);

expect(stripAnsi(checkResult.stdout)).toMatchInlineSnapshot(`
"index.gts:12:5 - error TS2578: Unused '@ts-expect-error' directive.
12 {{! @glint-expect-error 'no error here' }}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error in index.gts:12
"
`);
});

test('does not report errors skipped by @glint-expect-error', async () => {
let code = stripIndent`
import Component from '@glimmer/component';
type ApplicationArgs = {
version: string;
};
export default class Application extends Component<{ Args: ApplicationArgs }> {
private startupTime = new Date().toISOString();
<template>
Welcome to app v{{@version}}.
{{! @glint-expect-error 'skipping this error' }}
The current time is {{this.startupTimee}}.
{{this.otherError}}
</template>
}
`;

project.write('index.gts', code);

let checkResult = await project.check({ reject: false });

expect(checkResult.exitCode).not.toBe(0);

expect(stripAnsi(checkResult.stdout)).toMatchInlineSnapshot(`
"index.gts:15:12 - error TS2339: Property 'otherError' does not exist on type 'Application'.
15 {{this.otherError}}
~~~~~~~~~~
Found 1 error in index.gts:15
"
`);
});

test.skip('reports diagnostics for a companion template type error', async () => {
project.setGlintConfig({ environment: 'ember-loose' });

Expand Down
Loading

0 comments on commit 469c15e

Please sign in to comment.