1.1.0 • Published 3 years ago
@wayofdev/eslint-config v1.1.0
Eslint Config
Shareable eslint configuration.
Install
# install with yarn
$ yarn add -D @wayofdev/eslint-config
# install with pnpm
$ pnpm add -Dw @wayofdev/eslint-configUsage
.eslintrc.js
JS
module.exports = {
extends: '@wayofdev/eslint-config',
};TS
module.exports = {
extends: '@wayofdev/eslint-config/ts',
};Jest
module.exports = {
extends: '@wayofdev/eslint-config/jest',
};Extending
An example configuring a mixed JS/TS, tsconfig-compatible configuration.
.eslintrc.js
module.exports = {
// ignore linting in dist bundle output folder
ignorePatterns: ['dist/**'],
// enable global variables
env: {
browser: true,
node: true,
jest: true,
},
overrides: [
{
files: ['**/*.ts'],
extends: [
'@wayofdev/eslint-config/ts',
// add jest linting
'@wayofdev/eslint-config/jest',
],
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
},
},
{
files: ['**/*.js'],
extends: [
'@wayofdev/eslint-config',
// add jest linting
'@wayofdev/eslint-config/jest',
],
},
],
};Add an NPM Script
Running this command:
# using yarn, npm
$ npm pkg set scripts.lint:js="eslint --fix **/*.{js,jsx,ts,tsx}"
# using pnpm
$ pnpm pkg set scripts.lint:js="eslint --fix **/*.{js,jsx,ts,tsx}"Will create:
package.json
...
"scripts": {
...
"lint:js": "eslint --fix **/*.{js,jsx,ts,tsx}"
...
},
...Add a Pre-commit Hook
lint-staged.config.js
module.exports = {
'*.{js,jsx,ts,tsx}': ['prettier --cache --write', 'eslint --cache --fix'],
};Under The Hood
index.js
- Plugins
eslint-plugin-prettier
- Parser
- default
eslintparser
- default
- Extends
eslint-plugin-unicorneslint-plugin-promiseeslint-plugin-sonarjseslint-plugin-security,- default
eslintruleset eslint-config-airbnb-baseeslint-config-prettier
- Rules
- Prettier Special Rules
- Other rules can be found in the config
ts.js
- Plugins
@typescript-eslint/eslint-plugineslint-plugin-prettier
- Parser
@typescript-eslint/parser
- Extends
eslint-plugin-unicorneslint-plugin-promiseeslint-plugin-sonarjseslint-plugin-security,@typescript-eslint/eslint-plugineslint-config-airbnb-typescripteslint-config-prettier
- Rules
- Prettier Special Rules
- Other rules can be found in the config
jest.js
- Plugins
jestjest-domjest-formatting
- Extends
plugin:jest/recommendedplugin:jest-dom/recommendedplugin:jest-formatting/recommended
License
MIT