Skip to content

Commit

Permalink
feat(eslint-plugin-react-hooks): convert to typescript and package ty…
Browse files Browse the repository at this point in the history
…pe declarations (#32240)

<!--
  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

This change converts the eslint hooks plugin to typescript, which also
allows us to include type declarations in the package, for those using
[typescript eslint
configs](https://eslint.org/blog/2025/01/eslint-v9.18.0-released/#stable-typescript-configuration-file-support).

### Constituent changes that should land before this one

- [x] ~#32276
- [x] #32279
- [x] #32283
- [x] #32393
- [x] #32396

Closes #30119

---------

Co-authored-by: Lauren Tan <[email protected]>
  • Loading branch information
michaelfaith and poteto authored Feb 16, 2025
1 parent 037b25c commit 5adf402
Show file tree
Hide file tree
Showing 14 changed files with 574 additions and 857 deletions.
8 changes: 8 additions & 0 deletions packages/eslint-plugin-react-hooks/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* This file is purely being used for local jest runs, and doesn't participate in the build process.
*/
'use strict';

module.exports = {
extends: '../../babel.config-ts.js',
};
9 changes: 1 addition & 8 deletions packages/eslint-plugin-react-hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
/**
* 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.
*/

export * from './src/index';
module.exports = require('./src/index.ts');
8 changes: 8 additions & 0 deletions packages/eslint-plugin-react-hooks/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

process.env.NODE_ENV = 'development';

module.exports = {
setupFiles: [require.resolve('../../scripts/jest/setupEnvironment.js')],
moduleFileExtensions: ['ts', 'js', 'json'],
};
1 change: 1 addition & 0 deletions packages/eslint-plugin-react-hooks/npm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './cjs/eslint-plugin-react-hooks';
11 changes: 9 additions & 2 deletions packages/eslint-plugin-react-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@
"files": [
"LICENSE",
"README.md",
"cjs",
"index.js",
"cjs"
"index.d.ts"
],
"keywords": [
"eslint",
"eslint-plugin",
"eslintplugin",
"react"
],
"scripts": {
"test": "jest",
"typecheck": "tsc --noEmit"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/facebook/react/issues"
},
"main": "./index.js",
"types": "./index.d.ts",
"engines": {
"node": ">=10"
},
Expand All @@ -32,6 +39,7 @@
},
"devDependencies": {
"@babel/eslint-parser": "^7.11.4",
"@babel/preset-typescript": "^7.26.0",
"@tsconfig/strictest": "^2.0.5",
"@typescript-eslint/parser-v2": "npm:@typescript-eslint/parser@^2.26.0",
"@typescript-eslint/parser-v3": "npm:@typescript-eslint/parser@^3.10.0",
Expand All @@ -45,7 +53,6 @@
"eslint-v7": "npm:eslint@^7.7.0",
"eslint-v9": "npm:eslint@^9.0.0",
"jest": "^29.5.0",
"tsup": "^8.3.5",
"typescript": "^5.4.3"
}
}
Loading

0 comments on commit 5adf402

Please sign in to comment.