Commit Graph

54 Commits

Author SHA1 Message Date
mofeiZ
a99d8e8d97
[compiler][eslint] Report bailout diagnostics with correct column # (#30977)
Compiler bailout diagnostics should now highlight only the first line of
the source location span.

(Resubmission of #30423 which was reverted due to invalid column
number.)
2024-09-16 15:56:24 -04:00
Lauren Tan
b57d282369
Revert "[compiler][eslint] remove compilationMode override; report bailouts on first line"
This reverts commit b34b750729.

This hack doesn't play well internally so I'm reverting this for now
(but keeping the compilationMode override). I'll audit the locations we
report later and try to make them more accurate so we won't need this
workaround.

ghstack-source-id: b6be29c11d
Pull Request resolved: https://github.com/facebook/react/pull/30792
2024-08-22 15:04:39 -04:00
Lauren Tan
34edf3b684
[compiler] Surface unused opt out directives in eslint
This PR updates the eslint plugin to report unused opt out directives.
One of the downsides of the opt out directive is that it opts the
component/hook out of compilation forever, even if the underlying issue
was fixed in product code or fixed in the compiler.

ghstack-source-id: 81deb5c11b
Pull Request resolved: https://github.com/facebook/react/pull/30721
2024-08-16 18:12:05 -04:00
Mike Vitousek
5edbe29dbe [compiler] Make ref enforcement on by default
Summary:
The change earlier in this stack makes it less safe to have ref enforcement disabled. This diff enables it by default.

