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

@rinfel/eslint-plugin-unicorn

v40.0.0-1

Published

Various awesome ESLint rules

Downloads

3

Readme

eslint-plugin-unicorn Coverage Status npm version

Various awesome ESLint rules

⚠️ This is a fork of sindresorhus/eslint-plugin-unicorn with the explicit-length-check rule's greater-than-or-equal option retained. Read more about why this option was removed by the original authors and why we chose to keep using this style in the original GitHub issue discussions.

You might want to check out XO, which includes this plugin.

Propose or contribute a new rule ➡

Install

npm install --save-dev eslint @rinfel/eslint-plugin-unicorn

Usage

Configure it in package.json.

{
	"name": "my-awesome-project",
	"eslintConfig": {
		"env": {
			"es6": true
		},
		"parserOptions": {
			"ecmaVersion": "latest",
			"sourceType": "module"
		},
		"plugins": [
			"@rinfel/unicorn"
		],
		"rules": {
			"@rinfel/unicorn/better-regex": "error",
			"@rinfel/unicorn/catch-error-name": "error",
			"@rinfel/unicorn/consistent-destructuring": "error",
			"@rinfel/unicorn/consistent-function-scoping": "error",
			"@rinfel/unicorn/custom-error-definition": "off",
			"@rinfel/unicorn/empty-brace-spaces": "error",
			"@rinfel/unicorn/error-message": "error",
			"@rinfel/unicorn/escape-case": "error",
			"@rinfel/unicorn/expiring-todo-comments": "error",
			"@rinfel/unicorn/explicit-length-check": "error",
			"@rinfel/unicorn/filename-case": "error",
			"@rinfel/unicorn/import-index": "off",
			"@rinfel/unicorn/import-style": "error",
			"@rinfel/unicorn/new-for-builtins": "error",
			"@rinfel/unicorn/no-abusive-eslint-disable": "error",
			"@rinfel/unicorn/no-array-callback-reference": "error",
			"@rinfel/unicorn/no-array-for-each": "error",
			"@rinfel/unicorn/no-array-method-this-argument": "error",
			"@rinfel/unicorn/no-array-push-push": "error",
			"@rinfel/unicorn/no-array-reduce": "error",
			"@rinfel/unicorn/no-await-expression-member": "error",
			"@rinfel/unicorn/no-console-spaces": "error",
			"@rinfel/unicorn/no-document-cookie": "error",
			"@rinfel/unicorn/no-empty-file": "error",
			"@rinfel/unicorn/no-for-loop": "error",
			"@rinfel/unicorn/no-hex-escape": "error",
			"@rinfel/unicorn/no-instanceof-array": "error",
			"@rinfel/unicorn/no-invalid-remove-event-listener": "error",
			"@rinfel/unicorn/no-keyword-prefix": "off",
			"@rinfel/unicorn/no-lonely-if": "error",
			"no-nested-ternary": "off",
			"@rinfel/unicorn/no-nested-ternary": "error",
			"@rinfel/unicorn/no-new-array": "error",
			"@rinfel/unicorn/no-new-buffer": "error",
			"@rinfel/unicorn/no-null": "error",
			"@rinfel/unicorn/no-object-as-default-parameter": "error",
			"@rinfel/unicorn/no-process-exit": "error",
			"@rinfel/unicorn/no-static-only-class": "error",
			"@rinfel/unicorn/no-thenable": "error",
			"@rinfel/unicorn/no-this-assignment": "error",
			"@rinfel/unicorn/no-unreadable-array-destructuring": "error",
			"@rinfel/unicorn/no-unsafe-regex": "off",
			"@rinfel/unicorn/no-unused-properties": "off",
			"@rinfel/unicorn/no-useless-fallback-in-spread": "error",
			"@rinfel/unicorn/no-useless-length-check": "error",
			"@rinfel/unicorn/no-useless-promise-resolve-reject": "error",
			"@rinfel/unicorn/no-useless-spread": "error",
			"@rinfel/unicorn/no-useless-undefined": "error",
			"@rinfel/unicorn/no-zero-fractions": "error",
			"@rinfel/unicorn/number-literal-case": "error",
			"@rinfel/unicorn/numeric-separators-style": "error",
			"@rinfel/unicorn/prefer-add-event-listener": "error",
			"@rinfel/unicorn/prefer-array-find": "error",
			"@rinfel/unicorn/prefer-array-flat": "error",
			"@rinfel/unicorn/prefer-array-flat-map": "error",
			"@rinfel/unicorn/prefer-array-index-of": "error",
			"@rinfel/unicorn/prefer-array-some": "error",
			"@rinfel/unicorn/prefer-at": "off",
			"@rinfel/unicorn/prefer-code-point": "error",
			"@rinfel/unicorn/prefer-date-now": "error",
			"@rinfel/unicorn/prefer-default-parameters": "error",
			"@rinfel/unicorn/prefer-dom-node-append": "error",
			"@rinfel/unicorn/prefer-dom-node-dataset": "error",
			"@rinfel/unicorn/prefer-dom-node-remove": "error",
			"@rinfel/unicorn/prefer-dom-node-text-content": "error",
			"@rinfel/unicorn/prefer-export-from": "error",
			"@rinfel/unicorn/prefer-includes": "error",
			"@rinfel/unicorn/prefer-json-parse-buffer": "error",
			"@rinfel/unicorn/prefer-keyboard-event-key": "error",
			"@rinfel/unicorn/prefer-math-trunc": "error",
			"@rinfel/unicorn/prefer-modern-dom-apis": "error",
			"@rinfel/unicorn/prefer-module": "error",
			"@rinfel/unicorn/prefer-negative-index": "error",
			"@rinfel/unicorn/prefer-node-protocol": "error",
			"@rinfel/unicorn/prefer-number-properties": "error",
			"@rinfel/unicorn/prefer-object-from-entries": "error",
			"@rinfel/unicorn/prefer-optional-catch-binding": "error",
			"@rinfel/unicorn/prefer-prototype-methods": "error",
			"@rinfel/unicorn/prefer-query-selector": "error",
			"@rinfel/unicorn/prefer-reflect-apply": "error",
			"@rinfel/unicorn/prefer-regexp-test": "error",
			"@rinfel/unicorn/prefer-set-has": "error",
			"@rinfel/unicorn/prefer-spread": "error",
			"@rinfel/unicorn/prefer-string-replace-all": "off",
			"@rinfel/unicorn/prefer-string-slice": "error",
			"@rinfel/unicorn/prefer-string-starts-ends-with": "error",
			"@rinfel/unicorn/prefer-string-trim-start-end": "error",
			"@rinfel/unicorn/prefer-switch": "error",
			"@rinfel/unicorn/prefer-ternary": "error",
			"@rinfel/unicorn/prefer-top-level-await": "off",
			"@rinfel/unicorn/prefer-type-error": "error",
			"@rinfel/unicorn/prevent-abbreviations": "error",
			"@rinfel/unicorn/relative-url-style": "error",
			"@rinfel/unicorn/require-array-join-separator": "error",
			"@rinfel/unicorn/require-number-to-fixed-digits-argument": "error",
			"@rinfel/unicorn/require-post-message-target-origin": "off",
			"@rinfel/unicorn/string-content": "off",
			"@rinfel/unicorn/template-indent": "warn",
			"@rinfel/unicorn/throw-new-error": "error"
		}
	}
}

Rules

Each rule has emojis denoting:

  • ✅ if it belongs to the recommended configuration
  • 🔧 if some problems reported by the rule are automatically fixable by the --fix command line option
  • 💡 if some problems reported by the rule are manually fixable by editor suggestions

| Name                                         | Description | ✅ | 🔧 | 💡 | | :-- | :-- | :-- | :-- | :-- | | better-regex | Improve regexes by making them shorter, consistent, and safer. | ✅ | 🔧 | | | catch-error-name | Enforce a specific parameter name in catch clauses. | ✅ | 🔧 | | | consistent-destructuring | Use destructured variables over properties. | ✅ | 🔧 | 💡 | | consistent-function-scoping | Move function definitions to the highest possible scope. | ✅ | | | | custom-error-definition | Enforce correct Error subclassing. | | 🔧 | | | empty-brace-spaces | Enforce no spaces between braces. | ✅ | 🔧 | | | error-message | Enforce passing a message value when creating a built-in error. | ✅ | | | | escape-case | Require escape sequences to use uppercase values. | ✅ | 🔧 | | | expiring-todo-comments | Add expiration conditions to TODO comments. | ✅ | | | | explicit-length-check | Enforce explicitly comparing the length or size property of a value. | ✅ | 🔧 | 💡 | | filename-case | Enforce a case style for filenames. | ✅ | | | | import-index | Enforce importing index files with .. | | 🔧 | | | import-style | Enforce specific import styles per module. | ✅ | | | | new-for-builtins | Enforce the use of new for all builtins, except String, Number, Boolean, Symbol and BigInt. | ✅ | 🔧 | | | no-abusive-eslint-disable | Enforce specifying rules to disable in eslint-disable comments. | ✅ | | | | no-array-callback-reference | Prevent passing a function reference directly to iterator methods. | ✅ | | 💡 | | no-array-for-each | Prefer for…of over Array#forEach(…). | ✅ | 🔧 | | | no-array-method-this-argument | Disallow using the this argument in array methods. | ✅ | 🔧 | 💡 | | no-array-push-push | Enforce combining multiple Array#push() into one call. | ✅ | 🔧 | 💡 | | no-array-reduce | Disallow Array#reduce() and Array#reduceRight(). | ✅ | | | | no-await-expression-member | Forbid member access from await expression. | ✅ | 🔧 | | | no-console-spaces | Do not use leading/trailing space between console.log parameters. | ✅ | 🔧 | | | no-document-cookie | Do not use document.cookie directly. | ✅ | | | | no-empty-file | Disallow empty files. | ✅ | | | | no-for-loop | Do not use a for loop that can be replaced with a for-of loop. | ✅ | 🔧 | | | no-hex-escape | Enforce the use of Unicode escapes instead of hexadecimal escapes. | ✅ | 🔧 | | | no-instanceof-array | Require Array.isArray() instead of instanceof Array. | ✅ | 🔧 | | | no-invalid-remove-event-listener | Prevent calling EventTarget#removeEventListener() with the result of an expression. | ✅ | | | | no-keyword-prefix | Disallow identifiers starting with new or class. | | | | | no-lonely-if | Disallow if statements as the only statement in if blocks without else. | ✅ | 🔧 | | | no-nested-ternary | Disallow nested ternary expressions. | ✅ | 🔧 | | | no-new-array | Disallow new Array(). | ✅ | 🔧 | 💡 | | no-new-buffer | Enforce the use of Buffer.from() and Buffer.alloc() instead of the deprecated new Buffer(). | ✅ | 🔧 | 💡 | | no-null | Disallow the use of the null literal. | ✅ | 🔧 | 💡 | | no-object-as-default-parameter | Disallow the use of objects as default parameters. | ✅ | | | | no-process-exit | Disallow process.exit(). | ✅ | | | | no-static-only-class | Forbid classes that only have static members. | ✅ | 🔧 | | | no-thenable | Disallow then property. | ✅ | | | | no-this-assignment | Disallow assigning this to a variable. | ✅ | | | | no-unreadable-array-destructuring | Disallow unreadable array destructuring. | ✅ | 🔧 | | | no-unsafe-regex | Disallow unsafe regular expressions. | | | | | no-unused-properties | Disallow unused object properties. | | | | | no-useless-fallback-in-spread | Forbid useless fallback when spreading in object literals. | ✅ | 🔧 | | | no-useless-length-check | Disallow useless array length check. | ✅ | 🔧 | | | no-useless-promise-resolve-reject | Disallow returning/yielding Promise.resolve/reject() in async functions or promise callbacks | ✅ | 🔧 | | | no-useless-spread | Disallow unnecessary spread. | ✅ | 🔧 | | | no-useless-undefined | Disallow useless undefined. | ✅ | 🔧 | | | no-zero-fractions | Disallow number literals with zero fractions or dangling dots. | ✅ | 🔧 | | | number-literal-case | Enforce proper case for numeric literals. | ✅ | 🔧 | | | numeric-separators-style | Enforce the style of numeric separators by correctly grouping digits. | ✅ | 🔧 | | | prefer-add-event-listener | Prefer .addEventListener() and .removeEventListener() over on-functions. | ✅ | 🔧 | | | prefer-array-find | Prefer .find(…) over the first element from .filter(…). | ✅ | 🔧 | 💡 | | prefer-array-flat | Prefer Array#flat() over legacy techniques to flatten arrays. | ✅ | 🔧 | | | prefer-array-flat-map | Prefer .flatMap(…) over .map(…).flat(). | ✅ | 🔧 | | | prefer-array-index-of | Prefer Array#indexOf() over Array#findIndex() when looking for the index of an item. | ✅ | 🔧 | 💡 | | prefer-array-some | Prefer .some(…) over .filter(…).length check and .find(…). | ✅ | 🔧 | 💡 | | prefer-at | Prefer .at() method for index access and String#charAt(). | | 🔧 | 💡 | | prefer-code-point | Prefer String#codePointAt(…) over String#charCodeAt(…) and String.fromCodePoint(…) over String.fromCharCode(…). | ✅ | | 💡 | | prefer-date-now | Prefer Date.now() to get the number of milliseconds since the Unix Epoch. | ✅ | 🔧 | | | prefer-default-parameters | Prefer default parameters over reassignment. | ✅ | 🔧 | 💡 | | prefer-dom-node-append | Prefer Node#append() over Node#appendChild(). | ✅ | 🔧 | | | prefer-dom-node-dataset | Prefer using .dataset on DOM elements over calling attribute methods. | ✅ | 🔧 | | | prefer-dom-node-remove | Prefer childNode.remove() over parentNode.removeChild(childNode). | ✅ | 🔧 | 💡 | | prefer-dom-node-text-content | Prefer .textContent over .innerText. | ✅ | | 💡 | | prefer-export-from | Prefer export…from when re-exporting. | ✅ | 🔧 | 💡 | | prefer-includes | Prefer .includes() over .indexOf() and Array#some() when checking for existence or non-existence. | ✅ | 🔧 | 💡 | | prefer-json-parse-buffer | Prefer reading a JSON file as a buffer. | ✅ | 🔧 | | | prefer-keyboard-event-key | Prefer KeyboardEvent#key over KeyboardEvent#keyCode. | ✅ | 🔧 | | | prefer-math-trunc | Enforce the use of Math.trunc instead of bitwise operators. | ✅ | 🔧 | 💡 | | prefer-modern-dom-apis | Prefer .before() over .insertBefore(), .replaceWith() over .replaceChild(), prefer one of .before(), .after(), .append() or .prepend() over insertAdjacentText() and insertAdjacentElement(). | ✅ | 🔧 | | | prefer-module | Prefer JavaScript modules (ESM) over CommonJS. | ✅ | 🔧 | 💡 | | prefer-negative-index | Prefer negative index over .length - index for {String,Array,TypedArray}#slice(), Array#splice() and Array#at(). | ✅ | 🔧 | | | prefer-node-protocol | Prefer using the node: protocol when importing Node.js builtin modules. | ✅ | 🔧 | | | prefer-number-properties | Prefer Number static properties over global ones. | ✅ | 🔧 | 💡 | | prefer-object-from-entries | Prefer using Object.fromEntries(…) to transform a list of key-value pairs into an object. | ✅ | 🔧 | | | prefer-optional-catch-binding | Prefer omitting the catch binding parameter. | ✅ | 🔧 | | | prefer-prototype-methods | Prefer borrowing methods from the prototype instead of the instance. | ✅ | 🔧 | | | prefer-query-selector | Prefer .querySelector() over .getElementById(), .querySelectorAll() over .getElementsByClassName() and .getElementsByTagName(). | ✅ | 🔧 | | | prefer-reflect-apply | Prefer Reflect.apply() over Function#apply(). | ✅ | 🔧 | | | prefer-regexp-test | Prefer RegExp#test() over String#match() and RegExp#exec(). | ✅ | 🔧 | | | prefer-set-has | Prefer Set#has() over Array#includes() when checking for existence or non-existence. | ✅ | 🔧 | 💡 | | prefer-spread | Prefer the spread operator over Array.from(…), Array#concat(…), Array#slice() and String#split(''). | ✅ | 🔧 | 💡 | | prefer-string-replace-all | Prefer String#replaceAll() over regex searches with the global flag. | | 🔧 | | | prefer-string-slice | Prefer String#slice() over String#substr() and String#substring(). | ✅ | 🔧 | | | prefer-string-starts-ends-with | Prefer String#startsWith() & String#endsWith() over RegExp#test(). | ✅ | 🔧 | 💡 | | prefer-string-trim-start-end | Prefer String#trimStart() / String#trimEnd() over String#trimLeft() / String#trimRight(). | ✅ | 🔧 | | | prefer-switch | Prefer switch over multiple else-if. | ✅ | 🔧 | | | prefer-ternary | Prefer ternary expressions over simple if-else statements. | ✅ | 🔧 | | | prefer-top-level-await | Prefer top-level await over top-level promises and async function calls. | | | 💡 | | prefer-type-error | Enforce throwing TypeError in type checking conditions. | ✅ | 🔧 | | | prevent-abbreviations | Prevent abbreviations. | ✅ | 🔧 | | | relative-url-style | Enforce consistent relative URL style. | ✅ | 🔧 | | | require-array-join-separator | Enforce using the separator argument with Array#join(). | ✅ | 🔧 | | | require-number-to-fixed-digits-argument | Enforce using the digits argument with Number#toFixed(). | ✅ | 🔧 | | | require-post-message-target-origin | Enforce using the targetOrigin argument with window.postMessage(). | | | 💡 | | string-content | Enforce better string content. | | 🔧 | 💡 | | template-indent | Fix whitespace-insensitive template indentation. | | 🔧 | | | throw-new-error | Require new when throwing an error. | ✅ | 🔧 | |

Deprecated Rules

See docs/deprecated-rules.md

Recommended config

This plugin exports a recommended config that enforces good practices.

Enable it in your package.json with the extends option:

{
	"name": "my-awesome-project",
	"eslintConfig": {
		"extends": "plugin:@rinfel/unicorn/recommended"
	}
}

See the ESLint docs for more information about extending config files.

Note: This config will also enable the correct parser options and environment.

All config

This plugin exports an all config that makes use of all rules (except for deprecated ones).

Enable it in your package.json with the extends option:

{
	"name": "my-awesome-project",
	"eslintConfig": {
		"extends": "plugin:@rinfel/unicorn/all"
	}
}

See the ESLint docs for more information about extending config files.

Maintainers

Former