Convert Chai test assertions to Jest.
Grit comes with 58 out of the box patterns that can be leveraged immediately.
Migration patterns can be used to automatically migrate you to a new framework or library.
Converts function expressions to ES6 arrow functions
Converts CommonJS module.exports
to ES6-style exports.
Migrate from the legacy Hathora Cloud SDK to the TypeScript SDK.
Knockout.js is an older JavaScript framework that is still used by many developers. This migration helps with migrating your Knockout code to React.
Upgrade the Mux SDK to v8 with Stainless
Upgrade the OpenAI SDK to v4 following this guide.
Switch the OpenAI JS/TS SDK to use OpenRouter.
This pattern converts React class components to functional components, with hooks.
These patterns can autofix many common JavaScript mistakes, including issues that eslint doesn't fix automatically.
Add any
type annotation to caught errors. It is a common source of tsc errors.
The group_blocks
function takes a target
list and returns a list of lists, where each sublist is a block of items that are adjacent to each other in the original program.
If a PureComponent
has the shouldComponentUpdate
method, convert it to a regular Component
.
Convert any equality check with -0
to the more precise Object.is
.
Convert non-strict equality checking, using ==
, to the strict version, using ===
.
Converts ES6-style import
to require
statements.
Use explicit conversions between types, e.g., '' + x
=> String(s)
.
Files containing JSX should have a .jsx extension.
If a for
counter moves in the wrong direction the loop will run infinitely. Mostly, an infinite for
loop is a typo and causes a bug.
Grit includes standard patterns for declaratively adding, removing, and updating imports.
ES7 introduced the includes
method for arrays so bitwise and comparisons to -1
are no longer needed.
Replaces innerHtml
with innerText
, which is safer in most cases.
expect.arrayContaining
can be used to validate an array containing multiple different elements, so multiple statements are not required.
Replaces export default function () { }
with export default function main () { }
and export default () => { }
with const main = () => { }; export default main
The literal notation avoids the single-argument pitfall or the Array global being redefined.
The Promise is already executed asynchronously and exceptions thrown by the function will be lost.
Bitwise operators &
or |
are often used by mistake instead of &&
or ||
, which can cause unexpected errors.
arguments.caller
and arguments.called
have been deprecated.
Remove unreachable code found after return
/ throw
/ continue
or break
statements.
The code in production should not contain a debugger
. It causes the browser to stop executing the code and open the debugger.
Comparing to null
needs a type-checking operator (=== or !==), to avoid incorrect results when the value is undefined
.
Use _iterator_
instead of __iterator__
. __iterator__
is obsolete and is not implemented by all browsers.
The {}
literal form is a more concise way of creating an object.
Calling Symbol
with the new
operator throws a TypeError
exception.
Call hasOwnProperty
, isPrototypeOf
, propertyIsEnumerable
methods only from Object.prototype
.
Otherwise it can cause errors.
This rule hoists the assignments out of return
. Does not apply when assignment is wrapped in parentheses.
It is a good practice to throw Error
objects on exceptions because they automatically keep track of where they were created.
Negates key
instead of the entire expression, which is likely a bug.
Prefer natural language style conditions in favour of Yoda style conditions.
Convert comparisons to NaN
(e.g., x == NaN
) to use isNaN
(e.g., isNaN(x)
).
Components without children can be self-closed to avoid unnecessary extra closing tag.
Some template engines allow disabling HTML escaping, which can allow XSS vulnerabilities.
If the noAssert
flag is set, offset
can go beyond the end of the Buffer
, which is a security vulnerability.
Remove the shouldComponentUpdate
method from PureComponent
. PureComponent
already has an implementation.
ES7 introduced the exponentiation operator **
so that using Math.pow
is no longer necessary.
* Patterns with an asterisk are in private alpha with select customers.