Skip to content

Commit

Permalink
- Enhancement: Add new boolean options allowImplementsWithoutParam
Browse files Browse the repository at this point in the history
…and `allowAugmentsExtendsWithoutParam` and apply to `requireParam` (fixes gajus#100)
  • Loading branch information
brettz9 committed Dec 7, 2018
1 parent 559b287 commit 8d16526
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import _ from 'lodash';
import commentParser from 'comment-parser';
import jsdocUtils from './jsdocUtils';

const curryUtils = (functionNode, jsdoc, tagNamePreference, additionalTagNames, allowOverrideWithoutParam) => {
const curryUtils = (
functionNode, jsdoc, tagNamePreference, additionalTagNames,
allowOverrideWithoutParam, allowImplementsWithoutParam,
allowAugmentsExtendsWithoutParam
) => {
const utils = {};

utils.getFunctionParameterNames = () => {
Expand Down Expand Up @@ -33,6 +37,14 @@ const curryUtils = (functionNode, jsdoc, tagNamePreference, additionalTagNames,
return allowOverrideWithoutParam;
};

utils.isImplementsAllowedWithoutParam = () => {
return allowImplementsWithoutParam;
};

utils.isAugmentsExtendsAllowedWithoutParam = () => {
return allowAugmentsExtendsWithoutParam;
};

return utils;
};

Expand Down Expand Up @@ -61,6 +73,8 @@ export default (iterator) => {
const tagNamePreference = _.get(context, 'settings.jsdoc.tagNamePreference') || {};
const additionalTagNames = _.get(context, 'settings.jsdoc.additionalTagNames') || {};
const allowOverrideWithoutParam = Boolean(_.get(context, 'settings.jsdoc.allowOverrideWithoutParam'));
const allowImplementsWithoutParam = Boolean(_.get(context, 'settings.jsdoc.allowImplementsWithoutParam'));
const allowAugmentsExtendsWithoutParam = Boolean(_.get(context, 'settings.jsdoc.allowAugmentsExtendsWithoutParam'));

const checkJsdoc = (functionNode) => {
const jsdocNode = sourceCode.getJSDocComment(functionNode);
Expand Down Expand Up @@ -100,7 +114,11 @@ export default (iterator) => {
}
};

const utils = curryUtils(functionNode, jsdoc, tagNamePreference, additionalTagNames, allowOverrideWithoutParam);
const utils = curryUtils(
functionNode, jsdoc, tagNamePreference, additionalTagNames,
allowOverrideWithoutParam, allowImplementsWithoutParam,
allowAugmentsExtendsWithoutParam
);

iterator({
context,
Expand Down
12 changes: 12 additions & 0 deletions src/rules/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ export default iterateJsdoc(({
return;
}

// When settings.jsdoc.allowImplementsWithoutParam is true, implements implies that all documentation is inherited.
// See https://github.com/gajus/eslint-plugin-jsdoc/issues/100
if (utils.hasTag('implements') && utils.isImplementsAllowedWithoutParam()) {
return;
}

// When settings.jsdoc.allowAugmentsExtendsWithoutParam is true, augments or extends implies that all documentation is inherited.
// See https://github.com/gajus/eslint-plugin-jsdoc/issues/100
if ((utils.hasTag('augments') || utils.hasTag('extends')) && utils.isAugmentsExtendsAllowedWithoutParam()) {
return;
}

_.some(functionParameterNames, (functionParameterName, index) => {
const jsdocParameterName = jsdocParameterNames[index];

Expand Down
123 changes: 123 additions & 0 deletions test/rules/assertions/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,51 @@ export default {
message: 'Missing JSDoc @param "foo" declaration.'
}
]
},
{
code: `
/**
* @implements
*/
function quux (foo) {
}
`,
errors: [
{
message: 'Missing JSDoc @param "foo" declaration.'
}
]
},
{
code: `
/**
* @augments
*/
function quux (foo) {
}
`,
errors: [
{
message: 'Missing JSDoc @param "foo" declaration.'
}
]
},
{
code: `
/**
* @extends
*/
function quux (foo) {
}
`,
errors: [
{
message: 'Missing JSDoc @param "foo" declaration.'
}
]
}
],
valid: [
Expand Down Expand Up @@ -131,6 +176,84 @@ export default {
allowOverrideWithoutParam: true
}
}
},
{
code: `
/**
* @implements
*/
function quux (foo) {
}
`,
settings: {
jsdoc: {
allowImplementsWithoutParam: true
}
}
},
{
code: `
/**
* @implements
* @param foo
*/
function quux (foo) {
}
`
},
{
code: `
/**
* @augments
*/
function quux (foo) {
}
`,
settings: {
jsdoc: {
allowAugmentsExtendsWithoutParam: true
}
}
},
{
code: `
/**
* @augments
* @param foo
*/
function quux (foo) {
}
`
},
{
code: `
/**
* @extends
*/
function quux (foo) {
}
`,
settings: {
jsdoc: {
allowAugmentsExtendsWithoutParam: true
}
}
},
{
code: `
/**
* @extends
* @param foo
*/
function quux (foo) {
}
`
}
]
};

0 comments on commit 8d16526

Please sign in to comment.