Skip to content

Commit 7f3ac1b

Browse files
voxpelliljharb
authored andcommitted
[New] add type generation
1 parent 4ecf034 commit 7f3ac1b

File tree

12 files changed

+134
-4
lines changed

12 files changed

+134
-4
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"ignorePatterns": [
1717
"coverage/",
1818
".nyc_output/",
19+
"test-published-types/",
1920
"tests/fixtures/flat-config/"
2021
],
2122
"rules": {

.github/workflows/type-check.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: "Types: check published types"
2+
3+
on: [pull_request, push]
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
test:
10+
name: TS ${{ matrix.ts_version }}, "${{ matrix.ts_lib }}"
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
ts_version:
16+
# The official ESLint types are not compatible with TS 3.9
17+
# - 3.9
18+
- '4.0'
19+
- 4.1
20+
- 4.2
21+
- 4.3
22+
- 4.4
23+
- 4.5
24+
- '5.0'
25+
- 5.5
26+
- 5.6
27+
ts_lib:
28+
- es2015
29+
- es2015,dom
30+
- es2020
31+
- esnext
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
persist-credentials: false
36+
show-progress: false
37+
38+
- uses: ljharb/actions/node/install@main
39+
name: 'nvm install lts/* && npm install'
40+
with:
41+
node-version: 'lts/*'
42+
skip-ls-check: true
43+
44+
- name: build types
45+
run: npm run build-types
46+
47+
- name: npm install working directory
48+
run: npm install
49+
working-directory: test-published-types
50+
51+
- name: install typescript version ${{ matrix.ts_version }}
52+
run: npm install --no-save typescript@${{ matrix.ts_version }}
53+
working-directory: test-published-types
54+
55+
- name: show installed typescript version
56+
run: npm list typescript --depth=0
57+
working-directory: test-published-types
58+
59+
- name: check types with lib "${{ matrix.ts_lib }}"
60+
run: npx tsc --lib ${{ matrix.ts_lib }}
61+
working-directory: test-published-types

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ package-lock.json
2828
yarn.lock
2929

3030
.npmignore
31+
32+
/lib/**/*.d.ts
33+
/lib/**/*.d.ts.map
34+
!/lib/types.d.ts
35+
/index.d.ts
36+
/index.d.ts.map

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
66

77
## Unreleased
88

9+
### Added
10+
* add type generation ([#3830][] @voxpelli)
11+
12+
[#3830]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3830
13+
914
## [7.36.1] - 2024.09.12
1015

1116
### Fixed

build.tsconfig.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "./tsconfig",
3+
"files": [
4+
"index.js"
5+
],
6+
"compilerOptions": {
7+
"declaration": true,
8+
"declarationMap": true,
9+
"noEmit": false,
10+
"emitDeclarationOnly": true
11+
}
12+
}

lib/rules/jsx-no-literals.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,8 @@ const elementOverrides = {
182182
},
183183
};
184184

185-
/** @type {import('eslint').Rule.RuleModule} */
186185
module.exports = {
187-
meta: {
186+
meta: /** @type {import('eslint').Rule.RuleModule["meta"]} */ ({
188187
docs: {
189188
description: 'Disallow usage of string literals in JSX',
190189
category: 'Stylistic Issues',
@@ -202,7 +201,7 @@ module.exports = {
202201
),
203202
additionalProperties: false,
204203
}],
205-
},
204+
}),
206205

207206
create(context) {
208207
/** @type {RawConfig} */

lib/util/makeNoMethodSetStateRule.js

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ function shouldBeNoop(context, methodName) {
4444
&& !testReactVersion(context, '999.999.999'); // for when the version is not specified
4545
}
4646

47+
// eslint-disable-next-line valid-jsdoc
48+
/**
49+
* @param {string} methodName
50+
* @param {(context: import('eslint').Rule.RuleContext) => boolean} [shouldCheckUnsafeCb]
51+
* @returns {import('eslint').Rule.RuleModule}
52+
*/
4753
module.exports = function makeNoMethodSetStateRule(methodName, shouldCheckUnsafeCb) {
4854
return {
4955
meta: {
@@ -90,6 +96,7 @@ module.exports = function makeNoMethodSetStateRule(methodName, shouldCheckUnsafe
9096
if (
9197
callee.type !== 'MemberExpression'
9298
|| callee.object.type !== 'ThisExpression'
99+
|| !('name' in callee.property)
93100
|| callee.property.name !== 'setState'
94101
) {
95102
return;

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"description": "React specific linting rules for ESLint",
66
"main": "index.js",
77
"scripts": {
8-
"prepack": "npmignore --auto --commentLines=autogenerated",
8+
"clean-built-types": "rm -f $(find . -maxdepth 1 -type f -name '*.d.ts*') $(find lib -type f -name '*.d.ts*' ! -name 'types.d.ts')",
9+
"prebuild-types": "npm run clean-built-types",
10+
"build-types": "tsc -p build.tsconfig.json",
11+
"prepack": "npm run build-types && npmignore --auto --commentLines=autogenerated",
912
"prelint": "npm run lint:docs",
1013
"lint:docs": "markdownlint \"**/*.md\"",
1114
"postlint:docs": "npm run update:eslint-docs -- --check",
@@ -96,13 +99,15 @@
9699
"!lib",
97100
"docs/",
98101
"test/",
102+
"test-published-types/",
99103
"tests/",
100104
"*.md",
101105
"*.config.js",
102106
".eslint-doc-generatorrc.js",
103107
".eslintrc",
104108
".editorconfig",
105109
"tsconfig.json",
110+
"build.tsconfig.json",
106111
".markdownlint*",
107112
"types"
108113
]

test-published-types/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

test-published-types/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const react = require('eslint-plugin-react');
4+
5+
/** @type {import('eslint').Linter.Config[]} */
6+
module.exports = [
7+
{
8+
plugins: {
9+
react,
10+
},
11+
},
12+
];

test-published-types/package.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "eslint-plugin-react-test-published-types",
3+
"private": true,
4+
"version": "0.0.0",
5+
"dependencies": {
6+
"eslint": "^9.11.1",
7+
"eslint-plugin-react": "file:.."
8+
}
9+
}

test-published-types/tsconfig.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
4+
"files": [
5+
"index.js"
6+
],
7+
8+
"compilerOptions": {
9+
"lib": ["esnext"],
10+
"types": ["node"]
11+
}
12+
}

0 commit comments

Comments
 (0)