Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-preset)!: migrate to flat config #2813

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/khaki-dodos-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnx-kit/eslint-plugin": minor
---

ESLint 8.23+ and its new config system is now required — read more about ESLint's new config system, flat config, here: https://eslint.org/blog/2022/08/new-config-system-part-2/
3 changes: 0 additions & 3 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ packageExtensions:
peerDependenciesMeta:
"@types/react":
optional: true
"@microsoft/eslint-plugin-sdl@0.x":
peerDependencies:
eslint: ">=5.16.0"
"@react-native-community/cli-debugger-ui@*":
dependencies:
"@babel/runtime": "^7.20.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@rnx-kit/jest-preset": "*",
"@rnx-kit/scripts": "*",
"@types/node": "^20.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"prettier": "^3.0.0",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion incubator/build-plugin-firebase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@rnx-kit/eslint-config": "*",
"@rnx-kit/jest-preset": "*",
"@rnx-kit/scripts": "*",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion incubator/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@types/node": "^20.0.0",
"@types/qrcode": "^1.4.2",
"@types/yargs": "^16.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
Expand Down
2 changes: 1 addition & 1 deletion incubator/chromium-edge-launcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/mkdirp": "^1.0.1",
"@types/rimraf": "^3.0.0",
"@types/sinon": "^9.0.1",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"prettier": "^3.0.0",
"sinon": "^9.0.1",
Expand Down
2 changes: 1 addition & 1 deletion incubator/commitlint-lite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@rnx-kit/jest-preset": "*",
"@rnx-kit/scripts": "*",
"@types/node": "^20.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
Expand Down
2 changes: 1 addition & 1 deletion incubator/esbuild-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@types/jest": "^29.2.1",
"@types/node": "^20.0.0",
"@types/yargs": "^16.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
Expand Down
2 changes: 1 addition & 1 deletion incubator/patcher-rnmacos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@types/fs-extra": "^9.0.0",
"@types/istextorbinary": "^2.3.0",
"@types/node": "^20.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
Expand Down
2 changes: 1 addition & 1 deletion incubator/polyfills/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@types/babel__template": "^7.0.0",
"@types/node": "^20.0.0",
"chalk": "^4.1.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"metro-config": "^0.76.5",
"prettier": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@rnx-kit/scripts": "*",
"@types/node": "^20.0.0",
"@types/yargs": "^16.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
Expand Down
2 changes: 1 addition & 1 deletion incubator/rn-changelog-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@types/node": "^20.0.0",
"chalk": "^4.1.0",
"deepmerge": "^4.2.2",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"fast-levenshtein": "^3.0.0",
"jest": "^29.2.1",
"p-limit": "^3.1.0",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@changesets/cli": "^2.22.0",
"@types/jest": "^29.2.1",
"@types/node": "^20.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"metro": "^0.76.5",
"nx": "~17.0.2",
"prettier": "^3.0.0",
Expand All @@ -49,7 +49,7 @@
},
"packageManager": "yarn@3.6.1",
"resolutions": {
"@microsoft/eslint-plugin-sdl/eslint-plugin-react": "^7.26.0",
"@microsoft/eslint-plugin-sdl/eslint-plugin-react": "^7.33.0",
"@microsoft/eslint-plugin-sdl/eslint-plugin-security": "^1.4.0",
"@react-native-community/cli": "^11.3.6",
"@react-native-community/cli-platform-android": "^11.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/align-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/yargs": "^16.0.0",
"chalk": "^4.1.0",
"detect-indent": "^6.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"markdown-table": "^3.0.0",
"package-json": "^8.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-import-path-remapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@types/babel__helper-plugin-utils": "^7.0.0",
"@types/jest": "^29.2.1",
"@types/node": "^20.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-metro-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@types/babel__core": "^7.0.0",
"@types/jest": "^29.2.1",
"@types/node": "^20.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"metro-react-native-babel-preset": "^0.76.5",
"prettier": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/bundle-diff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@rnx-kit/scripts": "*",
"@types/jest": "^29.2.1",
"@types/node": "^20.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@types/node": "^20.0.0",
"@types/node-fetch": "^2.6.5",
"@types/qrcode": "^1.4.2",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"memfs": "^4.0.0",
"metro": "^0.76.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@rnx-kit/tools-react-native": "*",
"@types/node": "^20.0.0",
"@types/semver": "^7.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"metro": "^0.76.5",
"prettier": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@rnx-kit/scripts": "*",
"@types/jest": "^29.2.1",
"@types/node": "^20.0.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@rnx-kit/scripts": "*",
"@types/node": "^20.0.0",
"esbuild": "^0.19.0",
"eslint": "^8.0.0",
"eslint": "^8.23.0",
"jest": "^29.2.1",
"prettier": "^3.0.0",
"typescript": "^5.0.0"
Expand Down
21 changes: 5 additions & 16 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
const { FlatCompat } = require("@eslint/eslintrc");
const js = require("@eslint/js");
const rnx = require("@rnx-kit/eslint-plugin");

const compat = new FlatCompat({
baseDirectory: __dirname,
// Use `@rnx-kit/eslint-plugin` as base directory to ensure we get the same
// plugin instances
baseDirectory: require.resolve("@rnx-kit/eslint-plugin/package.json"),
recommendedConfig: js.configs.recommended,
});

module.exports = [
...rnx.configs.strict,
...compat.extends(
"plugin:@microsoft/sdl/required",
"plugin:@rnx-kit/recommended",
"plugin:@typescript-eslint/stylistic"
),
{
rules: {
"@rnx-kit/no-const-enum": "error",
"@rnx-kit/no-export-all": "error",
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"no-restricted-exports": [
"error",
{
restrictDefaultExports: {
direct: true,
named: true,
defaultFrom: true,
namedFrom: true,
namespaceFrom: true,
},
},
],
},
},
];
12 changes: 2 additions & 10 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,8 @@
},
"dependencies": {
"@eslint/eslintrc": "^2.1.2",
"@eslint/js": "^8.0.0",
"@microsoft/eslint-plugin-sdl": "^0.2.0",
"@react-native/eslint-plugin": "^0.74.0",
"@rnx-kit/eslint-plugin": "workspace:*",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-react": "^7.26.0",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-security": "^1.4.0"
"@eslint/js": "^8.33.0",
"@rnx-kit/eslint-plugin": "workspace:*"
},
"peerDependencies": {
"eslint": ">=6.0.0"
Expand Down
82 changes: 60 additions & 22 deletions packages/eslint-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
[![Build](https://github.com/microsoft/rnx-kit/actions/workflows/build.yml/badge.svg)](https://github.com/microsoft/rnx-kit/actions/workflows/build.yml)
[![npm version](https://img.shields.io/npm/v/@rnx-kit/eslint-plugin)](https://www.npmjs.com/package/@rnx-kit/eslint-plugin)

`@rnx-kit/eslint-plugin` is a set of rules that can be extended in your own
shareable ESLint config.
`@rnx-kit/eslint-plugin` is a set of configurations and rules that can be used
as is, or extended in your own ESLint config.

For more details on shareable configs, see
https://eslint.org/docs/developer-guide/shareable-configs.
Note that this plugin requires the
[new ESLint configuration format](https://eslint.org/blog/2022/08/new-config-system-part-2/).
If you still rely on the previous format, use version 0.5.x instead.

## Install

Expand All @@ -21,33 +22,70 @@ or if you're using npm:
npm add --save-dev @rnx-kit/eslint-plugin
```

## Recommended Configs
## Usage

This ESLint plugin exports
[`@rnx-kit/recommended`](https://github.com/microsoft/rnx-kit/blob/main/packages/eslint-plugin/src/configs/recommended.js)
configuration. To enable it, add it to the `extends` section of your ESLint
config file:
This ESLint plugin exports multiple configurations. For instance, to use the
[`recommended`](https://github.com/microsoft/rnx-kit/blob/main/packages/eslint-plugin/src/configs/recommended.js)
configuration, you can re-export it in your
[flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new)
like below:

```json
{
"extends": ["plugin:@rnx-kit/recommended"]
}
```js
module.exports = require("@rnx-kit/eslint-plugin/recommended");
```

`@rnx-kit/recommended` currently extends:

- [`eslint:recommended`](https://eslint.org/docs/rules/)
- [`plugin:@typescript-eslint/recommended`](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin#supported-rules)
- [`plugin:react-hooks/recommended`](https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/src/index.js)
- [`plugin:react/recommended`](https://github.com/yannickcr/eslint-plugin-react#recommended)
Alternatively, if you want to add customizations:

```js
const rnx = require("@rnx-kit/eslint-plugin");
module.exports = [
...rnx.configs.recommended,
{
rules: {
"@rnx-kit/no-const-enum": "error",
"@rnx-kit/no-export-all": "error",
},
},
];
```

Additionally, it also includes and enables:
If you're just interested in the rules, you can use it as a plugin and enable
the rules you're interested in:

```js
module.exports = [
{
plugins: {
"@rnx-kit": require("@rnx-kit/eslint-plugin"),
},
rules: {
"@rnx-kit/no-const-enum": "error",
"@rnx-kit/no-export-all": "error",
},
},
];
```

- [`@react-native/eslint-plugin`](https://github.com/facebook/react-native/tree/main/packages/eslint-plugin-react-native#readme)
## Recommended Configurations

- [`@rnx-kit/eslint-plugin/recommended`](https://github.com/microsoft/rnx-kit/blob/main/packages/eslint-plugin/src/configs/recommended.js)
extends:
- [`eslint:recommended`](https://eslint.org/docs/rules/)
- [`plugin:@typescript-eslint/recommended`](https://typescript-eslint.io/linting/configs#recommended)
- [`plugin:react-hooks/recommended`](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks#readme)
- [`plugin:react/recommended`](https://github.com/yannickcr/eslint-plugin-react#recommended)
- It also includes and enables the following rules:
- [`@react-native/platform-colors`](https://github.com/facebook/react-native/tree/main/packages/eslint-plugin-react-native#readme)
- [`@rnx-kit/eslint-plugin/strict`](https://github.com/microsoft/rnx-kit/blob/main/packages/eslint-plugin/src/configs/strict.js)
extends `@rnx-kit/eslint-plugin/recommended` with rules that enables better
tree shaking:
- [`@rnx-kit/no-const-enum`](https://github.com/microsoft/rnx-kit/blob/main/packages/eslint-plugin/src/rules/no-const-enum.js)
- [`@rnx-kit/no-export-all`](https://github.com/microsoft/rnx-kit/blob/main/packages/eslint-plugin/src/rules/no-export-all.js)
- [`no-restricted-exports`](https://archive.eslint.org/docs/rules/no-restricted-exports)

## Supported Rules

- ✓: Enabled with `@rnx-kit/recommended`
- ✓: Enabled with `@rnx-kit/eslint-plugin/recommended`
- 🔧: Fixable with `--fix`

| ✓ | 🔧 | Rule | Description |
Expand Down
Loading