Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
982b16d
[ci] Fix permissions and don't use pull_request_target (#7689)
poteto Mar 21, 2025
f6d762c
[ci] Pin 3rd party actions to specific hash (#7690)
poteto Mar 21, 2025
0bc6300
[ci] fix notify for forks (#7694)
rickhanlonii Mar 24, 2025
9b2ad17
[ci] Remove unused param (#7695)
poteto Mar 24, 2025
6788f6b
Fixes typo (#7688)
betovelandia Mar 24, 2025
2859efa
Add React Prague community (#7279)
pchalupa Mar 25, 2025
9f87530
Remove captureOwnerStack canary banner (#7701)
jackpope Mar 31, 2025
38ee8d2
Add note about StrictMode not as the root component (#7702)
rickhanlonii Mar 31, 2025
c0e1774
[errors] special case for 418 (#7705)
rickhanlonii Apr 1, 2025
b5f5134
update reactrouter url (#7703)
zongben Apr 1, 2025
06500ec
Typo correction (#7657)
SandwichGouda Apr 2, 2025
6a548a8
Use stable React by default in Sandpacks (#7709)
eps1lon Apr 2, 2025
b77c05d
Misc `captureOwnerStack` cleanup after stable release (#7710)
eps1lon Apr 2, 2025
b5c16dc
fix(reference): declare `subscribe` before passing it to the hook (#7…
hugmouse Apr 2, 2025
3dfa3bd
Fix heading links in StrictMode (#7713)
rickhanlonii Apr 2, 2025
9fc1221
Update meetups.md (#7700)
darshanyeah Apr 2, 2025
c74271e
Add React Denver to the Meetups page (#4727)
willklein Apr 2, 2025
0ea503b
typo (#7685)
pdurbin Apr 2, 2025
5138e60
Fix small grammatical mistake on Reusing Logic with Custom Hooks page…
LuckyT89 Apr 2, 2025
6ead1fa
Add note about `useId` being allowed in non-async Server Components (…
hernan-yadiel Apr 7, 2025
e148ffe
Add note about root.render microtask scheduling (#7717)
jukben Apr 8, 2025
420c2f6
Add React Conf banner (#7729)
mattcarrollcode Apr 8, 2025
5598696
Add React Conf to conferences.md and move past conferences (#7730)
mattcarrollcode Apr 9, 2025
3c805e7
fix(reference): missing parameter in hydrateRoot (#7724)
Kafuu-Chinocya Apr 15, 2025
84261aa
Update versions to mention the latest version: 19.1 (#7739)
val1984 Apr 15, 2025
947681e
docs: fix a typo in the docs (#7736)
Clatron Apr 15, 2025
4bea66b
Change the word 'Function' to 'Component' (#7741)
kapantzak Apr 16, 2025
4c54ac9
Fix missing Sunsetting CRA entry in sidebar (#7755)
poteto Apr 21, 2025
3a88efd
Compiler blog post (#7756)
poteto Apr 21, 2025
c1e5681
Compiler blog post edits (#7758)
poteto Apr 21, 2025
663df77
React compiler doc updates (#7759)
poteto Apr 21, 2025
740016e
More compiler blog post tweaks (#7760)
poteto Apr 21, 2025
39b9c56
Fix ESLint plugin version. (#7768)
cpojer Apr 23, 2025
5890bd6
Update react-compiler-rc.md (#7769)
poteto Apr 23, 2025
dd129e4
fix a typo in name in the blog post (#7762)
witch-factory Apr 23, 2025
55ddaa4
Add React Summit US 2025 and React Advanced London 2025 to conference…
Hlebread Apr 23, 2025
358d2be
[blog + docs] React Labs: View Transitions, Activity, and more (#7772)
rickhanlonii Apr 23, 2025
09c9593
Update Next.js deployment notes (#7771)
eduardoboucas Apr 23, 2025
159df67
Add React Norway 2025 conference to community page (#7766)
danisal Apr 24, 2025
f94ab10
Fix typos in blog post
sophiebits Apr 24, 2025
594ff45
Refine wording for Next.js + Compiler + SWC (#7779)
eps1lon Apr 25, 2025
d05547b
fix: server-components link in few pages (#7780)
ad1992 Apr 26, 2025
ecf7596
docs: rename unstableViewTransition to unstable_ViewTransition (#7778)
nick-private Apr 27, 2025
92dfd8c
fixed typo (#7785)
MrD9877 Apr 28, 2025
022e047
Remove extra copy of labs post (#7787)
jackpope Apr 28, 2025
4314b49
Improve grammar in component descriptions (#7788)
Maddily Apr 29, 2025
d6c4c0f
Fix useOptimistic example (#7792)
rickhanlonii Apr 29, 2025
a3e9466
fix action pattern in useTransition / useOptimistic (#7796)
rickhanlonii Apr 30, 2025
73d7073
fix: correct overlay highlighting in code examples (#7669)
mrbadri May 15, 2025
4a7bdc1
fix: the value property of checkbox to the checked property (#7804)
kosh-jp May 16, 2025
ae4a40a
No need for useState here — useCounter handles the state internally (…
gbhardwaj00 May 16, 2025
a73055f
docs: fix misplaced prepositional phrase error (#7799)
mehmetmalli May 16, 2025
e2d9fd7
Fix wrong documentation for effect events (#7800)
gbhardwaj00 May 16, 2025
b92bb59
Remove stray console.log and image (#7814)
rickhanlonii May 16, 2025
b3b2166
fix(template): remove unnecessary import of React in template code (#…
dahoho May 16, 2025
9fb0519
fix(reference): correct singular form of 'Server Functions' to 'Serve…
dahoho May 16, 2025
69ce5d3
Add bold mono font (#7815)
rickhanlonii May 16, 2025
8b2fe2b
Remove TODO comments and convert them to issues (#7743)
BartoszKlonowski May 16, 2025
00587d6
Add example of `useActionState` handling execution order (#7733)
ajits01 May 16, 2025
79e1c48
docs: update vite link (#7784)
bornkiss May 16, 2025
c289cd0
docs: add bsky link (#7781)
bornkiss May 16, 2025
7ab1969
React Montreal Meetings have a new link (#7809)
EricCote May 16, 2025
f275c9d
fix: remove useless content (#6615)
loveloki May 17, 2025
0b68054
fix: wrong verb tense in doc (#7818)
aalhoura May 17, 2025
65d297e
fix: typo in challenge solution (#7816)
aalhoura May 17, 2025
f15830d
Use experiemental in all uEE doc sandboxes (#7820)
rickhanlonii May 20, 2025
2571aee
Author: Josh Story <[email protected]>
gnoff May 21, 2025
3ee3a60
Fix wrong explanation in preserving-and-resetting-state (#6043)
smikitky May 26, 2025
9db23d6
fix: correct broken WAI-ARIA modal dialog link in createPortal refere…
dimatitov Jun 2, 2025
bbcb9af
Update meetups.md adding React Rajasthan Community (#7831)
shubhamui Jun 2, 2025
a2d17d1
Update components-and-hooks-must-be-pure.md (#7830)
ExercitusMortem Jun 2, 2025
94424ae
Update referencing-values-with-refs.md (#7829)
cHaLkdusT Jun 2, 2025
172f0b9
Add uwu click animation (#7822)
Jinsoo1004 Jun 2, 2025
3dcc4c4
Fix typo and clarily that a server function reference is created only…
kapantzak Jun 2, 2025
06965de
Add React Alicante 2025 to Conferences page (#7674)
mikedidomizio Jun 2, 2025
e901790
fix: use const where applicable in examples for keeping components pu…
ad1992 Jun 2, 2025
87cef4a
Remove `forwardRef` reference from API listing (#7837)
kassens Jun 3, 2025
c60173f
docs: Refactor context provider usage (#7793)
nannany Jun 3, 2025
37b09ea
fix: typo in docs on prerendering (#7823)
yeskunall Jun 3, 2025
5927c4e
Replace Context.Provider with Context (#7838)
kassens Jun 3, 2025
5dca520
fix(blog): resolve typo in React 19 blog post (`refs` → `ref`s) (#7828)
amir78729 Jun 3, 2025
50d6991
Update analyze_comment.yml (#7840)
jtn-dev Jun 6, 2025
82f2863
Fix #6915: typo fix (#6917)
Rekl0w Jun 28, 2025
741e8d9
fix: update ids to point to right part of the docs (#7854)
yeskunall Jun 28, 2025
c0c955e
chore: remove unused date-fns (#7856)
noritaka1166 Jun 28, 2025
b79ad22
chore: fix typo in resource and metadata components documentation (#7…
Rekl0w Jul 2, 2025
341c312
fix: correct typo in scaling-up-with-reducer-and-context.md (#7390)
bcdipesh Jul 2, 2025
4846020
fix flushSync link (#7862)
rickhanlonii Jul 9, 2025
84a5696
docs(react): fix grammar in forward ref deprecation message (#7864)
SimonSchick Jul 10, 2025
e245b77
[be] Add deadlinks script (#7879)
poteto Jul 18, 2025
d52b3ec
Fix deadlinks (#7880)
poteto Jul 18, 2025
8ad6c60
Revert "Fix deadlinks (#7880)" (#7881)
poteto Jul 21, 2025
79eb0c5
Update deadlinks script to take into account redirects (#7882)
poteto Jul 21, 2025
aa5448d
Fix deadlinks take 2 (#7883)
poteto Jul 21, 2025
b165e71
[compiler] Rewrite React Compiler Docs (#7868)
poteto Jul 21, 2025
d7160a8
[compiler] Fix misleading code example (#7889)
poteto Jul 21, 2025
b462664
[compiler] Flesh out incremental adoption intro more (#7890)
poteto Jul 21, 2025
b6450e8
[compiler] Add note about gating evaluation (#7891)
poteto Jul 21, 2025
e07ac94
Remove non-existent meetup group (Edinburgh, Scotland) (#7895)
melanterite Jul 25, 2025
1a6b2bb
Fixes animation jank on hover (#7904)
wesbos Aug 6, 2025
b092216
fix: box-shadow animation on community (#7905)
ChezFre Aug 7, 2025
e9a7cb1
Updates to Activity docs (#7884)
samselikoff Aug 8, 2025
0a74f01
Add more information about event and property binding on custom eleme…
crutchcorn Aug 22, 2025
27d86ff
Touch-ups to Activity (#7940)
samselikoff Aug 22, 2025
694aeac
Add React Paris 2025 conference talks + Add React Paris 2026 (#7935)
AymenBenAmor Aug 26, 2025
90686d8
Add CityJS New Delhi 2026 conference details (#7949)
arismarko Aug 26, 2025
9a370f2
[compiler] Tweak intro section on manual memo guidance (#7953)
poteto Aug 28, 2025
94a1164
[compiler][ez] Reference rc tag for install instructions (#7955)
poteto Aug 28, 2025
19c8201
[compiler] Update docs on eslint-plugin-react-hooks installation (#7956)
poteto Aug 28, 2025
2774ddf
Add reload button, rename reset to clear (#7954)
rickhanlonii Aug 29, 2025
ddfcf6e
fix: typo in component style documentation (#7925)
sky21kr Sep 1, 2025
bb998fd
fix broken link server-functions (#7923)
PouriaDamavandi Sep 1, 2025
4db5ecd
docs: Add Rendercon 2025 Conference (#7962)
orama254 Sep 2, 2025
9ced885
feat(i18n): make DocsPageFooter navigation labels translatable (#7943)
mrbadri Sep 2, 2025
04feec4
fix(rtl): resolve RTL issues in Challenges component (#7942)
mrbadri Sep 2, 2025
4d53629
Introduce Liverpool and Edinburgh meetup groups. (#7950)
asimno Sep 2, 2025
73a5fdd
docs: fix typo in update useTransition.md (#7936)
brookslybrand Sep 2, 2025
fc27b0a
docs: fix ordered list numbering in TypeScript with React Components …
mrbadri Sep 2, 2025
03a5465
Docs: update ref callback behaviour (#7927)
ninamma Sep 2, 2025
a4a37d8
Add setup to home sidebar (#7963)
rickhanlonii Sep 2, 2025
ca3e271
fix: definition typo on view transitions blog post (#7918)
vitormrmonteiro Sep 2, 2025
67584b3
Fix: grammar and add comma (#7917)
deepu7d Sep 2, 2025
0cc37ee
fix: typo (#7914)
Raghuboi Sep 2, 2025
afd84d1
Recommend installing `@types/*` as dev dependencies
Dejumo Sep 2, 2025
337d5ea
docs: minor grammar correction (#7906)
ergusto Sep 2, 2025
e9efd19
fix : typo in form component documentation (#7894)
developerjhp Sep 2, 2025
2217f45
Update "Deep Dive" in reusing-logic-with-custom-hooks.md with link an…
aurorascharff Sep 2, 2025
ff11cd2
Add note that form actions are actions (#7964)
rickhanlonii Sep 2, 2025
85ee6b2
Remove deprecated loremflickr placeholder images (#7968)
poteto Sep 3, 2025
b8e9faf
Fix handleClick compiler intro example (#7967)
rickhanlonii Sep 3, 2025
d34c6a2
Fix/tictactoe docs invalid file names (#7969)
mtayyabrawan Sep 4, 2025
4d3d495
Add React Conf 2024 to /videos (#7977)
rickhanlonii Sep 9, 2025
0bfd418
docs: add flushSync Troubleshooting section (#7978)
Akshay090 Sep 11, 2025
a5181c2
Bump Activity docs to canary (#7974)
rickhanlonii Sep 12, 2025
5b9a2ce
Upgrade babel-plugin-react-compiler (#7985)
poteto Sep 16, 2025
a566d87
Add copyright script (#7991)
poteto Sep 18, 2025
bd03b86
Update copyright on all files (#7992)
poteto Sep 18, 2025
b6a32d1
Add local eslint rule to validate markdown codeblocks with React Comp…
poteto Sep 18, 2025
5cc9b7b
fix compiler errors (#7989)
poteto Sep 18, 2025
2a9ef2d
Revert "fix compiler errors (#7989)" (#7995)
poteto Sep 18, 2025
f369f3e
Ignore braces when building Sandpack file map (#7996)
poteto Sep 18, 2025
730d045
Restore lint corrections from #7989 (#7997)
poteto Sep 18, 2025
c15e20f
Install eslint-local-rules as postinstall (#7993)
poteto Sep 19, 2025
366b5fb
Add new eslint rule reference docs (#7986)
poteto Sep 19, 2025
c8211fc
Add RC badge to RC-only lint rules (#8005)
rickhanlonii Sep 22, 2025
170e5b9
Remove unnecessary spaces from useCallback.md (#8006)
rammba Sep 23, 2025
790625f
Fix ViewTransition examples (#7999)
EugeneChoi4 Sep 23, 2025
1b20061
Fix value wrongly formatted as code in useDeferredValue.md (#8024)
rammba Sep 26, 2025
49c2d26
Update useEffectEvent docs for canary (#8025)
jackpope Sep 28, 2025
7cf7ecf
Merge branch 'main' of https://github.com/reactjs/react.dev into sync…
react-translations-bot Sep 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 21 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,36 @@
"root": true,
"extends": "next/core-web-vitals",
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "eslint-plugin-react-compiler"],
"plugins": ["@typescript-eslint", "eslint-plugin-react-compiler", "local-rules"],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", {"varsIgnorePattern": "^_"}],
"react-hooks/exhaustive-deps": "error",
"react/no-unknown-property": ["error", {"ignore": ["meta"]}],
"react-compiler/react-compiler": "error"
"react-compiler/react-compiler": "error",
"local-rules/lint-markdown-code-blocks": "error"
},
"env": {
"node": true,
"commonjs": true,
"browser": true,
"es6": true
}
},
"overrides": [
{
"files": ["src/content/**/*.md"],
"parser": "./eslint-local-rules/parser",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off",
"react-hooks/exhaustive-deps": "off",
"react/no-unknown-property": "off",
"react-compiler/react-compiler": "off",
"local-rules/lint-markdown-code-blocks": "error"
}
}
]
}
6 changes: 4 additions & 2 deletions .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
- main # change this if your default branch is named differently
workflow_dispatch:

permissions: {}

jobs:
analyze:
runs-on: ubuntu-latest
Expand All @@ -23,7 +25,7 @@ jobs:
- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: "**/node_modules"
path: '**/node_modules'
key: node_modules-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }}

- name: Install deps
Expand Down Expand Up @@ -55,7 +57,7 @@ jobs:
name: bundle_analysis.json

- name: Download base branch bundle stats
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e
if: success() && github.event.number
with:
workflow: analyze.yml
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/analyze_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ name: Analyze Bundle (Comment)

on:
workflow_run:
workflows: ["Analyze Bundle"]
workflows: ['Analyze Bundle']
types:
- completed

permissions:
contents: read
issues: write
pull-requests: write

jobs:
comment:
runs-on: ubuntu-latest
Expand All @@ -14,15 +19,15 @@ jobs:
github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download base branch bundle stats
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e
with:
workflow: analyze.yml
run_id: ${{ github.event.workflow_run.id }}
name: analysis_comment.txt
path: analysis_comment.txt

- name: Download PR number
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e
with:
workflow: analyze.yml
run_id: ${{ github.event.workflow_run.id }}
Expand All @@ -48,7 +53,7 @@ jobs:
echo "pr-number=$pr_number" >> $GITHUB_OUTPUT

- name: Comment
uses: marocchino/sticky-pull-request-comment@v2
uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728
with:
header: next-bundle-analysis
number: ${{ steps.get-comment-body.outputs.pr-number }}
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/discord_notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ on:
pull_request_target:
types: [opened, ready_for_review]

permissions: {}

jobs:
check_maintainer:
uses: facebook/react/.github/workflows/shared_check_maintainer.yml@main
permissions:
# Used by check_maintainer
contents: read
with:
actor: ${{ github.event.pull_request.user.login }}
is_remote: true

notify:
if: ${{ needs.check_maintainer.outputs.is_core_team == 'true' }}
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/label_core_team_prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Label Core Team PRs
on:
pull_request_target:

permissions: {}

env:
TZ: /usr/share/zoneinfo/America/Los_Angeles
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout
Expand All @@ -11,14 +13,21 @@ env:
jobs:
check_maintainer:
uses: facebook/react/.github/workflows/shared_check_maintainer.yml@main
permissions:
# Used by check_maintainer
contents: read
with:
actor: ${{ github.event.pull_request.user.login }}
is_remote: true

label:
if: ${{ needs.check_maintainer.outputs.is_core_team == 'true' }}
runs-on: ubuntu-latest
needs: check_maintainer
permissions:
# Used to add labels on issues
issues: write
# Used to add labels on PRs
pull-requests: write
steps:
- name: Label PR as React Core Team
uses: actions/github-script@v7
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/site_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
pull_request:
types: [opened, synchronize, reopened]

permissions: {}

jobs:
lint:
runs-on: ubuntu-latest
Expand All @@ -25,7 +27,7 @@ jobs:
- name: Restore cached node_modules
uses: actions/cache@v4
with:
path: "**/node_modules"
path: '**/node_modules'
key: node_modules-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }}

- name: Install deps
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
node_modules
/.pnp
.pnp.js

Expand Down
7 changes: 7 additions & 0 deletions colors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```jsx
import {useState} from 'react';
function Counter() {
const [count, setCount] = useState(0);
setCount(count + 1);
return <div>{count}</div>;
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```jsx title="Counter" {expectedErrors: {'react-compiler': [99]}} {expectedErrors: {'react-compiler': [2]}}
import {useState} from 'react';
function Counter() {
const [count, setCount] = useState(0);
setCount(count + 1);
return <div>{count}</div>;
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```jsx {expectedErrors: {'react-compiler': 'invalid'}}
import {useState} from 'react';
function Counter() {
const [count, setCount] = useState(0);
setCount(count + 1);
return <div>{count}</div>;
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```bash
setCount()
```

```txt
import {useState} from 'react';
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```jsx {expectedErrors: {'react-compiler': [3]}}
function Hello() {
return <h1>Hello</h1>;
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```jsx {expectedErrors: {'react-compiler': [4]}}
import {useState} from 'react';
function Counter() {
const [count, setCount] = useState(0);
setCount(count + 1);
return <div>{count}</div>;
}
```
131 changes: 131 additions & 0 deletions eslint-local-rules/__tests__/lint-markdown-code-blocks.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const {ESLint} = require('eslint');
const plugin = require('..');

const FIXTURES_DIR = path.join(
__dirname,
'fixtures',
'src',
'content'
);
const PARSER_PATH = path.join(__dirname, '..', 'parser.js');

function createESLint({fix = false} = {}) {
return new ESLint({
useEslintrc: false,
fix,
plugins: {
'local-rules': plugin,
},
overrideConfig: {
parser: PARSER_PATH,
plugins: ['local-rules'],
rules: {
'local-rules/lint-markdown-code-blocks': 'error',
},
parserOptions: {
sourceType: 'module',
},
},
});
}

function readFixture(name) {
return fs.readFileSync(path.join(FIXTURES_DIR, name), 'utf8');
}

async function lintFixture(name, {fix = false} = {}) {
const eslint = createESLint({fix});
const filePath = path.join(FIXTURES_DIR, name);
const markdown = readFixture(name);
const [result] = await eslint.lintText(markdown, {filePath});
return result;
}

async function run() {
const basicResult = await lintFixture('basic-error.md');
assert.strictEqual(
basicResult.messages.length,
1,
'expected one diagnostic'
);
assert(
basicResult.messages[0].message.includes('Calling setState during render'),
'expected message to mention setState during render'
);

const suppressedResult = await lintFixture('suppressed-error.md');
assert.strictEqual(
suppressedResult.messages.length,
0,
'expected suppression metadata to silence diagnostic'
);

const staleResult = await lintFixture('stale-expected-error.md');
assert.strictEqual(
staleResult.messages.length,
1,
'expected stale metadata error'
);
assert.strictEqual(
staleResult.messages[0].message,
'React Compiler expected error on line 3 was not triggered'
);

const duplicateResult = await lintFixture('duplicate-metadata.md');
assert.strictEqual(
duplicateResult.messages.length,
2,
'expected duplicate metadata to surface compiler diagnostic and stale metadata notice'
);
const duplicateFixed = await lintFixture('duplicate-metadata.md', {
fix: true,
});
assert(
duplicateFixed.output.includes(
"{expectedErrors: {'react-compiler': [4]}}"
),
'expected duplicates to be rewritten to a single canonical block'
);
assert(
!duplicateFixed.output.includes('[99]'),
'expected stale line numbers to be removed from metadata'
);

const mixedLanguageResult = await lintFixture('mixed-language.md');
assert.strictEqual(
mixedLanguageResult.messages.length,
0,
'expected non-js code fences to be ignored'
);

const malformedResult = await lintFixture('malformed-metadata.md');
assert.strictEqual(
malformedResult.messages.length,
1,
'expected malformed metadata to fall back to compiler diagnostics'
);
const malformedFixed = await lintFixture('malformed-metadata.md', {
fix: true,
});
assert(
malformedFixed.output.includes(
"{expectedErrors: {'react-compiler': [4]}}"
),
'expected malformed metadata to be replaced with canonical form'
);
}

run().catch(error => {
console.error(error);
process.exitCode = 1;
});
14 changes: 14 additions & 0 deletions eslint-local-rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const lintMarkdownCodeBlocks = require('./rules/lint-markdown-code-blocks');

module.exports = {
rules: {
'lint-markdown-code-blocks': lintMarkdownCodeBlocks,
},
};
Loading