Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate type declarations from JSDoc #3830

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ignorePatterns": [
"coverage/",
".nyc_output/",
"test-published-types/",
"tests/fixtures/flat-config/"
],
"rules": {
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/type-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "Types: check published types"

on: [pull_request, push]

permissions:
contents: read

jobs:
test:
name: TS ${{ matrix.ts_version }}, "${{ matrix.ts_lib }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ts_version:
# The official ESLint types are not compatible with TS 3.9
# - 3.9
- '4.0'
- 4.1
- 4.2
- 4.3
- 4.4
- 4.5
- '5.0'
- 5.5
- 5.6
ts_lib:
- es2015
- es2015,dom
- es2020
- esnext
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
show-progress: false
ljharb marked this conversation as resolved.
Show resolved Hide resolved

- uses: ljharb/actions/node/install@main
name: 'nvm install lts/* && npm install'
with:
node-version: 'lts/*'
skip-ls-check: true

- name: build types
run: npm run build-types

- name: npm install working directory
run: npm install
working-directory: test-published-types

- name: install typescript version ${{ matrix.ts_version }}
run: npm install --no-save typescript@${{ matrix.ts_version }}
working-directory: test-published-types

- name: show installed typescript version
run: npm list typescript --depth=0
working-directory: test-published-types

- name: check types with lib "${{ matrix.ts_lib }}"
run: npx tsc --lib ${{ matrix.ts_lib }}
working-directory: test-published-types
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ package-lock.json
yarn.lock

.npmignore

/lib/**/*.d.ts
/lib/**/*.d.ts.map
!/lib/types.d.ts
/index.d.ts
/index.d.ts.map
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

## Unreleased

### Added
* add type generation ([#3830][] @voxpelli)

[#3830]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3830

## [7.36.1] - 2024.09.12

### Fixed
Expand Down
12 changes: 12 additions & 0 deletions build.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig",
"files": [
"index.js"
],
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"noEmit": false,
"emitDeclarationOnly": true
}
}
5 changes: 2 additions & 3 deletions lib/rules/jsx-no-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ const elementOverrides = {
},
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
meta: /** @type {import('eslint').Rule.RuleModule["meta"]} */ ({
ljharb marked this conversation as resolved.
Show resolved Hide resolved
docs: {
description: 'Disallow usage of string literals in JSX',
category: 'Stylistic Issues',
Expand All @@ -202,7 +201,7 @@ module.exports = {
),
additionalProperties: false,
}],
},
}),

create(context) {
/** @type {RawConfig} */
Expand Down
7 changes: 7 additions & 0 deletions lib/util/makeNoMethodSetStateRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ function shouldBeNoop(context, methodName) {
&& !testReactVersion(context, '999.999.999'); // for when the version is not specified
}

// eslint-disable-next-line valid-jsdoc
/**
* @param {string} methodName
* @param {(context: import('eslint').Rule.RuleContext) => boolean} [shouldCheckUnsafeCb]
* @returns {import('eslint').Rule.RuleModule}
*/
module.exports = function makeNoMethodSetStateRule(methodName, shouldCheckUnsafeCb) {
return {
meta: {
Expand Down Expand Up @@ -90,6 +96,7 @@ module.exports = function makeNoMethodSetStateRule(methodName, shouldCheckUnsafe
if (
callee.type !== 'MemberExpression'
|| callee.object.type !== 'ThisExpression'
|| !('name' in callee.property)
|| callee.property.name !== 'setState'
) {
return;
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"description": "React specific linting rules for ESLint",
"main": "index.js",
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"clean-built-types": "rm -f $(find . -maxdepth 1 -type f -name '*.d.ts*') $(find lib -type f -name '*.d.ts*' ! -name 'types.d.ts')",
"prebuild-types": "npm run clean-built-types",
"build-types": "tsc -p build.tsconfig.json",
"prepack": "npm run build-types && npmignore --auto --commentLines=autogenerated",
"prelint": "npm run lint:docs",
"lint:docs": "markdownlint \"**/*.md\"",
"postlint:docs": "npm run update:eslint-docs -- --check",
Expand Down Expand Up @@ -96,13 +99,15 @@
"!lib",
"docs/",
"test/",
"test-published-types/",
"tests/",
"*.md",
"*.config.js",
".eslint-doc-generatorrc.js",
".eslintrc",
".editorconfig",
"tsconfig.json",
"build.tsconfig.json",
".markdownlint*",
"types"
]
Expand Down
1 change: 1 addition & 0 deletions test-published-types/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
12 changes: 12 additions & 0 deletions test-published-types/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const react = require('eslint-plugin-react');

/** @type {import('eslint').Linter.Config[]} */
module.exports = [
{
plugins: {
react,
},
},
];
9 changes: 9 additions & 0 deletions test-published-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "eslint-plugin-react-test-published-types",
"private": true,
"version": "0.0.0",
"dependencies": {
"eslint": "^9.11.1",
"eslint-plugin-react": "file:.."
}
}
12 changes: 12 additions & 0 deletions test-published-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",

"files": [
"index.js"
],

"compilerOptions": {
"lib": ["esnext"],
"types": ["node"]
}
}