Skip to content

Commit 4b38c7c

Browse files
committed
feat(eslint-plugin-react-hooks): convert to typescript and package type declarations
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).
1 parent 804f4b4 commit 4b38c7c

File tree

15 files changed

+1165
-386
lines changed

15 files changed

+1165
-386
lines changed

compiler/packages/eslint-plugin-react-compiler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@babel/preset-env": "^7.22.4",
2424
"@babel/preset-typescript": "^7.18.6",
2525
"@babel/types": "^7.19.0",
26-
"@types/eslint": "^8.56.6",
26+
"@types/eslint": "^8.56.12",
2727
"@types/node": "^20.2.5",
2828
"babel-jest": "^29.0.3",
2929
"eslint": "8.57.0",

packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const ESLintTesterV9 = require('eslint-v9').RuleTester;
1414
const ReactHooksESLintPlugin = require('eslint-plugin-react-hooks');
1515
const ReactHooksESLintRule = ReactHooksESLintPlugin.rules['exhaustive-deps'];
1616

17+
global.__EXPERIMENTAL__ =
18+
global.__EXPERIMENTAL__ ?? process.env.__EXPERIMENTAL__;
19+
1720
/**
1821
* A string template tag that removes padding from the left side of multi-line strings
1922
* @param {Array} strings array of code strings (only one expected)

packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const ESLintTesterV9 = require('eslint-v9').RuleTester;
1414
const ReactHooksESLintPlugin = require('eslint-plugin-react-hooks');
1515
const ReactHooksESLintRule = ReactHooksESLintPlugin.rules['rules-of-hooks'];
1616

17+
global.__EXPERIMENTAL__ =
18+
global.__EXPERIMENTAL__ ?? process.env.__EXPERIMENTAL__;
19+
1720
/**
1821
* A string template tag that removes padding from the left side of multi-line strings
1922
* @param {Array} strings array of code strings (only one expected)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
module.exports = {
4+
plugins: [
5+
'@babel/plugin-syntax-jsx',
6+
'@babel/plugin-transform-flow-strip-types',
7+
['@babel/plugin-proposal-class-properties', {loose: true}],
8+
'syntax-trailing-function-commas',
9+
[
10+
'@babel/plugin-proposal-object-rest-spread',
11+
{loose: true, useBuiltIns: true},
12+
],
13+
['@babel/plugin-transform-template-literals', {loose: true}],
14+
'@babel/plugin-transform-literals',
15+
'@babel/plugin-transform-arrow-functions',
16+
'@babel/plugin-transform-block-scoped-functions',
17+
'@babel/plugin-transform-object-super',
18+
'@babel/plugin-transform-shorthand-properties',
19+
'@babel/plugin-transform-computed-properties',
20+
'@babel/plugin-transform-for-of',
21+
['@babel/plugin-transform-spread', {loose: true, useBuiltIns: true}],
22+
'@babel/plugin-transform-parameters',
23+
['@babel/plugin-transform-destructuring', {loose: true, useBuiltIns: true}],
24+
],
25+
};

packages/eslint-plugin-react-hooks/index.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/eslint-plugin-react-hooks/npm/index.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/eslint-plugin-react-hooks/package.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,48 @@
1010
"files": [
1111
"LICENSE",
1212
"README.md",
13-
"index.js",
14-
"cjs"
13+
"build"
1514
],
1615
"keywords": [
1716
"eslint",
1817
"eslint-plugin",
1918
"eslintplugin",
2019
"react"
2120
],
21+
"scripts": {
22+
"build": "tsup",
23+
"test": "tsup && jest",
24+
"typecheck": "tsc"
25+
},
2226
"license": "MIT",
27+
"homepage": "https://react.dev/",
2328
"bugs": {
2429
"url": "https://github.com/facebook/react/issues"
2530
},
31+
"main": "build/index.js",
32+
"types": "build/index.d.ts",
2633
"engines": {
2734
"node": ">=10"
2835
},
29-
"homepage": "https://react.dev/",
3036
"peerDependencies": {
3137
"eslint": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0"
3238
},
3339
"devDependencies": {
3440
"@babel/eslint-parser": "^7.11.4",
41+
"@tsconfig/strictest": "^2.0.5",
3542
"@typescript-eslint/parser-v2": "npm:@typescript-eslint/parser@^2.26.0",
3643
"@typescript-eslint/parser-v3": "npm:@typescript-eslint/parser@^3.10.0",
3744
"@typescript-eslint/parser-v4": "npm:@typescript-eslint/parser@^4.1.0",
3845
"@typescript-eslint/parser-v5": "npm:@typescript-eslint/parser@^5.62.0",
46+
"@types/eslint": "^8.56.12",
47+
"@types/estree": "^1.0.6",
48+
"@types/estree-jsx": "^1.0.5",
49+
"@types/node": "^20.2.5",
3950
"babel-eslint": "^10.0.3",
4051
"eslint-v7": "npm:eslint@^7.7.0",
41-
"eslint-v9": "npm:eslint@^9.0.0"
52+
"eslint-v9": "npm:eslint@^9.0.0",
53+
"jest": "^29.5.0",
54+
"tsup": "^8.3.5",
55+
"typescript": "^5.4.3"
4256
}
4357
}

0 commit comments

Comments
 (0)