⚙️ My preferred configs for CommitLint, ESLint, MarkdownLint, Prettier, and TypeScript.
Install this package, husky, and lint-staged as a dev dependencies:
npm install --save-dev @joncursi/eslint-config husky lint-staged
Configure husky by adding the following to your package.json
file:
...
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
...
To configure CommitLint, create a
commitlint.config.js
file in the root of your project that contains the
following:
/**
* @prettier
*/
// eslint-disable-next-line immutable/no-mutation
module.exports = require('@joncursi/eslint-config/commitlint.config');
This will allow CommitLint to discover the configuration this repository
provides from within your node_modules
folder.
Next, add the following to your package.json
file so that CommitLint will
check for infractions in your commit messages every time you create a new
commit:
...
"husky": {
"hooks": {
...
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
...
}
},
...
To configure ESLint, add the following to your
package.json
file. This will allow ESLint to discover the configuration this
repository provides from within your node_modules
folder, and will check
your *.js
, *.ts
, and *.tsx
files for infractions every time you create a
new commit:
...
"eslintConfig": {
...
"extends": [
...
"@joncursi/eslint-config",
...
],
...
},
...
"lint-staged": {
...
"*.{js,ts,tsx}": "eslint",
...
},
...
To configure MarkdownLint, add the
following to your package.json
file. This will allow MarkdownLint to discover
the configuration this repository provides from within your node_modules
folder, and will check your *.md
files for infractions every time you create
a new commit:
...
"lint-staged": {
...
"*.{md}": "markdownlint --config node_modules/@joncursi/eslint-config/markdownlint.config.json",
...
},
...
To configure prettier, create a prettier.config.js
file in the root of your project that contains the following:
/**
* @prettier
*/
// eslint-disable-next-line immutable/no-mutation
module.exports = require('@joncursi/eslint-config/prettier.config');
This will allow Prettier to discover the configuration this repository
provides from within your node_modules
folder.
Next, add the following to your package.json
file so that prettier will check
your files for infractions every time you create a new commit:
...
"lint-staged": {
...
"*.{js,json,md,ts,tsx}": [
"prettier --write",
"git add"
]
...
},
...
To configure TypeScript, add the following
to your tsconfig.json
file. This will allow TypeScript to discover the
configuration this repository provides from within your node_modules
folder:
...
"extends": "node_modules/@joncursi/eslint-config/tsconfig.json",
...
To check for infractions in this codebase, run:
npm test