Skip to content

Commit

Permalink
[Fix] no-is-mounted: fix logic in method name check
Browse files Browse the repository at this point in the history
The last change to `no-is-mounted` caused the rule to error with any method name, not just with "isMounted".
  • Loading branch information
Mathias-S authored and ljharb committed Sep 12, 2024
1 parent 1df23d2 commit a09083b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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

### Fixed
* [`no-is-mounted`]: fix logic in method name check ([#3821][] @Mathias-S)

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

## [7.36.0] - 2024.09.12

### Added
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-is-mounted.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ module.exports = {
}
if (
callee.object.type !== 'ThisExpression'
&& (!('name' in callee.property) || callee.property.name !== 'isMounted')
|| !('name' in callee.property)
|| callee.property.name !== 'isMounted'
) {
return;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/no-is-mounted.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ ruleTester.run('no-is-mounted', rule, {
});
`,
},
{
code: `
class Hello extends React.Component {
notIsMounted() {}
render() {
this.notIsMounted();
return <div>Hello</div>;
}
};
`,
},
]),

invalid: parsers.all([
Expand Down

0 comments on commit a09083b

Please sign in to comment.