Skip to content

Commit

Permalink
fix(no-restricted-syntax): update jsdoccomment to be able to use ne…
Browse files Browse the repository at this point in the history
…w `descriptionStartLine`, `descriptionEndLine`, and `hasPreterminalDescription` properties; fixes #830
  • Loading branch information
brettz9 committed Nov 2, 2022
1 parent e5da5bb commit d68d742
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -9641,6 +9641,16 @@ const MyComponent = ({ children }) => {
}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[tag=\"type\"]:has([value=/FunctionComponent/]))","context":"any","message":"The `FunctionComponent` type is not allowed. Please use `FC` instead."}]}]
// Message: The `FunctionComponent` type is not allowed. Please use `FC` instead.

/** Some text and more */
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[descriptionStartLine=0][descriptionEndLine=0]","context":"any","message":"Requiring descriptive text on 0th line only"}]}]
// Message: Requiring descriptive text on 0th line only

/** Some text and
* more
*/
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[descriptionStartLine=0][hasPreterminalDescription=0]","context":"any","message":"Requiring descriptive text on 0th line and no preterminal description"}]}]
// Message: Requiring descriptive text on 0th line and no preterminal description
````

The following patterns are not considered problems:
Expand Down Expand Up @@ -9699,6 +9709,13 @@ const MY_ENUM = Object.freeze({
/** Does something very important. */
function foo(): string;
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[endLine=0][description!=/^\\S[\\s\\S]*\\S\\s$/]"}]}]

/** Some text and more */
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[descriptionStartLine=0][descriptionEndLine=1]","context":"any","message":"Requiring descriptive text on 0th line and no final newline"}]}]

/** Some text and
* more */
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[descriptionStartLine=0][hasPreterminalDescription=0]","context":"any","message":"Requiring descriptive text on 0th line and no preterminal description"}]}]
````


Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -5,7 +5,7 @@
"url": "http://gajus.com"
},
"dependencies": {
"@es-joy/jsdoccomment": "~0.33.4",
"@es-joy/jsdoccomment": "~0.35.0",
"comment-parser": "1.3.1",
"debug": "^4.3.4",
"escape-string-regexp": "^4.0.0",
Expand Down
79 changes: 79 additions & 0 deletions test/rules/assertions/noRestrictedSyntax.js
Expand Up @@ -372,6 +372,52 @@ export default {
],
parser: require.resolve('@es-joy/jsdoc-eslint-parser/typescript.js'),
},
{
code: `
/** Some text and more */
`,
errors: [
{
line: 2,
message: 'Requiring descriptive text on 0th line only',
},
],
options: [
{
contexts: [
{
comment: 'JsdocBlock[descriptionStartLine=0][descriptionEndLine=0]',
context: 'any',
message: 'Requiring descriptive text on 0th line only',
},
],
},
],
},
{
code: `
/** Some text and
* more
*/
`,
errors: [
{
line: 2,
message: 'Requiring descriptive text on 0th line and no preterminal description',
},
],
options: [
{
contexts: [
{
comment: 'JsdocBlock[descriptionStartLine=0][hasPreterminalDescription=0]',
context: 'any',
message: 'Requiring descriptive text on 0th line and no preterminal description',
},
],
},
],
},
],
valid: [
{
Expand Down Expand Up @@ -531,5 +577,38 @@ export default {
],
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/** Some text and more */
`,
options: [
{
contexts: [
{
comment: 'JsdocBlock[descriptionStartLine=0][descriptionEndLine=1]',
context: 'any',
message: 'Requiring descriptive text on 0th line and no final newline',
},
],
},
],
},
{
code: `
/** Some text and
* more */
`,
options: [
{
contexts: [
{
comment: 'JsdocBlock[descriptionStartLine=0][hasPreterminalDescription=0]',
context: 'any',
message: 'Requiring descriptive text on 0th line and no preterminal description',
},
],
},
],
},
],
};

0 comments on commit d68d742

Please sign in to comment.