Skip to content

Commit

Permalink
Switch to new flat config for eslint v9
Browse files Browse the repository at this point in the history
  • Loading branch information
robbevp committed May 6, 2024
1 parent 411129f commit 78e469b
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 203 deletions.
20 changes: 12 additions & 8 deletions eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ Install using `yarn add -D @tree-company/eslint-config eslint prettier`.
## How to use
You can add our base eslint config in the following way:
```js
// eslintrc.js
module.exports = {
extends: ["@tree-company/eslint-config"],
};
// eslint.config.js
import config from "./eslint-config/index.js";

export default config.configs.default;

```

If you work with react:
```js
// eslintrc.js
module.exports = {
extends: ["@tree-company/eslint-config/react"],
};
// eslint.config.js
import config from "./eslint-config/index.js";

export default config.configs.react;

```

To run eslint, you'll just need `eslint .` or `eslint . --fix`.

## Versioning
Except for patch versions, all packages in from [@tree-company/linting-config](https://github.com/tree-company/linting-config) are released at the same time, with the same version.
19 changes: 0 additions & 19 deletions eslint-config/default.js

This file was deleted.

62 changes: 62 additions & 0 deletions eslint-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import eslint from "@eslint/js";
import prettierPlugin from "eslint-plugin-prettier/recommended";
import reactPluginRecommended from "eslint-plugin-react/configs/recommended.js";
import reactPluginJsxRuntime from "eslint-plugin-react/configs/jsx-runtime.js";
import globals from "globals";

const defaultConfig = [
eslint.configs.recommended,
prettierPlugin,
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
parserOptions: {
ecmaVersion: 2023,
sourceType: "module",
},
},
rules: {
curly: ["warn", "multi-line", "consistent"],
"no-console": process.env.NODE_ENV === "production" ? "error" : "warn",
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "warn",
},
},
];

const reactConfig = [
defaultConfig,
reactPluginRecommended,
reactPluginJsxRuntime,
{
languageOptions: {
parserOptions: {
ecmaVersion: 2023,
},
},
settings: {
react: {
version: "detect",
},
},
rules: {
"react/prop-types": 0,
},
},
];

const plugin = {
// We have to repeat the information from our package.json. [see](https://eslint.org/docs/latest/extend/plugin-migration-flat-config#adding-plugin-meta-information)
meta: {
name: "@tree-company/eslint-config",
version: "0.3.2",
},
configs: {
default: defaultConfig,
react: reactConfig,
},
};

export default plugin;
13 changes: 9 additions & 4 deletions eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
"version": "0.3.2",
"repository": "[email protected]:tree-company/developer-handbook",
"author": "Tree company <[email protected]>",
"contributors": ["Robbe Van Petegem <[email protected]>"],
"contributors": [
"Robbe Van Petegem <[email protected]>"
],
"license": "MIT",
"main": "default.js",
"type": "module",
"scripts": {},
"dependencies": {
"@eslint/js": "^9.2.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.1"
"eslint-plugin-react": "^7.34.1",
"globals": "^15.1.0"
},
"devDependencies": {},
"peerDependencies": {
"eslint": "^8.56.0",
"prettier": "^3.2.4"
"eslint": "^9.2.0",
"prettier": "^3.2.5"
}
}
18 changes: 0 additions & 18 deletions eslint-config/react.js

This file was deleted.

3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from "./eslint-config/index.js";

export default config.configs.default;
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@
"author": "Tree company <[email protected]>",
"contributors": ["Robbe Van Petegem <[email protected]>"],
"license": "MIT",
"type": "module",
"private": true,
"workspaces": [
"eslint-config",
"stylelint-config"
],
"scripts": {
"lint": "yarn lint:js",
"lint:js": "eslint . --ext js --fix"
"lint:js": "eslint . --fix"
},
"devDependencies": {
"eslint": "^8.57.0",
"eslint": "^9.2.0",
"prettier": "^3.2.5"
},
"eslintConfig": {
"extends": [
"./eslint-config/default.js"
]
}
}
Loading

0 comments on commit 78e469b

Please sign in to comment.