Skip to content

Commit 0e09e55

Browse files
authored
Merge branch 'master' into patch-1
2 parents 7a3680d + d5da0a6 commit 0e09e55

29 files changed

+246
-121
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"coverage/",
1818
".nyc_output/",
1919
"test-published-types/",
20-
"tests/fixtures/flat-config/"
20+
"tests/fixtures/flat-config/",
21+
"**/*/*.d.ts",
2122
],
2223
"rules": {
2324
"comma-dangle": [2, "always-multiline"],

.github/workflows/npm-publish.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ jobs:
6363
const pending = checkSuites.filter(({ status }) => status !== 'completed')
6464
6565
if (pending.length > 0) {
66-
core.setFailed(`Some workflows for ${context.payload.inputs.tag} are still in-progress: ${JSON.stringify(pending)}`);
66+
core.setFailed(`Some workflows for ${context.payload.inputs.tag} are still in-progress`);
67+
pending.forEach(({ pull_requests, ...x }) => {
68+
core.debug(JSON.stringify(x));
69+
});
6770
}
6871
6972
const result = await Promise.all(
@@ -94,7 +97,7 @@ jobs:
9497
contents: read
9598
id-token: write
9699
steps:
97-
- uses: step-security/harden-runner@v1
100+
- uses: step-security/harden-runner@v2
98101
with:
99102
egress-policy: block
100103
allowed-endpoints: >

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
contents: write
1616

1717
steps:
18-
- uses: step-security/harden-runner@v1
18+
- uses: step-security/harden-runner@v2
1919
with:
2020
allowed-endpoints:
2121
api.github.com:443

.github/workflows/type-check.yml

+18-2
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,34 @@ jobs:
4444
- name: build types
4545
run: npm run build-types
4646

47+
# Pack the lib into a tarball so that when we install the lib later in the
48+
# test-published-types directory, it's only install `dependencies` of the
49+
# lib.
50+
- name: pack the lib
51+
run: npm pack --pack-destination /tmp/
52+
53+
- name: find the packed lib
54+
run: echo "ESLINT_PLUGIN_REACT_PATH=$(ls /tmp/eslint-plugin-react*.tgz | tail -n 1)" >> $GITHUB_ENV
55+
56+
- name: show the path to the packed lib
57+
run: echo "$ESLINT_PLUGIN_REACT_PATH"
58+
4759
- name: npm install working directory
4860
run: npm install
4961
working-directory: test-published-types
5062

51-
- name: install typescript version ${{ matrix.ts_version }}
52-
run: npm install --no-save typescript@${{ matrix.ts_version }}
63+
- name: install eslint-plugin-react and typescript version ${{ matrix.ts_version }}
64+
run: npm install --no-save "$ESLINT_PLUGIN_REACT_PATH" typescript@${{ matrix.ts_version }}
5365
working-directory: test-published-types
5466

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

71+
- name: show installed eslint-plugin-react version
72+
run: npm list eslint-plugin-react --depth=0
73+
working-directory: test-published-types
74+
5975
- name: check types with lib "${{ matrix.ts_lib }}"
6076
run: npx tsc --lib ${{ matrix.ts_lib }}
6177
working-directory: test-published-types

CHANGELOG.md

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

77
## Unreleased
88

9+
### Fixed
10+
* [`no-danger`]: avoid a crash on a nested component name ([#3833][] @ljharb)
11+
* [Fix] types: correct generated type declaration ([#3840][] @ocavue)
12+
13+
### Changed
14+
* [Tests] [`jsx-no-script-url`]: Improve tests ([#3849][] @radu2147)
15+
16+
[#3849]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3849
17+
[#3840]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3840
18+
[#3833]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3833
19+
20+
## [7.37.2] - 2024.10.22
21+
922
### Fixed
1023
* [`destructuring-assignment`]: fix false negative when using `typeof props.a` ([#3835][] @golopot)
1124

1225
### Changed
1326
* [Refactor] [`destructuring-assignment`]: use `getParentStatelessComponent` ([#3835][] @golopot)
1427

28+
[7.37.2]: https://github.com/jsx-eslint/eslint-plugin-react/compare/v7.37.1...v7.37.2
1529
[#3835]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3835
1630

1731
## [7.37.1] - 2024.10.01
@@ -22,6 +36,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2236
### Changed
2337
* [readme] Fix shared settings link ([#3834][] @MgenGlder)
2438

39+
[7.37.1]: https://github.com/jsx-eslint/eslint-plugin-react/compare/v7.37.0...v7.37.1
2540
[#3836]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3836
2641
[#3834]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3834
2742

@@ -36,7 +51,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
3651
### Changed
3752
* [readme] flat config example for react 17+ ([#3824][] @GabenGar)
3853

39-
[7.36.2]: https://github.com/jsx-eslint/eslint-plugin-react/compare/v7.36.1...v7.36.2
54+
[7.37.0]: https://github.com/jsx-eslint/eslint-plugin-react/compare/v7.36.1...v7.37.0
4055
[#3831]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3831
4156
[#3830]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3830
4257
[#3826]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3826

index.js

+29-25
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function filterRules(rules, predicate) {
1111

1212
/**
1313
* @param {object} rules - rules object mapping rule name to rule module
14-
* @returns {Record<string, 2 | 'error'>}
14+
* @returns {Record<string, SEVERITY_ERROR | 'error'>}
1515
*/
1616
function configureAsError(rules) {
1717
return fromEntries(Object.keys(rules).map((key) => [`react/${key}`, 2]));
@@ -31,6 +31,10 @@ const plugins = [
3131
'react',
3232
];
3333

34+
// TODO: with TS 4.5+, inline this
35+
const SEVERITY_ERROR = /** @type {2} */ (2);
36+
const SEVERITY_OFF = /** @type {0} */ (0);
37+
3438
const configs = {
3539
recommended: {
3640
plugins,
@@ -40,28 +44,28 @@ const configs = {
4044
},
4145
},
4246
rules: {
43-
'react/display-name': 2,
44-
'react/jsx-key': 2,
45-
'react/jsx-no-comment-textnodes': 2,
46-
'react/jsx-no-duplicate-props': 2,
47-
'react/jsx-no-target-blank': 2,
48-
'react/jsx-no-undef': 2,
49-
'react/jsx-uses-react': 2,
50-
'react/jsx-uses-vars': 2,
51-
'react/no-children-prop': 2,
52-
'react/no-danger-with-children': 2,
53-
'react/no-deprecated': 2,
54-
'react/no-direct-mutation-state': 2,
55-
'react/no-find-dom-node': 2,
56-
'react/no-is-mounted': 2,
57-
'react/no-render-return-value': 2,
58-
'react/no-string-refs': 2,
59-
'react/no-unescaped-entities': 2,
60-
'react/no-unknown-property': 2,
61-
'react/no-unsafe': 0,
62-
'react/prop-types': 2,
63-
'react/react-in-jsx-scope': 2,
64-
'react/require-render-return': 2,
47+
'react/display-name': SEVERITY_ERROR,
48+
'react/jsx-key': SEVERITY_ERROR,
49+
'react/jsx-no-comment-textnodes': SEVERITY_ERROR,
50+
'react/jsx-no-duplicate-props': SEVERITY_ERROR,
51+
'react/jsx-no-target-blank': SEVERITY_ERROR,
52+
'react/jsx-no-undef': SEVERITY_ERROR,
53+
'react/jsx-uses-react': SEVERITY_ERROR,
54+
'react/jsx-uses-vars': SEVERITY_ERROR,
55+
'react/no-children-prop': SEVERITY_ERROR,
56+
'react/no-danger-with-children': SEVERITY_ERROR,
57+
'react/no-deprecated': SEVERITY_ERROR,
58+
'react/no-direct-mutation-state': SEVERITY_ERROR,
59+
'react/no-find-dom-node': SEVERITY_ERROR,
60+
'react/no-is-mounted': SEVERITY_ERROR,
61+
'react/no-render-return-value': SEVERITY_ERROR,
62+
'react/no-string-refs': SEVERITY_ERROR,
63+
'react/no-unescaped-entities': SEVERITY_ERROR,
64+
'react/no-unknown-property': SEVERITY_ERROR,
65+
'react/no-unsafe': SEVERITY_OFF,
66+
'react/prop-types': SEVERITY_ERROR,
67+
'react/react-in-jsx-scope': SEVERITY_ERROR,
68+
'react/require-render-return': SEVERITY_ERROR,
6569
},
6670
},
6771
all: {
@@ -82,8 +86,8 @@ const configs = {
8286
jsxPragma: null, // for @typescript/eslint-parser
8387
},
8488
rules: {
85-
'react/react-in-jsx-scope': 0,
86-
'react/jsx-uses-react': 0,
89+
'react/react-in-jsx-scope': SEVERITY_OFF,
90+
'react/jsx-uses-react': SEVERITY_OFF,
8791
},
8892
},
8993
};

lib/rules/forbid-foreign-prop-types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ module.exports = {
109109
&& !ast.isAssignmentLHS(node)
110110
&& !isAllowedAssignment(node)
111111
)) || (
112-
// @ts-expect-error The JSXText type is not present in the estree type definitions
112+
// @ts-expect-error: The JSXText type is not present in the estree type definitions
113113
(node.property.type === 'Literal' || node.property.type === 'JSXText')
114114
&& 'value' in node.property
115115
&& node.property.value === 'propTypes'

lib/rules/forbid-prop-types.js

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ module.exports = {
195195
const propTypesSpecifier = node.specifiers.find((specifier) => (
196196
'imported' in specifier
197197
&& specifier.imported
198+
&& 'name' in specifier.imported
198199
&& specifier.imported.name === 'PropTypes'
199200
));
200201
if (propTypesSpecifier) {

lib/rules/forward-ref-uses-ref.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const messages = {
4141
removeForwardRef: 'Remove forwardRef wrapper',
4242
};
4343

44+
/** @type {import('eslint').Rule.RuleModule} */
4445
module.exports = {
4546
meta: {
4647
docs: {

lib/rules/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint global-require: 0 */
44

55
/** @satisfies {Record<string, import('eslint').Rule.RuleModule>} */
6-
module.exports = {
6+
const rules = {
77
'boolean-prop-naming': require('./boolean-prop-naming'),
88
'button-has-type': require('./button-has-type'),
99
'checked-requires-onchange-or-readonly': require('./checked-requires-onchange-or-readonly'),
@@ -108,3 +108,5 @@ module.exports = {
108108
'style-prop-object': require('./style-prop-object'),
109109
'void-dom-elements-no-children': require('./void-dom-elements-no-children'),
110110
};
111+
112+
module.exports = rules;

lib/rules/jsx-fragments.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ module.exports = {
170170
ImportDeclaration(node) {
171171
if (node.source && node.source.value === 'react') {
172172
node.specifiers.forEach((spec) => {
173-
if ('imported' in spec && spec.imported && spec.imported.name === fragmentPragma) {
173+
if (
174+
'imported' in spec
175+
&& spec.imported
176+
&& 'name' in spec.imported
177+
&& spec.imported.name === fragmentPragma
178+
) {
174179
if (spec.local) {
175180
fragmentNames.add(spec.local.name);
176181
}

lib/rules/jsx-handler-names.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ const messages = {
1919
badPropKey: 'Prop key for {{propValue}} must begin with \'{{handlerPropPrefix}}\'',
2020
};
2121

22+
function isPrefixDisabled(prefix) {
23+
return prefix === false;
24+
}
25+
26+
function isInlineHandler(node) {
27+
return node.value.expression.type === 'ArrowFunctionExpression';
28+
}
29+
2230
/** @type {import('eslint').Rule.RuleModule} */
2331
module.exports = {
2432
meta: {
@@ -109,14 +117,6 @@ module.exports = {
109117
},
110118

111119
create(context) {
112-
function isPrefixDisabled(prefix) {
113-
return prefix === false;
114-
}
115-
116-
function isInlineHandler(node) {
117-
return node.value.expression.type === 'ArrowFunctionExpression';
118-
}
119-
120120
const configuration = context.options[0] || {};
121121

122122
const eventHandlerPrefix = isPrefixDisabled(configuration.eventHandlerPrefix)
@@ -143,10 +143,10 @@ module.exports = {
143143
JSXAttribute(node) {
144144
const componentName = node.parent.name.name;
145145

146-
const isComponentNameIgnored = ignoreComponentNames.some((ignoredComponentNamePattern) => {
147-
const isIgnored = minimatch(componentName, ignoredComponentNamePattern);
148-
return isIgnored;
149-
});
146+
const isComponentNameIgnored = ignoreComponentNames.some((ignoredComponentNamePattern) => minimatch(
147+
componentName,
148+
ignoredComponentNamePattern
149+
));
150150

151151
if (
152152
!node.value

0 commit comments

Comments
 (0)