Skip to content

Commit

Permalink
feat(require-jsdoc): 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 06cb22e commit 9f9f4fb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
11 changes: 9 additions & 2 deletions src/rules/requireJsdoc.js
Expand Up @@ -3,6 +3,7 @@ import iterateJsdoc from '../iterateJsdoc';
import jsdocUtils from '../jsdocUtils';
import exportParser from '../exportParser';
import getJSDocComment from '../eslint/getJSDocComment';
import warnRemovedSettings from '../warnRemovedSettings';

const OPTIONS_SCHEMA = {
additionalProperties: false,
Expand All @@ -13,6 +14,10 @@ const OPTIONS_SCHEMA = {
},
type: 'array'
},
exemptEmptyFunctions: {
default: false,
type: 'boolean'
},
publicOnly: {
oneOf: [
{
Expand Down Expand Up @@ -85,6 +90,7 @@ const getOption = (context, baseObject, option, key) => {

const getOptions = (context) => {
return {
exemptEmptyFunctions: context.options[0] ? context.options[0].exemptEmptyFunctions : false,
publicOnly: ((baseObj) => {
const publicOnly = _.get(context, 'options[0].publicOnly');
if (!publicOnly) {
Expand Down Expand Up @@ -129,7 +135,9 @@ export default iterateJsdoc(null, {
type: 'suggestion'
},
returns (context, sourceCode) {
const {require: requireOption, publicOnly} = getOptions(context);
warnRemovedSettings(context, 'require-jsdoc');

const {require: requireOption, publicOnly, exemptEmptyFunctions} = getOptions(context);

const checkJsDoc = (node) => {
const jsDocNode = getJSDocComment(sourceCode, node);
Expand All @@ -138,7 +146,6 @@ export default iterateJsdoc(null, {
return;
}

const exemptEmptyFunctions = Boolean(_.get(context, 'settings.jsdoc.exemptEmptyFunctions'));
if (exemptEmptyFunctions) {
const functionParameterNames = jsdocUtils.getFunctionParameterNames(node);
if (!functionParameterNames.length && !jsdocUtils.hasReturnValue(node, context)) {
Expand Down
53 changes: 28 additions & 25 deletions test/rules/assertions/requireJsdoc.js
Expand Up @@ -202,6 +202,19 @@ export default {
}
]
},
{
code: '',
errors: [
{
message: '`settings.jsdoc.exemptEmptyFunctions` has been removed, use options in the rule `require-jsdoc` instead.'
}
],
settings: {
jsdoc: {
exemptEmptyFunctions: true
}
}
},
{
code: `
function quux (foo) {
Expand All @@ -213,11 +226,9 @@ export default {
message: 'Missing JSDoc comment.'
}
],
settings: {
jsdoc: {
exemptEmptyFunctions: true
}
}
options: [
{exemptEmptyFunctions: true}
]
},
{
code: 'function myFunction() {}',
Expand Down Expand Up @@ -427,11 +438,9 @@ export default {
message: 'Missing JSDoc comment.',
type: 'FunctionDeclaration'
}],
settings: {
jsdoc: {
exemptEmptyFunctions: false
}
}
options: [
{exemptEmptyFunctions: false}
]
},
{
code: `
Expand All @@ -443,11 +452,9 @@ export default {
message: 'Missing JSDoc comment.',
type: 'FunctionDeclaration'
}],
settings: {
jsdoc: {
exemptEmptyFunctions: false
}
}
options: [
{exemptEmptyFunctions: false}
]
},
{
code: `
Expand Down Expand Up @@ -1383,23 +1390,19 @@ export default {
code: `
function foo () {}
`,
settings: {
jsdoc: {
exemptEmptyFunctions: true
}
}
options: [
{exemptEmptyFunctions: true}
]
},
{
code: `
function foo () {
return;
}
`,
settings: {
jsdoc: {
exemptEmptyFunctions: true
}
}
options: [
{exemptEmptyFunctions: true}
]
},
{
code: `
Expand Down

0 comments on commit 9f9f4fb

Please sign in to comment.