Skip to content

Commit

Permalink
Merge pull request #204 from RightCapitalHQ/feature/eslint-v9
Browse files Browse the repository at this point in the history
Add support for ESLint v9
  • Loading branch information
frantic1048 authored Oct 15, 2024
2 parents 11f0390 + e28c101 commit c79a291
Show file tree
Hide file tree
Showing 66 changed files with 4,524 additions and 7,480 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": "major",
"comment": "feat: add `@rightcapital/eslint-config` that supports ESLint v9",
"packageName": "@rightcapital/eslint-config",
"email": "[email protected]",
"dependentChangeType": "patch"
}
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
Loading

0 comments on commit c79a291

Please sign in to comment.