Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiendmt authored Dec 5, 2024
2 parents 7a3680d + d5da0a6 commit 0e09e55
Show file tree
Hide file tree
Showing 29 changed files with 246 additions and 121 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"coverage/",
".nyc_output/",
"test-published-types/",
"tests/fixtures/flat-config/"
"tests/fixtures/flat-config/",
"**/*/*.d.ts",
],
"rules": {
"comma-dangle": [2, "always-multiline"],
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ jobs:
const pending = checkSuites.filter(({ status }) => status !== 'completed')
if (pending.length > 0) {
core.setFailed(`Some workflows for ${context.payload.inputs.tag} are still in-progress: ${JSON.stringify(pending)}`);
core.setFailed(`Some workflows for ${context.payload.inputs.tag} are still in-progress`);
pending.forEach(({ pull_requests, ...x }) => {
core.debug(JSON.stringify(x));
});
}
const result = await Promise.all(
Expand Down Expand Up @@ -94,7 +97,7 @@ jobs:
contents: read
id-token: write
steps:
- uses: step-security/harden-runner@v1
- uses: step-security/harden-runner@v2
with:
egress-policy: block
allowed-endpoints: >
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
contents: write

steps:
- uses: step-security/harden-runner@v1
- uses: step-security/harden-runner@v2
with:
allowed-endpoints:
api.github.com:443
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,34 @@ jobs:
- name: build types
run: npm run build-types

# Pack the lib into a tarball so that when we install the lib later in the
# test-published-types directory, it's only install `dependencies` of the
# lib.
- name: pack the lib
run: npm pack --pack-destination /tmp/

- name: find the packed lib
run: echo "ESLINT_PLUGIN_REACT_PATH=$(ls /tmp/eslint-plugin-react*.tgz | tail -n 1)" >> $GITHUB_ENV

- name: show the path to the packed lib
run: echo "$ESLINT_PLUGIN_REACT_PATH"

- 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 }}
- name: install eslint-plugin-react and typescript version ${{ matrix.ts_version }}
run: npm install --no-save "$ESLINT_PLUGIN_REACT_PATH" 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: show installed eslint-plugin-react version
run: npm list eslint-plugin-react --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
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

## Unreleased

