|
| 1 | +# eslint-graph-config |
| 2 | + |
| 3 | +This repository contains shared linting and formatting rules for TypeScript projects. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +yarn add --dev eslint eslint-graph-config |
| 9 | +``` |
| 10 | + |
| 11 | +For projects on this monorepo, you can use the following command to install the package: |
| 12 | + |
| 13 | +```bash |
| 14 | +yarn add --dev eslint eslint-graph-config@workspace:^x.y.z |
| 15 | +``` |
| 16 | + |
| 17 | +To enable the rules, you need to create an `eslint.config.js` file in the root of your project with the following content: |
| 18 | + |
| 19 | +```javascript |
| 20 | +const config = require('eslint-graph-config') |
| 21 | +module.exports = config.default |
| 22 | + ``` |
| 23 | + |
| 24 | +**Recommended config for existing projects** |
| 25 | +The default configuration is quite strict specially with the usage of `any` and it's derivatives. For existing projects with a codebase that was developed with more lenient guidelines migrating to this configuration can be a bit overwhelming. |
| 26 | + |
| 27 | +You can customize your `eslint.config.js` file to disable some rules and make the transition easier. For example, you can create a `eslint.config.js` file with the following content: |
| 28 | + |
| 29 | +```javascript |
| 30 | +const config = require('eslint-graph-config') |
| 31 | + |
| 32 | +module.exports = [ |
| 33 | + ...config.default, |
| 34 | + { |
| 35 | + rules: { |
| 36 | + '@typescript-eslint/no-unsafe-assignment': 'off', |
| 37 | + '@typescript-eslint/no-var-requires': 'off', |
| 38 | + '@typescript-eslint/no-unsafe-call': 'off', |
| 39 | + '@typescript-eslint/no-unsafe-member-access': 'off', |
| 40 | + '@typescript-eslint/no-unsafe-argument': 'off', |
| 41 | + }, |
| 42 | + }, |
| 43 | +] |
| 44 | +``` |
| 45 | + |
| 46 | +## Tooling |
| 47 | + |
| 48 | +This package uses the following tools: |
| 49 | +- [ESLint](https://eslint.org/) as the base linting tool |
| 50 | +- [typescript-eslint](https://typescript-eslint.io/) for TypeScript support |
| 51 | +- [ESLint Stylistic](https://eslint.style/) as the formatting tool |
| 52 | + |
| 53 | +**Why no prettier?** |
| 54 | +Instead of prettier we use ESLint Stylistic which is a set of ESLint rules focused on formatting and styling code. As opposed to prettier, ESLint Stylistic runs entirely within ESLint and does not require a separate tool to be run (e.g. `prettier`, `eslint-plugin-prettier` and `eslint-config-prettier`). Additionally it's supposed to be [more efficient](https://eslint.style/guide/why#linters-vs-formatters) and [less opinionated](https://antfu.me/posts/why-not-prettier). |
| 55 | + |
| 56 | +## VSCode support |
| 57 | + |
| 58 | +If you are using VSCode you can install the [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) to get real-time linting and formatting support. |
| 59 | + |
| 60 | +The following settings should be added to your `settings.json` file: |
| 61 | +```json |
| 62 | +{ |
| 63 | + "editor.defaultFormatter": "dbaeumer.vscode-eslint", |
| 64 | + "eslint.format.enable": true, |
| 65 | + "eslint.experimental.useFlatConfig": true, |
| 66 | + "eslint.workingDirectories": [{ "pattern": "./packages/*/" }] |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +Additionally you can configure the `Format document` keyboard shortcut to run `eslint --fix` on demand. |
0 commit comments