angelozerr / tern-lint

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

New Validation: Incorrect function call #32

Open p-bakker opened 9 years ago

p-bakker commented 9 years ago

Produce a builder marker when a function is called with the incorrect number and/or type of arguments, based on the @param declarations in the JSDoc (needs to have support for optional parameters and parameters of multiple types (@param {type1|type2|type3} paramname ))

p-bakker commented 9 years ago

Sample 1:

/**
 * @param {Boolean|Number} state
 * @param {String} [text] 
 */
function test(state, text) {
}

test() //warning
test('hello') //warning
test(true, 'hello') //This one is ok
test(10, 'hello') //This one is ok
test(true, 5) //warning
test(5, 5) //warning
test(true, 'hello', 5) //warning
angelozerr commented 9 years ago

To support this issue, I need the following PR https://github.com/marijnh/tern/pull/525 to know tha type comes from comment.

angelozerr commented 9 years ago

@p-bakker tern-lint starts supporting your cases :

issue32

The only thing that I don't know how to support it is optional parameter (the first case says that test waits 2 parameters, but those parameters could be optional and I don't know how to tern support optional parameter). I must study that.