angelozerr / tern-lint

Tern plugin to validate JavaScripts files to collect semantic errors
http://ternjs.net/
MIT License
62 stars 13 forks source link

Support AngularJS Dependency Injection (multiple signatures) #39

Closed KylePDavis closed 9 years ago

KylePDavis commented 9 years ago

When using both the lint and the angular plugins for ternjs and using strict dependency injection I get warnings about invalid parameters.

Example code:

angular
.module("app.greeting", [
  // module deps
])
.directive("helloWorld",
[ // deps as strings go here    <=====  linter complains here
function(/*deps as local params*/) {
}]
.

I get the following linter warning:

Invalid argument at 2: cannot convert from Array.prototype to Function.prototype

Not sure if this is an issue with the angular plugin or the lint plugin or both. I found the tern type info in the angular plugin here:

It would be nice if we could figure out a way to make functions with more than one signature work properly though.

I can't really use the lint plugin for any of my large projects until this works.

angelozerr commented 9 years ago

@KylePDavis I understand your problem.

At first I have forked tern angular from marijnh/tern : tern/plugin/angular.js #L405 for AngularJS Eclipse https://github.com/angelozerr/angularjs-eclipse to improve it and to get list of directives, controller. See https://github.com/angelozerr/angularjs-eclipse/wiki/Angular-Explorer-View

Your problem is because tern doesn't provide the capability to declare several type for the same function. I think to resolve this problem a custom !lint should be developped for angular. It was in my scope to do that. I must just find time to do that.

KylePDavis commented 9 years ago

@angelozerr, thanks for the additional information (and confirmation about typing in marijnh/tern). I just wanted to make sure that the issue was reported.

I think I can workaround most of this for now by removing the DI Arrays from my source code and add a build step to put them back before minification / mangling.

angelozerr commented 9 years ago

@KylePDavis I'm workinh on again about my fork of tern angular. I have created the project at https://github.com/angelozerr/tern-angularjs and I'm writing tests (I would like to have a lot of tests).

I think your lint problem is not difficult to fix it. It should be really cool if you could create an issues per problem (with a sample) at https://github.com/angelozerr/tern-angularjs

I will fix it. After that you will able to copy/paste https://github.com/angelozerr/tern-angularjs/blob/master/angular.js in your tern/plugin/angular.js

I have the attention to contribute to official tern plugin with my fork.

angelozerr commented 9 years ago

@KylePDavis fix was very easy https://github.com/angelozerr/tern-angularjs/commit/2d638d39e698e605b25c097539678fc94aad6456#diff-682a0dacb1474ac05ce433b2e5af0aafR1250 (multi parameter)