Skip to content

Commit 05c24d1

Browse files
committed
Merged pull request #248 from brettz9/object-default
BREAKING CHANGE: `check-types` now expects "object" instead of "Object" Makes consistent with Typescript recommendation and fact that `Object.create(null)` is not `instanceof Object` but its `typeof` is `object`. Can restore old behavior through `settings: {jsdoc: {preferredTypes: {object: 'Object'}}}}` (and `check-types` still enabled). Closes #164
1 parent ac284a2 commit 05c24d1

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

.README/rules/check-types.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ null
1010
boolean
1111
number
1212
string
13-
Object
13+
object
1414
Array
1515
Date
1616
RegExp
@@ -41,18 +41,23 @@ new String('lard') // String {0: "l", 1: "a", 2: "r", 3: "d", length: 4}
4141
new String('lard') === 'lard' // false
4242
```
4343

44-
To make things more confusing, there are also object literals and object Objects. But object literals are still static Objects and object Objects are instantiated Objects. So an object primitive is still an object Object. (`Object.create(null)` objects are not, however.)
44+
To make things more confusing, there are also object literals and object Objects. But object literals are still static Objects and object Objects are instantiated Objects. So an object primitive is still an object Object.
45+
46+
However, `Object.create(null)` objects are not `instanceof Object`, however, so
47+
in the case of this Object we lower-case to indicate possible support for
48+
these objects.
4549

4650
Basically, for primitives, we want to define the type as a primitive, because that's what we use in 99.9% of cases. For everything else, we use the type rather than the primitive. Otherwise it would all just be `{object}`.
4751

48-
In short: It's not about consistency, rather about the 99.9% use case.
52+
In short: It's not about consistency, rather about the 99.9% use case. (And some
53+
functions might not even support the objects if they are checking for identity.)
4954

5055
type name | `typeof` | check-types | testcase
5156
--|--|--|--
52-
**Object** | object | **Object** | `({}) instanceof Object` -> `true`
5357
**Array** | object | **Array** | `([]) instanceof Array` -> `true`
5458
**Date** | object | **Date** | `(new Date()) instanceof Date` -> `true`
5559
**RegExp** | object | **RegExp** | `(new RegExp(/.+/)) instanceof RegExp` -> `true`
60+
**Object** | object | **object** | `({}) instanceof Object` -> `true` but `Object.create(null) instanceof Object` -> `false`
5661
Boolean | **boolean** | **boolean** | `(true) instanceof Boolean` -> **`false`**
5762
Number | **number** | **number** | `(41) instanceof Number` -> **`false`**
5863
String | **string** | **string** | `("test") instanceof String` -> **`false`**

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ null
12481248
boolean
12491249
number
12501250
string
1251-
Object
1251+
object
12521252
Array
12531253
Date
12541254
RegExp
@@ -1281,18 +1281,23 @@ new String('lard') // String {0: "l", 1: "a", 2: "r", 3: "d", length: 4}
12811281
new String('lard') === 'lard' // false
12821282
```
12831283

1284-
To make things more confusing, there are also object literals and object Objects. But object literals are still static Objects and object Objects are instantiated Objects. So an object primitive is still an object Object. (`Object.create(null)` objects are not, however.)
1284+
To make things more confusing, there are also object literals and object Objects. But object literals are still static Objects and object Objects are instantiated Objects. So an object primitive is still an object Object.
1285+
1286+
However, `Object.create(null)` objects are not `instanceof Object`, however, so
1287+
in the case of this Object we lower-case to indicate possible support for
1288+
these objects.
12851289

12861290
Basically, for primitives, we want to define the type as a primitive, because that's what we use in 99.9% of cases. For everything else, we use the type rather than the primitive. Otherwise it would all just be `{object}`.
12871291

1288-
In short: It's not about consistency, rather about the 99.9% use case.
1292+
In short: It's not about consistency, rather about the 99.9% use case. (And some
1293+
functions might not even support the objects if they are checking for identity.)
12891294

