Skip to content

Commit

Permalink
fix(require-description, require-example): for missing descriptio…
Browse files Browse the repository at this point in the history
…n, use tag line number

Also adding tests with line numbers for most files and adding warnings during testing for missing `line` on errors.
  • Loading branch information
brettz9 committed May 14, 2021
1 parent a70eda7 commit 310ea75
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/rules/requireDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default iterateJsdoc(({

functionExamples.forEach((example) => {
if (!checkDescription(`${example.name} ${utils.getTagDescription(example)}`)) {
report(`Missing JSDoc @${targetTagName} description.`);
report(`Missing JSDoc @${targetTagName} description.`, null, example);
}
});
}, {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requireExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default iterateJsdoc(({
const exampleContent = _.compact(`${example.name} ${utils.getTagDescription(example)}`.trim().split('\n'));

if (!exampleContent.length) {
report(`Missing JSDoc @${targetTagName} description.`);
report(`Missing JSDoc @${targetTagName} description.`, null, example);
}
});
}, {
Expand Down
7 changes: 7 additions & 0 deletions test/rules/assertions/checkAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Unexpected tag `@access`',
},
],
Expand Down Expand Up @@ -111,6 +112,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'The @access tag may not be used with specific access-control tags (@package, @private, @protected, or @public).',
},
],
Expand All @@ -127,6 +129,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'At most one access-control tag may be present on a jsdoc block.',
},
],
Expand All @@ -143,6 +146,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'At most one access-control tag may be present on a jsdoc block.',
},
],
Expand All @@ -164,6 +168,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'At most one access-control tag may be present on a jsdoc block.',
},
],
Expand All @@ -180,6 +185,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'At most one access-control tag may be present on a jsdoc block.',
},
],
Expand All @@ -201,6 +207,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'At most one access-control tag may be present on a jsdoc block.',
},
],
Expand Down
3 changes: 3 additions & 0 deletions test/rules/assertions/checkValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Invalid JSDoc @license: "MIT-7"; expected SPDX expression: https://spdx.org/licenses/.',
},
],
Expand All @@ -144,6 +145,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Invalid JSDoc @license: "(MIT OR GPL-2.5)"; expected SPDX expression: https://spdx.org/licenses/.',
},
],
Expand All @@ -160,6 +162,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Invalid JSDoc @license: "MIT\nSome extra text"; expected SPDX expression: https://spdx.org/licenses/.',
},
],
Expand Down
3 changes: 3 additions & 0 deletions test/rules/assertions/newlineAfterDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export default {
`,
errors: [
{
line: 4,
message: 'There must be no newline after the description of the JSDoc block.',
},
],
Expand All @@ -236,6 +237,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'There must be a newline after the description of the JSDoc block.',
},
],
Expand Down Expand Up @@ -263,6 +265,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'There must be a newline after the description of the JSDoc block.',
},
],
Expand Down
5 changes: 5 additions & 0 deletions test/rules/assertions/noRestrictedSyntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Syntax is restricted: FunctionDeclaration.',
},
],
Expand All @@ -31,6 +32,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Oops: `FunctionDeclaration`.',
},
],
Expand All @@ -54,6 +56,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Syntax is restricted: FunctionDeclaration.',
},
],
Expand All @@ -77,6 +80,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'The bar one: FunctionDeclaration.',
},
],
Expand Down Expand Up @@ -106,6 +110,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Rule `no-restricted-syntax` is missing a `context` option.',
},
],
Expand Down
1 change: 1 addition & 0 deletions test/rules/assertions/noTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Types are not permitted on @returns.',
},
],
Expand Down
4 changes: 4 additions & 0 deletions test/rules/assertions/noUndefinedTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default {
message: 'Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object.',
},
{
line: 3,
message: 'The type \'HerType\' is undefined.',
},
],
Expand All @@ -37,6 +38,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'The type \'HerType\' is undefined.',
},
],
Expand Down Expand Up @@ -254,9 +256,11 @@ export default {
`,
errors: [
{
line: 7,
message: 'The type \'TEMPLATE_TYPE_A\' is undefined.',
},
{
line: 8,
message: 'The type \'TEMPLATE_TYPE_B\' is undefined.',
},
],
Expand Down
19 changes: 19 additions & 0 deletions test/rules/assertions/requireDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @description declaration.',
},
],
Expand All @@ -31,6 +32,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc block description or @description declaration.',
},
],
Expand All @@ -51,6 +53,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc block description.',
},
],
Expand All @@ -71,6 +74,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Remove the @desc tag to leave a plain block description or add additional description text above the @desc line.',
},
],
Expand All @@ -91,6 +95,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Remove the @description tag to leave a plain block description or add additional description text above the @description line.',
},
],
Expand All @@ -111,6 +116,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @description declaration.',
},
],
Expand All @@ -129,6 +135,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @description declaration.',
},
],
Expand All @@ -150,6 +157,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @description declaration.',
},
],
Expand All @@ -171,6 +179,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @description declaration.',
},
],
Expand All @@ -192,6 +201,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Missing JSDoc @description description.',
},
],
Expand All @@ -212,6 +222,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @description declaration.',
},
],
Expand All @@ -236,6 +247,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @description declaration.',
},
],
Expand All @@ -259,6 +271,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @description declaration.',
},
],
Expand All @@ -282,6 +295,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Missing JSDoc @someDesc description.',
},
],
Expand Down Expand Up @@ -312,6 +326,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Unexpected tag `@description`',
},
],
Expand Down Expand Up @@ -339,6 +354,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc block description or @description declaration.',
},
],
Expand Down Expand Up @@ -527,6 +543,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @description declaration.',
},
],
Expand Down Expand Up @@ -560,6 +577,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @description declaration.',
},
],
Expand Down Expand Up @@ -592,6 +610,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @description declaration.',
},
],
Expand Down
2 changes: 2 additions & 0 deletions test/rules/assertions/requireDescriptionCompleteSentence.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Sentence should start with an uppercase character.',
},
],
Expand Down Expand Up @@ -106,6 +107,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Sentence must end with a period.',
},
],
Expand Down

0 comments on commit 310ea75

Please sign in to comment.