Skip to content

Commit

Permalink
PR updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bsokol-wl committed May 10, 2024
1 parent 538d663 commit ae489a9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
12 changes: 6 additions & 6 deletions docs/eslint/flat-config-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ The `extends` keyword has been removed. Now you simply add multiple _configurati

The `.eslintignore` file is no longer valid. If you need to exclude files from linting, add them to a configuration block under the `ignores` key.

Config files no longer rely on custom resolution implemented by ESLint. Since they import modules directly, they now rely on Node file resolution. Config files no longer merge down the file tree, either. Every config file acts as if it is the root config file. This means if you have nested configs as well as a true root config (like in a monorepo), you will want to set your top-level config to ignore directories that have their own config files.
Config files no longer rely on custom resolution implemented by ESLint. Since they import modules directly, they now rely on Node file resolution. Nested config files are no longer read. When ESLint is run, it will find the nearest config file starting from the current directory and traversing up. We have detailed a technique for using nested configs in the monorepo setup section.

## Basic migration steps

1. Create a file called `eslint.config.js`. `@workleap/eslint-config` is published in ESM, so if your project `type` in `package.json` is not `module`, then you should create an `eslint.config.mjs` file instead.
Create a file called `eslint.config.js`. `@workleap/eslint-config` is published in ESM, so if your project `type` in `package.json` is not `module`, then you should create an `eslint.config.mjs` file instead.

### Initial setup

Expand Down Expand Up @@ -54,7 +54,7 @@ export default config;

## Recommended setup - By project type

`@workleap/eslint-config` exposes some pre-built configs based on common project types. Each of these configs are properly set up for **JavaScript**, **TypeScript**, **Jest**, **Testing Library**, **MDX**, **package.json**, and **YAML**.
`@workleap/eslint-config` exposes some pre-built configs based on common project types. Each of these configs are properly set up for **JavaScript**, **TypeScript**, **Jest**, **Testing Library**, **MDX**, **package.json**.

By convention, all configs are found at `workleapPlugin.configs`. A flat config can be a single object or an array, but for simplicity, all Workleap configs are exported as arrays. Therefore, each Workleap config must be spread (`...`) into the config array.

Expand Down Expand Up @@ -90,7 +90,7 @@ const config = [
...workleapPlugin.configs.webApplication,
{
rules: {
'react/jsx-uses-vars': 'error',
"react/jsx-uses-vars": "error",
}
}
];
Expand Down Expand Up @@ -133,7 +133,7 @@ export default config;

Create a new `eslint.config.js` at the root of your project. Import the monorepo workspace config.

In order to make it easier to scope config files to monorepo packages, we recommend using [eslint-flat-config-utils](https://github.com/antfu/eslint-flat-config-utils). The `concat` function makes it easier to join multiple configs together. Wrap your configuration objects in the `concat` function because it will automatically merege arrays.
In order to make it easier to scope config files to monorepo packages, we recommend using [eslint-flat-config-utils](https://github.com/antfu/eslint-flat-config-utils). The `concat` function makes it easier to join multiple configs together. Wrap your configuration objects in the `concat` function because it will automatically merge arrays.

```javascript
import { concat } from "eslint-flat-config-utils";
Expand All @@ -152,7 +152,7 @@ export default config;
Import each package's `eslint.config.js` and add them to the `concat` function. Wrap each of the package imports with the `extend` function, and provide the relative path to the root of each package. This will scope the files of that config to the given directory, including any ignores.

```javascript
import { concat } from "eslint-flat-config-utils";
import { concat, extend } from "eslint-flat-config-utils";
import workleapPlugin from "@workleap/eslint-config";
import packageOneConfig from "./packages/one";
import packageTwoConfig from "./packages/two";
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@workleap/eslint-plugin": "workspace:*",
"@workleap/typescript-configs": "workspace:*",
"eslint": "8.57.0",
"eslint-flat-config-utils": "^0.2.4",
"eslint-flat-config-utils": "0.2.4",
"installed-check": "9.3.0",
"jest": "29.7.0",
"knip": "5.9.4",
Expand Down
4 changes: 3 additions & 1 deletion packages/browserslist-config/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import workleapPlugin from "@workleap/eslint-plugin";

const config = workleapPlugin.configs.typescriptLibrary;
const config = {
...workleapPlugin.configs.typescriptLibrary
};

export default config;
6 changes: 3 additions & 3 deletions packages/eslint-plugin/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import workleapPlugin from "@workleap/eslint-plugin";

const config = [
...workleapPlugin.configs.typescriptLibrary.map(conf => ({
...conf,
{
ignores: ["lib/plugins.d.ts"]
}))
},
...workleapPlugin.configs.typescriptLibrary
];

export default config;
5 changes: 1 addition & 4 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
"typescript": "*"
},
"peerDependenciesMeta": {
"@typescript-eslint/parser": {
"optional": true
},
"typescript": {
"optional": true
}
Expand All @@ -52,7 +49,7 @@
"@swc/helpers": "0.5.9",
"@swc/jest": "0.2.36",
"@types/eslint": "8.56.9",
"@types/eslint__js": "^8.42.3",
"@types/eslint__js": "8.42.3",
"@types/estree": "1.0.5",
"@types/jest": "29.5.12",
"@types/node": "20.12.7",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ae489a9

Please sign in to comment.