This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
Implement the 100+ rules from eslint-plugin-unicorn #4756
flowstate247
started this conversation in
Suggestions
Replies: 2 comments 3 replies
-
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Frankly, I find that most of these rules add value to the linting process. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Implement the 100+ rules from eslint-plugin-unicorn: https://github.com/sindresorhus/eslint-plugin-unicorn/tree/main
✅ Set in the
recommended
configuration.🔧 Automatically fixable by the
--fix
CLI option.💡 Manually fixable by editor suggestions.
Error
subclassing.message
value when creating a built-in error.length
orsize
property of a value.new
for all builtins, exceptString
,Number
,Boolean
,Symbol
andBigInt
.eslint-disable
comments.for…of
over theforEach
method.this
argument in array methods.Array#push()
into one call.Array#reduce()
andArray#reduceRight()
.console.log
parameters.document.cookie
directly.for
loop that can be replaced with afor-of
loop.Array.isArray()
instead ofinstanceof Array
.EventTarget#removeEventListener()
with the result of an expression.new
orclass
.if
statements as the only statement inif
blocks withoutelse
.new Array()
.Buffer.from()
andBuffer.alloc()
instead of the deprecatednew Buffer()
.null
literal.process.exit()
.then
property.this
to a variable.undefined
usingtypeof
.Promise.resolve/reject()
in async functions or promise callbacksundefined
..addEventListener()
and.removeEventListener()
overon
-functions..find(…)
and.findLast(…)
over the first or last element from.filter(…)
.Array#flat()
over legacy techniques to flatten arrays..flatMap(…)
over.map(…).flat()
.Array#{indexOf,lastIndexOf}()
overArray#{findIndex,findLastIndex}()
when looking for the index of an item..some(…)
over.filter(…).length
check and.{find,findLast}(…)
..at()
method for index access andString#charAt()
.Blob#arrayBuffer()
overFileReader#readAsArrayBuffer(…)
andBlob#text()
overFileReader#readAsText(…)
.String#codePointAt(…)
overString#charCodeAt(…)
andString.fromCodePoint(…)
overString.fromCharCode(…)
.Date.now()
to get the number of milliseconds since the Unix Epoch.Node#append()
overNode#appendChild()
..dataset
on DOM elements over calling attribute methods.childNode.remove()
overparentNode.removeChild(childNode)
..textContent
over.innerText
.EventTarget
overEventEmitter
.export…from
when re-exporting..includes()
over.indexOf()
andArray#some()
when checking for existence or non-existence.KeyboardEvent#key
overKeyboardEvent#keyCode
.Math.trunc
instead of bitwise operators..before()
over.insertBefore()
,.replaceWith()
over.replaceChild()
, prefer one of.before()
,.after()
,.append()
or.prepend()
overinsertAdjacentText()
andinsertAdjacentElement()
.Math
APIs over legacy patterns.String
,Number
,BigInt
,Boolean
, andSymbol
directly..length - index
when possible.node:
protocol when importing Node.js builtin modules.Number
static properties over global ones.Object.fromEntries(…)
to transform a list of key-value pairs into an object.catch
binding parameter..querySelector()
over.getElementById()
,.querySelectorAll()
over.getElementsByClassName()
and.getElementsByTagName()
.Reflect.apply()
overFunction#apply()
.RegExp#test()
overString#match()
andRegExp#exec()
.Set#has()
overArray#includes()
when checking for existence or non-existence.Set#size
instead ofArray#length
.Array.from(…)
,Array#concat(…)
,Array#{slice,toSpliced}()
andString#split('')
.String#replaceAll()
over regex searches with the global flag.String#slice()
overString#substr()
andString#substring()
.String#startsWith()
&String#endsWith()
overRegExp#test()
.String#trimStart()
/String#trimEnd()
overString#trimLeft()
/String#trimRight()
.switch
over multipleelse-if
.if-else
statements.TypeError
in type checking conditions.Array#join()
.Number#toFixed()
.targetOrigin
argument withwindow.postMessage()
.case
clauses.new
when throwing an error.Beta Was this translation helpful? Give feedback.
All reactions