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

feat(eslint-plugin) new rule: require @since annotations #401

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

luc122c
Copy link

@luc122c luc122c commented Apr 20, 2024

Hi there! This is work towards resolving nuxt/nuxt#24950. This PR adds a new rule: require-jsdoc-since. The purpose of this rule is to check exported functions and make sure they have a JSDoc with a @since annotation.

Methodology

  • Filter only ExportNamedDeclaration and ExportDefaultDeclaration
  • Filter out TSInterfaceDeclaration and TSTypeAliasDeclaration
  • Get leading comments
    • If there are none, then report missing JSDoc
  • Check for a valid JSDOC with @since annotation
    • If there is none then report missing annotation

Issues

Because it is looping over all definitions and checking individually, it is not aware of overloads. This leads to cases where a JSDoc defines a function with overloads, but the new rule reports that the overloads are missing valid JSDoc comments.

Any help would be appreciated 😄

Development

I have made the following modifications to my local copy of Nuxt to test this. If there is a better way to integrate te types, please let me know as I'll need to make a PR to integrate this into Nuxt next :)

// eslint.config.mjs
// ...
  .override('nuxt/rules', {
    files: [
      // Here we define which files get checked
      'packages/*/src/utils.ts',
      'packages/nuxt/src/app/composables/*.ts',
      'packages/nuxt/src/app/utils.ts',
    ],
    rules: {
      // Override removed this default. 
      // Is there a better way to do this?
      'nuxt/prefer-import-meta': 'error',
      'nuxt/require-jsdoc-since': 'error',
    },
  })
// ...
// package.json
{
  // ...
 "resolutions": {
    // ...
    "@nuxt/eslint-plugin": "../eslint/packages/eslint-plugin",
    // ...                           ^ My local copy
  }
  // ...
}

Testing

I have created a test file, but I have absolutely no idea how to run it. I would appreciate it if anyone could help 😃

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

Successfully merging this pull request may close these issues.

None yet

1 participant