@kevinwolf/eslint-config v0.2.4
🤔 Problem
I share almost the same ESLint configuration between all my projects, with variations depending if the project uses typescript, jest, react, etc. Whenever a new configuration or plugin gets upgraded, I have to go through all the projects and upgrade the dependencies.
🤓 Solution
This opinionated ESLint configuration automatically detects what dependencies my project depends on and dynamically generates configs, plugins and rules configuration. So now my projects rather than depending on a lot of eslint-* packages, only depends on this one.
📚 Table of Contents
- ⬇️ Installation
- 📝 Usage
- 📦 What's included?
- 📄 License
⬇️ Installation
Add this package to the devDependencies section of your package.json. Since this package is part of a Yarn workspaces powered monorepo, I encourage you to install it via yarn.
yarn add -D @kevinwolf/eslint-config📝 Usage
ESLint config file
Create a new .eslintrc.js file on the root of your project and just extend my configuration.
module.exports = {
extends: "@kevinwolf"
};package.json script
Add a new script to your package.json in order to run eslint.
{
"scripts": {
"lint": "eslint . --ext .ts,.tsx,.js,.jsx"
}
}NOTE: Since this package has an explicit dependency on eslint and the supporting packages, you won't need to install them separately.
Auto formatting
You get auto formatting out-of-the-box if your code editor supports eslint formatting or you have prettier configured to format using ESLint rules.
Overriding configuration
Thanks to the awesome config system of ESLint, you can override any rule, add extra plugins and whatever you want on the same .eslintrc.js file.
📦 What's included?
The generated rules vary depending on your project type, they can and will be combined depending on your dependencies.
Vanilla JS
All projects will inherit this configurations, except on typescript projects, on which the parser will be different.
parser
babel-eslint
extends
airbnb-baseplugin:prettier/recommended
plugins
prettier
env
es6node
import/resolver plugin settings
- Allows importing
.jsfiles - Allows absolute imports from
srcfolder
Rules
no-console: generates warning when usingconsoleno-use-before-define: generates error when using a variable before its definition. It won't display an error when using a function before its definitionimport/prefer-default-export: offprettier/prettier: enforces parenthesis on all arrow function arguments, disables the use of semicolons, enforces single quote and enforces adding a trailing comma for multiline arrays and objects
Jest
This rules will apply if you have jest installed as a devDependency.
env
jest
TypeScript
This rules will apply if you have typescript installed as a devDependency.
parser
@typescript-eslint/parser
extends
plugin:@typescript-eslint/recommendedprettier/@typescript-eslint
plugins
@typescript-eslint
import/resolver plugin settings
- Allows importing
.tsfiles
rules
@typescript-eslint/explicit-function-return-type: disabled@typescript-eslint/no-unused-vars: error when broken@typescript-eslint/no-use-before-define: disabled
React
This rules will apply if you have react installed in any dependency group.
extends
airbnbprettier/react
plugins
reactreact-hooks
env
browser(ifreact-domis installed in any dependency group)
import/resolver plugin settings
- Allows importing
.jsxfiles
rules
react/jsx-filename-extension: only allows jsx on.jsxfilesreact/prop-types: will throw error if not checking the prop typesreact-hooks/exhaustive-deps: error when brokenreact-hooks/rules-of-hooks: error when broken
React with TypeScript
This rules will apply if you have react installed in any dependency group and typescript installed as a devDependency.
import/resolver plugin settings
- Allows importing
.tsxfiles
rules
react/jsx-filename-extension: only allows jsx on.jsxand.tsxfiles
React Native
This rules will apply if you have react-native installed in any dependency group.
plugins
react-native
env
react-native/react-native
import/resolver plugin settings
- Allows importing
.native.js,.android.js,.ios.js,.native.jsx,.android.jsxand.ios.jsxfiles
React Native with TypeScript
This rules will apply if you have react-native installed in any dependency group and typescript installed as a devDependency.
import/resolver plugin settings
- Allows importing
.native.ts,.android.ts,.ios.ts,.native.tsx,.android.tsxand.ios.tsxfiles