Skip to content

Commit 407d3a9

Browse files
committed
feat(require-example): move settings to options
1 parent 9f9f4fb commit 407d3a9

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

src/iterateJsdoc.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,6 @@ const getSettings = (context) => {
275275
settings.allowImplementsWithoutParam = _.get(context, 'settings.jsdoc.allowImplementsWithoutParam');
276276
settings.allowAugmentsExtendsWithoutParam = _.get(context, 'settings.jsdoc.allowAugmentsExtendsWithoutParam');
277277

278-
// `require-example` only
279-
settings.avoidExampleOnConstructors = Boolean(_.get(context, 'settings.jsdoc.avoidExampleOnConstructors'));
280-
281278
return settings;
282279
};
283280

src/rules/requireExample.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
import _ from 'lodash';
22
import iterateJsdoc from '../iterateJsdoc';
3+
import warnRemovedSettings from '../warnRemovedSettings';
34

45
export default iterateJsdoc(({
56
jsdoc,
67
report,
78
utils,
8-
settings
9+
context
910
}) => {
11+
warnRemovedSettings(context, 'require-example');
12+
1013
if (utils.avoidDocs()) {
1114
return;
1215
}
1316

17+
const options = context.options[0] || {
18+
avoidExampleOnConstructors: false
19+
};
20+
1421
const targetTagName = 'example';
1522

1623
const functionExamples = _.filter(jsdoc.tags, {
1724
tag: targetTagName
1825
});
1926

20-
if (settings.avoidExampleOnConstructors && (
27+
if (options.avoidExampleOnConstructors && (
2128
utils.hasATag([
2229
'class',
2330
'constructor'
@@ -46,6 +53,10 @@ export default iterateJsdoc(({
4653
{
4754
additionalProperties: false,
4855
properties: {
56+
avoidExampleOnConstructors: {
57+
default: false,
58+
type: 'boolean'
59+
},
4960
exemptedBy: {
5061
items: {
5162
type: 'string'

test/rules/assertions/requireExample.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ export default {
3030
}
3131
]
3232
},
33+
{
34+
code: `
35+
/**
36+
* @constructor
37+
*/
38+
function f () {
39+
40+
}
41+
`,
42+
errors: [
43+
{
44+
message: '`settings.jsdoc.avoidExampleOnConstructors` has been removed, use options in the rule `require-example` instead.'
45+
},
46+
{
47+
message: 'Missing JSDoc @example declaration.'
48+
}
49+
],
50+
settings: {
51+
jsdoc: {
52+
avoidExampleOnConstructors: true
53+
}
54+
}
55+
},
3356
{
3457
code: `
3558
/**
@@ -108,11 +131,9 @@ export default {
108131
109132
}
110133
`,
111-
settings: {
112-
jsdoc: {
113-
avoidExampleOnConstructors: true
114-
}
115-
}
134+
options: [
135+
{avoidExampleOnConstructors: true}
136+
]
116137
},
117138
{
118139
code: `
@@ -124,11 +145,9 @@ export default {
124145
125146
}
126147
`,
127-
settings: {
128-
jsdoc: {
129-
avoidExampleOnConstructors: true
130-
}
131-
}
148+
options: [
149+
{avoidExampleOnConstructors: true}
150+
]
132151
},
133152
{
134153
code: `
@@ -141,11 +160,9 @@ export default {
141160
}
142161
}
143162
`,
144-
settings: {
145-
jsdoc: {
146-
avoidExampleOnConstructors: true
147-
}
148-
}
163+
options: [
164+
{avoidExampleOnConstructors: true}
165+
]
149166
},
150167
{
151168
code: `

0 commit comments

Comments
 (0)