12901295
type name | `typeof` | check-types | testcase
12911296
--|--|--|--
1292-
**Object** | object | **Object** | `({}) instanceof Object` -> `true`
12931297
**Array** | object | **Array** | `([]) instanceof Array` -> `true`
12941298
**Date** | object | **Date** | `(new Date()) instanceof Date` -> `true`
12951299
**RegExp** | object | **RegExp** | `(new RegExp(/.+/)) instanceof RegExp` -> `true`
1300+
**Object** | object | **object** | `({}) instanceof Object` -> `true` but `Object.create(null) instanceof Object` -> `false`
12961301
Boolean | **boolean** | **boolean** | `(true) instanceof Boolean` -> **`false`**
12971302
Number | **number** | **number** | `(41) instanceof Number` -> **`false`**
12981303
String | **string** | **string** | `("test") instanceof String` -> **`false`**
@@ -1375,11 +1380,11 @@ function qux(foo) {
13751380
/**
13761381
* @param {abc} foo
13771382
* @param {cde} bar
1378-
* @param {Object} baz
1383+
* @param {object} baz
13791384
*/
13801385
function qux(foo, bar, baz) {
13811386
}
1382-
// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"{{badType}}\"; prefer: \"{{preferredType}}\".","replacement":"Abc"},"cde":{"message":"More messed up JSDoc @{{tagName}}{{tagValue}} type \"{{badType}}\"; prefer: \"{{preferredType}}\".","replacement":"Cde"},"Object":"object"}}}
1387+
// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"{{badType}}\"; prefer: \"{{preferredType}}\".","replacement":"Abc"},"cde":{"message":"More messed up JSDoc @{{tagName}}{{tagValue}} type \"{{badType}}\"; prefer: \"{{preferredType}}\".","replacement":"Cde"},"object":"Object"}}}
13831388
// Message: Messed up JSDoc @param "foo" type "abc"; prefer: "Abc".
13841389

13851390
/**
@@ -1521,12 +1526,12 @@ function quux () {
15211526
// Options: [{"noDefaults":true}]
15221527

15231528
/**
1524-
* @param {object} foo
1529+
* @param {Object} foo
15251530
*/
15261531
function quux (foo) {
15271532

15281533
}
1529-
// Settings: {"jsdoc":{"preferredTypes":{"Object":"object"}}}
1534+
// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
15301535
````
15311536

15321537

src/rules/checkTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const strictNativeTypes = [
99
'number',
1010
'string',
1111
'Array',
12-
'Object',
12+
'object',
1313
'RegExp',
1414
'Date',
1515
'Function'

test/rules/assertions/checkTypes.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export default {
204204
/**
205205
* @param {abc} foo
206206
* @param {cde} bar
207-
* @param {Object} baz
207+
* @param {object} baz
208208
*/
209209
function qux(foo, bar, baz) {
210210
}
@@ -220,7 +220,7 @@ export default {
220220
},
221221
{
222222
line: 5,
223-
message: 'Invalid JSDoc @param "baz" type "Object"; prefer: "object".'
223+
message: 'Invalid JSDoc @param "baz" type "object"; prefer: "Object".'
224224
}
225225
],
226226
settings: {
@@ -234,7 +234,7 @@ export default {
234234
message: 'More messed up JSDoc @{{tagName}}{{tagValue}} type "{{badType}}"; prefer: "{{preferredType}}".',
235235
replacement: 'Cde'
236236
},
237-
Object: 'object'
237+
object: 'Object'
238238
}
239239
}
240240
}
@@ -577,7 +577,7 @@ export default {
577577
{
578578
code: `
579579
/**
580-
* @param {object} foo
580+
* @param {Object} foo
581581
*/
582582
function quux (foo) {
583583
@@ -586,7 +586,7 @@ export default {
586586
settings: {
587587
jsdoc: {
588588
preferredTypes: {
589-
Object: 'object'
589+
object: 'Object'
590590
}
591591
}
592592
}

0 commit comments

Comments
 (0)