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

@automattic/eslint-plugin-wpvip

v0.13.0

Published

ESLint plugin for internal WordPress VIP projects

Downloads

7,055

Readme

WordPress VIP ESLint plugin

This is an ESLint plugin to provide WordPress VIP's (internal) JavaScript and TypeScript coding standards. It is inspired by and borrows from @wordpress/eslint-plugin.

Installation

Install eslint and @automattic/eslint-plugin-wpvip to your project.

npm install --save-dev eslint @automattic/eslint-plugin-wpvip

Contributing

See CONTRIBUTING.md for details on development, testing, publishing, etc.

Configuration

Create an .eslintrc.js file. Note: The init file allows you to avoid installing peer dependencies (available from v0.5.0).

require( '@automattic/eslint-plugin-wpvip/init' );

module.exports = {
	extends: [ 'plugin:@automattic/wpvip/recommended' ],
	root: true,
};

And that's it! It works automatically with most Babel and TypeScript projects. Code editors that are configured to work with ESLint will automatically pick up the rules and flag any errors or warnings.

You may also wish to define an .eslintignore file if there are files or paths that you do not want to lint.

Package scripts can be useful to run linting and formatting commands automatically. Here are some suggested scripts for your project's package.json—only copy the ones that are useful to you. The cmd: scripts help you compose commands without repeating verbose CLI arguments.

{
	"scripts": {
		"cmd:format": "prettier '**/*.(js|json|jsx|md|ts|tsx|yml|yaml)'",
		"cmd:lint": "eslint --ext 'js,jsx,ts,tsx'",
		"format": "npm run cmd:format -- --write",
		"format:check": "npm run cmd:format -- --check",
		"lint": "npm run cmd:lint .",
		"lint:fix": "npm run cmd:lint . -- --fix",
		"lint:ignore-warnings": "npm run cmd:lint . -- --quiet"
	}
}

Note: ESLint automatically ignores files listed in .eslintignore or you can target .gitignore using --ignore-path. Similarly, Prettier automatically ignores files listed in .prettierignore or you can target .gitignore using --ignore-path.

Recommended config

The "recommended" config includes rules for JavaScript, TypeScript, Jest, and React, including rules related to formatting and white space. It is intended to be strict! Opinionated defaults keep our codebases consistent and reduce the friction we experience when context-switching between projects.

Of course, this recommended config may not be ideal for every project, so feel free to "build your own" using the available modular configs. The recommended config is equivalent to:

module.exports = {
	extends: [
		'plugin:@automattic/wpvip/javascript',
		'plugin:@automattic/wpvip/typescript', // when "typescript" is installed
		'plugin:@automattic/wpvip/formatting',
		'plugin:@automattic/wpvip/testing', // when "jest" is installed
		'plugin:@automattic/wpvip/react', // when "react" is installed
		'plugin:@automattic/wpvip/prettier', // when "prettier" is installed
	],
};

Note that the order of configs can matter, since they can contain overrides. It is particularly important to add the prettier config last.

Prettier

Install WP Prettier v2.x to benefit from additional formatting rules:

npm i --save-dev --save-exact "prettier@npm:[email protected]"

This repo also provides a Prettier config, which you can use with the following .prettierrc:

"@automattic/eslint-plugin-wpvip/prettierrc"

For maximum benefit, see Prettier's documentation on enabling format-on-save in your editor. This enables you to concentrate on coding while Prettier handles formatting.

Editorconfig

Editorconfig provides additional formatting rules and works well with Prettier. Copy the .editorconfig file from this repo into your project.

CLI

The cli config allows certain behaviors that are usually against best practice but are useful in a codebase that produces a CLI tool:

module.exports = {
	extends: [ 'plugin:@automattic/wpvip/recommended', 'plugin:@automattic/wpvip/cli' ],
};

If your project is not a CLI tool but calls process methods occasionally, you probably don't need this config. Instead, disable those rules only where necessary and include an explanation:

// Intentionally exiting because we have observed an unrecoverable error.
// eslint-disable-next-line no-process-exit
process.exit( 1 );

Note that console.log is still forbidden (see here for an explanation). If you're writing one-off Node scripts, you can disable the rule per file:

/* eslint-disable no-console */

JSDoc

JSDoc is considered optional, especially compared to better alternatives like TypeScript and OpenAPI documentation. If you want to enforce the use of JSDoc, use the jsdoc config:

module.exports = {
	extends: [ 'plugin:@automattic/wpvip/recommended', 'plugin:@automattic/wpvip/jsdoc' ],
};

Note that rules that require @param and @return types are relaxed in TypeScript files.

"Weak" configs

This plugin provides a few so-called "weak" configs for legacy codebases that are working to transition to stronger standards. These configs downgrade select rules from the recommended config to warnings. Warnings will still be visible in code editors and other outputs but will not fail continous integration workflows.

These configs are intended for temporary use and should not be used long-term. We also do not recommend the use of tools like eslines to ignore errors or warnings. While the intention is to prevent large-scale changes and transition slowly to stronger standards, the effect is usually that the transition stalls and eventually stops completely.

Three "weak" configs are available: weak-javascript, weak-typescript, and weak-testing. While pull requests on this project are always welcome, please carefully consider whether adding rules to these configs is truly necessary. Ideally, we work to remove rules from these configs until they are no longer needed.