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

CheckJS marks global variables and text in comments #26009

Closed
dbaeumer opened this issue May 5, 2017 · 5 comments
Closed

CheckJS marks global variables and text in comments #26009

dbaeumer opened this issue May 5, 2017 · 5 comments
Assignees
Labels
javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)

Comments

@dbaeumer
Copy link
Member

dbaeumer commented May 5, 2017

From @sbowler on May 4, 2017 20:2

I'm not quite sure this is the right repo for this, but here goes. Using the latest released vscode I've tried to use the new checkJs compiler option. I'm not finding any way to mark global variables in client side code like lodash as valid so they are not flagged everywhere. Even better would be automatically reading them from ESLint config files, but that's another feature.

In addition it also seems to be scanning and marking items in jsdoc style comments as invalid like
* @param {float}
"Cannot find name float"

Copied from original issue: microsoft/vscode-languageserver-node#205

@MikeyBurkman
Copy link

MikeyBurkman commented May 5, 2017

I agree with the issue with globals. We rely on Ramda as a global in most of our files, which means lots and lots of red lines everywhere. (It would be really sweet to go one step further, and actually give VSC the name of the dependency along with the global, so it could fetch the typings if they exist.)

As for the float though, well float isn't valid in JS, since there's only a single number type. If you change float to number, it'll get rid of the error.

@mjbvz mjbvz added the javascript JavaScript support issues label May 5, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented May 5, 2017

@MikeyBurkman For globals, try creating a jsconfig.json at the root of your project:

{
    "compilerOptions": {
        "checkJs": true
    },
    "typeAcquisition": {
        "include": [
            "ramda",
            "jquery"
        ]
    }
}

This tells our tooling to include 'ramda' as a global module when analyzing JavaScript files. This works great for jquery, however the ramda .d.ts file that defines ramda's interface does not actually define the R global currently. I've submitted a PR to fix this: DefinitelyTyped/DefinitelyTyped#16362

@sbowler
Copy link

sbowler commented May 6, 2017

Thanks for the information guys. Sometimes we like to use float or int so we can be more specific on the type of number we are expecting to handle even though I realize those are not valid JavaScript types so to speak. I had not seen anything about the typeAquisition option. I'll have to try that out and hopefully that will help remove a lot of the false errors.

@mjbvz mjbvz added the upstream Issue identified as 'upstream' component related (exists outside of VS Code) label May 10, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented May 10, 2017

  1. Ramda d.ts fix is merged and published to @types/ramda.

  2. I've added documentation on how to let TypeScript know about globals when using checkJS: Add section on globals and ts-check vscode-docs#991 We're also discussing how this flow can be improved: [Discussion] Better Way to Declare Globals in JavaScript files TypeScript#15626

  3. I've also opened Cannot Easily Ignore checkJS Errors in JSDocs TypeScript#15621 to track suppressing errors in jsdoc comments. Please read through that issue and share any thoughts your have on the problem

Closing as upstream

@mjbvz mjbvz closed this as completed May 10, 2017
@JeremyBYU
Copy link

I was having an issue with this and came across some other documentation that said you could declare global variable as comments in the top of the file (/* global someVar */). However when trying it, it doesnt seem to work. The documentation is here. Can't find any information for it on the official VScode docs though, which are referenced in the merge requests in this thread.

I will use the typescript definition file, but was just hoping not having to introduce it to a JavaScript only project. Thanks

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Projects
None yet
Development

No branches or pull requests

5 participants