ghstack-source-id: d3ab5f1b28b7aed0f0d6d69547bb638a1e326b66
Pull Request resolved: https://github.com/facebook/react/pull/30716
2024-08-16 13:27:14 -04:00
Mike Vitousek
9eb288e657 [compiler][ez] Default to using flow suppressions
ghstack-source-id: b6592650e0
Pull Request resolved: https://github.com/facebook/react/pull/30622
2024-08-06 23:47:09 -07:00
Ahmed Abdelbaset
f7ee804c22
[compiler] Add git info to package.json files in compiler packages (#30475)
This PR adds the repository field to `compiler/packages/*/package.json`

| eslint-plugin-react-compiler | eslint-plugin-react-hooks |
| --- | --- |
|
![image](https://github.com/user-attachments/assets/3392a496-1ff1-4f36-ab96-cfbe1ed88693)
|
![image](https://github.com/user-attachments/assets/b0605dba-eef7-44fe-9484-979b4814d9fb)
|
2024-07-26 12:56:39 -04:00
Lauren Tan
83035ee299
Bump version to 0.0.0-experimental-9ed098e-20240725 2024-07-25 15:46:46 -04:00
Lauren Tan
9f04494b8e
Bump version to 0.0.0-experimental-47e15aa-20240725 2024-07-25 12:27:05 -04:00
Mofei Zhang
b34b750729 [compiler][eslint] remove compilationMode override; report bailouts on first line
ghstack-source-id: 1870c7aa09
Pull Request resolved: https://github.com/facebook/react/pull/30423
2024-07-23 14:24:36 -04:00
Jan Kassens
fd2b3e13d3
Compiler: unfork prettier config (#30205)
Updates the prettier config to format all `.ts` and `.tsx` files in the
repo using the existing defaults and removing overrides.

The first commit in this PR contains the config changes, the second is
just the result of running `yarn prettier-all`.
2024-07-18 17:00:24 -04:00
Mofei Zhang
1f60a41801 [compiler][eslint] Add donotuse flag for bailouts
---
Adding an experimental / donotuse flag for small Meta internal usecase

ghstack-source-id: 908ef1e150c9fef1347616c9c4dc6bf3316900b0
Pull Request resolved: https://github.com/facebook/react/pull/30342
2024-07-15 17:56:04 -04:00
Mofei Zhang
e307a49544 [compiler][eslint] Use logger callback instead of exceptions to report eslint diagnostics
---
* panicThreshold: `all_errors` -> `none`
* inject an error logger through compiler config (instead of using exceptions)

We currently report at most one lint warning per file, this lets us exhaustively report all available ones (see new
test fixture for example)

ghstack-source-id: 5299315574d11929efc39ee8f6033e3035d1e378
Pull Request resolved: https://github.com/facebook/react/pull/30336
2024-07-15 17:56:04 -04:00
Mofei Zhang
6cca9c3184 [compiler][be] Fix lint violations in eslint-plugin
ghstack-source-id: 7c11dce833fcf8f46aaa23858ac94a05e870fae8
Pull Request resolved: https://github.com/facebook/react/pull/30335
2024-07-15 17:56:04 -04:00
Lauren Tan
bdb355f349 Bump version to 0.0.0-experimental-0998c1e-20240625 2024-06-25 12:42:06 -04:00
Lauren Tan
d46985282d Bump version to 0.0.0-experimental-8ae29d2-20240614 2024-06-14 17:21:59 -04:00
Lauren Tan
c6b651bee0 Bump version to 0.0.0-experimental-51a85ea-20240601 2024-06-01 08:15:27 +09:00
Lauren Tan
113c8e7f72 [compiler:eslint] Don't crash if hermes parser fails to parse
Eslint rules should never throw, so if we fail to parse with Babel or
Hermes, we should just ignore the error. This should fix issues such as
trying to run the eslint rule on non tsx|ts|jsx|js files, Hermes parser
not supporting certain JS syntax, etc.

I didn't add a test for this as our eslint-rule-tester config uses
hermes-eslint parser, so it wasn't possible to add a top level await as
it would crash hermes-eslint before our rule was triggered. Similarly I
couldn't add a test for non-JS files as it would not be parseable by
hermes-eslint.

Fixes #29107

ghstack-source-id: 60afcdb89ab4a8d2e4697cc50c5490803e7cbeac
Pull Request resolved: https://github.com/facebook/react/pull/29631
2024-06-01 08:04:41 +09:00
Lauren Tan
bd30dc3ae2 Bump version to 0.0.0-experimental-a97cca1-20240529 2024-05-29 12:01:35 +09:00
Lauren Tan
9d530e94c4 [compiler:babel] Don't read config files when not running as part of
user's pipeline

When the user app has a babel.config file that is missing the compiler,
strange things happen as babel does some strange merging of options from
the user's config and in various callsites like in our eslint rule and
healthcheck script. To minimize odd behavior, we default to not reading
the user's babel.config

Fixes #29135

ghstack-source-id: d6fdc43c5c
Pull Request resolved: https://github.com/facebook/react/pull/29211
2024-05-29 11:46:27 +09:00
Lauren Tan
630c6fb89b Bump version to 0.0.0-experimental-c8b3f72-20240517 2024-05-17 15:17:05 -07:00
Jan Amann
94896cb8c5
[React Compiler] Fix rule name for ESLint plugin (#29096)
/cc @poteto

<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->

Seems like the README of the package was outdated.

## How did you test this change?

Tried this configuration in a project of mine.

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->
2024-05-16 12:36:22 -04:00
Kirill Zyusko
e8779a9a9a
[React Compiler] use filename instead of context.filename in ESLint plugin (#29104)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

Use `filename` instead of `context.filename` in eslint compiler.

The problem is that in `react-native` + `typescript` project the context
may not have `filename`:

<img width="384" alt="image"
src="https://github.com/facebook/react/assets/22820318/e5d184fa-5ac9-4512-96b9-644baa3d5f25">

And eslint will crash with:

```bash
TypeError: Error while loading rule 'react-compiler/react-compiler': Cannot read properties of undefined (reading 'endsWith')
```

But in fact we already derive `filename` variable earlier so we can
simply reuse the variable (I guess).

## How did you test this change?

- add `eslint` plugin to RN project;
- run eslint
2024-05-16 12:35:52 -04:00
Lauren Tan
c912057093 Bump version to 0.0.0-experimental-53bb89e-20240515 2024-05-15 17:43:41 -07:00
Lauren Tan
cf7d895db6 [compiler:eslint] Fix false positive with TS type param syntax
Previously we would attempt to parse code in the eslint plugin with the
HermesParser first as it can handle some TS syntax. However, this was
leading to a mis-parse of React hook calls with type params (eg,
`useRef<null>()` as a BinaryExpression rather than a CallExpression with
a type param. This triggered our validation that Hooks should not be
used as normal values.

To fix this, we now try to parse with the babel parser (with TS support)
for filenames that end with ts/tsx, and fallback to HermesParser for
regular JS files.

ghstack-source-id: 5b7231031c
Pull Request resolved: https://github.com/facebook/react/pull/29081
2024-05-15 15:44:21 -07:00
Christoph Nakazawa
cfeb491ee7
Add a main field to eslint-plugin-react-compiler, fixes #29068. (#29072)
## Summary

The main field is missing, this fixes it.

Fixes #29068.

## How did you test this change?

Manually patched the package and tried it in my codebase.
2024-05-15 17:02:20 -04:00
Lauren Tan
5501ebceec Bump version to 0.0.0-experimental-e04a001-20240515 2024-05-15 08:05:02 -07:00
Lauren Tan
67ea821e5f [publish] Fix files field for packages, invalid version range
The [`files` field](https://docs.npmjs.com/cli/v10/commands/npm-publish#files-included-in-package)
controls what files get included in the published package.

This PR specifies the `files` field on our publishable packages to only
include the `dist` directory, since we don't need to ship any types or
sourcemaps with 3 of them.

react-compiler-runtime is a runtime package which has sourcemaps, so we
also include the `src` directory in the published package.

Also fixes an invalid version range for the react peer dependency in
react-compiler-runtime, tested that it works via https://semver.npmjs.com/

ghstack-source-id: 12b36c203fc9fd8d72a1995fb3fba2312de4aa51
Pull Request resolved: https://github.com/facebook/react-forget/pull/2965
2024-05-14 11:02:29 -04:00
Lauren Tan
7caf071e01 Add failing test for eslint-plugin false positive
The eslint rule seems to false positive on this typescript syntax, but
strangely the compiler does not

ghstack-source-id: 19baa24ff7addd83f59e2b03fdb180af169a2794
Pull Request resolved: https://github.com/facebook/react-forget/pull/2913
2024-05-06 20:39:49 -04:00
Lauren Tan
d0a51e7dfc Allow eslint rule reportable severity to be set
During the demo I might show an example of fixing a
CannotPreserveMemoization error. But I don't want to make that
reportable by default, so this PR allows configuration like so

```js
module.exports = {
  root: true,
  plugins: [
    'eslint-plugin-react-compiler',
  ],
  rules: {
    'react-compiler/react-compiler': [
      'error', {
        reportableLevels: new Set([
          'InvalidJs',
          'InvalidReact',
          'CannotPreserveMemoization'
        ])
      }
     ]
  }
}
```

ghstack-source-id: 984c6d3cb7e19c8fea2bb88108dd26335c031573
Pull Request resolved: https://github.com/facebook/react-forget/pull/2936
2024-05-06 20:07:36 -04:00
Lauren Tan
84d28ebcc5 Default to raising all errors in eslint plugin
We control what gets reported via another function anyway so it's better
to raise everything at the compiler config level. This lets us configure
what level of diagnostic is reportable later

ghstack-source-id: 996d3cbb8d8f3e1bbe943210b8d633420e0f3f3b
Pull Request resolved: https://github.com/facebook/react-forget/pull/2935
2024-05-06 20:07:35 -04:00
Joe Savona
1c8f8bfb89 Rename ReactForgetBabelPlugin locals
ghstack-source-id: 9cd5fe41ae322632dfeb3d5c7468268678006d94
Pull Request resolved: https://github.com/facebook/react-forget/pull/2929
2024-05-02 17:14:25 -07:00
Joe Savona
48e0c70292 Rename babel plugin
ghstack-source-id: bb66913e2d3c814696311371ed655f3da03d1199
Pull Request resolved: https://github.com/facebook/react-forget/pull/2926
2024-05-02 14:12:33 -07:00
Lauren Tan
fddc0151fe Remove duplicated hermes-parser
ghstack-source-id: 79f3319d87909d05731ef821d0ffe86cb01b0432
Pull Request resolved: https://github.com/facebook/react-forget/pull/2920
2024-04-30 21:34:36 -04:00
Sathya Gunsasekaran
8d234c64eb [hir] Remove hermes parser
Exporting the hermes parser breaks the playground
as the hermes parser can not work in the browser.

No one is using this directly anyway -- snap and
others bundle hermes parser on their own, so,
let's remove it.

ghstack-source-id: d448c346eb137f8ba6ada4ad113e41a90b29baff
Pull Request resolved: https://github.com/facebook/react-forget/pull/2890
2024-04-23 12:28:42 +01:00
Joe Savona
896d1b0027 [dx] Improve error message from InferReferenceEffects
ghstack-source-id: 06265d9676b671a5b02ca05433a219dd219be4f1
Pull Request resolved: https://github.com/facebook/react-forget/pull/2883
2024-04-22 08:14:35 -07:00
Joe Savona
87993f333a [dx] Update suppression error messages
ghstack-source-id: 0c362a349de86a07b4e9e381b942939ce4a24e69
Pull Request resolved: https://github.com/facebook/react-forget/pull/2859
2024-04-17 18:25:40 -07:00
Lauren Tan
ec05176fb3 Make string values for config case-insensitive
Fixes a tiny inconsistency with compiler options where one was all
uppercase and one all lowercase by normalizing to lowercase regardless
of the casing of the user's config.

ghstack-source-id: fe60a3259de89a1b3fdd7475950e16e96cc57f6b
Pull Request resolved: https://github.com/facebook/react-forget/pull/2832
2024-04-11 10:45:35 -04:00
Lauren Tan
1f35f7e320 Add new ErrorSeverity.CannotPreserveMemoization
This adds a new category of error where the compiler cannot preserve
memoization exactly how as it was originally authored. We're adding a
new category here because it's not an actionable error, and allows us to
more specifically control whether it's reportable or not.

ghstack-source-id: 9693cd42ca64b980248c6202091bdd4c827e1cd4
Pull Request resolved: https://github.com/facebook/react-forget/pull/2824
2024-04-08 11:00:41 -04:00
Jan Kassens
76bb13cd26 First attempt at making the linter work with advanced TypeScript syntax
First attempt at making the linter work with advanced TypeScript syntax 

Falls back to the babel parser for some advanced syntax like string template 
syntax. 

This is pretty hacky as it doesn't take in any parsing options that are 
configured for the outer ESLint parser, not sure how that could be handled.
2024-04-04 18:31:31 -04:00
Lauren Tan
5485ed0855 Standardize on banner2 plugin 2024-04-02 12:13:41 -04:00
Lauren Tan
b4eeae6f5d Share rollup packages across workspace 2024-04-02 12:13:39 -04:00
Lauren Tan
91826d4924 Configure rollup to strip comments and whitespace
For now this configures rollup to strip out comments in DEV builds and 
whitespace. Unfortunately there's no easy way to do this in just terser alone or 
other minifiers/manglers, so I had to add prettier as well to re-format the 
minified code. This does make the build a little bit slower: 

``` before: yarn build  118.96s user 12.38s system 185% cpu 1:10.81 total after: 
 yarn build  121.55s user 12.90s system 183% cpu 1:13.17 total ``` 

Eventually I would like to have a similar setup to React's rollup config where 
we can have DEV and prod builds. After the repo merge we could probably share or 
reuse bits of React's rollup config.
2024-04-02 12:13:38 -04:00
Lauren Tan
ba661c80f3 Remove comments in builds 2024-04-02 10:32:24 -04:00
Lauren Tan
4e6aa42773 Upgrade to typescript 5.4.3
This PR makes all packages share the same typescript version and updates us to 
latest versions of typescript, ts-node, typescript-eslint/eslint-plugin and 
typescript-eslint/parser. 

I also noticed that the tsconfig we were extending (node18-strictest) was 
deprecated, so I switched us over to one that's more up to date. 

Also had to make a couple of small changes to the playground so that continues 
to build correctly.
2024-04-02 10:32:23 -04:00
Lauren Tan
7748ce8f3f Update compiler naming in remaining error text 2024-03-28 10:40:05 -04:00
Lauren Tan
f4229cdb7f Rename error type 2024-03-28 10:40:04 -04:00
Lauren Tan
e6ce5e4922 [eslint] Update devDep to match types 2024-03-25 15:00:34 -04:00
Lauren Tan
15abd38911 Cleanup unused eslint-browser and js-fuzzer packages
These were never used, so let's clean them up
2024-03-25 15:00:31 -04:00
Jan Kassens
d7d82e7bee Correct eslint-plugin-react-compiler dependencies
Correct eslint-plugin-react-compiler dependencies 

- The eslint plugin doesn't actually depend on the babel plugin as it compiles 
in the dependencies. - `zod` and `zod-validation-error` were missing, but 
required to run the plugin. - Update to the `hermes-parser` dependency just to 
keep it updated.
2024-03-22 17:03:30 -04:00
Jan Kassens
72d374e978 [linter] rename ReactForgetDiagnostics to ReactCompilerRule
[linter] rename ReactForgetDiagnostics to ReactCompilerRule
2024-03-14 11:53:32 -04:00