Skip to content

Commit 276362a

Browse files
authored
Merge branch 'main' into translate-activity
2 parents a5708b0 + 2937f62 commit 276362a

File tree

10 files changed

+177
-142
lines changed

10 files changed

+177
-142
lines changed

eslint-local-rules/__tests__/lint-markdown-code-blocks.test.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ const path = require('path');
1111
const {ESLint} = require('eslint');
1212
const plugin = require('..');
1313

14-
const FIXTURES_DIR = path.join(
15-
__dirname,
16-
'fixtures',
17-
'src',
18-
'content'
19-
);
14+
const FIXTURES_DIR = path.join(__dirname, 'fixtures', 'src', 'content');
2015
const PARSER_PATH = path.join(__dirname, '..', 'parser.js');
2116

2217
function createESLint({fix = false} = {}) {
@@ -53,11 +48,7 @@ async function lintFixture(name, {fix = false} = {}) {
5348

5449
async function run() {
5550
const basicResult = await lintFixture('basic-error.md');
56-
assert.strictEqual(
57-
basicResult.messages.length,
58-
1,
59-
'expected one diagnostic'
60-
);
51+
assert.strictEqual(basicResult.messages.length, 1, 'expected one diagnostic');
6152
assert(
6253
basicResult.messages[0].message.includes('Calling setState during render'),
6354
'expected message to mention setState during render'
@@ -91,9 +82,7 @@ async function run() {
9182
fix: true,
9283
});
9384
assert(
94-
duplicateFixed.output.includes(
95-
"{expectedErrors: {'react-compiler': [4]}}"
96-
),
85+
duplicateFixed.output.includes("{expectedErrors: {'react-compiler': [4]}}"),
9786
'expected duplicates to be rewritten to a single canonical block'
9887
);
9988
assert(
@@ -118,14 +107,12 @@ async function run() {
118107
fix: true,
119108
});
120109
assert(
121-
malformedFixed.output.includes(
122-
"{expectedErrors: {'react-compiler': [4]}}"
123-
),
110+
malformedFixed.output.includes("{expectedErrors: {'react-compiler': [4]}}"),
124111
'expected malformed metadata to be replaced with canonical form'
125112
);
126113
}
127114

128-
run().catch(error => {
115+
run().catch((error) => {
129116
console.error(error);
130117
process.exitCode = 1;
131118
});

eslint-local-rules/rules/metadata.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,19 @@ function parseExpectedErrorsEntries(rawEntries) {
8484

8585
if (parsed && typeof parsed === 'object') {
8686
for (const [key, value] of Object.entries(parsed)) {
87-
entries[key] = normalizeEntryValues(Array.isArray(value) ? value.flat() : value);
87+
entries[key] = normalizeEntryValues(
88+
Array.isArray(value) ? value.flat() : value
89+
);
8890
}
8991
}
9092

9193
return entries;
9294
}
9395

9496
function parseExpectedErrorsToken(tokenText) {
95-
const match = tokenText.match(/^\{\s*expectedErrors\s*:\s*(\{[\s\S]*\})\s*\}$/);
97+
const match = tokenText.match(
98+
/^\{\s*expectedErrors\s*:\s*(\{[\s\S]*\})\s*\}$/
99+
);
96100
if (!match) {
97101
return null;
98102
}
@@ -203,7 +207,9 @@ function cloneMetadata(metadata) {
203207
}
204208

205209
function findExpectedErrorsToken(metadata) {
206-
return metadata.tokens.find((token) => token.type === 'expectedErrors') || null;
210+
return (
211+
metadata.tokens.find((token) => token.type === 'expectedErrors') || null
212+
);
207213
}
208214

209215
function getCompilerExpectedLines(metadata) {

eslint-local-rules/rules/react-compiler.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,19 @@ function runReactCompiler(code, filename) {
9898
continue;
9999
}
100100

101-
const loc = typeof detail.primaryLocation === 'function'
102-
? detail.primaryLocation()
103-
: null;
101+
const loc =
102+
typeof detail.primaryLocation === 'function'
103+
? detail.primaryLocation()
104+
: null;
104105

105106
if (loc == null || typeof loc === 'symbol') {
106107
continue;
107108
}
108109

109-
const message = typeof detail.printErrorMessage === 'function'
110-
? detail.printErrorMessage(result.sourceCode, {eslint: true})
111-
: detail.description || 'Unknown React Compiler error';
110+
const message =
111+
typeof detail.printErrorMessage === 'function'
112+
? detail.printErrorMessage(result.sourceCode, {eslint: true})
113+
: detail.description || 'Unknown React Compiler error';
112114

113115
diagnostics.push({detail, loc, message});
114116
}

next.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ const nextConfig = {
3636
// Don't bundle the shim unnecessarily.
3737
config.resolve.alias['use-sync-external-store/shim'] = 'react';
3838

39+
// ESLint depends on the CommonJS version of esquery,
40+
// but Webpack loads the ESM version by default. This
41+
// alias ensures the correct version is used.
42+
//
43+
// More info:
44+
// https://github.com/reactjs/react.dev/pull/8115
45+
config.resolve.alias['esquery'] = 'esquery/dist/esquery.min.js';
46+
3947
const {IgnorePlugin, NormalModuleReplacementPlugin} = require('webpack');
4048
config.plugins.push(
4149
new NormalModuleReplacementPlugin(

src/components/MDX/Sandpack/runESLint.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ const getCodeMirrorPosition = (
2121

2222
const linter = new Linter();
2323

24-
// HACK! Eslint requires 'esquery' using `require`, but there's no commonjs interop.
25-
// because of this it tries to run `esquery.parse()`, while there's only `esquery.default.parse()`.
26-
// This hack places the functions in the right place.
27-
const esquery = require('esquery');
28-
esquery.parse = esquery.default?.parse;
29-
esquery.matches = esquery.default?.matches;
30-
3124
const reactRules = require('eslint-plugin-react-hooks').rules;
3225
linter.defineRules({
3326
'react-hooks/rules-of-hooks': reactRules['rules-of-hooks'],

0 commit comments

Comments
 (0)