1
- <h1 id =" eslint-plugin-jsdoc " >eslint-plugin-jsdoc</h1 >
1
+ <a name =" eslint-plugin-jsdoc " ></a >
2
+ # eslint-plugin-jsdoc
2
3
3
4
[ ![ NPM version] ( http://img.shields.io/npm/v/eslint-plugin-jsdoc.svg?style=flat-square )] ( https://www.npmjs.org/package/eslint-plugin-jsdoc )
4
5
[ ![ Travis build status] ( http://img.shields.io/travis/gajus/eslint-plugin-jsdoc/master.svg?style=flat-square )] ( https://travis-ci.org/gajus/eslint-plugin-jsdoc )
@@ -12,6 +13,7 @@ JSDoc linting rules for ESLint.
12
13
* [ Configuration] ( #eslint-plugin-jsdoc-configuration )
13
14
* [ Settings] ( #eslint-plugin-jsdoc-settings )
14
15
* [ Alias Preference] ( #eslint-plugin-jsdoc-settings-alias-preference )
16
+ * [ Additional Tag Names] ( #eslint-plugin-jsdoc-settings-additional-tag-names )
15
17
* [ Rules] ( #eslint-plugin-jsdoc-rules )
16
18
* [ ` check-param-names ` ] ( #eslint-plugin-jsdoc-rules-check-param-names )
17
19
* [ ` check-tag-names ` ] ( #eslint-plugin-jsdoc-rules-check-tag-names )
@@ -26,7 +28,8 @@ JSDoc linting rules for ESLint.
26
28
* [ ` require-returns-type ` ] ( #eslint-plugin-jsdoc-rules-require-returns-type )
27
29
28
30
29
- <h3 id =" eslint-plugin-jsdoc-reference-to-jscs-jsdoc " >Reference to jscs-jsdoc</h3 >
31
+ <a name =" eslint-plugin-jsdoc-reference-to-jscs-jsdoc " ></a >
32
+ ### Reference to jscs-jsdoc
30
33
31
34
This table maps the rules between ` eslint-plugin-jsdoc ` and ` jscs-jsdoc ` .
32
35
@@ -50,7 +53,8 @@ This table maps the rules between `eslint-plugin-jsdoc` and `jscs-jsdoc`.
50
53
| N/A | [ ` enforceExistence ` ] ( https://github.com/jscs-dev/jscs-jsdoc#enforceexistence ) |
51
54
| N/A | [ ` leadingUnderscoreAccess ` ] ( https://github.com/jscs-dev/jscs-jsdoc#leadingunderscoreaccess ) |
52
55
53
- <h2 id =" eslint-plugin-jsdoc-installation " >Installation</h2 >
56
+ <a name =" eslint-plugin-jsdoc-installation " ></a >
57
+ ## Installation
54
58
55
59
Install [ ESLint] ( https://www.github.com/eslint/eslint ) either locally or globally.
56
60
@@ -64,7 +68,8 @@ If you have installed `ESLint` globally, you have to install JSDoc plugin global
64
68
npm install eslint-plugin-jsdoc
65
69
```
66
70
67
- <h2 id =" eslint-plugin-jsdoc-configuration " >Configuration</h2 >
71
+ <a name =" eslint-plugin-jsdoc-configuration " ></a >
72
+ ## Configuration
68
73
69
74
Add ` plugins ` section and specify ` eslint-plugin-jsdoc ` as a plugin.
70
75
@@ -96,9 +101,11 @@ Finally, enable all of the rules that you would like to use.
96
101
}
97
102
```
98
103
99
- <h2 id =" eslint-plugin-jsdoc-settings " >Settings</h2 >
104
+ <a name =" eslint-plugin-jsdoc-settings " ></a >
105
+ ## Settings
100
106
101
- <h3 id =" eslint-plugin-jsdoc-settings-alias-preference " >Alias Preference</h3 >
107
+ <a name =" eslint-plugin-jsdoc-settings-alias-preference " ></a >
108
+ ### Alias Preference
102
109
103
110
Use ` settings.jsdoc.tagNamePreference ` to configure a preferred alias name for a JSDoc tag. The format of the configuration is: ` <primary tag name>: <preferred alias name> ` , e.g.
104
111
@@ -116,9 +123,30 @@ Use `settings.jsdoc.tagNamePreference` to configure a preferred alias name for a
116
123
}
117
124
```
118
125
119
- <h2 id =" eslint-plugin-jsdoc-rules " >Rules</h2 >
120
126
121
- <h3 id =" eslint-plugin-jsdoc-rules-check-param-names " ><code >check-param-names</code ></h3 >
127
+ <a name =" eslint-plugin-jsdoc-settings-additional-tag-names " ></a >
128
+ ### Additional Tag Names
129
+
130
+ Use ` settings.jsdoc.additionalTagNames ` to configure additional, allowed JSDoc tags. The format of the configuration is as follows:
131
+
132
+ ``` json
133
+ {
134
+ "rules" : {},
135
+ "settings" : {
136
+ "jsdoc" : {
137
+ "additionalTagNames" : {
138
+ "customTags" : [" define" , " extends" , " record" ]
139
+ }
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ <a name =" eslint-plugin-jsdoc-rules " ></a >
146
+ ## Rules
147
+
148
+ <a name =" eslint-plugin-jsdoc-rules-check-param-names " ></a >
149
+ ### <code >check-param-names</code >
122
150
123
151
Ensures that parameter names in JSDoc match those in the function declaration.
124
152
@@ -249,7 +277,8 @@ function quux ({a, b}) {
249
277
```
250
278
251
279
252
- <h4 id =" eslint-plugin-jsdoc-rules-check-param-names-deconstructing-function-parameter " >Deconstructing Function Parameter</h4 >
280
+ <a name =" eslint-plugin-jsdoc-rules-check-param-names-deconstructing-function-parameter " ></a >
281
+ #### Deconstructing Function Parameter
253
282
254
283
` eslint-plugin-jsdoc ` does not validate names of parameters in function deconstruction, e.g.
255
284
@@ -267,7 +296,8 @@ function quux ({
267
296
268
297
` {a, b} ` is an [ ` ObjectPattern ` ] ( https://github.com/estree/estree/blob/master/es6.md#objectpattern ) AST type and does not have a name. Therefore, the associated parameter in JSDoc block can have any name.
269
298
270
- <h3 id =" eslint-plugin-jsdoc-rules-check-tag-names " ><code >check-tag-names</code ></h3 >
299
+ <a name =" eslint-plugin-jsdoc-rules-check-tag-names " ></a >
300
+ ### <code >check-tag-names</code >
271
301
272
302
Reports invalid block tag names.
273
303
@@ -377,6 +407,31 @@ function quux (foo) {
377
407
378
408
}
379
409
// Message: Invalid JSDoc tag (preference). Replace "param" JSDoc tag with "arg".
410
+
411
+ /**
412
+ * @bar foo
413
+ */
414
+ function quux (foo ) {
415
+
416
+ }
417
+ // Message: Invalid JSDoc tag name "bar".
418
+
419
+ /**
420
+ * @baz @bar foo
421
+ */
422
+ function quux (foo ) {
423
+
424
+ }
425
+ // Message: Invalid JSDoc tag name "baz".
426
+
427
+ /**
428
+ * @bar
429
+ * @baz
430
+ */
431
+ function quux (foo ) {
432
+
433
+ }
434
+ // Message: Invalid JSDoc tag name "baz".
380
435
```
381
436
382
437
The following patterns are not considered problems:
@@ -395,10 +450,91 @@ function quux (foo) {
395
450
function quux (foo ) {
396
451
397
452
}
453
+
454
+ /**
455
+ * @bar foo
456
+ */
457
+ function quux (foo ) {
458
+
459
+ }
460
+
461
+ /**
462
+ * @baz @bar foo
463
+ */
464
+ function quux (foo ) {
465
+
466
+ }
467
+
468
+ /**
469
+ * @abstract
470
+ * @access
471
+ * @alias
472
+ * @augments
473
+ * @author
474
+ * @borrows
475
+ * @callback
476
+ * @class
477
+ * @classdesc
478
+ * @constant
479
+ * @constructs
480
+ * @copyright
481
+ * @default
482
+ * @deprecated
483
+ * @description
484
+ * @enum
485
+ * @event
486
+ * @example
487
+ * @exports
488
+ * @external
489
+ * @file
490
+ * @fires
491
+ * @function
492
+ * @global
493
+ * @ignore
494
+ * @implements
495
+ * @inheritdoc
496
+ * @inner
497
+ * @instance
498
+ * @interface
499
+ * @kind
500
+ * @lends
501
+ * @license
502
+ * @listens
503
+ * @member
504
+ * @memberof
505
+ * @mixes
506
+ * @mixin
507
+ * @module
508
+ * @name
509
+ * @namespace
510
+ * @override
511
+ * @param
512
+ * @private
513
+ * @property
514
+ * @protected
515
+ * @public
516
+ * @readonly
517
+ * @requires
518
+ * @returns
519
+ * @see
520
+ * @since
521
+ * @static
522
+ * @summary
523
+ * @this
524
+ * @throws
525
+ * @todo
526
+ * @tutorial
527
+ * @type
528
+ * @typedef
529
+ * @variation
530
+ * @version
531
+ */
532
+ function quux (foo ) {}
398
533
```
399
534
400
535
401
- <h3 id =" eslint-plugin-jsdoc-rules-check-types " ><code >check-types</code ></h3 >
536
+ <a name =" eslint-plugin-jsdoc-rules-check-types " ></a >
537
+ ### <code >check-types</code >
402
538
403
539
Reports invalid types.
404
540
@@ -414,6 +550,37 @@ Date
414
550
RegExp
415
551
```
416
552
553
+ <a name =" eslint-plugin-jsdoc-rules-check-types-why-not-capital-case-everything " ></a >
554
+ #### Why not capital case everything?
555
+
556
+ Why are ` boolean ` , ` number ` and ` string ` exempt from starting with a capital letter? Let's take ` string ` as an example. In Javascript, everything is an object. The string Object has prototypes for string functions such as ` .toUpperCase() ` .
557
+
558
+ Fortunately we don't have to write ` new String() ` everywhere in our code. Javascript will automatically wrap string primitives into string Objects when we're applying a string function to a string primitive. This way the memory footprint is a tiny little bit smaller, and the [ GC] ( https://en.wikipedia.org/wiki/Garbage_collection_(computer_science) ) has less work to do.
559
+
560
+ So in a sense, there two types of strings in Javascript; ` {string} ` literals, also called primitives and ` {String} ` Objects. We use the primitives because it's easier to write and uses less memory. ` {String} ` and ` {string} ` are technically both valid, but they are not the same.
561
+
562
+ ``` js
563
+ new String (' lard' ) // String {0: "l", 1: "a", 2: "r", 3: "d", length: 4}
564
+ ' lard' // "lard"
565
+ new String (' lard' ) === ' lard' // false
566
+ ```
567
+
568
+ 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.
569
+
570
+ 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} ` .
571
+
572
+ In short: It's not about consistency, rather about the 99.9% use case.
573
+
574
+ type name | ` typeof ` | check-types | testcase
575
+ --|--|--|--
576
+ ** Object** | object | ** Object** | ` ({}) instanceof Object ` -> ` true `
577
+ ** Array** | object | ** Array** | ` ([]) instanceof Array ` -> ` true `
578
+ ** Date** | object | ** Date** | ` (new Date()) instanceof Date ` -> ` true `
579
+ ** RegExp** | object | ** RegExp** | ` (new RegExp(/.+/)) instanceof RegExp ` -> ` true `
580
+ Boolean | ** boolean** | ** boolean** | ` (true) instanceof Boolean ` -> ** ` false ` **
581
+ Number | ** number** | ** number** | ` (41) instanceof Number ` -> ** ` false ` **
582
+ String | ** string** | ** string** | ` ("test") instanceof String ` -> ** ` false ` **
583
+
417
584
|||
418
585
| ---| ---|
419
586
| Context| ` ArrowFunctionExpression ` , ` FunctionDeclaration ` , ` FunctionExpression ` |
@@ -462,7 +629,8 @@ function quux (foo, bar, baz) {
462
629
```
463
630
464
631
465
- <h3 id =" eslint-plugin-jsdoc-rules-newline-after-description " ><code >newline-after-description</code ></h3 >
632
+ <a name =" eslint-plugin-jsdoc-rules-newline-after-description " ></a >
633
+ ### <code >newline-after-description</code >
466
634
467
635
Enforces a consistent padding of the block description.
468
636
@@ -542,7 +710,8 @@ function quux () {
542
710
```
543
711
544
712
545
- <h3 id =" eslint-plugin-jsdoc-rules-require-description-complete-sentence " ><code >require-description-complete-sentence</code ></h3 >
713
+ <a name =" eslint-plugin-jsdoc-rules-require-description-complete-sentence " ></a >
714
+ ### <code >require-description-complete-sentence</code >
546
715
547
716
Requires that block description and tag description are written in complete sentences, i.e.,
548
717
@@ -666,7 +835,8 @@ function quux () {
666
835
```
667
836
668
837
669
- <h3 id =" eslint-plugin-jsdoc-rules-require-hyphen-before-param-description " ><code >require-hyphen-before-param-description</code ></h3 >
838
+ <a name =" eslint-plugin-jsdoc-rules-require-hyphen-before-param-description " ></a >
839
+ ### <code >require-hyphen-before-param-description</code >
670
840
671
841
Requires a hyphen before the ` @param ` description.
672
842
@@ -699,7 +869,8 @@ function quux () {
699
869
```
700
870
701
871
702
- <h3 id =" eslint-plugin-jsdoc-rules-require-param " ><code >require-param</code ></h3 >
872
+ <a name =" eslint-plugin-jsdoc-rules-require-param " ></a >
873
+ ### <code >require-param</code >
703
874
704
875
Requires that all function parameters are documented.
705
876
@@ -746,6 +917,13 @@ function quux (foo) {
746
917
747
918
}
748
919
920
+ /**
921
+ * @inheritdoc
922
+ */
923
+ function quux (foo ) {
924
+
925
+ }
926
+
749
927
/**
750
928
* @arg foo
751
929
*/
@@ -755,7 +933,8 @@ function quux (foo) {
755
933
```
756
934
757
935
758
- <h3 id =" eslint-plugin-jsdoc-rules-require-param-description " ><code >require-param-description</code ></h3 >
936
+ <a name =" eslint-plugin-jsdoc-rules-require-param-description " ></a >
937
+ ### <code >require-param-description</code >
759
938
760
939
Requires that ` @param ` tag has ` description ` value.
761
940
@@ -803,7 +982,8 @@ function quux (foo) {
803
982
```
804
983
805
984
806
- <h3 id =" eslint-plugin-jsdoc-rules-require-param-type " ><code >require-param-type</code ></h3 >
985
+ <a name =" eslint-plugin-jsdoc-rules-require-param-type " ></a >
986
+ ### <code >require-param-type</code >
807
987
808
988
Requires that ` @param ` tag has ` type ` value.
809
989
@@ -851,7 +1031,8 @@ function quux (foo) {
851
1031
```
852
1032
853
1033
854
- <h3 id =" eslint-plugin-jsdoc-rules-require-returns-description " ><code >require-returns-description</code ></h3 >
1034
+ <a name =" eslint-plugin-jsdoc-rules-require-returns-description " ></a >
1035
+ ### <code >require-returns-description</code >
855
1036
856
1037
Requires that ` @returns ` tag has ` description ` value.
857
1038
@@ -899,7 +1080,8 @@ function quux () {
899
1080
```
900
1081
901
1082
902
- <h3 id =" eslint-plugin-jsdoc-rules-require-returns-type " ><code >require-returns-type</code ></h3 >
1083
+ <a name =" eslint-plugin-jsdoc-rules-require-returns-type " ></a >
1084
+ ### <code >require-returns-type</code >
903
1085
904
1086
Requires that ` @returns ` tag has ` type ` value.
905
1087
0 commit comments