Skip to content

@ts-ignore false positive inside strings and other comments #25240

@ajafff

Description

@ajafff

TypeScript Version: 3.0.0-dev.20180621

Search Terms: ts-ignore

Code

<>
    // @ts-ignore
    {nonExistent}
</>;

`
// @ts-ignore
${nonExistent}
`;

"\
// @ts-ignore"
nonExistent;

/**
// @ts-ignore all the things */
nonExistent;

Expected behavior:

3 times Cannot find name 'nonExistent'.

Actual behavior:

No error, because the regex used to lookup the comment doesn't (and cannot reliably) check the surroundings of the comment.

To fix this, you probably need to use getTokenAtPosition and get(Leading|Trailing)CommentRanges to check if this is really a comment.

Playground Link: https://agentcooper.github.io/typescript-play/?jsx=1#code/DwPgUABFEPQxABALgZwLQEsDmA7A9gE4Cmk0A3vjgKIAeGKSROSAvmMDCANxhgAGYOIlSZchEgBIKeanQZNW-HmABEAHUHxk6bPmIqwlWvUbNlMAFQXNwnWOIQAhgBtnEJAAsi7jxhxYUCAsYQxljeTMgA

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions