Skip to content

Commit

Permalink
[New] add type generation
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli authored and ljharb committed Sep 23, 2024
1 parent 4ecf034 commit 7f3ac1b
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 4 deletions.
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

- 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"]} */ ({
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"]
}
}

0 comments on commit 7f3ac1b

Please sign in to comment.