eslint-config-mbuchalik
v1.2.2
Published
An opinionated ESLint config
Downloads
9
Maintainers
Readme
This is an opinionated set of ESLint rules.
Usage
The following steps need to be performed in order to use this package:
- Install the package
- Create a
.prettierrc.js
file - Create a
.eslintrc.js
file - Update your
tsconfig.json
file - (Optional) Add a lint script to
package.json
- (Optional) Install VSCode extensions
1. Install the package
First, install this package:
npm install --save-dev eslint-config-mbuchalik
2. Create the .prettierrc.js
file
Create a .prettierrc.js
file in the root of your project. The content of this file:
module.exports = require('eslint-config-mbuchalik/.prettierrc.js');
3. Create the .eslintrc.js
file
Next to your Prettier file, create a file called .eslintrc.js
. For a regular TypeScript-only project, use the following config:
module.exports = {
root: true,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
overrides: [
{
files: ['*.ts'],
extends: ['eslint-config-mbuchalik'],
},
],
};
For a TypeScript+React project, use the following config:
module.exports = {
root: true,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
overrides: [
{
files: ['*.ts', '*.tsx'],
extends: ['eslint-config-mbuchalik/react'],
},
],
};
Tip: If you want to lint a specific directory only (e.g. only a src/
directory), add the following:
module.exports = {
root: true,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
+ // Ignore all folders except for '/src'.
+ ignorePatterns: ['/*', '!/src'],
overrides: [
{
files: ['*.ts'],
extends: ['eslint-config-mbuchalik'],
},
],
};
4. Update your tsconfig.json
file
Make sure that your tsconfig.json
file contains the following settings:
{
"compilerOptions": {
"strict": true,
"noImplicitOverride": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true
// Other project-specific settings.
}
}
5. (Optional) Add a lint script to package.json
Often, you want to be able to lint your files by running a CLI command. This is particularly useful in CI environments. To do so, add the following to your package.json
:
{
"scripts": {
"lint": "eslint . --max-warnings=0"
}
}
6. (Optional) Install VSCode extensions
Are you using VSCode? If so, then it is recommended to install the following extensions:
Tip: You can enable auto formatting on save by creating a .vscode/settings.json
file with the following content:
{
"eslint.validate": ["typescript"],
"typescript.preferences.importModuleSpecifier": "relative",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": { "source.fixAll.eslint": true }
}
Development
Are you working on your own fork of this project? Great! The following is a (very short) guide that might help you with you development setup.
First, fork this project and install all npm dependencies.
Now, you can apply your intended changes to the ESLint config files. The files are called index.js
(for the TypeScript-only project) and react.js
(for the TypeScript+React project).
Once you are happy with your changes, it is highly recommend to test them locally. To do so, create a new project outside the folder of eslint-config-mbuchalik
. In the following, we call this project test-project
. Now perform the following steps:
- In the
eslint-config-mbuchalik
folder, runnpm pack
. This will create a file ending on.tgz
. The generated file is pretty much the same you get when pulling from a registry. - In
test-project
, runnpm install --save-dev ../eslint-config-mbuchalik/eslint-config-mbuchalik-<version>.tgz
. In this command, you need to replace<version>
with the actual version of the package. Also, it might be necessary to adjust the relative file path. - Now, you can use the package as if it was installed from an actual registry.
- Tip: If you make changes and need to rerun
npm pack
and all other steps, you might get an error regarding package integrity when runningnpm install
intest-project
. This is an expected error, because the hash of the package changes. A pretty easy solution to this is to remove the reference toeslint-config-mbuchalik
frompackage.json
intest-project
, then to runnpm install
, and then to re-install the package. If you need to do this frequently, you could also symlink the package, but that might require you to install peer dependencies manually.