Skip to content

Commit

Permalink
fix(check-tag-names, empty-tags, require-description, require-example…
Browse files Browse the repository at this point in the history
…, require-param, require-returns) explicitly allow `inheritDoc` in all modes while only allowing `inheritdoc` in non-Closure mode; fixes #520
  • Loading branch information
brettz9 committed Apr 20, 2020
1 parent 6d0511b commit 81164fd
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 6 deletions.
129 changes: 129 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2444,6 +2444,7 @@ function quux () {
* @ignore
* @implements
* @inheritdoc
* @inheritDoc
* @inner
* @instance
* @interface
Expand Down Expand Up @@ -2519,6 +2520,7 @@ function quux (foo) {}
* @ignore
* @implements
* @inheritdoc
* @inheritDoc
* @inner
* @instance
* @interface
Expand Down Expand Up @@ -2650,6 +2652,7 @@ function quux (foo) {
* @ignore
* @implements
* @inheritdoc
* @inheritDoc
* @inner
* @instance
* @interface
Expand Down Expand Up @@ -2723,6 +2726,7 @@ function quux (foo) {}
* @ignore
* @implements
* @inheritdoc
* @inheritDoc
* @inner
* @instance
* @interface
Expand Down Expand Up @@ -9043,6 +9047,15 @@ function quux (foo) {
// Options: [{"exemptedBy":[]}]
// Message: Missing JSDoc @param "foo" declaration.

/**
* @inheritdoc
*/
function quux (foo) {

}
// Settings: {"jsdoc":{"mode":"closure"}}
// Message: Missing JSDoc @param "foo" declaration.

/**
* Assign the project to a list of employees.
* @param {object[]} employees - The employees who are responsible for the project.
Expand Down Expand Up @@ -9095,6 +9108,89 @@ TestMethod(id);
declare let TestFunction: (id) => void;
// Options: [{"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.

/**
* A test function.
*/
let TestFunction: (id) => void;
// Options: [{"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.

/**
* A test function.
*/
function test(
processor: (id: number) => string
) {
return processor(10);
}
// Options: [{"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.

/**
* A test function.
*/
let test = (processor: (id: number) => string) =>
{
return processor(10);
}
// Options: [{"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.

class TestClass {
/**
* A class property.
*/
public Test: (id: number) => string;
}
// Options: [{"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.

class TestClass {
/**
* A class method.
*/
public TestMethod(): (id: number) => string
{
}
}
// Options: [{"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.

interface TestInterface {
/**
* An interface property.
*/
public Test: (id: number) => string;
}
// Options: [{"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.

interface TestInterface {
/**
* An interface method.
*/
public TestMethod(): (id: number) => string;
}
// Options: [{"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.

/**
* A function with return type
*/
function test(): (id: number) => string;
// Options: [{"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.

/**
* A function with return type
*/
let test = (): (id: number) => string =>
{
return (id) => `${id}`;
}
// Options: [{"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.
````

The following patterns are not considered problems:
Expand All @@ -9114,6 +9210,13 @@ function quux (foo) {

}

/**
* @inheritDoc
*/
function quux (foo) {

}

/**
* @arg foo
*/
Expand Down Expand Up @@ -9461,6 +9564,32 @@ function quux (foo) {

}
// Options: [{"contexts":["ArrowFunctionExpression"]}]

/**
* A function with return type
*
* @param id
*/
let test = (): (id: number) => string =>
{
return (id) => `${id}`;
}
// Options: [{"contexts":["TSFunctionType"]}]

/** @abstract */
class base {
/** @param {boolean} arg0 */
constructor(arg0) {}
}

class foo extends base {
/** @inheritDoc */
constructor(arg0) {
super(arg0);
this.arg0 = arg0;
}
}
// Settings: {"jsdoc":{"mode":"closure"}}
````


Expand Down
7 changes: 6 additions & 1 deletion src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,12 @@ const getUtils = (
return true;
}

const exemptedBy = _.get(context, 'options[0].exemptedBy', ['inheritdoc']);
const exemptedBy = _.get(
context, 'options[0].exemptedBy', [
'inheritDoc',
...settings.mode === 'closure' ? [] : ['inheritdoc'],
],
);
if (exemptedBy.length && utils.getPresentTags(exemptedBy).length) {
return true;
}
Expand Down
9 changes: 8 additions & 1 deletion src/rules/emptyTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ import iterateJsdoc from '../iterateJsdoc';

const defaultEmptyTags = [
'abstract', 'async', 'generator', 'global', 'hideconstructor',
'ignore', 'inheritdoc', 'inner', 'instance', 'override', 'readonly',
'ignore', 'inner', 'instance', 'override', 'readonly',

// jsdoc doesn't use this form in its docs, but allow for compatibility with
// TypeScript which allows and Closure which requires
'inheritDoc',
];

const emptyIfNotClosure = [
'package', 'private', 'protected', 'public', 'static',

// Closure doesn't allow with this casing
'inheritdoc',
];

export default iterateJsdoc(({
Expand Down
15 changes: 11 additions & 4 deletions src/tagNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const jsdocTags = {
ignore: [],
implements: [],
inheritdoc: [],

// Allowing casing distinct from jsdoc `definitions.js` (required in Closure)
inheritDoc: [],

inner: [],
instance: [],
interface: [],
Expand Down Expand Up @@ -139,8 +143,14 @@ const undocumentedClosureTags = {
wizaction: [],
};

const {
// eslint-disable-next-line no-unused-vars
inheritdoc,
...typeScriptTagsNoInheritdoc
} = typeScriptTags;

const closureTags = {
...typeScriptTags,
...typeScriptTagsNoInheritdoc,
...undocumentedClosureTags,

// From https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler
Expand All @@ -158,9 +168,6 @@ const closureTags = {
// With casing distinct from jsdoc `definitions.js`
implicitCast: [],

// With casing distinct from jsdoc `definitions.js`
inheritDoc: [],

noalias: [],
nocollapse: [],
nocompile: [],
Expand Down
53 changes: 53 additions & 0 deletions test/rules/assertions/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,27 @@ export default {
},
],
},
{
code: `
/**
* @inheritdoc
*/
function quux (foo) {
}
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @param "foo" declaration.',
},
],
settings: {
jsdoc: {
mode: 'closure',
},
},
},
{
code: `
/**
Expand Down Expand Up @@ -1012,6 +1033,16 @@ export default {
}
`,
},
{
code: `
/**
* @inheritDoc
*/
function quux (foo) {
}
`,
},
{
code: `
/**
Expand Down Expand Up @@ -1560,5 +1591,27 @@ export default {
],
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/** @abstract */
class base {
/** @param {boolean} arg0 */
constructor(arg0) {}
}
class foo extends base {
/** @inheritDoc */
constructor(arg0) {
super(arg0);
this.arg0 = arg0;
}
}
`,
settings: {
jsdoc: {
mode: 'closure',
},
},
},
],
};

0 comments on commit 81164fd

Please sign in to comment.