Skip to content

Commit

Permalink
feat: add @rightcapital/eslint-config that supports ESLint v9
Browse files Browse the repository at this point in the history
resolves #128
  • Loading branch information
frantic1048 committed Oct 11, 2024
1 parent 11f0390 commit 614f250
Show file tree
Hide file tree
Showing 55 changed files with 8,768 additions and 1,241 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

47 changes: 0 additions & 47 deletions .eslintrc.cjs

This file was deleted.

79 changes: 67 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,68 @@ Following tools are covered:

## ESLint

This repo provides the following ESLint config packages:
### Prerequisite

- `eslint`(>=9)
- `typescript`(optional, for TypeScript support)

### Usage

Install `@rightcapital/eslint-config` to your project.

```sh
pnpm add -D @rightcapital/eslint-config
```

In your `eslint.config.mjs`([or equivalent](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file-formats)):

```js
import eslintConfigRightcapital from '@rightcapital/eslint-config';

const { config } = eslintConfigRightcapital.utils;

export default config(
...eslintConfigRightcapital.configs.recommended,

// add more configs for specific files or packages if needed
{
files: ['scripts/**/*.{js,cjs,mjs}'],
extends: [
...eslintConfigRightcapital.configs.node,
...eslintConfigRightcapital.configs.script,
],
},
);
```

### Exported configs and utils

**`configs`**

- `recommended`: the all-in-one config, contains multiple rules configs for different files.

