Skip to content

Commit 733a78b

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 f75236e commit 733a78b

File tree

9 files changed

+551
-362
lines changed

9 files changed

+551
-362
lines changed

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/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@
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",
2327
"bugs": {
2428
"url": "https://github.com/facebook/react/issues"
2529
},
30+
"main": "build/index.js",
31+
"types": "build/index.d.ts",
2632
"engines": {
2733
"node": ">=10"
2834
},

0 commit comments

Comments
 (0)