npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-config-tjw-jsdoc

v2.0.1

Published

The Jared Wilcurt's Premium JSDoc Linting rules

Downloads

926

Readme

eslint-config-tjw-jsdoc

The Jared Wilcurt's premium JSDoc ESLint rules.

Using this

This assumes you have ESLint 9+ already set up, if not, refer to this guide.

  1. npm install --save-dev eslint-plugin-jsdoc eslint-config-tjw-jsdoc
  2. In your eslint.config.js:
    import tjwJsdoc from 'eslint-config-tjw-jsdoc';
    
    export default [
      ...tjwJsdoc,
      {
        // Your project specific settings
      }
    ];

What does it look like?

The linter will enforce the formatting and types for functions arguments/returns.

Below is an example function and what the formatting looks like for its comment block.

  • A description is required (and must end in a period). Followed by a return. This explains what the function does, and why it exists.
  • All arguments and return require a type, but can be an imported interface if complex/reusable. (see: ESM Example or CJS example)
  • All argument names must match the code (to ensure the comment isn't outdated).
  • All arguments and return must have description text explaining what they are/why they exist.
  • If the function returns a value, then the @return and a description will be required.
  • If the function has no return, then the JSDoc comment must remove the @return line.
  • You can optionally include an @example after the main description and it will be formatted.
  • Almost all formatting can be applied automatically with ESLint's --fix. Including the vertically aligned columns for @token/{type}/name/description.
/** @typedef {import('../types.js').OPTIONS} OPTIONS */

/**
 * Generic validation method to ensure a specific key on the options
 * object is either a string, or removed.
 *
 * @param  {OPTIONS} options  User's options
 * @param  {string}  key      The key on the user's options object to be validated as an optional string
 * @return {OPTIONS}          Validated or mutated user options
 */
function validateOptionalString (options, key) {
  if (
    typeof(options) === 'object' &&
    Object(options).hasOwnProperty(key) &&
    typeof(options[key]) !== 'string'
  ) {
    console.warn(options, 'Optional ' + key + ' must be a string');
    delete options[key];
  }
  return options;
}

Pairs really well with:

  • Sublime Text plugin - DocBlockr - Best in class
  • VS Codium plugin - VS DocBlockr - Not as good as the SublimeText one, but not bad
  • IntelliJ based editors (WebStorm, etc) have a built in plugin you can enable, but it's not open source, it's handled by Jet Brains, and it's almost completely useless. But you can still enable it and try it out. If enough people turn it on, maybe they'll prioritize making it better.

But the point of using ESLint to enforce this is so that you don't have to do editor-specific things. Any team can adopt this approach and each dev can make ESLint work with whatever tools they use.


See also: