Eslint-plugin-jsdoc: check-types should accept capitalized primitive types

Created on 31 Oct 2016  路  6Comments  路  Source: gajus/eslint-plugin-jsdoc

Eslint and this plugin conflict.
Eslint suggest that {string} should be {String}
This plugin suggests that {String} should be {string}

Jscs setting would be "checkTypes": "capitalizedNativeCase",

question

Most helpful comment

Ah I get it. {String} and {string} are technically both valid, but they are not the same.

new String('lard') === 'lard' // false

new String('lard') // String {0: "l", 1: "a", 2: "r", 3: "d", length: 4}
'lard' // "lard"

鈥婼o it's not about consistency, rather about probability of use.

type name | typeof | check-types | testcase
--|--|--|--
Object | object | Object | ({}) instanceof Object -> true
Array | object | Array | ([]) instanceof Array -> true
Date | object | Date | (new Date()) instanceof Date -> true
RegExp | object | RegExp | (new RegExp(/.+/)) instanceof RegExp -> true
Boolean | boolean | boolean | (true) instanceof Boolean -> false
Number | number | number | (41) instanceof Number -> false
String | string | string | ("test") instanceof String -> false

Confusing. But makes sense.

All 6 comments

This has been discussed a number of times, e.g. https://github.com/gajus/eslint-plugin-jsdoc/issues/22.

ESLint is wrong to recommend String. 99% of the time you mean string, e.g.

// Thats 'string'
const foo = 'FOO';

// Thats 'String'
const bar = new String('BAR');

Right, so {String} is a valid type, regardless of if its not the common case.
Could there be an option to allow for these types? Like a nativeTypes vs strictNativeTypes

It is such a rare use case that I would like to avoid adding support for it, esp. since it has the potential of being abused to wrongly document native types.

I have not seen a single valid use of a native type constructor in the past 5 years. Prove me wrong and I will add this feature.

Ah I get it. {String} and {string} are technically both valid, but they are not the same.

new String('lard') === 'lard' // false

new String('lard') // String {0: "l", 1: "a", 2: "r", 3: "d", length: 4}
'lard' // "lard"

鈥婼o it's not about consistency, rather about probability of use.

type name | typeof | check-types | testcase
--|--|--|--
Object | object | Object | ({}) instanceof Object -> true
Array | object | Array | ([]) instanceof Array -> true
Date | object | Date | (new Date()) instanceof Date -> true
RegExp | object | RegExp | (new RegExp(/.+/)) instanceof RegExp -> true
Boolean | boolean | boolean | (true) instanceof Boolean -> false
Number | number | number | (41) instanceof Number -> false
String | string | string | ("test") instanceof String -> false

Confusing. But makes sense.

@Redsandro Please contribute a variation of this to the documentation. This is the most often asked question.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ibbignerd picture ibbignerd  路  3Comments

lgaticaq picture lgaticaq  路  6Comments

hipstersmoothie picture hipstersmoothie  路  3Comments

zhaparoff picture zhaparoff  路  3Comments

tdmalone picture tdmalone  路  5Comments