-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add eslint-graph-config package
Signed-off-by: Tomás Migone <[email protected]>
- Loading branch information
Showing
8 changed files
with
572 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
"packageManager": "[email protected]", | ||
"workspaces": [ | ||
"packages/contracts", | ||
"packages/eslint-graph-config", | ||
"packages/subgraph-service", | ||
"packages/sdk" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# eslint-graph-config | ||
|
||
This repository contains shared linting and formatting rules for TypeScript projects. | ||
|
||
## Installation | ||
|
||
```bash | ||
yarn add --dev eslint eslint-graph-config | ||
``` | ||
|
||
For projects on this monorepo, you can use the following command to install the package: | ||
|
||
```bash | ||
yarn add --dev eslint eslint-graph-config@workspace:^x.y.z | ||
``` | ||
|
||
To enable the rules, you need to create an `eslint.config.js` file in the root of your project with the following content: | ||
|
||
```javascript | ||
import eslintGraphConfig from 'eslint-graph-config' | ||
export default eslintGraphConfig | ||
``` | ||
|
||
## Tooling | ||
|
||
This package uses the following tools: | ||
- [ESLint](https://eslint.org/) as the base linting tool | ||
- [typescript-eslint](https://typescript-eslint.io/) for TypeScript support | ||
- [ESLint Stylistic](https://eslint.style/) as the formatting tool | ||
|
||
**Why no prettier?** | ||
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). | ||
|
||
## VSCode support | ||
|
||
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. | ||
|
||
The following settings should be added to your `settings.json` file: | ||
```json | ||
{ | ||
"editor.defaultFormatter": "dbaeumer.vscode-eslint", | ||
"eslint.format.enable": true, | ||
"eslint.experimental.useFlatConfig": true, | ||
"eslint.workingDirectories": [{ "pattern": "./packages/*/" }] | ||
} | ||
``` | ||
|
||
Additionally you can configure the `Format document` keyboard shortcut to run `eslint --fix` on demand. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This file only exists to enable linting on index.js | ||
import config from './index.js' | ||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// @ts-check | ||
|
||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
|
||
import eslint from '@eslint/js' | ||
import noOnlyTests from 'eslint-plugin-no-only-tests' | ||
import noSecrets from 'eslint-plugin-no-secrets' | ||
import stylistic from '@stylistic/eslint-plugin' | ||
import tseslint from 'typescript-eslint' | ||
|
||
export default tseslint.config( | ||
// Base eslint configuration | ||
// @ts-expect-error tseslint doesn't recognize eslint types for some reason | ||
eslint.configs.recommended, | ||
|
||
// Enable linting with type information | ||
// https://typescript-eslint.io/getting-started/typed-linting | ||
...tseslint.configs.recommendedTypeChecked, | ||
{ | ||
languageOptions: { | ||
parserOptions: { | ||
project: true, | ||
tsconfigRootDir: import.meta.dirname, | ||
}, | ||
}, | ||
}, | ||
|
||
// Formatting and stylistic rules | ||
stylistic.configs['recommended-flat'], | ||
|
||
// Custom rules | ||
{ | ||
plugins: { | ||
'no-only-tests': noOnlyTests, | ||
'no-secrets': noSecrets, | ||
}, | ||
rules: { | ||
'prefer-const': 'warn', | ||
'@typescript-eslint/no-inferrable-types': 'warn', | ||
'@typescript-eslint/no-empty-function': 'warn', | ||
'no-only-tests/no-only-tests': 'error', | ||
'no-secrets/no-secrets': 'error', | ||
'sort-imports': [ | ||
'warn', { | ||
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], | ||
ignoreCase: true, | ||
allowSeparatedGroups: true, | ||
}], | ||
}, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "eslint-graph-config", | ||
"version": "0.0.1", | ||
"description": "Linting and formatting rules for The Graph's TypeScript projects", | ||
"main": "index.js", | ||
"type": "module", | ||
"author": "The Graph Team", | ||
"license": "GPL-2.0-or-later", | ||
"devDependencies": { | ||
"@stylistic/eslint-plugin": "^1.6.2", | ||
"eslint": "^8.56.0", | ||
"eslint-plugin-no-only-tests": "^3.1.0", | ||
"eslint-plugin-no-secrets": "^0.8.9", | ||
"typescript": "^5.3.3", | ||
"typescript-eslint": "^7.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"resolveJsonModule": true | ||
} | ||
} |
Oops, something went wrong.