Skip to content

Commit

Permalink
feat(require-example): move settings to options
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Jul 7, 2019
1 parent 9f9f4fb commit 407d3a9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
3 changes: 0 additions & 3 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,6 @@ const getSettings = (context) => {
settings.allowImplementsWithoutParam = _.get(context, 'settings.jsdoc.allowImplementsWithoutParam');
settings.allowAugmentsExtendsWithoutParam = _.get(context, 'settings.jsdoc.allowAugmentsExtendsWithoutParam');

// `require-example` only
settings.avoidExampleOnConstructors = Boolean(_.get(context, 'settings.jsdoc.avoidExampleOnConstructors'));

return settings;
};

Expand Down
15 changes: 13 additions & 2 deletions src/rules/requireExample.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import _ from 'lodash';
import iterateJsdoc from '../iterateJsdoc';
import warnRemovedSettings from '../warnRemovedSettings';

export default iterateJsdoc(({
jsdoc,
report,
utils,
settings
context
}) => {
warnRemovedSettings(context, 'require-example');

if (utils.avoidDocs()) {
return;
}

const options = context.options[0] || {
avoidExampleOnConstructors: false
};

const targetTagName = 'example';

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

if (settings.avoidExampleOnConstructors && (
if (options.avoidExampleOnConstructors && (
utils.hasATag([
'class',
'constructor'
Expand Down Expand Up @@ -46,6 +53,10 @@ export default iterateJsdoc(({
{
additionalProperties: false,
properties: {
avoidExampleOnConstructors: {
default: false,
type: 'boolean'
},
exemptedBy: {
items: {
type: 'string'
Expand Down
47 changes: 32 additions & 15 deletions test/rules/assertions/requireExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ export default {
}
]
},
{
code: `
/**
* @constructor
*/
function f () {
}
`,
errors: [
{
message: '`settings.jsdoc.avoidExampleOnConstructors` has been removed, use options in the rule `require-example` instead.'
},
{
message: 'Missing JSDoc @example declaration.'
}
],
settings: {
jsdoc: {
avoidExampleOnConstructors: true
}
}
},
{
code: `
/**
Expand Down Expand Up @@ -108,11 +131,9 @@ export default {
}
`,
settings: {
jsdoc: {
avoidExampleOnConstructors: true
}
}
options: [
{avoidExampleOnConstructors: true}
]
},
{
code: `
Expand All @@ -124,11 +145,9 @@ export default {
}
`,
settings: {
jsdoc: {
avoidExampleOnConstructors: true
}
}
options: [
{avoidExampleOnConstructors: true}
]
},
{
code: `
Expand All @@ -141,11 +160,9 @@ export default {
}
}
`,
settings: {
jsdoc: {
avoidExampleOnConstructors: true
}
}
options: [
{avoidExampleOnConstructors: true}
]
},
{
code: `
Expand Down

0 comments on commit 407d3a9

Please sign in to comment.