ESLint
Summary
Adds a linting setup to the TypeScript setup using ESLint, based on standardjs and prettier.
We will now add a linting setup to our TypeScript library, for which we will need the following packages:
Using Prettier from within ESLint is no longer recommended. Also, newer versions of ESLint (>= 8) support a new configuration style, which will be the enforced starting with version 9.
I will update this soonâ„¢
eslint
: the binaries doing the actual linting.eslint-config-standard-with-typescript
: an opinionated set of rules to follow the JavaScript Standard Style, including TypeScript support.eslint-plugin-react
: react-specific ESLint rules.eslint-plugin-prettier
: let's us run Prettier as part of ESLint. Prettier takes care of things like line lengths etc.eslint-config-prettier
: in order to avoid clashes between ESLint end Prettier, this config overwrites all ESLint rules that would clash with prettier.
Now, we can set up an .eslintrc.js
:
A couple of notes on the config:
- We don't want to lint the build artifacts, so we add
dist
to theignorePatterns
. - In addition to
react/recommended
, we also includereact/jsx-runtime
, as we're using the new JSX runtime as of React 17. react/prop-types
is turned off as the props are typed through TypeScript.no-use-before-define
: we want to use the TypeScript version, so we turn off the JavaScript one.
Yes, configuring ESLint is currently quite uncomfortable. There will be a new config format soon, but as of now it's still experimental and many libraries (like @typescript-eslint
) don't support it, yet.