jscs-jsdoc
jscs-jsdoc copied to clipboard
check default values
One thing, which came to my mind while thinking about #96, is the checking of default values. The following snippet should raise an error:
/**
* Function with wrong default value
*
* @param {number} [a = 17] - This parameter has the wrong default value
* @return {number} description
*/
var test = function (a = 42) {
return a;
}
Thoughts?
Yeah, it should.
What about denying default values in docs if it exists in code?
Why do you want to disallow default values in the docs, if they exist in code? Shouldn't they then be required in the docs? I am a bit confused...
My plan introducing a new rule named checkDefaultValues which does something like:
- If there is a default value in code, the value should be marked as optional in the docs and have a default value. If this is not the case, throw an error.
- And of course the other way round, if there is a default value in the docs, there should be one in the code. If not, throw an error.
- Lastly, the default values in code and docs should be checked for equality. This is probably the most difficult part, because default values can be arbitrarily complex.
@alawatthe Yeah, it was a bad idea. You're going right, I like your plan :+1:
And of course the other way round, if there is a default value in the docs, there should be one in the code. If not, throw an error.
This one should works only in ES6+, of course. The rest is good to me.
Not sure what we decide about default mode but looks like we should pass these: https://github.com/jscs-dev/node-jscs/blob/master/lib/config/configuration.js#L167-L178
you could have each bullet point as 3 different options passed in.
one option for each bullet point. That way we can worry about the issues each one causes separably.
And so people who do not have ES6 won't have to worry about their code failing to pass.