@appleute/eslint-config v2.0.2
Appleute ESLint Config
Shared ESLint configs for Node, Web, React Native, and Expo projects.
Stack | Config |
---|---|
Server NestJS (experimental) | @appleute/eslint-config/server-nest-experimental |
Node | @appleute/eslint-config/node |
React Native | @appleute/eslint-config/native |
Web (experimental) | @appleute/eslint-config/web-experimental |
Web | @appleute/eslint-config/web |
Web (NextJS experimental) | @appleute/eslint-config/web-next-experimental |
Web (NextJS) | @appleute/eslint-config/web-next |
Usage
Configuration
New project
Install this package and peer dependencies
yarn add -D eslint prettier @appleute/eslint-config
Existing project
Install this package and update peer dependencies
yarn add -D eslint@latest prettier@latest @appleute/eslint-config
This package already inclues eslint plugins and configs, so you can remove them if you have them installed.
yarn remove @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-next eslint-config-universe eslint-plugin-unused-imports
@appleute/eslint-config@^2 has strict type checks, if this breaks your existing project completely the use @appleute/eslint-config@1 for now.
Configure ESLint
Import this config into your own ESLint configuration using the extends option. ESLint checks both package.json and .eslintrc.* files for its configuration:
There is no need to configure both package.json and .eslintrc.js, any one will do.
Either add this to package.json
{
"eslintConfig": {
"extends": "@appleute/eslint-config/web"
}
}
or create .eslintrc.js
with the following lines
module.exports = {
extends: "@appleute/eslint-config/web",
};
Configure Prettier
You can import the default prettier config used by the package into yours.
.prettierrc.js
const prettierRc = require("@appleute/eslint-config/.prettierrc.js");
module.exports = {
...prettierRc,
};
.prettierignore
You can copy the .prettierignore
file as is from the package.
cp node_modules/@appleute/eslint-config/.prettierignore .
Commit hooks
Setup a pre-commit hook using husky and lint-staged to automatically lint and prettify before commit.
1. Install husky and lint staged
yarn add -D husky lint-staged
2. Configure package.json
{
...
"scripts": {
...
"postinstall": "husky install"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown",
"**/*.{js,ts,jsx,tsx}": "eslint --fix"
},
}
3. Add pre-commit hook
npx husky install
npx husky add .husky/pre-commit "npx lint-staged"
Format on save
In VS Code, you can enable format on save by adding this config to the file .vscode/settings.json
at the root of your repository.
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
Develop
Publish
Use npm version to increment major, minor or patch version
Then publish using:
npm publish