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

Using tern for error checking? #297

Closed
rkistner opened this issue Feb 27, 2014 · 5 comments
Closed

Using tern for error checking? #297

rkistner opened this issue Feb 27, 2014 · 5 comments

Comments

@rkistner
Copy link
Contributor

Tern's type inference is amazing for auto-complete. Is it possible to use the same engine for error checking in JS?

It doesn't need to do syntax errors (which other tools such as JSHint can handle), but type errors like this:

var a = [];
var len = a.length();  // Error, since length is not a function

In the example above, Tern would know that a.length is an int, and cannot be called as a function.

I realize there could be false positives with difficult-to-detect cases whether e.g. the user defining/overriding functions/variables on prototypes. In my case I'm happy to ignore these.

Would it be possible to add functionality like this into Tern?

@marijnh
Copy link
Member

marijnh commented Feb 27, 2014

It might be possible to create a Tern-like tool that does something like this, but it is not in the current scope of the project (and it would be tricky to get any kind of useful results on top of the current engine). I think something like TypeScript is a more promising approach here.

(Closing, since I have no plans to start adding such functionality.)

@marijnh marijnh closed this as completed Feb 27, 2014
@angelozerr
Copy link
Contributor

IMHO I think validation feature is the missing feature of tern. But I understand you have no time to support it. https://github.com/eslint/eslint based on esprima parser seems doing that. It is based on esprima parser. Perhaps it's interesting to study it to provide the same version with acorn+tern?

@angelozerr
Copy link
Contributor

Jus for your information, I have created https://github.com/angelozerr/tern.lint project. It contains both tern lint plugin and CodeMirror lint addon which uses this tern lint plugin.

Any contribution are welcome!

@rkistner
Copy link
Contributor Author

@angelozerr Looks great! I'll try it out later this week.

@angelozerr
Copy link
Contributor

@rkistner pay attention, it's just a POC. Your original case with length() is not managed for instance.

Please create issues at https://github.com/angelozerr/tern.lint/issues to improve tern lint and any contribution are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants