eslint-plugin-unicorn
eslint-plugin-unicorn copied to clipboard
More than 100 powerful ESLint rules
### Description [`prefer-ternary`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-ternary.md#prefer-ternary-expressions-over-simple-if-else-statements) currently only supports > 'simple' if-else statements, where 'simple' means the consequent and alternate are each one line and have the same basic type and form. Would...
The [documentation](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-number-properties.md) shows good and bad examples in two large blocks, but this means that finding the _right_ way to do things takes longer than necessary. I'd suggest this format:...
### Description Often [`no-for-loop`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-for-loop.md) results in something that could be simplified down to usage of [`Array.prototype.map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) This is an alternative to https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1714 and only one of these rules should be...
### Description Often [`no-for-loop`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-for-loop.md) results in something that be simplified down to [`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from) Note for even simpler cases are handled by https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1713 This is an alternative to https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1712 and only...
We'd like to enforce casing of both files and directories. Is that possible, or would it need some kind of "root" directory to avoid caring about directory name outside of...
### Description Any usage of `element.insertBefore(child, element.firstChild)` can be converted to `element.prepend(child)`. (Note, this isn't safe with `element.firstChildElement`) ### Fail ```js element.insertBefore(child, element.firstChild); ``` ### Pass ```js element.prepend(child) ```
### Description Often [`no-for-loop`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-for-loop.md) results in something that is a simple spread, which [`prefer-spread`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-spread.md) should handle This works for both arrays and iterators. ### Fail ```js const result = []...
### Description I didn't know [`Object.defineProperties`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties) existed. Would have been nice for a rule to teach me as [I wrote consecutive `Object.defineProperty`](https://github.com/concept-not-found/module-linking-polyfill/blob/b7bc16056f4faf42173cc4fd334d4ef177df0121/packages/transformer/parser/grammar.js#L76-L83). ### Fail ```js Object.defineProperty(matcher, 'logger', { value: ()...
### Description I was reading upon this proposal: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-reflect-apply.md#prefer-reflectapply-over-functionapply why not suggest using spread? ### Fail ```js foo.apply(null, arguments) ``` ### Pass ```js foo(...arguments) ```
### Description ESLint has various rules to enforce methods or function declarations vs arrow functions. One that’s missing is a way to enforce the use of a short arrow function...