Skip to content

Commit 129aa85

Browse files
authored
[compiler] Use diagnostic for "found suppression" error (facebook#33981)
1 parent bcea869 commit 129aa85

12 files changed

+40
-35
lines changed

compiler/apps/playground/__tests__/e2e/__snapshots__/page.spec.ts/compilationMode-all-output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { c as _c } from "react/compiler-runtime"; // 
2-
        @compilationMode:"all"
2+
@compilationMode:"all"
33
function nonReactFn() {
44
  const $ = _c(1);
55
  let t0;

compiler/apps/playground/components/Editor/Output.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ async function tabify(
137137
} else {
138138
language = 'markdown';
139139
output = `
140-
# Output
140+
# Summary
141141
142-
React Compiler compiled this function sucessfully, but there are lint errors that indicate potential issues with the original code.
142+
React Compiler compiled this function successfully, but there are lint errors that indicate potential issues with the original code.
143143
144144
## ${compilerOutput.errors.length} Lint Errors
145145
@@ -181,7 +181,7 @@ ${code}
181181
'Output',
182182
<TextTabContent
183183
output={errors}
184-
language="plaintext"
184+
language="markdown"
185185
diff={null}
186186
showInfoPanel={false}></TextTabContent>,
187187
);

compiler/apps/playground/components/Editor/monacoOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ export const monacoOptions: Partial<EditorProps['options']> = {
2828

2929
automaticLayout: true,
3030
wordWrap: 'on',
31-
wrappingIndent: 'deepIndent',
31+
wrappingIndent: 'same',
3232
};

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Suppression.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import {NodePath} from '@babel/core';
99
import * as t from '@babel/types';
1010
import {
11+
CompilerDiagnostic,
1112
CompilerError,
12-
CompilerErrorDetail,
1313
CompilerSuggestionOperation,
1414
ErrorSeverity,
1515
} from '../CompilerError';
@@ -181,12 +181,11 @@ export function suppressionsToCompilerError(
181181
'Unhandled suppression source',
182182
);
183183
}
184-
error.pushErrorDetail(
185-
new CompilerErrorDetail({
186-
reason: `${reason}. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior`,
187-
description: suppressionRange.disableComment.value.trim(),
184+
error.pushDiagnostic(
185+
CompilerDiagnostic.create({
186+
category: reason,
187+
description: `React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression \`${suppressionRange.disableComment.value.trim()}\``,
188188
severity: ErrorSeverity.InvalidReact,
189-
loc: suppressionRange.disableComment.loc ?? null,
190189
suggestions: [
191190
{
192191
description: suggestion,
@@ -197,6 +196,10 @@ export function suppressionsToCompilerError(
197196
op: CompilerSuggestionOperation.Remove,
198197
},
199198
],
199+
}).withDetail({
200+
kind: 'error',
201+
loc: suppressionRange.disableComment.loc ?? null,
202+
message: 'Found React rule suppression',
200203
}),
201204
);
202205
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bailout-on-flow-suppression.expect.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ function Foo(props) {
1818
```
1919
Found 1 error:
2020
21-
Error: React Compiler has skipped optimizing this component because one or more React rule violations were reported by Flow. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
21+
Error: React Compiler has skipped optimizing this component because one or more React rule violations were reported by Flow
2222
23-
$FlowFixMe[react-rule-hook].
23+
React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression `$FlowFixMe[react-rule-hook]`
2424
2525
error.bailout-on-flow-suppression.ts:4:2
2626
2 |
2727
3 | function Foo(props) {
2828
> 4 | // $FlowFixMe[react-rule-hook]
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React Compiler has skipped optimizing this component because one or more React rule violations were reported by Flow. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Found React rule suppression
3030
5 | useX();
3131
6 | return null;
3232
7 | }

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bailout-on-suppression-of-custom-rule.expect.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ function lowercasecomponent() {
2121
```
2222
Found 2 errors:
2323
24-
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
24+
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled
2525
26-
eslint-disable my-app/react-rule.
26+
React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression `eslint-disable my-app/react-rule`
2727
2828
error.bailout-on-suppression-of-custom-rule.ts:3:0
2929
1 | // @eslintSuppressionRules:["my-app","react-rule"]
3030
2 |
3131
> 3 | /* eslint-disable my-app/react-rule */
32-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Found React rule suppression
3333
4 | function lowercasecomponent() {
3434
5 | 'use forget';
3535
6 | const x = [];
3636
37-
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
37+
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled
3838
39-
eslint-disable-next-line my-app/react-rule.
39+
React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression `eslint-disable-next-line my-app/react-rule`
4040
4141
error.bailout-on-suppression-of-custom-rule.ts:7:2
4242
5 | 'use forget';
4343
6 | const x = [];
4444
> 7 | // eslint-disable-next-line my-app/react-rule
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Found React rule suppression
4646
8 | return <div>{x}</div>;
4747
9 | }
4848
10 | /* eslint-enable my-app/react-rule */

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-sketchy-code-use-forget.expect.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ function lowercasecomponent() {
1919
```
2020
Found 2 errors:
2121
22-
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
22+
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled
2323
24-
eslint-disable react-hooks/rules-of-hooks.
24+
React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression `eslint-disable react-hooks/rules-of-hooks`
2525
2626
error.invalid-sketchy-code-use-forget.ts:1:0
2727
> 1 | /* eslint-disable react-hooks/rules-of-hooks */
28-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Found React rule suppression
2929
2 | function lowercasecomponent() {
3030
3 | 'use forget';
3131
4 | const x = [];
3232
33-
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
33+
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled
3434
35-
eslint-disable-next-line react-hooks/rules-of-hooks.
35+
React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression `eslint-disable-next-line react-hooks/rules-of-hooks`
3636
3737
error.invalid-sketchy-code-use-forget.ts:5:2
3838
3 | 'use forget';
3939
4 | const x = [];
4040
> 5 | // eslint-disable-next-line react-hooks/rules-of-hooks
41-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Found React rule suppression
4242
6 | return <div>{x}</div>;
4343
7 | }
4444
8 | /* eslint-enable react-hooks/rules-of-hooks */

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-unclosed-eslint-suppression.expect.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ function CrimesAgainstReact() {
3838
```
3939
Found 1 error:
4040
41-
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
41+
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled
4242
43-
eslint-disable react-hooks/rules-of-hooks.
43+
React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression `eslint-disable react-hooks/rules-of-hooks`
4444
4545
error.invalid-unclosed-eslint-suppression.ts:2:0
4646
1 | // Note: Everything below this is sketchy
4747
> 2 | /* eslint-disable react-hooks/rules-of-hooks */
48-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
48+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Found React rule suppression
4949
3 | function lowercasecomponent() {
5050
4 | 'use forget';
5151
5 | const x = [];

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.sketchy-code-exhaustive-deps.expect.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ function Component() {
2222
```
2323
Found 1 error:
2424
25-
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
25+
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled
2626
27-
eslint-disable-next-line react-hooks/exhaustive-deps.
27+
React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression `eslint-disable-next-line react-hooks/exhaustive-deps`
2828
2929
error.sketchy-code-exhaustive-deps.ts:6:7
3030
4 | () => {
3131
5 | item.push(1);
3232
> 6 | }, // eslint-disable-next-line react-hooks/exhaustive-deps
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Found React rule suppression
3434
7 | []
3535
8 | );
3636
9 |

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.sketchy-code-rules-of-hooks.expect.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export const FIXTURE_ENTRYPOINT = {
2323
```
2424
Found 1 error:
2525
26-
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
26+
Error: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled
2727
28-
eslint-disable react-hooks/rules-of-hooks.
28+
React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression `eslint-disable react-hooks/rules-of-hooks`
2929
3030
error.sketchy-code-rules-of-hooks.ts:1:0
3131
> 1 | /* eslint-disable react-hooks/rules-of-hooks */
32-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Found React rule suppression
3333
2 | function lowercasecomponent() {
3434
3 | const x = [];
3535
4 | return <div>{x}</div>;

0 commit comments

Comments
 (0)