Skip to content

Commit f1a1c24

Browse files
committed
feat: Sync with react.dev f8c81a0
1 parent d504834 commit f1a1c24

File tree

294 files changed

+11636
-1583
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

294 files changed

+11636
-1583
lines changed

.eslintrc

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,36 @@
22
"root": true,
33
"extends": "next/core-web-vitals",
44
"parser": "@typescript-eslint/parser",
5-
"plugins": ["@typescript-eslint", "eslint-plugin-react-compiler"],
5+
"plugins": ["@typescript-eslint", "eslint-plugin-react-compiler", "local-rules"],
66
"rules": {
77
"no-unused-vars": "off",
88
"@typescript-eslint/no-unused-vars": ["error", {"varsIgnorePattern": "^_"}],
99
"react-hooks/exhaustive-deps": "error",
1010
"react/no-unknown-property": ["error", {"ignore": ["meta"]}],
11-
"react-compiler/react-compiler": "error"
11+
"react-compiler/react-compiler": "error",
12+
"local-rules/lint-markdown-code-blocks": "error"
1213
},
1314
"env": {
1415
"node": true,
1516
"commonjs": true,
1617
"browser": true,
1718
"es6": true
18-
}
19+
},
20+
"overrides": [
21+
{
22+
"files": ["src/content/**/*.md"],
23+
"parser": "./eslint-local-rules/parser",
24+
"parserOptions": {
25+
"sourceType": "module"
26+
},
27+
"rules": {
28+
"no-unused-vars": "off",
29+
"@typescript-eslint/no-unused-vars": "off",
30+
"react-hooks/exhaustive-deps": "off",
31+
"react/no-unknown-property": "off",
32+
"react-compiler/react-compiler": "off",
33+
"local-rules/lint-markdown-code-blocks": "error"
34+
}
35+
}
36+
]
1937
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

33
# dependencies
4-
/node_modules
4+
node_modules
55
/.pnp
66
.pnp.js
77

colors.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
18
/*
29
* Copyright (c) Facebook, Inc. and its affiliates.
310
*/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
```jsx
2+
import {useState} from 'react';
3+
function Counter() {
4+
const [count, setCount] = useState(0);
5+
setCount(count + 1);
6+
return <div>{count}</div>;
7+
}
8+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
```jsx title="Counter" {expectedErrors: {'react-compiler': [99]}} {expectedErrors: {'react-compiler': [2]}}
2+
import {useState} from 'react';
3+
function Counter() {
4+
const [count, setCount] = useState(0);
5+
setCount(count + 1);
6+
return <div>{count}</div>;
7+
}
8+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
```jsx {expectedErrors: {'react-compiler': 'invalid'}}
2+
import {useState} from 'react';
3+
function Counter() {
4+
const [count, setCount] = useState(0);
5+
setCount(count + 1);
6+
return <div>{count}</div>;
7+
}
8+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```bash
2+
setCount()
3+
```
4+
5+
```txt
6+
import {useState} from 'react';
7+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
```jsx {expectedErrors: {'react-compiler': [3]}}
2+
function Hello() {
3+
return <h1>Hello</h1>;
4+
}
5+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
```jsx {expectedErrors: {'react-compiler': [4]}}
2+
import {useState} from 'react';
3+
function Counter() {
4+
const [count, setCount] = useState(0);
5+
setCount(count + 1);
6+
return <div>{count}</div>;
7+
}
8+
```
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
const assert = require('assert');
9+
const fs = require('fs');
10+
const path = require('path');
11+
const {ESLint} = require('eslint');
12+
const plugin = require('..');
13+
14+
const FIXTURES_DIR = path.join(__dirname, 'fixtures', 'src', 'content');
15+
const PARSER_PATH = path.join(__dirname, '..', 'parser.js');
16+
17+
function createESLint({fix = false} = {}) {
18+
return new ESLint({
19+
useEslintrc: false,
20+
fix,
21+
plugins: {
22+
'local-rules': plugin,
23+
},
24+
overrideConfig: {
25+
parser: PARSER_PATH,
26+
plugins: ['local-rules'],
27+
rules: {
28+
'local-rules/lint-markdown-code-blocks': 'error',
29+
},
30+
parserOptions: {
31+
sourceType: 'module',
32+
},
33+
},
34+
});
35+
}
36+
37+
function readFixture(name) {
38+
return fs.readFileSync(path.join(FIXTURES_DIR, name), 'utf8');
39+
}
40+
41+
async function lintFixture(name, {fix = false} = {}) {
42+
const eslint = createESLint({fix});
43+
const filePath = path.join(FIXTURES_DIR, name);
44+
const markdown = readFixture(name);
45+
const [result] = await eslint.lintText(markdown, {filePath});
46+
return result;
47+
}
48+
49+
async function run() {
50+
const basicResult = await lintFixture('basic-error.md');
51+
assert.strictEqual(basicResult.messages.length, 1, 'expected one diagnostic');
52+
assert(
53+
basicResult.messages[0].message.includes('Calling setState during render'),
54+
'expected message to mention setState during render'
55+
);
56+
57+
const suppressedResult = await lintFixture('suppressed-error.md');
58+
assert.strictEqual(
59+
suppressedResult.messages.length,
60+
0,
61+
'expected suppression metadata to silence diagnostic'
62+
);
63+
64+
const staleResult = await lintFixture('stale-expected-error.md');
65+
assert.strictEqual(
66+
staleResult.messages.length,
67+
1,
68+
'expected stale metadata error'
69+
);
70+
assert.strictEqual(
71+
staleResult.messages[0].message,
72+
'React Compiler expected error on line 3 was not triggered'
73+
);
74+
75+
const duplicateResult = await lintFixture('duplicate-metadata.md');
76+
assert.strictEqual(
77+
duplicateResult.messages.length,
78+
2,
79+
'expected duplicate metadata to surface compiler diagnostic and stale metadata notice'
80+
);
81+
const duplicateFixed = await lintFixture('duplicate-metadata.md', {
82+
fix: true,
83+
});
84+
assert(
85+
duplicateFixed.output.includes("{expectedErrors: {'react-compiler': [4]}}"),
86+
'expected duplicates to be rewritten to a single canonical block'
87+
);
88+
assert(
89+
!duplicateFixed.output.includes('[99]'),
90+
'expected stale line numbers to be removed from metadata'
91+
);
92+
93+
const mixedLanguageResult = await lintFixture('mixed-language.md');
94+
assert.strictEqual(
95+
mixedLanguageResult.messages.length,
96+
0,
97+
'expected non-js code fences to be ignored'
98+
);
99+
100+
const malformedResult = await lintFixture('malformed-metadata.md');
101+
assert.strictEqual(
102+
malformedResult.messages.length,
103+
1,
104+
'expected malformed metadata to fall back to compiler diagnostics'
105+
);
106+
const malformedFixed = await lintFixture('malformed-metadata.md', {
107+
fix: true,
108+
});
109+
assert(
110+
malformedFixed.output.includes("{expectedErrors: {'react-compiler': [4]}}"),
111+
'expected malformed metadata to be replaced with canonical form'
112+
);
113+
}
114+
115+
run().catch((error) => {
116+
console.error(error);
117+
process.exitCode = 1;
118+
});

0 commit comments

Comments
 (0)