@samitouri / QOS-React / commits / 442150e0e2

build(eslint-plugin-react-hooks): tsconfig and global types (#32283)

<!-- 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 Contributing to https://github.com/facebook/react/pull/32240, this change adds the tsconfig, tsup config, and estree type declarations that will be needed for that plugin's typescript migration.

michael faith committed Feb 3, 2025 at 11:07 UTC 442150e0e2783ce9ab407a113acd2656752323d2
4 files changed +98
packages/eslint-plugin-react-hooks/src/types/estree.d.ts new
+70
@@ -0,0 +1,70 @@
1 +/**
2 + * This file augments the `estree` types to include types that are not built-in to `estree` or `estree-jsx`.
3 + * This is necessary because the `estree` types are used by ESLint, and ESLint does not natively support
4 + * TypeScript or Flow types. Since we're not using a ton of them, we can just add them here, rather than
5 + * installing typescript estree or flow estree types.
6 + *
7 + * This also adds support for the AST mutation that the Exhaustive deps rule does to add parent nodes.
8 + */
9 +declare module 'estree' {
10 + // The Exhaustive deps rule mutates the AST to add parent nodes for efficient traversal.
11 + // We need to augment the `estree` types to support that.
12 + interface BaseNode {
13 + parent?: Node;
14 + }
15 +
16 + // Adding types that aren't built-in to estree or estree-jsx.
17 + // Namely, the specific TS and Flow types that we're using.
18 + interface AsExpression extends BaseExpression {
19 + type: 'AsExpression';
20 + expression: Expression | Identifier;
21 + }
22 +
23 + interface OptionalCallExpression extends BaseCallExpression {
24 + type: 'OptionalCallExpression';
25 + }
26 +
27 + interface OptionalMemberExpression extends MemberExpression {
28 + type: 'OptionalMemberExpression';
29 + }
30 +
31 + interface TSAsExpression extends BaseExpression {
32 + type: 'TSAsExpression';
33 + expression: Expression | Identifier;
34 + }
35 +
36 + interface TSTypeQuery extends BaseNode {
37 + type: 'TSTypeQuery';
38 + exprName: Identifier;
39 + }
40 +
41 + interface TSTypeReference extends BaseNode {
42 + type: 'TSTypeReference';
43 + typeName: Identifier;
44 + }
45 +
46 + interface TypeCastExpression extends BaseExpression {
47 + type: 'TypeCastExpression';
48 + expression: Expression | Identifier;
49 + }
50 +
51 + // Extend the set of known Expression types
52 + interface ExpressionMap {
53 + AsExpression: AsExpression;
54 + OptionalCallExpression: OptionalCallExpression;
55 + OptionalMemberExpression: OptionalMemberExpression;
56 + TSAsExpression: TSAsExpression;
57 + TypeCastExpression: TypeCastExpression;
58 + }
59 +
60 + // Extend the set of known Node types
61 + interface NodeMap {
62 + AsExpression: AsExpression;
63 + OptionalCallExpression: OptionalCallExpression;
64 + OptionalMemberExpression: OptionalMemberExpression;
65 + TSAsExpression: TSAsExpression;
66 + TSTypeQuery: TSTypeQuery;
67 + TSTypeReference: TSTypeReference;
68 + TypeCastExpression: TypeCastExpression;
69 + }
70 +}
packages/eslint-plugin-react-hooks/src/types/global.d.ts new
+4
@@ -0,0 +1,4 @@
1 +// In order to support the __EXPERIMENTAL__ global in TypeScript,
2 +// we need to declare it here. The value of this is set in both
3 +// the jest setup and CI build
4 +declare const __EXPERIMENTAL__: boolean;
packages/eslint-plugin-react-hooks/tsconfig.json new
+15
@@ -0,0 +1,15 @@
1 +{
2 + "extends": "@tsconfig/strictest/tsconfig.json",
3 + "compilerOptions": {
4 + "module": "ES2015",
5 + "target": "ES2015",
6 + "moduleResolution": "Bundler",
7 + "lib": ["ES2020"],
8 + "rootDir": ".",
9 + "noEmit": true,
10 + "sourceMap": false,
11 + "types": ["estree-jsx", "node"]
12 + },
13 + "exclude": ["node_modules"],
14 + "include": ["src/**/*.ts"]
15 +}
packages/eslint-plugin-react-hooks/tsup.config.ts new
+9
@@ -0,0 +1,9 @@
1 +import {defineConfig} from 'tsup';
2 +
3 +export default defineConfig({
4 + clean: true,
5 + dts: true,
6 + entry: ['src/index.ts'],
7 + format: ['cjs'],
8 + outDir: 'build',
9 +});