Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I require an @author tag in every JSDoc? #876

Closed
riquier opened this issue Apr 19, 2022 · 6 comments
Closed

How can I require an @author tag in every JSDoc? #876

riquier opened this issue Apr 19, 2022 · 6 comments
Labels

Comments

@riquier
Copy link

riquier commented Apr 19, 2022

I am loving this plugin and have been trying to work out if there was a way to require each JSDoc comment to have an @author tag as per our development standards we use?

@brettz9
Copy link
Collaborator

brettz9 commented Apr 19, 2022

Glad to hear you're enjoying the plugin.

Yes, you can use the jsdoc/no-missing-syntax rule as follows:

`jsdoc/no-missing-syntax`: ['error', {
   contexts: [
     {
       comment: 'JsdocBlock:has(JsdocTag[tag=author])',
       context: 'any'
     }
   ]
 }
]

Closing as that should resolve, though feel free to reply further as needed.

@brettz9 brettz9 closed this as completed Apr 19, 2022
@riquier
Copy link
Author

riquier commented Apr 19, 2022

@brettz9 appreciate the quick reply, I had been trying that though it is only reporting a failure if there are no @author tags in the entire JS file not the /** **/ block. Any thoughts?

@brettz9
Copy link
Collaborator

brettz9 commented Apr 19, 2022

If you are looking for the tags at the beginning of the document, you can use the following which insists that they be at the beginning:

        'jsdoc/require-file-overview': ['error', {
          tags: {
            author: {
              initialCommentsOnly: true,
              mustExist: true,
              preventDuplicates: false,
            },
          },
        }]

Although there is no special recognized enforcement for tags ending in **/, you could target such tags with the following (in jsdoc/no-missing-syntax):

comment: 'JsdocBlock[description=/\\*$/]:has(JsdocTag[tag=author])'

@riquier
Copy link
Author

riquier commented Apr 19, 2022

Apologies explained clumsily, I want to enforce @author in every comment block within the file (e.g. every function, method, class), whereas when I tried your solution it was only only checking if @author existed in at least 1 comment block in the entire file.

@brettz9
Copy link
Collaborator

brettz9 commented Apr 19, 2022

Try jsdoc/no-restricted-syntax with:

        {
          contexts: [
            {
              comment: 'JsdocBlock:not(*:has(JsdocTag[tag=author]))',
              context: 'any',
            },
          ],
        },

@riquier
Copy link
Author

riquier commented Apr 19, 2022

that works, really appreciate your help @brettz9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants