Skip to content

Commit

Permalink
fix(no-missing-syntax): pass in missing comment
Browse files Browse the repository at this point in the history
Also documents `message` values and adds test line numbers.
  • Loading branch information
brettz9 committed May 14, 2021
1 parent 310ea75 commit a977896
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .README/rules/no-missing-syntax.md
Expand Up @@ -42,7 +42,8 @@ Use the `minimum` property (defaults to 1) to indicate how many are required
for the rule to be reported.

Use the `message` property to indicate the specific error to be shown when an
error is reported for that context being found missing.
error is reported for that context being found missing. You may use
`{{context}}` and `{{comment}}` with such messages.

Set to `"any"` if you want the rule to apply to any jsdoc block throughout
your files (as is necessary for finding function blocks not attached to a
Expand Down
11 changes: 6 additions & 5 deletions README.md
Expand Up @@ -7601,7 +7601,8 @@ Use the `minimum` property (defaults to 1) to indicate how many are required
for the rule to be reported.
Use the `message` property to indicate the specific error to be shown when an
error is reported for that context being found missing.
error is reported for that context being found missing. You may use
`{{context}}` and `{{comment}}` with such messages.
Set to `"any"` if you want the rule to apply to any jsdoc block throughout
your files (as is necessary for finding function blocks not attached to a
Expand All @@ -7628,16 +7629,16 @@ function quux () {
}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JSDocBlock[postDelimiter=\"\"]:has(JSDocTypeUnion[left.name=\"Foo\"])","context":"FunctionDeclaration"}]}]
// Message: Syntax is required: FunctionDeclaration
// Message: Syntax is required: FunctionDeclaration with JSDocBlock[postDelimiter=""]:has(JSDocTypeUnion[left.name="Foo"])

/**
* @implements {Bar|Foo}
*/
function quux () {

}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JSDocBlock[postDelimiter=\"\"]:has(JSDocTypeUnion[left.name=\"Foo\"])","context":"FunctionDeclaration","message":"Problematic function syntax: `{{context}}`."}]}]
// Message: Problematic function syntax: `FunctionDeclaration`.
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JSDocBlock[postDelimiter=\"\"]:has(JSDocTypeUnion[left.name=\"Foo\"])","context":"FunctionDeclaration","message":"Problematically missing function syntax: `{{context}}` with `{{comment}}`."}]}]
// Message: Problematically missing function syntax: `FunctionDeclaration` with `JSDocBlock[postDelimiter=""]:has(JSDocTypeUnion[left.name="Foo"])`.

/**
* @implements {Bar|Foo}
Expand All @@ -7663,7 +7664,7 @@ function quux () {

}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JSDocBlock[postDelimiter=\"\"]:has(JSDocTypeUnion[left.name=\"Bar\"])","context":"FunctionDeclaration","minimum":2}]}]
// Message: Syntax is required: FunctionDeclaration
// Message: Syntax is required: FunctionDeclaration with JSDocBlock[postDelimiter=""]:has(JSDocTypeUnion[left.name="Bar"])
````

The following patterns are not considered problems:
Expand Down
4 changes: 3 additions & 1 deletion src/rules/noMissingSyntax.js
Expand Up @@ -56,9 +56,11 @@ export default iterateJsdoc(({
!state.selectorMap[contextStr][comment] ||
state.selectorMap[contextStr][comment] < (cntxt?.minimum ?? 1)
) {
const message = cntxt?.message ?? 'Syntax is required: {{context}}';
const message = cntxt?.message ?? 'Syntax is required: {{context}}' +
(comment ? ' with {{comment}}' : '');
context.report({
data: {
comment,
context: contextStr,
},
loc: {
Expand Down
28 changes: 28 additions & 0 deletions test/rules/assertions/checkLineAlignment.js
Expand Up @@ -12,6 +12,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -42,6 +43,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -72,6 +74,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -101,6 +104,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -130,6 +134,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -159,6 +164,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -188,6 +194,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -217,6 +224,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -248,6 +256,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -281,6 +290,7 @@ export default {
`,
errors: [
{
line: 3,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -312,6 +322,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -344,6 +355,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -377,6 +389,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -410,6 +423,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -445,6 +459,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -477,10 +492,12 @@ export default {
`,
errors: [
{
line: 5,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -510,6 +527,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -539,6 +557,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -568,6 +587,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -595,6 +615,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -628,6 +649,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -659,6 +681,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -718,6 +741,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -745,6 +769,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -772,6 +797,7 @@ export default {
`,
errors: [
{
line: 5,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -800,6 +826,7 @@ export default {
`,
errors: [
{
line: 7,
message: 'Expected JSDoc block lines to not be aligned.',
type: 'Block',
},
Expand Down Expand Up @@ -873,6 +900,7 @@ export default {
`,
errors: [
{
line: 2,
message: 'Expected JSDoc block lines to be aligned.',
type: 'Block',
},
Expand Down
14 changes: 14 additions & 0 deletions test/rules/assertions/checkParamNames.js
Expand Up @@ -753,15 +753,19 @@ export default {
`,
errors: [
{
line: 4,
message: 'Missing @param "bbox.x"',
},
{
line: 4,
message: 'Missing @param "bbox.y"',
},
{
line: 4,
message: 'Missing @param "bbox.width"',
},
{
line: 4,
message: 'Missing @param "bbox.height"',
},
],
Expand All @@ -783,15 +787,19 @@ export default {
`,
errors: [
{
line: 4,
message: 'Missing @param "bbox.x"',
},
{
line: 4,
message: 'Missing @param "bbox.y"',
},
{
line: 4,
message: 'Missing @param "bbox.width"',
},
{
line: 4,
message: 'Missing @param "bbox.height"',
},
],
Expand All @@ -809,9 +817,11 @@ export default {
`,
errors: [
{
line: 4,
message: 'Missing @param "fetchOptions.url"',
},
{
line: 4,
message: 'Missing @param "fetchOptions.options"',
},
],
Expand Down Expand Up @@ -905,9 +915,11 @@ export default {
`,
errors: [
{
line: 4,
message: 'Missing @param "options.foo"',
},
{
line: 4,
message: 'Missing @param "options.foo.bar"',
},
],
Expand Down Expand Up @@ -958,9 +970,11 @@ export default {
`,
errors: [
{
line: 6,
message: '@param "props.prop.a" does not exist on props',
},
{
line: 7,
message: '@param "props.prop.b" does not exist on props',
},
],
Expand Down

0 comments on commit a977896

Please sign in to comment.