Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playground: incorrect type causing false negatives #4493

Closed
bradzacher opened this issue Jan 29, 2022 · 4 comments · Fixed by #4765
Closed

Playground: incorrect type causing false negatives #4493

bradzacher opened this issue Jan 29, 2022 · 4 comments · Fixed by #4765
Assignees
Labels
bug Something isn't working has pr there is a PR raised to close this package: website Issues related to the @typescript-eslint website

Comments

@bradzacher
Copy link
Member

/* eslint "@typescript-eslint/prefer-readonly-parameter-types": "error" */

function foo(arg: string[]) {}

playground link

This should error because the array is mutable. But it doesn't.

Debugging a bit - for some reason the type of arg is {}.
Maybe there's a config issue somewhere?

cc @armano2

@bradzacher bradzacher added bug Something isn't working package: website Issues related to the @typescript-eslint website labels Jan 29, 2022
@lonyele
Copy link
Contributor

lonyele commented Feb 17, 2022

I was trying to figure out the problem that the playground can't reproduce the bugs such as #4554, this issue, or others I've seen.

For issue #4554's case
This is the official playground. It doesn't reproduce error because that symAtLocation doesn't have declarations(unresolved) and the flow doesn't go to this rules's actual logic part because typeParamters is undefined

const typeParameters = getTypeParametersFromNode(expression, checker);
if (typeParameters) {
checkTSArgsAndParameters(node, typeParameters);

스크린샷 2022-02-17 오후 2 04 36

I went to the commit before #4555 is merged and tested locally and it reproduces as expected. Because symAtLocation has declarations and it goes further down the code and errors it. I didn't actually test it but probably the code after #4555 merged will fix this case and does not produce error(real fix)
스크린샷 2022-02-17 오후 1 51 37

This is the same commit before #4555 is merged and it is the local website's localhost. It's the same result as the official playground.
스크린샷 2022-02-17 오후 1 55 15

I initially thought maybe the latest version was not used at playground by looking issue #4554 that upgraded 5.12.0 produces error locally and published npm but not on the playground(maybe version before this commit is used chore: publish v5.12.0

But It seems like latest ts-eslint versions are always used on website by hard copying dist/index.js from website-eslint and it actually is the same by comparing them on local file and localhost's source file.

To sum up, same code but playground's linting and local repo's linting are different

My guess now... is that usage of linter is somewhat wrong? 'tsWorker' or somewhere https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/website-eslint/src/linter/parser.js I don't know just maybe totally something else. I tried it for few days and it's all I've found. Maybe someone can help or guess what can be the cause.

@bradzacher
Copy link
Member Author

The issue is that for some reason the program that is created for the lint process does not include the TS lib defs, even though the monaco TS instance does.

For example here is a playground I created for #4553 (comment).

You'll notice that if you delete all of the definitions below the #region comment, all the rule reports will disappear.
In a nutshell - in order to create a repro I manually copied the relevant lib defs into the playground.

@bradzacher bradzacher added the accepting prs Go ahead, send a pull request that resolves this issue label Feb 17, 2022
@lonyele
Copy link
Contributor

lonyele commented Feb 22, 2022

Just in case, please tackle this problem if you want because I'm out... I tried tweaking some part where lint was created or sandboxInstance or tried setting up with tsvfs but failed to find the solution... Fix can be easy.. or maybe not. I feel like #4414 is also highly related. good luck

@armano2
Copy link
Member

armano2 commented Mar 30, 2022

Just in case, please tackle this problem if you want because I'm out... I tried tweaking some part where lint was created or sandboxInstance or tried setting up with tsvfs but failed to find the solution... Fix can be easy.. or maybe not. I feel like #4414 is also highly related. good luck

sadly no, #4414 is unrelated to this one, and has to be handled in different part of code,

currently we have 2 additional issues:

  1. we are missing some options for editor, eg. downlevelIteration (easy fix by just adding it to json)
  2. compiler options are not passed / updated in typescript program used for eslint (this is a little harder to fix)

@lonyele as for loading libs, all what we have to do is load them from cdn (or cache - localStorage) and add them to program, you can see how this can be done in #4765

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: website Issues related to the @typescript-eslint website
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants