@@ -20,6 +20,7 @@ JSDoc linting rules for ESLint.
20
20
* [ ` check-types ` ] ( #eslint-plugin-jsdoc-rules-check-types )
21
21
* [ ` newline-after-description ` ] ( #eslint-plugin-jsdoc-rules-newline-after-description )
22
22
* [ ` require-description-complete-sentence ` ] ( #eslint-plugin-jsdoc-rules-require-description-complete-sentence )
23
+ * [ ` require-example ` ] ( #eslint-plugin-jsdoc-rules-require-example )
23
24
* [ ` require-hyphen-before-param-description ` ] ( #eslint-plugin-jsdoc-rules-require-hyphen-before-param-description )
24
25
* [ ` require-param ` ] ( #eslint-plugin-jsdoc-rules-require-param )
25
26
* [ ` require-param-description ` ] ( #eslint-plugin-jsdoc-rules-require-param-description )
@@ -40,6 +41,7 @@ This table maps the rules between `eslint-plugin-jsdoc` and `jscs-jsdoc`.
40
41
| [ ` check-types ` ] ( https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-types ) | [ ` checkTypes ` ] ( https://github.com/jscs-dev/jscs-jsdoc#checktypes ) |
41
42
| [ ` newline-after-description ` ] ( https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-newline-after-description ) | [ ` requireNewlineAfterDescription ` ] ( https://github.com/jscs-dev/jscs-jsdoc#requirenewlineafterdescription ) and [ ` disallowNewlineAfterDescription ` ] ( https://github.com/jscs-dev/jscs-jsdoc#disallownewlineafterdescription ) |
42
43
| [ ` require-description-complete-sentence ` ] ( https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-description-complete-sentence ) | [ ` requireDescriptionCompleteSentence ` ] ( https://github.com/jscs-dev/jscs-jsdoc#requiredescriptioncompletesentence ) |
44
+ | [ ` require-example ` ] ( https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-example ) | N/A |
43
45
| [ ` require-hyphen-before-param-description ` ] ( https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-hyphen-before-param-description ) | [ ` requireHyphenBeforeDescription ` ] ( https://github.com/jscs-dev/jscs-jsdoc#requirehyphenbeforedescription ) |
44
46
| [ ` require-param ` ] ( https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-param ) | [ ` checkParamExistence ` ] ( https://github.com/jscs-dev/jscs-jsdoc#checkparamexistence ) |
45
47
| [ ` require-param-description ` ] ( https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-param-description ) | [ ` requireParamDescription ` ] ( https://github.com/jscs-dev/jscs-jsdoc#requireparamdescription ) |
@@ -91,6 +93,7 @@ Finally, enable all of the rules that you would like to use.
91
93
"jsdoc/check-types" : 1 ,
92
94
"jsdoc/newline-after-description" : 1 ,
93
95
"jsdoc/require-description-complete-sentence" : 1 ,
96
+ "jsdoc/require-example" : 1 ,
94
97
"jsdoc/require-hyphen-before-param-description" : 1 ,
95
98
"jsdoc/require-param" : 1 ,
96
99
"jsdoc/require-param-description" : 1 ,
@@ -835,6 +838,71 @@ function quux () {
835
838
```
836
839
837
840
841
+ <a name =" eslint-plugin-jsdoc-rules-require-example " ></a >
842
+ ### <code >require-example</code >
843
+
844
+ Requires that all functions have examples.
845
+
846
+ * All functions must have one or more ` @example ` tags.
847
+ * Every example tag must have a non-empty description that explains the method's usage.
848
+
849
+ |||
850
+ | ---| ---|
851
+ | Context| ` ArrowFunctionExpression ` , ` FunctionDeclaration ` , ` FunctionExpression ` |
852
+ | Tags| ` example ` |
853
+
854
+ The following patterns are considered problems:
855
+
856
+ ``` js
857
+ /**
858
+ *
859
+ */
860
+ function quux () {
861
+
862
+ }
863
+ // Message: Missing JSDoc @example declaration.
864
+
865
+ /**
866
+ * @example
867
+ */
868
+ function quux () {
869
+
870
+ }
871
+ // Message: Missing JSDoc @example description.
872
+ ```
873
+
874
+ The following patterns are not considered problems:
875
+
876
+ ``` js
877
+ /**
878
+ * @example
879
+ * // arbitrary example content
880
+ */
881
+ function quux () {
882
+
883
+ }
884
+
885
+ /**
886
+ * @example
887
+ * quux (); // does something useful
888
+ */
889
+ function quux () {
890
+
891
+ }
892
+
893
+ /**
894
+ * @example <caption> Valid usage </caption>
895
+ * quux (); // does something useful
896
+ *
897
+ * @example <caption> Invalid usage </caption>
898
+ * quux (' random unwanted arg' ); // results in an error
899
+ */
900
+ function quux () {
901
+
902
+ }
903
+ ```
904
+
905
+
838
906
<a name =" eslint-plugin-jsdoc-rules-require-hyphen-before-param-description " ></a >
839
907
### <code >require-hyphen-before-param-description</code >
840
908
0 commit comments