@@ -14,6 +14,7 @@ This table maps the rules between `eslint-plugin-jsdoc` and `jscs-jsdoc`.
14
14
15
15
| ` eslint-plugin-jsdoc ` | ` jscs-jsdoc ` |
16
16
| --- | --- |
17
+ | [ ` check-examples ` ] ( https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-examples ) | N/A |
17
18
| [ ` check-param-names ` ] ( https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-param-names ) | [ ` checkParamNames ` ] ( https://github.com/jscs-dev/jscs-jsdoc#checkparamnames ) |
18
19
| [ ` check-tag-names ` ] ( https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-tag-names ) | N/A ~ [ ` checkAnnotations ` ] ( https://github.com/jscs-dev/jscs-jsdoc#checkannotations ) |
19
20
| [ ` check-types ` ] ( https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-types ) | [ ` checkTypes ` ] ( https://github.com/jscs-dev/jscs-jsdoc#checktypes ) |
@@ -68,6 +69,7 @@ Finally, enable all of the rules that you would like to use.
68
69
``` json
69
70
{
70
71
"rules" : {
72
+ "jsdoc/check-examples" : 1 ,
71
73
"jsdoc/check-param-names" : 1 ,
72
74
"jsdoc/check-tag-names" : 1 ,
73
75
"jsdoc/check-types" : 1 ,
@@ -108,7 +110,6 @@ Use `settings.jsdoc.tagNamePreference` to configure a preferred alias name for a
108
110
}
109
111
```
110
112
111
-
112
113
### Additional Tag Names
113
114
114
115
Use ` settings.jsdoc.additionalTagNames ` to configure additional, allowed JSDoc tags. The format of the configuration is as follows:
@@ -154,8 +155,83 @@ The format of the configuration is as follows:
154
155
}
155
156
```
156
157
158
+ ### Settings to Configure ` check-examples `
159
+
160
+ The settings below all impact the ` check-examples ` rule and default to
161
+ no-op/false except for ` eslintrcForExamples ` which defaults to ` true ` .
162
+
163
+ JSDoc specs use of an optional ` <caption> ` element at the beginning of
164
+ ` @example ` . The following setting requires its use.
165
+
166
+ * ` settings.jsdoc.captionRequired ` - Require ` <caption> ` at beginning
167
+ of any ` @example `
168
+
169
+ JSDoc does not specify a formal means for delimiting code blocks within
170
+ ` @example ` (it uses generic syntax highlighting techniques for its own
171
+ syntax highlighting). The following settings determine whether a given
172
+ ` @example ` tag will have the ` check-examples ` checks applied to it:
173
+
174
+ * ` settings.jsdoc.exampleCodeRegex ` - Regex which whitelists lintable
175
+ examples. If a parenthetical group is used, the first one will be used,
176
+ so you may wish to use ` (?:...) ` groups where you do not wish the
177
+ first such group treated as one to include. If no parenthetical group
178
+ exists or matches, the whole matching expression will be used.
179
+ An example might be ```` "^```(?:js|javascript)([\\s\\S]*)```$" ````
180
+ to only match explicitly fenced JavaScript blocks.
181
+ * ` settings.jsdoc.rejectExampleCodeRegex ` - Regex blacklist which rejects
182
+ non-lintable examples (has priority over ` exampleCodeRegex ` ). An example
183
+ might be ``` "^`" ``` to avoid linting fenced blocks which may indicate
184
+ a non-JavaScript language.
185
+
186
+ If neither is in use, all examples will be matched. Note also that even if
187
+ ` settings.jsdoc.captionRequired ` is not set, any initial ` <caption> `
188
+ will be stripped out before doing the regex matching.
189
+
190
+ The following settings determine which individual ESLint rules will be
191
+ applied to the JavaScript found within the ` @example ` tags (as determined
192
+ to be applicable by the above regex settings). They are ordered by
193
+ decreasing precedence:
194
+
195
+ * ` settings.jsdoc.noDefaultExampleRules ` - Setting to ` true ` will disable the
196
+ default rules which are expected to be troublesome for most documentation
197
+ use. See the section below for the specific default rules.
198
+ * ` settings.jsdoc.matchingFileName ` - Setting for a dummy file name to trigger
199
+ specific rules defined in one's config; usable with ESLint ` .eslintrc.* `
200
+ ` overrides ` -> ` files ` globs, to apply a desired subset of rules with
201
+ ` @example ` (besides allowing for rules specific to examples, this setting
202
+ can be useful for enabling reuse of the same rules within ` @example ` as
203
+ with JavaScript Markdown lintable by
204
+ [ other plugins] ( https://github.com/eslint/eslint-plugin-markdown ) , e.g.,
205
+ if one sets ` matchingFileName ` to ` dummy.md ` so that ` @example ` rules will
206
+ follow one's Markdown rules).
207
+ * ` settings.jsdoc.configFile ` - A config file. Corresponds to ` -c ` .
208
+ * ` settings.jsdoc.eslintrcForExamples ` - Defaults to ` true ` in adding rules
209
+ based on an ` .eslintrc.* ` file. Setting to ` false ` corresponds to
210
+ ` --no-eslintrc ` .
211
+ * ` settings.jsdoc.baseConfig ` - An object of rules with the same schema
212
+ as ` .eslintrc.* ` for defaults
213
+
214
+ #### Rules Disabled by Default Unless ` noDefaultExampleRules ` is Set to ` true `
215
+
216
+ * ` eol-last ` - Insisting that a newline "always" be at the end is less likely
217
+ to be desired in sample code as with the code file convention
218
+ * ` no-console ` - Unlikely to have inadvertent temporary debugging within
219
+ examples
220
+ * ` no-undef ` - Many variables in examples will be ` undefined ` .
221
+ * ` no-unused-vars ` - It is common to define variables for clarity without always
222
+ using them within examples.
223
+ * ` padded-blocks ` - It can generally look nicer to pad a little even if one's
224
+ code follows more stringency as far as block padding.
225
+ * ` import/no-unresolved ` - One wouldn't generally expect example paths to
226
+ resolve relative to the current JavaScript file as one would with real code.
227
+ * ` import/unambiguous ` - Snippets in examples are likely too short to always
228
+ include full import/export info
229
+ * ` node/no-missing-import ` - See ` import/no-unresolved `
230
+ * ` node/no-missing-require ` - See ` import/no-unresolved `
231
+
157
232
## Rules
158
233
234
+ {"gitdown": "include", "file": "./rules/check-examples.md"}
159
235
{"gitdown": "include", "file": "./rules/check-param-names.md"}
160
236
{"gitdown": "include", "file": "./rules/check-tag-names.md"}
161
237
{"gitdown": "include", "file": "./rules/check-types.md"}
0 commit comments