### Fixed
* [`no-danger`]: avoid a crash on a nested component name ([#3833][] @ljharb)
* [Fix] types: correct generated type declaration ([#3840][] @ocavue)

### Changed
* [Tests] [`jsx-no-script-url`]: Improve tests ([#3849][] @radu2147)

[#3849]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3849
[#3840]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3840
[#3833]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3833

## [7.37.2] - 2024.10.22

### Fixed
* [`destructuring-assignment`]: fix false negative when using `typeof props.a` ([#3835][] @golopot)

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

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

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

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

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

[7.36.2]: https://github.com/jsx-eslint/eslint-plugin-react/compare/v7.36.1...v7.36.2
[7.37.0]: https://github.com/jsx-eslint/eslint-plugin-react/compare/v7.36.1...v7.37.0
[#3831]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3831
[#3830]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3830
[#3826]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3826
Expand Down
54 changes: 29 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function filterRules(rules, predicate) {

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

// TODO: with TS 4.5+, inline this
const SEVERITY_ERROR = /** @type {2} */ (2);
const SEVERITY_OFF = /** @type {0} */ (0);

const configs = {
recommended: {
plugins,
Expand All @@ -40,28 +44,28 @@ const configs = {
},
},
rules: {
'react/display-name': 2,
'react/jsx-key': 2,
'react/jsx-no-comment-textnodes': 2,
'react/jsx-no-duplicate-props': 2,
'react/jsx-no-target-blank': 2,
'react/jsx-no-undef': 2,
'react/jsx-uses-react': 2,
'react/jsx-uses-vars': 2,
'react/no-children-prop': 2,
'react/no-danger-with-children': 2,
'react/no-deprecated': 2,
'react/no-direct-mutation-state': 2,
'react/no-find-dom-node': 2,
'react/no-is-mounted': 2,
'react/no-render-return-value': 2,
'react/no-string-refs': 2,
'react/no-unescaped-entities': 2,
'react/no-unknown-property': 2,
'react/no-unsafe': 0,
'react/prop-types': 2,
'react/react-in-jsx-scope': 2,
'react/require-render-return': 2,
'react/display-name': SEVERITY_ERROR,
'react/jsx-key': SEVERITY_ERROR,
'react/jsx-no-comment-textnodes': SEVERITY_ERROR,
'react/jsx-no-duplicate-props': SEVERITY_ERROR,
'react/jsx-no-target-blank': SEVERITY_ERROR,
'react/jsx-no-undef': SEVERITY_ERROR,
'react/jsx-uses-react': SEVERITY_ERROR,
'react/jsx-uses-vars': SEVERITY_ERROR,
'react/no-children-prop': SEVERITY_ERROR,
'react/no-danger-with-children': SEVERITY_ERROR,
'react/no-deprecated': SEVERITY_ERROR,
'react/no-direct-mutation-state': SEVERITY_ERROR,
'react/no-find-dom-node': SEVERITY_ERROR,
'react/no-is-mounted': SEVERITY_ERROR,
'react/no-render-return-value': SEVERITY_ERROR,
'react/no-string-refs': SEVERITY_ERROR,
'react/no-unescaped-entities': SEVERITY_ERROR,
'react/no-unknown-property': SEVERITY_ERROR,
'react/no-unsafe': SEVERITY_OFF,
'react/prop-types': SEVERITY_ERROR,
'react/react-in-jsx-scope': SEVERITY_ERROR,
'react/require-render-return': SEVERITY_ERROR,
},
},
all: {
Expand All @@ -82,8 +86,8 @@ const configs = {
jsxPragma: null, // for @typescript/eslint-parser
},
rules: {
'react/react-in-jsx-scope': 0,
'react/jsx-uses-react': 0,
'react/react-in-jsx-scope': SEVERITY_OFF,
'react/jsx-uses-react': SEVERITY_OFF,
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/forbid-foreign-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = {
&& !ast.isAssignmentLHS(node)
&& !isAllowedAssignment(node)
)) || (
// @ts-expect-error The JSXText type is not present in the estree type definitions
// @ts-expect-error: The JSXText type is not present in the estree type definitions
(node.property.type === 'Literal' || node.property.type === 'JSXText')
&& 'value' in node.property
&& node.property.value === 'propTypes'
Expand Down
1 change: 1 addition & 0 deletions lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ module.exports = {
const propTypesSpecifier = node.specifiers.find((specifier) => (
'imported' in specifier
&& specifier.imported
&& 'name' in specifier.imported
&& specifier.imported.name === 'PropTypes'
));
if (propTypesSpecifier) {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/forward-ref-uses-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const messages = {
removeForwardRef: 'Remove forwardRef wrapper',
};

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
docs: {
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint global-require: 0 */

/** @satisfies {Record<string, import('eslint').Rule.RuleModule>} */
module.exports = {
const rules = {
'boolean-prop-naming': require('./boolean-prop-naming'),
'button-has-type': require('./button-has-type'),
'checked-requires-onchange-or-readonly': require('./checked-requires-onchange-or-readonly'),
Expand Down Expand Up @@ -108,3 +108,5 @@ module.exports = {
'style-prop-object': require('./style-prop-object'),
'void-dom-elements-no-children': require('./void-dom-elements-no-children'),
};

module.exports = rules;
7 changes: 6 additions & 1 deletion lib/rules/jsx-fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ module.exports = {
ImportDeclaration(node) {
if (node.source && node.source.value === 'react') {
node.specifiers.forEach((spec) => {
if ('imported' in spec && spec.imported && spec.imported.name === fragmentPragma) {
if (
'imported' in spec
&& spec.imported
&& 'name' in spec.imported
&& spec.imported.name === fragmentPragma
) {
if (spec.local) {
fragmentNames.add(spec.local.name);
}
Expand Down
24 changes: 12 additions & 12 deletions lib/rules/jsx-handler-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ const messages = {
badPropKey: 'Prop key for {{propValue}} must begin with \'{{handlerPropPrefix}}\'',
};

function isPrefixDisabled(prefix) {
return prefix === false;
}

function isInlineHandler(node) {
return node.value.expression.type === 'ArrowFunctionExpression';
}

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
Expand Down Expand Up @@ -109,14 +117,6 @@ module.exports = {
},

create(context) {
function isPrefixDisabled(prefix) {
return prefix === false;
}

function isInlineHandler(node) {
return node.value.expression.type === 'ArrowFunctionExpression';
}

const configuration = context.options[0] || {};

const eventHandlerPrefix = isPrefixDisabled(configuration.eventHandlerPrefix)
Expand All @@ -143,10 +143,10 @@ module.exports = {
JSXAttribute(node) {
const componentName = node.parent.name.name;

const isComponentNameIgnored = ignoreComponentNames.some((ignoredComponentNamePattern) => {
const isIgnored = minimatch(componentName, ignoredComponentNamePattern);
return isIgnored;
});
const isComponentNameIgnored = ignoreComponentNames.some((ignoredComponentNamePattern) => minimatch(
componentName,
ignoredComponentNamePattern
));

if (
!node.value
Expand Down
Loading

0 comments on commit 0e09e55

Please sign in to comment.