Skip to content
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
6 changes: 5 additions & 1 deletion .github/workflows/compiler_discord_notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ on:
- .github/workflows/compiler_**.yml

jobs:
check_maintainer:
uses: facebook/react/.github/workflows/shared_check_maintainer.yml@main

notify:
if: ${{ github.event.label.name == 'React Core Team' }}
if: ${{ needs.check_maintainer.outputs.is_core_team }}
needs: check_maintainer
runs-on: ubuntu-latest
steps:
- name: Discord Webhook Action
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/runtime_discord_notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ on:
- .github/workflows/compiler_**.yml

jobs:
check_maintainer:
uses: facebook/react/.github/workflows/shared_check_maintainer.yml@main

notify:
if: ${{ github.event.label.name == 'React Core Team' }}
if: ${{ needs.check_maintainer.outputs.is_core_team }}
needs: check_maintainer
runs-on: ubuntu-latest
steps:
- name: Discord Webhook Action
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/shared_check_maintainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: (Shared) Check maintainer

on:
workflow_call:
outputs:
is_core_team:
value: ${{ jobs.check_maintainer.outputs.is_core_team }}

env:
TZ: /usr/share/zoneinfo/America/Los_Angeles
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1

jobs:
check_maintainer:
runs-on: ubuntu-latest
outputs:
is_core_team: ${{ steps.check_if_actor_is_maintainer.outputs.result }}
steps:
- uses: actions/checkout@v4
- name: Check if actor is maintainer
id: check_if_actor_is_maintainer
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const actor = '${{ github.actor }}';
const data = await fs.readFileSync('./MAINTAINERS', { encoding: 'utf8' });
const maintainers = new Set(data.split('\n'));
if (maintainers.has(actor)) {
console.log(`🟢 ${actor} is a maintainer`);
return true;
}
console.log(`🔴 ${actor} is NOT a maintainer`);
return null;
29 changes: 29 additions & 0 deletions .github/workflows/shared_label_core_team_prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: (Shared) Label Core Team PRs

on:
pull_request_target:

env:
TZ: /usr/share/zoneinfo/America/Los_Angeles
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1

jobs:
check_maintainer:
uses: facebook/react/.github/workflows/shared_check_maintainer.yml@main

label:
if: ${{ needs.check_maintainer.outputs.is_core_team }}
runs-on: ubuntu-latest
needs: check_maintainer
steps:
- name: Label PR as React Core Team
uses: actions/github-script@v7
with:
script: |
github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.number }},
labels: ['React Core Team']
});
25 changes: 25 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
acdlite
eps1lon
gaearon
gnoff
gsathya
hoxyq
jackpope
jbonta
jbrown215
josephsavona
kassens
lunaleaps
mattcarrollcode
mofeiZ
mvitousek
noahlemen
pieterv
poteto
rickhanlonii
sebmarkbage
sethwebster
sophiebits
TheSavior
tyao1
yuzhi
38 changes: 36 additions & 2 deletions packages/eslint-plugin-react-hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,38 @@ npm install eslint-plugin-react-hooks --save-dev
yarn add eslint-plugin-react-hooks --dev
```

Then extend the recommended eslint config:
### Legacy Config (.eslintrc)

If you are still using ESLint below 9.0.0, please continue to use `recommended-legacy`. To avoid breaking changes, we still support `recommended` as well, but note that this will be changed to alias the flat recommended config in v6.

```js
{
"extends": [
// ...
"plugin:react-hooks/recommended"
"plugin:react-hooks/recommended-legacy"
]
}
```

### Flat Config (eslint.config.js)

For [ESLint 9.0.0 and above](https://eslint.org/blog/2024/04/eslint-v9.0.0-released/) users, add the `recommended-latest` config.

```js
import reactHooks from 'eslint-plugin-react-hooks';

export default [
// ...
reactHooks.configs['recommended-latest'],
];
```

### Custom Configuration

If you want more fine-grained configuration, you can instead add a snippet like this to your ESLint configuration file:

#### Legacy Config (.eslintrc)

```js
{
"plugins": [
Expand All @@ -47,6 +64,23 @@ If you want more fine-grained configuration, you can instead add a snippet like
}
```

#### Flat Config (eslint.config.js)

```js
import reactHooks from 'eslint-plugin-react-hooks';

export default [
{
files: ['**/*.{js,jsx}'],
plugins: { 'react-hooks': reactHooks },
// ...
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
}
},
];
```

## Advanced Configuration

Expand Down
55 changes: 46 additions & 9 deletions packages/eslint-plugin-react-hooks/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,54 @@
import RulesOfHooks from './RulesOfHooks';
import ExhaustiveDeps from './ExhaustiveDeps';

export const configs = {
recommended: {
plugins: ['react-hooks'],
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
},
},
};
const {name, version} = require('../package.json');

// All rules
export const rules = {
'rules-of-hooks': RulesOfHooks,
'exhaustive-deps': ExhaustiveDeps,
};

// Config rules
const configRules = {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
};

// Legacy config
const legacyRecommendedConfig = {
plugins: ['react-hooks'],
rules: configRules,
};

// Base plugin object
const reactHooksPlugin = {
meta: {name, version},
rules,
};

// Flat config
const flatRecommendedConfig = {
name: 'react-hooks/recommended',
plugins: {'react-hooks': reactHooksPlugin},
rules: configRules,
};

export const configs = {
/** Legacy recommended config, to be used with rc-based configurations */
'recommended-legacy': legacyRecommendedConfig,

/** Latest recommended config, to be used with flat configurations */
'recommended-latest': flatRecommendedConfig,

/**
* 'recommended' is currently aliased to the legacy / rc recommended config) to maintain backwards compatibility.
* This is deprecated and in v6, it will switch to alias the flat recommended config.
*/
recommended: legacyRecommendedConfig,
};

export default {
...reactHooksPlugin,
configs,
};
Loading