> [!NOTE]
> The following configs are designed to be used with `extends` option. They do have a preset [`files` option](https://eslint.org/docs/latest/use/configure/configuration-files#:~:text=files%20%2D%20An%20array%20of%20glob%20patterns%20indicating%20the%20files%20that%20the%20configuration%20object%20should%20apply%20to.%20If%20not%20specified%2C%20the%20configuration%20object%20applies%20to%20all%20files%20matched%20by%20any%20other%20configuration%20object.).
- `js`: JavaScript specific config.
- `ts`: TypeScript specific config.
- `react`: React specific config.
- `node`: Node.js specific config.
- `script`: Script oriented config, with less strict rules.

**`utils`**

- `config`: reexported util from `typescript-eslint` for easier compositing ESLint config. (docs: https://typescript-eslint.io/packages/typescript-eslint#config)
- `globals`: reexported util from [globals](https://github.com/sindresorhus/globals), useful for configuring [`languageOptions.globals`](https://eslint.org/docs/latest/use/configure/language-options#specifying-globals).

---

<details>
<summary>
<b>[Deprecated]</b> Usage for Legacy ESLint versions(&lt;9)
</summary>

There are following config packages for legacy ESLint versions(<9):

- `@rightcapital/eslint-config-javascript`: for JavaScript files
- `@rightcapital/eslint-config-typescript`: for TypeScript files
Expand All @@ -31,13 +92,6 @@ This repo provides the following ESLint config packages:

They can be used independently or combined together according to your project's needs.

### Usage

> [!NOTE]
> make sure `eslint` is installed in your project.
>
> And install `typescript` to your project if you want to use the config supporting TypeScript(`@rightcapital/eslint-config-typescript*`).
Install the config package(s) you need:

```sh
Expand Down Expand Up @@ -133,15 +187,16 @@ module.exports = {
};
```

</details>
</details>

## Prettier

### Usage
### Prerequisite

> Note: Prettier is a peer dependency of the config package. You need to install it in the root of your project.
>
> See: https://prettier.io/docs/en/install.html
- `prettier`

### Usage

Install config package to your project:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "feat: add `@rightcapital/eslint-config` that supports ESLint v9",
"packageName": "@rightcapital/eslint-config-base",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "major",
"comment": "feat: add `@rightcapital/eslint-config` that supports ESLint v9",
"packageName": "@rightcapital/eslint-config",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "feat: add `@rightcapital/eslint-config` that supports ESLint v9",
"packageName": "@rightcapital/eslint-config-javascript",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "feat: add `@rightcapital/eslint-config` that supports ESLint v9",
"packageName": "@rightcapital/eslint-config-typescript",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "feat: add `@rightcapital/eslint-config` that supports ESLint v9",
"packageName": "@rightcapital/eslint-config-typescript-react",
"email": "[email protected]",
"dependentChangeType": "none"
}
61 changes: 61 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import eslintConfigRightcapital from '@rightcapital/eslint-config';
import eslintPluginEslintPlugin from 'eslint-plugin-eslint-plugin';

const { config } = eslintConfigRightcapital.utils;

export default config(
{
/**
* NOTE:
* DO NOT put any other keys other than `ignores` in this object.
* see: https://eslint.org/docs/latest/use/configure/configuration-files#globally-ignoring-files-with-ignores
*/
ignores: [
// build output
'packages/*/lib',
'.github/actions/*/dist',

// E2E tests, they contains individual lint config and specific ESLint dependencies
'specs',
],
},
...eslintConfigRightcapital.configs.recommended,

// scripts
{
files: [
'packages/*/*.{js,cjs,mjs,ts,cts,mts}', // each package's top-level directory files
'scripts/**/*.{js,cjs,mjs}',
'.github/actions/**/*.{js,cjs,mjs}',
],
extends: [
...eslintConfigRightcapital.configs.script,
...eslintConfigRightcapital.configs.node,
],
},

// -----------------------
// package specific rules
// -----------------------

// @rightcapital/eslint-plugin
{
files: ['packages/eslint-plugin/**/*.ts'],
extends: [eslintPluginEslintPlugin.configs['flat/recommended']],
},
{
files: ['packages/eslint-plugin/src/helpers/test/*.ts'],
rules: {
'import-x/no-extraneous-dependencies': [
'error',
{ devDependencies: true },
],
},
},

// @rightcapital/lint-eslint-config-rules
{
files: ['packages/lint-eslint-config-rules/**/*.ts'],
extends: [...eslintConfigRightcapital.configs.script],
},
);
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@
"@commitlint/cli": "19.5.0",
"@commitlint/config-conventional": "19.5.0",
"@commitlint/cz-commitlint": "19.5.0",
"@rightcapital/eslint-config-javascript": "workspace:*",
"@rightcapital/eslint-config-typescript": "workspace:*",
"@rightcapital/eslint-config": "workspace:*",
"@rightcapital/prettier-config": "workspace:*",
"@rightcapital/scripts": "workspace:*",
"@types/node": "20.16.5",
"beachball": "2.47.1",
"commitizen": "4.3.0",
"concurrently": "9.0.1",
"eslint": "8.57.1",
"eslint": "9.12.0",
"eslint-plugin-eslint-plugin": "6.2.0",
"execa": "9.4.0",
"husky": "9.1.6",
Expand Down
6 changes: 4 additions & 2 deletions packages/eslint-config-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
"devDependencies": {
"@rightcapital/tsconfig": "workspace:*",
"@types/confusing-browser-globals": "1.0.3",
"@types/semver": "7.5.8"
"@types/eslint": "8.56.10",
"@types/semver": "7.5.8",
"eslint": "8.57.1"
},
"peerDependencies": {
"eslint": "^8.23.1 || ^9.0.0"
"eslint": "^8.23.1"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-config-javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"@rushstack/eslint-patch": "1.10.4"
},
"devDependencies": {
"@rightcapital/tsconfig": "workspace:*"
"@rightcapital/tsconfig": "workspace:*",
"@types/eslint": "8.56.10",
"eslint": "8.57.1"
},
"peerDependencies": {
"eslint": "^8.23.1"
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-config-typescript-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"eslint-plugin-react-hooks": "4.6.2"
},
"devDependencies": {
"@rightcapital/tsconfig": "workspace:*"
"@rightcapital/tsconfig": "workspace:*",
"@types/eslint": "8.56.10",
"eslint": "8.57.1"
},
"peerDependencies": {
"eslint": "^8.57.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-config-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"eslint-config-prettier": "9.1.0"
},
"devDependencies": {
"@rightcapital/tsconfig": "workspace:*"
"@rightcapital/tsconfig": "workspace:*",
"@types/eslint": "8.56.10",
"eslint": "8.57.1"
},
"peerDependencies": {
"eslint": "^8.23.1",
Expand Down
63 changes: 63 additions & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@rightcapital/eslint-config",
"version": "36.3.0",
"description": "ESLint Config for RightCapital",
"repository": {
"type": "git",
"url": "https://github.com/RightCapitalHQ/frontend-style-guide.git",
"directory": "packages/eslint-config"
},
"license": "MIT",
"type": "module",
"exports": "./lib/index.js",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib"
],
"scripts": {
"prebuild": "pnpm run clean",
"build": "tsc --build",
"clean": "tsc --build --clean",
"prepack": "pnpm run build"
},
"dependencies": {
"@eslint-react/eslint-plugin": "1.9.0",
"@rightcapital/eslint-plugin": "workspace:*",
"@stylistic/eslint-plugin": "2.9.0",
"@typescript-eslint/utils": "8.0.1",
"confusing-browser-globals": "1.0.11",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-import-x": "4.3.1",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-lodash": "8.0.0",
"eslint-plugin-n": "17.10.2",
"eslint-plugin-react-hooks": "4.6.2",
"eslint-plugin-simple-import-sort": "12.1.1",
"eslint-plugin-unicorn": "55.0.0",
"globals": "15.10.0",
"typescript-eslint": "8.0.1"
},
"devDependencies": {
"@rightcapital/tsconfig": "workspace:*",
"@types/confusing-browser-globals": "1.0.3",
"@types/eslint-plugin-jsx-a11y": "6.9.0",
"@types/semver": "7.5.8"
},
"peerDependencies": {
"eslint": ">=9",
"typescript": "^5.0.0"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
},
"packageManager": "[email protected]",
"engines": {
"node": ">=20"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
}
}
Loading

0 comments on commit 614f250

Please sign in to comment.